summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 22:25:24 +0000
committerjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 22:25:24 +0000
commit5375f66d9604e7d6b2cd8a3d4b15e3b34b5878a5 (patch)
tree6d7c835d9e8487d8b68c179a394217483a3f9064 /components
parent94e20d445e63f4167fb84a9364fc6cfa53cfd0e3 (diff)
downloadchromium_src-5375f66d9604e7d6b2cd8a3d4b15e3b34b5878a5.zip
chromium_src-5375f66d9604e7d6b2cd8a3d4b15e3b34b5878a5.tar.gz
chromium_src-5375f66d9604e7d6b2cd8a3d4b15e3b34b5878a5.tar.bz2
Componentize GCM Part 1: create GCM component and move some files over
BUG=356716 TEST=existing tests Review URL: https://codereview.chromium.org/261853012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270226 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/OWNERS5
-rw-r--r--components/components.gyp1
-rw-r--r--components/gcm_driver.gypi29
-rw-r--r--components/gcm_driver/DEPS4
-rw-r--r--components/gcm_driver/OWNERS4
-rw-r--r--components/gcm_driver/default_gcm_app_handler.cc39
-rw-r--r--components/gcm_driver/default_gcm_app_handler.h35
-rw-r--r--components/gcm_driver/gcm_app_handler.h42
-rw-r--r--components/gcm_driver/gcm_client_factory.cc22
-rw-r--r--components/gcm_driver/gcm_client_factory.h30
-rw-r--r--components/gcm_driver/system_encryptor.cc23
-rw-r--r--components/gcm_driver/system_encryptor.h27
12 files changed, 261 insertions, 0 deletions
diff --git a/components/OWNERS b/components/OWNERS
index 9f8bcb9..255860f 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 infobars.gypi=pkasting@chromium.org
per-file json_schema.gypi=asargent@chromium.org
diff --git a/components/components.gyp b/components/components.gyp
index cab78f6..83e41da8 100644
--- a/components/components.gyp
+++ b/components/components.gyp
@@ -73,6 +73,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/components/gcm_driver/default_gcm_app_handler.cc b/components/gcm_driver/default_gcm_app_handler.cc
new file mode 100644
index 0000000..3a87946
--- /dev/null
+++ b/components/gcm_driver/default_gcm_app_handler.cc
@@ -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.
+
+#include "components/gcm_driver/default_gcm_app_handler.h"
+
+#include "base/logging.h"
+
+namespace gcm {
+
+DefaultGCMAppHandler::DefaultGCMAppHandler() {
+}
+
+DefaultGCMAppHandler::~DefaultGCMAppHandler() {
+}
+
+void DefaultGCMAppHandler::ShutdownHandler() {
+ // Nothing to do.
+}
+
+void DefaultGCMAppHandler::OnMessage(
+ const std::string& app_id,
+ const GCMClient::IncomingMessage& message) {
+ LOG(ERROR) << "No app handler is found to route message for " << app_id;
+}
+
+void DefaultGCMAppHandler::OnMessagesDeleted(const std::string& app_id) {
+ LOG(ERROR) << "No app handler is found to route deleted message for "
+ << app_id;
+}
+
+void DefaultGCMAppHandler::OnSendError(
+ const std::string& app_id,
+ const GCMClient::SendErrorDetails& send_error_details) {
+ LOG(ERROR) << "No app handler is found to route send error message for "
+ << app_id;
+}
+
+} // namespace gcm
diff --git a/components/gcm_driver/default_gcm_app_handler.h b/components/gcm_driver/default_gcm_app_handler.h
new file mode 100644
index 0000000..6b5f036
--- /dev/null
+++ b/components/gcm_driver/default_gcm_app_handler.h
@@ -0,0 +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 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..9e24a90
--- /dev/null
+++ b/components/gcm_driver/gcm_app_handler.h
@@ -0,0 +1,42 @@
+// 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_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/components/gcm_driver/gcm_client_factory.cc b/components/gcm_driver/gcm_client_factory.cc
new file mode 100644
index 0000000..27443bb
--- /dev/null
+++ b/components/gcm_driver/gcm_client_factory.cc
@@ -0,0 +1,22 @@
+// 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_client_factory.h"
+
+#include "google_apis/gcm/gcm_client_impl.h"
+
+namespace gcm {
+
+scoped_ptr<GCMClient> GCMClientFactory::BuildInstance() {
+ return scoped_ptr<GCMClient>(new GCMClientImpl(
+ make_scoped_ptr<GCMInternalsBuilder>(new GCMInternalsBuilder())));
+}
+
+GCMClientFactory::GCMClientFactory() {
+}
+
+GCMClientFactory::~GCMClientFactory() {
+}
+
+} // namespace gcm
diff --git a/components/gcm_driver/gcm_client_factory.h b/components/gcm_driver/gcm_client_factory.h
new file mode 100644
index 0000000..29165ba
--- /dev/null
+++ b/components/gcm_driver/gcm_client_factory.h
@@ -0,0 +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 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..787dff3
--- /dev/null
+++ b/components/gcm_driver/system_encryptor.cc
@@ -0,0 +1,23 @@
+// 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/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..4058548
--- /dev/null
+++ b/components/gcm_driver/system_encryptor.h
@@ -0,0 +1,27 @@
+// 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_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_