OLD | NEW |
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/value_store/value_store_change.h" | 10 #include "chrome/browser/value_store/value_store_change.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 it->first, it->second.value->DeepCopy()); | 50 it->first, it->second.value->DeepCopy()); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 // Get the previous policies stored in the database. | 54 // Get the previous policies stored in the database. |
55 // TODO(joaodasilva): it'd be better to have a less expensive way of | 55 // TODO(joaodasilva): it'd be better to have a less expensive way of |
56 // determining which keys are currently stored, or of determining which keys | 56 // determining which keys are currently stored, or of determining which keys |
57 // must be removed. | 57 // must be removed. |
58 base::DictionaryValue previous_policy; | 58 base::DictionaryValue previous_policy; |
59 ValueStore::ReadResult read_result = delegate_->Get(); | 59 ValueStore::ReadResult read_result = delegate_->Get(); |
60 | |
61 // If the database is corrupted, try to restore it. | |
62 // This may have the unfortunate side-effect of incorrectly informing the | |
63 // extension of a "new" key, which isn't new and was corrupted. Unfortunately, | |
64 // there's not always a way around this - if the database is corrupted, there | |
65 // may be no way of telling which keys were previously present. | |
66 if (read_result->IsCorrupted()) { | |
67 if (delegate_->Restore()) | |
68 read_result = delegate_->Get(); | |
69 } | |
70 | |
71 if (read_result->HasError()) { | 60 if (read_result->HasError()) { |
72 LOG(WARNING) << "Failed to read managed settings for extension " | 61 LOG(WARNING) << "Failed to read managed settings for extension " |
73 << extension_id_ << ": " << read_result->error().message; | 62 << extension_id_ << ": " << read_result->error().message; |
74 // Leave |previous_policy| empty, so that events are generated for every | 63 // Leave |previous_policy| empty, so that events are generated for every |
75 // policy in |current_policy|. | 64 // policy in |current_policy|. |
76 } else { | 65 } else { |
77 read_result->settings().Swap(&previous_policy); | 66 read_result->settings().Swap(&previous_policy); |
78 } | 67 } |
79 | 68 |
80 // Now get two lists of changes: changes after setting the current policies, | 69 // Now get two lists of changes: changes after setting the current policies, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 154 |
166 ValueStore::WriteResult PolicyValueStore::Remove( | 155 ValueStore::WriteResult PolicyValueStore::Remove( |
167 const std::vector<std::string>& keys) { | 156 const std::vector<std::string>& keys) { |
168 return MakeWriteResult(ReadOnlyError(util::NoKey())); | 157 return MakeWriteResult(ReadOnlyError(util::NoKey())); |
169 } | 158 } |
170 | 159 |
171 ValueStore::WriteResult PolicyValueStore::Clear() { | 160 ValueStore::WriteResult PolicyValueStore::Clear() { |
172 return MakeWriteResult(ReadOnlyError(util::NoKey())); | 161 return MakeWriteResult(ReadOnlyError(util::NoKey())); |
173 } | 162 } |
174 | 163 |
175 bool PolicyValueStore::Restore() { return delegate_->Restore(); } | |
176 | |
177 bool PolicyValueStore::RestoreKey(const std::string& key) { | |
178 return delegate_->RestoreKey(key); | |
179 } | |
180 | |
181 } // namespace extensions | 164 } // namespace extensions |
OLD | NEW |