Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ | |
| 6 #define COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "components/gcm_driver/gcm_app_handler.h" | |
| 15 #include "components/gcm_driver/gcm_client.h" | |
| 16 #include "google_apis/gcm/engine/account_mapping.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class Clock; | |
| 20 } | |
| 21 | |
| 22 namespace gcm { | |
| 23 | |
| 24 class GCMDriver; | |
| 25 | |
| 26 // Class for mapping signed in GAIA accounts to the GCM Device ID. | |
|
jianli
2014/08/28 18:43:52
nit: signed-in
fgorski
2014/08/29 02:29:17
Done.
| |
| 27 class GCMAccountMapper : public GCMAppHandler { | |
| 28 public: | |
| 29 // List of account mappings. | |
| 30 typedef std::vector<AccountMapping> AccountMappings; | |
| 31 | |
| 32 explicit GCMAccountMapper(GCMDriver* gcm_driver); | |
| 33 virtual ~GCMAccountMapper(); | |
| 34 | |
| 35 // Initializes a list of mappings with |account_mappings| and sets the | |
| 36 // |registration_id| for the mapper, if it was previously registered with GCM. | |
|
jianli
2014/08/28 18:43:51
Probably no need to comment since the method name
fgorski
2014/08/29 02:29:18
Done.
| |
| 37 void Initialize(const AccountMappings& account_mappings, | |
| 38 const std::string& registration_id); | |
| 39 | |
| 40 // Refreshes a list of accounts present in the system, providing them with | |
| 41 // corresponding access tokens. | |
|
jianli
2014/08/28 18:43:51
Probably better to comment on when this is called,
fgorski
2014/08/29 02:29:18
Done.
| |
| 42 void SetAccountTokens( | |
| 43 const std::vector<GCMClient::AccountTokenInfo> account_tokens); | |
| 44 | |
| 45 // Implementation of GCMAppHandler: | |
| 46 virtual void ShutdownHandler() OVERRIDE; | |
| 47 virtual void OnMessage(const std::string& app_id, | |
| 48 const GCMClient::IncomingMessage& message) OVERRIDE; | |
| 49 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; | |
| 50 virtual void OnSendError( | |
| 51 const std::string& app_id, | |
| 52 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; | |
| 53 virtual void OnSendAcknowledged(const std::string& app_id, | |
| 54 const std::string& message_id) OVERRIDE; | |
| 55 virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE; | |
| 56 virtual void OnDisconnected() OVERRIDE; | |
| 57 virtual bool CanHandle(const std::string& app_id) const OVERRIDE; | |
| 58 | |
| 59 private: | |
| 60 friend class GCMAccountMapperTest; | |
| 61 | |
| 62 typedef std::map<std::string, GCMClient::OutgoingMessage> OutgoingMessages; | |
| 63 | |
| 64 // Sends a mapping message to GCM for the |account_mapping|. | |
|
jianli
2014/08/28 18:43:52
Probably simpler to say:
// Informs the GCM to a
fgorski
2014/08/29 02:29:18
Done.
| |
| 65 void SendAddMappingMessage(AccountMapping& account_mapping); | |
| 66 | |
| 67 // Sends a message removing the mapping from GCM for the |account_mapping|. | |
|
jianli
2014/08/28 18:43:52
ditto
// Informs the GCM to remove an account ma
fgorski
2014/08/29 02:29:18
Done.
| |
| 68 void SendRemoveMappingMessage(AccountMapping& account_mapping); | |
| 69 | |
| 70 // Callback for sending a message. | |
| 71 void OnSendFinished(const std::string& account_id, | |
| 72 AccountMapping::MessageType message_type, | |
| 73 const std::string& message_id, | |
| 74 GCMClient::Result result); | |
| 75 | |
| 76 // Checks whether the update can be triggered now, or if it is OK to wait | |
| 77 // until next time the token for account arrives. | |
|
jianli
2014/08/28 18:43:51
The part before or and after or are contradicted.
fgorski
2014/08/29 02:29:18
Done.
| |
| 78 bool IsUpdateDue(const base::Time& last_update_time) const; | |
| 79 | |
| 80 // Checks whether last status change is older than a TTL of a message. | |
| 81 bool IsLastStatusChangeOlderThanTTL( | |
| 82 const base::Time& estimated_send_time) const; | |
| 83 | |
| 84 // Finds an account mapping in |accounts_| by |account_id|. | |
| 85 AccountMapping* FindMappingByAccountId(const std::string& account_id); | |
| 86 // Finds an account mapping in |accounts_| by |message_id|. | |
| 87 // Returns iterator that can be used to delete the account. | |
| 88 AccountMappings::iterator FindMappingByMessageId( | |
| 89 const std::string& message_id); | |
| 90 | |
| 91 // Sets the clock for testing. | |
| 92 void SetClockForTesting(scoped_ptr<base::Clock> clock); | |
| 93 | |
| 94 // GCMDriver owns AccountMapper. | |
|
jianli
2014/08/28 18:43:52
AccountMapper => GCMAccountMapper
fgorski
2014/08/29 02:29:18
Done.
| |
| 95 GCMDriver* gcm_driver_; | |
| 96 | |
| 97 // Clock for timestamping status changes. | |
| 98 scoped_ptr<base::Clock> clock_; | |
| 99 | |
| 100 // Currnetly tracked account mappings. | |
| 101 AccountMappings accounts_; | |
| 102 | |
| 103 // GCM Registration ID of the account mapper. | |
| 104 std::string registration_id_; | |
| 105 | |
| 106 // Is the account tracker initialized. | |
|
jianli
2014/08/28 18:43:52
account tracker or mapper? Probably no need to add
fgorski
2014/08/29 02:29:18
Done.
| |
| 107 bool initialized_; | |
| 108 | |
| 109 base::WeakPtrFactory<GCMAccountMapper> weak_ptr_factory_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(GCMAccountMapper); | |
| 112 }; | |
| 113 | |
| 114 } // namespace gcm | |
| 115 | |
| 116 #endif // COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ | |
| OLD | NEW |