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 void AddHeartbeatInterval(const std::string& scope, int interval_ms) override; | 89 void AddHeartbeatInterval(const std::string& scope, int interval_ms) override; |
89 void RemoveHeartbeatInterval(const std::string& scope) override; | 90 void RemoveHeartbeatInterval(const std::string& scope) override; |
90 | 91 |
91 // InstanceIDStore overrides: | 92 // InstanceIDHandler overrides: |
| 93 void GetToken(const std::string& app_id, |
| 94 const std::string& authorized_entity, |
| 95 const std::string& scope, |
| 96 const std::map<std::string, std::string>& options, |
| 97 const GetTokenCallback& callback) override; |
| 98 void DeleteToken(const std::string& app_id, |
| 99 const std::string& authorized_entity, |
| 100 const std::string& scope, |
| 101 const DeleteTokenCallback& callback) override; |
92 void AddInstanceIDData(const std::string& app_id, | 102 void AddInstanceIDData(const std::string& app_id, |
93 const std::string& instance_id_data) override; | 103 const std::string& instance_id, |
| 104 const std::string& extra_data) override; |
94 void RemoveInstanceIDData(const std::string& app_id) override; | 105 void RemoveInstanceIDData(const std::string& app_id) override; |
95 void GetInstanceIDData(const std::string& app_id, | 106 void GetInstanceIDData(const std::string& app_id, |
96 const GetInstanceIDDataCallback& callback) override; | 107 const GetInstanceIDDataCallback& callback) override; |
97 | 108 |
98 // Exposed for testing purpose. | 109 // Exposed for testing purpose. |
99 bool gcm_enabled() const { return gcm_enabled_; } | 110 bool gcm_enabled() const { return gcm_enabled_; } |
100 GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() { | 111 GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() { |
101 return gcm_channel_status_syncer_.get(); | 112 return gcm_channel_status_syncer_.get(); |
102 } | 113 } |
103 | 114 |
104 protected: | 115 protected: |
105 // GCMDriver implementation: | 116 // GCMDriver implementation: |
106 GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) override; | 117 GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) override; |
107 void RegisterImpl(const std::string& app_id, | 118 void RegisterImpl(const std::string& app_id, |
108 const std::vector<std::string>& sender_ids) override; | 119 const std::vector<std::string>& sender_ids) override; |
109 void UnregisterImpl(const std::string& app_id) override; | 120 void UnregisterImpl(const std::string& app_id) override; |
110 void SendImpl(const std::string& app_id, | 121 void SendImpl(const std::string& app_id, |
111 const std::string& receiver_id, | 122 const std::string& receiver_id, |
112 const GCMClient::OutgoingMessage& message) override; | 123 const GCMClient::OutgoingMessage& message) override; |
113 | 124 |
114 private: | 125 private: |
115 class IOWorker; | 126 class IOWorker; |
116 | 127 |
| 128 typedef Tuple<std::string, std::string, std::string> TokenTuple; |
| 129 struct TokenTupleComparer { |
| 130 bool operator()(const TokenTuple& a, const TokenTuple& b) const; |
| 131 }; |
| 132 |
117 // Stops the GCM service. It can be restarted by calling EnsureStarted again. | 133 // Stops the GCM service. It can be restarted by calling EnsureStarted again. |
118 void Stop(); | 134 void Stop(); |
119 | 135 |
120 // Remove cached data when GCM service is stopped. | 136 // Remove cached data when GCM service is stopped. |
121 void RemoveCachedData(); | 137 void RemoveCachedData(); |
122 | 138 |
123 void DoRegister(const std::string& app_id, | 139 void DoRegister(const std::string& app_id, |
124 const std::vector<std::string>& sender_ids); | 140 const std::vector<std::string>& sender_ids); |
125 void DoUnregister(const std::string& app_id); | 141 void DoUnregister(const std::string& app_id); |
126 void DoSend(const std::string& app_id, | 142 void DoSend(const std::string& app_id, |
127 const std::string& receiver_id, | 143 const std::string& receiver_id, |
128 const GCMClient::OutgoingMessage& message); | 144 const GCMClient::OutgoingMessage& message); |
129 | 145 |
130 // Callbacks posted from IO thread to UI thread. | 146 // Callbacks posted from IO thread to UI thread. |
131 void MessageReceived(const std::string& app_id, | 147 void MessageReceived(const std::string& app_id, |
132 const GCMClient::IncomingMessage& message); | 148 const GCMClient::IncomingMessage& message); |
133 void MessagesDeleted(const std::string& app_id); | 149 void MessagesDeleted(const std::string& app_id); |
134 void MessageSendError(const std::string& app_id, | 150 void MessageSendError(const std::string& app_id, |
135 const GCMClient::SendErrorDetails& send_error_details); | 151 const GCMClient::SendErrorDetails& send_error_details); |
136 void SendAcknowledged(const std::string& app_id, | 152 void SendAcknowledged(const std::string& app_id, |
137 const std::string& message_id); | 153 const std::string& message_id); |
138 void GCMClientReady(const std::vector<AccountMapping>& account_mappings, | 154 void GCMClientReady(const std::vector<AccountMapping>& account_mappings, |
139 const base::Time& last_token_fetch_time); | 155 const base::Time& last_token_fetch_time); |
140 void OnConnected(const net::IPEndPoint& ip_endpoint); | 156 void OnConnected(const net::IPEndPoint& ip_endpoint); |
141 void OnDisconnected(); | 157 void OnDisconnected(); |
142 | 158 |
143 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); | 159 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); |
144 void GetInstanceIDDataFinished(const std::string& app_id, | 160 void GetInstanceIDDataFinished(const std::string& app_id, |
145 const std::string& instance_id_data); | 161 const std::string& instance_id, |
| 162 const std::string& extra_data); |
| 163 void GetTokenFinished(const std::string& app_id, |
| 164 const std::string& authorized_entity, |
| 165 const std::string& scope, |
| 166 const std::string& token, |
| 167 GCMClient::Result result); |
| 168 void DeleteTokenFinished(const std::string& app_id, |
| 169 const std::string& authorized_entity, |
| 170 const std::string& scope, |
| 171 GCMClient::Result result); |
146 | 172 |
147 scoped_ptr<GCMChannelStatusSyncer> gcm_channel_status_syncer_; | 173 scoped_ptr<GCMChannelStatusSyncer> gcm_channel_status_syncer_; |
148 | 174 |
149 // Flag to indicate whether the user is signed in to a GAIA account. | 175 // Flag to indicate whether the user is signed in to a GAIA account. |
150 bool signed_in_; | 176 bool signed_in_; |
151 | 177 |
152 // Flag to indicate if GCM is started. | 178 // Flag to indicate if GCM is started. |
153 bool gcm_started_; | 179 bool gcm_started_; |
154 | 180 |
155 // Flag to indicate if GCM is enabled. | 181 // Flag to indicate if GCM is enabled. |
(...skipping 26 matching lines...) Expand all Loading... |
182 // thread. | 208 // thread. |
183 scoped_ptr<IOWorker> io_worker_; | 209 scoped_ptr<IOWorker> io_worker_; |
184 | 210 |
185 // Callback for GetGCMStatistics. | 211 // Callback for GetGCMStatistics. |
186 GetGCMStatisticsCallback request_gcm_statistics_callback_; | 212 GetGCMStatisticsCallback request_gcm_statistics_callback_; |
187 | 213 |
188 // Callbacks for GetInstanceIDData. | 214 // Callbacks for GetInstanceIDData. |
189 std::map<std::string, GetInstanceIDDataCallback> | 215 std::map<std::string, GetInstanceIDDataCallback> |
190 get_instance_id_data_callbacks_; | 216 get_instance_id_data_callbacks_; |
191 | 217 |
| 218 // Callbacks for GetToken/DeleteToken. |
| 219 std::map<TokenTuple, GetTokenCallback, TokenTupleComparer> |
| 220 get_token_callbacks_; |
| 221 std::map<TokenTuple, DeleteTokenCallback, TokenTupleComparer> |
| 222 delete_token_callbacks_; |
| 223 |
192 // Used to pass a weak pointer to the IO worker. | 224 // Used to pass a weak pointer to the IO worker. |
193 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; | 225 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; |
194 | 226 |
195 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); | 227 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); |
196 }; | 228 }; |
197 | 229 |
198 } // namespace gcm | 230 } // namespace gcm |
199 | 231 |
200 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ | 232 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ |
OLD | NEW |