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 19 matching lines...) Expand all Loading... |
30 int64 seq_no = 0; | 30 int64 seq_no = 0; |
31 if (db_iter->Valid()) { | 31 if (db_iter->Valid()) { |
32 history_report::DeltaFileEntry last_entry; | 32 history_report::DeltaFileEntry last_entry; |
33 leveldb::Slice value_slice = db_iter->value(); | 33 leveldb::Slice value_slice = db_iter->value(); |
34 if (last_entry.ParseFromArray(value_slice.data(), value_slice.size())) | 34 if (last_entry.ParseFromArray(value_slice.data(), value_slice.size())) |
35 seq_no = last_entry.seq_no(); | 35 seq_no = last_entry.seq_no(); |
36 } | 36 } |
37 return seq_no; | 37 return seq_no; |
38 } | 38 } |
39 | 39 |
40 void SaveChange(leveldb::DB* db, std::string url, std::string type) { | 40 void SaveChange(leveldb::DB* db, |
| 41 const std::string& url, |
| 42 const std::string& type) { |
41 int64 seq_no = GetLastSeqNo(db) + 1; | 43 int64 seq_no = GetLastSeqNo(db) + 1; |
42 history_report::DeltaFileEntry entry; | 44 history_report::DeltaFileEntry entry; |
43 entry.set_seq_no(seq_no); | 45 entry.set_seq_no(seq_no); |
44 entry.set_type(type); | 46 entry.set_type(type); |
45 entry.set_url(url); | 47 entry.set_url(url); |
46 leveldb::WriteOptions writeOptions; | 48 leveldb::WriteOptions writeOptions; |
47 std::string key; | 49 std::string key; |
48 base::SStringPrintf(&key, "%" PRId64, seq_no); | 50 base::SStringPrintf(&key, "%" PRId64, seq_no); |
49 leveldb::Status status = db->Put( | 51 leveldb::Status status = db->Put( |
50 writeOptions, | 52 writeOptions, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 leveldb::ReadOptions options; | 230 leveldb::ReadOptions options; |
229 scoped_ptr<leveldb::Iterator> db_it(db_->NewIterator(options)); | 231 scoped_ptr<leveldb::Iterator> db_it(db_->NewIterator(options)); |
230 int num_entries = 0; | 232 int num_entries = 0; |
231 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++; |
232 dump.append(base::IntToString(num_entries)); | 234 dump.append(base::IntToString(num_entries)); |
233 dump.append("]"); | 235 dump.append("]"); |
234 return dump; | 236 return dump; |
235 } | 237 } |
236 | 238 |
237 } // namespace history_report | 239 } // namespace history_report |
OLD | NEW |