summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 04:08:51 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 04:08:51 +0000
commit5a9e4767704cdfea576cb6b934c3d0400beb738f (patch)
tree812bdc1723c784edb4807d53d04c4127da8fc104
parentd061e9bd1a883172db01c644d83c1a1ae45efc90 (diff)
downloadchromium_src-5a9e4767704cdfea576cb6b934c3d0400beb738f.zip
chromium_src-5a9e4767704cdfea576cb6b934c3d0400beb738f.tar.gz
chromium_src-5a9e4767704cdfea576cb6b934c3d0400beb738f.tar.bz2
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
-rw-r--r--chrome/browser/browsing_data_local_storage_helper.cc33
-rw-r--r--chrome/browser/browsing_data_local_storage_helper.h11
-rw-r--r--chrome/browser/browsing_data_remover.cc14
-rw-r--r--chrome/browser/browsing_data_remover.h4
-rw-r--r--chrome/browser/extensions/extension_data_deleter.cc15
-rw-r--r--chrome/browser/extensions/extension_data_deleter.h5
-rw-r--r--content/browser/browser_context.cc10
-rw-r--r--content/browser/in_process_webkit/dom_storage_context_impl.cc42
-rw-r--r--content/browser/in_process_webkit/dom_storage_context_impl.h11
-rw-r--r--content/public/browser/dom_storage_context.h21
10 files changed, 84 insertions, 82 deletions
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 @@ BrowsingDataLocalStorageHelper::BrowsingDataLocalStorageHelper(
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 @@ void BrowsingDataLocalStorageHelper::StartFetching(
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::CancelNotification() {
void BrowsingDataLocalStorageHelper::DeleteLocalStorageFile(
const FilePath& file_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- dom_storage_context_->task_runner()->PostTask(
+ dom_storage_context_->DeleteLocalStorageFile(file_path);
+}
+
+void BrowsingDataLocalStorageHelper::GetAllStorageFilesCallback(
+ const std::vector<FilePath>& files) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ BrowserThread::PostTask(
+ BrowserThread::FILE,
FROM_HERE,
base::Bind(
- &BrowsingDataLocalStorageHelper::DeleteLocalStorageFileHelper,
- this, file_path));
+ &BrowsingDataLocalStorageHelper::FetchLocalStorageInfo,
+ this, files));
}
-void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoHelper() {
- DCHECK(dom_storage_context_->task_runner()->RunsTasksOnCurrentThread());
- std::vector<FilePath> files = dom_storage_context_->GetAllStorageFiles();
+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 @@ void BrowsingDataLocalStorageHelper::NotifyInUIThread() {
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..7f88985 100644
--- a/chrome/browser/browsing_data_local_storage_helper.h
+++ b/chrome/browser/browsing_data_local_storage_helper.h
@@ -84,7 +84,8 @@ class BrowsingDataLocalStorageHelper
// 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 @@ class BrowsingDataLocalStorageHelper
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..446dd18 100644
--- a/chrome/browser/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data_remover.cc
@@ -303,11 +303,8 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask,
}
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 @@ base::Time BrowsingDataRemover::CalculateBeginDeleteTime(
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 @@ class BrowsingDataRemover : public content::NotificationObserver,
// 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 @@ void ExtensionDataDeleter::StartDeleting(
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 @@ void ExtensionDataDeleter::DeleteDatabaseOnFileThread() {
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 @@ class ExtensionDataDeleter
// 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(
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index 94d0661..da137f4 100644
--- a/content/browser/browser_context.cc
+++ b/content/browser/browser_context.cc
@@ -72,11 +72,11 @@ void CreateQuotaManagerAndClients(BrowserContext* context) {
new UserDataAdapter<DatabaseTracker>(db_tracker));
FilePath path = context->IsOffTheRecord() ? FilePath() : context->GetPath();
- scoped_refptr<DOMStorageContext> dom_storage_context =
+ scoped_refptr<DOMStorageContextImpl> dom_storage_context =
new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy());
context->SetUserData(
kDOMStorageContextKeyName,
- new UserDataAdapter<DOMStorageContext>(dom_storage_context));
+ new UserDataAdapter<DOMStorageContextImpl>(dom_storage_context));
scoped_refptr<IndexedDBContext> indexed_db_context = new IndexedDBContextImpl(
path, context->GetSpecialStoragePolicy(), quota_manager->proxy(),
@@ -138,7 +138,7 @@ QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) {
DOMStorageContext* BrowserContext::GetDOMStorageContext(
BrowserContext* context) {
CreateQuotaManagerAndClients(context);
- return UserDataAdapter<DOMStorageContext>::Get(
+ return UserDataAdapter<DOMStorageContextImpl>::Get(
context, kDOMStorageContextKeyName);
}
@@ -250,8 +250,8 @@ BrowserContext::~BrowserContext() {
if (GetUserData(kDOMStorageContextKeyName) &&
BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) {
- DOMStorageContext* dom_storage_context =
- (static_cast<UserDataAdapter<DOMStorageContext>*>(
+ DOMStorageContextImpl* dom_storage_context =
+ (static_cast<UserDataAdapter<DOMStorageContextImpl>*>(
GetUserData(kDOMStorageContextKeyName)))->release();
BrowserThread::ReleaseSoon(
BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, dom_storage_context);
diff --git a/content/browser/in_process_webkit/dom_storage_context_impl.cc b/content/browser/in_process_webkit/dom_storage_context_impl.cc
index 1be7c3f..8120fb5 100644
--- a/content/browser/in_process_webkit/dom_storage_context_impl.cc
+++ b/content/browser/in_process_webkit/dom_storage_context_impl.cc
@@ -204,6 +204,14 @@ void DOMStorageContextImpl::PurgeMemory() {
}
void DOMStorageContextImpl::DeleteDataModifiedSince(const base::Time& cutoff) {
+ if (!webkit_message_loop_->RunsTasksOnCurrentThread()) {
+ webkit_message_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &DOMStorageContextImpl::DeleteDataModifiedSince, this, cutoff));
+ return;
+ }
+
// Make sure that we don't delete a database that's currently being accessed
// by unloading all of the databases temporarily.
PurgeMemory();
@@ -226,7 +234,13 @@ void DOMStorageContextImpl::DeleteDataModifiedSince(const base::Time& cutoff) {
}
void DOMStorageContextImpl::DeleteLocalStorageFile(const FilePath& file_path) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
+ if (!webkit_message_loop_->RunsTasksOnCurrentThread()) {
+ webkit_message_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &DOMStorageContextImpl::DeleteLocalStorageFile, this, file_path));
+ return;
+ }
// Make sure that we don't delete a database that's currently being accessed
// by unloading all of the databases temporarily.
@@ -238,7 +252,6 @@ void DOMStorageContextImpl::DeleteLocalStorageFile(const FilePath& file_path) {
}
void DOMStorageContextImpl::DeleteForOrigin(const string16& origin_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
DeleteLocalStorageFile(GetFilePath(origin_id));
}
@@ -295,11 +308,16 @@ void DOMStorageContextImpl::CompleteCloningSessionStorage(
RegisterStorageNamespace(existing_namespace->Copy(clone_id));
}
-base::SequencedTaskRunner* DOMStorageContextImpl::task_runner() const {
- return webkit_message_loop_;
-}
+void DOMStorageContextImpl::GetAllStorageFiles(
+ const GetAllStorageFilesCallback& callback) {
+ if (!webkit_message_loop_->RunsTasksOnCurrentThread()) {
+ webkit_message_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &DOMStorageContextImpl::GetAllStorageFiles, this, callback));
+ return;
+ }
-std::vector<FilePath> DOMStorageContextImpl::GetAllStorageFiles() {
std::vector<FilePath> files;
file_util::FileEnumerator file_enumerator(
data_path_.Append(kLocalStorageDirectory), false,
@@ -309,7 +327,17 @@ std::vector<FilePath> DOMStorageContextImpl::GetAllStorageFiles() {
if (file_path.Extension() == kLocalStorageExtension)
files.push_back(file_path);
}
- return files;
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&DOMStorageContextImpl::RunAllStorageFilesCallback,
+ this, files, callback));
+}
+
+void DOMStorageContextImpl::RunAllStorageFilesCallback(
+ const std::vector<FilePath>& files,
+ const GetAllStorageFilesCallback& callback) {
+ callback.Run(files);
}
FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const {
diff --git a/content/browser/in_process_webkit/dom_storage_context_impl.h b/content/browser/in_process_webkit/dom_storage_context_impl.h
index 2cd84f5..44120d6 100644
--- a/content/browser/in_process_webkit/dom_storage_context_impl.h
+++ b/content/browser/in_process_webkit/dom_storage_context_impl.h
@@ -12,6 +12,7 @@
#include "base/compiler_specific.h"
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
+#include "base/memory/ref_counted.h"
#include "base/time.h"
#include "content/public/browser/dom_storage_context.h"
@@ -34,7 +35,8 @@ class SpecialStoragePolicy;
// and in StorageNamespace and StorageArea. Everything is only to be accessed
// on the WebKit thread unless noted otherwise.
class CONTENT_EXPORT DOMStorageContextImpl :
- NON_EXPORTED_BASE(public content::DOMStorageContext) {
+ NON_EXPORTED_BASE(public content::DOMStorageContext),
+ public base::RefCountedThreadSafe<DOMStorageContextImpl> {
public:
// If |data_path| is empty, nothing will be saved to disk.
DOMStorageContextImpl(const FilePath& data_path,
@@ -42,8 +44,8 @@ class CONTENT_EXPORT DOMStorageContextImpl :
virtual ~DOMStorageContextImpl();
// DOMStorageContext implementation:
- virtual base::SequencedTaskRunner* task_runner() const OVERRIDE;
- virtual std::vector<FilePath> GetAllStorageFiles() OVERRIDE;
+ virtual void GetAllStorageFiles(
+ const GetAllStorageFilesCallback& callback) OVERRIDE;
virtual FilePath GetFilePath(const string16& origin_id) const OVERRIDE;
virtual void DeleteForOrigin(const string16& origin_id) OVERRIDE;
virtual void DeleteLocalStorageFile(const FilePath& file_path) OVERRIDE;
@@ -126,6 +128,9 @@ class CONTENT_EXPORT DOMStorageContextImpl :
// The WebKit thread half of CloneSessionStorage above.
void CompleteCloningSessionStorage(int64 existing_id, int64 clone_id);
+ void RunAllStorageFilesCallback(const std::vector<FilePath>& files,
+ const GetAllStorageFilesCallback& callback);
+
// The last used storage_area_id and storage_namespace_id's. For the storage
// namespaces, IDs allocated on the UI thread are positive and count up while
// IDs allocated on the IO thread are negative and count down. This allows us
diff --git a/content/public/browser/dom_storage_context.h b/content/public/browser/dom_storage_context.h
index 9d21ebb..06c36e3 100644
--- a/content/public/browser/dom_storage_context.h
+++ b/content/public/browser/dom_storage_context.h
@@ -8,14 +8,13 @@
#include <vector>
+#include "base/callback.h"
#include "base/string16.h"
-#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
class FilePath;
namespace base {
-class SequencedTaskRunner;
class Time;
}
@@ -24,17 +23,14 @@ namespace content {
class BrowserContext;
// Represents the per-BrowserContext Local Storage data.
-// Call these methods only on tasks scheduled via it's task_runner().
-class DOMStorageContext : public base::RefCountedThreadSafe<DOMStorageContext> {
+class DOMStorageContext {
public:
- virtual ~DOMStorageContext() {}
-
- // Returns a task runner which should be used to schedule tasks
- // which can invoke the other methods of this interface.
- virtual base::SequencedTaskRunner* task_runner() const = 0;
+ typedef base::Callback<void(const std::vector<FilePath>&)>
+ GetAllStorageFilesCallback;
- // Returns all the file paths of local storage files.
- virtual std::vector<FilePath> GetAllStorageFiles() = 0;
+ // Returns all the file paths of local storage files to the given callback.
+ virtual void GetAllStorageFiles(
+ const GetAllStorageFilesCallback& callback) = 0;
// Get the file name of the local storage file for the given origin.
virtual FilePath GetFilePath(const string16& origin_id) const = 0;
@@ -49,6 +45,9 @@ class DOMStorageContext : public base::RefCountedThreadSafe<DOMStorageContext> {
// date that's supplied. Protected origins, per the SpecialStoragePolicy,
// are not deleted by this method.
virtual void DeleteDataModifiedSince(const base::Time& cutoff) = 0;
+
+ protected:
+ virtual ~DOMStorageContext() {}
};
} // namespace content