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/settings/settings_leveldb_storage.h" | 5 #include "chrome/browser/extensions/settings/settings_leveldb_storage.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 for (DictionaryValue::Iterator it(settings); it.HasNext(); it.Advance()) { | 201 for (DictionaryValue::Iterator it(settings); it.HasNext(); it.Advance()) { |
202 scoped_ptr<Value> old_value; | 202 scoped_ptr<Value> old_value; |
203 if (!ReadFromDb(leveldb::ReadOptions(), it.key(), &old_value)) { | 203 if (!ReadFromDb(leveldb::ReadOptions(), it.key(), &old_value)) { |
204 return WriteResult(kGenericOnFailureMessage); | 204 return WriteResult(kGenericOnFailureMessage); |
205 } | 205 } |
206 | 206 |
207 if (!old_value.get() || !old_value->Equals(&it.value())) { | 207 if (!old_value.get() || !old_value->Equals(&it.value())) { |
208 changes->push_back( | 208 changes->push_back( |
209 SettingChange( | 209 SettingChange( |
210 it.key(), old_value.release(), it.value().DeepCopy())); | 210 it.key(), old_value.release(), it.value().DeepCopy())); |
211 base::JSONWriter::Write(&it.value(), false, &value_as_json); | 211 base::JSONWriter::Write(&it.value(), &value_as_json); |
212 batch.Put(it.key(), value_as_json); | 212 batch.Put(it.key(), value_as_json); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch); | 216 leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch); |
217 if (!status.ok()) { | 217 if (!status.ok()) { |
218 LOG(WARNING) << "DB batch write failed: " << status.ToString(); | 218 LOG(WARNING) << "DB batch write failed: " << status.ToString(); |
219 return WriteResult(kGenericOnFailureMessage); | 219 return WriteResult(kGenericOnFailureMessage); |
220 } | 220 } |
221 | 221 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 it->SeekToFirst(); | 337 it->SeekToFirst(); |
338 bool is_empty = !it->Valid(); | 338 bool is_empty = !it->Valid(); |
339 if (!it->status().ok()) { | 339 if (!it->status().ok()) { |
340 LOG(ERROR) << "Checking DB emptiness failed: " << it->status().ToString(); | 340 LOG(ERROR) << "Checking DB emptiness failed: " << it->status().ToString(); |
341 return false; | 341 return false; |
342 } | 342 } |
343 return is_empty; | 343 return is_empty; |
344 } | 344 } |
345 | 345 |
346 } // namespace extensions | 346 } // namespace extensions |
OLD | NEW |