Make the content::DOMStorageContext methods callable on the main thread and hide the threading details from the embedder.
Review URL: https://chromiumcodereview.appspot.com/9704048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126835 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/browsing_data_local_storage_helper.cc b/chrome/browser/browsing_data_local_storage_helper.cc
index ff66398..05b31c1 100644
--- a/chrome/browser/browsing_data_local_storage_helper.cc
+++ b/chrome/browser/browsing_data_local_storage_helper.cc
@@ -52,7 +52,7 @@
Profile* profile)
: dom_storage_context_(BrowserContext::GetDOMStorageContext(profile)),
is_fetching_(false) {
- DCHECK(dom_storage_context_.get());
+ DCHECK(dom_storage_context_);
}
BrowsingDataLocalStorageHelper::~BrowsingDataLocalStorageHelper() {
@@ -66,11 +66,9 @@
is_fetching_ = true;
completion_callback_ = callback;
- dom_storage_context_->task_runner()->PostTask(
- FROM_HERE,
+ dom_storage_context_->GetAllStorageFiles(
base::Bind(
- &BrowsingDataLocalStorageHelper::FetchLocalStorageInfoHelper,
- this));
+ &BrowsingDataLocalStorageHelper::GetAllStorageFilesCallback, this));
}
void BrowsingDataLocalStorageHelper::CancelNotification() {
@@ -81,16 +79,23 @@
void BrowsingDataLocalStorageHelper::DeleteLocalStorageFile(
const FilePath& file_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- dom_storage_context_->task_runner()->PostTask(
- FROM_HERE,
- base::Bind(
- &BrowsingDataLocalStorageHelper::DeleteLocalStorageFileHelper,
- this, file_path));
+ dom_storage_context_->DeleteLocalStorageFile(file_path);
}
-void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoHelper() {
- DCHECK(dom_storage_context_->task_runner()->RunsTasksOnCurrentThread());
- std::vector<FilePath> files = dom_storage_context_->GetAllStorageFiles();
+void BrowsingDataLocalStorageHelper::GetAllStorageFilesCallback(
+ const std::vector<FilePath>& files) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ BrowserThread::PostTask(
+ BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(
+ &BrowsingDataLocalStorageHelper::FetchLocalStorageInfo,
+ this, files));
+}
+
+void BrowsingDataLocalStorageHelper::FetchLocalStorageInfo(
+ const std::vector<FilePath>& files) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
for (size_t i = 0; i < files.size(); ++i) {
FilePath file_path = files[i];
WebSecurityOrigin web_security_origin =
@@ -132,12 +137,6 @@
is_fetching_ = false;
}
-void BrowsingDataLocalStorageHelper::DeleteLocalStorageFileHelper(
- const FilePath& file_path) {
- DCHECK(dom_storage_context_->task_runner()->RunsTasksOnCurrentThread());
- dom_storage_context_->DeleteLocalStorageFile(file_path);
-}
-
//---------------------------------------------------------
CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper(
diff --git a/chrome/browser/browsing_data_local_storage_helper.h b/chrome/browser/browsing_data_local_storage_helper.h
index a2c79fe..7f889858 100644
--- a/chrome/browser/browsing_data_local_storage_helper.h
+++ b/chrome/browser/browsing_data_local_storage_helper.h
@@ -84,7 +84,8 @@
// Notifies the completion callback in the UI thread.
void NotifyInUIThread();
- scoped_refptr<content::DOMStorageContext> dom_storage_context_;
+ // Owned by the profile
+ content::DOMStorageContext* dom_storage_context_;
// This only mutates on the UI thread.
base::Callback<void(const std::list<LocalStorageInfo>&)> completion_callback_;
@@ -99,10 +100,10 @@
std::list<LocalStorageInfo> local_storage_info_;
private:
- // Enumerates all local storage files in a sequenced task.
- void FetchLocalStorageInfoHelper();
- // Delete a single local storage file in a sequenced task.
- void DeleteLocalStorageFileHelper(const FilePath& file_path);
+ // Called back with the all the local storage files.
+ void GetAllStorageFilesCallback(const std::vector<FilePath>& files);
+ // Get the file info on the file thread.
+ void FetchLocalStorageInfo(const std::vector<FilePath>& files);
DISALLOW_COPY_AND_ASSIGN(BrowsingDataLocalStorageHelper);
};
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc
index 0612dde..446dd1832 100644
--- a/chrome/browser/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data_remover.cc
@@ -303,11 +303,8 @@
}
if (remove_mask & REMOVE_LOCAL_STORAGE) {
- DOMStorageContext* context = BrowserContext::GetDOMStorageContext(profile_);
- context->task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&BrowsingDataRemover::ClearDOMStorageInSequencedTask,
- base::Unretained(this), make_scoped_refptr(context)));
+ BrowserContext::GetDOMStorageContext(profile_)->DeleteDataModifiedSince(
+ delete_begin_);
}
if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL ||
@@ -436,13 +433,6 @@
return delete_begin_time - diff;
}
-void BrowsingDataRemover::ClearDOMStorageInSequencedTask(
- DOMStorageContext* dom_storage_context) {
- // We assume the end time is now.
- DCHECK(dom_storage_context->task_runner()->RunsTasksOnCurrentThread());
- dom_storage_context->DeleteDataModifiedSince(delete_begin_);
-}
-
void BrowsingDataRemover::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
diff --git a/chrome/browser/browsing_data_remover.h b/chrome/browser/browsing_data_remover.h
index a2459d1c..d474624 100644
--- a/chrome/browser/browsing_data_remover.h
+++ b/chrome/browser/browsing_data_remover.h
@@ -246,10 +246,6 @@
// Calculate the begin time for the deletion range specified by |time_period|.
base::Time CalculateBeginDeleteTime(TimePeriod time_period);
- // Invoked in a background task to clear local storage.
- void ClearDOMStorageInSequencedTask(
- content::DOMStorageContext* dom_storage_context);
-
// Returns true if we're all done.
bool all_done() {
return registrar_.IsEmpty() && !waiting_for_clear_cache_ &&
diff --git a/chrome/browser/extensions/extension_data_deleter.cc b/chrome/browser/extensions/extension_data_deleter.cc
index ab92bae..7ab0f59 100644
--- a/chrome/browser/extensions/extension_data_deleter.cc
+++ b/chrome/browser/extensions/extension_data_deleter.cc
@@ -48,13 +48,8 @@
base::Bind(
&ExtensionDataDeleter::DeleteCookiesOnIOThread, deleter));
- scoped_refptr<DOMStorageContext> dom_storage_context =
- BrowserContext::GetDOMStorageContext(profile);
- dom_storage_context->task_runner()->PostTask(
- FROM_HERE,
- base::Bind(
- &ExtensionDataDeleter::DeleteLocalStorageInSequencedTask, deleter,
- dom_storage_context));
+ BrowserContext::GetDOMStorageContext(profile)->DeleteForOrigin(
+ deleter->origin_id_);
BrowserThread::PostTask(
BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
@@ -127,12 +122,6 @@
DCHECK(rv == net::OK || rv == net::ERR_IO_PENDING);
}
-void ExtensionDataDeleter::DeleteLocalStorageInSequencedTask(
- DOMStorageContext* dom_storage_context) {
- DCHECK(dom_storage_context->task_runner()->RunsTasksOnCurrentThread());
- dom_storage_context->DeleteForOrigin(origin_id_);
-}
-
void ExtensionDataDeleter::DeleteIndexedDBOnWebkitThread(
scoped_refptr<IndexedDBContext> indexed_db_context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
diff --git a/chrome/browser/extensions/extension_data_deleter.h b/chrome/browser/extensions/extension_data_deleter.h
index c3ab6ce..41c781b 100644
--- a/chrome/browser/extensions/extension_data_deleter.h
+++ b/chrome/browser/extensions/extension_data_deleter.h
@@ -70,11 +70,6 @@
// thread.
void DeleteDatabaseOnFileThread();
- // Deletes local storage for the extension. May only be called in a
- // DOMStorageContext sequenced task.
- void DeleteLocalStorageInSequencedTask(
- content::DOMStorageContext* dom_storage_context);
-
// Deletes indexed db files for the extension. May only be called on the
// webkit thread.
void DeleteIndexedDBOnWebkitThread(