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.
5 #include "chrome/browser/services/gcm/gcm_desktop_utils.h"
7 #include "base/command_line.h"
8 #include "base/sequenced_task_runner.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/common/channel_info.h"
11 #include "components/gcm_driver/gcm_client_factory.h"
12 #include "components/gcm_driver/gcm_driver.h"
13 #include "components/gcm_driver/gcm_driver_desktop.h"
14 #include "components/sync_driver/sync_util.h"
15 #include "components/version_info/version_info.h"
16 #include "content/public/browser/browser_thread.h"
23 const char kChannelStatusRelativePath
[] = "/experimentstatus";
25 GCMClient::ChromePlatform
GetPlatform() {
27 return GCMClient::PLATFORM_WIN
;
28 #elif defined(OS_MACOSX)
29 return GCMClient::PLATFORM_MAC
;
31 return GCMClient::PLATFORM_IOS
;
32 #elif defined(OS_ANDROID)
33 return GCMClient::PLATFORM_ANDROID
;
34 #elif defined(OS_CHROMEOS)
35 return GCMClient::PLATFORM_CROS
;
36 #elif defined(OS_LINUX)
37 return GCMClient::PLATFORM_LINUX
;
39 // For all other platforms, return as LINUX.
40 return GCMClient::PLATFORM_LINUX
;
44 GCMClient::ChromeChannel
GetChannel() {
45 version_info::Channel channel
= chrome::GetChannel();
47 case version_info::Channel::UNKNOWN
:
48 return GCMClient::CHANNEL_UNKNOWN
;
49 case version_info::Channel::CANARY
:
50 return GCMClient::CHANNEL_CANARY
;
51 case version_info::Channel::DEV
:
52 return GCMClient::CHANNEL_DEV
;
53 case version_info::Channel::BETA
:
54 return GCMClient::CHANNEL_BETA
;
55 case version_info::Channel::STABLE
:
56 return GCMClient::CHANNEL_STABLE
;
59 return GCMClient::CHANNEL_UNKNOWN
;
63 std::string
GetVersion() {
64 return version_info::GetVersionNumber();
67 GCMClient::ChromeBuildInfo
GetChromeBuildInfo() {
68 GCMClient::ChromeBuildInfo chrome_build_info
;
69 chrome_build_info
.platform
= GetPlatform();
70 chrome_build_info
.channel
= GetChannel();
71 chrome_build_info
.version
= GetVersion();
72 return chrome_build_info
;
75 std::string
GetChannelStatusRequestUrl() {
76 GURL
sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(),
77 chrome::GetChannel()));
78 return sync_url
.spec() + kChannelStatusRelativePath
;
81 std::string
GetUserAgent() {
82 return MakeDesktopUserAgentForSync(chrome::GetChannel());
87 scoped_ptr
<GCMDriver
> CreateGCMDriverDesktop(
88 scoped_ptr
<GCMClientFactory
> gcm_client_factory
,
90 const base::FilePath
& store_path
,
91 const scoped_refptr
<net::URLRequestContextGetter
>& request_context
) {
93 scoped_refptr
<base::SequencedWorkerPool
> worker_pool(
94 content::BrowserThread::GetBlockingPool());
95 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner(
96 worker_pool
->GetSequencedTaskRunnerWithShutdownBehavior(
97 worker_pool
->GetSequenceToken(),
98 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
));
100 return scoped_ptr
<GCMDriver
>(new GCMDriverDesktop(
101 gcm_client_factory
.Pass(),
102 GetChromeBuildInfo(),
103 GetChannelStatusRequestUrl(),
108 content::BrowserThread::GetMessageLoopProxyForThread(
109 content::BrowserThread::UI
),
110 content::BrowserThread::GetMessageLoopProxyForThread(
111 content::BrowserThread::IO
),
112 blocking_task_runner
));