Update To 11.40.268.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 <set>
10 #include <string>
11 #include <vector>
12
13 #include <google/protobuf/message_lite.h>
14
15 #include "base/basictypes.h"
16 #include "base/callback_forward.h"
17 #include "base/memory/linked_ptr.h"
18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/time/time.h"
21 #include "google_apis/gcm/base/gcm_export.h"
22 #include "google_apis/gcm/engine/account_mapping.h"
23 #include "google_apis/gcm/engine/registration_info.h"
24
25 namespace gcm {
26
27 class MCSMessage;
28
29 // A GCM data store interface. GCM Store will handle persistence portion of RMQ,
30 // as well as store device and user checkin information.
31 class GCM_EXPORT GCMStore {
32  public:
33   // Map of message id to message data for outgoing messages.
34   typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> >
35       OutgoingMessageMap;
36
37   // List of account mappings.
38   typedef std::vector<AccountMapping> AccountMappings;
39
40   // Container for Load(..) results.
41   struct GCM_EXPORT LoadResult {
42     LoadResult();
43     ~LoadResult();
44
45     void Reset();
46
47     bool success;
48     uint64 device_android_id;
49     uint64 device_security_token;
50     RegistrationInfoMap registrations;
51     std::vector<std::string> incoming_messages;
52     OutgoingMessageMap outgoing_messages;
53     std::map<std::string, std::string> gservices_settings;
54     std::string gservices_digest;
55     base::Time last_checkin_time;
56     std::set<std::string> last_checkin_accounts;
57     AccountMappings account_mappings;
58     base::Time last_token_fetch_time;
59   };
60
61   typedef std::vector<std::string> PersistentIdList;
62   typedef base::Callback<void(scoped_ptr<LoadResult> result)> LoadCallback;
63   typedef base::Callback<void(bool success)> UpdateCallback;
64
65   GCMStore();
66   virtual ~GCMStore();
67
68   // Load the data from persistent store and pass the initial state back to
69   // caller.
70   virtual void Load(const LoadCallback& callback) = 0;
71
72   // Close the persistent store.
73   virtual void Close() = 0;
74
75   // Clears the GCM store of all data.
76   virtual void Destroy(const UpdateCallback& callback) = 0;
77
78   // Sets this device's messaging credentials.
79   virtual void SetDeviceCredentials(uint64 device_android_id,
80                                     uint64 device_security_token,
81                                     const UpdateCallback& callback) = 0;
82
83   // Registration info.
84   virtual void AddRegistration(const std::string& app_id,
85                                const linked_ptr<RegistrationInfo>& registration,
86                                const UpdateCallback& callback) = 0;
87   virtual void RemoveRegistration(const std::string& app_id,
88                                   const UpdateCallback& callback) = 0;
89
90   // Unacknowledged incoming message handling.
91   virtual void AddIncomingMessage(const std::string& persistent_id,
92                                   const UpdateCallback& callback) = 0;
93   virtual void RemoveIncomingMessage(const std::string& persistent_id,
94                                      const UpdateCallback& callback) = 0;
95   virtual void RemoveIncomingMessages(const PersistentIdList& persistent_ids,
96                                       const UpdateCallback& callback) = 0;
97
98   // Unacknowledged outgoing messages handling.
99   // Returns false if app has surpassed message limits, else returns true. Note
100   // that the message isn't persisted until |callback| is invoked with
101   // |success| == true.
102   virtual bool AddOutgoingMessage(const std::string& persistent_id,
103                                   const MCSMessage& message,
104                                   const UpdateCallback& callback) = 0;
105   virtual void OverwriteOutgoingMessage(const std::string& persistent_id,
106                                         const MCSMessage& message,
107                                         const UpdateCallback& callback) = 0;
108   virtual void RemoveOutgoingMessage(const std::string& persistent_id,
109                                      const UpdateCallback& callback) = 0;
110   virtual void RemoveOutgoingMessages(const PersistentIdList& persistent_ids,
111                                       const UpdateCallback& callback) = 0;
112
113   // Sets last device's checkin information.
114   virtual void SetLastCheckinInfo(const base::Time& time,
115                                   const std::set<std::string>& accounts,
116                                   const UpdateCallback& callback) = 0;
117
118   // G-service settings handling.
119   // Persists |settings| and |settings_digest|. It completely replaces the
120   // existing data.
121   virtual void SetGServicesSettings(
122       const std::map<std::string, std::string>& settings,
123       const std::string& settings_digest,
124       const UpdateCallback& callback) = 0;
125
126   // Sets the account information related to device to account mapping.
127   virtual void AddAccountMapping(const AccountMapping& account_mapping,
128                                  const UpdateCallback& callback) = 0;
129   virtual void RemoveAccountMapping(const std::string& account_id,
130                                     const UpdateCallback& callback) = 0;
131
132   // Sets last token fetch time.
133   virtual void SetLastTokenFetchTime(const base::Time& time,
134                                      const UpdateCallback& callback) = 0;
135
136  private:
137   DISALLOW_COPY_AND_ASSIGN(GCMStore);
138 };
139
140 }  // namespace gcm
141
142 #endif  // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_