Commit 8f4c9206 authored by jsbell@chromium.org's avatar jsbell@chromium.org

Split IndexedDBFactory into virtual base + impl.

This change makes IndexedDBFactory a virtual base class, and what was
IndexedDBFactory is now IndexedDBFactoryImpl. This change will allow tests
to create proper mock factories and not require them to instantiate the
"real" factory (which often doesn't work) in the test. It will also take us
one step closer to eliminating special cases in IDB's other classes where
having a factory is optional (because tests don't create them).

BUG=393974
R=ericu@chromium.org, jochen@chromium.org, jsbell@chromium.org, michaeln@chromium.org

Review URL: https://codereview.chromium.org/313883003

Patch from cmumford@chromium.org <cmumford@chromium.org>.

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284161 0039d316-1c4b-4281-b951-d872f2087c98
parent 15cc6f4a
......@@ -7,7 +7,7 @@
#include "base/test/test_simple_task_runner.h"
#include "content/browser/indexed_db/indexed_db_active_blob_registry.h"
#include "content/browser/indexed_db/indexed_db_backing_store.h"
#include "content/browser/indexed_db/indexed_db_factory.h"
#include "content/browser/indexed_db/indexed_db_factory_impl.h"
#include "content/browser/indexed_db/indexed_db_fake_backing_store.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -15,9 +15,9 @@ namespace content {
namespace {
class MockIDBFactory : public IndexedDBFactory {
class MockIDBFactory : public IndexedDBFactoryImpl {
public:
MockIDBFactory() : IndexedDBFactory(NULL), duplicate_calls_(false) {}
MockIDBFactory() : IndexedDBFactoryImpl(NULL), duplicate_calls_(false) {}
virtual void ReportOutstandingBlobs(const GURL& origin_url,
bool blobs_outstanding) OVERRIDE {
......
......@@ -14,6 +14,7 @@
#include "base/task_runner.h"
#include "base/test/test_simple_task_runner.h"
#include "content/browser/indexed_db/indexed_db_context_impl.h"
#include "content/browser/indexed_db/indexed_db_factory_impl.h"
#include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
#include "content/browser/indexed_db/indexed_db_value.h"
#include "content/browser/indexed_db/leveldb/leveldb_factory.h"
......@@ -173,10 +174,10 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore {
DISALLOW_COPY_AND_ASSIGN(TestableIndexedDBBackingStore);
};
class TestIDBFactory : public IndexedDBFactory {
class TestIDBFactory : public IndexedDBFactoryImpl {
public:
explicit TestIDBFactory(IndexedDBContextImpl* idb_context)
: IndexedDBFactory(idb_context) {}
: IndexedDBFactoryImpl(idb_context) {}
scoped_refptr<TestableIndexedDBBackingStore> OpenBackingStoreForTest(
const GURL& origin,
......
......@@ -23,7 +23,7 @@
#include "content/browser/indexed_db/indexed_db_connection.h"
#include "content/browser/indexed_db/indexed_db_database.h"
#include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
#include "content/browser/indexed_db/indexed_db_factory.h"
#include "content/browser/indexed_db/indexed_db_factory_impl.h"
#include "content/browser/indexed_db/indexed_db_quota_client.h"
#include "content/browser/indexed_db/indexed_db_tracing.h"
#include "content/browser/indexed_db/indexed_db_transaction.h"
......@@ -123,7 +123,7 @@ IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() {
// Prime our cache of origins with existing databases so we can
// detect when dbs are newly created.
GetOriginSet();
factory_ = new IndexedDBFactory(this);
factory_ = new IndexedDBFactoryImpl(this);
}
return factory_;
}
......
......@@ -27,7 +27,6 @@ class URLRequestContext;
namespace content {
class IndexedDBBackingStore;
class IndexedDBContextImpl;
struct IndexedDBPendingConnection;
class CONTENT_EXPORT IndexedDBFactory
......@@ -36,52 +35,53 @@ class CONTENT_EXPORT IndexedDBFactory
typedef std::multimap<GURL, IndexedDBDatabase*> OriginDBMap;
typedef OriginDBMap::const_iterator OriginDBMapIterator;
explicit IndexedDBFactory(IndexedDBContextImpl* context);
virtual void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier,
bool forcedClose) = 0;
void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier,
bool forcedClose);
void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks,
virtual void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks,
const GURL& origin_url,
const base::FilePath& data_directory,
net::URLRequestContext* request_context);
void Open(const base::string16& name,
net::URLRequestContext* request_context) = 0;
virtual void Open(const base::string16& name,
const IndexedDBPendingConnection& connection,
net::URLRequestContext* request_context,
const GURL& origin_url,
const base::FilePath& data_directory);
const base::FilePath& data_directory) = 0;
void DeleteDatabase(const base::string16& name,
virtual void DeleteDatabase(const base::string16& name,
net::URLRequestContext* request_context,
scoped_refptr<IndexedDBCallbacks> callbacks,
const GURL& origin_url,
const base::FilePath& data_directory);
const base::FilePath& data_directory) = 0;
void HandleBackingStoreFailure(const GURL& origin_url);
void HandleBackingStoreCorruption(const GURL& origin_url,
const IndexedDBDatabaseError& error);
virtual void HandleBackingStoreFailure(const GURL& origin_url) = 0;
virtual void HandleBackingStoreCorruption(
const GURL& origin_url,
const IndexedDBDatabaseError& error) = 0;
std::pair<OriginDBMapIterator, OriginDBMapIterator> GetOpenDatabasesForOrigin(
const GURL& origin_url) const;
virtual std::pair<OriginDBMapIterator, OriginDBMapIterator>
GetOpenDatabasesForOrigin(const GURL& origin_url) const = 0;
void ForceClose(const GURL& origin_url);
virtual void ForceClose(const GURL& origin_url) = 0;
// Called by the IndexedDBContext destructor so the factory can do cleanup.
void ContextDestroyed();
virtual void ContextDestroyed() = 0;
// Called by the IndexedDBActiveBlobRegistry.
virtual void ReportOutstandingBlobs(const GURL& origin_url,
bool blobs_outstanding);
bool blobs_outstanding) = 0;
// Called by an IndexedDBDatabase when it is actually deleted.
void DatabaseDeleted(const IndexedDBDatabase::Identifier& identifier);
virtual void DatabaseDeleted(
const IndexedDBDatabase::Identifier& identifier) = 0;
size_t GetConnectionCount(const GURL& origin_url) const;
virtual size_t GetConnectionCount(const GURL& origin_url) const = 0;
protected:
friend class base::RefCountedThreadSafe<IndexedDBFactory>;
virtual ~IndexedDBFactory();
IndexedDBFactory() {}
virtual ~IndexedDBFactory() {}
virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore(
const GURL& origin_url,
......@@ -90,7 +90,7 @@ class CONTENT_EXPORT IndexedDBFactory
blink::WebIDBDataLoss* data_loss,
std::string* data_loss_reason,
bool* disk_full,
leveldb::Status* status);
leveldb::Status* status) = 0;
virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper(
const GURL& origin_url,
......@@ -100,54 +100,9 @@ class CONTENT_EXPORT IndexedDBFactory
std::string* data_loss_message,
bool* disk_full,
bool first_time,
leveldb::Status* status);
void ReleaseBackingStore(const GURL& origin_url, bool immediate);
void CloseBackingStore(const GURL& origin_url);
IndexedDBContextImpl* context() const { return context_; }
leveldb::Status* status) = 0;
private:
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
BackingStoreReleasedOnForcedClose);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
BackingStoreReleaseDelayedOnClose);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
DeleteDatabaseClosesBackingStore);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
ForceCloseReleasesBackingStore);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
GetDatabaseNamesClosesBackingStore);
FRIEND_TEST_ALL_PREFIXES(IndexedDBTest,
ForceCloseOpenDatabasesOnCommitFailure);
// Called internally after a database is closed, with some delay. If this
// factory has the last reference, it will be released.
void MaybeCloseBackingStore(const GURL& origin_url);
bool HasLastBackingStoreReference(const GURL& origin_url) const;
// Testing helpers, so unit tests don't need to grovel through internal state.
bool IsDatabaseOpen(const GURL& origin_url,
const base::string16& name) const;
bool IsBackingStoreOpen(const GURL& origin_url) const;
bool IsBackingStorePendingClose(const GURL& origin_url) const;
void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier);
IndexedDBContextImpl* context_;
typedef std::map<IndexedDBDatabase::Identifier,
IndexedDBDatabase*> IndexedDBDatabaseMap;
IndexedDBDatabaseMap database_map_;
OriginDBMap origin_dbs_;
typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> >
IndexedDBBackingStoreMap;
IndexedDBBackingStoreMap backing_store_map_;
std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_;
IndexedDBBackingStoreMap backing_stores_with_active_blobs_;
std::set<GURL> backends_opened_since_boot_;
DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory);
};
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/indexed_db/indexed_db_factory.h"
#include "content/browser/indexed_db/indexed_db_factory_impl.h"
#include <vector>
......@@ -24,12 +24,14 @@ namespace content {
const int64 kBackingStoreGracePeriodMs = 2000;
IndexedDBFactory::IndexedDBFactory(IndexedDBContextImpl* context)
: context_(context) {}
IndexedDBFactoryImpl::IndexedDBFactoryImpl(IndexedDBContextImpl* context)
: context_(context) {
}
IndexedDBFactory::~IndexedDBFactory() {}
IndexedDBFactoryImpl::~IndexedDBFactoryImpl() {
}
void IndexedDBFactory::RemoveDatabaseFromMaps(
void IndexedDBFactoryImpl::RemoveDatabaseFromMaps(
const IndexedDBDatabase::Identifier& identifier) {
IndexedDBDatabaseMap::iterator it = database_map_.find(identifier);
DCHECK(it != database_map_.end());
......@@ -47,10 +49,9 @@ void IndexedDBFactory::RemoveDatabaseFromMaps(
}
}
void IndexedDBFactory::ReleaseDatabase(
void IndexedDBFactoryImpl::ReleaseDatabase(
const IndexedDBDatabase::Identifier& identifier,
bool forcedClose) {
DCHECK(!database_map_.find(identifier)->second->backing_store());
RemoveDatabaseFromMaps(identifier);
......@@ -61,7 +62,7 @@ void IndexedDBFactory::ReleaseDatabase(
ReleaseBackingStore(identifier.first, forcedClose);
}
void IndexedDBFactory::ReleaseBackingStore(const GURL& origin_url,
void IndexedDBFactoryImpl::ReleaseBackingStore(const GURL& origin_url,
bool immediate) {
if (immediate) {
IndexedDBBackingStoreMap::iterator it =
......@@ -90,17 +91,18 @@ void IndexedDBFactory::ReleaseBackingStore(const GURL& origin_url,
backing_store_map_[origin_url]->close_timer()->Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kBackingStoreGracePeriodMs),
base::Bind(&IndexedDBFactory::MaybeCloseBackingStore, this, origin_url));
base::Bind(
&IndexedDBFactoryImpl::MaybeCloseBackingStore, this, origin_url));
}
void IndexedDBFactory::MaybeCloseBackingStore(const GURL& origin_url) {
void IndexedDBFactoryImpl::MaybeCloseBackingStore(const GURL& origin_url) {
// Another reference may have opened since the maybe-close was posted, so it
// is necessary to check again.
if (HasLastBackingStoreReference(origin_url))
CloseBackingStore(origin_url);
}
void IndexedDBFactory::CloseBackingStore(const GURL& origin_url) {
void IndexedDBFactoryImpl::CloseBackingStore(const GURL& origin_url) {
IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url);
DCHECK(it != backing_store_map_.end());
// Stop the timer (if it's running) - this may happen if the timer was started
......@@ -109,8 +111,8 @@ void IndexedDBFactory::CloseBackingStore(const GURL& origin_url) {
backing_store_map_.erase(it);
}
bool IndexedDBFactory::HasLastBackingStoreReference(const GURL& origin_url)
const {
bool IndexedDBFactoryImpl::HasLastBackingStoreReference(
const GURL& origin_url) const {
IndexedDBBackingStore* ptr;
{
// Scope so that the implicit scoped_refptr<> is freed.
......@@ -122,7 +124,7 @@ bool IndexedDBFactory::HasLastBackingStoreReference(const GURL& origin_url)
return ptr->HasOneRef();
}
void IndexedDBFactory::ForceClose(const GURL& origin_url) {
void IndexedDBFactoryImpl::ForceClose(const GURL& origin_url) {
std::pair<OriginDBMapIterator, OriginDBMapIterator> range =
GetOpenDatabasesForOrigin(origin_url);
......@@ -136,7 +138,7 @@ void IndexedDBFactory::ForceClose(const GURL& origin_url) {
ReleaseBackingStore(origin_url, true /* immediate */);
}
void IndexedDBFactory::ContextDestroyed() {
void IndexedDBFactoryImpl::ContextDestroyed() {
// Timers on backing stores hold a reference to this factory. When the
// context (which nominally owns this factory) is destroyed during thread
// termination the timers must be stopped so that this factory and the
......@@ -150,7 +152,7 @@ void IndexedDBFactory::ContextDestroyed() {
context_ = NULL;
}
void IndexedDBFactory::ReportOutstandingBlobs(const GURL& origin_url,
void IndexedDBFactoryImpl::ReportOutstandingBlobs(const GURL& origin_url,
bool blobs_outstanding) {
if (!context_)
return;
......@@ -171,12 +173,12 @@ void IndexedDBFactory::ReportOutstandingBlobs(const GURL& origin_url,
}
}
void IndexedDBFactory::GetDatabaseNames(
void IndexedDBFactoryImpl::GetDatabaseNames(
scoped_refptr<IndexedDBCallbacks> callbacks,
const GURL& origin_url,
const base::FilePath& data_directory,
net::URLRequestContext* request_context) {
IDB_TRACE("IndexedDBFactory::GetDatabaseNames");
IDB_TRACE("IndexedDBFactoryImpl::GetDatabaseNames");
// TODO(dgrogan): Plumb data_loss back to script eventually?
blink::WebIDBDataLoss data_loss;
std::string data_loss_message;
......@@ -216,13 +218,13 @@ void IndexedDBFactory::GetDatabaseNames(
ReleaseBackingStore(origin_url, false /* immediate */);
}
void IndexedDBFactory::DeleteDatabase(
void IndexedDBFactoryImpl::DeleteDatabase(
const base::string16& name,
net::URLRequestContext* request_context,
scoped_refptr<IndexedDBCallbacks> callbacks,
const GURL& origin_url,
const base::FilePath& data_directory) {
IDB_TRACE("IndexedDBFactory::DeleteDatabase");
IDB_TRACE("IndexedDBFactoryImpl::DeleteDatabase");
IndexedDBDatabase::Identifier unique_identifier(origin_url, name);
IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier);
if (it != database_map_.end()) {
......@@ -282,7 +284,7 @@ void IndexedDBFactory::DeleteDatabase(
ReleaseBackingStore(origin_url, false /* immediate */);
}
void IndexedDBFactory::DatabaseDeleted(
void IndexedDBFactoryImpl::DatabaseDeleted(
const IndexedDBDatabase::Identifier& identifier) {
// NULL after ContextDestroyed() called, and in some unit tests.
if (!context_)
......@@ -290,7 +292,7 @@ void IndexedDBFactory::DatabaseDeleted(
context_->DatabaseDeleted(identifier.first);
}
void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) {
void IndexedDBFactoryImpl::HandleBackingStoreFailure(const GURL& origin_url) {
// NULL after ContextDestroyed() called, and in some unit tests.
if (!context_)
return;
......@@ -298,7 +300,7 @@ void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) {
IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE);
}
void IndexedDBFactory::HandleBackingStoreCorruption(
void IndexedDBFactoryImpl::HandleBackingStoreCorruption(
const GURL& origin_url,
const IndexedDBDatabaseError& error) {
// Make a copy of origin_url as this is likely a reference to a member of a
......@@ -317,17 +319,17 @@ void IndexedDBFactory::HandleBackingStoreCorruption(
DLOG(ERROR) << "Unable to delete backing store: " << s.ToString();
}
bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url,
bool IndexedDBFactoryImpl::IsDatabaseOpen(const GURL& origin_url,
const base::string16& name) const {
return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name));
}
bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const {
bool IndexedDBFactoryImpl::IsBackingStoreOpen(const GURL& origin_url) const {
return backing_store_map_.find(origin_url) != backing_store_map_.end();
}
bool IndexedDBFactory::IsBackingStorePendingClose(const GURL& origin_url)
const {
bool IndexedDBFactoryImpl::IsBackingStorePendingClose(
const GURL& origin_url) const {
IndexedDBBackingStoreMap::const_iterator it =
backing_store_map_.find(origin_url);
if (it == backing_store_map_.end())
......@@ -335,7 +337,8 @@ bool IndexedDBFactory::IsBackingStorePendingClose(const GURL& origin_url)
return it->second->close_timer()->IsRunning();
}
scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStoreHelper(
scoped_refptr<IndexedDBBackingStore>
IndexedDBFactoryImpl::OpenBackingStoreHelper(
const GURL& origin_url,
const base::FilePath& data_directory,
net::URLRequestContext* request_context,
......@@ -356,7 +359,7 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStoreHelper(
status);
}
scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore(
scoped_refptr<IndexedDBBackingStore> IndexedDBFactoryImpl::OpenBackingStore(
const GURL& origin_url,
const base::FilePath& data_directory,
net::URLRequestContext* request_context,
......@@ -408,12 +411,12 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore(
return 0;
}
void IndexedDBFactory::Open(const base::string16& name,
void IndexedDBFactoryImpl::Open(const base::string16& name,
const IndexedDBPendingConnection& connection,
net::URLRequestContext* request_context,
const GURL& origin_url,
const base::FilePath& data_directory) {
IDB_TRACE("IndexedDBFactory::Open");
IDB_TRACE("IndexedDBFactoryImpl::Open");
scoped_refptr<IndexedDBDatabase> database;
IndexedDBDatabase::Identifier unique_identifier(origin_url, name);
IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier);
......@@ -483,13 +486,13 @@ void IndexedDBFactory::Open(const base::string16& name,
}
}
std::pair<IndexedDBFactory::OriginDBMapIterator,
IndexedDBFactory::OriginDBMapIterator>
IndexedDBFactory::GetOpenDatabasesForOrigin(const GURL& origin_url) const {
std::pair<IndexedDBFactoryImpl::OriginDBMapIterator,
IndexedDBFactoryImpl::OriginDBMapIterator>
IndexedDBFactoryImpl::GetOpenDatabasesForOrigin(const GURL& origin_url) const {
return origin_dbs_.equal_range(origin_url);
}
size_t IndexedDBFactory::GetConnectionCount(const GURL& origin_url) const {
size_t IndexedDBFactoryImpl::GetConnectionCount(const GURL& origin_url) const {
size_t count(0);
std::pair<OriginDBMapIterator, OriginDBMapIterator> range =
......
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_
#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_
#include "content/browser/indexed_db/indexed_db_factory.h"
namespace content {
class IndexedDBContextImpl;
class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory {
public:
explicit IndexedDBFactoryImpl(IndexedDBContextImpl* context);
// content::IndexedDBFactory overrides:
virtual void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier,
bool forcedClose) OVERRIDE;
virtual void GetDatabaseNames(
scoped_refptr<IndexedDBCallbacks> callbacks,
const GURL& origin_url,
const base::FilePath& data_directory,
net::URLRequestContext* request_context) OVERRIDE;
virtual void Open(const base::string16& name,
const IndexedDBPendingConnection& connection,
net::URLRequestContext* request_context,
const GURL& origin_url,
const base::FilePath& data_directory) OVERRIDE;
virtual void DeleteDatabase(const base::string16& name,
net::URLRequestContext* request_context,
scoped_refptr<IndexedDBCallbacks> callbacks,
const GURL& origin_url,
const base::FilePath& data_directory) OVERRIDE;
virtual void HandleBackingStoreFailure(const GURL& origin_url) OVERRIDE;
virtual void HandleBackingStoreCorruption(
const GURL& origin_url,
const IndexedDBDatabaseError& error) OVERRIDE;
virtual std::pair<OriginDBMapIterator, OriginDBMapIterator>
GetOpenDatabasesForOrigin(const GURL& origin_url) const OVERRIDE;
virtual void ForceClose(const GURL& origin_url) OVERRIDE;
// Called by the IndexedDBContext destructor so the factory can do cleanup.
virtual void ContextDestroyed() OVERRIDE;
// Called by the IndexedDBActiveBlobRegistry.
virtual void ReportOutstandingBlobs(const GURL& origin_url,
bool blobs_outstanding) OVERRIDE;
// Called by an IndexedDBDatabase when it is actually deleted.
virtual void DatabaseDeleted(
const IndexedDBDatabase::Identifier& identifier) OVERRIDE;
virtual size_t GetConnectionCount(const GURL& origin_url) const OVERRIDE;
protected:
virtual ~IndexedDBFactoryImpl();
virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore(
const GURL& origin_url,
const base::FilePath& data_directory,
net::URLRequestContext* request_context,
blink::WebIDBDataLoss* data_loss,
std::string* data_loss_reason,
bool* disk_full,
leveldb::Status* s) OVERRIDE;
virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper(
const GURL& origin_url,
const base::FilePath& data_directory,
net::URLRequestContext* request_context,
blink::WebIDBDataLoss* data_loss,
std::string* data_loss_message,
bool* disk_full,
bool first_time,
leveldb::Status* s) OVERRIDE;
void ReleaseBackingStore(const GURL& origin_url, bool immediate);
void CloseBackingStore(const GURL& origin_url);
IndexedDBContextImpl* context() const { return context_; }
private:
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
BackingStoreReleasedOnForcedClose);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
BackingStoreReleaseDelayedOnClose);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
DeleteDatabaseClosesBackingStore);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
ForceCloseReleasesBackingStore);
FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
GetDatabaseNamesClosesBackingStore);
FRIEND_TEST_ALL_PREFIXES(IndexedDBTest,
ForceCloseOpenDatabasesOnCommitFailure);
// Called internally after a database is closed, with some delay. If this
// factory has the last reference, it will be released.
void MaybeCloseBackingStore(const GURL& origin_url);
bool HasLastBackingStoreReference(const GURL& origin_url) const;
// Testing helpers, so unit tests don't need to grovel through internal state.
bool IsDatabaseOpen(const GURL& origin_url, const base::string16& name) const;
bool IsBackingStoreOpen(const GURL& origin_url) const;
bool IsBackingStorePendingClose(const GURL& origin_url) const;
void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier);
IndexedDBContextImpl* context_;
typedef std::map<IndexedDBDatabase::Identifier, IndexedDBDatabase*>
IndexedDBDatabaseMap;
IndexedDBDatabaseMap database_map_;
OriginDBMap origin_dbs_;
typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> >
IndexedDBBackingStoreMap;
IndexedDBBackingStoreMap backing_store_map_;
std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_;
IndexedDBBackingStoreMap backing_stores_with_active_blobs_;
std::set<GURL> backends_opened_since_boot_;
DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryImpl);
};
} // namespace content
#endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/indexed_db/indexed_db_factory.h"
#include "content/browser/indexed_db/indexed_db_factory_impl.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
......@@ -26,10 +26,10 @@ namespace content {
namespace {
class MockIDBFactory : public IndexedDBFactory {
class MockIDBFactory : public IndexedDBFactoryImpl {
public:
explicit MockIDBFactory(IndexedDBContextImpl* context)
: IndexedDBFactory(context) {}
: IndexedDBFactoryImpl(context) {}
scoped_refptr<IndexedDBBackingStore> TestOpenBackingStore(
const GURL& origin,
const base::FilePath& data_directory) {
......@@ -199,10 +199,10 @@ TEST_F(IndexedDBFactoryTest, RejectLongOrigins) {
EXPECT_TRUE(diskStore2);
}
class DiskFullFactory : public IndexedDBFactory {
class DiskFullFactory : public IndexedDBFactoryImpl {
public:
explicit DiskFullFactory(IndexedDBContextImpl* context)
: IndexedDBFactory(context) {}
: IndexedDBFactoryImpl(context) {}
private:
virtual ~DiskFullFactory() {}
......
......@@ -9,6 +9,7 @@
#include "content/browser/browser_thread_impl.h"
#include "content/browser/indexed_db/indexed_db_connection.h"
#include "content/browser/indexed_db/indexed_db_context_impl.h"
#include "content/browser/indexed_db/indexed_db_factory_impl.h"
#include "content/browser/indexed_db/mock_indexed_db_callbacks.h"
#include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h"
#include "content/public/browser/storage_partition.h"
......@@ -247,7 +248,8 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnCommitFailure) {
scoped_refptr<IndexedDBContextImpl> context = new IndexedDBContextImpl(
temp_dir.path(), special_storage_policy_, NULL, task_runner_);
scoped_refptr<IndexedDBFactory> factory = context->GetIDBFactory();
scoped_refptr<IndexedDBFactoryImpl> factory =
static_cast<IndexedDBFactoryImpl*>(context->GetIDBFactory());
scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
......
......@@ -725,8 +725,9 @@
'browser/indexed_db/indexed_db_database_error.h',
'browser/indexed_db/indexed_db_dispatcher_host.cc',
'browser/indexed_db/indexed_db_dispatcher_host.h',
'browser/indexed_db/indexed_db_factory.cc',
'browser/indexed_db/indexed_db_factory.h',
'browser/indexed_db/indexed_db_factory_impl.cc',
'browser/indexed_db/indexed_db_factory_impl.h',
'browser/indexed_db/indexed_db_index_writer.cc',
'browser/indexed_db/indexed_db_index_writer.h',
'browser/indexed_db/indexed_db_internals_ui.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment