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..13e9d2a801f4b140e22dd343ced7a4c225ae51fa |
--- /dev/null |
+++ b/components/gcm_driver/gcm_account_mapper.h |
@@ -0,0 +1,97 @@ |
+// 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 GCMAccountMapper : public GCMAppHandler { |
+ public: |
+ typedef std::vector<AccountMapping> AccountMappings; |
+ |
+ GCMAccountMapper(GCMDriver* gcm_driver); |
jianli
2014/08/27 18:12:01
nit: add explicit
fgorski
2014/08/27 21:47:17
Done.
|
+ virtual ~GCMAccountMapper(); |
+ |
+ void Initialize(const AccountMappings& account_mappings, |
+ const std::string& registration_id); |
+ |
+ void SetAccountTokens( |
+ const std::vector<GCMClient::AccountTokenInfo> account_tokens); |
+ |
+ void AddAccountMapping(const GCMClient::AccountTokenInfo& account_token); |
+ void RemoveAccountMapping(const std::string& account_id); |
+ |
+ // 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; |
+ |
+ void SendAddMappingMessage(AccountMapping& account_mapping); |
+ void SendRemoveMappingMessage(AccountMapping& account_mapping); |
+ void OnSendFinished(const std::string& account_id, |
+ AccountMapping::MessageType message_type, |
+ const std::string& message_id, |
+ GCMClient::Result result); |
+ |
+ bool IsUpdateDue(const base::Time& last_update_time); |
jianli
2014/08/27 18:12:01
nit: add const modifier
fgorski
2014/08/27 21:47:17
Done.
|
+ bool IsMessageExpired(const base::Time& estimated_send_time); |
jianli
2014/08/27 18:12:01
ditto
fgorski
2014/08/27 21:47:17
Done.
|
+ |
+ AccountMapping* FindMappingByAccountId(const std::string& account_id); |
+ AccountMappings::iterator FindMappingByMessageId( |
+ const std::string& message_id); |
+ |
+ // Sets the clock for testing. |
+ void SetClockForTesting(scoped_ptr<base::Clock> clock); |
+ |
+ GCMDriver* gcm_driver_; |
jianli
2014/08/27 18:12:01
Comment that GCMDriver owns this instance.
fgorski
2014/08/27 21:47:17
Done.
|
+ |
+ scoped_ptr<base::Clock> clock_; |
+ |
+ AccountMappings accounts_; |
+ |
+ OutgoingMessages sent_messages_; |
+ |
+ std::string registration_id_; |
+ |
+ bool initialized_; |
+ |
+ base::WeakPtrFactory<GCMAccountMapper> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GCMAccountMapper); |
+}; |
+ |
+} // namespace gcm |
+ |
+#endif // COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ |