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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "google_apis/gcm/base/gcm_export.h" | 17 #include "google_apis/gcm/base/gcm_export.h" |
| 18 #include "google_apis/gcm/engine/registration_info.h" |
18 #include "google_apis/gcm/protocol/mcs.pb.h" | 19 #include "google_apis/gcm/protocol/mcs.pb.h" |
19 | 20 |
20 namespace google { | 21 namespace google { |
21 namespace protobuf { | 22 namespace protobuf { |
22 class MessageLite; | 23 class MessageLite; |
23 } // namespace protobuf | 24 } // namespace protobuf |
24 } // namespace google | 25 } // namespace google |
25 | 26 |
26 namespace gcm { | 27 namespace gcm { |
27 | 28 |
28 class MCSMessage; | 29 class MCSMessage; |
29 | 30 |
30 // A GCM data store interface. GCM Store will handle persistence portion of RMQ, | 31 // A GCM data store interface. GCM Store will handle persistence portion of RMQ, |
31 // as well as store device and user checkin information. | 32 // as well as store device and user checkin information. |
32 class GCM_EXPORT GCMStore { | 33 class GCM_EXPORT GCMStore { |
33 public: | 34 public: |
34 // Map of message id to message data for outgoing messages. | 35 // Map of message id to message data for outgoing messages. |
35 typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> > | 36 typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> > |
36 OutgoingMessageMap; | 37 OutgoingMessageMap; |
37 | 38 |
38 // Part of load results storing user serial number mapping related values. | |
39 struct GCM_EXPORT SerialNumberMappings { | |
40 SerialNumberMappings(); | |
41 ~SerialNumberMappings(); | |
42 | |
43 int64 next_serial_number; | |
44 std::map<std::string, int64> user_serial_numbers; | |
45 }; | |
46 | |
47 // Container for Load(..) results. | 39 // Container for Load(..) results. |
48 struct GCM_EXPORT LoadResult { | 40 struct GCM_EXPORT LoadResult { |
49 LoadResult(); | 41 LoadResult(); |
50 ~LoadResult(); | 42 ~LoadResult(); |
51 | 43 |
52 bool success; | 44 bool success; |
53 uint64 device_android_id; | 45 uint64 device_android_id; |
54 uint64 device_security_token; | 46 uint64 device_security_token; |
| 47 RegistrationInfoMap registrations; |
55 std::vector<std::string> incoming_messages; | 48 std::vector<std::string> incoming_messages; |
56 OutgoingMessageMap outgoing_messages; | 49 OutgoingMessageMap outgoing_messages; |
57 SerialNumberMappings serial_number_mappings; | |
58 }; | 50 }; |
59 | 51 |
60 typedef std::vector<std::string> PersistentIdList; | 52 typedef std::vector<std::string> PersistentIdList; |
61 typedef base::Callback<void(scoped_ptr<LoadResult> result)> LoadCallback; | 53 typedef base::Callback<void(scoped_ptr<LoadResult> result)> LoadCallback; |
62 typedef base::Callback<void(bool success)> UpdateCallback; | 54 typedef base::Callback<void(bool success)> UpdateCallback; |
63 | 55 |
64 GCMStore(); | 56 GCMStore(); |
65 virtual ~GCMStore(); | 57 virtual ~GCMStore(); |
66 | 58 |
67 // Load the data from persistent store and pass the initial state back to | 59 // Load the data from persistent store and pass the initial state back to |
68 // caller. | 60 // caller. |
69 virtual void Load(const LoadCallback& callback) = 0; | 61 virtual void Load(const LoadCallback& callback) = 0; |
70 | 62 |
71 // Close the persistent store. | 63 // Close the persistent store. |
72 virtual void Close() = 0; | 64 virtual void Close() = 0; |
73 | 65 |
74 // Clears the GCM store of all data. | 66 // Clears the GCM store of all data. |
75 virtual void Destroy(const UpdateCallback& callback) = 0; | 67 virtual void Destroy(const UpdateCallback& callback) = 0; |
76 | 68 |
77 // Sets this device's messaging credentials. | 69 // Sets this device's messaging credentials. |
78 virtual void SetDeviceCredentials(uint64 device_android_id, | 70 virtual void SetDeviceCredentials(uint64 device_android_id, |
79 uint64 device_security_token, | 71 uint64 device_security_token, |
80 const UpdateCallback& callback) = 0; | 72 const UpdateCallback& callback) = 0; |
81 | 73 |
| 74 // Registration info. |
| 75 virtual void AddRegistration(const std::string& app_id, |
| 76 const linked_ptr<RegistrationInfo>& registration, |
| 77 const UpdateCallback& callback) = 0; |
| 78 virtual void RemoveRegistration(const std::string& app_id, |
| 79 const UpdateCallback& callback) = 0; |
| 80 |
82 // Unacknowledged incoming message handling. | 81 // Unacknowledged incoming message handling. |
83 virtual void AddIncomingMessage(const std::string& persistent_id, | 82 virtual void AddIncomingMessage(const std::string& persistent_id, |
84 const UpdateCallback& callback) = 0; | 83 const UpdateCallback& callback) = 0; |
85 virtual void RemoveIncomingMessage(const std::string& persistent_id, | 84 virtual void RemoveIncomingMessage(const std::string& persistent_id, |
86 const UpdateCallback& callback) = 0; | 85 const UpdateCallback& callback) = 0; |
87 virtual void RemoveIncomingMessages(const PersistentIdList& persistent_ids, | 86 virtual void RemoveIncomingMessages(const PersistentIdList& persistent_ids, |
88 const UpdateCallback& callback) = 0; | 87 const UpdateCallback& callback) = 0; |
89 | 88 |
90 // Unacknowledged outgoing messages handling. | 89 // Unacknowledged outgoing messages handling. |
91 // Returns false if app has surpassed message limits, else returns true. Note | 90 // Returns false if app has surpassed message limits, else returns true. Note |
92 // that the message isn't persisted until |callback| is invoked with | 91 // that the message isn't persisted until |callback| is invoked with |
93 // |success| == true. | 92 // |success| == true. |
94 virtual bool AddOutgoingMessage(const std::string& persistent_id, | 93 virtual bool AddOutgoingMessage(const std::string& persistent_id, |
95 const MCSMessage& message, | 94 const MCSMessage& message, |
96 const UpdateCallback& callback) = 0; | 95 const UpdateCallback& callback) = 0; |
97 virtual void OverwriteOutgoingMessage(const std::string& persistent_id, | 96 virtual void OverwriteOutgoingMessage(const std::string& persistent_id, |
98 const MCSMessage& message, | 97 const MCSMessage& message, |
99 const UpdateCallback& callback) = 0; | 98 const UpdateCallback& callback) = 0; |
100 virtual void RemoveOutgoingMessage(const std::string& persistent_id, | 99 virtual void RemoveOutgoingMessage(const std::string& persistent_id, |
101 const UpdateCallback& callback) = 0; | 100 const UpdateCallback& callback) = 0; |
102 virtual void RemoveOutgoingMessages(const PersistentIdList& persistent_ids, | 101 virtual void RemoveOutgoingMessages(const PersistentIdList& persistent_ids, |
103 const UpdateCallback& callback) = 0; | 102 const UpdateCallback& callback) = 0; |
104 | 103 |
105 // User serial number handling. | |
106 virtual void SetNextSerialNumber(int64 next_serial_number, | |
107 const UpdateCallback& callback) = 0; | |
108 virtual void AddUserSerialNumber(const std::string& username, | |
109 int64 serial_number, | |
110 const UpdateCallback& callback) = 0; | |
111 virtual void RemoveUserSerialNumber(const std::string& username, | |
112 const UpdateCallback& callback) = 0; | |
113 | |
114 private: | 104 private: |
115 DISALLOW_COPY_AND_ASSIGN(GCMStore); | 105 DISALLOW_COPY_AND_ASSIGN(GCMStore); |
116 }; | 106 }; |
117 | 107 |
118 } // namespace gcm | 108 } // namespace gcm |
119 | 109 |
120 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ | 110 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ |
OLD | NEW |