Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: services/preferences/persistent_pref_store_impl.h

Issue 2771723002: Pref service: Merge PrefStoreConnector interfaces. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // If |initialized()| is false after construction, |on_initialized| will be
26 // called when it becomes true.
26 PersistentPrefStoreImpl( 27 PersistentPrefStoreImpl(
27 scoped_refptr<PersistentPrefStore> backing_pref_store, 28 scoped_refptr<PersistentPrefStore> backing_pref_store,
28 mojom::TrackedPreferenceValidationDelegatePtr validation_delegate); 29 mojom::TrackedPreferenceValidationDelegatePtr validation_delegate,
30 base::OnceClosure on_initialized);
29 31
30 ~PersistentPrefStoreImpl() override; 32 ~PersistentPrefStoreImpl() override;
31 33
32 // mojom::PersistentPrefStoreConnector override: 34 mojom::PersistentPrefStoreConnectionPtr CreateConnection();
33 void Connect(const ConnectCallback& callback) override; 35
36 bool initialized() { return !initializing_; }
34 37
35 private: 38 private:
36 class Connection; 39 class Connection;
37 40
38 void SetValue(const std::string& key, 41 void SetValue(const std::string& key,
39 std::unique_ptr<base::Value> value, 42 std::unique_ptr<base::Value> value,
40 uint32_t flags); 43 uint32_t flags);
41 44
42 void CommitPendingWrite(); 45 void CommitPendingWrite();
43 void SchedulePendingLossyWrites(); 46 void SchedulePendingLossyWrites();
44 void ClearMutableValues(); 47 void ClearMutableValues();
45 48
46 // PrefStore::Observer: 49 // PrefStore::Observer:
47 void OnPrefValueChanged(const std::string& key) override; 50 void OnPrefValueChanged(const std::string& key) override;
48 void OnInitializationCompleted(bool succeeded) override; 51 void OnInitializationCompleted(bool succeeded) override;
49 52
50 void CallConnectCallback(
51 const mojom::PersistentPrefStoreConnector::ConnectCallback& callback);
52 void OnConnectionError(Connection* connection); 53 void OnConnectionError(Connection* connection);
53 54
54 scoped_refptr<PersistentPrefStore> backing_pref_store_; 55 scoped_refptr<PersistentPrefStore> backing_pref_store_;
55 mojom::TrackedPreferenceValidationDelegatePtr validation_delegate_; 56 mojom::TrackedPreferenceValidationDelegatePtr validation_delegate_;
56 57
57 bool initializing_ = false; 58 bool initializing_ = false;
58 std::vector<ConnectCallback> pending_connect_callbacks_;
59 59
60 std::unordered_map<Connection*, std::unique_ptr<Connection>> connections_; 60 std::unordered_map<Connection*, std::unique_ptr<Connection>> connections_;
61 61
62 base::OnceClosure on_initialized_;
63
62 DISALLOW_COPY_AND_ASSIGN(PersistentPrefStoreImpl); 64 DISALLOW_COPY_AND_ASSIGN(PersistentPrefStoreImpl);
63 }; 65 };
64 66
65 } // namespace prefs 67 } // namespace prefs
66 68
67 #endif // SERVICES_PREFERENCES_PERSISTENT_PREF_STORE_IMPL_H_ 69 #endif // SERVICES_PREFERENCES_PERSISTENT_PREF_STORE_IMPL_H_
OLDNEW
« no previous file with comments | « services/preferences/persistent_pref_store_factory.cc ('k') | services/preferences/persistent_pref_store_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698