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 GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ | 5 #ifndef GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ |
6 #define GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ | 6 #define GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include <google/protobuf/message_lite.h> | 13 #include <google/protobuf/message_lite.h> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "google_apis/gcm/base/gcm_export.h" | 21 #include "google_apis/gcm/base/gcm_export.h" |
| 22 #include "google_apis/gcm/engine/account_info.h" |
22 #include "google_apis/gcm/engine/registration_info.h" | 23 #include "google_apis/gcm/engine/registration_info.h" |
23 | 24 |
24 namespace gcm { | 25 namespace gcm { |
25 | 26 |
26 class MCSMessage; | 27 class MCSMessage; |
27 | 28 |
28 // A GCM data store interface. GCM Store will handle persistence portion of RMQ, | 29 // A GCM data store interface. GCM Store will handle persistence portion of RMQ, |
29 // as well as store device and user checkin information. | 30 // as well as store device and user checkin information. |
30 class GCM_EXPORT GCMStore { | 31 class GCM_EXPORT GCMStore { |
31 public: | 32 public: |
32 // Map of message id to message data for outgoing messages. | 33 // Map of message id to message data for outgoing messages. |
33 typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> > | 34 typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> > |
34 OutgoingMessageMap; | 35 OutgoingMessageMap; |
35 | 36 |
| 37 // Map of account id to account info for account mappings. |
| 38 typedef std::map<std::string, AccountInfo> AccountInfoMap; |
| 39 |
36 // Container for Load(..) results. | 40 // Container for Load(..) results. |
37 struct GCM_EXPORT LoadResult { | 41 struct GCM_EXPORT LoadResult { |
38 LoadResult(); | 42 LoadResult(); |
39 ~LoadResult(); | 43 ~LoadResult(); |
40 | 44 |
| 45 void Reset(); |
| 46 |
41 bool success; | 47 bool success; |
42 uint64 device_android_id; | 48 uint64 device_android_id; |
43 uint64 device_security_token; | 49 uint64 device_security_token; |
44 RegistrationInfoMap registrations; | 50 RegistrationInfoMap registrations; |
45 std::vector<std::string> incoming_messages; | 51 std::vector<std::string> incoming_messages; |
46 OutgoingMessageMap outgoing_messages; | 52 OutgoingMessageMap outgoing_messages; |
47 std::map<std::string, std::string> gservices_settings; | 53 std::map<std::string, std::string> gservices_settings; |
48 std::string gservices_digest; | 54 std::string gservices_digest; |
49 base::Time last_checkin_time; | 55 base::Time last_checkin_time; |
50 std::set<std::string> last_checkin_accounts; | 56 std::set<std::string> last_checkin_accounts; |
| 57 AccountInfoMap account_infos; |
51 }; | 58 }; |
52 | 59 |
53 typedef std::vector<std::string> PersistentIdList; | 60 typedef std::vector<std::string> PersistentIdList; |
54 typedef base::Callback<void(scoped_ptr<LoadResult> result)> LoadCallback; | 61 typedef base::Callback<void(scoped_ptr<LoadResult> result)> LoadCallback; |
55 typedef base::Callback<void(bool success)> UpdateCallback; | 62 typedef base::Callback<void(bool success)> UpdateCallback; |
56 | 63 |
57 GCMStore(); | 64 GCMStore(); |
58 virtual ~GCMStore(); | 65 virtual ~GCMStore(); |
59 | 66 |
60 // Load the data from persistent store and pass the initial state back to | 67 // Load the data from persistent store and pass the initial state back to |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 const MCSMessage& message, | 102 const MCSMessage& message, |
96 const UpdateCallback& callback) = 0; | 103 const UpdateCallback& callback) = 0; |
97 virtual void OverwriteOutgoingMessage(const std::string& persistent_id, | 104 virtual void OverwriteOutgoingMessage(const std::string& persistent_id, |
98 const MCSMessage& message, | 105 const MCSMessage& message, |
99 const UpdateCallback& callback) = 0; | 106 const UpdateCallback& callback) = 0; |
100 virtual void RemoveOutgoingMessage(const std::string& persistent_id, | 107 virtual void RemoveOutgoingMessage(const std::string& persistent_id, |
101 const UpdateCallback& callback) = 0; | 108 const UpdateCallback& callback) = 0; |
102 virtual void RemoveOutgoingMessages(const PersistentIdList& persistent_ids, | 109 virtual void RemoveOutgoingMessages(const PersistentIdList& persistent_ids, |
103 const UpdateCallback& callback) = 0; | 110 const UpdateCallback& callback) = 0; |
104 | 111 |
105 // Sets last device's checkin time. | 112 // Sets last device's checkin information. |
106 virtual void SetLastCheckinInfo(const base::Time& time, | 113 virtual void SetLastCheckinInfo(const base::Time& time, |
107 const std::set<std::string>& accounts, | 114 const std::set<std::string>& accounts, |
108 const UpdateCallback& callback) = 0; | 115 const UpdateCallback& callback) = 0; |
109 | 116 |
110 // G-service settings handling. | 117 // G-service settings handling. |
111 // Persists |settings| and |settings_digest|. It completely replaces the | 118 // Persists |settings| and |settings_digest|. It completely replaces the |
112 // existing data. | 119 // existing data. |
113 virtual void SetGServicesSettings( | 120 virtual void SetGServicesSettings( |
114 const std::map<std::string, std::string>& settings, | 121 const std::map<std::string, std::string>& settings, |
115 const std::string& settings_digest, | 122 const std::string& settings_digest, |
116 const UpdateCallback& callback) = 0; | 123 const UpdateCallback& callback) = 0; |
117 | 124 |
| 125 // Sets the account information related to device to account mapping. |
| 126 virtual void AddAccountMapping(const AccountInfo& account_info, |
| 127 const UpdateCallback& callback) = 0; |
| 128 virtual void RemoveAccountMapping(const std::string& account_id, |
| 129 const UpdateCallback& callback) = 0; |
| 130 |
118 private: | 131 private: |
119 DISALLOW_COPY_AND_ASSIGN(GCMStore); | 132 DISALLOW_COPY_AND_ASSIGN(GCMStore); |
120 }; | 133 }; |
121 | 134 |
122 } // namespace gcm | 135 } // namespace gcm |
123 | 136 |
124 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ | 137 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ |
OLD | NEW |