| 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 |
| 59 // Android. |
| 60 // TODO(jianli): Switch to using GCM's unsubscribe API. |
| 61 // |app_id|: application ID. |
| 62 // |sender_id|: the sender ID that was passed when registering. |
| 63 // |callback|: to be called once the asynchronous operation is done. |
| 64 void UnregisterWithSenderId(const std::string& app_id, |
| 65 const std::string& sender_id, |
| 66 const UnregisterCallback& callback); |
| 67 |
| 57 // Sends a message to a given receiver. | 68 // Sends a message to a given receiver. |
| 58 // |app_id|: application ID. | 69 // |app_id|: application ID. |
| 59 // |receiver_id|: registration ID of the receiver party. | 70 // |receiver_id|: registration ID of the receiver party. |
| 60 // |message|: message to be sent. | 71 // |message|: message to be sent. |
| 61 // |callback|: to be called once the asynchronous operation is done. | 72 // |callback|: to be called once the asynchronous operation is done. |
| 62 void Send(const std::string& app_id, | 73 void Send(const std::string& app_id, |
| 63 const std::string& receiver_id, | 74 const std::string& receiver_id, |
| 64 const GCMClient::OutgoingMessage& message, | 75 const GCMClient::OutgoingMessage& message, |
| 65 const SendCallback& callback); | 76 const SendCallback& callback); |
| 66 | 77 |
| (...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). | 150 // Ensures that the GCM service starts (if necessary conditions are met). |
| 140 virtual GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) = 0; | 151 virtual GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) = 0; |
| 141 | 152 |
| 142 // Platform-specific implementation of Register. | 153 // Platform-specific implementation of Register. |
| 143 virtual void RegisterImpl(const std::string& app_id, | 154 virtual void RegisterImpl(const std::string& app_id, |
| 144 const std::vector<std::string>& sender_ids) = 0; | 155 const std::vector<std::string>& sender_ids) = 0; |
| 145 | 156 |
| 146 // Platform-specific implementation of Unregister. | 157 // Platform-specific implementation of Unregister. |
| 147 virtual void UnregisterImpl(const std::string& app_id) = 0; | 158 virtual void UnregisterImpl(const std::string& app_id) = 0; |
| 148 | 159 |
| 160 // Platform-specific implementation of UnregisterWithSenderId. |
| 161 virtual void UnregisterWithSenderIdImpl(const std::string& app_id, |
| 162 const std::string& sender_id); |
| 163 |
| 149 // Platform-specific implementation of Send. | 164 // Platform-specific implementation of Send. |
| 150 virtual void SendImpl(const std::string& app_id, | 165 virtual void SendImpl(const std::string& app_id, |
| 151 const std::string& receiver_id, | 166 const std::string& receiver_id, |
| 152 const GCMClient::OutgoingMessage& message) = 0; | 167 const GCMClient::OutgoingMessage& message) = 0; |
| 153 | 168 |
| 154 // Runs the Register callback. | 169 // Runs the Register callback. |
| 155 void RegisterFinished(const std::string& app_id, | 170 void RegisterFinished(const std::string& app_id, |
| 156 const std::string& registration_id, | 171 const std::string& registration_id, |
| 157 GCMClient::Result result); | 172 GCMClient::Result result); |
| 158 | 173 |
| 159 // Runs the Unregister callback. | 174 // Runs the Unregister callback. |
| 160 void UnregisterFinished(const std::string& app_id, | 175 void UnregisterFinished(const std::string& app_id, |
| 161 GCMClient::Result result); | 176 GCMClient::Result result); |
| 162 | 177 |
| 163 // Runs the Send callback. | 178 // Runs the Send callback. |
| 164 void SendFinished(const std::string& app_id, | 179 void SendFinished(const std::string& app_id, |
| 165 const std::string& message_id, | 180 const std::string& message_id, |
| 166 GCMClient::Result result); | 181 GCMClient::Result result); |
| 167 | 182 |
| 168 bool HasRegisterCallback(const std::string& app_id); | 183 bool HasRegisterCallback(const std::string& app_id); |
| 169 | 184 |
| 170 void ClearCallbacks(); | 185 void ClearCallbacks(); |
| 171 | 186 |
| 172 private: | 187 private: |
| 188 // Common code shared by Unregister and UnregisterWithSenderId. |
| 189 void UnregisterInternal(const std::string& app_id, |
| 190 const std::string* sender_id, |
| 191 const UnregisterCallback& callback); |
| 192 |
| 173 // Called after unregistration completes in order to trigger the pending | 193 // Called after unregistration completes in order to trigger the pending |
| 174 // registration. | 194 // registration. |
| 175 void RegisterAfterUnregister( | 195 void RegisterAfterUnregister( |
| 176 const std::string& app_id, | 196 const std::string& app_id, |
| 177 const std::vector<std::string>& normalized_sender_ids, | 197 const std::vector<std::string>& normalized_sender_ids, |
| 178 const UnregisterCallback& unregister_callback, | 198 const UnregisterCallback& unregister_callback, |
| 179 GCMClient::Result result); | 199 GCMClient::Result result); |
| 180 | 200 |
| 181 // Callback map (from app_id to callback) for Register. | 201 // Callback map (from app_id to callback) for Register. |
| 182 std::map<std::string, RegisterCallback> register_callbacks_; | 202 std::map<std::string, RegisterCallback> register_callbacks_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 195 DefaultGCMAppHandler default_app_handler_; | 215 DefaultGCMAppHandler default_app_handler_; |
| 196 | 216 |
| 197 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; | 217 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; |
| 198 | 218 |
| 199 DISALLOW_COPY_AND_ASSIGN(GCMDriver); | 219 DISALLOW_COPY_AND_ASSIGN(GCMDriver); |
| 200 }; | 220 }; |
| 201 | 221 |
| 202 } // namespace gcm | 222 } // namespace gcm |
| 203 | 223 |
| 204 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ | 224 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ |
| OLD | NEW |