Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / google_apis / gcm / engine / gcm_store.h
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.
4
5 #ifndef GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_
6 #define GOOGLE_APIS_GCM_ENGINE_GCM_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/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"
20
21 namespace google {
22 namespace protobuf {
23 class MessageLite;
24 }  // namespace protobuf
25 }  // namespace google
26
27 namespace gcm {
28
29 class MCSMessage;
30
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 {
34  public:
35   // Map of message id to message data for outgoing messages.
36   typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> >
37       OutgoingMessageMap;
38
39   // Container for Load(..) results.
40   struct GCM_EXPORT LoadResult {
41     LoadResult();
42     ~LoadResult();
43
44     bool success;
45     uint64 device_android_id;
46     uint64 device_security_token;
47     RegistrationInfoMap registrations;
48     std::vector<std::string> incoming_messages;
49     OutgoingMessageMap outgoing_messages;
50   };
51
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;
55
56   GCMStore();
57   virtual ~GCMStore();
58
59   // Load the data from persistent store and pass the initial state back to
60   // caller.
61   virtual void Load(const LoadCallback& callback) = 0;
62
63   // Close the persistent store.
64   virtual void Close() = 0;
65
66   // Clears the GCM store of all data.
67   virtual void Destroy(const UpdateCallback& callback) = 0;
68
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;
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
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;
88
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
92   // |success| == true.
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;
103
104  private:
105   DISALLOW_COPY_AND_ASSIGN(GCMStore);
106 };
107
108 }  // namespace gcm
109
110 #endif  // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_