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/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" |
15 #include "google_apis/gcm/base/gcm_export.h" | 17 #include "google_apis/gcm/base/gcm_export.h" |
| 18 #include "google_apis/gcm/protocol/mcs.pb.h" |
16 | 19 |
17 namespace google { | 20 namespace google { |
18 namespace protobuf { | 21 namespace protobuf { |
19 class MessageLite; | 22 class MessageLite; |
20 } // namespace protobuf | 23 } // namespace protobuf |
21 } // namespace google | 24 } // namespace google |
22 | 25 |
23 namespace gcm { | 26 namespace gcm { |
24 | 27 |
25 class MCSMessage; | 28 class MCSMessage; |
26 | 29 |
27 // A GCM data store interface. GCM Store will handle persistence portion of RMQ, | 30 // A GCM data store interface. GCM Store will handle persistence portion of RMQ, |
28 // as well as store device and user checkin information. | 31 // as well as store device and user checkin information. |
29 class GCM_EXPORT GCMStore { | 32 class GCM_EXPORT GCMStore { |
30 public: | 33 public: |
| 34 // Map of message id to message data for outgoing messages. |
| 35 typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> > |
| 36 OutgoingMessageMap; |
| 37 |
31 // Part of load results storing user serial number mapping related values. | 38 // Part of load results storing user serial number mapping related values. |
32 struct GCM_EXPORT SerialNumberMappings { | 39 struct GCM_EXPORT SerialNumberMappings { |
33 SerialNumberMappings(); | 40 SerialNumberMappings(); |
34 ~SerialNumberMappings(); | 41 ~SerialNumberMappings(); |
35 | 42 |
36 int64 next_serial_number; | 43 int64 next_serial_number; |
37 std::map<std::string, int64> user_serial_numbers; | 44 std::map<std::string, int64> user_serial_numbers; |
38 }; | 45 }; |
39 | 46 |
40 // Container for Load(..) results. | 47 // Container for Load(..) results. |
41 struct GCM_EXPORT LoadResult { | 48 struct GCM_EXPORT LoadResult { |
42 LoadResult(); | 49 LoadResult(); |
43 ~LoadResult(); | 50 ~LoadResult(); |
44 | 51 |
45 bool success; | 52 bool success; |
46 uint64 device_android_id; | 53 uint64 device_android_id; |
47 uint64 device_security_token; | 54 uint64 device_security_token; |
48 std::vector<std::string> incoming_messages; | 55 std::vector<std::string> incoming_messages; |
49 std::map<std::string, google::protobuf::MessageLite*> outgoing_messages; | 56 OutgoingMessageMap outgoing_messages; |
50 SerialNumberMappings serial_number_mappings; | 57 SerialNumberMappings serial_number_mappings; |
51 }; | 58 }; |
52 | 59 |
53 typedef std::vector<std::string> PersistentIdList; | 60 typedef std::vector<std::string> PersistentIdList; |
54 // Note: callee receives ownership of |outgoing_messages|' values. | 61 typedef base::Callback<void(scoped_ptr<LoadResult> result)> LoadCallback; |
55 typedef base::Callback<void(const LoadResult& result)> LoadCallback; | |
56 typedef base::Callback<void(bool success)> UpdateCallback; | 62 typedef base::Callback<void(bool success)> UpdateCallback; |
57 | 63 |
58 GCMStore(); | 64 GCMStore(); |
59 virtual ~GCMStore(); | 65 virtual ~GCMStore(); |
60 | 66 |
61 // 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 |
62 // caller. | 68 // caller. |
63 virtual void Load(const LoadCallback& callback) = 0; | 69 virtual void Load(const LoadCallback& callback) = 0; |
64 | 70 |
65 // Clears the GCM store of all data. | 71 // Clears the GCM store of all data. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 virtual void RemoveUserSerialNumber(const std::string& username, | 105 virtual void RemoveUserSerialNumber(const std::string& username, |
100 const UpdateCallback& callback) = 0; | 106 const UpdateCallback& callback) = 0; |
101 | 107 |
102 private: | 108 private: |
103 DISALLOW_COPY_AND_ASSIGN(GCMStore); | 109 DISALLOW_COPY_AND_ASSIGN(GCMStore); |
104 }; | 110 }; |
105 | 111 |
106 } // namespace gcm | 112 } // namespace gcm |
107 | 113 |
108 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ | 114 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_ |
OLD | NEW |