OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GOOGLE_APIS_GCM_ENGINE_GCM_STORE_IMPL_H_ | 5 #ifndef GOOGLE_APIS_GCM_ENGINE_GCM_STORE_IMPL_H_ |
6 #define GOOGLE_APIS_GCM_ENGINE_GCM_STORE_IMPL_H_ | 6 #define GOOGLE_APIS_GCM_ENGINE_GCM_STORE_IMPL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class Encryptor; | 21 class Encryptor; |
22 | 22 |
23 // An implementation of GCM Store that uses LevelDB for persistence. | 23 // An implementation of GCM Store that uses LevelDB for persistence. |
24 // It performs all blocking operations on the blocking task runner, and posts | 24 // It performs all blocking operations on the blocking task runner, and posts |
25 // all callbacks to the thread on which the GCMStoreImpl is created. | 25 // all callbacks to the thread on which the GCMStoreImpl is created. |
26 class GCM_EXPORT GCMStoreImpl : public GCMStore { | 26 class GCM_EXPORT GCMStoreImpl : public GCMStore { |
27 public: | 27 public: |
28 GCMStoreImpl(const base::FilePath& path, | 28 GCMStoreImpl(const base::FilePath& path, |
29 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, | 29 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
30 scoped_ptr<Encryptor> encryptor); | 30 scoped_ptr<Encryptor> encryptor); |
31 virtual ~GCMStoreImpl(); | 31 ~GCMStoreImpl() override; |
32 | 32 |
33 // Load the directory and pass the initial state back to caller. | 33 // Load the directory and pass the initial state back to caller. |
34 virtual void Load(const LoadCallback& callback) override; | 34 void Load(const LoadCallback& callback) override; |
35 | 35 |
36 // Closes the GCM store. | 36 // Closes the GCM store. |
37 virtual void Close() override; | 37 void Close() override; |
38 | 38 |
39 // Clears the GCM store of all data and destroys any LevelDB files associated | 39 // Clears the GCM store of all data and destroys any LevelDB files associated |
40 // with this store. | 40 // with this store. |
41 // WARNING: this will permanently destroy any pending outgoing messages | 41 // WARNING: this will permanently destroy any pending outgoing messages |
42 // and require the device to re-create credentials and serial number mapping | 42 // and require the device to re-create credentials and serial number mapping |
43 // tables. | 43 // tables. |
44 virtual void Destroy(const UpdateCallback& callback) override; | 44 void Destroy(const UpdateCallback& callback) override; |
45 | 45 |
46 // Sets this device's messaging credentials. | 46 // Sets this device's messaging credentials. |
47 virtual void SetDeviceCredentials(uint64 device_android_id, | 47 void SetDeviceCredentials(uint64 device_android_id, |
48 uint64 device_security_token, | 48 uint64 device_security_token, |
49 const UpdateCallback& callback) override; | 49 const UpdateCallback& callback) override; |
50 | 50 |
51 // Registration info. | 51 // Registration info. |
52 virtual void AddRegistration(const std::string& app_id, | 52 void AddRegistration(const std::string& app_id, |
53 const linked_ptr<RegistrationInfo>& registration, | 53 const linked_ptr<RegistrationInfo>& registration, |
54 const UpdateCallback& callback) override; | 54 const UpdateCallback& callback) override; |
55 virtual void RemoveRegistration(const std::string& app_id, | 55 void RemoveRegistration(const std::string& app_id, |
56 const UpdateCallback& callback) override; | 56 const UpdateCallback& callback) override; |
57 | 57 |
58 // Unacknowledged incoming message handling. | 58 // Unacknowledged incoming message handling. |
59 virtual void AddIncomingMessage(const std::string& persistent_id, | 59 void AddIncomingMessage(const std::string& persistent_id, |
60 const UpdateCallback& callback) override; | 60 const UpdateCallback& callback) override; |
61 virtual void RemoveIncomingMessage(const std::string& persistent_id, | 61 void RemoveIncomingMessage(const std::string& persistent_id, |
62 const UpdateCallback& callback) override; | 62 const UpdateCallback& callback) override; |
63 virtual void RemoveIncomingMessages(const PersistentIdList& persistent_ids, | 63 void RemoveIncomingMessages(const PersistentIdList& persistent_ids, |
64 const UpdateCallback& callback) override; | 64 const UpdateCallback& callback) override; |
65 | 65 |
66 // Unacknowledged outgoing messages handling. | 66 // Unacknowledged outgoing messages handling. |
67 virtual bool AddOutgoingMessage(const std::string& persistent_id, | 67 bool AddOutgoingMessage(const std::string& persistent_id, |
68 const MCSMessage& message, | 68 const MCSMessage& message, |
69 const UpdateCallback& callback) override; | 69 const UpdateCallback& callback) override; |
70 virtual void OverwriteOutgoingMessage(const std::string& persistent_id, | 70 void OverwriteOutgoingMessage(const std::string& persistent_id, |
71 const MCSMessage& message, | 71 const MCSMessage& message, |
72 const UpdateCallback& callback) | 72 const UpdateCallback& callback) override; |
73 override; | 73 void RemoveOutgoingMessage(const std::string& persistent_id, |
74 virtual void RemoveOutgoingMessage(const std::string& persistent_id, | 74 const UpdateCallback& callback) override; |
75 const UpdateCallback& callback) override; | 75 void RemoveOutgoingMessages(const PersistentIdList& persistent_ids, |
76 virtual void RemoveOutgoingMessages(const PersistentIdList& persistent_ids, | 76 const UpdateCallback& callback) override; |
77 const UpdateCallback& callback) override; | |
78 | 77 |
79 // Sets last device's checkin information. | 78 // Sets last device's checkin information. |
80 virtual void SetLastCheckinInfo(const base::Time& time, | 79 void SetLastCheckinInfo(const base::Time& time, |
81 const std::set<std::string>& accounts, | 80 const std::set<std::string>& accounts, |
82 const UpdateCallback& callback) override; | 81 const UpdateCallback& callback) override; |
83 | 82 |
84 // G-service settings handling. | 83 // G-service settings handling. |
85 virtual void SetGServicesSettings( | 84 void SetGServicesSettings(const std::map<std::string, std::string>& settings, |
86 const std::map<std::string, std::string>& settings, | 85 const std::string& settings_digest, |
87 const std::string& settings_digest, | 86 const UpdateCallback& callback) override; |
88 const UpdateCallback& callback) override; | |
89 | 87 |
90 // Sets the account information related to device to account mapping. | 88 // Sets the account information related to device to account mapping. |
91 virtual void AddAccountMapping(const AccountMapping& account_mapping, | 89 void AddAccountMapping(const AccountMapping& account_mapping, |
92 const UpdateCallback& callback) override; | 90 const UpdateCallback& callback) override; |
93 virtual void RemoveAccountMapping(const std::string& account_id, | 91 void RemoveAccountMapping(const std::string& account_id, |
94 const UpdateCallback& callback) override; | 92 const UpdateCallback& callback) override; |
95 | 93 |
96 private: | 94 private: |
97 typedef std::map<std::string, int> AppIdToMessageCountMap; | 95 typedef std::map<std::string, int> AppIdToMessageCountMap; |
98 | 96 |
99 // Continuation to update the per-app message counts after a load. | 97 // Continuation to update the per-app message counts after a load. |
100 void LoadContinuation(const LoadCallback& callback, | 98 void LoadContinuation(const LoadCallback& callback, |
101 scoped_ptr<LoadResult> result); | 99 scoped_ptr<LoadResult> result); |
102 | 100 |
103 // Continuation to update the per-app message counts when adding messages. | 101 // Continuation to update the per-app message counts when adding messages. |
104 // In particular, if a message fails to add, the message count is decremented. | 102 // In particular, if a message fails to add, the message count is decremented. |
(...skipping 19 matching lines...) Expand all Loading... |
124 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 122 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
125 | 123 |
126 base::WeakPtrFactory<GCMStoreImpl> weak_ptr_factory_; | 124 base::WeakPtrFactory<GCMStoreImpl> weak_ptr_factory_; |
127 | 125 |
128 DISALLOW_COPY_AND_ASSIGN(GCMStoreImpl); | 126 DISALLOW_COPY_AND_ASSIGN(GCMStoreImpl); |
129 }; | 127 }; |
130 | 128 |
131 } // namespace gcm | 129 } // namespace gcm |
132 | 130 |
133 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_IMPL_H_ | 131 #endif // GOOGLE_APIS_GCM_ENGINE_GCM_STORE_IMPL_H_ |
OLD | NEW |