OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/services/gcm/gcm_desktop_utils.h" | 5 #include "chrome/browser/services/gcm/gcm_desktop_utils.h" |
6 | 6 |
7 #include "base/command_line.h" | |
7 #include "base/sequenced_task_runner.h" | 8 #include "base/sequenced_task_runner.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
9 #include "chrome/common/gcm_desktop_util.h" | 10 #include "chrome/browser/services/gcm/gcm_desktop_utils.h" |
11 #include "chrome/common/channel_info.h" | |
12 #include "chrome/common/sync_util.h" | |
10 #include "components/gcm_driver/gcm_client_factory.h" | 13 #include "components/gcm_driver/gcm_client_factory.h" |
11 #include "components/gcm_driver/gcm_driver.h" | 14 #include "components/gcm_driver/gcm_driver.h" |
15 #include "components/gcm_driver/gcm_driver_desktop.h" | |
16 #include "components/version_info/version_info.h" | |
12 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "url/gurl.h" | |
13 | 19 |
14 namespace gcm { | 20 namespace gcm { |
15 | 21 |
22 namespace { | |
23 | |
24 const char kChannelStatusRelativePath[] = "/experimentstatus"; | |
25 | |
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 | |
43 } | |
44 | |
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; | |
61 } | |
62 } | |
63 | |
64 std::string GetVersion() { | |
65 return version_info::GetVersionNumber(); | |
66 } | |
67 | |
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; | |
74 } | |
75 | |
76 std::string GetChannelStatusRequestUrl() { | |
77 GURL sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess())); | |
78 return sync_url.spec() + kChannelStatusRelativePath; | |
79 } | |
80 | |
81 std::string GetUserAgent() { | |
82 return MakeDesktopUserAgentForSync(); | |
83 } | |
84 | |
85 scoped_ptr<GCMDriver> CreateGCMDriverDesktopWithTaskRunners( | |
Nicolas Zea
2015/08/19 16:56:14
nit: Considering this is only used in one place an
Jitu( very slow this week)
2015/08/20 13:47:41
Done.
| |
86 scoped_ptr<GCMClientFactory> gcm_client_factory, | |
87 PrefService* prefs, | |
88 const base::FilePath& store_path, | |
89 const scoped_refptr<net::URLRequestContextGetter>& request_context, | |
90 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | |
91 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | |
92 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) { | |
93 return scoped_ptr<GCMDriver>(new GCMDriverDesktop( | |
94 gcm_client_factory.Pass(), GetChromeBuildInfo(), | |
95 GetChannelStatusRequestUrl(), GetUserAgent(), prefs, store_path, | |
96 request_context, ui_thread, io_thread, blocking_task_runner)); | |
97 } | |
98 | |
99 } // namespace | |
100 | |
16 scoped_ptr<GCMDriver> CreateGCMDriverDesktop( | 101 scoped_ptr<GCMDriver> CreateGCMDriverDesktop( |
17 scoped_ptr<GCMClientFactory> gcm_client_factory, | 102 scoped_ptr<GCMClientFactory> gcm_client_factory, |
18 PrefService* prefs, | 103 PrefService* prefs, |
19 const base::FilePath& store_path, | 104 const base::FilePath& store_path, |
20 const scoped_refptr<net::URLRequestContextGetter>& request_context) { | 105 const scoped_refptr<net::URLRequestContextGetter>& request_context) { |
21 | 106 |
22 scoped_refptr<base::SequencedWorkerPool> worker_pool( | 107 scoped_refptr<base::SequencedWorkerPool> worker_pool( |
23 content::BrowserThread::GetBlockingPool()); | 108 content::BrowserThread::GetBlockingPool()); |
24 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( | 109 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( |
25 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 110 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
26 worker_pool->GetSequenceToken(), | 111 worker_pool->GetSequenceToken(), |
27 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 112 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
28 | 113 |
29 return CreateGCMDriverDesktopWithTaskRunners( | 114 return CreateGCMDriverDesktopWithTaskRunners( |
30 gcm_client_factory.Pass(), | 115 gcm_client_factory.Pass(), |
31 prefs, | 116 prefs, |
32 store_path, | 117 store_path, |
33 request_context, | 118 request_context, |
34 content::BrowserThread::GetMessageLoopProxyForThread( | 119 content::BrowserThread::GetMessageLoopProxyForThread( |
35 content::BrowserThread::UI), | 120 content::BrowserThread::UI), |
36 content::BrowserThread::GetMessageLoopProxyForThread( | 121 content::BrowserThread::GetMessageLoopProxyForThread( |
37 content::BrowserThread::IO), | 122 content::BrowserThread::IO), |
38 blocking_task_runner); | 123 blocking_task_runner); |
39 } | 124 } |
40 | 125 |
41 } // namespace gcm | 126 } // namespace gcm |
OLD | NEW |