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 GCM_EXPORT 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; |
| 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 associated |
| 63 // with this store. |
| 64 // WARNING: this will permanently destroy any pending outgoing messages |
| 65 // and require the device to re-create credentials. |
| 66 void Destroy(const UpdateCallback& callback); |
| 67 |
| 68 // Sets this device's messaging credentials. |
| 69 void SetDeviceCredentials(uint64 device_android_id, |
| 70 uint64 device_security_token, |
| 71 const UpdateCallback& callback); |
| 72 |
| 73 // Unacknowledged incoming message handling. |
| 74 void AddIncomingMessage(const std::string& persistent_id, |
| 75 const UpdateCallback& callback); |
| 76 void RemoveIncomingMessage(const std::string& persistent_id, |
| 77 const UpdateCallback& callback); |
| 78 void RemoveIncomingMessages(const PersistentIdList& persistent_ids, |
| 79 const UpdateCallback& callback); |
| 80 |
| 81 // Unacknowledged outgoing messages handling. |
| 82 // TODO(zea): implement per-app limits on the number of outgoing messages. |
| 83 void AddOutgoingMessage(const std::string& persistent_id, |
| 84 const MCSMessage& message, |
| 85 const UpdateCallback& callback); |
| 86 void RemoveOutgoingMessage(const std::string& persistent_id, |
| 87 const UpdateCallback& callback); |
| 88 void RemoveOutgoingMessages(const PersistentIdList& persistent_ids, |
| 89 const UpdateCallback& callback); |
| 90 |
| 91 private: |
| 92 class Backend; |
| 93 |
| 94 scoped_refptr<Backend> backend_; |
| 95 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(RMQStore); |
| 98 }; |
| 99 |
| 100 } // namespace gcm |
| 101 |
| 102 #endif // GOOGLE_APIS_GCM_ENGINE_RMQ_STORE_H_ |
OLD | NEW |