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> |
(...skipping 19 matching lines...) Expand all Loading... | |
30 GCMClient::Result result)> RegisterCallback; | 30 GCMClient::Result result)> RegisterCallback; |
31 typedef base::Callback<void(const std::string& message_id, | 31 typedef base::Callback<void(const std::string& message_id, |
32 GCMClient::Result result)> SendCallback; | 32 GCMClient::Result result)> SendCallback; |
33 typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback; | 33 typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback; |
34 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> | 34 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> |
35 GetGCMStatisticsCallback; | 35 GetGCMStatisticsCallback; |
36 | 36 |
37 GCMDriver(); | 37 GCMDriver(); |
38 virtual ~GCMDriver(); | 38 virtual ~GCMDriver(); |
39 | 39 |
40 // Registers |sender_id| for an app. A registration ID will be returned by | 40 // Registers |sender_ids| for an app. A registration ID will be returned by |
41 // the GCM server. | 41 // the GCM server. On Android, only a single sender ID is supported, but |
42 // instead multiple simultaneous registrations are allowed. | |
42 // |app_id|: application ID. | 43 // |app_id|: application ID. |
43 // |sender_ids|: list of IDs of the servers that are allowed to send the | 44 // |sender_ids|: list of IDs of the servers that are allowed to send the |
44 // messages to the application. These IDs are assigned by the | 45 // messages to the application. These IDs are assigned by the |
45 // Google API Console. | 46 // Google API Console. |
46 // |callback|: to be called once the asynchronous operation is done. | 47 // |callback|: to be called once the asynchronous operation is done. |
47 void Register(const std::string& app_id, | 48 void Register(const std::string& app_id, |
48 const std::vector<std::string>& sender_ids, | 49 const std::vector<std::string>& sender_ids, |
49 const RegisterCallback& callback); | 50 const RegisterCallback& callback); |
50 | 51 |
51 // Unregisters an app from using GCM. | 52 // Unregisters all sender_ids for an app. Only works on non-Android. |
52 // |app_id|: application ID. | 53 // |app_id|: application ID. |
53 // |callback|: to be called once the asynchronous operation is done. | 54 // |callback|: to be called once the asynchronous operation is done. |
54 void Unregister(const std::string& app_id, | 55 void Unregister(const std::string& app_id, |
55 const UnregisterCallback& callback); | 56 const UnregisterCallback& callback); |
56 | 57 |
58 // Unregisters an app_id,sender_id pair from using GCM. Only works on Android. | |
jianli
2015/02/17 23:02:27
nit: "(app_id, sender)" or "app_id and sender_id"
johnme
2015/02/17 23:10:11
Done.
| |
59 // TODO(jianli): Switch to using GCM's unsubscribe API. | |
60 // |app_id|: application ID. | |
61 // |sender_id|: the sender ID that was passed when registering. | |
62 // |callback|: to be called once the asynchronous operation is done. | |
63 void UnregisterWithSenderId(const std::string& app_id, | |
64 const std::string& sender_id, | |
65 const UnregisterCallback& callback); | |
66 | |
57 // Sends a message to a given receiver. | 67 // Sends a message to a given receiver. |
58 // |app_id|: application ID. | 68 // |app_id|: application ID. |
59 // |receiver_id|: registration ID of the receiver party. | 69 // |receiver_id|: registration ID of the receiver party. |
60 // |message|: message to be sent. | 70 // |message|: message to be sent. |
61 // |callback|: to be called once the asynchronous operation is done. | 71 // |callback|: to be called once the asynchronous operation is done. |
62 void Send(const std::string& app_id, | 72 void Send(const std::string& app_id, |
63 const std::string& receiver_id, | 73 const std::string& receiver_id, |
64 const GCMClient::OutgoingMessage& message, | 74 const GCMClient::OutgoingMessage& message, |
65 const SendCallback& callback); | 75 const SendCallback& callback); |
66 | 76 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 // Ensures that the GCM service starts (if necessary conditions are met). | 149 // Ensures that the GCM service starts (if necessary conditions are met). |
140 virtual GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) = 0; | 150 virtual GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) = 0; |
141 | 151 |
142 // Platform-specific implementation of Register. | 152 // Platform-specific implementation of Register. |
143 virtual void RegisterImpl(const std::string& app_id, | 153 virtual void RegisterImpl(const std::string& app_id, |
144 const std::vector<std::string>& sender_ids) = 0; | 154 const std::vector<std::string>& sender_ids) = 0; |
145 | 155 |
146 // Platform-specific implementation of Unregister. | 156 // Platform-specific implementation of Unregister. |
147 virtual void UnregisterImpl(const std::string& app_id) = 0; | 157 virtual void UnregisterImpl(const std::string& app_id) = 0; |
148 | 158 |
159 // Platform-specific implementation of UnregisterWithSenderId. | |
160 virtual void UnregisterWithSenderIdImpl(const std::string& app_id, | |
161 const std::string& sender_id); | |
162 | |
149 // Platform-specific implementation of Send. | 163 // Platform-specific implementation of Send. |
150 virtual void SendImpl(const std::string& app_id, | 164 virtual void SendImpl(const std::string& app_id, |
151 const std::string& receiver_id, | 165 const std::string& receiver_id, |
152 const GCMClient::OutgoingMessage& message) = 0; | 166 const GCMClient::OutgoingMessage& message) = 0; |
153 | 167 |
154 // Runs the Register callback. | 168 // Runs the Register callback. |
155 void RegisterFinished(const std::string& app_id, | 169 void RegisterFinished(const std::string& app_id, |
156 const std::string& registration_id, | 170 const std::string& registration_id, |
157 GCMClient::Result result); | 171 GCMClient::Result result); |
158 | 172 |
159 // Runs the Unregister callback. | 173 // Runs the Unregister callback. |
160 void UnregisterFinished(const std::string& app_id, | 174 void UnregisterFinished(const std::string& app_id, |
161 GCMClient::Result result); | 175 GCMClient::Result result); |
162 | 176 |
163 // Runs the Send callback. | 177 // Runs the Send callback. |
164 void SendFinished(const std::string& app_id, | 178 void SendFinished(const std::string& app_id, |
165 const std::string& message_id, | 179 const std::string& message_id, |
166 GCMClient::Result result); | 180 GCMClient::Result result); |
167 | 181 |
168 bool HasRegisterCallback(const std::string& app_id); | 182 bool HasRegisterCallback(const std::string& app_id); |
169 | 183 |
170 void ClearCallbacks(); | 184 void ClearCallbacks(); |
171 | 185 |
172 private: | 186 private: |
187 // Common code shared by Unregister and UnregisterWithSenderId. | |
188 void UnregisterInternal(const std::string& app_id, | |
189 const std::string* sender_id, | |
190 const UnregisterCallback& callback); | |
191 | |
173 // Called after unregistration completes in order to trigger the pending | 192 // Called after unregistration completes in order to trigger the pending |
174 // registration. | 193 // registration. |
175 void RegisterAfterUnregister( | 194 void RegisterAfterUnregister( |
176 const std::string& app_id, | 195 const std::string& app_id, |
177 const std::vector<std::string>& normalized_sender_ids, | 196 const std::vector<std::string>& normalized_sender_ids, |
178 const UnregisterCallback& unregister_callback, | 197 const UnregisterCallback& unregister_callback, |
179 GCMClient::Result result); | 198 GCMClient::Result result); |
180 | 199 |
181 // Callback map (from app_id to callback) for Register. | 200 // Callback map (from app_id to callback) for Register. |
182 std::map<std::string, RegisterCallback> register_callbacks_; | 201 std::map<std::string, RegisterCallback> register_callbacks_; |
(...skipping 12 matching lines...) Expand all Loading... | |
195 DefaultGCMAppHandler default_app_handler_; | 214 DefaultGCMAppHandler default_app_handler_; |
196 | 215 |
197 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; | 216 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; |
198 | 217 |
199 DISALLOW_COPY_AND_ASSIGN(GCMDriver); | 218 DISALLOW_COPY_AND_ASSIGN(GCMDriver); |
200 }; | 219 }; |
201 | 220 |
202 } // namespace gcm | 221 } // namespace gcm |
203 | 222 |
204 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ | 223 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ |
OLD | NEW |