Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/android/history_report/delta_file_backend_leveldb.cc

Issue 2953473002: Use leveldb_env::OpenDB() to open leveldb databases. (Closed)
Patch Set: Rebase; add comments to CHECK() Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | chrome/browser/android/history_report/usage_reports_buffer_backend.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/history_report/delta_file_backend_leveldb.h" 5 #include "chrome/browser/android/history_report/delta_file_backend_leveldb.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "chrome/browser/android/history_report/delta_file_commons.h" 14 #include "chrome/browser/android/history_report/delta_file_commons.h"
15 #include "third_party/leveldatabase/env_chromium.h"
15 #include "third_party/leveldatabase/src/include/leveldb/comparator.h" 16 #include "third_party/leveldatabase/src/include/leveldb/comparator.h"
16 #include "third_party/leveldatabase/src/include/leveldb/db.h" 17 #include "third_party/leveldatabase/src/include/leveldb/db.h"
17 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" 18 #include "third_party/leveldatabase/src/include/leveldb/iterator.h"
18 #include "third_party/leveldatabase/src/include/leveldb/options.h" 19 #include "third_party/leveldatabase/src/include/leveldb/options.h"
19 #include "third_party/leveldatabase/src/include/leveldb/slice.h" 20 #include "third_party/leveldatabase/src/include/leveldb/slice.h"
20 #include "third_party/leveldatabase/src/include/leveldb/status.h" 21 #include "third_party/leveldatabase/src/include/leveldb/status.h"
21 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 22 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 namespace { 25 namespace {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 89 }
89 90
90 DeltaFileBackend::~DeltaFileBackend() {} 91 DeltaFileBackend::~DeltaFileBackend() {}
91 92
92 bool DeltaFileBackend::Init() { 93 bool DeltaFileBackend::Init() {
93 leveldb::Options options; 94 leveldb::Options options;
94 options.create_if_missing = true; 95 options.create_if_missing = true;
95 options.max_open_files = 0; // Use minimum number of files. 96 options.max_open_files = 0; // Use minimum number of files.
96 options.comparator = leveldb_cmp_.get(); 97 options.comparator = leveldb_cmp_.get();
97 std::string path = path_.value(); 98 std::string path = path_.value();
98 leveldb::DB* db = NULL; 99 leveldb::Status status = leveldb_env::OpenDB(options, path, &db_);
99 leveldb::Status status = leveldb::DB::Open(options, path, &db);
100 if (status.IsCorruption()) { 100 if (status.IsCorruption()) {
101 LOG(WARNING) << "Deleting possibly-corrupt database"; 101 LOG(WARNING) << "Deleting possibly-corrupt database";
102 base::DeleteFile(path_, true); 102 base::DeleteFile(path_, true);
103 status = leveldb::DB::Open(options, path, &db); 103 status = leveldb_env::OpenDB(options, path, &db_);
104 } 104 }
105 if (status.ok()) { 105 if (status.ok()) {
106 CHECK(db); 106 CHECK(db_);
107 db_.reset(db);
108 return true; 107 return true;
109 } 108 }
110 LOG(WARNING) << "Unable to open " << path_.value() << ": " 109 LOG(WARNING) << "Unable to open " << path_.value() << ": "
111 << status.ToString(); 110 << status.ToString();
112 return false; 111 return false;
113 } 112 }
114 113
115 bool DeltaFileBackend::EnsureInitialized() { 114 bool DeltaFileBackend::EnsureInitialized() {
116 if (db_.get()) return true; 115 if (db_.get()) return true;
117 return Init(); 116 return Init();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 leveldb::ReadOptions options; 231 leveldb::ReadOptions options;
233 std::unique_ptr<leveldb::Iterator> db_it(db_->NewIterator(options)); 232 std::unique_ptr<leveldb::Iterator> db_it(db_->NewIterator(options));
234 int num_entries = 0; 233 int num_entries = 0;
235 for (db_it->SeekToFirst(); db_it->Valid(); db_it->Next()) num_entries++; 234 for (db_it->SeekToFirst(); db_it->Valid(); db_it->Next()) num_entries++;
236 dump.append(base::IntToString(num_entries)); 235 dump.append(base::IntToString(num_entries));
237 dump.append("]"); 236 dump.append("]");
238 return dump; 237 return dump;
239 } 238 }
240 239
241 } // namespace history_report 240 } // namespace history_report
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | chrome/browser/android/history_report/usage_reports_buffer_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698