| 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 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 new std::vector<DeltaFileEntryWithData>()); | 203 new std::vector<DeltaFileEntryWithData>()); |
| 204 int32_t count = 0; | 204 int32_t count = 0; |
| 205 for (db_it->Seek(start); db_it->Valid() && count < limit; db_it->Next()) { | 205 for (db_it->Seek(start); db_it->Valid() && count < limit; db_it->Next()) { |
| 206 DeltaFileEntry entry; | 206 DeltaFileEntry entry; |
| 207 leveldb::Slice value_slice = db_it->value(); | 207 leveldb::Slice value_slice = db_it->value(); |
| 208 if (!entry.ParseFromArray(value_slice.data(), value_slice.size())) | 208 if (!entry.ParseFromArray(value_slice.data(), value_slice.size())) |
| 209 continue; | 209 continue; |
| 210 result->push_back(DeltaFileEntryWithData(entry)); | 210 result->push_back(DeltaFileEntryWithData(entry)); |
| 211 ++count; | 211 ++count; |
| 212 } | 212 } |
| 213 return result.Pass(); | 213 return result; |
| 214 } | 214 } |
| 215 | 215 |
| 216 void DeltaFileBackend::Clear() { | 216 void DeltaFileBackend::Clear() { |
| 217 if (!EnsureInitialized()) return; | 217 if (!EnsureInitialized()) return; |
| 218 db_.reset(); | 218 db_.reset(); |
| 219 base::DeleteFile(path_, true); | 219 base::DeleteFile(path_, true); |
| 220 Init(); | 220 Init(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 std::string DeltaFileBackend::Dump() { | 223 std::string DeltaFileBackend::Dump() { |
| 224 std::string dump("\n Delta File ["); | 224 std::string dump("\n Delta File ["); |
| 225 if (!EnsureInitialized()) { | 225 if (!EnsureInitialized()) { |
| 226 dump.append("not initialized]"); | 226 dump.append("not initialized]"); |
| 227 return dump; | 227 return dump; |
| 228 } | 228 } |
| 229 dump.append("num pending entries="); | 229 dump.append("num pending entries="); |
| 230 leveldb::ReadOptions options; | 230 leveldb::ReadOptions options; |
| 231 scoped_ptr<leveldb::Iterator> db_it(db_->NewIterator(options)); | 231 scoped_ptr<leveldb::Iterator> db_it(db_->NewIterator(options)); |
| 232 int num_entries = 0; | 232 int num_entries = 0; |
| 233 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++; |
| 234 dump.append(base::IntToString(num_entries)); | 234 dump.append(base::IntToString(num_entries)); |
| 235 dump.append("]"); | 235 dump.append("]"); |
| 236 return dump; | 236 return dump; |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace history_report | 239 } // namespace history_report |
| OLD | NEW |