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