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_
12 #include <google/protobuf/message_lite.h>
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"
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
{
31 // Map of message id to message data for outgoing messages.
32 typedef std::map
<std::string
, linked_ptr
<google::protobuf::MessageLite
> >
35 // Container for Load(..) results.
36 struct GCM_EXPORT LoadResult
{
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
;
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
;
58 // Load the data from persistent store and pass the initial state back to
60 virtual void Load(const LoadCallback
& callback
) = 0;
62 // Close the persistent store.
63 virtual void Close() = 0;
65 // Clears the GCM store of all data.
66 virtual void Destroy(const UpdateCallback
& callback
) = 0;
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;
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;
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;
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
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;
103 // Sets last device's checkin time.
104 virtual void SetLastCheckinTime(const base::Time
& last_checkin_time
,
105 const UpdateCallback
& callback
) = 0;
107 // G-service settings handling.
108 // Persists |settings| and |settings_digest|. It completely replaces the
110 virtual void SetGServicesSettings(
111 const std::map
<std::string
, std::string
>& settings
,
112 const std::string
& settings_digest
,
113 const UpdateCallback
& callback
) = 0;
116 DISALLOW_COPY_AND_ASSIGN(GCMStore
);
121 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_H_