| 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/common/gcm_desktop_util.h" | 5 #include "chrome/common/gcm_desktop_util.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "chrome/common/chrome_version_info.h" | 11 #include "chrome/common/channel_info.h" |
| 12 #include "chrome/common/sync_util.h" | 12 #include "chrome/common/sync_util.h" |
| 13 #include "components/gcm_driver/gcm_client.h" | 13 #include "components/gcm_driver/gcm_client.h" |
| 14 #include "components/gcm_driver/gcm_client_factory.h" | 14 #include "components/gcm_driver/gcm_client_factory.h" |
| 15 #include "components/gcm_driver/gcm_driver.h" | 15 #include "components/gcm_driver/gcm_driver.h" |
| 16 #include "components/gcm_driver/gcm_driver_desktop.h" | 16 #include "components/gcm_driver/gcm_driver_desktop.h" |
| 17 #include "components/version_info/version_info.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 namespace gcm { | 20 namespace gcm { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 const char kChannelStatusRelativePath[] = "/experimentstatus"; | 24 const char kChannelStatusRelativePath[] = "/experimentstatus"; |
| 24 | 25 |
| 25 GCMClient::ChromePlatform GetPlatform() { | 26 GCMClient::ChromePlatform GetPlatform() { |
| 26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 27 return GCMClient::PLATFORM_WIN; | 28 return GCMClient::PLATFORM_WIN; |
| 28 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
| 29 return GCMClient::PLATFORM_MAC; | 30 return GCMClient::PLATFORM_MAC; |
| 30 #elif defined(OS_IOS) | 31 #elif defined(OS_IOS) |
| 31 return GCMClient::PLATFORM_IOS; | 32 return GCMClient::PLATFORM_IOS; |
| 32 #elif defined(OS_ANDROID) | 33 #elif defined(OS_ANDROID) |
| 33 return GCMClient::PLATFORM_ANDROID; | 34 return GCMClient::PLATFORM_ANDROID; |
| 34 #elif defined(OS_CHROMEOS) | 35 #elif defined(OS_CHROMEOS) |
| 35 return GCMClient::PLATFORM_CROS; | 36 return GCMClient::PLATFORM_CROS; |
| 36 #elif defined(OS_LINUX) | 37 #elif defined(OS_LINUX) |
| 37 return GCMClient::PLATFORM_LINUX; | 38 return GCMClient::PLATFORM_LINUX; |
| 38 #else | 39 #else |
| 39 // For all other platforms, return as LINUX. | 40 // For all other platforms, return as LINUX. |
| 40 return GCMClient::PLATFORM_LINUX; | 41 return GCMClient::PLATFORM_LINUX; |
| 41 #endif | 42 #endif |
| 42 } | 43 } |
| 43 | 44 |
| 44 GCMClient::ChromeChannel GetChannel() { | 45 GCMClient::ChromeChannel GetChannel() { |
| 45 version_info::Channel channel = chrome::VersionInfo::GetChannel(); | 46 version_info::Channel channel = chrome::GetChannel(); |
| 46 switch (channel) { | 47 switch (channel) { |
| 47 case version_info::Channel::UNKNOWN: | 48 case version_info::Channel::UNKNOWN: |
| 48 return GCMClient::CHANNEL_UNKNOWN; | 49 return GCMClient::CHANNEL_UNKNOWN; |
| 49 case version_info::Channel::CANARY: | 50 case version_info::Channel::CANARY: |
| 50 return GCMClient::CHANNEL_CANARY; | 51 return GCMClient::CHANNEL_CANARY; |
| 51 case version_info::Channel::DEV: | 52 case version_info::Channel::DEV: |
| 52 return GCMClient::CHANNEL_DEV; | 53 return GCMClient::CHANNEL_DEV; |
| 53 case version_info::Channel::BETA: | 54 case version_info::Channel::BETA: |
| 54 return GCMClient::CHANNEL_BETA; | 55 return GCMClient::CHANNEL_BETA; |
| 55 case version_info::Channel::STABLE: | 56 case version_info::Channel::STABLE: |
| 56 return GCMClient::CHANNEL_STABLE; | 57 return GCMClient::CHANNEL_STABLE; |
| 57 default: | 58 default: |
| 58 NOTREACHED(); | 59 NOTREACHED(); |
| 59 return GCMClient::CHANNEL_UNKNOWN; | 60 return GCMClient::CHANNEL_UNKNOWN; |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 std::string GetVersion() { | 64 std::string GetVersion() { |
| 64 chrome::VersionInfo version_info; | 65 return version_info::GetVersionNumber(); |
| 65 return version_info.Version(); | |
| 66 } | 66 } |
| 67 | 67 |
| 68 GCMClient::ChromeBuildInfo GetChromeBuildInfo() { | 68 GCMClient::ChromeBuildInfo GetChromeBuildInfo() { |
| 69 GCMClient::ChromeBuildInfo chrome_build_info; | 69 GCMClient::ChromeBuildInfo chrome_build_info; |
| 70 chrome_build_info.platform = GetPlatform(); | 70 chrome_build_info.platform = GetPlatform(); |
| 71 chrome_build_info.channel = GetChannel(); | 71 chrome_build_info.channel = GetChannel(); |
| 72 chrome_build_info.version = GetVersion(); | 72 chrome_build_info.version = GetVersion(); |
| 73 return chrome_build_info; | 73 return chrome_build_info; |
| 74 } | 74 } |
| 75 | 75 |
| 76 std::string GetChannelStatusRequestUrl() { | 76 std::string GetChannelStatusRequestUrl() { |
| 77 GURL sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess())); | 77 GURL sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess())); |
| 78 return sync_url.spec() + kChannelStatusRelativePath; | 78 return sync_url.spec() + kChannelStatusRelativePath; |
| 79 } | 79 } |
| 80 | 80 |
| 81 std::string GetUserAgent() { | 81 std::string GetUserAgent() { |
| 82 chrome::VersionInfo version_info; | 82 return MakeDesktopUserAgentForSync(); |
| 83 return MakeDesktopUserAgentForSync(version_info); | |
| 84 } | 83 } |
| 85 | 84 |
| 86 } // namespace | 85 } // namespace |
| 87 | 86 |
| 88 scoped_ptr<GCMDriver> CreateGCMDriverDesktopWithTaskRunners( | 87 scoped_ptr<GCMDriver> CreateGCMDriverDesktopWithTaskRunners( |
| 89 scoped_ptr<GCMClientFactory> gcm_client_factory, | 88 scoped_ptr<GCMClientFactory> gcm_client_factory, |
| 90 PrefService* prefs, | 89 PrefService* prefs, |
| 91 const base::FilePath& store_path, | 90 const base::FilePath& store_path, |
| 92 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 91 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| 93 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 92 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
| 94 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 93 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
| 95 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) { | 94 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) { |
| 96 return scoped_ptr<GCMDriver>(new GCMDriverDesktop( | 95 return scoped_ptr<GCMDriver>(new GCMDriverDesktop( |
| 97 gcm_client_factory.Pass(), | 96 gcm_client_factory.Pass(), |
| 98 GetChromeBuildInfo(), | 97 GetChromeBuildInfo(), |
| 99 GetChannelStatusRequestUrl(), | 98 GetChannelStatusRequestUrl(), |
| 100 GetUserAgent(), | 99 GetUserAgent(), |
| 101 prefs, | 100 prefs, |
| 102 store_path, | 101 store_path, |
| 103 request_context, | 102 request_context, |
| 104 ui_thread, | 103 ui_thread, |
| 105 io_thread, | 104 io_thread, |
| 106 blocking_task_runner)); | 105 blocking_task_runner)); |
| 107 } | 106 } |
| 108 | 107 |
| 109 } // namespace gcm | 108 } // namespace gcm |
| OLD | NEW |