OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 SERVICES_PREFERENCES_PERSISTENT_PREF_STORE_IMPL_H_ | 5 #ifndef SERVICES_PREFERENCES_PERSISTENT_PREF_STORE_IMPL_H_ |
6 #define SERVICES_PREFERENCES_PERSISTENT_PREF_STORE_IMPL_H_ | 6 #define SERVICES_PREFERENCES_PERSISTENT_PREF_STORE_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <unordered_map> | 10 #include <unordered_map> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "services/preferences/public/interfaces/preferences.mojom.h" | 14 #include "services/preferences/public/interfaces/preferences.mojom.h" |
15 #include "services/preferences/public/interfaces/tracked_preference_validation_d
elegate.mojom.h" | 15 #include "services/preferences/public/interfaces/tracked_preference_validation_d
elegate.mojom.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class Value; | 18 class Value; |
19 } | 19 } |
20 | 20 |
21 namespace prefs { | 21 namespace prefs { |
22 | 22 |
23 class PersistentPrefStoreImpl : public mojom::PersistentPrefStoreConnector, | 23 class PersistentPrefStoreImpl : public PrefStore::Observer { |
24 public PrefStore::Observer { | |
25 public: | 24 public: |
| 25 using ConnectCallback = |
| 26 base::Callback<void(mojom::PersistentPrefStoreConfigurationPtr)>; |
| 27 |
| 28 // If |initialized()| is false after construction, |on_initialized| will be |
| 29 // called when it becomes true. |
26 PersistentPrefStoreImpl( | 30 PersistentPrefStoreImpl( |
27 scoped_refptr<PersistentPrefStore> backing_pref_store, | 31 scoped_refptr<PersistentPrefStore> backing_pref_store, |
28 mojom::TrackedPreferenceValidationDelegatePtr validation_delegate); | 32 mojom::TrackedPreferenceValidationDelegatePtr validation_delegate, |
| 33 base::Closure on_initialized); |
29 | 34 |
30 ~PersistentPrefStoreImpl() override; | 35 ~PersistentPrefStoreImpl() override; |
31 | 36 |
32 // mojom::PersistentPrefStoreConnector override: | 37 mojom::PersistentPrefStoreConnectionPtr Connect( |
33 void Connect(const ConnectCallback& callback) override; | 38 mojom::PrefRegistryPtr pref_registry); |
| 39 |
| 40 bool initialized() { return !initializing_; } |
34 | 41 |
35 private: | 42 private: |
36 class Connection; | 43 class Connection; |
37 | 44 |
38 void SetValue(const std::string& key, | 45 void SetValue(const std::string& key, |
39 std::unique_ptr<base::Value> value, | 46 std::unique_ptr<base::Value> value, |
40 uint32_t flags); | 47 uint32_t flags); |
41 | 48 |
42 void CommitPendingWrite(); | 49 void CommitPendingWrite(); |
43 void SchedulePendingLossyWrites(); | 50 void SchedulePendingLossyWrites(); |
44 void ClearMutableValues(); | 51 void ClearMutableValues(); |
45 | 52 |
46 // PrefStore::Observer: | 53 // PrefStore::Observer: |
47 void OnPrefValueChanged(const std::string& key) override; | 54 void OnPrefValueChanged(const std::string& key) override; |
48 void OnInitializationCompleted(bool succeeded) override; | 55 void OnInitializationCompleted(bool succeeded) override; |
49 | 56 |
50 void CallConnectCallback( | |
51 const mojom::PersistentPrefStoreConnector::ConnectCallback& callback); | |
52 void OnConnectionError(Connection* connection); | 57 void OnConnectionError(Connection* connection); |
53 | 58 |
54 scoped_refptr<PersistentPrefStore> backing_pref_store_; | 59 scoped_refptr<PersistentPrefStore> backing_pref_store_; |
55 mojom::TrackedPreferenceValidationDelegatePtr validation_delegate_; | 60 mojom::TrackedPreferenceValidationDelegatePtr validation_delegate_; |
56 | 61 |
57 bool initializing_ = false; | 62 bool initializing_ = false; |
58 std::vector<ConnectCallback> pending_connect_callbacks_; | |
59 | 63 |
60 std::unordered_map<Connection*, std::unique_ptr<Connection>> connections_; | 64 std::unordered_map<Connection*, std::unique_ptr<Connection>> connections_; |
61 | 65 |
| 66 base::Closure on_initialized_; |
| 67 |
62 DISALLOW_COPY_AND_ASSIGN(PersistentPrefStoreImpl); | 68 DISALLOW_COPY_AND_ASSIGN(PersistentPrefStoreImpl); |
63 }; | 69 }; |
64 | 70 |
65 } // namespace prefs | 71 } // namespace prefs |
66 | 72 |
67 #endif // SERVICES_PREFERENCES_PERSISTENT_PREF_STORE_IMPL_H_ | 73 #endif // SERVICES_PREFERENCES_PERSISTENT_PREF_STORE_IMPL_H_ |
OLD | NEW |