| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "components/gcm_driver/gcm_app_handler.h" | 15 #include "components/gcm_driver/gcm_app_handler.h" |
| 15 #include "components/gcm_driver/gcm_client.h" | 16 #include "components/gcm_driver/gcm_client.h" |
| 16 #include "google_apis/gcm/engine/account_mapping.h" | 17 #include "google_apis/gcm/engine/account_mapping.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class Clock; | 20 class Clock; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace gcm { | 23 namespace gcm { |
| 23 | 24 |
| 24 class GCMDriver; | 25 class GCMDriver; |
| 25 extern const char kGCMAccountMapperAppId[]; | 26 extern const char kGCMAccountMapperAppId[]; |
| 26 | 27 |
| 27 // Class for mapping signed-in GAIA accounts to the GCM Device ID. | 28 // Class for mapping signed-in GAIA accounts to the GCM Device ID. |
| 28 class GCMAccountMapper : public GCMAppHandler { | 29 class GCMAccountMapper : public GCMAppHandler { |
| 29 public: | 30 public: |
| 30 // List of account mappings. | 31 // List of account mappings. |
| 31 typedef std::vector<AccountMapping> AccountMappings; | 32 typedef std::vector<AccountMapping> AccountMappings; |
| 33 typedef base::Callback<void(const std::string& app_id, |
| 34 const GCMClient::IncomingMessage& message)> |
| 35 DispatchMessageCallback; |
| 32 | 36 |
| 33 explicit GCMAccountMapper(GCMDriver* gcm_driver); | 37 explicit GCMAccountMapper(GCMDriver* gcm_driver); |
| 34 ~GCMAccountMapper() override; | 38 ~GCMAccountMapper() override; |
| 35 | 39 |
| 36 void Initialize(const AccountMappings& account_mappings); | 40 void Initialize(const AccountMappings& account_mappings, |
| 41 const DispatchMessageCallback& callback); |
| 37 | 42 |
| 38 // Called by AccountTracker, when a new list of account tokens is available. | 43 // Called by AccountTracker, when a new list of account tokens is available. |
| 39 // This will cause a refresh of account mappings and sending updates to GCM. | 44 // This will cause a refresh of account mappings and sending updates to GCM. |
| 40 void SetAccountTokens( | 45 void SetAccountTokens( |
| 41 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); | 46 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); |
| 42 | 47 |
| 43 // Implementation of GCMAppHandler: | 48 // Implementation of GCMAppHandler: |
| 44 void ShutdownHandler() override; | 49 void ShutdownHandler() override; |
| 45 void OnMessage(const std::string& app_id, | 50 void OnMessage(const std::string& app_id, |
| 46 const GCMClient::IncomingMessage& message) override; | 51 const GCMClient::IncomingMessage& message) override; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // Returns iterator that can be used to delete the account. | 100 // Returns iterator that can be used to delete the account. |
| 96 AccountMappings::iterator FindMappingByMessageId( | 101 AccountMappings::iterator FindMappingByMessageId( |
| 97 const std::string& message_id); | 102 const std::string& message_id); |
| 98 | 103 |
| 99 // Sets the clock for testing. | 104 // Sets the clock for testing. |
| 100 void SetClockForTesting(scoped_ptr<base::Clock> clock); | 105 void SetClockForTesting(scoped_ptr<base::Clock> clock); |
| 101 | 106 |
| 102 // GCMDriver owns GCMAccountMapper. | 107 // GCMDriver owns GCMAccountMapper. |
| 103 GCMDriver* gcm_driver_; | 108 GCMDriver* gcm_driver_; |
| 104 | 109 |
| 110 // Callback to GCMDriver to dispatch messages sent to Gaia ID. |
| 111 DispatchMessageCallback dispatch_message_callback_; |
| 112 |
| 105 // Clock for timestamping status changes. | 113 // Clock for timestamping status changes. |
| 106 scoped_ptr<base::Clock> clock_; | 114 scoped_ptr<base::Clock> clock_; |
| 107 | 115 |
| 108 // Currnetly tracked account mappings. | 116 // Currnetly tracked account mappings. |
| 109 AccountMappings accounts_; | 117 AccountMappings accounts_; |
| 110 | 118 |
| 111 std::vector<GCMClient::AccountTokenInfo> pending_account_tokens_; | 119 std::vector<GCMClient::AccountTokenInfo> pending_account_tokens_; |
| 112 | 120 |
| 113 // GCM Registration ID of the account mapper. | 121 // GCM Registration ID of the account mapper. |
| 114 std::string registration_id_; | 122 std::string registration_id_; |
| 115 | 123 |
| 116 bool initialized_; | 124 bool initialized_; |
| 117 | 125 |
| 118 base::WeakPtrFactory<GCMAccountMapper> weak_ptr_factory_; | 126 base::WeakPtrFactory<GCMAccountMapper> weak_ptr_factory_; |
| 119 | 127 |
| 120 DISALLOW_COPY_AND_ASSIGN(GCMAccountMapper); | 128 DISALLOW_COPY_AND_ASSIGN(GCMAccountMapper); |
| 121 }; | 129 }; |
| 122 | 130 |
| 123 } // namespace gcm | 131 } // namespace gcm |
| 124 | 132 |
| 125 #endif // COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ | 133 #endif // COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ |
| OLD | NEW |