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

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

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

Powered by Google App Engine
This is Rietveld 408576698