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/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index ab85392..093afcbe 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -111,8 +111,8 @@
#if !defined(OS_ANDROID)
#include "chrome/browser/chrome_device_client.h"
-#include "chrome/browser/services/gcm/gcm_desktop_utils.h"
#include "components/gcm_driver/gcm_client_factory.h"
+#include "components/gcm_driver/gcm_desktop_utils.h"
#endif
#if defined(ENABLE_BACKGROUND)
@@ -1172,11 +1172,24 @@
#else
base::FilePath store_path;
CHECK(PathService::Get(chrome::DIR_GLOBAL_GCM_STORE, &store_path));
+ base::SequencedWorkerPool* worker_pool =
+ content::BrowserThread::GetBlockingPool();
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
+ worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
+ worker_pool->GetSequenceToken(),
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
+
gcm_driver_ = gcm::CreateGCMDriverDesktop(
make_scoped_ptr(new gcm::GCMClientFactory),
local_state(),
store_path,
- system_request_context());
+ system_request_context(),
+ chrome::GetChannel(),
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::UI),
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::IO),
+ blocking_task_runner);
#endif // defined(OS_ANDROID)
}
diff --git a/chrome/browser/services/gcm/gcm_desktop_utils.h b/chrome/browser/services/gcm/gcm_desktop_utils.h
deleted file mode 100644
index 8105829d..0000000
--- a/chrome/browser/services/gcm/gcm_desktop_utils.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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 CHROME_BROWSER_SERVICES_GCM_GCM_DESKTOP_UTILS_H_
-#define CHROME_BROWSER_SERVICES_GCM_GCM_DESKTOP_UTILS_H_
-
-#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.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);
-
-} // namespace gcm
-
-#endif // CHROME_BROWSER_SERVICES_GCM_GCM_DESKTOP_UTILS_H_
diff --git a/chrome/browser/services/gcm/gcm_profile_service.cc b/chrome/browser/services/gcm/gcm_profile_service.cc
index 69399d9..50d2de2b 100644
--- a/chrome/browser/services/gcm/gcm_profile_service.cc
+++ b/chrome/browser/services/gcm/gcm_profile_service.cc
@@ -22,16 +22,18 @@
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
-#include "chrome/browser/services/gcm/gcm_desktop_utils.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
+#include "chrome/common/channel_info.h"
#include "components/gcm_driver/gcm_account_tracker.h"
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#include "components/gcm_driver/gcm_client_factory.h"
+#include "components/gcm_driver/gcm_desktop_utils.h"
#include "components/gcm_driver/gcm_driver_desktop.h"
#include "components/signin/core/browser/profile_identity_provider.h"
#include "components/signin/core/browser/signin_manager.h"
+#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/account_tracker.h"
#include "google_apis/gaia/identity_provider.h"
#include "net/url_request/url_request_context_getter.h"
@@ -174,11 +176,24 @@
: profile_(profile) {
DCHECK(!profile->IsOffTheRecord());
+ base::SequencedWorkerPool* worker_pool =
+ content::BrowserThread::GetBlockingPool();
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
+ worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
+ worker_pool->GetSequenceToken(),
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
+
driver_ = CreateGCMDriverDesktop(
gcm_client_factory.Pass(),
profile_->GetPrefs(),
profile_->GetPath().Append(chrome::kGCMStoreDirname),
- profile_->GetRequestContext());
+ profile_->GetRequestContext(),
+ chrome::GetChannel(),
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::UI),
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::IO),
+ blocking_task_runner);
identity_observer_.reset(new IdentityObserver(profile, driver_.get()));
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index d4b2798..072c07d0 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1253,8 +1253,6 @@
'browser/search/local_ntp_source.h',
'browser/search/search_terms_tracker.cc',
'browser/search/search_terms_tracker.h',
- 'browser/services/gcm/gcm_desktop_utils.cc',
- 'browser/services/gcm/gcm_desktop_utils.h',
'browser/signin/signin_promo.cc',
'browser/signin/signin_promo.h',
'browser/signin/signin_ui_util.cc',
diff --git a/components/gcm_driver.gypi b/components/gcm_driver.gypi
index 197c15ea..1090e69 100644
--- a/components/gcm_driver.gypi
+++ b/components/gcm_driver.gypi
@@ -29,10 +29,12 @@
'gcm_driver_common',
'gcm_driver_crypto',
'os_crypt',
+ 'sync_driver',
'../base/base.gyp:base',
'../google_apis/gcm/gcm.gyp:gcm',
'../net/net.gyp:net',
'../sync/sync.gyp:sync_proto',
+ '../url/url.gyp:url_lib',
],
'include_dirs': [
'..',
@@ -67,6 +69,8 @@
'gcm_driver/gcm_connection_observer.h',
'gcm_driver/gcm_delayed_task_controller.cc',
'gcm_driver/gcm_delayed_task_controller.h',
+ 'gcm_driver/gcm_desktop_utils.cc',
+ 'gcm_driver/gcm_desktop_utils.h',
'gcm_driver/gcm_driver.cc',
'gcm_driver/gcm_driver.h',
'gcm_driver/gcm_driver_android.cc',
@@ -101,6 +105,8 @@
'gcm_driver/gcm_client_factory.h',
'gcm_driver/gcm_client_impl.cc',
'gcm_driver/gcm_client_impl.h',
+ 'gcm_driver/gcm_desktop_utils.cc',
+ 'gcm_driver/gcm_desktop_utils.h',
'gcm_driver/gcm_driver_desktop.cc',
'gcm_driver/gcm_driver_desktop.h',
'gcm_driver/gcm_stats_recorder_impl.cc',
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/chrome/browser/services/gcm/gcm_desktop_utils.cc b/components/gcm_driver/gcm_desktop_utils.cc
similarity index 66%
rename from chrome/browser/services/gcm/gcm_desktop_utils.cc
rename to components/gcm_driver/gcm_desktop_utils.cc
index 206d875a..f5049f5 100644
--- a/chrome/browser/services/gcm/gcm_desktop_utils.cc
+++ b/components/gcm_driver/gcm_desktop_utils.cc
@@ -2,18 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/services/gcm/gcm_desktop_utils.h"
+#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 "chrome/common/channel_info.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 "components/version_info/version_info.h"
-#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
namespace gcm {
@@ -41,8 +38,7 @@
#endif
}
-GCMClient::ChromeChannel GetChannel() {
- version_info::Channel channel = chrome::GetChannel();
+GCMClient::ChromeChannel GetChannel(version_info::Channel channel) {
switch (channel) {
case version_info::Channel::UNKNOWN:
return GCMClient::CHANNEL_UNKNOWN;
@@ -64,22 +60,22 @@
return version_info::GetVersionNumber();
}
-GCMClient::ChromeBuildInfo GetChromeBuildInfo() {
+GCMClient::ChromeBuildInfo GetChromeBuildInfo(version_info::Channel channel) {
GCMClient::ChromeBuildInfo chrome_build_info;
chrome_build_info.platform = GetPlatform();
- chrome_build_info.channel = GetChannel();
+ chrome_build_info.channel = GetChannel(channel);
chrome_build_info.version = GetVersion();
return chrome_build_info;
}
-std::string GetChannelStatusRequestUrl() {
+std::string GetChannelStatusRequestUrl(version_info::Channel channel) {
GURL sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(),
- chrome::GetChannel()));
+ channel));
return sync_url.spec() + kChannelStatusRelativePath;
}
-std::string GetUserAgent() {
- return MakeDesktopUserAgentForSync(chrome::GetChannel());
+std::string GetUserAgent(version_info::Channel channel) {
+ return MakeDesktopUserAgentForSync(channel);
}
} // namespace
@@ -88,27 +84,22 @@
scoped_ptr<GCMClientFactory> gcm_client_factory,
PrefService* prefs,
const base::FilePath& store_path,
- const scoped_refptr<net::URLRequestContextGetter>& request_context) {
-
- scoped_refptr<base::SequencedWorkerPool> worker_pool(
- content::BrowserThread::GetBlockingPool());
- scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
- worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
- worker_pool->GetSequenceToken(),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
+ 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(),
- GetChannelStatusRequestUrl(),
- GetUserAgent(),
+ GetChromeBuildInfo(channel),
+ GetChannelStatusRequestUrl(channel),
+ GetUserAgent(channel),
prefs,
store_path,
request_context,
- content::BrowserThread::GetMessageLoopProxyForThread(
- content::BrowserThread::UI),
- content::BrowserThread::GetMessageLoopProxyForThread(
- content::BrowserThread::IO),
+ ui_task_runner,
+ io_task_runner,
blocking_task_runner));
}
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_