OLD | NEW |
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/indexed_db_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 using base::ASCIIToUTF16; | 29 using base::ASCIIToUTF16; |
30 | 30 |
31 namespace content { | 31 namespace content { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 class Comparator : public LevelDBComparator { | 35 class Comparator : public LevelDBComparator { |
36 public: | 36 public: |
37 virtual int Compare(const base::StringPiece& a, | 37 virtual int Compare(const base::StringPiece& a, |
38 const base::StringPiece& b) const OVERRIDE { | 38 const base::StringPiece& b) const override { |
39 return content::Compare(a, b, false /*index_keys*/); | 39 return content::Compare(a, b, false /*index_keys*/); |
40 } | 40 } |
41 virtual const char* Name() const OVERRIDE { return "idb_cmp1"; } | 41 virtual const char* Name() const override { return "idb_cmp1"; } |
42 }; | 42 }; |
43 | 43 |
44 class DefaultLevelDBFactory : public LevelDBFactory { | 44 class DefaultLevelDBFactory : public LevelDBFactory { |
45 public: | 45 public: |
46 DefaultLevelDBFactory() {} | 46 DefaultLevelDBFactory() {} |
47 virtual leveldb::Status OpenLevelDB(const base::FilePath& file_name, | 47 virtual leveldb::Status OpenLevelDB(const base::FilePath& file_name, |
48 const LevelDBComparator* comparator, | 48 const LevelDBComparator* comparator, |
49 scoped_ptr<LevelDBDatabase>* db, | 49 scoped_ptr<LevelDBDatabase>* db, |
50 bool* is_disk_full) OVERRIDE { | 50 bool* is_disk_full) override { |
51 return LevelDBDatabase::Open(file_name, comparator, db, is_disk_full); | 51 return LevelDBDatabase::Open(file_name, comparator, db, is_disk_full); |
52 } | 52 } |
53 virtual leveldb::Status DestroyLevelDB( | 53 virtual leveldb::Status DestroyLevelDB( |
54 const base::FilePath& file_name) OVERRIDE { | 54 const base::FilePath& file_name) override { |
55 return LevelDBDatabase::Destroy(file_name); | 55 return LevelDBDatabase::Destroy(file_name); |
56 } | 56 } |
57 | 57 |
58 private: | 58 private: |
59 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory); | 59 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory); |
60 }; | 60 }; |
61 | 61 |
62 class TestableIndexedDBBackingStore : public IndexedDBBackingStore { | 62 class TestableIndexedDBBackingStore : public IndexedDBBackingStore { |
63 public: | 63 public: |
64 static scoped_refptr<TestableIndexedDBBackingStore> Open( | 64 static scoped_refptr<TestableIndexedDBBackingStore> Open( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 void ClearWrites() { writes_.clear(); } | 112 void ClearWrites() { writes_.clear(); } |
113 const std::vector<int64>& removals() const { return removals_; } | 113 const std::vector<int64>& removals() const { return removals_; } |
114 void ClearRemovals() { removals_.clear(); } | 114 void ClearRemovals() { removals_.clear(); } |
115 | 115 |
116 protected: | 116 protected: |
117 virtual ~TestableIndexedDBBackingStore() {} | 117 virtual ~TestableIndexedDBBackingStore() {} |
118 | 118 |
119 virtual bool WriteBlobFile( | 119 virtual bool WriteBlobFile( |
120 int64 database_id, | 120 int64 database_id, |
121 const Transaction::WriteDescriptor& descriptor, | 121 const Transaction::WriteDescriptor& descriptor, |
122 Transaction::ChainedBlobWriter* chained_blob_writer) OVERRIDE { | 122 Transaction::ChainedBlobWriter* chained_blob_writer) override { |
123 if (KeyPrefix::IsValidDatabaseId(database_id_)) { | 123 if (KeyPrefix::IsValidDatabaseId(database_id_)) { |
124 if (database_id_ != database_id) { | 124 if (database_id_ != database_id) { |
125 return false; | 125 return false; |
126 } | 126 } |
127 } else { | 127 } else { |
128 database_id_ = database_id; | 128 database_id_ = database_id; |
129 } | 129 } |
130 writes_.push_back(descriptor); | 130 writes_.push_back(descriptor); |
131 task_runner()->PostTask( | 131 task_runner()->PostTask( |
132 FROM_HERE, | 132 FROM_HERE, |
133 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, | 133 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, |
134 chained_blob_writer, | 134 chained_blob_writer, |
135 true, | 135 true, |
136 1)); | 136 1)); |
137 return true; | 137 return true; |
138 } | 138 } |
139 | 139 |
140 virtual bool RemoveBlobFile(int64 database_id, int64 key) OVERRIDE { | 140 virtual bool RemoveBlobFile(int64 database_id, int64 key) override { |
141 if (database_id_ != database_id || | 141 if (database_id_ != database_id || |
142 !KeyPrefix::IsValidDatabaseId(database_id)) { | 142 !KeyPrefix::IsValidDatabaseId(database_id)) { |
143 return false; | 143 return false; |
144 } | 144 } |
145 removals_.push_back(key); | 145 removals_.push_back(key); |
146 return true; | 146 return true; |
147 } | 147 } |
148 | 148 |
149 // Timers don't play nicely with unit tests. | 149 // Timers don't play nicely with unit tests. |
150 virtual void StartJournalCleaningTimer() OVERRIDE { | 150 virtual void StartJournalCleaningTimer() override { |
151 CleanPrimaryJournalIgnoreReturn(); | 151 CleanPrimaryJournalIgnoreReturn(); |
152 } | 152 } |
153 | 153 |
154 private: | 154 private: |
155 TestableIndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, | 155 TestableIndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, |
156 const GURL& origin_url, | 156 const GURL& origin_url, |
157 const base::FilePath& blob_path, | 157 const base::FilePath& blob_path, |
158 net::URLRequestContext* request_context, | 158 net::URLRequestContext* request_context, |
159 scoped_ptr<LevelDBDatabase> db, | 159 scoped_ptr<LevelDBDatabase> db, |
160 scoped_ptr<LevelDBComparator> comparator, | 160 scoped_ptr<LevelDBComparator> comparator, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 virtual ~TestIDBFactory() {} | 204 virtual ~TestIDBFactory() {} |
205 | 205 |
206 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( | 206 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( |
207 const GURL& origin_url, | 207 const GURL& origin_url, |
208 const base::FilePath& data_directory, | 208 const base::FilePath& data_directory, |
209 net::URLRequestContext* request_context, | 209 net::URLRequestContext* request_context, |
210 blink::WebIDBDataLoss* data_loss, | 210 blink::WebIDBDataLoss* data_loss, |
211 std::string* data_loss_message, | 211 std::string* data_loss_message, |
212 bool* disk_full, | 212 bool* disk_full, |
213 bool first_time, | 213 bool first_time, |
214 leveldb::Status* status) OVERRIDE { | 214 leveldb::Status* status) override { |
215 DefaultLevelDBFactory leveldb_factory; | 215 DefaultLevelDBFactory leveldb_factory; |
216 return TestableIndexedDBBackingStore::Open(this, | 216 return TestableIndexedDBBackingStore::Open(this, |
217 origin_url, | 217 origin_url, |
218 data_directory, | 218 data_directory, |
219 request_context, | 219 request_context, |
220 &leveldb_factory, | 220 &leveldb_factory, |
221 context()->TaskRunner(), | 221 context()->TaskRunner(), |
222 status); | 222 status); |
223 } | 223 } |
224 | 224 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 IndexedDBValue m_value3; | 352 IndexedDBValue m_value3; |
353 std::vector<IndexedDBBlobInfo> m_blob_info; | 353 std::vector<IndexedDBBlobInfo> m_blob_info; |
354 | 354 |
355 private: | 355 private: |
356 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStoreTest); | 356 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStoreTest); |
357 }; | 357 }; |
358 | 358 |
359 class TestCallback : public IndexedDBBackingStore::BlobWriteCallback { | 359 class TestCallback : public IndexedDBBackingStore::BlobWriteCallback { |
360 public: | 360 public: |
361 TestCallback() : called(false), succeeded(false) {} | 361 TestCallback() : called(false), succeeded(false) {} |
362 virtual void Run(bool succeeded_in) OVERRIDE { | 362 virtual void Run(bool succeeded_in) override { |
363 called = true; | 363 called = true; |
364 succeeded = succeeded_in; | 364 succeeded = succeeded_in; |
365 } | 365 } |
366 bool called; | 366 bool called; |
367 bool succeeded; | 367 bool succeeded; |
368 | 368 |
369 protected: | 369 protected: |
370 virtual ~TestCallback() {} | 370 virtual ~TestCallback() {} |
371 | 371 |
372 private: | 372 private: |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 | 998 |
999 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); | 999 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); |
1000 EXPECT_TRUE(s.ok()); | 1000 EXPECT_TRUE(s.ok()); |
1001 EXPECT_EQ(names.size(), 1ULL); | 1001 EXPECT_EQ(names.size(), 1ULL); |
1002 EXPECT_EQ(names[0], db1_name); | 1002 EXPECT_EQ(names[0], db1_name); |
1003 } | 1003 } |
1004 | 1004 |
1005 } // namespace | 1005 } // namespace |
1006 | 1006 |
1007 } // namespace content | 1007 } // namespace content |
OLD | NEW |