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/browser/services/gcm/gcm_desktop_utils.h"
11 #include "chrome/common/channel_info.h"
12 #include "chrome/common/sync_util.h"
13 #include "components/gcm_driver/gcm_client_factory.h"
14 #include "components/gcm_driver/gcm_driver.h"
15 #include "components/gcm_driver/gcm_driver_desktop.h"
16 #include "components/version_info/version_info.h"
17 #include "content/public/browser/browser_thread.h"
24 const char kChannelStatusRelativePath
[] = "/experimentstatus";
26 GCMClient::ChromePlatform
GetPlatform() {
28 return GCMClient::PLATFORM_WIN
;
29 #elif defined(OS_MACOSX)
30 return GCMClient::PLATFORM_MAC
;
32 return GCMClient::PLATFORM_IOS
;
33 #elif defined(OS_ANDROID)
34 return GCMClient::PLATFORM_ANDROID
;
35 #elif defined(OS_CHROMEOS)
36 return GCMClient::PLATFORM_CROS
;
37 #elif defined(OS_LINUX)
38 return GCMClient::PLATFORM_LINUX
;
40 // For all other platforms, return as LINUX.
41 return GCMClient::PLATFORM_LINUX
;
45 GCMClient::ChromeChannel
GetChannel() {
46 version_info::Channel channel
= chrome::GetChannel();
48 case version_info::Channel::UNKNOWN
:
49 return GCMClient::CHANNEL_UNKNOWN
;
50 case version_info::Channel::CANARY
:
51 return GCMClient::CHANNEL_CANARY
;
52 case version_info::Channel::DEV
:
53 return GCMClient::CHANNEL_DEV
;
54 case version_info::Channel::BETA
:
55 return GCMClient::CHANNEL_BETA
;
56 case version_info::Channel::STABLE
:
57 return GCMClient::CHANNEL_STABLE
;
60 return GCMClient::CHANNEL_UNKNOWN
;
64 std::string
GetVersion() {
65 return version_info::GetVersionNumber();
68 GCMClient::ChromeBuildInfo
GetChromeBuildInfo() {
69 GCMClient::ChromeBuildInfo chrome_build_info
;
70 chrome_build_info
.platform
= GetPlatform();
71 chrome_build_info
.channel
= GetChannel();
72 chrome_build_info
.version
= GetVersion();
73 return chrome_build_info
;
76 std::string
GetChannelStatusRequestUrl() {
77 GURL
sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess()));
78 return sync_url
.spec() + kChannelStatusRelativePath
;
81 std::string
GetUserAgent() {
82 return MakeDesktopUserAgentForSync();
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
));