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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 writes_.push_back(descriptor); | 129 writes_.push_back(descriptor); |
130 task_runner()->PostTask( | 130 task_runner()->PostTask( |
131 FROM_HERE, | 131 FROM_HERE, |
132 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, | 132 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, |
133 chained_blob_writer, | 133 chained_blob_writer, |
134 true, | 134 true, |
135 1)); | 135 1)); |
136 return true; | 136 return true; |
137 } | 137 } |
138 | 138 |
139 bool RemoveBlobFile(int64 database_id, int64 key) override { | 139 bool RemoveBlobFile(int64 database_id, int64 key) const override { |
140 if (database_id_ != database_id || | 140 if (database_id_ != database_id || |
141 !KeyPrefix::IsValidDatabaseId(database_id)) { | 141 !KeyPrefix::IsValidDatabaseId(database_id)) { |
142 return false; | 142 return false; |
143 } | 143 } |
144 removals_.push_back(key); | 144 removals_.push_back(key); |
145 return true; | 145 return true; |
146 } | 146 } |
147 | 147 |
148 // Timers don't play nicely with unit tests. | 148 // Timers don't play nicely with unit tests. |
149 void StartJournalCleaningTimer() override { | 149 void StartJournalCleaningTimer() override { |
(...skipping 12 matching lines...) Expand all Loading... | |
162 origin_url, | 162 origin_url, |
163 blob_path, | 163 blob_path, |
164 request_context, | 164 request_context, |
165 db.Pass(), | 165 db.Pass(), |
166 comparator.Pass(), | 166 comparator.Pass(), |
167 task_runner), | 167 task_runner), |
168 database_id_(0) {} | 168 database_id_(0) {} |
169 | 169 |
170 int64 database_id_; | 170 int64 database_id_; |
171 std::vector<Transaction::WriteDescriptor> writes_; | 171 std::vector<Transaction::WriteDescriptor> writes_; |
172 std::vector<int64> removals_; | 172 |
173 // This is modified in an overridden virtual function that is properly const | |
174 // in the real implementation, therefore must be mutable here. | |
cmumford
2015/01/22 00:56:57
Why is RemoveBlobFile properly const? Seams reason
jsbell
2015/01/22 19:40:45
The various blob methods are a mix of modifying th
| |
175 mutable std::vector<int64> removals_; | |
173 | 176 |
174 DISALLOW_COPY_AND_ASSIGN(TestableIndexedDBBackingStore); | 177 DISALLOW_COPY_AND_ASSIGN(TestableIndexedDBBackingStore); |
175 }; | 178 }; |
176 | 179 |
177 class TestIDBFactory : public IndexedDBFactoryImpl { | 180 class TestIDBFactory : public IndexedDBFactoryImpl { |
178 public: | 181 public: |
179 explicit TestIDBFactory(IndexedDBContextImpl* idb_context) | 182 explicit TestIDBFactory(IndexedDBContextImpl* idb_context) |
180 : IndexedDBFactoryImpl(idb_context) {} | 183 : IndexedDBFactoryImpl(idb_context) {} |
181 | 184 |
182 scoped_refptr<TestableIndexedDBBackingStore> OpenBackingStoreForTest( | 185 scoped_refptr<TestableIndexedDBBackingStore> OpenBackingStoreForTest( |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok()); | 640 EXPECT_TRUE(transaction2.CommitPhaseOne(callback).ok()); |
638 task_runner_->RunUntilIdle(); | 641 task_runner_->RunUntilIdle(); |
639 EXPECT_TRUE(callback->called); | 642 EXPECT_TRUE(callback->called); |
640 EXPECT_TRUE(callback->succeeded); | 643 EXPECT_TRUE(callback->succeeded); |
641 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | 644 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); |
642 EXPECT_EQ(0UL, backing_store_->removals().size()); | 645 EXPECT_EQ(0UL, backing_store_->removals().size()); |
643 } | 646 } |
644 } | 647 } |
645 } | 648 } |
646 | 649 |
650 TEST_F(IndexedDBBackingStoreTest, BlobJournalInterleavedTransactions) { | |
651 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | |
652 transaction1.Begin(); | |
653 ScopedVector<storage::BlobDataHandle> handles1; | |
654 IndexedDBBackingStore::RecordIdentifier record1; | |
655 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, 1, 1, m_key3, &m_value3, | |
656 &handles1, &record1).ok()); | |
657 scoped_refptr<TestCallback> callback1(new TestCallback()); | |
658 EXPECT_TRUE(transaction1.CommitPhaseOne(callback1).ok()); | |
659 task_runner_->RunUntilIdle(); | |
660 EXPECT_TRUE(CheckBlobWrites()); | |
661 EXPECT_TRUE(callback1->called); | |
662 EXPECT_TRUE(callback1->succeeded); | |
663 EXPECT_EQ(0U, backing_store_->removals().size()); | |
664 | |
665 IndexedDBBackingStore::Transaction transaction2(backing_store_.get()); | |
666 transaction2.Begin(); | |
667 ScopedVector<storage::BlobDataHandle> handles2; | |
668 IndexedDBBackingStore::RecordIdentifier record2; | |
669 EXPECT_TRUE(backing_store_->PutRecord(&transaction2, 1, 1, m_key1, &m_value1, | |
670 &handles2, &record2).ok()); | |
671 scoped_refptr<TestCallback> callback2(new TestCallback()); | |
672 EXPECT_TRUE(transaction2.CommitPhaseOne(callback2).ok()); | |
673 task_runner_->RunUntilIdle(); | |
674 EXPECT_TRUE(CheckBlobWrites()); | |
675 EXPECT_TRUE(callback2->called); | |
676 EXPECT_TRUE(callback2->succeeded); | |
677 EXPECT_EQ(0U, backing_store_->removals().size()); | |
678 | |
679 EXPECT_TRUE(transaction1.CommitPhaseTwo().ok()); | |
680 EXPECT_EQ(0U, backing_store_->removals().size()); | |
681 | |
682 EXPECT_TRUE(transaction2.CommitPhaseTwo().ok()); | |
683 EXPECT_EQ(0U, backing_store_->removals().size()); | |
684 } | |
685 | |
647 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { | 686 TEST_F(IndexedDBBackingStoreTest, LiveBlobJournal) { |
648 { | 687 { |
649 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); | 688 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); |
650 transaction1.Begin(); | 689 transaction1.Begin(); |
651 ScopedVector<storage::BlobDataHandle> handles; | 690 ScopedVector<storage::BlobDataHandle> handles; |
652 IndexedDBBackingStore::RecordIdentifier record; | 691 IndexedDBBackingStore::RecordIdentifier record; |
653 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, | 692 EXPECT_TRUE(backing_store_->PutRecord(&transaction1, |
654 1, | 693 1, |
655 1, | 694 1, |
656 m_key3, | 695 m_key3, |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 | 1042 |
1004 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); | 1043 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); |
1005 EXPECT_TRUE(s.ok()); | 1044 EXPECT_TRUE(s.ok()); |
1006 EXPECT_EQ(names.size(), 1ULL); | 1045 EXPECT_EQ(names.size(), 1ULL); |
1007 EXPECT_EQ(names[0], db1_name); | 1046 EXPECT_EQ(names[0], db1_name); |
1008 } | 1047 } |
1009 | 1048 |
1010 } // namespace | 1049 } // namespace |
1011 | 1050 |
1012 } // namespace content | 1051 } // namespace content |
OLD | NEW |