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
3 // found in the LICENSE file.
5 #ifndef GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_
6 #define GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_
12 #include "base/basictypes.h"
13 #include "base/callback_forward.h"
14 #include "base/memory/linked_ptr.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "google_apis/gcm/base/gcm_export.h"
18 #include "google_apis/gcm/engine/registration_info.h"
19 #include "google_apis/gcm/protocol/mcs.pb.h"
24 } // namespace protobuf
31 // A GCM data store interface. GCM Store will handle persistence portion of RMQ,
32 // as well as store device and user checkin information.
33 class GCM_EXPORT GCMStore {
35 // Map of message id to message data for outgoing messages.
36 typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> >
39 // Container for Load(..) results.
40 struct GCM_EXPORT LoadResult {
45 uint64 device_android_id;
46 uint64 device_security_token;
47 RegistrationInfoMap registrations;
48 std::vector<std::string> incoming_messages;
49 OutgoingMessageMap outgoing_messages;
52 typedef std::vector<std::string> PersistentIdList;
53 typedef base::Callback<void(scoped_ptr<LoadResult> result)> LoadCallback;
54 typedef base::Callback<void(bool success)> UpdateCallback;
59 // Load the data from persistent store and pass the initial state back to
61 virtual void Load(const LoadCallback& callback) = 0;
63 // Close the persistent store.
64 virtual void Close() = 0;
66 // Clears the GCM store of all data.
67 virtual void Destroy(const UpdateCallback& callback) = 0;
69 // Sets this device's messaging credentials.
70 virtual void SetDeviceCredentials(uint64 device_android_id,
71 uint64 device_security_token,
72 const UpdateCallback& callback) = 0;
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;
81 // Unacknowledged incoming message handling.
82 virtual void AddIncomingMessage(const std::string& persistent_id,
83 const UpdateCallback& callback) = 0;
84 virtual void RemoveIncomingMessage(const std::string& persistent_id,
85 const UpdateCallback& callback) = 0;
86 virtual void RemoveIncomingMessages(const PersistentIdList& persistent_ids,
87 const UpdateCallback& callback) = 0;
89 // Unacknowledged outgoing messages handling.
90 // Returns false if app has surpassed message limits, else returns true. Note
91 // that the message isn't persisted until |callback| is invoked with
93 virtual bool AddOutgoingMessage(const std::string& persistent_id,
94 const MCSMessage& message,
95 const UpdateCallback& callback) = 0;
96 virtual void OverwriteOutgoingMessage(const std::string& persistent_id,
97 const MCSMessage& message,
98 const UpdateCallback& callback) = 0;
99 virtual void RemoveOutgoingMessage(const std::string& persistent_id,
100 const UpdateCallback& callback) = 0;
101 virtual void RemoveOutgoingMessages(const PersistentIdList& persistent_ids,
102 const UpdateCallback& callback) = 0;
105 DISALLOW_COPY_AND_ASSIGN(GCMStore);
110 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_