| OLD | NEW | 
|    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" | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   88 } |   88 } | 
|   89  |   89  | 
|   90 DeltaFileBackend::~DeltaFileBackend() {} |   90 DeltaFileBackend::~DeltaFileBackend() {} | 
|   91  |   91  | 
|   92 bool DeltaFileBackend::Init() { |   92 bool DeltaFileBackend::Init() { | 
|   93   leveldb::Options options; |   93   leveldb::Options options; | 
|   94   options.create_if_missing = true; |   94   options.create_if_missing = true; | 
|   95   options.max_open_files = 0;  // Use minimum number of files. |   95   options.max_open_files = 0;  // Use minimum number of files. | 
|   96   options.comparator = leveldb_cmp_.get(); |   96   options.comparator = leveldb_cmp_.get(); | 
|   97   std::string path = path_.value(); |   97   std::string path = path_.value(); | 
|   98   leveldb::DB* db = NULL; |   98   leveldb::Status status = leveldb_env::OpenDB(options, path, &db_); | 
|   99   leveldb::Status status = leveldb::DB::Open(options, path, &db); |  | 
|  100   if (status.IsCorruption()) { |   99   if (status.IsCorruption()) { | 
|  101     LOG(WARNING) << "Deleting possibly-corrupt database"; |  100     LOG(WARNING) << "Deleting possibly-corrupt database"; | 
|  102     base::DeleteFile(path_, true); |  101     base::DeleteFile(path_, true); | 
|  103     status = leveldb::DB::Open(options, path, &db); |  102     status = leveldb_env::OpenDB(options, path, &db_); | 
|  104   } |  103   } | 
|  105   if (status.ok()) { |  104   if (status.ok()) { | 
|  106     CHECK(db); |  105     CHECK(db_); | 
|  107     db_.reset(db); |  | 
|  108     return true; |  106     return true; | 
|  109   } |  107   } | 
|  110   LOG(WARNING) << "Unable to open " << path_.value() << ": " |  108   LOG(WARNING) << "Unable to open " << path_.value() << ": " | 
|  111                << status.ToString(); |  109                << status.ToString(); | 
|  112   return false; |  110   return false; | 
|  113 } |  111 } | 
|  114  |  112  | 
|  115 bool DeltaFileBackend::EnsureInitialized() { |  113 bool DeltaFileBackend::EnsureInitialized() { | 
|  116   if (db_.get()) return true; |  114   if (db_.get()) return true; | 
|  117   return Init(); |  115   return Init(); | 
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  232   leveldb::ReadOptions options; |  230   leveldb::ReadOptions options; | 
|  233   std::unique_ptr<leveldb::Iterator> db_it(db_->NewIterator(options)); |  231   std::unique_ptr<leveldb::Iterator> db_it(db_->NewIterator(options)); | 
|  234   int num_entries = 0; |  232   int num_entries = 0; | 
|  235   for (db_it->SeekToFirst(); db_it->Valid(); db_it->Next()) num_entries++; |  233   for (db_it->SeekToFirst(); db_it->Valid(); db_it->Next()) num_entries++; | 
|  236   dump.append(base::IntToString(num_entries)); |  234   dump.append(base::IntToString(num_entries)); | 
|  237   dump.append("]"); |  235   dump.append("]"); | 
|  238   return dump; |  236   return dump; | 
|  239 } |  237 } | 
|  240  |  238  | 
|  241 }  // namespace history_report |  239 }  // namespace history_report | 
| OLD | NEW |