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_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ |
6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ | 6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_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/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "components/gcm_driver/default_gcm_app_handler.h" | 16 #include "components/gcm_driver/default_gcm_app_handler.h" |
17 #include "components/gcm_driver/gcm_client.h" | 17 #include "components/gcm_driver/gcm_client.h" |
18 | 18 |
19 namespace gcm { | 19 namespace gcm { |
20 | 20 |
21 class GCMAppHandler; | 21 class GCMAppHandler; |
22 class GCMConnectionObserver; | 22 class GCMConnectionObserver; |
23 struct AccountMapping; | 23 struct AccountMapping; |
24 | 24 |
25 // Provides the capability to set/get InstanceID data in the GCM store. | 25 // Provides the InstanceID support via GCMDriver. |
26 class InstanceIDStore { | 26 class InstanceIDHandler { |
27 public: | 27 public: |
28 typedef base::Callback<void(const std::string& instance_id_data)> | 28 typedef base::Callback<void(const std::string& token, |
| 29 GCMClient::Result result)> GetTokenCallback; |
| 30 typedef base::Callback<void(GCMClient::Result result)> DeleteTokenCallback; |
| 31 typedef base::Callback<void(const std::string& instance_id, |
| 32 const std::string& extra_data)> |
29 GetInstanceIDDataCallback; | 33 GetInstanceIDDataCallback; |
30 | 34 |
31 InstanceIDStore(); | 35 InstanceIDHandler(); |
32 virtual ~InstanceIDStore(); | 36 virtual ~InstanceIDHandler(); |
33 | 37 |
| 38 // Token service. |
| 39 virtual void GetToken(const std::string& app_id, |
| 40 const std::string& authorized_entity, |
| 41 const std::string& scope, |
| 42 const std::map<std::string, std::string>& options, |
| 43 const GetTokenCallback& callback) = 0; |
| 44 virtual void DeleteToken(const std::string& app_id, |
| 45 const std::string& authorized_entity, |
| 46 const std::string& scope, |
| 47 const DeleteTokenCallback& callback) = 0; |
| 48 |
| 49 // Persistence support. |
34 virtual void AddInstanceIDData(const std::string& app_id, | 50 virtual void AddInstanceIDData(const std::string& app_id, |
35 const std::string& instance_id_data) = 0; | 51 const std::string& instance_id, |
| 52 const std::string& extra_data) = 0; |
36 virtual void RemoveInstanceIDData(const std::string& app_id) = 0; | 53 virtual void RemoveInstanceIDData(const std::string& app_id) = 0; |
37 virtual void GetInstanceIDData( | 54 virtual void GetInstanceIDData( |
38 const std::string& app_id, | 55 const std::string& app_id, |
39 const GetInstanceIDDataCallback& callback) = 0; | 56 const GetInstanceIDDataCallback& callback) = 0; |
40 | 57 |
41 private: | 58 private: |
42 DISALLOW_COPY_AND_ASSIGN(InstanceIDStore); | 59 DISALLOW_COPY_AND_ASSIGN(InstanceIDHandler); |
43 }; | 60 }; |
44 | 61 |
45 // Bridge between GCM users in Chrome and the platform-specific implementation. | 62 // Bridge between GCM users in Chrome and the platform-specific implementation. |
46 class GCMDriver { | 63 class GCMDriver { |
47 public: | 64 public: |
48 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; | 65 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; |
49 typedef base::Callback<void(const std::string& registration_id, | 66 typedef base::Callback<void(const std::string& registration_id, |
50 GCMClient::Result result)> RegisterCallback; | 67 GCMClient::Result result)> RegisterCallback; |
51 typedef base::Callback<void(const std::string& message_id, | 68 typedef base::Callback<void(const std::string& message_id, |
52 GCMClient::Result result)> SendCallback; | 69 GCMClient::Result result)> SendCallback; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 virtual void RemoveAccountMapping(const std::string& account_id) = 0; | 176 virtual void RemoveAccountMapping(const std::string& account_id) = 0; |
160 | 177 |
161 // Getter and setter of last token fetch time. | 178 // Getter and setter of last token fetch time. |
162 virtual base::Time GetLastTokenFetchTime() = 0; | 179 virtual base::Time GetLastTokenFetchTime() = 0; |
163 virtual void SetLastTokenFetchTime(const base::Time& time) = 0; | 180 virtual void SetLastTokenFetchTime(const base::Time& time) = 0; |
164 | 181 |
165 // Sets whether or not GCM should try to wake the system from suspend in order | 182 // Sets whether or not GCM should try to wake the system from suspend in order |
166 // to send a heartbeat message. | 183 // to send a heartbeat message. |
167 virtual void WakeFromSuspendForHeartbeat(bool wake) = 0; | 184 virtual void WakeFromSuspendForHeartbeat(bool wake) = 0; |
168 | 185 |
169 // Supports saving the Instance ID data in the GCM store. | 186 // Supports InstanceID handling. |
170 virtual InstanceIDStore* GetInstanceIDStore() = 0; | 187 virtual InstanceIDHandler* GetInstanceIDHandler() = 0; |
171 | 188 |
172 // Adds or removes a custom client requested heartbeat interval. If multiple | 189 // Adds or removes a custom client requested heartbeat interval. If multiple |
173 // components set that setting, the lowest setting will be used. If the | 190 // components set that setting, the lowest setting will be used. If the |
174 // setting is outside of GetMax/MinClientHeartbeatIntervalMs() it will be | 191 // setting is outside of GetMax/MinClientHeartbeatIntervalMs() it will be |
175 // ignored. If a new setting is less than the currently used, the connection | 192 // ignored. If a new setting is less than the currently used, the connection |
176 // will be reset with the new heartbeat. Client that no longer require | 193 // will be reset with the new heartbeat. Client that no longer require |
177 // aggressive heartbeats, should remove their requested interval. Heartbeats | 194 // aggressive heartbeats, should remove their requested interval. Heartbeats |
178 // set this way survive connection/Chrome restart. | 195 // set this way survive connection/Chrome restart. |
179 // | 196 // |
180 // GCM Driver can decide to postpone the action until Client is properly | 197 // GCM Driver can decide to postpone the action until Client is properly |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 DefaultGCMAppHandler default_app_handler_; | 277 DefaultGCMAppHandler default_app_handler_; |
261 | 278 |
262 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; | 279 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; |
263 | 280 |
264 DISALLOW_COPY_AND_ASSIGN(GCMDriver); | 281 DISALLOW_COPY_AND_ASSIGN(GCMDriver); |
265 }; | 282 }; |
266 | 283 |
267 } // namespace gcm | 284 } // namespace gcm |
268 | 285 |
269 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ | 286 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ |
OLD | NEW |