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/common/gcm_desktop_util.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/sequenced_task_runner.h"
10 #include "base/threading/sequenced_worker_pool.h"
11 #include "chrome/common/channel_info.h"
12 #include "chrome/common/sync_util.h"
13 #include "components/gcm_driver/gcm_client.h"
14 #include "components/gcm_driver/gcm_client_factory.h"
15 #include "components/gcm_driver/gcm_driver.h"
16 #include "components/gcm_driver/gcm_driver_desktop.h"
17 #include "components/version_info/version_info.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
> CreateGCMDriverDesktopWithTaskRunners(
88 scoped_ptr
<GCMClientFactory
> gcm_client_factory
,
90 const base::FilePath
& store_path
,
91 const scoped_refptr
<net::URLRequestContextGetter
>& request_context
,
92 const scoped_refptr
<base::SequencedTaskRunner
>& ui_thread
,
93 const scoped_refptr
<base::SequencedTaskRunner
>& io_thread
,
94 const scoped_refptr
<base::SequencedTaskRunner
>& blocking_task_runner
) {
95 return scoped_ptr
<GCMDriver
>(new GCMDriverDesktop(
96 gcm_client_factory
.Pass(),
98 GetChannelStatusRequestUrl(),
105 blocking_task_runner
));