Chromium Code Reviews| Index: components/gcm_driver/gcm_account_mapper.h |
| diff --git a/components/gcm_driver/gcm_account_mapper.h b/components/gcm_driver/gcm_account_mapper.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..812a0a12eb1a3a2233217bc72ec8e5a9c573eed8 |
| --- /dev/null |
| +++ b/components/gcm_driver/gcm_account_mapper.h |
| @@ -0,0 +1,116 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ |
| +#define COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/gcm_driver/gcm_app_handler.h" |
| +#include "components/gcm_driver/gcm_client.h" |
| +#include "google_apis/gcm/engine/account_mapping.h" |
| + |
| +namespace base { |
| +class Clock; |
| +} |
| + |
| +namespace gcm { |
| + |
| +class GCMDriver; |
| + |
| +// 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.
|
| +class GCMAccountMapper : public GCMAppHandler { |
| + public: |
| + // List of account mappings. |
| + typedef std::vector<AccountMapping> AccountMappings; |
| + |
| + explicit GCMAccountMapper(GCMDriver* gcm_driver); |
| + virtual ~GCMAccountMapper(); |
| + |
| + // Initializes a list of mappings with |account_mappings| and sets the |
| + // |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.
|
| + void Initialize(const AccountMappings& account_mappings, |
| + const std::string& registration_id); |
| + |
| + // Refreshes a list of accounts present in the system, providing them with |
| + // 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.
|
| + void SetAccountTokens( |
| + const std::vector<GCMClient::AccountTokenInfo> account_tokens); |
| + |
| + // Implementation of GCMAppHandler: |
| + virtual void ShutdownHandler() OVERRIDE; |
| + virtual void OnMessage(const std::string& app_id, |
| + const GCMClient::IncomingMessage& message) OVERRIDE; |
| + virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; |
| + virtual void OnSendError( |
| + const std::string& app_id, |
| + const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; |
| + virtual void OnSendAcknowledged(const std::string& app_id, |
| + const std::string& message_id) OVERRIDE; |
| + virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE; |
| + virtual void OnDisconnected() OVERRIDE; |
| + virtual bool CanHandle(const std::string& app_id) const OVERRIDE; |
| + |
| + private: |
| + friend class GCMAccountMapperTest; |
| + |
| + typedef std::map<std::string, GCMClient::OutgoingMessage> OutgoingMessages; |
| + |
| + // 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.
|
| + void SendAddMappingMessage(AccountMapping& account_mapping); |
| + |
| + // 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.
|
| + void SendRemoveMappingMessage(AccountMapping& account_mapping); |
| + |
| + // Callback for sending a message. |
| + void OnSendFinished(const std::string& account_id, |
| + AccountMapping::MessageType message_type, |
| + const std::string& message_id, |
| + GCMClient::Result result); |
| + |
| + // Checks whether the update can be triggered now, or if it is OK to wait |
| + // 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.
|
| + bool IsUpdateDue(const base::Time& last_update_time) const; |
| + |
| + // Checks whether last status change is older than a TTL of a message. |
| + bool IsLastStatusChangeOlderThanTTL( |
| + const base::Time& estimated_send_time) const; |
| + |
| + // Finds an account mapping in |accounts_| by |account_id|. |
| + AccountMapping* FindMappingByAccountId(const std::string& account_id); |
| + // Finds an account mapping in |accounts_| by |message_id|. |
| + // Returns iterator that can be used to delete the account. |
| + AccountMappings::iterator FindMappingByMessageId( |
| + const std::string& message_id); |
| + |
| + // Sets the clock for testing. |
| + void SetClockForTesting(scoped_ptr<base::Clock> clock); |
| + |
| + // GCMDriver owns AccountMapper. |
|
jianli
2014/08/28 18:43:52
AccountMapper => GCMAccountMapper
fgorski
2014/08/29 02:29:18
Done.
|
| + GCMDriver* gcm_driver_; |
| + |
| + // Clock for timestamping status changes. |
| + scoped_ptr<base::Clock> clock_; |
| + |
| + // Currnetly tracked account mappings. |
| + AccountMappings accounts_; |
| + |
| + // GCM Registration ID of the account mapper. |
| + std::string registration_id_; |
| + |
| + // 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.
|
| + bool initialized_; |
| + |
| + base::WeakPtrFactory<GCMAccountMapper> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(GCMAccountMapper); |
| +}; |
| + |
| +} // namespace gcm |
| + |
| +#endif // COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ |