Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: chrome/browser/services/gcm/gcm_desktop_utils.cc

Issue 1325063002: Componentizing chrome/browser/services/gcm/gcm_desktop_utils.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/services/gcm/gcm_desktop_utils.h"
6
7 #include "base/command_line.h"
8 #include "base/sequenced_task_runner.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/common/channel_info.h"
11 #include "components/gcm_driver/gcm_client_factory.h"
12 #include "components/gcm_driver/gcm_driver.h"
13 #include "components/gcm_driver/gcm_driver_desktop.h"
14 #include "components/sync_driver/sync_util.h"
15 #include "components/version_info/version_info.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "url/gurl.h"
18
19 namespace gcm {
20
21 namespace {
22
23 const char kChannelStatusRelativePath[] = "/experimentstatus";
24
25 GCMClient::ChromePlatform GetPlatform() {
26 #if defined(OS_WIN)
27 return GCMClient::PLATFORM_WIN;
28 #elif defined(OS_MACOSX)
29 return GCMClient::PLATFORM_MAC;
30 #elif defined(OS_IOS)
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;
38 #else
39 // For all other platforms, return as LINUX.
40 return GCMClient::PLATFORM_LINUX;
41 #endif
42 }
43
44 GCMClient::ChromeChannel GetChannel() {
45 version_info::Channel channel = chrome::GetChannel();
46 switch (channel) {
47 case version_info::Channel::UNKNOWN:
48 return GCMClient::CHANNEL_UNKNOWN;
49 case version_info::Channel::CANARY:
50 return GCMClient::CHANNEL_CANARY;
51 case version_info::Channel::DEV:
52 return GCMClient::CHANNEL_DEV;
53 case version_info::Channel::BETA:
54 return GCMClient::CHANNEL_BETA;
55 case version_info::Channel::STABLE:
56 return GCMClient::CHANNEL_STABLE;
57 default:
58 NOTREACHED();
59 return GCMClient::CHANNEL_UNKNOWN;
60 }
61 }
62
63 std::string GetVersion() {
64 return version_info::GetVersionNumber();
65 }
66
67 GCMClient::ChromeBuildInfo GetChromeBuildInfo() {
68 GCMClient::ChromeBuildInfo chrome_build_info;
69 chrome_build_info.platform = GetPlatform();
70 chrome_build_info.channel = GetChannel();
71 chrome_build_info.version = GetVersion();
72 return chrome_build_info;
73 }
74
75 std::string GetChannelStatusRequestUrl() {
76 GURL sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(),
77 chrome::GetChannel()));
78 return sync_url.spec() + kChannelStatusRelativePath;
79 }
80
81 std::string GetUserAgent() {
82 return MakeDesktopUserAgentForSync(chrome::GetChannel());
83 }
84
85 } // namespace
86
87 scoped_ptr<GCMDriver> CreateGCMDriverDesktop(
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
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));
99
100 return scoped_ptr<GCMDriver>(new GCMDriverDesktop(
101 gcm_client_factory.Pass(),
102 GetChromeBuildInfo(),
103 GetChannelStatusRequestUrl(),
104 GetUserAgent(),
105 prefs,
106 store_path,
107 request_context,
108 content::BrowserThread::GetMessageLoopProxyForThread(
109 content::BrowserThread::UI),
110 content::BrowserThread::GetMessageLoopProxyForThread(
111 content::BrowserThread::IO),
112 blocking_task_runner));
113 }
114
115 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_desktop_utils.h ('k') | chrome/browser/services/gcm/gcm_profile_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698