| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // Removes all the cached and persisted GCM data. If the GCM service is | 74 // Removes all the cached and persisted GCM data. If the GCM service is |
| 75 // restarted after the purge, a new Android ID will be obtained. | 75 // restarted after the purge, a new Android ID will be obtained. |
| 76 virtual void Purge() = 0; | 76 virtual void Purge() = 0; |
| 77 | 77 |
| 78 // Adds a handler for a given app. | 78 // Adds a handler for a given app. |
| 79 virtual void AddAppHandler(const std::string& app_id, GCMAppHandler* handler); | 79 virtual void AddAppHandler(const std::string& app_id, GCMAppHandler* handler); |
| 80 | 80 |
| 81 // Remove the handler for a given app. | 81 // Remove the handler for a given app. |
| 82 virtual void RemoveAppHandler(const std::string& app_id); | 82 virtual void RemoveAppHandler(const std::string& app_id); |
| 83 | 83 |
| 84 // Returns the handler for the given app. |
| 85 GCMAppHandler* GetAppHandler(const std::string& app_id); |
| 86 |
| 84 // Enables/disables GCM service. | 87 // Enables/disables GCM service. |
| 85 virtual void Enable() = 0; | 88 virtual void Enable() = 0; |
| 86 virtual void Disable() = 0; | 89 virtual void Disable() = 0; |
| 87 | 90 |
| 88 // For testing purpose. Always NULL on Android. | 91 // For testing purpose. Always NULL on Android. |
| 89 virtual GCMClient* GetGCMClientForTesting() const = 0; | 92 virtual GCMClient* GetGCMClientForTesting() const = 0; |
| 90 | 93 |
| 91 // Returns true if the service was started. | 94 // Returns true if the service was started. |
| 92 virtual bool IsStarted() const = 0; | 95 virtual bool IsStarted() const = 0; |
| 93 | 96 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 137 |
| 135 // Runs the Send callback. | 138 // Runs the Send callback. |
| 136 void SendFinished(const std::string& app_id, | 139 void SendFinished(const std::string& app_id, |
| 137 const std::string& message_id, | 140 const std::string& message_id, |
| 138 GCMClient::Result result); | 141 GCMClient::Result result); |
| 139 | 142 |
| 140 bool HasRegisterCallback(const std::string& app_id); | 143 bool HasRegisterCallback(const std::string& app_id); |
| 141 | 144 |
| 142 void ClearCallbacks(); | 145 void ClearCallbacks(); |
| 143 | 146 |
| 144 // Returns the handler for the given app. | |
| 145 GCMAppHandler* GetAppHandler(const std::string& app_id); | |
| 146 | |
| 147 private: | 147 private: |
| 148 // Should be called when an app with |app_id| is trying to un/register. | 148 // Should be called when an app with |app_id| is trying to un/register. |
| 149 // Checks whether another un/registration is in progress. | 149 // Checks whether another un/registration is in progress. |
| 150 bool IsAsyncOperationPending(const std::string& app_id) const; | 150 bool IsAsyncOperationPending(const std::string& app_id) const; |
| 151 | 151 |
| 152 // Callback map (from app_id to callback) for Register. | 152 // Callback map (from app_id to callback) for Register. |
| 153 std::map<std::string, RegisterCallback> register_callbacks_; | 153 std::map<std::string, RegisterCallback> register_callbacks_; |
| 154 | 154 |
| 155 // Callback map (from app_id to callback) for Unregister. | 155 // Callback map (from app_id to callback) for Unregister. |
| 156 std::map<std::string, UnregisterCallback> unregister_callbacks_; | 156 std::map<std::string, UnregisterCallback> unregister_callbacks_; |
| 157 | 157 |
| 158 // Callback map (from <app_id, message_id> to callback) for Send. | 158 // Callback map (from <app_id, message_id> to callback) for Send. |
| 159 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; | 159 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; |
| 160 | 160 |
| 161 // App handler map (from app_id to handler pointer). | 161 // App handler map (from app_id to handler pointer). |
| 162 // The handler is not owned. | 162 // The handler is not owned. |
| 163 GCMAppHandlerMap app_handlers_; | 163 GCMAppHandlerMap app_handlers_; |
| 164 | 164 |
| 165 // The default handler when no app handler can be found in the map. | 165 // The default handler when no app handler can be found in the map. |
| 166 DefaultGCMAppHandler default_app_handler_; | 166 DefaultGCMAppHandler default_app_handler_; |
| 167 | 167 |
| 168 DISALLOW_COPY_AND_ASSIGN(GCMDriver); | 168 DISALLOW_COPY_AND_ASSIGN(GCMDriver); |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 } // namespace gcm | 171 } // namespace gcm |
| 172 | 172 |
| 173 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ | 173 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ |
| OLD | NEW |