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