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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "storage/browser/quota/special_storage_policy.h" | 31 #include "storage/browser/quota/special_storage_policy.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" | 33 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" |
34 | 34 |
35 using base::ASCIIToUTF16; | 35 using base::ASCIIToUTF16; |
36 using url::Origin; | 36 using url::Origin; |
37 | 37 |
38 namespace content { | 38 namespace content { |
39 | 39 |
40 namespace { | 40 namespace { |
| 41 static const size_t kDefaultMaxOpenIteratorsPerDatabase = 50; |
41 | 42 |
42 // Write |content| to |file|. Returns true on success. | 43 // Write |content| to |file|. Returns true on success. |
43 bool WriteFile(const base::FilePath& file, base::StringPiece content) { | 44 bool WriteFile(const base::FilePath& file, base::StringPiece content) { |
44 int write_size = base::WriteFile(file, content.data(), content.length()); | 45 int write_size = base::WriteFile(file, content.data(), content.length()); |
45 return write_size >= 0 && write_size == static_cast<int>(content.length()); | 46 return write_size >= 0 && write_size == static_cast<int>(content.length()); |
46 } | 47 } |
47 | 48 |
48 class Comparator : public LevelDBComparator { | 49 class Comparator : public LevelDBComparator { |
49 public: | 50 public: |
50 int Compare(const base::StringPiece& a, | 51 int Compare(const base::StringPiece& a, |
51 const base::StringPiece& b) const override { | 52 const base::StringPiece& b) const override { |
52 return content::Compare(a, b, false /*index_keys*/); | 53 return content::Compare(a, b, false /*index_keys*/); |
53 } | 54 } |
54 const char* Name() const override { return "idb_cmp1"; } | 55 const char* Name() const override { return "idb_cmp1"; } |
55 }; | 56 }; |
56 | 57 |
57 class DefaultLevelDBFactory : public LevelDBFactory { | 58 class DefaultLevelDBFactory : public LevelDBFactory { |
58 public: | 59 public: |
59 DefaultLevelDBFactory() {} | 60 DefaultLevelDBFactory() {} |
60 | 61 |
61 leveldb::Status OpenLevelDB(const base::FilePath& file_name, | 62 leveldb::Status OpenLevelDB(const base::FilePath& file_name, |
62 const LevelDBComparator* comparator, | 63 const LevelDBComparator* comparator, |
63 std::unique_ptr<LevelDBDatabase>* db, | 64 std::unique_ptr<LevelDBDatabase>* db, |
64 bool* is_disk_full) override { | 65 bool* is_disk_full) override { |
65 return LevelDBDatabase::Open(file_name, comparator, db, is_disk_full); | 66 return LevelDBDatabase::Open(file_name, comparator, |
| 67 kDefaultMaxOpenIteratorsPerDatabase, db, |
| 68 is_disk_full); |
66 } | 69 } |
67 leveldb::Status DestroyLevelDB(const base::FilePath& file_name) override { | 70 leveldb::Status DestroyLevelDB(const base::FilePath& file_name) override { |
68 return LevelDBDatabase::Destroy(file_name); | 71 return LevelDBDatabase::Destroy(file_name); |
69 } | 72 } |
70 | 73 |
71 private: | 74 private: |
72 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory); | 75 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory); |
73 }; | 76 }; |
74 | 77 |
75 class TestableIndexedDBBackingStore : public IndexedDBBackingStore { | 78 class TestableIndexedDBBackingStore : public IndexedDBBackingStore { |
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 | 1149 |
1147 // Dictionary, message key and more. | 1150 // Dictionary, message key and more. |
1148 ASSERT_TRUE(WriteFile(info_path, "{\"message\":\"foo\",\"bar\":5}")); | 1151 ASSERT_TRUE(WriteFile(info_path, "{\"message\":\"foo\",\"bar\":5}")); |
1149 EXPECT_TRUE( | 1152 EXPECT_TRUE( |
1150 IndexedDBBackingStore::ReadCorruptionInfo(path_base, origin, &message)); | 1153 IndexedDBBackingStore::ReadCorruptionInfo(path_base, origin, &message)); |
1151 EXPECT_FALSE(PathExists(info_path)); | 1154 EXPECT_FALSE(PathExists(info_path)); |
1152 EXPECT_EQ("foo", message); | 1155 EXPECT_EQ("foo", message); |
1153 } | 1156 } |
1154 | 1157 |
1155 } // namespace content | 1158 } // namespace content |
OLD | NEW |