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 |
60 if (read_result->HasError()) { | 71 if (read_result->HasError()) { |
61 LOG(WARNING) << "Failed to read managed settings for extension " | 72 LOG(WARNING) << "Failed to read managed settings for extension " |
62 << extension_id_ << ": " << read_result->error().message; | 73 << extension_id_ << ": " << read_result->error().message; |
63 // Leave |previous_policy| empty, so that events are generated for every | 74 // Leave |previous_policy| empty, so that events are generated for every |
64 // policy in |current_policy|. | 75 // policy in |current_policy|. |
65 } else { | 76 } else { |
66 read_result->settings().Swap(&previous_policy); | 77 read_result->settings().Swap(&previous_policy); |
67 } | 78 } |
68 | 79 |
69 // Now get two lists of changes: changes after setting the current policies, | 80 // 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... |
154 | 165 |
155 ValueStore::WriteResult PolicyValueStore::Remove( | 166 ValueStore::WriteResult PolicyValueStore::Remove( |
156 const std::vector<std::string>& keys) { | 167 const std::vector<std::string>& keys) { |
157 return MakeWriteResult(ReadOnlyError(util::NoKey())); | 168 return MakeWriteResult(ReadOnlyError(util::NoKey())); |
158 } | 169 } |
159 | 170 |
160 ValueStore::WriteResult PolicyValueStore::Clear() { | 171 ValueStore::WriteResult PolicyValueStore::Clear() { |
161 return MakeWriteResult(ReadOnlyError(util::NoKey())); | 172 return MakeWriteResult(ReadOnlyError(util::NoKey())); |
162 } | 173 } |
163 | 174 |
| 175 bool PolicyValueStore::Restore() { return delegate_->Restore(); } |
| 176 |
| 177 bool PolicyValueStore::RestoreKey(const std::string& key) { |
| 178 return delegate_->RestoreKey(key); |
| 179 } |
| 180 |
164 } // namespace extensions | 181 } // namespace extensions |
OLD | NEW |