Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / components / gcm_driver / gcm_driver_desktop.h
index 91a0399..c79351f 100644 (file)
 #include "base/memory/ref_counted.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "components/gcm_driver/gcm_channel_status_syncer.h"
 #include "components/gcm_driver/gcm_client.h"
+#include "components/gcm_driver/gcm_connection_observer.h"
 #include "components/gcm_driver/gcm_driver.h"
 
+class PrefService;
+
 namespace base {
 class FilePath;
 class SequencedTaskRunner;
@@ -34,6 +39,7 @@ namespace gcm {
 
 class GCMAppHandler;
 class GCMClientFactory;
+class GCMDelayedTaskController;
 
 // GCMDriver implementation for desktop and Chrome OS, using GCMClient.
 class GCMDriverDesktop : public GCMDriver {
@@ -41,6 +47,7 @@ class GCMDriverDesktop : public GCMDriver {
   GCMDriverDesktop(
       scoped_ptr<GCMClientFactory> gcm_client_factory,
       const GCMClient::ChromeBuildInfo& chrome_build_info,
+      PrefService* prefs,
       const base::FilePath& store_path,
       const scoped_refptr<net::URLRequestContextGetter>& request_context,
       const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
@@ -55,6 +62,9 @@ class GCMDriverDesktop : public GCMDriver {
   virtual void AddAppHandler(const std::string& app_id,
                              GCMAppHandler* handler) OVERRIDE;
   virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
+  virtual void AddConnectionObserver(GCMConnectionObserver* observer) OVERRIDE;
+  virtual void RemoveConnectionObserver(
+      GCMConnectionObserver* observer) OVERRIDE;
   virtual void Enable() OVERRIDE;
   virtual void Disable() OVERRIDE;
   virtual GCMClient* GetGCMClientForTesting() const OVERRIDE;
@@ -64,6 +74,9 @@ class GCMDriverDesktop : public GCMDriver {
                                 bool clear_logs) OVERRIDE;
   virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
                                bool recording) OVERRIDE;
+  virtual void UpdateAccountMapping(
+      const AccountMapping& account_mapping) OVERRIDE;
+  virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;
 
   // GCMDriverDesktop specific implementation.
   // Sets a list of accounts with OAuth2 tokens for the next checkin.
@@ -74,6 +87,12 @@ class GCMDriverDesktop : public GCMDriver {
   void SetAccountsForCheckin(
       const std::map<std::string, std::string>& account_tokens);
 
+  // Exposed for testing purpose.
+  bool gcm_enabled() const { return gcm_enabled_; }
+  GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() {
+    return gcm_channel_status_syncer_.get();
+  }
+
  protected:
   // GCMDriver implementation:
   virtual GCMClient::Result EnsureStarted() OVERRIDE;
@@ -86,7 +105,6 @@ class GCMDriverDesktop : public GCMDriver {
                         const GCMClient::OutgoingMessage& message) OVERRIDE;
 
  private:
-  class DelayedTaskController;
   class IOWorker;
 
   //  Stops the GCM service. It can be restarted by calling EnsureStarted again.
@@ -110,12 +128,15 @@ class GCMDriverDesktop : public GCMDriver {
                         const GCMClient::SendErrorDetails& send_error_details);
   void SendAcknowledged(const std::string& app_id,
                         const std::string& message_id);
-  void GCMClientReady();
+  void GCMClientReady(
+      const std::vector<AccountMapping>& account_mappings);
   void OnConnected(const net::IPEndPoint& ip_endpoint);
   void OnDisconnected();
 
   void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats);
 
+  scoped_ptr<GCMChannelStatusSyncer> gcm_channel_status_syncer_;
+
   // Flag to indicate whether the user is signed in to a GAIA account.
   // TODO(jianli): To be removed when sign-in enforcement is dropped.
   bool signed_in_;
@@ -124,6 +145,7 @@ class GCMDriverDesktop : public GCMDriver {
   bool gcm_started_;
 
   // Flag to indicate if GCM is enabled.
+  // TODO(jianli): Removed when we switch completely to support all users.
   bool gcm_enabled_;
 
   // Flag to indicate the last known state of the GCM client. Because this
@@ -131,10 +153,14 @@ class GCMDriverDesktop : public GCMDriver {
   // it may be out of date while connection changes are happening.
   bool connected_;
 
+  // List of observers to notify when connection state changes.
+  // Makes sure list is empty on destruction.
+  ObserverList<GCMConnectionObserver, true> connection_observer_list_;
+
   scoped_refptr<base::SequencedTaskRunner> ui_thread_;
   scoped_refptr<base::SequencedTaskRunner> io_thread_;
 
-  scoped_ptr<DelayedTaskController> delayed_task_controller_;
+  scoped_ptr<GCMDelayedTaskController> delayed_task_controller_;
 
   // For all the work occurring on the IO thread. Must be destroyed on the IO
   // thread.