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_ACCOUNT_MAPPER_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ |
6 #define COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ | 6 #define COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
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/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "components/gcm_driver/gcm_app_handler.h" | 15 #include "components/gcm_driver/gcm_app_handler.h" |
16 #include "components/gcm_driver/gcm_client.h" | 16 #include "components/gcm_driver/gcm_client.h" |
| 17 #include "components/gcm_driver/gcm_message_status.h" |
17 #include "google_apis/gcm/engine/account_mapping.h" | 18 #include "google_apis/gcm/engine/account_mapping.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class Clock; | 21 class Clock; |
21 } | 22 } |
22 | 23 |
23 namespace gcm { | 24 namespace gcm { |
24 | 25 |
25 class GCMDriver; | 26 class GCMDriver; |
26 extern const char kGCMAccountMapperAppId[]; | 27 extern const char kGCMAccountMapperAppId[]; |
27 | 28 |
28 // Class for mapping signed-in GAIA accounts to the GCM Device ID. | 29 // Class for mapping signed-in GAIA accounts to the GCM Device ID. |
29 class GCMAccountMapper : public GCMAppHandler { | 30 class GCMAccountMapper : public GCMAppHandler { |
30 public: | 31 public: |
31 // List of account mappings. | 32 // List of account mappings. |
32 typedef std::vector<AccountMapping> AccountMappings; | 33 using AccountMappings = std::vector<AccountMapping>; |
33 typedef base::Callback<void(const std::string& app_id, | 34 using DispatchMessageCallback = base::Callback<void( |
34 const IncomingMessage& message)> | 35 const std::string& app_id, |
35 DispatchMessageCallback; | 36 const IncomingMessage& message, |
| 37 const MessageReceiptCallback& optional_receipt_callback)>; |
36 | 38 |
37 explicit GCMAccountMapper(GCMDriver* gcm_driver); | 39 explicit GCMAccountMapper(GCMDriver* gcm_driver); |
38 ~GCMAccountMapper() override; | 40 ~GCMAccountMapper() override; |
39 | 41 |
40 void Initialize(const AccountMappings& account_mappings, | 42 void Initialize(const AccountMappings& account_mappings, |
41 const DispatchMessageCallback& callback); | 43 const DispatchMessageCallback& callback); |
42 | 44 |
43 // Called by AccountTracker, when a new list of account tokens is available. | 45 // Called by AccountTracker, when a new list of account tokens is available. |
44 // This will cause a refresh of account mappings and sending updates to GCM. | 46 // This will cause a refresh of account mappings and sending updates to GCM. |
45 void SetAccountTokens( | 47 void SetAccountTokens( |
46 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); | 48 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); |
47 | 49 |
48 // Implementation of GCMAppHandler: | 50 // Implementation of GCMAppHandler: |
49 void ShutdownHandler() override; | 51 void ShutdownHandler() override; |
50 void OnStoreReset() override; | 52 void OnStoreReset() override; |
51 void OnMessage(const std::string& app_id, | 53 void OnMessage(const std::string& app_id, |
52 const IncomingMessage& message) override; | 54 const IncomingMessage& message) override; |
53 void OnMessagesDeleted(const std::string& app_id) override; | 55 void OnMessagesDeleted(const std::string& app_id) override; |
54 void OnSendError( | 56 void OnSendError( |
55 const std::string& app_id, | 57 const std::string& app_id, |
56 const GCMClient::SendErrorDetails& send_error_details) override; | 58 const GCMClient::SendErrorDetails& send_error_details) override; |
57 void OnSendAcknowledged(const std::string& app_id, | 59 void OnSendAcknowledged(const std::string& app_id, |
58 const std::string& message_id) override; | 60 const std::string& message_id) override; |
59 bool CanHandle(const std::string& app_id) const override; | 61 bool CanHandle(const std::string& app_id) const override; |
60 | 62 |
61 private: | 63 private: |
62 friend class GCMAccountMapperTest; | 64 friend class GCMAccountMapperTest; |
63 | 65 |
64 typedef std::map<std::string, OutgoingMessage> OutgoingMessages; | 66 using OutgoingMessages = std::map<std::string, OutgoingMessage>; |
65 | 67 |
66 // Checks whether account mapper is ready to process new account tokens. | 68 // Checks whether account mapper is ready to process new account tokens. |
67 bool IsReady(); | 69 bool IsReady(); |
68 | 70 |
69 // Informs GCM of an added or refreshed account mapping. | 71 // Informs GCM of an added or refreshed account mapping. |
70 void SendAddMappingMessage(AccountMapping& account_mapping); | 72 void SendAddMappingMessage(AccountMapping& account_mapping); |
71 | 73 |
72 // Informs GCM of a removed account mapping. | 74 // Informs GCM of a removed account mapping. |
73 void SendRemoveMappingMessage(AccountMapping& account_mapping); | 75 void SendRemoveMappingMessage(AccountMapping& account_mapping); |
74 | 76 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 bool initialized_; | 127 bool initialized_; |
126 | 128 |
127 base::WeakPtrFactory<GCMAccountMapper> weak_ptr_factory_; | 129 base::WeakPtrFactory<GCMAccountMapper> weak_ptr_factory_; |
128 | 130 |
129 DISALLOW_COPY_AND_ASSIGN(GCMAccountMapper); | 131 DISALLOW_COPY_AND_ASSIGN(GCMAccountMapper); |
130 }; | 132 }; |
131 | 133 |
132 } // namespace gcm | 134 } // namespace gcm |
133 | 135 |
134 #endif // COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ | 136 #endif // COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ |
OLD | NEW |