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

Side by Side Diff: chrome/browser/prefs/testing_pref_store.cc

Issue 11243002: Move the bits of Prefs where production code has only trivially easy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments, fix gypi problem Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/prefs/testing_pref_store.h ('k') | chrome/browser/prefs/value_map_pref_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "chrome/browser/prefs/testing_pref_store.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
9
10 TestingPrefStore::TestingPrefStore()
11 : read_only_(true),
12 init_complete_(false) {
13 }
14
15 PrefStore::ReadResult TestingPrefStore::GetValue(const std::string& key,
16 const Value** value) const {
17 return prefs_.GetValue(key, value) ? READ_OK : READ_NO_VALUE;
18 }
19
20 PrefStore::ReadResult TestingPrefStore::GetMutableValue(const std::string& key,
21 Value** value) {
22 return prefs_.GetValue(key, value) ? READ_OK : READ_NO_VALUE;
23 }
24
25 void TestingPrefStore::AddObserver(PrefStore::Observer* observer) {
26 observers_.AddObserver(observer);
27 }
28
29 void TestingPrefStore::RemoveObserver(PrefStore::Observer* observer) {
30 observers_.RemoveObserver(observer);
31 }
32
33 size_t TestingPrefStore::NumberOfObservers() const {
34 return observers_.size();
35 }
36
37 bool TestingPrefStore::IsInitializationComplete() const {
38 return init_complete_;
39 }
40
41 void TestingPrefStore::SetValue(const std::string& key, Value* value) {
42 if (prefs_.SetValue(key, value))
43 NotifyPrefValueChanged(key);
44 }
45
46 void TestingPrefStore::SetValueSilently(const std::string& key, Value* value) {
47 prefs_.SetValue(key, value);
48 }
49
50 void TestingPrefStore::RemoveValue(const std::string& key) {
51 if (prefs_.RemoveValue(key))
52 NotifyPrefValueChanged(key);
53 }
54
55 void TestingPrefStore::MarkNeedsEmptyValue(const std::string& key) {
56 }
57
58 bool TestingPrefStore::ReadOnly() const {
59 return read_only_;
60 }
61
62 PersistentPrefStore::PrefReadError TestingPrefStore::GetReadError() const {
63 return PersistentPrefStore::PREF_READ_ERROR_NONE;
64 }
65
66 PersistentPrefStore::PrefReadError TestingPrefStore::ReadPrefs() {
67 NotifyInitializationCompleted();
68 return PersistentPrefStore::PREF_READ_ERROR_NONE;
69 }
70
71 void TestingPrefStore::ReadPrefsAsync(ReadErrorDelegate* error_delegate_raw) {
72 scoped_ptr<ReadErrorDelegate> error_delegate(error_delegate_raw);
73 NotifyInitializationCompleted();
74 }
75
76 void TestingPrefStore::SetInitializationCompleted() {
77 init_complete_ = true;
78 NotifyInitializationCompleted();
79 }
80
81 void TestingPrefStore::NotifyPrefValueChanged(const std::string& key) {
82 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
83 }
84
85 void TestingPrefStore::NotifyInitializationCompleted() {
86 FOR_EACH_OBSERVER(Observer, observers_, OnInitializationCompleted(true));
87 }
88
89 void TestingPrefStore::ReportValueChanged(const std::string& key) {
90 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
91 }
92
93 void TestingPrefStore::SetString(const std::string& key,
94 const std::string& value) {
95 SetValue(key, Value::CreateStringValue(value));
96 }
97
98 void TestingPrefStore::SetInteger(const std::string& key, int value) {
99 SetValue(key, Value::CreateIntegerValue(value));
100 }
101
102 void TestingPrefStore::SetBoolean(const std::string& key, bool value) {
103 SetValue(key, Value::CreateBooleanValue(value));
104 }
105
106 bool TestingPrefStore::GetString(const std::string& key,
107 std::string* value) const {
108 const Value* stored_value;
109 if (!prefs_.GetValue(key, &stored_value) || !stored_value)
110 return false;
111
112 return stored_value->GetAsString(value);
113 }
114
115 bool TestingPrefStore::GetInteger(const std::string& key, int* value) const {
116 const Value* stored_value;
117 if (!prefs_.GetValue(key, &stored_value) || !stored_value)
118 return false;
119
120 return stored_value->GetAsInteger(value);
121 }
122
123 bool TestingPrefStore::GetBoolean(const std::string& key, bool* value) const {
124 const Value* stored_value;
125 if (!prefs_.GetValue(key, &stored_value) || !stored_value)
126 return false;
127
128 return stored_value->GetAsBoolean(value);
129 }
130
131 void TestingPrefStore::set_read_only(bool read_only) {
132 read_only_ = read_only;
133 }
134
135 TestingPrefStore::~TestingPrefStore() {}
OLDNEW
« no previous file with comments | « chrome/browser/prefs/testing_pref_store.h ('k') | chrome/browser/prefs/value_map_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698