| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_class_factory.h" | 5 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "content/browser/indexed_db/indexed_db_transaction.h" | 10 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 10 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h" | 11 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h" |
| 11 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 12 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 15 static IndexedDBClassFactory::GetterCallback* s_factory_getter; | 16 static IndexedDBClassFactory::GetterCallback* s_factory_getter; |
| 16 static ::base::LazyInstance<IndexedDBClassFactory>::Leaky s_factory = | 17 static ::base::LazyInstance<IndexedDBClassFactory>::Leaky s_factory = |
| 17 LAZY_INSTANCE_INITIALIZER; | 18 LAZY_INSTANCE_INITIALIZER; |
| 18 | 19 |
| 19 void IndexedDBClassFactory::SetIndexedDBClassFactoryGetter(GetterCallback* cb) { | 20 void IndexedDBClassFactory::SetIndexedDBClassFactoryGetter(GetterCallback* cb) { |
| 20 s_factory_getter = cb; | 21 s_factory_getter = cb; |
| 21 } | 22 } |
| 22 | 23 |
| 23 IndexedDBClassFactory* IndexedDBClassFactory::Get() { | 24 IndexedDBClassFactory* IndexedDBClassFactory::Get() { |
| 24 if (s_factory_getter) | 25 if (s_factory_getter) |
| 25 return (*s_factory_getter)(); | 26 return (*s_factory_getter)(); |
| 26 else | 27 else |
| 27 return s_factory.Pointer(); | 28 return s_factory.Pointer(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 IndexedDBDatabase* IndexedDBClassFactory::CreateIndexedDBDatabase( | 31 scoped_refptr<IndexedDBDatabase> IndexedDBClassFactory::CreateIndexedDBDatabase( |
| 31 const base::string16& name, | 32 const base::string16& name, |
| 32 IndexedDBBackingStore* backing_store, | 33 IndexedDBBackingStore* backing_store, |
| 33 IndexedDBFactory* factory, | 34 IndexedDBFactory* factory, |
| 34 const IndexedDBDatabase::Identifier& unique_identifier) { | 35 const IndexedDBDatabase::Identifier& unique_identifier) { |
| 35 return new IndexedDBDatabase(name, backing_store, factory, unique_identifier); | 36 return new IndexedDBDatabase(name, backing_store, factory, unique_identifier); |
| 36 } | 37 } |
| 37 | 38 |
| 38 IndexedDBTransaction* IndexedDBClassFactory::CreateIndexedDBTransaction( | 39 IndexedDBTransaction* IndexedDBClassFactory::CreateIndexedDBTransaction( |
| 39 int64_t id, | 40 int64_t id, |
| 40 base::WeakPtr<IndexedDBConnection> connection, | 41 base::WeakPtr<IndexedDBConnection> connection, |
| 41 const std::set<int64_t>& scope, | 42 const std::set<int64_t>& scope, |
| 42 blink::WebIDBTransactionMode mode, | 43 blink::WebIDBTransactionMode mode, |
| 43 IndexedDBBackingStore::Transaction* backing_store_transaction) { | 44 IndexedDBBackingStore::Transaction* backing_store_transaction) { |
| 44 return new IndexedDBTransaction(id, std::move(connection), scope, mode, | 45 // The transaction adds itself to |connection|'s database's transaction |
| 45 backing_store_transaction); | 46 // coordinator, which owns the object. |
| 47 IndexedDBTransaction* transaction = new IndexedDBTransaction( |
| 48 id, std::move(connection), scope, mode, backing_store_transaction); |
| 49 return transaction; |
| 46 } | 50 } |
| 47 | 51 |
| 48 LevelDBTransaction* IndexedDBClassFactory::CreateLevelDBTransaction( | 52 scoped_refptr<LevelDBTransaction> |
| 49 LevelDBDatabase* db) { | 53 IndexedDBClassFactory::CreateLevelDBTransaction(LevelDBDatabase* db) { |
| 50 return new LevelDBTransaction(db); | 54 return new LevelDBTransaction(db); |
| 51 } | 55 } |
| 52 | 56 |
| 53 content::LevelDBIteratorImpl* IndexedDBClassFactory::CreateIteratorImpl( | 57 std::unique_ptr<LevelDBIteratorImpl> IndexedDBClassFactory::CreateIteratorImpl( |
| 54 std::unique_ptr<leveldb::Iterator> iterator) { | 58 std::unique_ptr<leveldb::Iterator> iterator) { |
| 55 return new LevelDBIteratorImpl(std::move(iterator)); | 59 return base::WrapUnique(new LevelDBIteratorImpl(std::move(iterator))); |
| 56 } | 60 } |
| 57 | 61 |
| 58 } // namespace content | 62 } // namespace content |
| OLD | NEW |