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