summaryrefslogtreecommitdiffstats
path: root/content/browser/indexed_db/indexed_db_context_impl.cc
diff options
context:
space:
mode:
authorjsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-28 18:22:58 +0000
committerjsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-28 18:22:58 +0000
commit4d9d3bc75c7e6598f8c3b3341f8b9d05afcb821d (patch)
treed1cfc4b93f7716d60db658369a0c6a0309f26c96 /content/browser/indexed_db/indexed_db_context_impl.cc
parent5772630103e70aba61dbb547cc23d2c8ad0aa793 (diff)
downloadchromium_src-4d9d3bc75c7e6598f8c3b3341f8b9d05afcb821d.zip
chromium_src-4d9d3bc75c7e6598f8c3b3341f8b9d05afcb821d.tar.gz
chromium_src-4d9d3bc75c7e6598f8c3b3341f8b9d05afcb821d.tar.bz2
Migrate the IndexedDB backend from Blink to Chromium
To get the IDB backend off the (deprecated) WebKit thread, remove intermediate proxying, and let us take advantage of base utilities, we're moving the code from Blink to Chromium. This patch is basically a glorified copy/paste of the Blink IDB backend code, with Chromium coding style applied, WTF dependencies replaced with STL and base/, redundant classes removed, etc. It introduces some new temporary proxy classes (content/browser/webidb*_impl.*) to allow us build both the old and new backends. The new backend is currently disabled by default. It can be enabled using a new (and temporary) command line switch: --new-indexeddb Once we've done some further cleanup and are confident that the new backend is stable, and the bots have moved from DumpRenderTree to content_shell, we'll switch to the new backend by default. Once that has survived through a dev channel release, we'll delete the Blink code and eliminate unnecessary proxy classes. BUG=234278 R=alecflett@chromium.org, dgrogan@chromium.org, piman@chromium.org Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=202215 Review URL: https://codereview.chromium.org/15564008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/indexed_db/indexed_db_context_impl.cc')
-rw-r--r--content/browser/indexed_db/indexed_db_context_impl.cc84
1 files changed, 50 insertions, 34 deletions
diff --git a/content/browser/indexed_db/indexed_db_context_impl.cc b/content/browser/indexed_db/indexed_db_context_impl.cc
index 2a958b4..e478883 100644
--- a/content/browser/indexed_db/indexed_db_context_impl.cc
+++ b/content/browser/indexed_db/indexed_db_context_impl.cc
@@ -14,6 +14,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "content/browser/indexed_db/indexed_db_quota_client.h"
+#include "content/browser/indexed_db/webidbfactory_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/indexed_db_info.h"
#include "content/public/common/content_switches.h"
@@ -40,15 +41,14 @@ const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] =
namespace {
-void GetAllOriginsAndPaths(
- const base::FilePath& indexeddb_path,
- std::vector<GURL>* origins,
- std::vector<base::FilePath>* file_paths) {
+void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path,
+ std::vector<GURL>* origins,
+ std::vector<base::FilePath>* file_paths) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
if (indexeddb_path.empty())
return;
- file_util::FileEnumerator file_enumerator(indexeddb_path,
- false, file_util::FileEnumerator::DIRECTORIES);
+ file_util::FileEnumerator file_enumerator(
+ indexeddb_path, false, file_util::FileEnumerator::DIRECTORIES);
for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty();
file_path = file_enumerator.Next()) {
if (file_path.Extension() == IndexedDBContextImpl::kIndexedDBExtension) {
@@ -74,7 +74,8 @@ void ClearSessionOnlyOrigins(
std::vector<base::FilePath>::const_iterator file_path_iter =
file_paths.begin();
for (std::vector<GURL>::const_iterator iter = origins.begin();
- iter != origins.end(); ++iter, ++file_path_iter) {
+ iter != origins.end();
+ ++iter, ++file_path_iter) {
if (!special_storage_policy->IsStorageSessionOnly(*iter))
continue;
if (special_storage_policy->IsStorageProtected(*iter))
@@ -108,7 +109,10 @@ WebIDBFactory* IndexedDBContextImpl::GetIDBFactory() {
// Prime our cache of origins with existing databases so we can
// detect when dbs are newly created.
GetOriginSet();
- idb_factory_.reset(WebIDBFactory::create());
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewIndexedDB))
+ idb_factory_.reset(new content::WebIDBFactoryImpl());
+ else
+ idb_factory_.reset(WebIDBFactory::create());
}
return idb_factory_.get();
}
@@ -118,7 +122,8 @@ std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() {
std::vector<GURL> origins;
std::set<GURL>* origins_set = GetOriginSet();
for (std::set<GURL>::const_iterator iter = origins_set->begin();
- iter != origins_set->end(); ++iter) {
+ iter != origins_set->end();
+ ++iter) {
origins.push_back(*iter);
}
return origins;
@@ -128,7 +133,8 @@ std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() {
std::vector<GURL> origins = GetAllOrigins();
std::vector<IndexedDBInfo> result;
for (std::vector<GURL>::const_iterator iter = origins.begin();
- iter != origins.end(); ++iter) {
+ iter != origins.end();
+ ++iter) {
const GURL& origin_url = *iter;
base::FilePath idb_directory = GetFilePath(origin_url);
@@ -202,7 +208,7 @@ base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) {
}
base::FilePath IndexedDBContextImpl::GetFilePathForTesting(
- const string16& origin_id) const {
+ const string16& origin_id) const {
return GetIndexedDBFilePath(origin_id);
}
@@ -211,7 +217,8 @@ void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url,
DCHECK_EQ(connections_[origin_url].count(connection), 0UL);
if (quota_manager_proxy()) {
quota_manager_proxy()->NotifyStorageAccessed(
- quota::QuotaClient::kIndexedDatabase, origin_url,
+ quota::QuotaClient::kIndexedDatabase,
+ origin_url,
quota::kStorageTypeTemporary);
}
connections_[origin_url].insert(connection);
@@ -232,7 +239,8 @@ void IndexedDBContextImpl::ConnectionClosed(const GURL& origin_url,
return;
if (quota_manager_proxy()) {
quota_manager_proxy()->NotifyStorageAccessed(
- quota::QuotaClient::kIndexedDatabase, origin_url,
+ quota::QuotaClient::kIndexedDatabase,
+ origin_url,
quota::kStorageTypeTemporary);
}
connections_[origin_url].erase(connection);
@@ -271,8 +279,8 @@ quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() {
IndexedDBContextImpl::~IndexedDBContextImpl() {
WebKit::WebIDBFactory* factory = idb_factory_.release();
if (factory) {
- if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT_DEPRECATED,
- FROM_HERE, factory))
+ if (!BrowserThread::DeleteSoon(
+ BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, factory))
delete factory;
}
@@ -293,18 +301,17 @@ IndexedDBContextImpl::~IndexedDBContextImpl() {
// No WEBKIT thread here means we are running in a unit test where no clean
// up is needed.
BrowserThread::PostTask(
- BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
- base::Bind(&ClearSessionOnlyOrigins,
- data_path_,
- special_storage_policy_));
+ BrowserThread::WEBKIT_DEPRECATED,
+ FROM_HERE,
+ base::Bind(
+ &ClearSessionOnlyOrigins, data_path_, special_storage_policy_));
}
base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath(
const string16& origin_id) const {
DCHECK(!data_path_.empty());
- base::FilePath::StringType id =
- webkit_base::WebStringToFilePathString(origin_id).append(
- FILE_PATH_LITERAL(".indexeddb"));
+ base::FilePath::StringType id = webkit_base::WebStringToFilePathString(
+ origin_id).append(FILE_PATH_LITERAL(".indexeddb"));
return data_path_.Append(id.append(kIndexedDBExtension));
}
@@ -331,18 +338,20 @@ void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage(
if (difference) {
origin_size_map_[origin_url] = current_disk_usage;
// quota_manager_proxy() is NULL in unit tests.
- if (quota_manager_proxy())
+ if (quota_manager_proxy()) {
quota_manager_proxy()->NotifyStorageModified(
quota::QuotaClient::kIndexedDatabase,
origin_url,
quota::kStorageTypeTemporary,
difference);
+ }
}
}
void IndexedDBContextImpl::GotUsageAndQuota(const GURL& origin_url,
quota::QuotaStatusCode status,
- int64 usage, int64 quota) {
+ int64 usage,
+ int64 quota) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort)
<< "status was " << status;
@@ -350,13 +359,17 @@ void IndexedDBContextImpl::GotUsageAndQuota(const GURL& origin_url,
// We seem to no longer care to wait around for the answer.
return;
}
- BrowserThread::PostTask(
- BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
- base::Bind(&IndexedDBContextImpl::GotUpdatedQuota, this, origin_url,
- usage, quota));
+ BrowserThread::PostTask(BrowserThread::WEBKIT_DEPRECATED,
+ FROM_HERE,
+ base::Bind(&IndexedDBContextImpl::GotUpdatedQuota,
+ this,
+ origin_url,
+ usage,
+ quota));
}
-void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, int64 usage,
+void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url,
+ int64 usage,
int64 quota) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
space_available_map_[origin_url] = quota - usage;
@@ -365,11 +378,13 @@ void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, int64 usage,
void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) {
if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- if (quota_manager_proxy())
+ if (quota_manager_proxy()) {
BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&IndexedDBContextImpl::QueryAvailableQuota, this,
- origin_url));
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(
+ &IndexedDBContextImpl::QueryAvailableQuota, this, origin_url));
+ }
return;
}
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
@@ -387,7 +402,8 @@ std::set<GURL>* IndexedDBContextImpl::GetOriginSet() {
std::vector<GURL> origins;
GetAllOriginsAndPaths(data_path_, &origins, NULL);
for (std::vector<GURL>::const_iterator iter = origins.begin();
- iter != origins.end(); ++iter) {
+ iter != origins.end();
+ ++iter) {
origin_set_->insert(*iter);
}
}