Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 41 // the GCM server. | 41 // the GCM server. |
| 42 // |app_id|: application ID. | 42 // |app_id|: application ID. |
| 43 // |sender_ids|: list of IDs of the servers that are allowed to send the | 43 // |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 | 44 // messages to the application. These IDs are assigned by the |
| 45 // Google API Console. | 45 // Google API Console. |
| 46 // |callback|: to be called once the asynchronous operation is done. | 46 // |callback|: to be called once the asynchronous operation is done. |
| 47 void Register(const std::string& app_id, | 47 void Register(const std::string& app_id, |
| 48 const std::vector<std::string>& sender_ids, | 48 const std::vector<std::string>& sender_ids, |
| 49 const RegisterCallback& callback); | 49 const RegisterCallback& callback); |
| 50 | 50 |
| 51 // Unregisters an app from using GCM. | 51 // Unregisters an app from using GCM. Only works on non-Android; use |
| 52 // UnregisterWithSenderId instead on 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 from using GCM, explicitly providing a single sender ID. | |
|
jianli
2015/02/17 19:17:39
Please comment that this only applies to Android.
johnme
2015/02/17 21:24:07
Done.
| |
| 59 // (Use normal Unregister if you registered with multiple sender IDs). | |
|
Peter Beverloo
2015/02/17 18:49:36
nit: I don't think this line adds much value.
Ins
johnme
2015/02/17 21:24:07
Done.
| |
| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 147 |
| 138 protected: | 148 protected: |
| 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, |
| 158 const std::string* maybe_sender_id) = 0; | |
|
Peter Beverloo
2015/02/17 18:49:36
nit: |maybe_sender_id| is a const pointer, it's cl
Peter Beverloo
2015/02/17 18:49:36
Since behavior of Android and non-Android is diffe
jianli
2015/02/17 19:17:39
Yes please have two platform-specific implementati
johnme
2015/02/17 21:24:07
Done.
johnme
2015/02/17 21:24:07
Done.
johnme
2015/02/17 21:24:07
Done.
| |
| 148 | 159 |
| 149 // Platform-specific implementation of Send. | 160 // Platform-specific implementation of Send. |
| 150 virtual void SendImpl(const std::string& app_id, | 161 virtual void SendImpl(const std::string& app_id, |
| 151 const std::string& receiver_id, | 162 const std::string& receiver_id, |
| 152 const GCMClient::OutgoingMessage& message) = 0; | 163 const GCMClient::OutgoingMessage& message) = 0; |
| 153 | 164 |
| 154 // Runs the Register callback. | 165 // Runs the Register callback. |
| 155 void RegisterFinished(const std::string& app_id, | 166 void RegisterFinished(const std::string& app_id, |
| 156 const std::string& registration_id, | 167 const std::string& registration_id, |
| 157 GCMClient::Result result); | 168 GCMClient::Result result); |
| 158 | 169 |
| 159 // Runs the Unregister callback. | 170 // Runs the Unregister callback. |
| 160 void UnregisterFinished(const std::string& app_id, | 171 void UnregisterFinished(const std::string& app_id, |
| 161 GCMClient::Result result); | 172 GCMClient::Result result); |
| 162 | 173 |
| 163 // Runs the Send callback. | 174 // Runs the Send callback. |
| 164 void SendFinished(const std::string& app_id, | 175 void SendFinished(const std::string& app_id, |
| 165 const std::string& message_id, | 176 const std::string& message_id, |
| 166 GCMClient::Result result); | 177 GCMClient::Result result); |
| 167 | 178 |
| 168 bool HasRegisterCallback(const std::string& app_id); | 179 bool HasRegisterCallback(const std::string& app_id); |
| 169 | 180 |
| 170 void ClearCallbacks(); | 181 void ClearCallbacks(); |
| 171 | 182 |
| 172 private: | 183 private: |
| 184 // Common code shared by Unregister and UnregisterWithSenderId. | |
| 185 void UnregisterInternal(const std::string& app_id, | |
| 186 const std::string* maybe_sender_id, | |
| 187 const UnregisterCallback& callback); | |
| 188 | |
| 173 // Called after unregistration completes in order to trigger the pending | 189 // Called after unregistration completes in order to trigger the pending |
| 174 // registration. | 190 // registration. |
| 175 void RegisterAfterUnregister( | 191 void RegisterAfterUnregister( |
| 176 const std::string& app_id, | 192 const std::string& app_id, |
| 177 const std::vector<std::string>& normalized_sender_ids, | 193 const std::vector<std::string>& normalized_sender_ids, |
| 178 const UnregisterCallback& unregister_callback, | 194 const UnregisterCallback& unregister_callback, |
| 179 GCMClient::Result result); | 195 GCMClient::Result result); |
| 180 | 196 |
| 181 // Callback map (from app_id to callback) for Register. | 197 // Callback map (from app_id to callback) for Register. |
| 182 std::map<std::string, RegisterCallback> register_callbacks_; | 198 std::map<std::string, RegisterCallback> register_callbacks_; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 195 DefaultGCMAppHandler default_app_handler_; | 211 DefaultGCMAppHandler default_app_handler_; |
| 196 | 212 |
| 197 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; | 213 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; |
| 198 | 214 |
| 199 DISALLOW_COPY_AND_ASSIGN(GCMDriver); | 215 DISALLOW_COPY_AND_ASSIGN(GCMDriver); |
| 200 }; | 216 }; |
| 201 | 217 |
| 202 } // namespace gcm | 218 } // namespace gcm |
| 203 | 219 |
| 204 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ | 220 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ |
| OLD | NEW |