| 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 "base/tuple.h" |
| 18 #include "components/gcm_driver/gcm_channel_status_syncer.h" | 19 #include "components/gcm_driver/gcm_channel_status_syncer.h" |
| 19 #include "components/gcm_driver/gcm_client.h" | 20 #include "components/gcm_driver/gcm_client.h" |
| 20 #include "components/gcm_driver/gcm_connection_observer.h" | 21 #include "components/gcm_driver/gcm_connection_observer.h" |
| 21 #include "components/gcm_driver/gcm_driver.h" | 22 #include "components/gcm_driver/gcm_driver.h" |
| 22 | 23 |
| 23 class PrefService; | 24 class PrefService; |
| 24 | 25 |
| 25 namespace base { | 26 namespace base { |
| 26 class FilePath; | 27 class FilePath; |
| 27 class SequencedTaskRunner; | 28 class SequencedTaskRunner; |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace extensions { | 31 namespace extensions { |
| 31 class ExtensionGCMAppHandlerTest; | 32 class ExtensionGCMAppHandlerTest; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace net { | 35 namespace net { |
| 35 class URLRequestContextGetter; | 36 class URLRequestContextGetter; |
| 36 } | 37 } |
| 37 | 38 |
| 38 namespace gcm { | 39 namespace gcm { |
| 39 | 40 |
| 40 class GCMAccountMapper; | 41 class GCMAccountMapper; |
| 41 class GCMAppHandler; | 42 class GCMAppHandler; |
| 42 class GCMClientFactory; | 43 class GCMClientFactory; |
| 43 class GCMDelayedTaskController; | 44 class GCMDelayedTaskController; |
| 44 | 45 |
| 45 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. | 46 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. |
| 46 class GCMDriverDesktop : public GCMDriver, | 47 class GCMDriverDesktop : public GCMDriver, |
| 47 public InstanceIDStore { | 48 public InstanceIDHandler { |
| 48 public: | 49 public: |
| 49 GCMDriverDesktop( | 50 GCMDriverDesktop( |
| 50 scoped_ptr<GCMClientFactory> gcm_client_factory, | 51 scoped_ptr<GCMClientFactory> gcm_client_factory, |
| 51 const GCMClient::ChromeBuildInfo& chrome_build_info, | 52 const GCMClient::ChromeBuildInfo& chrome_build_info, |
| 52 const std::string& channel_status_request_url, | 53 const std::string& channel_status_request_url, |
| 53 const std::string& user_agent, | 54 const std::string& user_agent, |
| 54 PrefService* prefs, | 55 PrefService* prefs, |
| 55 const base::FilePath& store_path, | 56 const base::FilePath& store_path, |
| 56 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 57 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| 57 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 58 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 77 bool clear_logs) override; | 78 bool clear_logs) override; |
| 78 void SetGCMRecording(const GetGCMStatisticsCallback& callback, | 79 void SetGCMRecording(const GetGCMStatisticsCallback& callback, |
| 79 bool recording) override; | 80 bool recording) override; |
| 80 void SetAccountTokens( | 81 void SetAccountTokens( |
| 81 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) override; | 82 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) override; |
| 82 void UpdateAccountMapping(const AccountMapping& account_mapping) override; | 83 void UpdateAccountMapping(const AccountMapping& account_mapping) override; |
| 83 void RemoveAccountMapping(const std::string& account_id) override; | 84 void RemoveAccountMapping(const std::string& account_id) override; |
| 84 base::Time GetLastTokenFetchTime() override; | 85 base::Time GetLastTokenFetchTime() override; |
| 85 void SetLastTokenFetchTime(const base::Time& time) override; | 86 void SetLastTokenFetchTime(const base::Time& time) override; |
| 86 void WakeFromSuspendForHeartbeat(bool wake) override; | 87 void WakeFromSuspendForHeartbeat(bool wake) override; |
| 87 InstanceIDStore* GetInstanceIDStore() override; | 88 InstanceIDHandler* GetInstanceIDHandler() override; |
| 88 | 89 |
| 89 // InstanceIDStore overrides: | 90 // InstanceIDHandler overrides: |
| 91 void GetToken(const std::string& app_id, |
| 92 const std::string& authorized_entity, |
| 93 const std::string& scope, |
| 94 const std::map<std::string, std::string>& options, |
| 95 const GetTokenCallback& callback) override; |
| 96 void DeleteToken(const std::string& app_id, |
| 97 const std::string& authorized_entity, |
| 98 const std::string& scope, |
| 99 const DeleteTokenCallback& callback) override; |
| 90 void AddInstanceIDData(const std::string& app_id, | 100 void AddInstanceIDData(const std::string& app_id, |
| 91 const std::string& instance_id_data) override; | 101 const std::string& instance_id_data) override; |
| 92 void RemoveInstanceIDData(const std::string& app_id) override; | 102 void RemoveInstanceIDData(const std::string& app_id) override; |
| 93 void GetInstanceIDData(const std::string& app_id, | 103 void GetInstanceIDData(const std::string& app_id, |
| 94 const GetInstanceIDDataCallback& callback) override; | 104 const GetInstanceIDDataCallback& callback) override; |
| 95 | 105 |
| 96 // Exposed for testing purpose. | 106 // Exposed for testing purpose. |
| 97 bool gcm_enabled() const { return gcm_enabled_; } | 107 bool gcm_enabled() const { return gcm_enabled_; } |
| 98 GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() { | 108 GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() { |
| 99 return gcm_channel_status_syncer_.get(); | 109 return gcm_channel_status_syncer_.get(); |
| 100 } | 110 } |
| 101 | 111 |
| 102 protected: | 112 protected: |
| 103 // GCMDriver implementation: | 113 // GCMDriver implementation: |
| 104 GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) override; | 114 GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) override; |
| 105 void RegisterImpl(const std::string& app_id, | 115 void RegisterImpl(const std::string& app_id, |
| 106 const std::vector<std::string>& sender_ids) override; | 116 const std::vector<std::string>& sender_ids) override; |
| 107 void UnregisterImpl(const std::string& app_id) override; | 117 void UnregisterImpl(const std::string& app_id) override; |
| 108 void SendImpl(const std::string& app_id, | 118 void SendImpl(const std::string& app_id, |
| 109 const std::string& receiver_id, | 119 const std::string& receiver_id, |
| 110 const GCMClient::OutgoingMessage& message) override; | 120 const GCMClient::OutgoingMessage& message) override; |
| 111 | 121 |
| 112 private: | 122 private: |
| 113 class IOWorker; | 123 class IOWorker; |
| 114 | 124 |
| 125 typedef Tuple<std::string, std::string, std::string> TokenTuple; |
| 126 struct TokenTupleComparer { |
| 127 bool operator()(const TokenTuple& a, const TokenTuple& b) const; |
| 128 }; |
| 129 |
| 115 // Stops the GCM service. It can be restarted by calling EnsureStarted again. | 130 // Stops the GCM service. It can be restarted by calling EnsureStarted again. |
| 116 void Stop(); | 131 void Stop(); |
| 117 | 132 |
| 118 // Remove cached data when GCM service is stopped. | 133 // Remove cached data when GCM service is stopped. |
| 119 void RemoveCachedData(); | 134 void RemoveCachedData(); |
| 120 | 135 |
| 121 void DoRegister(const std::string& app_id, | 136 void DoRegister(const std::string& app_id, |
| 122 const std::vector<std::string>& sender_ids); | 137 const std::vector<std::string>& sender_ids); |
| 123 void DoUnregister(const std::string& app_id); | 138 void DoUnregister(const std::string& app_id); |
| 124 void DoSend(const std::string& app_id, | 139 void DoSend(const std::string& app_id, |
| 125 const std::string& receiver_id, | 140 const std::string& receiver_id, |
| 126 const GCMClient::OutgoingMessage& message); | 141 const GCMClient::OutgoingMessage& message); |
| 127 | 142 |
| 128 // Callbacks posted from IO thread to UI thread. | 143 // Callbacks posted from IO thread to UI thread. |
| 129 void MessageReceived(const std::string& app_id, | 144 void MessageReceived(const std::string& app_id, |
| 130 const GCMClient::IncomingMessage& message); | 145 const GCMClient::IncomingMessage& message); |
| 131 void MessagesDeleted(const std::string& app_id); | 146 void MessagesDeleted(const std::string& app_id); |
| 132 void MessageSendError(const std::string& app_id, | 147 void MessageSendError(const std::string& app_id, |
| 133 const GCMClient::SendErrorDetails& send_error_details); | 148 const GCMClient::SendErrorDetails& send_error_details); |
| 134 void SendAcknowledged(const std::string& app_id, | 149 void SendAcknowledged(const std::string& app_id, |
| 135 const std::string& message_id); | 150 const std::string& message_id); |
| 136 void GCMClientReady(const std::vector<AccountMapping>& account_mappings, | 151 void GCMClientReady(const std::vector<AccountMapping>& account_mappings, |
| 137 const base::Time& last_token_fetch_time); | 152 const base::Time& last_token_fetch_time); |
| 138 void OnConnected(const net::IPEndPoint& ip_endpoint); | 153 void OnConnected(const net::IPEndPoint& ip_endpoint); |
| 139 void OnDisconnected(); | 154 void OnDisconnected(); |
| 140 | 155 |
| 141 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); | 156 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); |
| 142 void GetInstanceIDDataFinished(const std::string& app_id, | 157 void GetInstanceIDDataFinished(const std::string& app_id, |
| 143 const std::string& instance_id_data); | 158 const std::string& instance_id_data); |
| 159 void GetTokenFinished(const std::string& app_id, |
| 160 const std::string& authorized_entity, |
| 161 const std::string& scope, |
| 162 const std::string& registration_id, |
| 163 GCMClient::Result result); |
| 164 void DeleteTokenFinished(const std::string& app_id, |
| 165 const std::string& authorized_entity, |
| 166 const std::string& scope, |
| 167 GCMClient::Result result); |
| 144 | 168 |
| 145 scoped_ptr<GCMChannelStatusSyncer> gcm_channel_status_syncer_; | 169 scoped_ptr<GCMChannelStatusSyncer> gcm_channel_status_syncer_; |
| 146 | 170 |
| 147 // Flag to indicate whether the user is signed in to a GAIA account. | 171 // Flag to indicate whether the user is signed in to a GAIA account. |
| 148 bool signed_in_; | 172 bool signed_in_; |
| 149 | 173 |
| 150 // Flag to indicate if GCM is started. | 174 // Flag to indicate if GCM is started. |
| 151 bool gcm_started_; | 175 bool gcm_started_; |
| 152 | 176 |
| 153 // Flag to indicate if GCM is enabled. | 177 // Flag to indicate if GCM is enabled. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 180 // thread. | 204 // thread. |
| 181 scoped_ptr<IOWorker> io_worker_; | 205 scoped_ptr<IOWorker> io_worker_; |
| 182 | 206 |
| 183 // Callback for GetGCMStatistics. | 207 // Callback for GetGCMStatistics. |
| 184 GetGCMStatisticsCallback request_gcm_statistics_callback_; | 208 GetGCMStatisticsCallback request_gcm_statistics_callback_; |
| 185 | 209 |
| 186 // Callbacks for GetInstanceIDData. | 210 // Callbacks for GetInstanceIDData. |
| 187 std::map<std::string, GetInstanceIDDataCallback> | 211 std::map<std::string, GetInstanceIDDataCallback> |
| 188 get_instance_id_data_callbacks_; | 212 get_instance_id_data_callbacks_; |
| 189 | 213 |
| 214 // Callbacks for GetToken/DeleteToken. |
| 215 std::map<TokenTuple, GetTokenCallback, TokenTupleComparer> |
| 216 get_token_callbacks_; |
| 217 std::map<TokenTuple, DeleteTokenCallback, TokenTupleComparer> |
| 218 delete_token_callbacks_; |
| 219 |
| 190 // Used to pass a weak pointer to the IO worker. | 220 // Used to pass a weak pointer to the IO worker. |
| 191 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; | 221 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; |
| 192 | 222 |
| 193 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); | 223 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); |
| 194 }; | 224 }; |
| 195 | 225 |
| 196 } // namespace gcm | 226 } // namespace gcm |
| 197 | 227 |
| 198 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ | 228 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ |
| OLD | NEW |