| 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 "chrome/common/gcm_desktop_util.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/sequenced_task_runner.h" | |
| 10 #include "base/threading/sequenced_worker_pool.h" | |
| 11 #include "chrome/common/channel_info.h" | |
| 12 #include "chrome/common/sync_util.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 "components/version_info/version_info.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 namespace gcm { | |
| 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 } // namespace | |
| 86 | |
| 87 scoped_ptr<GCMDriver> CreateGCMDriverDesktopWithTaskRunners( | |
| 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 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | |
| 93 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | |
| 94 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) { | |
| 95 return scoped_ptr<GCMDriver>(new GCMDriverDesktop( | |
| 96 gcm_client_factory.Pass(), | |
| 97 GetChromeBuildInfo(), | |
| 98 GetChannelStatusRequestUrl(), | |
| 99 GetUserAgent(), | |
| 100 prefs, | |
| 101 store_path, | |
| 102 request_context, | |
| 103 ui_thread, | |
| 104 io_thread, | |
| 105 blocking_task_runner)); | |
| 106 } | |
| 107 | |
| 108 } // namespace gcm | |
| OLD | NEW |