Reland of Skip the Service Worker CORS fallback for same origin requests. [2/2 chromi...
[chromium-blink-merge.git] / google_apis / gcm / engine / gcm_store.h
blob9375882dbbc3025e71a97676b60cce6ea6c20362
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_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include <google/protobuf/message_lite.h>
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"
24 namespace gcm {
26 class MCSMessage;
28 // A GCM data store interface. GCM Store will handle persistence portion of RMQ,
29 // as well as store device and user checkin information.
30 class GCM_EXPORT GCMStore {
31 public:
32 enum StoreOpenMode {
33 DO_NOT_CREATE,
34 CREATE_IF_MISSING
37 // Map of message id to message data for outgoing messages.
38 typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> >
39 OutgoingMessageMap;
41 // List of account mappings.
42 typedef std::vector<AccountMapping> AccountMappings;
44 // Container for Load(..) results.
45 struct GCM_EXPORT LoadResult {
46 LoadResult();
47 ~LoadResult();
49 void Reset();
51 bool success;
52 bool store_does_not_exist;
53 uint64 device_android_id;
54 uint64 device_security_token;
55 std::map<std::string, std::string> registrations;
56 std::vector<std::string> incoming_messages;
57 OutgoingMessageMap outgoing_messages;
58 std::map<std::string, std::string> gservices_settings;
59 std::string gservices_digest;
60 base::Time last_checkin_time;
61 std::set<std::string> last_checkin_accounts;
62 AccountMappings account_mappings;
63 base::Time last_token_fetch_time;
64 std::map<std::string, int> heartbeat_intervals;
65 std::map<std::string, std::string> instance_id_data;
68 typedef std::vector<std::string> PersistentIdList;
69 typedef base::Callback<void(scoped_ptr<LoadResult> result)> LoadCallback;
70 typedef base::Callback<void(bool success)> UpdateCallback;
72 GCMStore();
73 virtual ~GCMStore();
75 // Load the data from persistent store and pass the initial state back to
76 // caller.
77 virtual void Load(StoreOpenMode open_mode, const LoadCallback& callback) = 0;
79 // Close the persistent store.
80 virtual void Close() = 0;
82 // Clears the GCM store of all data.
83 virtual void Destroy(const UpdateCallback& callback) = 0;
85 // Sets this device's messaging credentials.
86 virtual void SetDeviceCredentials(uint64 device_android_id,
87 uint64 device_security_token,
88 const UpdateCallback& callback) = 0;
90 // Registration info for both GCM registrations and InstanceID tokens.
91 // For GCM, |serialized_key| is app_id and |serialized_value| is
92 // serialization of (senders, registration_id). For InstanceID,
93 // |serialized_key| is serialization of (app_id, authorized_entity, scope)
94 // and |serialized_value| is token.
95 virtual void AddRegistration(const std::string& serialized_key,
96 const std::string& serialized_value,
97 const UpdateCallback& callback) = 0;
98 virtual void RemoveRegistration(const std::string& serialized_key,
99 const UpdateCallback& callback) = 0;
101 // Unacknowledged incoming message handling.
102 virtual void AddIncomingMessage(const std::string& persistent_id,
103 const UpdateCallback& callback) = 0;
104 virtual void RemoveIncomingMessage(const std::string& persistent_id,
105 const UpdateCallback& callback) = 0;
106 virtual void RemoveIncomingMessages(const PersistentIdList& persistent_ids,
107 const UpdateCallback& callback) = 0;
109 // Unacknowledged outgoing messages handling.
110 // Returns false if app has surpassed message limits, else returns true. Note
111 // that the message isn't persisted until |callback| is invoked with
112 // |success| == true.
113 virtual bool AddOutgoingMessage(const std::string& persistent_id,
114 const MCSMessage& message,
115 const UpdateCallback& callback) = 0;
116 virtual void OverwriteOutgoingMessage(const std::string& persistent_id,
117 const MCSMessage& message,
118 const UpdateCallback& callback) = 0;
119 virtual void RemoveOutgoingMessage(const std::string& persistent_id,
120 const UpdateCallback& callback) = 0;
121 virtual void RemoveOutgoingMessages(const PersistentIdList& persistent_ids,
122 const UpdateCallback& callback) = 0;
124 // Sets last device's checkin information.
125 virtual void SetLastCheckinInfo(const base::Time& time,
126 const std::set<std::string>& accounts,
127 const UpdateCallback& callback) = 0;
129 // G-service settings handling.
130 // Persists |settings| and |settings_digest|. It completely replaces the
131 // existing data.
132 virtual void SetGServicesSettings(
133 const std::map<std::string, std::string>& settings,
134 const std::string& settings_digest,
135 const UpdateCallback& callback) = 0;
137 // Sets the account information related to device to account mapping.
138 virtual void AddAccountMapping(const AccountMapping& account_mapping,
139 const UpdateCallback& callback) = 0;
140 virtual void RemoveAccountMapping(const std::string& account_id,
141 const UpdateCallback& callback) = 0;
143 // Sets last token fetch time.
144 virtual void SetLastTokenFetchTime(const base::Time& time,
145 const UpdateCallback& callback) = 0;
147 // Sets the custom client heartbeat interval for a specified scope.
148 virtual void AddHeartbeatInterval(const std::string& scope,
149 int interval_ms,
150 const UpdateCallback& callback) = 0;
151 virtual void RemoveHeartbeatInterval(const std::string& scope,
152 const UpdateCallback& callback) = 0;
154 // Instance ID data.
155 virtual void AddInstanceIDData(const std::string& app_id,
156 const std::string& instance_id_data,
157 const UpdateCallback& callback) = 0;
158 virtual void RemoveInstanceIDData(const std::string& app_id,
159 const UpdateCallback& callback) = 0;
161 private:
162 DISALLOW_COPY_AND_ASSIGN(GCMStore);
165 } // namespace gcm
167 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_