Revert of [GCM] Start GCMChannelStatusSyncer when GCM is disabled (patchset #2 id...
[chromium-blink-merge.git] / chrome / browser / services / gcm / gcm_desktop_utils.cc
blobfa66bb35d361af0afc96583085e6329e147a7ad0
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/logging.h"
8 #include "base/sequenced_task_runner.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h"
11 #include "chrome/browser/sync/profile_sync_service.h"
12 #include "chrome/common/chrome_version_info.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 "content/public/browser/browser_thread.h"
19 namespace gcm {
21 namespace {
23 GCMClient::ChromePlatform GetPlatform() {
24 #if defined(OS_WIN)
25 return GCMClient::PLATFORM_WIN;
26 #elif defined(OS_MACOSX)
27 return GCMClient::PLATFORM_MAC;
28 #elif defined(OS_IOS)
29 return GCMClient::PLATFORM_IOS;
30 #elif defined(OS_ANDROID)
31 return GCMClient::PLATFORM_ANDROID;
32 #elif defined(OS_CHROMEOS)
33 return GCMClient::PLATFORM_CROS;
34 #elif defined(OS_LINUX)
35 return GCMClient::PLATFORM_LINUX;
36 #else
37 // For all other platforms, return as LINUX.
38 return GCMClient::PLATFORM_LINUX;
39 #endif
42 GCMClient::ChromeChannel GetChannel() {
43 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
44 switch (channel) {
45 case chrome::VersionInfo::CHANNEL_UNKNOWN:
46 return GCMClient::CHANNEL_UNKNOWN;
47 case chrome::VersionInfo::CHANNEL_CANARY:
48 return GCMClient::CHANNEL_CANARY;
49 case chrome::VersionInfo::CHANNEL_DEV:
50 return GCMClient::CHANNEL_DEV;
51 case chrome::VersionInfo::CHANNEL_BETA:
52 return GCMClient::CHANNEL_BETA;
53 case chrome::VersionInfo::CHANNEL_STABLE:
54 return GCMClient::CHANNEL_STABLE;
55 default:
56 NOTREACHED();
57 return GCMClient::CHANNEL_UNKNOWN;
61 std::string GetVersion() {
62 chrome::VersionInfo version_info;
63 return version_info.Version();
66 GCMClient::ChromeBuildInfo GetChromeBuildInfo() {
67 GCMClient::ChromeBuildInfo chrome_build_info;
68 chrome_build_info.platform = GetPlatform();
69 chrome_build_info.channel = GetChannel();
70 chrome_build_info.version = GetVersion();
71 return chrome_build_info;
74 std::string GetChannelStatusRequestUrl() {
75 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
76 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
77 channel == chrome::VersionInfo::CHANNEL_BETA) {
78 return ProfileSyncService::kSyncServerUrl;
81 return ProfileSyncService::kDevServerUrl;
84 std::string GetUserAgent() {
85 chrome::VersionInfo version_info;
86 return browser_sync::LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi(
87 version_info);
90 } // namespace
92 scoped_ptr<GCMDriver> CreateGCMDriverDesktop(
93 scoped_ptr<GCMClientFactory> gcm_client_factory,
94 PrefService* prefs,
95 const base::FilePath& store_path,
96 const scoped_refptr<net::URLRequestContextGetter>& request_context) {
97 scoped_refptr<base::SequencedWorkerPool> worker_pool(
98 content::BrowserThread::GetBlockingPool());
99 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
100 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
101 worker_pool->GetSequenceToken(),
102 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
103 return scoped_ptr<GCMDriver>(
104 new GCMDriverDesktop(gcm_client_factory.Pass(),
105 GetChromeBuildInfo(),
106 GetChannelStatusRequestUrl(),
107 GetUserAgent(),
108 prefs,
109 store_path,
110 request_context,
111 content::BrowserThread::GetMessageLoopProxyForThread(
112 content::BrowserThread::UI),
113 content::BrowserThread::GetMessageLoopProxyForThread(
114 content::BrowserThread::IO),
115 blocking_task_runner));
118 } // namespace gcm