| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ |
| 6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ | 6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "components/gcm_driver/gcm_channel_status_syncer.h" |
| 18 #include "components/gcm_driver/gcm_client.h" | 19 #include "components/gcm_driver/gcm_client.h" |
| 19 #include "components/gcm_driver/gcm_connection_observer.h" | 20 #include "components/gcm_driver/gcm_connection_observer.h" |
| 20 #include "components/gcm_driver/gcm_driver.h" | 21 #include "components/gcm_driver/gcm_driver.h" |
| 21 | 22 |
| 23 class PrefService; |
| 24 |
| 22 namespace base { | 25 namespace base { |
| 23 class FilePath; | 26 class FilePath; |
| 24 class SequencedTaskRunner; | 27 class SequencedTaskRunner; |
| 25 } | 28 } |
| 26 | 29 |
| 27 namespace extensions { | 30 namespace extensions { |
| 28 class ExtensionGCMAppHandlerTest; | 31 class ExtensionGCMAppHandlerTest; |
| 29 } | 32 } |
| 30 | 33 |
| 31 namespace net { | 34 namespace net { |
| 32 class URLRequestContextGetter; | 35 class URLRequestContextGetter; |
| 33 } | 36 } |
| 34 | 37 |
| 35 namespace gcm { | 38 namespace gcm { |
| 36 | 39 |
| 37 class GCMAppHandler; | 40 class GCMAppHandler; |
| 38 class GCMClientFactory; | 41 class GCMClientFactory; |
| 39 class GCMDelayedTaskController; | 42 class GCMDelayedTaskController; |
| 40 | 43 |
| 41 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. | 44 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. |
| 42 class GCMDriverDesktop : public GCMDriver { | 45 class GCMDriverDesktop : public GCMDriver { |
| 43 public: | 46 public: |
| 44 GCMDriverDesktop( | 47 GCMDriverDesktop( |
| 45 scoped_ptr<GCMClientFactory> gcm_client_factory, | 48 scoped_ptr<GCMClientFactory> gcm_client_factory, |
| 46 const GCMClient::ChromeBuildInfo& chrome_build_info, | 49 const GCMClient::ChromeBuildInfo& chrome_build_info, |
| 50 PrefService* prefs, |
| 47 const base::FilePath& store_path, | 51 const base::FilePath& store_path, |
| 48 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 52 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| 49 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 53 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
| 50 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 54 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
| 51 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); | 55 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
| 52 virtual ~GCMDriverDesktop(); | 56 virtual ~GCMDriverDesktop(); |
| 53 | 57 |
| 54 // GCMDriver overrides: | 58 // GCMDriver overrides: |
| 55 virtual void Shutdown() OVERRIDE; | 59 virtual void Shutdown() OVERRIDE; |
| 56 virtual void OnSignedIn() OVERRIDE; | 60 virtual void OnSignedIn() OVERRIDE; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 77 | 81 |
| 78 // GCMDriverDesktop specific implementation. | 82 // GCMDriverDesktop specific implementation. |
| 79 // Sets a list of accounts with OAuth2 tokens for the next checkin. | 83 // Sets a list of accounts with OAuth2 tokens for the next checkin. |
| 80 // |account_tokens| maps email addresses to OAuth2 access tokens. | 84 // |account_tokens| maps email addresses to OAuth2 access tokens. |
| 81 // |account_removed| indicates that an account has been removed since the | 85 // |account_removed| indicates that an account has been removed since the |
| 82 // last time the callback was called, which triggers an immediate checkin, | 86 // last time the callback was called, which triggers an immediate checkin, |
| 83 // to ensure that association between device and account is removed. | 87 // to ensure that association between device and account is removed. |
| 84 void SetAccountsForCheckin( | 88 void SetAccountsForCheckin( |
| 85 const std::map<std::string, std::string>& account_tokens); | 89 const std::map<std::string, std::string>& account_tokens); |
| 86 | 90 |
| 91 // Exposed for testing purpose. |
| 92 bool gcm_enabled() const { return gcm_enabled_; } |
| 93 GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() { |
| 94 return gcm_channel_status_syncer_.get(); |
| 95 } |
| 96 |
| 87 protected: | 97 protected: |
| 88 // GCMDriver implementation: | 98 // GCMDriver implementation: |
| 89 virtual GCMClient::Result EnsureStarted() OVERRIDE; | 99 virtual GCMClient::Result EnsureStarted() OVERRIDE; |
| 90 virtual void RegisterImpl( | 100 virtual void RegisterImpl( |
| 91 const std::string& app_id, | 101 const std::string& app_id, |
| 92 const std::vector<std::string>& sender_ids) OVERRIDE; | 102 const std::vector<std::string>& sender_ids) OVERRIDE; |
| 93 virtual void UnregisterImpl(const std::string& app_id) OVERRIDE; | 103 virtual void UnregisterImpl(const std::string& app_id) OVERRIDE; |
| 94 virtual void SendImpl(const std::string& app_id, | 104 virtual void SendImpl(const std::string& app_id, |
| 95 const std::string& receiver_id, | 105 const std::string& receiver_id, |
| 96 const GCMClient::OutgoingMessage& message) OVERRIDE; | 106 const GCMClient::OutgoingMessage& message) OVERRIDE; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 118 void MessageSendError(const std::string& app_id, | 128 void MessageSendError(const std::string& app_id, |
| 119 const GCMClient::SendErrorDetails& send_error_details); | 129 const GCMClient::SendErrorDetails& send_error_details); |
| 120 void SendAcknowledged(const std::string& app_id, | 130 void SendAcknowledged(const std::string& app_id, |
| 121 const std::string& message_id); | 131 const std::string& message_id); |
| 122 void GCMClientReady(); | 132 void GCMClientReady(); |
| 123 void OnConnected(const net::IPEndPoint& ip_endpoint); | 133 void OnConnected(const net::IPEndPoint& ip_endpoint); |
| 124 void OnDisconnected(); | 134 void OnDisconnected(); |
| 125 | 135 |
| 126 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); | 136 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); |
| 127 | 137 |
| 138 scoped_ptr<GCMChannelStatusSyncer> gcm_channel_status_syncer_; |
| 139 |
| 128 // Flag to indicate whether the user is signed in to a GAIA account. | 140 // Flag to indicate whether the user is signed in to a GAIA account. |
| 129 // TODO(jianli): To be removed when sign-in enforcement is dropped. | 141 // TODO(jianli): To be removed when sign-in enforcement is dropped. |
| 130 bool signed_in_; | 142 bool signed_in_; |
| 131 | 143 |
| 132 // Flag to indicate if GCM is started. | 144 // Flag to indicate if GCM is started. |
| 133 bool gcm_started_; | 145 bool gcm_started_; |
| 134 | 146 |
| 135 // Flag to indicate if GCM is enabled. | 147 // Flag to indicate if GCM is enabled. |
| 148 // TODO(jianli): Removed when we switch completely to support all users. |
| 136 bool gcm_enabled_; | 149 bool gcm_enabled_; |
| 137 | 150 |
| 138 // Flag to indicate the last known state of the GCM client. Because this | 151 // Flag to indicate the last known state of the GCM client. Because this |
| 139 // flag lives on the UI thread, while the GCM client lives on the IO thread, | 152 // flag lives on the UI thread, while the GCM client lives on the IO thread, |
| 140 // it may be out of date while connection changes are happening. | 153 // it may be out of date while connection changes are happening. |
| 141 bool connected_; | 154 bool connected_; |
| 142 | 155 |
| 143 // List of observers to notify when connection state changes. | 156 // List of observers to notify when connection state changes. |
| 144 // Makes sure list is empty on destruction. | 157 // Makes sure list is empty on destruction. |
| 145 ObserverList<GCMConnectionObserver, true> connection_observer_list_; | 158 ObserverList<GCMConnectionObserver, true> connection_observer_list_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 158 | 171 |
| 159 // Used to pass a weak pointer to the IO worker. | 172 // Used to pass a weak pointer to the IO worker. |
| 160 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; | 173 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; |
| 161 | 174 |
| 162 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); | 175 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); |
| 163 }; | 176 }; |
| 164 | 177 |
| 165 } // namespace gcm | 178 } // namespace gcm |
| 166 | 179 |
| 167 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ | 180 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ |
| OLD | NEW |