Add ICU message format support
[chromium-blink-merge.git] / chrome / common / gcm_desktop_util.cc
blob692e21b245c631c36e230a6aae49e412ea651f74
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"
18 #include "url/gurl.h"
20 namespace gcm {
22 namespace {
24 const char kChannelStatusRelativePath[] = "/experimentstatus";
26 GCMClient::ChromePlatform GetPlatform() {
27 #if defined(OS_WIN)
28 return GCMClient::PLATFORM_WIN;
29 #elif defined(OS_MACOSX)
30 return GCMClient::PLATFORM_MAC;
31 #elif defined(OS_IOS)
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;
39 #else
40 // For all other platforms, return as LINUX.
41 return GCMClient::PLATFORM_LINUX;
42 #endif
45 GCMClient::ChromeChannel GetChannel() {
46 version_info::Channel channel = chrome::GetChannel();
47 switch (channel) {
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;
58 default:
59 NOTREACHED();
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();
85 } // namespace
87 scoped_ptr<GCMDriver> CreateGCMDriverDesktopWithTaskRunners(
88 scoped_ptr<GCMClientFactory> gcm_client_factory,
89 PrefService* prefs,
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(),
97 GetChromeBuildInfo(),
98 GetChannelStatusRequestUrl(),
99 GetUserAgent(),
100 prefs,
101 store_path,
102 request_context,
103 ui_thread,
104 io_thread,
105 blocking_task_runner));
108 } // namespace gcm