diff options
42 files changed, 364 insertions, 167 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 86d6aba..e764055 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -23,6 +23,7 @@ include_rules = [ "+components/domain_reliability", "+components/favicon_base", "+components/feedback", + "+components/gcm_driver", "+components/google", "+components/infobars", "+components/keyed_service", diff --git a/chrome/browser/extensions/api/gcm/gcm_apitest.cc b/chrome/browser/extensions/api/gcm/gcm_apitest.cc index b93060a..70212ab 100644 --- a/chrome/browser/extensions/api/gcm/gcm_apitest.cc +++ b/chrome/browser/extensions/api/gcm/gcm_apitest.cc @@ -9,11 +9,11 @@ #include "chrome/browser/extensions/extension_gcm_app_handler.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" -#include "chrome/browser/services/gcm/gcm_client_factory.h" #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/ui_test_utils.h" +#include "components/gcm_driver/gcm_client_factory.h" namespace { diff --git a/chrome/browser/extensions/extension_gcm_app_handler.h b/chrome/browser/extensions/extension_gcm_app_handler.h index 9a7298d..7b1f0da 100644 --- a/chrome/browser/extensions/extension_gcm_app_handler.h +++ b/chrome/browser/extensions/extension_gcm_app_handler.h @@ -12,7 +12,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/scoped_observer.h" -#include "chrome/browser/services/gcm/gcm_app_handler.h" +#include "components/gcm_driver/gcm_app_handler.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "extensions/browser/browser_context_keyed_api_factory.h" diff --git a/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc b/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc index 8e9f3cc..eaa72b1 100644 --- a/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc +++ b/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc @@ -22,13 +22,13 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/services/gcm/fake_gcm_client_factory.h" #include "chrome/browser/services/gcm/fake_signin_manager.h" -#include "chrome/browser/services/gcm/gcm_client_factory.h" #include "chrome/browser/services/gcm/gcm_client_mock.h" #include "chrome/browser/services/gcm/gcm_profile_service.h" #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" +#include "components/gcm_driver/gcm_client_factory.h" #include "components/keyed_service/core/keyed_service.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" diff --git a/chrome/browser/invalidation/gcm_invalidation_bridge.h b/chrome/browser/invalidation/gcm_invalidation_bridge.h index a9d781e..b88449f 100644 --- a/chrome/browser/invalidation/gcm_invalidation_bridge.h +++ b/chrome/browser/invalidation/gcm_invalidation_bridge.h @@ -9,7 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/threading/non_thread_safe.h" -#include "chrome/browser/services/gcm/gcm_app_handler.h" +#include "components/gcm_driver/gcm_app_handler.h" #include "google_apis/gaia/oauth2_token_service.h" #include "google_apis/gcm/gcm_client.h" #include "sync/notifier/gcm_network_channel_delegate.h" diff --git a/chrome/browser/services/gcm/fake_gcm_client_factory.h b/chrome/browser/services/gcm/fake_gcm_client_factory.h index 11fdf65..9a9c311 100644 --- a/chrome/browser/services/gcm/fake_gcm_client_factory.h +++ b/chrome/browser/services/gcm/fake_gcm_client_factory.h @@ -7,8 +7,8 @@ #include "base/compiler_specific.h" #include "base/macros.h" -#include "chrome/browser/services/gcm/gcm_client_factory.h" #include "chrome/browser/services/gcm/gcm_client_mock.h" +#include "components/gcm_driver/gcm_client_factory.h" namespace gcm { diff --git a/chrome/browser/services/gcm/gcm_app_handler.h b/chrome/browser/services/gcm/gcm_app_handler.h index e53a25b..6777c68 100644 --- a/chrome/browser/services/gcm/gcm_app_handler.h +++ b/chrome/browser/services/gcm/gcm_app_handler.h @@ -1,42 +1,12 @@ -// 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_APP_HANDLER_H_ -#define CHROME_BROWSER_SERVICES_GCM_GCM_APP_HANDLER_H_ - -#include <string> - -#include "base/basictypes.h" -#include "google_apis/gcm/gcm_client.h" - -namespace gcm { - -// Defines the interface to provide handling and event routing logic for a given -// app. -class GCMAppHandler { - public: - GCMAppHandler() {} - virtual ~GCMAppHandler() {} - - // Called to do all the cleanup when GCM is shutting down. - // In the case that multiple apps share the same app handler, it should be - // make safe for ShutdownHandler to be called multiple times. - virtual void ShutdownHandler() = 0; - - // Called when a GCM message has been received. - virtual void OnMessage(const std::string& app_id, - const GCMClient::IncomingMessage& message) = 0; - - // Called when some GCM messages have been deleted from the server. - virtual void OnMessagesDeleted(const std::string& app_id) = 0; - - // Called when a GCM message failed to be delivered. - virtual void OnSendError( - const std::string& app_id, - const GCMClient::SendErrorDetails& send_error_details) = 0; -}; - -} // namespace gcm - -#endif // CHROME_BROWSER_SERVICES_GCM_GCM_APP_HANDLER_H_ +// Copyright (c) 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_APP_HANDLER_H_
+#define CHROME_BROWSER_SERVICES_GCM_GCM_APP_HANDLER_H_
+
+// Temporary workaround to make code depends on gcm_app_handler in old location
+// build.
+#include "components/gcm_driver/gcm_app_handler.h"
+
+#endif // CHROME_BROWSER_SERVICES_GCM_GCM_APP_HANDLER_H_
diff --git a/chrome/browser/services/gcm/gcm_client_mock.cc b/chrome/browser/services/gcm/gcm_client_mock.cc index 96c8ffe..5ed3d90 100644 --- a/chrome/browser/services/gcm/gcm_client_mock.cc +++ b/chrome/browser/services/gcm/gcm_client_mock.cc @@ -10,6 +10,7 @@ #include "base/sys_byteorder.h" #include "base/time/time.h" #include "content/public/browser/browser_thread.h" +#include "google_apis/gcm/base/encryptor.h" namespace gcm { @@ -30,6 +31,7 @@ void GCMClientMock::Initialize( const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, const scoped_refptr<net::URLRequestContextGetter>& url_request_context_getter, + scoped_ptr<Encryptor> encryptor, Delegate* delegate) { delegate_ = delegate; } diff --git a/chrome/browser/services/gcm/gcm_client_mock.h b/chrome/browser/services/gcm/gcm_client_mock.h index b6e8dd9..a878a88 100644 --- a/chrome/browser/services/gcm/gcm_client_mock.h +++ b/chrome/browser/services/gcm/gcm_client_mock.h @@ -37,6 +37,7 @@ class GCMClientMock : public GCMClient { const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, const scoped_refptr<net::URLRequestContextGetter>& url_request_context_getter, + scoped_ptr<Encryptor> encryptor, Delegate* delegate) OVERRIDE; virtual void Start() OVERRIDE; virtual void Stop() OVERRIDE; diff --git a/chrome/browser/services/gcm/gcm_profile_service_factory.cc b/chrome/browser/services/gcm/gcm_profile_service_factory.cc index 437fa5f..2e380b1 100644 --- a/chrome/browser/services/gcm/gcm_profile_service_factory.cc +++ b/chrome/browser/services/gcm/gcm_profile_service_factory.cc @@ -7,10 +7,10 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/services/gcm/gcm_client_factory.h" #include "chrome/browser/services/gcm/gcm_profile_service.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" +#include "components/gcm_driver/gcm_client_factory.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" #if !defined(OS_ANDROID) diff --git a/chrome/browser/services/gcm/gcm_profile_service_factory.h b/chrome/browser/services/gcm/gcm_profile_service_factory.h index 2e5763e..83ea9cb 100644 --- a/chrome/browser/services/gcm/gcm_profile_service_factory.h +++ b/chrome/browser/services/gcm/gcm_profile_service_factory.h @@ -7,6 +7,7 @@ #include "base/compiler_specific.h" #include "base/memory/singleton.h" +#include "components/gcm_driver/system_encryptor.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h" class Profile; diff --git a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc b/chrome/browser/services/gcm/gcm_profile_service_unittest.cc index 6ac3ceb..df67388 100644 --- a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc +++ b/chrome/browser/services/gcm/gcm_profile_service_unittest.cc @@ -13,11 +13,11 @@ #include "base/run_loop.h" #include "chrome/browser/services/gcm/fake_gcm_client_factory.h" #include "chrome/browser/services/gcm/fake_signin_manager.h" -#include "chrome/browser/services/gcm/gcm_client_factory.h" #include "chrome/browser/services/gcm/gcm_client_mock.h" #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/test/base/testing_profile.h" +#include "components/gcm_driver/gcm_client_factory.h" #include "components/user_prefs/pref_registry_syncable.h" #include "content/public/browser/browser_context.h" #include "content/public/test/test_browser_thread_bundle.h" diff --git a/chrome/browser/services/gcm/gcm_service.cc b/chrome/browser/services/gcm/gcm_service.cc index 4a33e0c..a8e6227 100644 --- a/chrome/browser/services/gcm/gcm_service.cc +++ b/chrome/browser/services/gcm/gcm_service.cc @@ -13,9 +13,10 @@ #include "base/logging.h" #include "base/sequenced_task_runner.h" #include "base/threading/sequenced_worker_pool.h" -#include "chrome/browser/services/gcm/gcm_app_handler.h" -#include "chrome/browser/services/gcm/gcm_client_factory.h" #include "chrome/common/chrome_version_info.h" +#include "components/gcm_driver/gcm_app_handler.h" +#include "components/gcm_driver/gcm_client_factory.h" +#include "components/gcm_driver/system_encryptor.h" #include "content/public/browser/browser_thread.h" #include "google_apis/gaia/oauth2_token_service.h" #include "google_apis/gcm/protocol/android_checkin.pb.h" @@ -193,7 +194,7 @@ void GCMService::IOWorker::Initialize( url_request_context_getter) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - gcm_client_ = gcm_client_factory->BuildInstance().Pass(); + gcm_client_ = gcm_client_factory->BuildInstance(); checkin_proto::ChromeBuildProto chrome_build_proto; chrome_build_proto.set_platform(GetPlatform()); @@ -212,6 +213,7 @@ void GCMService::IOWorker::Initialize( account_ids, blocking_task_runner, url_request_context_getter, + make_scoped_ptr<Encryptor>(new SystemEncryptor), this); } diff --git a/chrome/browser/services/gcm/gcm_service.h b/chrome/browser/services/gcm/gcm_service.h index afa9dbe..02fe433 100644 --- a/chrome/browser/services/gcm/gcm_service.h +++ b/chrome/browser/services/gcm/gcm_service.h @@ -16,7 +16,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "chrome/browser/services/gcm/default_gcm_app_handler.h" +#include "components/gcm_driver/default_gcm_app_handler.h" #include "google_apis/gaia/identity_provider.h" #include "google_apis/gcm/gcm_client.h" diff --git a/chrome/browser/services/gcm/gcm_service_unittest.cc b/chrome/browser/services/gcm/gcm_service_unittest.cc index 9de63d3..575e11c 100644 --- a/chrome/browser/services/gcm/gcm_service_unittest.cc +++ b/chrome/browser/services/gcm/gcm_service_unittest.cc @@ -12,13 +12,14 @@ #include "base/run_loop.h" #include "base/strings/string_util.h" #include "chrome/browser/services/gcm/fake_gcm_client_factory.h" -#include "chrome/browser/services/gcm/gcm_app_handler.h" -#include "chrome/browser/services/gcm/gcm_client_factory.h" #include "chrome/browser/services/gcm/gcm_client_mock.h" +#include "components/gcm_driver/gcm_app_handler.h" +#include "components/gcm_driver/gcm_client_factory.h" #include "content/public/browser/browser_thread.h" #include "content/public/test/test_browser_thread_bundle.h" #include "google_apis/gaia/fake_identity_provider.h" #include "google_apis/gaia/fake_oauth2_token_service.h" +#include "google_apis/gcm/base/fake_encryptor.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index e4381da..cf6d7da 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -37,6 +37,7 @@ '../components/components.gyp:favicon_base', '../components/components.gyp:favicon_core', '../components/components.gyp:feedback_component', + '../components/components.gyp:gcm_driver', '../components/components.gyp:google_core_browser', '../components/components.gyp:infobars_core', '../components/components.gyp:invalidation', @@ -66,7 +67,6 @@ '../content/content.gyp:content_common', '../courgette/courgette.gyp:courgette_lib', '../crypto/crypto.gyp:crypto', - '../google_apis/gcm/gcm.gyp:gcm', '../google_apis/google_apis.gyp:google_apis', '../jingle/jingle.gyp:notifier', '../skia/skia.gyp:skia', @@ -1986,11 +1986,6 @@ 'browser/search_engines/template_url_service_observer.h', 'browser/search_engines/util.cc', 'browser/search_engines/util.h', - 'browser/services/gcm/default_gcm_app_handler.cc', - 'browser/services/gcm/default_gcm_app_handler.h', - 'browser/services/gcm/gcm_app_handler.h', - 'browser/services/gcm/gcm_client_factory.cc', - 'browser/services/gcm/gcm_client_factory.h', 'browser/services/gcm/gcm_profile_service.cc', 'browser/services/gcm/gcm_profile_service.h', 'browser/services/gcm/gcm_profile_service_factory.cc', diff --git a/components/OWNERS b/components/OWNERS index 562d1fb..9d38f8a 100644 --- a/components/OWNERS +++ b/components/OWNERS @@ -43,6 +43,11 @@ per-file favicon*=blundell@chromium.org # Temporary for the duration of the favicon componentization. per-file favicon*=droger@chromium.org +per-file gcm*=dimich@chromium.org +per-file gcm*=jianli@chromium.org +per-file gcm*=fgorski@chromium.org +per-file gcm*=zea@chromium.org + per-file google*=isherman@chromium.org per-file google*=pkasting@chromium.org diff --git a/components/components.gyp b/components/components.gyp index 1242b78..7d57704 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -74,6 +74,7 @@ # Android WebView fails to build if a dependency on these targets is # introduced. 'includes': [ + 'gcm_driver.gypi', 'sync_driver.gypi', 'invalidation.gypi', ], diff --git a/components/gcm_driver.gypi b/components/gcm_driver.gypi new file mode 100644 index 0000000..489a710 --- /dev/null +++ b/components/gcm_driver.gypi @@ -0,0 +1,29 @@ +# 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. + +{ + 'targets': [ + { + 'target_name': 'gcm_driver', + 'type': 'static_library', + 'dependencies': [ + '../base/base.gyp:base', + '../google_apis/gcm/gcm.gyp:gcm', + 'os_crypt', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'gcm_driver/default_gcm_app_handler.cc', + 'gcm_driver/default_gcm_app_handler.h', + 'gcm_driver/gcm_app_handler.h', + 'gcm_driver/gcm_client_factory.cc', + 'gcm_driver/gcm_client_factory.h', + 'gcm_driver/system_encryptor.cc', + 'gcm_driver/system_encryptor.h', + ], + }, + ], +} diff --git a/components/gcm_driver/DEPS b/components/gcm_driver/DEPS new file mode 100644 index 0000000..b69f312 --- /dev/null +++ b/components/gcm_driver/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+components/os_crypt", + "+google_apis/gcm", +] diff --git a/components/gcm_driver/OWNERS b/components/gcm_driver/OWNERS new file mode 100644 index 0000000..0f8cc7a --- /dev/null +++ b/components/gcm_driver/OWNERS @@ -0,0 +1,4 @@ +dimich@chromium.org +fgorski@chromium.org +jianli@chromium.org +zea@chromium.org diff --git a/chrome/browser/services/gcm/default_gcm_app_handler.cc b/components/gcm_driver/default_gcm_app_handler.cc index 7b14409..80aee2f 100644 --- a/chrome/browser/services/gcm/default_gcm_app_handler.cc +++ b/components/gcm_driver/default_gcm_app_handler.cc @@ -1,8 +1,8 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright (c) 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 "chrome/browser/services/gcm/default_gcm_app_handler.h" +#include "components/gcm_driver/default_gcm_app_handler.h" #include "base/logging.h" diff --git a/chrome/browser/services/gcm/default_gcm_app_handler.h b/components/gcm_driver/default_gcm_app_handler.h index dcec5598..0f6c4ce 100644 --- a/chrome/browser/services/gcm/default_gcm_app_handler.h +++ b/components/gcm_driver/default_gcm_app_handler.h @@ -1,35 +1,35 @@ -// 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_DEFAULT_GCM_APP_HANDLER_H_ -#define CHROME_BROWSER_SERVICES_GCM_DEFAULT_GCM_APP_HANDLER_H_ - -#include "base/compiler_specific.h" -#include "chrome/browser/services/gcm/gcm_app_handler.h" - -namespace gcm { - -// The default app handler that is triggered when there is no registered app -// handler for an application id. -class DefaultGCMAppHandler : public GCMAppHandler { - public: - DefaultGCMAppHandler(); - virtual ~DefaultGCMAppHandler(); - - // Overridden from GCMAppHandler: - virtual void ShutdownHandler() OVERRIDE; - virtual void OnMessage(const std::string& app_id, - const GCMClient::IncomingMessage& message) OVERRIDE; - virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; - virtual void OnSendError( - const std::string& app_id, - const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(DefaultGCMAppHandler); -}; - -} // namespace gcm - -#endif // CHROME_BROWSER_SERVICES_GCM_DEFAULT_GCM_APP_HANDLER_H_ +// Copyright (c) 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_DEFAULT_GCM_APP_HANDLER_H_
+#define COMPONENTS_GCM_DRIVER_DEFAULT_GCM_APP_HANDLER_H_
+
+#include "base/compiler_specific.h"
+#include "components/gcm_driver/gcm_app_handler.h"
+
+namespace gcm {
+
+// The default app handler that is triggered when there is no registered app
+// handler for an application id.
+class DefaultGCMAppHandler : public GCMAppHandler {
+ public:
+ DefaultGCMAppHandler();
+ virtual ~DefaultGCMAppHandler();
+
+ // Overridden from GCMAppHandler:
+ virtual void ShutdownHandler() OVERRIDE;
+ virtual void OnMessage(const std::string& app_id,
+ const GCMClient::IncomingMessage& message) OVERRIDE;
+ virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
+ virtual void OnSendError(
+ const std::string& app_id,
+ const GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DefaultGCMAppHandler);
+};
+
+} // namespace gcm
+
+#endif // COMPONENTS_GCM_DRIVER_DEFAULT_GCM_APP_HANDLER_H_
diff --git a/components/gcm_driver/gcm_app_handler.h b/components/gcm_driver/gcm_app_handler.h new file mode 100644 index 0000000..f1487a7 --- /dev/null +++ b/components/gcm_driver/gcm_app_handler.h @@ -0,0 +1,42 @@ +// Copyright (c) 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_APP_HANDLER_H_
+#define COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "google_apis/gcm/gcm_client.h"
+
+namespace gcm {
+
+// Defines the interface to provide handling and event routing logic for a given
+// app.
+class GCMAppHandler {
+ public:
+ GCMAppHandler() {}
+ virtual ~GCMAppHandler() {}
+
+ // Called to do all the cleanup when GCM is shutting down.
+ // In the case that multiple apps share the same app handler, it should be
+ // make safe for ShutdownHandler to be called multiple times.
+ virtual void ShutdownHandler() = 0;
+
+ // Called when a GCM message has been received.
+ virtual void OnMessage(const std::string& app_id,
+ const GCMClient::IncomingMessage& message) = 0;
+
+ // Called when some GCM messages have been deleted from the server.
+ virtual void OnMessagesDeleted(const std::string& app_id) = 0;
+
+ // Called when a GCM message failed to be delivered.
+ virtual void OnSendError(
+ const std::string& app_id,
+ const GCMClient::SendErrorDetails& send_error_details) = 0;
+};
+
+} // namespace gcm
+
+#endif // COMPONENTS_GCM_DRIVER_GCM_APP_HANDLER_H_
diff --git a/chrome/browser/services/gcm/gcm_client_factory.cc b/components/gcm_driver/gcm_client_factory.cc index 053b01c..64d7d5c 100644 --- a/chrome/browser/services/gcm/gcm_client_factory.cc +++ b/components/gcm_driver/gcm_client_factory.cc @@ -1,8 +1,8 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright (c) 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 "chrome/browser/services/gcm/gcm_client_factory.h" +#include "components/gcm_driver/gcm_client_factory.h" #include "google_apis/gcm/gcm_client_impl.h" diff --git a/chrome/browser/services/gcm/gcm_client_factory.h b/components/gcm_driver/gcm_client_factory.h index 9112399..78c43f4 100644 --- a/chrome/browser/services/gcm/gcm_client_factory.h +++ b/components/gcm_driver/gcm_client_factory.h @@ -1,30 +1,30 @@ -// 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_CLIENT_FACTORY_H_ -#define CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_FACTORY_H_ - -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" - -namespace gcm { - -class GCMClient; - -class GCMClientFactory { - public: - GCMClientFactory(); - virtual ~GCMClientFactory(); - - // Creates a new instance of GCMClient. The testing code could override this - // to provide a mocked instance. - virtual scoped_ptr<GCMClient> BuildInstance(); - - private: - DISALLOW_COPY_AND_ASSIGN(GCMClientFactory); -}; - -} // namespace gcm - -#endif // CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_FACTORY_H_ +// Copyright (c) 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_CLIENT_FACTORY_H_
+#define COMPONENTS_GCM_DRIVER_GCM_CLIENT_FACTORY_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace gcm {
+
+class GCMClient;
+
+class GCMClientFactory {
+ public:
+ GCMClientFactory();
+ virtual ~GCMClientFactory();
+
+ // Creates a new instance of GCMClient. The testing code could override this
+ // to provide a mocked instance.
+ virtual scoped_ptr<GCMClient> BuildInstance();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GCMClientFactory);
+};
+
+} // namespace gcm
+
+#endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_FACTORY_H_
diff --git a/components/gcm_driver/system_encryptor.cc b/components/gcm_driver/system_encryptor.cc new file mode 100644 index 0000000..bc731a3 --- /dev/null +++ b/components/gcm_driver/system_encryptor.cc @@ -0,0 +1,23 @@ +// Copyright (c) 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/system_encryptor.h" + +#include "components/os_crypt/os_crypt.h" + +namespace gcm { + +SystemEncryptor::~SystemEncryptor() {} + +bool SystemEncryptor::EncryptString(const std::string& plaintext, + std::string* ciphertext) { + return ::OSCrypt::EncryptString(plaintext, ciphertext); +} + +bool SystemEncryptor::DecryptString(const std::string& ciphertext, + std::string* plaintext) { + return ::OSCrypt::DecryptString(ciphertext, plaintext); +} + +} // namespace gcm diff --git a/components/gcm_driver/system_encryptor.h b/components/gcm_driver/system_encryptor.h new file mode 100644 index 0000000..c7ae645 --- /dev/null +++ b/components/gcm_driver/system_encryptor.h @@ -0,0 +1,27 @@ +// Copyright (c) 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_SYSTEM_ENCRYPTOR_H_
+#define COMPONENTS_GCM_DRIVER_SYSTEM_ENCRYPTOR_H_
+
+#include "base/compiler_specific.h"
+#include "google_apis/gcm/base/encryptor.h"
+
+namespace gcm {
+
+// Encryptor that uses the Chrome password manager's encryptor.
+class SystemEncryptor : public Encryptor {
+ public:
+ virtual ~SystemEncryptor();
+
+ virtual bool EncryptString(const std::string& plaintext,
+ std::string* ciphertext) OVERRIDE;
+
+ virtual bool DecryptString(const std::string& ciphertext,
+ std::string* plaintext) OVERRIDE;
+};
+
+} // namespace gcm
+
+#endif // COMPONENTS_GCM_DRIVER_SYSTEM_ENCRYPTOR_H_
diff --git a/google_apis/gcm/DEPS b/google_apis/gcm/DEPS index 5accad6..047dc156 100644 --- a/google_apis/gcm/DEPS +++ b/google_apis/gcm/DEPS @@ -7,7 +7,6 @@ include_rules = [ "+base", "+testing", - "+components/os_crypt", "+google", # For third_party/protobuf/src. "+net", "+third_party/leveldatabase", diff --git a/google_apis/gcm/base/encryptor.h b/google_apis/gcm/base/encryptor.h new file mode 100644 index 0000000..898e7db --- /dev/null +++ b/google_apis/gcm/base/encryptor.h @@ -0,0 +1,27 @@ +// Copyright (c) 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 GOOGLE_APIS_GCM_ENCRYPTOR_H_ +#define GOOGLE_APIS_GCM_ENCRYPTOR_H_ + +#include <string> +#include "google_apis/gcm/base/gcm_export.h" + +namespace gcm { + +class GCM_EXPORT Encryptor { + public: + // All methods below should be thread-safe. + virtual bool EncryptString(const std::string& plaintext, + std::string* ciphertext) = 0; + + virtual bool DecryptString(const std::string& ciphertext, + std::string* plaintext) = 0; + + virtual ~Encryptor() {} +}; + +} // namespace gcm + +#endif // GOOGLE_APIS_GCM_ENCRYPTOR_H_ diff --git a/google_apis/gcm/base/fake_encryptor.cc b/google_apis/gcm/base/fake_encryptor.cc new file mode 100644 index 0000000..ac58081 --- /dev/null +++ b/google_apis/gcm/base/fake_encryptor.cc @@ -0,0 +1,24 @@ +// Copyright (c) 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 "google_apis/gcm/base/fake_encryptor.h" + +#include "base/base64.h" + +namespace gcm { + +FakeEncryptor::~FakeEncryptor() {} + +bool FakeEncryptor::EncryptString(const std::string& plaintext, + std::string* ciphertext) { + base::Base64Encode(plaintext, ciphertext); + return true; +} + +bool FakeEncryptor::DecryptString(const std::string& ciphertext, + std::string* plaintext) { + return base::Base64Decode(ciphertext, plaintext); +} + +} // namespace gcm diff --git a/google_apis/gcm/base/fake_encryptor.h b/google_apis/gcm/base/fake_encryptor.h new file mode 100644 index 0000000..01ae67b --- /dev/null +++ b/google_apis/gcm/base/fake_encryptor.h @@ -0,0 +1,28 @@ +// Copyright (c) 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 GOOGLE_APIS_GCM_BASE_ENCRYPTOR_H_ +#define GOOGLE_APIS_GCM_BASE_ENCRYPTOR_H_ + +#include "base/compiler_specific.h" +#include "google_apis/gcm/base/encryptor.h" + +namespace gcm { + +// Encryptor which simply base64-encodes the plaintext to get the +// ciphertext. Obviously, this should be used only for testing. +class FakeEncryptor : public Encryptor { + public: + virtual ~FakeEncryptor(); + + virtual bool EncryptString(const std::string& plaintext, + std::string* ciphertext) OVERRIDE; + + virtual bool DecryptString(const std::string& ciphertext, + std::string* plaintext) OVERRIDE; +}; + +} // namespace gcm + +#endif // GOOGLE_APIS_GCM_BASE_ENCRYPTOR_H_ diff --git a/google_apis/gcm/engine/gcm_store_impl.cc b/google_apis/gcm/engine/gcm_store_impl.cc index 5393fd1..8c6f730f 100644 --- a/google_apis/gcm/engine/gcm_store_impl.cc +++ b/google_apis/gcm/engine/gcm_store_impl.cc @@ -18,7 +18,7 @@ #include "base/strings/string_piece.h" #include "base/time/time.h" #include "base/tracked_objects.h" -#include "components/os_crypt/os_crypt.h" +#include "google_apis/gcm/base/encryptor.h" #include "google_apis/gcm/base/mcs_message.h" #include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/protocol/mcs.pb.h" @@ -107,7 +107,8 @@ class GCMStoreImpl::Backend : public base::RefCountedThreadSafe<GCMStoreImpl::Backend> { public: Backend(const base::FilePath& path, - scoped_refptr<base::SequencedTaskRunner> foreground_runner); + scoped_refptr<base::SequencedTaskRunner> foreground_runner, + scoped_ptr<Encryptor> encryptor); // Blocking implementations of GCMStoreImpl methods. void Load(const LoadCallback& callback); @@ -158,14 +159,19 @@ class GCMStoreImpl::Backend const base::FilePath path_; scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_; + scoped_ptr<Encryptor> encryptor_; scoped_ptr<leveldb::DB> db_; }; GCMStoreImpl::Backend::Backend( const base::FilePath& path, - scoped_refptr<base::SequencedTaskRunner> foreground_task_runner) - : path_(path), foreground_task_runner_(foreground_task_runner) {} + scoped_refptr<base::SequencedTaskRunner> foreground_task_runner, + scoped_ptr<Encryptor> encryptor) + : path_(path), + foreground_task_runner_(foreground_task_runner), + encryptor_(encryptor.Pass()) { +} GCMStoreImpl::Backend::~Backend() {} @@ -278,8 +284,8 @@ void GCMStoreImpl::Backend::SetDeviceCredentials( write_options.sync = true; std::string encrypted_token; - OSCrypt::EncryptString(base::Uint64ToString(device_security_token), - &encrypted_token); + encryptor_->EncryptString(base::Uint64ToString(device_security_token), + &encrypted_token); std::string android_id_str = base::Uint64ToString(device_android_id); leveldb::Status s = db_->Put(write_options, @@ -551,7 +557,7 @@ bool GCMStoreImpl::Backend::LoadDeviceCredentials(uint64* android_id, } if (s.ok()) { std::string decrypted_token; - OSCrypt::DecryptString(result, &decrypted_token); + encryptor_->DecryptString(result, &decrypted_token); if (!base::StringToUint64(decrypted_token, security_token)) { LOG(ERROR) << "Failed to restore security token."; return false; @@ -699,8 +705,11 @@ bool GCMStoreImpl::Backend::LoadGServicesSettings( GCMStoreImpl::GCMStoreImpl( const base::FilePath& path, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) - : backend_(new Backend(path, base::MessageLoopProxy::current())), + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, + scoped_ptr<Encryptor> encryptor) + : backend_(new Backend(path, + base::MessageLoopProxy::current(), + encryptor.Pass())), blocking_task_runner_(blocking_task_runner), weak_ptr_factory_(this) { } diff --git a/google_apis/gcm/engine/gcm_store_impl.h b/google_apis/gcm/engine/gcm_store_impl.h index e46c503..f49509a 100644 --- a/google_apis/gcm/engine/gcm_store_impl.h +++ b/google_apis/gcm/engine/gcm_store_impl.h @@ -18,13 +18,16 @@ class SequencedTaskRunner; namespace gcm { +class Encryptor; + // An implementation of GCM Store that uses LevelDB for persistence. // It performs all blocking operations on the blocking task runner, and posts // all callbacks to the thread on which the GCMStoreImpl is created. class GCM_EXPORT GCMStoreImpl : public GCMStore { public: GCMStoreImpl(const base::FilePath& path, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, + scoped_ptr<Encryptor> encryptor); virtual ~GCMStoreImpl(); // Load the directory and pass the initial state back to caller. diff --git a/google_apis/gcm/engine/gcm_store_impl_unittest.cc b/google_apis/gcm/engine/gcm_store_impl_unittest.cc index a587bc1198..7b9c893 100644 --- a/google_apis/gcm/engine/gcm_store_impl_unittest.cc +++ b/google_apis/gcm/engine/gcm_store_impl_unittest.cc @@ -15,7 +15,7 @@ #include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" -#include "components/os_crypt/os_crypt_switches.h" +#include "google_apis/gcm/base/fake_encryptor.h" #include "google_apis/gcm/base/mcs_message.h" #include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/protocol/mcs.pb.h" @@ -76,16 +76,13 @@ GCMStoreImplTest::~GCMStoreImplTest() {} void GCMStoreImplTest::SetUp() { testing::Test::SetUp(); -#if defined(OS_MACOSX) - base::CommandLine::ForCurrentProcess()->AppendSwitch( - os_crypt::switches::kUseMockKeychain); -#endif // OS_MACOSX } scoped_ptr<GCMStore> GCMStoreImplTest::BuildGCMStore() { return scoped_ptr<GCMStore>(new GCMStoreImpl( temp_directory_.path(), - message_loop_.message_loop_proxy())); + message_loop_.message_loop_proxy(), + make_scoped_ptr<Encryptor>(new FakeEncryptor))); } std::string GCMStoreImplTest::GetNextPersistentId() { diff --git a/google_apis/gcm/engine/mcs_client_unittest.cc b/google_apis/gcm/engine/mcs_client_unittest.cc index a062136..3e94532 100644 --- a/google_apis/gcm/engine/mcs_client_unittest.cc +++ b/google_apis/gcm/engine/mcs_client_unittest.cc @@ -10,7 +10,7 @@ #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/test/simple_test_clock.h" -#include "components/os_crypt/os_crypt_switches.h" +#include "google_apis/gcm/base/fake_encryptor.h" #include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/engine/fake_connection_factory.h" #include "google_apis/gcm/engine/fake_connection_handler.h" @@ -159,15 +159,13 @@ MCSClientTest::~MCSClientTest() {} void MCSClientTest::SetUp() { testing::Test::SetUp(); -#if defined(OS_MACOSX) - base::CommandLine::ForCurrentProcess()->AppendSwitch( - os_crypt::switches::kUseMockKeychain); -#endif // OS_MACOSX } void MCSClientTest::BuildMCSClient() { - gcm_store_.reset(new GCMStoreImpl(temp_directory_.path(), - message_loop_.message_loop_proxy())); + gcm_store_.reset(new GCMStoreImpl( + temp_directory_.path(), + message_loop_.message_loop_proxy(), + make_scoped_ptr<Encryptor>(new FakeEncryptor))); mcs_client_.reset(new TestMCSClient(&clock_, &connection_factory_, gcm_store_.get(), diff --git a/google_apis/gcm/gcm.gyp b/google_apis/gcm/gcm.gyp index 3f40c8d..670b0a1 100644 --- a/google_apis/gcm/gcm.gyp +++ b/google_apis/gcm/gcm.gyp @@ -31,7 +31,6 @@ 'dependencies': [ '../../base/base.gyp:base', '../../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', - '../../components/components.gyp:os_crypt', '../../net/net.gyp:net', '../../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', '../../third_party/protobuf/protobuf.gyp:protobuf_lite', @@ -101,6 +100,8 @@ 'gcm' ], 'sources': [ + 'base/fake_encryptor.cc', + 'base/fake_encryptor.h', 'tools/mcs_probe.cc', ], }, @@ -119,7 +120,6 @@ 'dependencies': [ '../../base/base.gyp:run_all_unittests', '../../base/base.gyp:base', - '../../components/components.gyp:os_crypt', '../../net/net.gyp:net', '../../net/net.gyp:net_test_support', '../../testing/gtest.gyp:gtest', @@ -127,6 +127,8 @@ 'gcm' ], 'sources': [ + 'base/fake_encryptor.cc', + 'base/fake_encryptor.h', 'base/mcs_message_unittest.cc', 'base/mcs_util_unittest.cc', 'base/socket_stream_unittest.cc', diff --git a/google_apis/gcm/gcm_client.h b/google_apis/gcm/gcm_client.h index bee154b..dc65967 100644 --- a/google_apis/gcm/gcm_client.h +++ b/google_apis/gcm/gcm_client.h @@ -30,6 +30,8 @@ class URLRequestContextGetter; namespace gcm { +class Encryptor; + // Interface that encapsulates the network communications with the Google Cloud // Messaging server. This interface is not supposed to be thread-safe. class GCM_EXPORT GCMClient { @@ -183,6 +185,7 @@ class GCM_EXPORT GCMClient { const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, const scoped_refptr<net::URLRequestContextGetter>& url_request_context_getter, + scoped_ptr<Encryptor> encryptor, Delegate* delegate) = 0; // Starts the GCM service by first loading the data from the persistent store. diff --git a/google_apis/gcm/gcm_client_impl.cc b/google_apis/gcm/gcm_client_impl.cc index ed9838c..4065d65 100644 --- a/google_apis/gcm/gcm_client_impl.cc +++ b/google_apis/gcm/gcm_client_impl.cc @@ -14,6 +14,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/time/default_clock.h" +#include "google_apis/gcm/base/encryptor.h" #include "google_apis/gcm/base/mcs_message.h" #include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/engine/checkin_request.h" @@ -206,6 +207,7 @@ void GCMClientImpl::Initialize( const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, const scoped_refptr<net::URLRequestContextGetter>& url_request_context_getter, + scoped_ptr<Encryptor> encryptor, GCMClient::Delegate* delegate) { DCHECK_EQ(UNINITIALIZED, state_); DCHECK(url_request_context_getter); @@ -221,7 +223,8 @@ void GCMClientImpl::Initialize( chrome_build_proto_.CopyFrom(chrome_build_proto); account_ids_ = account_ids; - gcm_store_.reset(new GCMStoreImpl(path, blocking_task_runner)); + gcm_store_.reset( + new GCMStoreImpl(path, blocking_task_runner, encryptor.Pass())); delegate_ = delegate; diff --git a/google_apis/gcm/gcm_client_impl.h b/google_apis/gcm/gcm_client_impl.h index 5555ca3..5c4c84a 100644 --- a/google_apis/gcm/gcm_client_impl.h +++ b/google_apis/gcm/gcm_client_impl.h @@ -87,6 +87,7 @@ class GCM_EXPORT GCMClientImpl const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, const scoped_refptr<net::URLRequestContextGetter>& url_request_context_getter, + scoped_ptr<Encryptor> encryptor, GCMClient::Delegate* delegate) OVERRIDE; virtual void Start() OVERRIDE; virtual void Stop() OVERRIDE; diff --git a/google_apis/gcm/gcm_client_impl_unittest.cc b/google_apis/gcm/gcm_client_impl_unittest.cc index 010660a..7fc0e49 100644 --- a/google_apis/gcm/gcm_client_impl_unittest.cc +++ b/google_apis/gcm/gcm_client_impl_unittest.cc @@ -10,7 +10,7 @@ #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/time/clock.h" -#include "components/os_crypt/os_crypt_switches.h" +#include "google_apis/gcm/base/fake_encryptor.h" #include "google_apis/gcm/base/mcs_message.h" #include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/engine/fake_connection_factory.h" @@ -330,10 +330,6 @@ GCMClientImplTest::~GCMClientImplTest() {} void GCMClientImplTest::SetUp() { testing::Test::SetUp(); -#if defined(OS_MACOSX) - base::CommandLine::ForCurrentProcess()->AppendSwitch( - os_crypt::switches::kUseMockKeychain); -#endif // OS_MACOSX ASSERT_TRUE(CreateUniqueTempDir()); InitializeLoop(); BuildGCMClient(base::TimeDelta()); @@ -454,6 +450,7 @@ void GCMClientImplTest::InitializeGCMClient() { std::vector<std::string>(), message_loop_.message_loop_proxy(), url_request_context_getter_, + make_scoped_ptr<Encryptor>(new FakeEncryptor), this); // Start loading and check-in. @@ -702,10 +699,6 @@ GCMClientImplCheckinTest::~GCMClientImplCheckinTest() { void GCMClientImplCheckinTest::SetUp() { testing::Test::SetUp(); -#if defined(OS_MACOSX) - base::CommandLine::ForCurrentProcess()->AppendSwitch( - os_crypt::switches::kUseMockKeychain); -#endif // OS_MACOSX // Creating unique temp directory that will be used by GCMStore shared between // GCM Client and G-services settings. ASSERT_TRUE(CreateUniqueTempDir()); diff --git a/google_apis/gcm/tools/mcs_probe.cc b/google_apis/gcm/tools/mcs_probe.cc index b7f984d..3f93fd0 100644 --- a/google_apis/gcm/tools/mcs_probe.cc +++ b/google_apis/gcm/tools/mcs_probe.cc @@ -23,6 +23,7 @@ #include "base/threading/worker_pool.h" #include "base/time/default_clock.h" #include "base/values.h" +#include "google_apis/gcm/base/fake_encryptor.h" #include "google_apis/gcm/base/mcs_message.h" #include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/engine/checkin_request.h" @@ -306,7 +307,8 @@ void MCSProbe::Start() { &recorder_)); gcm_store_.reset( new GCMStoreImpl(gcm_store_path_, - file_thread_.message_loop_proxy())); + file_thread_.message_loop_proxy(), + make_scoped_ptr<Encryptor>(new FakeEncryptor))); mcs_client_.reset(new MCSClient("probe", &clock_, connection_factory_.get(), |