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_
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"
23 #include "google_apis/gcm/engine/registration_info.h"
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
{
33 // Map of message id to message data for outgoing messages.
34 typedef std::map
<std::string
, linked_ptr
<google::protobuf::MessageLite
> >
37 // Map of account id to account info for account mappings.
38 typedef std::map
<std::string
, AccountMapping
> AccountMappingMap
;
40 // Container for Load(..) results.
41 struct GCM_EXPORT LoadResult
{
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 AccountMappingMap account_mappings
;
60 typedef std::vector
<std::string
> PersistentIdList
;
61 typedef base::Callback
<void(scoped_ptr
<LoadResult
> result
)> LoadCallback
;
62 typedef base::Callback
<void(bool success
)> UpdateCallback
;
67 // Load the data from persistent store and pass the initial state back to
69 virtual void Load(const LoadCallback
& callback
) = 0;
71 // Close the persistent store.
72 virtual void Close() = 0;
74 // Clears the GCM store of all data.
75 virtual void Destroy(const UpdateCallback
& callback
) = 0;
77 // Sets this device's messaging credentials.
78 virtual void SetDeviceCredentials(uint64 device_android_id
,
79 uint64 device_security_token
,
80 const UpdateCallback
& callback
) = 0;
83 virtual void AddRegistration(const std::string
& app_id
,
84 const linked_ptr
<RegistrationInfo
>& registration
,
85 const UpdateCallback
& callback
) = 0;
86 virtual void RemoveRegistration(const std::string
& app_id
,
87 const UpdateCallback
& callback
) = 0;
89 // Unacknowledged incoming message handling.
90 virtual void AddIncomingMessage(const std::string
& persistent_id
,
91 const UpdateCallback
& callback
) = 0;
92 virtual void RemoveIncomingMessage(const std::string
& persistent_id
,
93 const UpdateCallback
& callback
) = 0;
94 virtual void RemoveIncomingMessages(const PersistentIdList
& persistent_ids
,
95 const UpdateCallback
& callback
) = 0;
97 // Unacknowledged outgoing messages handling.
98 // Returns false if app has surpassed message limits, else returns true. Note
99 // that the message isn't persisted until |callback| is invoked with
100 // |success| == true.
101 virtual bool AddOutgoingMessage(const std::string
& persistent_id
,
102 const MCSMessage
& message
,
103 const UpdateCallback
& callback
) = 0;
104 virtual void OverwriteOutgoingMessage(const std::string
& persistent_id
,
105 const MCSMessage
& message
,
106 const UpdateCallback
& callback
) = 0;
107 virtual void RemoveOutgoingMessage(const std::string
& persistent_id
,
108 const UpdateCallback
& callback
) = 0;
109 virtual void RemoveOutgoingMessages(const PersistentIdList
& persistent_ids
,
110 const UpdateCallback
& callback
) = 0;
112 // Sets last device's checkin information.
113 virtual void SetLastCheckinInfo(const base::Time
& time
,
114 const std::set
<std::string
>& accounts
,
115 const UpdateCallback
& callback
) = 0;
117 // G-service settings handling.
118 // Persists |settings| and |settings_digest|. It completely replaces the
120 virtual void SetGServicesSettings(
121 const std::map
<std::string
, std::string
>& settings
,
122 const std::string
& settings_digest
,
123 const UpdateCallback
& callback
) = 0;
125 // Sets the account information related to device to account mapping.
126 virtual void AddAccountMapping(const AccountMapping
& account_mapping
,
127 const UpdateCallback
& callback
) = 0;
128 virtual void RemoveAccountMapping(const std::string
& account_id
,
129 const UpdateCallback
& callback
) = 0;
132 DISALLOW_COPY_AND_ASSIGN(GCMStore
);
137 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_