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

Side by Side Diff: chrome/browser/extensions/api/storage/policy_value_store.cc

Issue 24021002: Propagate more information about ValueStore errors to callers, notably an (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add Pass*() Created 7 years, 3 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 | « no previous file | chrome/browser/extensions/api/storage/policy_value_store_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/extensions/api/storage/policy_value_store.h" 5 #include "chrome/browser/extensions/api/storage/policy_value_store.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/api/storage/settings_namespace.h" 9 #include "chrome/browser/extensions/api/storage/settings_namespace.h"
10 #include "chrome/browser/policy/policy_map.h" 10 #include "chrome/browser/policy/policy_map.h"
11 #include "chrome/browser/policy/policy_types.h" 11 #include "chrome/browser/policy/policy_types.h"
12 #include "chrome/browser/value_store/value_store_change.h" 12 #include "chrome/browser/value_store/value_store_change.h"
13 #include "chrome/browser/value_store/value_store_util.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 15
15 using content::BrowserThread; 16 using content::BrowserThread;
16 17
18 namespace util = value_store_util;
19
17 namespace extensions { 20 namespace extensions {
18 21
19 namespace { 22 namespace {
20 23
21 const char kReadOnlyStoreErrorMessage[] = "This is a read-only store."; 24 scoped_ptr<ValueStore::Error> ReadOnlyError(scoped_ptr<std::string> key) {
22 25 return make_scoped_ptr(new ValueStore::Error(
23 ValueStore::WriteResult WriteResultError() { 26 ValueStore::READ_ONLY, "This is a read-only store.", key.Pass()));
24 return ValueStore::MakeWriteResult(kReadOnlyStoreErrorMessage);
25 } 27 }
26 28
27 } // namespace 29 } // namespace
28 30
29 PolicyValueStore::PolicyValueStore( 31 PolicyValueStore::PolicyValueStore(
30 const std::string& extension_id, 32 const std::string& extension_id,
31 const scoped_refptr<SettingsObserverList>& observers, 33 const scoped_refptr<SettingsObserverList>& observers,
32 scoped_ptr<ValueStore> delegate) 34 scoped_ptr<ValueStore> delegate)
33 : extension_id_(extension_id), 35 : extension_id_(extension_id),
34 observers_(observers), 36 observers_(observers),
(...skipping 16 matching lines...) Expand all
51 } 53 }
52 54
53 // Get the previous policies stored in the database. 55 // Get the previous policies stored in the database.
54 // TODO(joaodasilva): it'd be better to have a less expensive way of 56 // TODO(joaodasilva): it'd be better to have a less expensive way of
55 // determining which keys are currently stored, or of determining which keys 57 // determining which keys are currently stored, or of determining which keys
56 // must be removed. 58 // must be removed.
57 base::DictionaryValue previous_policy; 59 base::DictionaryValue previous_policy;
58 ValueStore::ReadResult read_result = delegate_->Get(); 60 ValueStore::ReadResult read_result = delegate_->Get();
59 if (read_result->HasError()) { 61 if (read_result->HasError()) {
60 LOG(WARNING) << "Failed to read managed settings for extension " 62 LOG(WARNING) << "Failed to read managed settings for extension "
61 << extension_id_ << ": " << read_result->error(); 63 << extension_id_ << ": " << read_result->error().message;
62 // Leave |previous_policy| empty, so that events are generated for every 64 // Leave |previous_policy| empty, so that events are generated for every
63 // policy in |current_policy|. 65 // policy in |current_policy|.
64 } else { 66 } else {
65 read_result->settings()->Swap(&previous_policy); 67 read_result->settings().Swap(&previous_policy);
66 } 68 }
67 69
68 // Now get two lists of changes: changes after setting the current policies, 70 // Now get two lists of changes: changes after setting the current policies,
69 // and changes after removing old policies that aren't in |current_policy| 71 // and changes after removing old policies that aren't in |current_policy|
70 // anymore. 72 // anymore.
71 std::vector<std::string> removed_keys; 73 std::vector<std::string> removed_keys;
72 for (base::DictionaryValue::Iterator it(previous_policy); 74 for (base::DictionaryValue::Iterator it(previous_policy);
73 !it.IsAtEnd(); it.Advance()) { 75 !it.IsAtEnd(); it.Advance()) {
74 if (!current_policy.HasKey(it.key())) 76 if (!current_policy.HasKey(it.key()))
75 removed_keys.push_back(it.key()); 77 removed_keys.push_back(it.key());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 const std::vector<std::string>& keys) { 134 const std::vector<std::string>& keys) {
133 return delegate_->Get(keys); 135 return delegate_->Get(keys);
134 } 136 }
135 137
136 ValueStore::ReadResult PolicyValueStore::Get() { 138 ValueStore::ReadResult PolicyValueStore::Get() {
137 return delegate_->Get(); 139 return delegate_->Get();
138 } 140 }
139 141
140 ValueStore::WriteResult PolicyValueStore::Set( 142 ValueStore::WriteResult PolicyValueStore::Set(
141 WriteOptions options, const std::string& key, const base::Value& value) { 143 WriteOptions options, const std::string& key, const base::Value& value) {
142 return WriteResultError(); 144 return MakeWriteResult(ReadOnlyError(util::NewKey(key)));
143 } 145 }
144 146
145 ValueStore::WriteResult PolicyValueStore::Set( 147 ValueStore::WriteResult PolicyValueStore::Set(
146 WriteOptions options, const base::DictionaryValue& settings) { 148 WriteOptions options, const base::DictionaryValue& settings) {
147 return WriteResultError(); 149 return MakeWriteResult(ReadOnlyError(util::NoKey()));
148 } 150 }
149 151
150 ValueStore::WriteResult PolicyValueStore::Remove(const std::string& key) { 152 ValueStore::WriteResult PolicyValueStore::Remove(const std::string& key) {
151 return WriteResultError(); 153 return MakeWriteResult(ReadOnlyError(util::NewKey(key)));
152 } 154 }
153 155
154 ValueStore::WriteResult PolicyValueStore::Remove( 156 ValueStore::WriteResult PolicyValueStore::Remove(
155 const std::vector<std::string>& keys) { 157 const std::vector<std::string>& keys) {
156 return WriteResultError(); 158 return MakeWriteResult(ReadOnlyError(util::NoKey()));
157 } 159 }
158 160
159 ValueStore::WriteResult PolicyValueStore::Clear() { 161 ValueStore::WriteResult PolicyValueStore::Clear() {
160 return WriteResultError(); 162 return MakeWriteResult(ReadOnlyError(util::NoKey()));
161 } 163 }
162 164
163 } // namespace extensions 165 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/storage/policy_value_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698