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/chrome_version_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"
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 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
47 case chrome::VersionInfo::CHANNEL_UNKNOWN
:
48 return GCMClient::CHANNEL_UNKNOWN
;
49 case chrome::VersionInfo::CHANNEL_CANARY
:
50 return GCMClient::CHANNEL_CANARY
;
51 case chrome::VersionInfo::CHANNEL_DEV
:
52 return GCMClient::CHANNEL_DEV
;
53 case chrome::VersionInfo::CHANNEL_BETA
:
54 return GCMClient::CHANNEL_BETA
;
55 case chrome::VersionInfo::CHANNEL_STABLE
:
56 return GCMClient::CHANNEL_STABLE
;
59 return GCMClient::CHANNEL_UNKNOWN
;
63 std::string
GetVersion() {
64 chrome::VersionInfo version_info
;
65 return version_info
.Version();
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 chrome::VersionInfo version_info
;
83 return MakeDesktopUserAgentForSync(version_info
);
88 scoped_ptr
<GCMDriver
> CreateGCMDriverDesktopWithTaskRunners(
89 scoped_ptr
<GCMClientFactory
> gcm_client_factory
,
91 const base::FilePath
& store_path
,
92 const scoped_refptr
<net::URLRequestContextGetter
>& request_context
,
93 const scoped_refptr
<base::SequencedTaskRunner
>& ui_thread
,
94 const scoped_refptr
<base::SequencedTaskRunner
>& io_thread
,
95 const scoped_refptr
<base::SequencedTaskRunner
>& blocking_task_runner
) {
96 return scoped_ptr
<GCMDriver
>(new GCMDriverDesktop(
97 gcm_client_factory
.Pass(),
99 GetChannelStatusRequestUrl(),
106 blocking_task_runner
));