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> |
| 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/ref_counted.h" | |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 16 #include "components/gcm_driver/common/gcm_messages.h" | 17 #include "components/gcm_driver/common/gcm_messages.h" |
| 18 #include "components/gcm_driver/crypto/gcm_encryption_handler.h" | |
| 17 #include "components/gcm_driver/default_gcm_app_handler.h" | 19 #include "components/gcm_driver/default_gcm_app_handler.h" |
| 18 #include "components/gcm_driver/gcm_client.h" | 20 #include "components/gcm_driver/gcm_client.h" |
| 19 | 21 |
| 22 namespace base { | |
| 23 class FilePath; | |
| 24 class SequencedTaskRunner; | |
| 25 } | |
| 26 | |
| 20 namespace gcm { | 27 namespace gcm { |
| 21 | 28 |
| 22 class GCMAppHandler; | 29 class GCMAppHandler; |
| 23 class GCMConnectionObserver; | 30 class GCMConnectionObserver; |
| 24 struct AccountMapping; | 31 struct AccountMapping; |
| 25 | 32 |
| 26 // Provides the InstanceID support via GCMDriver. | 33 // Provides the InstanceID support via GCMDriver. |
| 27 class InstanceIDHandler { | 34 class InstanceIDHandler { |
| 28 public: | 35 public: |
| 29 typedef base::Callback<void(const std::string& token, | 36 typedef base::Callback<void(const std::string& token, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 public: | 76 public: |
| 70 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; | 77 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; |
| 71 typedef base::Callback<void(const std::string& registration_id, | 78 typedef base::Callback<void(const std::string& registration_id, |
| 72 GCMClient::Result result)> RegisterCallback; | 79 GCMClient::Result result)> RegisterCallback; |
| 73 typedef base::Callback<void(const std::string& message_id, | 80 typedef base::Callback<void(const std::string& message_id, |
| 74 GCMClient::Result result)> SendCallback; | 81 GCMClient::Result result)> SendCallback; |
| 75 typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback; | 82 typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback; |
| 76 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> | 83 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> |
| 77 GetGCMStatisticsCallback; | 84 GetGCMStatisticsCallback; |
| 78 | 85 |
| 79 GCMDriver(); | 86 GCMDriver( |
| 87 const base::FilePath& store_path, | |
| 88 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); | |
| 80 virtual ~GCMDriver(); | 89 virtual ~GCMDriver(); |
| 81 | 90 |
| 82 // Registers |sender_ids| for an app. A registration ID will be returned by | 91 // Registers |sender_ids| for an app. A registration ID will be returned by |
| 83 // the GCM server. On Android, only a single sender ID is supported, but | 92 // the GCM server. On Android, only a single sender ID is supported, but |
| 84 // instead multiple simultaneous registrations are allowed. | 93 // instead multiple simultaneous registrations are allowed. |
| 85 // |app_id|: application ID. | 94 // |app_id|: application ID. |
| 86 // |sender_ids|: list of IDs of the servers that are allowed to send the | 95 // |sender_ids|: list of IDs of the servers that are allowed to send the |
| 87 // messages to the application. These IDs are assigned by the | 96 // messages to the application. These IDs are assigned by the |
| 88 // Google API Console. | 97 // Google API Console. |
| 89 // |callback|: to be called once the asynchronous operation is done. | 98 // |callback|: to be called once the asynchronous operation is done. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 110 // Sends a message to a given receiver. | 119 // Sends a message to a given receiver. |
| 111 // |app_id|: application ID. | 120 // |app_id|: application ID. |
| 112 // |receiver_id|: registration ID of the receiver party. | 121 // |receiver_id|: registration ID of the receiver party. |
| 113 // |message|: message to be sent. | 122 // |message|: message to be sent. |
| 114 // |callback|: to be called once the asynchronous operation is done. | 123 // |callback|: to be called once the asynchronous operation is done. |
| 115 void Send(const std::string& app_id, | 124 void Send(const std::string& app_id, |
| 116 const std::string& receiver_id, | 125 const std::string& receiver_id, |
| 117 const OutgoingMessage& message, | 126 const OutgoingMessage& message, |
| 118 const SendCallback& callback); | 127 const SendCallback& callback); |
| 119 | 128 |
| 129 // Get the public encryption key associated with |app_id|. If no keys have | |
| 130 // been associated with |app_id| yet, they will be created. The |callback| | |
| 131 // will be invoked when it is available. | |
| 132 void GetPublicEncryptionKey( | |
|
jianli
2015/07/17 20:55:21
GetPublicKey
Peter Beverloo
2015/07/20 17:55:54
Done.
| |
| 133 const std::string& app_id, | |
| 134 const GCMEncryptionHandler::KeyCallback& callback); | |
|
jianli
2015/07/17 20:55:21
We should try avoid referring something defined in
Peter Beverloo
2015/07/20 17:55:54
Done.
| |
| 135 | |
| 120 const GCMAppHandlerMap& app_handlers() const { return app_handlers_; } | 136 const GCMAppHandlerMap& app_handlers() const { return app_handlers_; } |
| 121 | 137 |
| 122 // This method must be called before destroying the GCMDriver. Once it has | 138 // This method must be called before destroying the GCMDriver. Once it has |
| 123 // been called, no other GCMDriver methods may be used. | 139 // been called, no other GCMDriver methods may be used. |
| 124 virtual void Shutdown(); | 140 virtual void Shutdown(); |
| 125 | 141 |
| 126 // Called when the user signs in to or out of a GAIA account. | 142 // Called when the user signs in to or out of a GAIA account. |
| 127 virtual void OnSignedIn() = 0; | 143 virtual void OnSignedIn() = 0; |
| 128 virtual void OnSignedOut() = 0; | 144 virtual void OnSignedOut() = 0; |
| 129 | 145 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 | 283 |
| 268 // Callback map (from app_id to callback) for Register. | 284 // Callback map (from app_id to callback) for Register. |
| 269 std::map<std::string, RegisterCallback> register_callbacks_; | 285 std::map<std::string, RegisterCallback> register_callbacks_; |
| 270 | 286 |
| 271 // Callback map (from app_id to callback) for Unregister. | 287 // Callback map (from app_id to callback) for Unregister. |
| 272 std::map<std::string, UnregisterCallback> unregister_callbacks_; | 288 std::map<std::string, UnregisterCallback> unregister_callbacks_; |
| 273 | 289 |
| 274 // Callback map (from <app_id, message_id> to callback) for Send. | 290 // Callback map (from <app_id, message_id> to callback) for Send. |
| 275 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; | 291 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; |
| 276 | 292 |
| 293 // The encryption handler, used for key management and decryption of | |
| 294 // encrypted, incoming messages. | |
| 295 GCMEncryptionHandler encryption_handler_; | |
| 296 | |
| 277 // App handler map (from app_id to handler pointer). | 297 // App handler map (from app_id to handler pointer). |
| 278 // The handler is not owned. | 298 // The handler is not owned. |
| 279 GCMAppHandlerMap app_handlers_; | 299 GCMAppHandlerMap app_handlers_; |
| 280 | 300 |
| 281 // The default handler when no app handler can be found in the map. | 301 // The default handler when no app handler can be found in the map. |
| 282 DefaultGCMAppHandler default_app_handler_; | 302 DefaultGCMAppHandler default_app_handler_; |
| 283 | 303 |
| 284 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; | 304 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; |
| 285 | 305 |
| 286 DISALLOW_COPY_AND_ASSIGN(GCMDriver); | 306 DISALLOW_COPY_AND_ASSIGN(GCMDriver); |
| 287 }; | 307 }; |
| 288 | 308 |
| 289 } // namespace gcm | 309 } // namespace gcm |
| 290 | 310 |
| 291 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ | 311 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ |
| OLD | NEW |