Chromium Code Reviews| 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 if (read_result->IsCorrupted()) { | |
| 63 if (delegate_->Restore()) | |
| 64 read_result = delegate_->Get(); | |
|
not at google - send to devlin
2014/02/19 18:40:37
I still don't think this is quite right though, be
Devlin
2014/02/19 19:13:55
Yes, the extension will be notified of all keys be
| |
| 65 } | |
| 66 | |
| 60 if (read_result->HasError()) { | 67 if (read_result->HasError()) { |
| 61 LOG(WARNING) << "Failed to read managed settings for extension " | 68 LOG(WARNING) << "Failed to read managed settings for extension " |
| 62 << extension_id_ << ": " << read_result->error().message; | 69 << extension_id_ << ": " << read_result->error().message; |
| 63 // Leave |previous_policy| empty, so that events are generated for every | 70 // Leave |previous_policy| empty, so that events are generated for every |
| 64 // policy in |current_policy|. | 71 // policy in |current_policy|. |
| 65 } else { | 72 } else { |
| 66 read_result->settings().Swap(&previous_policy); | 73 read_result->settings().Swap(&previous_policy); |
| 67 } | 74 } |
| 68 | 75 |
| 69 // Now get two lists of changes: changes after setting the current policies, | 76 // 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 | 161 |
| 155 ValueStore::WriteResult PolicyValueStore::Remove( | 162 ValueStore::WriteResult PolicyValueStore::Remove( |
| 156 const std::vector<std::string>& keys) { | 163 const std::vector<std::string>& keys) { |
| 157 return MakeWriteResult(ReadOnlyError(util::NoKey())); | 164 return MakeWriteResult(ReadOnlyError(util::NoKey())); |
| 158 } | 165 } |
| 159 | 166 |
| 160 ValueStore::WriteResult PolicyValueStore::Clear() { | 167 ValueStore::WriteResult PolicyValueStore::Clear() { |
| 161 return MakeWriteResult(ReadOnlyError(util::NoKey())); | 168 return MakeWriteResult(ReadOnlyError(util::NoKey())); |
| 162 } | 169 } |
| 163 | 170 |
| 171 bool PolicyValueStore::Restore() { return delegate_->Restore(); } | |
|
not at google - send to devlin
2014/02/19 18:40:37
GRR GIT CL FORMAT IS WRONG.
anyhow, it seems like
not at google - send to devlin
2014/02/19 18:48:26
I suppose if Restore actually does manage to resto
Devlin
2014/02/19 19:13:55
Ideally, yes, Restore() would give more informatio
| |
| 172 | |
| 173 bool PolicyValueStore::RestoreKey(const std::string& key) { | |
| 174 return delegate_->RestoreKey(key); | |
| 175 } | |
| 176 | |
| 164 } // namespace extensions | 177 } // namespace extensions |
| OLD | NEW |