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

Side by Side Diff: content/browser/indexed_db/leveldb/leveldb_database.cc

Issue 213263004: Made IndexedDB's comparators public. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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 | « content/browser/indexed_db/leveldb/leveldb_database.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/indexed_db/leveldb/leveldb_database.h" 5 #include "content/browser/indexed_db/leveldb/leveldb_database.h"
6 6
7 #include <cerrno> 7 #include <cerrno>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/sys_info.h" 18 #include "base/sys_info.h"
19 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" 19 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h"
20 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" 20 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h"
21 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" 21 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h"
22 #include "third_party/leveldatabase/env_chromium.h" 22 #include "third_party/leveldatabase/env_chromium.h"
23 #include "third_party/leveldatabase/env_idb.h" 23 #include "third_party/leveldatabase/env_idb.h"
24 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" 24 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
25 #include "third_party/leveldatabase/src/include/leveldb/comparator.h"
26 #include "third_party/leveldatabase/src/include/leveldb/db.h" 25 #include "third_party/leveldatabase/src/include/leveldb/db.h"
27 #include "third_party/leveldatabase/src/include/leveldb/env.h" 26 #include "third_party/leveldatabase/src/include/leveldb/env.h"
28 #include "third_party/leveldatabase/src/include/leveldb/slice.h" 27 #include "third_party/leveldatabase/src/include/leveldb/slice.h"
29 28
30 using base::StringPiece; 29 using base::StringPiece;
31 30
32 namespace content { 31 namespace content {
33 32
34 // Forcing flushes to disk at the end of a transaction guarantees that the 33 // Forcing flushes to disk at the end of a transaction guarantees that the
35 // data hit disk, but drastically impacts throughput when the filesystem is 34 // data hit disk, but drastically impacts throughput when the filesystem is
(...skipping 12 matching lines...) Expand all
48 #endif 47 #endif
49 48
50 static leveldb::Slice MakeSlice(const StringPiece& s) { 49 static leveldb::Slice MakeSlice(const StringPiece& s) {
51 return leveldb::Slice(s.begin(), s.size()); 50 return leveldb::Slice(s.begin(), s.size());
52 } 51 }
53 52
54 static StringPiece MakeStringPiece(const leveldb::Slice& s) { 53 static StringPiece MakeStringPiece(const leveldb::Slice& s) {
55 return StringPiece(s.data(), s.size()); 54 return StringPiece(s.data(), s.size());
56 } 55 }
57 56
58 class ComparatorAdapter : public leveldb::Comparator { 57 LevelDBDatabase::ComparatorAdapter::ComparatorAdapter(
59 public: 58 const LevelDBComparator* comparator)
60 explicit ComparatorAdapter(const LevelDBComparator* comparator) 59 : comparator_(comparator) {}
61 : comparator_(comparator) {}
62 60
63 virtual int Compare(const leveldb::Slice& a, const leveldb::Slice& b) const 61 int LevelDBDatabase::ComparatorAdapter::Compare(const leveldb::Slice& a,
64 OVERRIDE { 62 const leveldb::Slice& b) const {
65 return comparator_->Compare(MakeStringPiece(a), MakeStringPiece(b)); 63 return comparator_->Compare(MakeStringPiece(a), MakeStringPiece(b));
66 } 64 }
67 65
68 virtual const char* Name() const OVERRIDE { return comparator_->Name(); } 66 const char* LevelDBDatabase::ComparatorAdapter::Name() const {
67 return comparator_->Name();
68 }
69 69
70 // TODO(jsbell): Support the methods below in the future. 70 // TODO(jsbell): Support the methods below in the future.
71 virtual void FindShortestSeparator(std::string* start, 71 void LevelDBDatabase::ComparatorAdapter::FindShortestSeparator(
72 const leveldb::Slice& limit) const 72 std::string* start,
73 OVERRIDE {} 73 const leveldb::Slice& limit) const {}
74 virtual void FindShortSuccessor(std::string* key) const OVERRIDE {}
75 74
76 private: 75 void LevelDBDatabase::ComparatorAdapter::FindShortSuccessor(
77 const LevelDBComparator* comparator_; 76 std::string* key) const {}
78 };
79 77
80 LevelDBSnapshot::LevelDBSnapshot(LevelDBDatabase* db) 78 LevelDBSnapshot::LevelDBSnapshot(LevelDBDatabase* db)
81 : db_(db->db_.get()), snapshot_(db_->GetSnapshot()) {} 79 : db_(db->db_.get()), snapshot_(db_->GetSnapshot()) {}
82 80
83 LevelDBSnapshot::~LevelDBSnapshot() { db_->ReleaseSnapshot(snapshot_); } 81 LevelDBSnapshot::~LevelDBSnapshot() { db_->ReleaseSnapshot(snapshot_); }
84 82
85 LevelDBDatabase::LevelDBDatabase() {} 83 LevelDBDatabase::LevelDBDatabase() {}
86 84
87 LevelDBDatabase::~LevelDBDatabase() { 85 LevelDBDatabase::~LevelDBDatabase() {
88 // db_'s destructor uses comparator_adapter_; order of deletion is important. 86 // db_'s destructor uses comparator_adapter_; order of deletion is important.
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 453 }
456 454
457 void LevelDBDatabase::Compact(const base::StringPiece& start, 455 void LevelDBDatabase::Compact(const base::StringPiece& start,
458 const base::StringPiece& stop) { 456 const base::StringPiece& stop) {
459 const leveldb::Slice start_slice = MakeSlice(start); 457 const leveldb::Slice start_slice = MakeSlice(start);
460 const leveldb::Slice stop_slice = MakeSlice(stop); 458 const leveldb::Slice stop_slice = MakeSlice(stop);
461 db_->CompactRange(&start_slice, &stop_slice); 459 db_->CompactRange(&start_slice, &stop_slice);
462 } 460 }
463 461
464 } // namespace content 462 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/leveldb/leveldb_database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698