Chromium Code Reviews| Index: components/gcm/gcm_driver.h |
| diff --git a/components/gcm/gcm_driver.h b/components/gcm/gcm_driver.h |
| index af70e48dbc9ed5154e3196f814aa52c4c6052e54..694faecd547b17b10383def7c720a61bb032ada7 100644 |
| --- a/components/gcm/gcm_driver.h |
| +++ b/components/gcm/gcm_driver.h |
| @@ -9,32 +9,21 @@ |
| #include <string> |
| #include <vector> |
| -#include "base/basictypes.h" |
| #include "base/callback.h" |
| -#include "base/compiler_specific.h" |
| +#include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| -#include "base/memory/scoped_ptr.h" |
| -#include "base/memory/weak_ptr.h" |
| -#include "components/gcm/default_gcm_app_handler.h" |
| -#include "google_apis/gaia/identity_provider.h" |
| #include "google_apis/gcm/gcm_client.h" |
| namespace base { |
| -class FilePath; |
| class MessageLoopProxy; |
| } |
| -namespace net { |
| -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 { |
| +class GCMDriver { |
| public: |
| typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; |
| typedef base::Callback<void(const std::string& registration_id, |
| @@ -45,21 +34,14 @@ class GCMDriver : public IdentityProvider::Observer { |
| 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); |
| + GCMDriver(const scoped_refptr<base::MessageLoopProxy>& ui_thread); |
|
jianli
2014/05/08 00:26:48
I don't think you need to pass a ui thread to the
johnme
2014/05/08 16:08:02
Done.
|
| 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(); |
| + virtual void Enable() = 0; |
| + virtual void Disable() = 0; |
| // Shuts down the GCM service completely. This will tell all the apps |
| // to shut them down. After that, no GCM service could be consumed. |
| @@ -81,13 +63,13 @@ class GCMDriver : public IdentityProvider::Observer { |
| // |callback|: to be called once the asynchronous operation is done. |
| virtual void Register(const std::string& app_id, |
| const std::vector<std::string>& sender_ids, |
| - const RegisterCallback& callback); |
| + const RegisterCallback& callback) = 0; |
| // Unregisters an app from using GCM. |
| // |app_id|: application ID. |
| // |callback|: to be called once the asynchronous operation is done. |
| virtual void Unregister(const std::string& app_id, |
| - const UnregisterCallback& callback); |
| + const UnregisterCallback& callback) = 0; |
| // Sends a message to a given receiver. |
| // |app_id|: application ID. |
| @@ -97,30 +79,28 @@ class GCMDriver : public IdentityProvider::Observer { |
| virtual void Send(const std::string& app_id, |
| const std::string& receiver_id, |
| const GCMClient::OutgoingMessage& message, |
| - const SendCallback& callback); |
| + const SendCallback& callback) = 0; |
| - // For testing purpose. |
| - GCMClient* GetGCMClientForTesting() const; |
| + // For testing purpose. Always NULL on Android. |
| + virtual GCMClient* GetGCMClientForTesting() const = 0; |
| // Returns true if the service was started. |
| - bool IsStarted() const; |
| + virtual bool IsStarted() const = 0; |
| // Returns true if the gcm client is ready. |
| - bool IsGCMClientReady() const; |
| + virtual bool IsGCMClientReady() const = 0; |
| - std::string SignedInUserName() const; |
| + virtual std::string SignedInUserName() const = 0; |
| // 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); |
| + virtual void GetGCMStatistics(GetGCMStatisticsCallback callback, |
| + bool clear_logs) = 0; |
| // Enables/disables GCM activity recording, and then returns the stats. |
| - void SetGCMRecording(GetGCMStatisticsCallback callback, bool recording); |
| - |
| - // IdentityProvider::Observer: |
| - virtual void OnActiveAccountLogin() OVERRIDE; |
| - virtual void OnActiveAccountLogout() OVERRIDE; |
| + virtual void SetGCMRecording(GetGCMStatisticsCallback callback, |
| + bool recording) = 0; |
| const GCMAppHandlerMap& app_handlers() const { return app_handlers_; } |
| @@ -128,99 +108,13 @@ class GCMDriver : public IdentityProvider::Observer { |
| // Used for constructing fake GCMDriver for testing purpose. |
| GCMDriver(); |
| - private: |
| - class DelayedTaskController; |
| - class IOWorker; |
| - |
| - // Ensures that the GCM service starts when all of the following conditions |
| - // satisfy: |
| - // 1) GCM is enabled. |
| - // 2) The identity provider is able to supply an account ID. |
| - // 3) An app requests to consume the service by register the app handler. |
| - GCMClient::Result EnsureStarted(); |
| - |
| - // Stops the GCM service. It can be restarted by calling EnsureStarted again. |
| - void Stop(); |
| - |
| - // Remove cached data when GCM service is stopped. |
| - void RemoveCachedData(); |
| - |
| - // Checks out of GCM and erases any cached and persisted data. |
| - void CheckOut(); |
| - |
| - // Should be called when an app with |app_id| is trying to un/register. |
| - // Checks whether another un/registration is in progress. |
| - bool IsAsyncOperationPending(const std::string& app_id) const; |
| - |
| - void DoRegister(const std::string& app_id, |
| - const std::vector<std::string>& sender_ids); |
| - void DoUnregister(const std::string& app_id); |
| - void DoSend(const std::string& app_id, |
| - const std::string& receiver_id, |
| - const GCMClient::OutgoingMessage& message); |
| - |
| - // Callbacks posted from IO thread to UI thread. |
| - void RegisterFinished(const std::string& app_id, |
| - const std::string& registration_id, |
| - GCMClient::Result result); |
| - void UnregisterFinished(const std::string& app_id, GCMClient::Result result); |
| - void SendFinished(const std::string& app_id, |
| - const std::string& message_id, |
| - GCMClient::Result result); |
| - void MessageReceived(const std::string& app_id, |
| - GCMClient::IncomingMessage message); |
| - void MessagesDeleted(const std::string& app_id); |
| - void MessageSendError(const std::string& app_id, |
| - const GCMClient::SendErrorDetails& send_error_details); |
| - void GCMClientReady(); |
| - |
| - // Returns the handler for the given app. |
| - GCMAppHandler* GetAppHandler(const std::string& app_id); |
| - |
| - 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. |
| - bool gcm_enabled_; |
| - |
| - // Flag to indicate if GCMClient is ready. |
| - bool gcm_client_ready_; |
| - |
| - // The account ID that this service is responsible for. Empty when the service |
| - // is not running. |
| - std::string account_id_; |
| - |
| - scoped_ptr<DelayedTaskController> delayed_task_controller_; |
| - |
| - // For all the work occurring on the IO thread. Must be destroyed on the IO |
| - // thread. |
| - scoped_ptr<IOWorker> io_worker_; |
| + private: |
| // App handler map (from app_id to handler pointer). |
| // The handler is not owned. |
| GCMAppHandlerMap app_handlers_; |
| - // The default handler when no app handler can be found in the map. |
| - DefaultGCMAppHandler default_app_handler_; |
| - |
| - // Callback map (from app_id to callback) for Register. |
| - std::map<std::string, RegisterCallback> register_callbacks_; |
| - |
| - // Callback map (from app_id to callback) for Unregister. |
| - std::map<std::string, UnregisterCallback> unregister_callbacks_; |
| - |
| - // Callback map (from <app_id, message_id> to callback) for Send. |
| - std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; |
| - |
| - // Callback for GetGCMStatistics. |
| - GetGCMStatisticsCallback request_gcm_statistics_callback_; |
| - |
| - // Used to pass a weak pointer to the IO worker. |
| - base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; |
| - |
| DISALLOW_COPY_AND_ASSIGN(GCMDriver); |
| }; |