• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/services/gcm/gcm_desktop_utils.h"
6 
7 #include "base/logging.h"
8 #include "base/sequenced_task_runner.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/common/chrome_version_info.h"
11 #include "components/gcm_driver/gcm_client.h"
12 #include "components/gcm_driver/gcm_client_factory.h"
13 #include "components/gcm_driver/gcm_driver.h"
14 #include "components/gcm_driver/gcm_driver_desktop.h"
15 #include "content/public/browser/browser_thread.h"
16 
17 namespace gcm {
18 
19 namespace {
20 
GetPlatform()21 GCMClient::ChromePlatform GetPlatform() {
22 #if defined(OS_WIN)
23   return GCMClient::PLATFORM_WIN;
24 #elif defined(OS_MACOSX)
25   return GCMClient::PLATFORM_MAC;
26 #elif defined(OS_IOS)
27   return GCMClient::PLATFORM_IOS;
28 #elif defined(OS_ANDROID)
29   return GCMClient::PLATFORM_ANDROID;
30 #elif defined(OS_CHROMEOS)
31   return GCMClient::PLATFORM_CROS;
32 #elif defined(OS_LINUX)
33   return GCMClient::PLATFORM_LINUX;
34 #else
35   // For all other platforms, return as LINUX.
36   return GCMClient::PLATFORM_LINUX;
37 #endif
38 }
39 
GetChannel()40 GCMClient::ChromeChannel GetChannel() {
41   chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
42   switch (channel) {
43     case chrome::VersionInfo::CHANNEL_UNKNOWN:
44       return GCMClient::CHANNEL_UNKNOWN;
45     case chrome::VersionInfo::CHANNEL_CANARY:
46       return GCMClient::CHANNEL_CANARY;
47     case chrome::VersionInfo::CHANNEL_DEV:
48       return GCMClient::CHANNEL_DEV;
49     case chrome::VersionInfo::CHANNEL_BETA:
50       return GCMClient::CHANNEL_BETA;
51     case chrome::VersionInfo::CHANNEL_STABLE:
52       return GCMClient::CHANNEL_STABLE;
53     default:
54       NOTREACHED();
55       return GCMClient::CHANNEL_UNKNOWN;
56   }
57 }
58 
GetVersion()59 std::string GetVersion() {
60   chrome::VersionInfo version_info;
61   return version_info.Version();
62 }
63 
GetChromeBuildInfo()64 GCMClient::ChromeBuildInfo GetChromeBuildInfo() {
65   GCMClient::ChromeBuildInfo chrome_build_info;
66   chrome_build_info.platform = GetPlatform();
67   chrome_build_info.channel = GetChannel();
68   chrome_build_info.version = GetVersion();
69   return chrome_build_info;
70 }
71 
72 }  // namespace
73 
CreateGCMDriverDesktop(scoped_ptr<GCMClientFactory> gcm_client_factory,const base::FilePath & store_path,const scoped_refptr<net::URLRequestContextGetter> & request_context)74 scoped_ptr<GCMDriver> CreateGCMDriverDesktop(
75     scoped_ptr<GCMClientFactory> gcm_client_factory,
76     const base::FilePath& store_path,
77     const scoped_refptr<net::URLRequestContextGetter>& request_context) {
78   scoped_refptr<base::SequencedWorkerPool> worker_pool(
79       content::BrowserThread::GetBlockingPool());
80   scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
81       worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
82           worker_pool->GetSequenceToken(),
83           base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
84   return scoped_ptr<GCMDriver>(new GCMDriverDesktop(
85       gcm_client_factory.Pass(),
86       GetChromeBuildInfo(),
87       store_path,
88       request_context,
89       content::BrowserThread::GetMessageLoopProxyForThread(
90           content::BrowserThread::UI),
91       content::BrowserThread::GetMessageLoopProxyForThread(
92           content::BrowserThread::IO),
93       blocking_task_runner));
94 }
95 
96 }  // namespace gcm
97