| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/prefs/leveldb_pref_store.h" | 5 #include "chrome/browser/prefs/leveldb_pref_store.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
| 15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "third_party/leveldatabase/env_chromium.h" |
| 18 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 19 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 19 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 20 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 enum ErrorMasks { | 24 enum ErrorMasks { |
| 24 OPENED = 1 << 0, | 25 OPENED = 1 << 0, |
| 25 DESTROYED = 1 << 1, | 26 DESTROYED = 1 << 1, |
| 26 REPAIRED = 1 << 2, | 27 REPAIRED = 1 << 2, |
| 27 DESTROY_FAILED = 1 << 3, | 28 DESTROY_FAILED = 1 << 3, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 100 } |
| 100 return true; | 101 return true; |
| 101 } | 102 } |
| 102 | 103 |
| 103 /* static */ | 104 /* static */ |
| 104 void LevelDBPrefStore::OpenDB(const base::FilePath& path, | 105 void LevelDBPrefStore::OpenDB(const base::FilePath& path, |
| 105 ReadingResults* reading_results) { | 106 ReadingResults* reading_results) { |
| 106 DCHECK_EQ(0, reading_results->error); | 107 DCHECK_EQ(0, reading_results->error); |
| 107 leveldb::Options options; | 108 leveldb::Options options; |
| 108 options.create_if_missing = true; | 109 options.create_if_missing = true; |
| 110 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; |
| 109 leveldb::DB* db; | 111 leveldb::DB* db; |
| 110 while (1) { | 112 while (1) { |
| 111 leveldb::Status status = | 113 leveldb::Status status = |
| 112 leveldb::DB::Open(options, path.AsUTF8Unsafe(), &db); | 114 leveldb::DB::Open(options, path.AsUTF8Unsafe(), &db); |
| 113 if (status.ok()) { | 115 if (status.ok()) { |
| 114 reading_results->db.reset(db); | 116 reading_results->db.reset(db); |
| 115 reading_results->error |= OPENED; | 117 reading_results->error |= OPENED; |
| 116 break; | 118 break; |
| 117 } | 119 } |
| 118 if (status.IsIOError()) { | 120 if (status.IsIOError()) { |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 } | 411 } |
| 410 | 412 |
| 411 // TODO(dgrogan): Call pref_filter_->FilterOnLoad | 413 // TODO(dgrogan): Call pref_filter_->FilterOnLoad |
| 412 | 414 |
| 413 if (error_delegate_.get() && read_error_ != PREF_READ_ERROR_NONE) | 415 if (error_delegate_.get() && read_error_ != PREF_READ_ERROR_NONE) |
| 414 error_delegate_->OnError(read_error_); | 416 error_delegate_->OnError(read_error_); |
| 415 | 417 |
| 416 FOR_EACH_OBSERVER( | 418 FOR_EACH_OBSERVER( |
| 417 PrefStore::Observer, observers_, OnInitializationCompleted(true)); | 419 PrefStore::Observer, observers_, OnInitializationCompleted(true)); |
| 418 } | 420 } |
| OLD | NEW |