OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 GOOGLE_APIS_GCM_ENGINE_RMQ_STORE_H_ | |
6 #define GOOGLE_APIS_GCM_ENGINE_RMQ_STORE_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/callback_forward.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "google_apis/gcm/base/gcm_export.h" | |
16 | |
17 namespace base { | |
18 class FilePath; | |
19 class SequencedTaskRunner; | |
20 } // namespace base | |
21 | |
22 namespace google { | |
23 namespace protobuf { | |
24 class MessageLite; | |
25 } // namespace protobuf | |
26 } // namespace google | |
27 | |
28 namespace gcm { | |
29 | |
30 class MCSMessage; | |
31 | |
32 // A Reliable Message Queue store. | |
33 // Will perform all blocking operations on the blocking task runner, and will | |
34 // post all callbacks to the thread on which the RMQStore is created. | |
35 class GCM_EXPORT RMQStore { | |
36 public: | |
37 // Container for Load(..) results. | |
38 struct LoadResult { | |
39 LoadResult(); | |
40 ~LoadResult(); | |
41 | |
42 bool success; | |
43 uint64 device_android_id; | |
44 uint64 device_security_token; | |
45 std::vector<std::string> incoming_messages; | |
fgorski
2013/11/01 20:26:10
Possibly reuse PersistentIdList for the type.
Nicolas Zea
2013/11/01 21:18:49
PersistentIdList is defined below, so I'd have to
| |
46 std::map<std::string, google::protobuf::MessageLite*> | |
47 outgoing_messages; | |
48 }; | |
49 | |
50 typedef std::vector<std::string> PersistentIdList; | |
51 // Note: callee receives ownership of |outgoing_messages|' values. | |
52 typedef base::Callback<void(const LoadResult& result)> LoadCallback; | |
53 typedef base::Callback<void(bool success)> UpdateCallback; | |
54 | |
55 RMQStore(const base::FilePath& path, | |
56 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | |
57 ~RMQStore(); | |
58 | |
59 // Load the directory and pass the initial state back to caller. | |
60 void Load(const LoadCallback& callback); | |
61 | |
62 // Clears the RMQ store of all data and destroys any LevelDB files. | |
fgorski
2013/11/01 20:26:10
these are only the files related to RMQ, and not *
Nicolas Zea
2013/11/01 21:18:49
Right, clarified.
| |
63 // WARNING: this will permanently destroy any pending outgoing messages | |
64 // and require the device to re-create credentials. | |
65 void Destroy(const UpdateCallback& callback); | |
66 | |
67 // Sets this device's messaging credentials. | |
68 void SetDeviceCredentials(uint64 device_android_id, | |
69 uint64 device_security_token, | |
70 const UpdateCallback& callback); | |
71 | |
72 // Unacknowledged incoming message handling. | |
73 void AddIncomingMessage(const std::string& persistent_id, | |
74 const UpdateCallback& callback); | |
75 void RemoveIncomingMessage(const std::string& persistent_id, | |
76 const UpdateCallback& callback); | |
77 void RemoveIncomingMessages(const PersistentIdList& persistent_ids, | |
78 const UpdateCallback& callback); | |
79 | |
80 // Unacknowledged outgoing messages handling. | |
81 // TODO(zea): implement per-app limits on the number of outgoing messages. | |
82 void AddOutgoingMessage(const std::string& persistent_id, | |
83 const MCSMessage& message, | |
84 const UpdateCallback& callback); | |
85 void RemoveOutgoingMessage(const std::string& persistent_id, | |
86 const UpdateCallback& callback); | |
87 void RemoveOutgoingMessages(const PersistentIdList& persistent_ids, | |
88 const UpdateCallback& callback); | |
89 | |
90 private: | |
91 class Backend; | |
92 | |
93 scoped_refptr<Backend> backend_; | |
94 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(RMQStore); | |
97 }; | |
98 | |
99 } // namespace gcm | |
100 | |
101 #endif // GOOGLE_APIS_GCM_ENGINE_RMQ_STORE_H_ | |
OLD | NEW |