Componentizing chrome/browser/services/gcm/gcm_desktop_utils.cc.
Moved chrome/browser/services/gcm/gcm_desktop_utils.* to
components/gcm_driver/.
Added a extra param version_info to CreateGCMDriverDesktop()
for resolving the bad dependancy from chrome.
BUG=519579
Committed: https://crrev.com/ae5abc9a10333564b9e30c5fc1013f97e19ff4e0
Cr-Commit-Position: refs/heads/master@{#347128}
Review URL: https://codereview.chromium.org/1325063002
Cr-Commit-Position: refs/heads/master@{#350184}
diff --git a/components/gcm_driver/BUILD.gn b/components/gcm_driver/BUILD.gn
index e80ac0af..f3d42ee 100644
--- a/components/gcm_driver/BUILD.gn
+++ b/components/gcm_driver/BUILD.gn
@@ -33,6 +33,8 @@
"gcm_connection_observer.h",
"gcm_delayed_task_controller.cc",
"gcm_delayed_task_controller.h",
+ "gcm_desktop_utils.cc",
+ "gcm_desktop_utils.h",
"gcm_driver.cc",
"gcm_driver.h",
"gcm_driver_android.cc",
@@ -54,9 +56,11 @@
"//base",
"//components/gcm_driver/common",
"//components/os_crypt",
+ "//components/sync_driver",
"//google_apis/gcm",
"//net",
"//sync/protocol",
+ "//url:url",
]
if (is_chromeos) {
@@ -75,6 +79,8 @@
"gcm_client_factory.h",
"gcm_client_impl.cc",
"gcm_client_impl.h",
+ "gcm_desktop_utils.cc",
+ "gcm_desktop_utils.h",
"gcm_driver_desktop.cc",
"gcm_driver_desktop.h",
"gcm_stats_recorder_impl.cc",
diff --git a/components/gcm_driver/DEPS b/components/gcm_driver/DEPS
index cad5eddf..de2e4cc 100644
--- a/components/gcm_driver/DEPS
+++ b/components/gcm_driver/DEPS
@@ -1,7 +1,9 @@
include_rules = [
"+components/os_crypt",
"+components/pref_registry",
+ "+components/sync_driver",
"+components/timers", # Only used for Chrome OS builds.
+ "+components/version_info",
# TODO(johnme): Fix this layering violation.
"!content/public/android/java",
"+google_apis/gaia",
diff --git a/components/gcm_driver/gcm_desktop_utils.cc b/components/gcm_driver/gcm_desktop_utils.cc
new file mode 100644
index 0000000..f5049f5
--- /dev/null
+++ b/components/gcm_driver/gcm_desktop_utils.cc
@@ -0,0 +1,106 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/gcm_driver/gcm_desktop_utils.h"
+
+#include "base/command_line.h"
+#include "base/sequenced_task_runner.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "components/gcm_driver/gcm_client_factory.h"
+#include "components/gcm_driver/gcm_driver.h"
+#include "components/gcm_driver/gcm_driver_desktop.h"
+#include "components/sync_driver/sync_util.h"
+#include "url/gurl.h"
+
+namespace gcm {
+
+namespace {
+
+const char kChannelStatusRelativePath[] = "/experimentstatus";
+
+GCMClient::ChromePlatform GetPlatform() {
+#if defined(OS_WIN)
+ return GCMClient::PLATFORM_WIN;
+#elif defined(OS_MACOSX)
+ return GCMClient::PLATFORM_MAC;
+#elif defined(OS_IOS)
+ return GCMClient::PLATFORM_IOS;
+#elif defined(OS_ANDROID)
+ return GCMClient::PLATFORM_ANDROID;
+#elif defined(OS_CHROMEOS)
+ return GCMClient::PLATFORM_CROS;
+#elif defined(OS_LINUX)
+ return GCMClient::PLATFORM_LINUX;
+#else
+ // For all other platforms, return as LINUX.
+ return GCMClient::PLATFORM_LINUX;
+#endif
+}
+
+GCMClient::ChromeChannel GetChannel(version_info::Channel channel) {
+ switch (channel) {
+ case version_info::Channel::UNKNOWN:
+ return GCMClient::CHANNEL_UNKNOWN;
+ case version_info::Channel::CANARY:
+ return GCMClient::CHANNEL_CANARY;
+ case version_info::Channel::DEV:
+ return GCMClient::CHANNEL_DEV;
+ case version_info::Channel::BETA:
+ return GCMClient::CHANNEL_BETA;
+ case version_info::Channel::STABLE:
+ return GCMClient::CHANNEL_STABLE;
+ default:
+ NOTREACHED();
+ return GCMClient::CHANNEL_UNKNOWN;
+ }
+}
+
+std::string GetVersion() {
+ return version_info::GetVersionNumber();
+}
+
+GCMClient::ChromeBuildInfo GetChromeBuildInfo(version_info::Channel channel) {
+ GCMClient::ChromeBuildInfo chrome_build_info;
+ chrome_build_info.platform = GetPlatform();
+ chrome_build_info.channel = GetChannel(channel);
+ chrome_build_info.version = GetVersion();
+ return chrome_build_info;
+}
+
+std::string GetChannelStatusRequestUrl(version_info::Channel channel) {
+ GURL sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(),
+ channel));
+ return sync_url.spec() + kChannelStatusRelativePath;
+}
+
+std::string GetUserAgent(version_info::Channel channel) {
+ return MakeDesktopUserAgentForSync(channel);
+}
+
+} // namespace
+
+scoped_ptr<GCMDriver> CreateGCMDriverDesktop(
+ scoped_ptr<GCMClientFactory> gcm_client_factory,
+ PrefService* prefs,
+ const base::FilePath& store_path,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context,
+ version_info::Channel channel,
+ const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
+ const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) {
+
+ return scoped_ptr<GCMDriver>(new GCMDriverDesktop(
+ gcm_client_factory.Pass(),
+ GetChromeBuildInfo(channel),
+ GetChannelStatusRequestUrl(channel),
+ GetUserAgent(channel),
+ prefs,
+ store_path,
+ request_context,
+ ui_task_runner,
+ io_task_runner,
+ blocking_task_runner));
+}
+
+} // namespace gcm
diff --git a/components/gcm_driver/gcm_desktop_utils.h b/components/gcm_driver/gcm_desktop_utils.h
new file mode 100644
index 0000000..b7e62e40
--- /dev/null
+++ b/components/gcm_driver/gcm_desktop_utils.h
@@ -0,0 +1,39 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_GCM_DRIVER_GCM_GCM_DESKTOP_UTILS_H_
+#define COMPONENTS_GCM_DRIVER_GCM_GCM_DESKTOP_UTILS_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/sequenced_task_runner.h"
+#include "components/version_info/version_info.h"
+
+class PrefService;
+namespace base {
+class FilePath;
+}
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+namespace gcm {
+
+class GCMDriver;
+class GCMClientFactory;
+
+scoped_ptr<GCMDriver> CreateGCMDriverDesktop(
+ scoped_ptr<GCMClientFactory> gcm_client_factory,
+ PrefService* prefs,
+ const base::FilePath& store_path,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context,
+ version_info::Channel channel,
+ const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
+ const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
+
+} // namespace gcm
+
+#endif // COMPONENTS_GCM_DRIVER_GCM_GCM_DESKTOP_UTILS_H_