OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 5 #include <stdint.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
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/macros.h" | 10 #include "base/macros.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 scoped_refptr<ForceCloseDBCallbacks> open_callbacks = | 186 scoped_refptr<ForceCloseDBCallbacks> open_callbacks = |
187 new ForceCloseDBCallbacks(idb_context, kTestOrigin); | 187 new ForceCloseDBCallbacks(idb_context, kTestOrigin); |
188 | 188 |
189 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = | 189 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = |
190 new ForceCloseDBCallbacks(idb_context, kTestOrigin); | 190 new ForceCloseDBCallbacks(idb_context, kTestOrigin); |
191 | 191 |
192 IndexedDBFactory* factory = idb_context->GetIDBFactory(); | 192 IndexedDBFactory* factory = idb_context->GetIDBFactory(); |
193 | 193 |
194 test_path = idb_context->GetFilePathForTesting(kTestOrigin); | 194 test_path = idb_context->GetFilePathForTesting(kTestOrigin); |
195 | 195 |
196 IndexedDBPendingConnection open_connection(open_callbacks, | 196 std::unique_ptr<IndexedDBPendingConnection> open_connection( |
197 open_db_callbacks, | 197 new IndexedDBPendingConnection( |
198 0 /* child_process_id */, | 198 open_callbacks, open_db_callbacks, 0 /* child_process_id */, |
199 0 /* host_transaction_id */, | 199 0 /* host_transaction_id */, 0 /* version */)); |
200 0 /* version */); | 200 factory->Open(base::ASCIIToUTF16("opendb"), std::move(open_connection), |
201 factory->Open(base::ASCIIToUTF16("opendb"), open_connection, | |
202 NULL /* request_context */, Origin(kTestOrigin), | 201 NULL /* request_context */, Origin(kTestOrigin), |
203 idb_context->data_path()); | 202 idb_context->data_path()); |
204 IndexedDBPendingConnection closed_connection(closed_callbacks, | 203 std::unique_ptr<IndexedDBPendingConnection> closed_connection( |
205 closed_db_callbacks, | 204 new IndexedDBPendingConnection( |
206 0 /* child_process_id */, | 205 closed_callbacks, closed_db_callbacks, 0 /* child_process_id */, |
207 0 /* host_transaction_id */, | 206 0 /* host_transaction_id */, 0 /* version */)); |
208 0 /* version */); | 207 factory->Open(base::ASCIIToUTF16("closeddb"), std::move(closed_connection), |
209 factory->Open(base::ASCIIToUTF16("closeddb"), closed_connection, | |
210 NULL /* request_context */, Origin(kTestOrigin), | 208 NULL /* request_context */, Origin(kTestOrigin), |
211 idb_context->data_path()); | 209 idb_context->data_path()); |
212 | 210 |
213 closed_callbacks->connection()->Close(); | 211 closed_callbacks->connection()->Close(); |
214 | 212 |
215 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. | 213 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. |
216 idb_context->TaskRunner()->PostTask( | 214 idb_context->TaskRunner()->PostTask( |
217 FROM_HERE, | 215 FROM_HERE, |
218 base::Bind(static_cast<void (IndexedDBContextImpl::*)(const Origin&)>( | 216 base::Bind(static_cast<void (IndexedDBContextImpl::*)(const Origin&)>( |
219 &IndexedDBContextImpl::DeleteForOrigin), | 217 &IndexedDBContextImpl::DeleteForOrigin), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 new IndexedDBContextImpl(temp_dir.path(), special_storage_policy_.get(), | 265 new IndexedDBContextImpl(temp_dir.path(), special_storage_policy_.get(), |
268 quota_manager_proxy_.get(), task_runner_.get()); | 266 quota_manager_proxy_.get(), task_runner_.get()); |
269 | 267 |
270 scoped_refptr<IndexedDBFactoryImpl> factory = | 268 scoped_refptr<IndexedDBFactoryImpl> factory = |
271 static_cast<IndexedDBFactoryImpl*>(context->GetIDBFactory()); | 269 static_cast<IndexedDBFactoryImpl*>(context->GetIDBFactory()); |
272 | 270 |
273 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 271 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
274 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 272 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
275 new MockIndexedDBDatabaseCallbacks()); | 273 new MockIndexedDBDatabaseCallbacks()); |
276 const int64_t transaction_id = 1; | 274 const int64_t transaction_id = 1; |
277 IndexedDBPendingConnection connection( | 275 std::unique_ptr<IndexedDBPendingConnection> connection( |
278 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 276 new IndexedDBPendingConnection( |
279 IndexedDBDatabaseMetadata::DEFAULT_VERSION); | 277 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
280 factory->Open(base::ASCIIToUTF16("db"), connection, | 278 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 279 factory->Open(base::ASCIIToUTF16("db"), std::move(connection), |
281 NULL /* request_context */, Origin(kTestOrigin), | 280 NULL /* request_context */, Origin(kTestOrigin), |
282 temp_dir.path()); | 281 temp_dir.path()); |
283 | 282 |
284 EXPECT_TRUE(callbacks->connection()); | 283 EXPECT_TRUE(callbacks->connection()); |
285 | 284 |
286 // ConnectionOpened() is usually called by the dispatcher. | 285 // ConnectionOpened() is usually called by the dispatcher. |
287 context->ConnectionOpened(kTestOrigin, callbacks->connection()); | 286 context->ConnectionOpened(kTestOrigin, callbacks->connection()); |
288 | 287 |
289 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); | 288 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); |
290 | 289 |
291 // Simulate the write failure. | 290 // Simulate the write failure. |
292 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); | 291 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); |
293 callbacks->connection()->database()->TransactionCommitFailed(status); | 292 callbacks->connection()->database()->TransactionCommitFailed(status); |
294 | 293 |
295 EXPECT_TRUE(db_callbacks->forced_close_called()); | 294 EXPECT_TRUE(db_callbacks->forced_close_called()); |
296 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); | 295 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); |
297 } | 296 } |
298 | 297 |
299 } // namespace content | 298 } // namespace content |
OLD | NEW |