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 GCMAccountMapper : public GCMAppHandler { | |
27 public: | |
28 typedef std::vector<AccountMapping> AccountMappings; | |
29 | |
30 GCMAccountMapper(GCMDriver* gcm_driver); | |
jianli
2014/08/27 18:12:01
nit: add explicit
fgorski
2014/08/27 21:47:17
Done.
| |
31 virtual ~GCMAccountMapper(); | |
32 | |
33 void Initialize(const AccountMappings& account_mappings, | |
34 const std::string& registration_id); | |
35 | |
36 void SetAccountTokens( | |
37 const std::vector<GCMClient::AccountTokenInfo> account_tokens); | |
38 | |
39 void AddAccountMapping(const GCMClient::AccountTokenInfo& account_token); | |
40 void RemoveAccountMapping(const std::string& account_id); | |
41 | |
42 // Implementation of GCMAppHandler: | |
43 virtual void ShutdownHandler() OVERRIDE; | |
44 virtual void OnMessage(const std::string& app_id, | |
45 const GCMClient::IncomingMessage& message) OVERRIDE; | |
46 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; | |
47 virtual void OnSendError( | |
48 const std::string& app_id, | |
49 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; | |
50 virtual void OnSendAcknowledged(const std::string& app_id, | |
51 const std::string& message_id) OVERRIDE; | |
52 virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE; | |
53 virtual void OnDisconnected() OVERRIDE; | |
54 virtual bool CanHandle(const std::string& app_id) const OVERRIDE; | |
55 | |
56 private: | |
57 friend class GCMAccountMapperTest; | |
58 | |
59 typedef std::map<std::string, GCMClient::OutgoingMessage> OutgoingMessages; | |
60 | |
61 void SendAddMappingMessage(AccountMapping& account_mapping); | |
62 void SendRemoveMappingMessage(AccountMapping& account_mapping); | |
63 void OnSendFinished(const std::string& account_id, | |
64 AccountMapping::MessageType message_type, | |
65 const std::string& message_id, | |
66 GCMClient::Result result); | |
67 | |
68 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.
| |
69 bool IsMessageExpired(const base::Time& estimated_send_time); | |
jianli
2014/08/27 18:12:01
ditto
fgorski
2014/08/27 21:47:17
Done.
| |
70 | |
71 AccountMapping* FindMappingByAccountId(const std::string& account_id); | |
72 AccountMappings::iterator FindMappingByMessageId( | |
73 const std::string& message_id); | |
74 | |
75 // Sets the clock for testing. | |
76 void SetClockForTesting(scoped_ptr<base::Clock> clock); | |
77 | |
78 GCMDriver* gcm_driver_; | |
jianli
2014/08/27 18:12:01
Comment that GCMDriver owns this instance.
fgorski
2014/08/27 21:47:17
Done.
| |
79 | |
80 scoped_ptr<base::Clock> clock_; | |
81 | |
82 AccountMappings accounts_; | |
83 | |
84 OutgoingMessages sent_messages_; | |
85 | |
86 std::string registration_id_; | |
87 | |
88 bool initialized_; | |
89 | |
90 base::WeakPtrFactory<GCMAccountMapper> weak_ptr_factory_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(GCMAccountMapper); | |
93 }; | |
94 | |
95 } // namespace gcm | |
96 | |
97 #endif // COMPONENTS_GCM_DRIVER_GCM_ACCOUNT_MAPPER_H_ | |
OLD | NEW |