Index: components/gcm/gcm_driver_desktop.h |
diff --git a/components/gcm/gcm_driver.h b/components/gcm/gcm_driver_desktop.h |
similarity index 54% |
copy from components/gcm/gcm_driver.h |
copy to components/gcm/gcm_driver_desktop.h |
index af70e48dbc9ed5154e3196f814aa52c4c6052e54..db1855d6b4cf371346c829fae62a9a2ff7f70236 100644 |
--- a/components/gcm/gcm_driver.h |
+++ b/components/gcm/gcm_driver_desktop.h |
@@ -2,8 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef COMPONENTS_GCM_GCM_DRIVER_H_ |
-#define COMPONENTS_GCM_GCM_DRIVER_H_ |
+#ifndef COMPONENTS_GCM_GCM_DRIVER_DESKTOP_H_ |
+#define COMPONENTS_GCM_GCM_DRIVER_DESKTOP_H_ |
#include <map> |
#include <string> |
@@ -16,6 +16,7 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/weak_ptr.h" |
#include "components/gcm/default_gcm_app_handler.h" |
+#include "components/gcm/gcm_driver.h" |
#include "google_apis/gaia/identity_provider.h" |
#include "google_apis/gcm/gcm_client.h" |
@@ -30,103 +31,54 @@ class URLRequestContextGetter; |
namespace gcm { |
-class GCMAppHandler; |
class GCMClientFactory; |
-// A bridge between the GCM users in Chrome and the GCMClient layer. |
-class GCMDriver : public IdentityProvider::Observer { |
+// GCMDriver implementation for Chrome OS, Windows, Linux and Mac. |
+class GCMDriverDesktop : public GCMDriver, public IdentityProvider::Observer { |
public: |
- typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; |
- typedef base::Callback<void(const std::string& registration_id, |
- GCMClient::Result result)> RegisterCallback; |
- typedef base::Callback<void(const std::string& message_id, |
- GCMClient::Result result)> SendCallback; |
- typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback; |
- typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> |
- GetGCMStatisticsCallback; |
- |
- GCMDriver(const checkin_proto::ChromeBuildProto& chrome_build_proto, |
- scoped_ptr<GCMClientFactory> gcm_client_factory, |
- scoped_ptr<IdentityProvider> identity_provider, |
- const base::FilePath& store_path, |
- const scoped_refptr<net::URLRequestContextGetter>& request_context, |
- const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
- const scoped_refptr<base::MessageLoopProxy>& ui_thread, |
- const scoped_refptr<base::MessageLoopProxy>& io_thread); |
- virtual ~GCMDriver(); |
- |
- // Enables/disables GCM service. When GCM is disabled, the GCM service |
- // will always be stopped. Otherwise, the GCM service will be started |
- // on demand, i.e., some app is asking for the service. |
- void Enable(); |
- void Disable(); |
- |
- // Shuts down the GCM service completely. This will tell all the apps |
- // to shut them down. After that, no GCM service could be consumed. |
- virtual void Shutdown(); |
- |
- // Adds a handler for a given app. It is OK to call this again to update the |
- // handler. |
- virtual void AddAppHandler(const std::string& app_id, GCMAppHandler* handler); |
- |
- // Removes the handler for a given app. |
- virtual void RemoveAppHandler(const std::string& app_id); |
- |
- // Registers |sender_id| for an app. A registration ID will be returned by |
- // the GCM server. |
- // |app_id|: application ID. |
- // |sender_ids|: list of IDs of the servers that are allowed to send the |
- // messages to the application. These IDs are assigned by the |
- // Google API Console. |
- // |callback|: to be called once the asynchronous operation is done. |
+ GCMDriverDesktop( |
+ const checkin_proto::ChromeBuildProto& chrome_build_proto, |
+ scoped_ptr<GCMClientFactory> gcm_client_factory, |
+ scoped_ptr<IdentityProvider> identity_provider, |
+ const base::FilePath& store_path, |
+ const scoped_refptr<net::URLRequestContextGetter>& request_context, |
+ const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
+ const scoped_refptr<base::MessageLoopProxy>& ui_thread, |
+ const scoped_refptr<base::MessageLoopProxy>& io_thread); |
+ virtual ~GCMDriverDesktop(); |
+ |
+ // GCMDriver implementation. |
+ virtual void Enable() OVERRIDE; |
+ virtual void Disable() OVERRIDE; |
+ virtual void Shutdown() OVERRIDE; |
+ virtual void AddAppHandler(const std::string& app_id, |
+ GCMAppHandler* handler) OVERRIDE; |
+ virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; |
virtual void Register(const std::string& app_id, |
const std::vector<std::string>& sender_ids, |
- const RegisterCallback& callback); |
- |
- // Unregisters an app from using GCM. |
- // |app_id|: application ID. |
- // |callback|: to be called once the asynchronous operation is done. |
+ const RegisterCallback& callback) OVERRIDE; |
virtual void Unregister(const std::string& app_id, |
- const UnregisterCallback& callback); |
- |
- // Sends a message to a given receiver. |
- // |app_id|: application ID. |
- // |receiver_id|: registration ID of the receiver party. |
- // |message|: message to be sent. |
- // |callback|: to be called once the asynchronous operation is done. |
+ const UnregisterCallback& callback) OVERRIDE; |
virtual void Send(const std::string& app_id, |
const std::string& receiver_id, |
const GCMClient::OutgoingMessage& message, |
- const SendCallback& callback); |
- |
- // For testing purpose. |
- GCMClient* GetGCMClientForTesting() const; |
- |
- // Returns true if the service was started. |
- bool IsStarted() const; |
- |
- // Returns true if the gcm client is ready. |
- bool IsGCMClientReady() const; |
- |
- std::string SignedInUserName() const; |
- |
- // Get GCM client internal states and statistics. |
- // If clear_logs is true then activity logs will be cleared before the stats |
- // are returned. |
- void GetGCMStatistics(GetGCMStatisticsCallback callback, bool clear_logs); |
- |
- // Enables/disables GCM activity recording, and then returns the stats. |
- void SetGCMRecording(GetGCMStatisticsCallback callback, bool recording); |
- |
- // IdentityProvider::Observer: |
+ const SendCallback& callback) OVERRIDE; |
+ virtual GCMClient* GetGCMClientForTesting() const OVERRIDE; |
+ virtual bool IsStarted() const OVERRIDE; |
+ virtual bool IsGCMClientReady() const OVERRIDE; |
+ virtual std::string SignedInUserName() const OVERRIDE; |
+ virtual void GetGCMStatistics(GetGCMStatisticsCallback callback, |
+ bool clear_logs) OVERRIDE; |
+ virtual void SetGCMRecording(GetGCMStatisticsCallback callback, |
+ bool recording) OVERRIDE; |
+ |
+ // IdentityProvider::Observer implementation. |
virtual void OnActiveAccountLogin() OVERRIDE; |
virtual void OnActiveAccountLogout() OVERRIDE; |
- const GCMAppHandlerMap& app_handlers() const { return app_handlers_; } |
- |
protected: |
// Used for constructing fake GCMDriver for testing purpose. |
- GCMDriver(); |
+ GCMDriverDesktop(); |
private: |
class DelayedTaskController; |
@@ -180,7 +132,6 @@ class GCMDriver : public IdentityProvider::Observer { |
void GetGCMStatisticsFinished(GCMClient::GCMStatistics stats); |
scoped_ptr<IdentityProvider> identity_provider_; |
- scoped_refptr<base::MessageLoopProxy> ui_thread_; |
scoped_refptr<base::MessageLoopProxy> io_thread_; |
// Flag to indicate if GCM is enabled. |
@@ -219,11 +170,11 @@ class GCMDriver : public IdentityProvider::Observer { |
GetGCMStatisticsCallback request_gcm_statistics_callback_; |
// Used to pass a weak pointer to the IO worker. |
- base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; |
+ base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; |
- DISALLOW_COPY_AND_ASSIGN(GCMDriver); |
+ DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); |
}; |
} // namespace gcm |
-#endif // COMPONENTS_GCM_GCM_DRIVER_H_ |
+#endif // COMPONENTS_GCM_GCM_DRIVER_DESKTOP_H_ |