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

Side by Side Diff: services/preferences/public/cpp/persistent_pref_store_mojo.h

Issue 2601873002: Add a mojo bridge for PersistentPrefStore. (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_MOJO_H_
6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_MOJO_H_
7
8 #include "base/macros.h"
9 #include "base/observer_list.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/values.h"
12 #include "components/prefs/persistent_pref_store.h"
13 #include "services/preferences/public/interfaces/preferences.mojom.h"
14
15 namespace prefs {
16
17 // An implementation of PersistentPrefStore which uses
18 // mojom::PersistentPrefStore as the backing of the preferences.
19 //
20 // TODO(sammc): Make this an implementation detail once the PrefService
21 // factory/builder is responsible for constructing the user prefs PrefStore.
22 class PersistentPrefStoreMojo : public PersistentPrefStore {
23 public:
24 explicit PersistentPrefStoreMojo(
25 mojom::PersistentPrefStoreConnectorPtr connector);
26
27 // PrefStore:
28 bool GetValue(const std::string& key,
29 const base::Value** value) const override;
30 std::unique_ptr<base::DictionaryValue> GetValues() const override;
31 void AddObserver(PrefStore::Observer* observer) override;
32 void RemoveObserver(PrefStore::Observer* observer) override;
33 bool HasObservers() const override;
34 bool IsInitializationComplete() const override;
35
36 // WriteablePrefStore overrides.
37 void SetValue(const std::string& key,
38 std::unique_ptr<base::Value> value,
39 uint32_t flags) override;
40 void RemoveValue(const std::string& key, uint32_t flags) override;
41 bool GetMutableValue(const std::string& key, base::Value** result) override;
42 void ReportValueChanged(const std::string& key, uint32_t flags) override;
43 void SetValueSilently(const std::string& key,
44 std::unique_ptr<base::Value> value,
45 uint32_t flags) override;
46
47 // PersistentPrefStore overrides.
48 bool ReadOnly() const override;
49 PrefReadError GetReadError() const override;
50 PrefReadError ReadPrefs() override;
51 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override;
52 void CommitPendingWrite() override;
53 void SchedulePendingLossyWrites() override;
54 void ClearMutableValues() override;
55
56 protected:
57 // base::RefCounted<PrefStore>:
58 ~PersistentPrefStoreMojo() override;
59
60 private:
61 void OnCreateComplete(PrefReadError read_error,
62 bool read_only,
63 std::unique_ptr<base::DictionaryValue> local_prefs,
64 mojom::PersistentPrefStorePtr pref_store);
65
66 mojom::PersistentPrefStoreConnectorPtr connector_;
67 bool read_only_ = false;
68 PrefReadError read_error_ = PersistentPrefStore::PREF_READ_ERROR_NONE;
69 mojom::PersistentPrefStorePtr pref_store_;
70 mojom::PersistentPrefStoreRequest pref_store_request_;
71
72 std::unique_ptr<base::DictionaryValue> local_prefs_;
73
74 std::unique_ptr<ReadErrorDelegate> error_delegate_;
75 base::ObserverList<PrefStore::Observer, true> observers_;
76
77 DISALLOW_COPY_AND_ASSIGN(PersistentPrefStoreMojo);
78 };
79
80 } // namespace prefs
81
82 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_MOJO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698