Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Unified Diff: content/browser/dom_storage/dom_storage_context_wrapper.cc

Issue 2861473002: Clear up session only storage on localstorage shutdown (Closed)
Patch Set: address comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/dom_storage/dom_storage_context_wrapper.cc
diff --git a/content/browser/dom_storage/dom_storage_context_wrapper.cc b/content/browser/dom_storage/dom_storage_context_wrapper.cc
index 64964fe9e4fb6df6712067b3958b6b7836c66992..fbfda0dc61fb5cabb27ace3f32734d458e58f48a 100644
--- a/content/browser/dom_storage/dom_storage_context_wrapper.cc
+++ b/content/browser/dom_storage/dom_storage_context_wrapper.cc
@@ -126,14 +126,15 @@ DOMStorageContextWrapper::DOMStorageContextWrapper(
base::FilePath storage_dir;
if (!profile_path.empty())
storage_dir = local_partition_path.AppendASCII(kLocalStorageDirectory);
- // TODO(michaeln): Enable writing to disk when db is versioned,
- // for now using an empty subdirectory to use an in-memory db.
- // subdirectory_(subdirectory),
- mojo_state_.reset(new LocalStorageContextMojo(
+ // TODO(mek): Use a SequencedTaskRunner once mojo no longer requires a
+ // SingleThreadTaskRunner (http://crbug.com/678155).
+ mojo_task_runner_ =
+ BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
+ mojo_state_ = new LocalStorageContextMojo(
connector, context_->task_runner(),
data_path.empty() ? data_path
: data_path.AppendASCII(kLocalStorageDirectory),
- storage_dir));
+ storage_dir, special_storage_policy);
}
if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) {
@@ -144,14 +145,27 @@ DOMStorageContextWrapper::DOMStorageContextWrapper(
}
}
-DOMStorageContextWrapper::~DOMStorageContextWrapper() {}
+DOMStorageContextWrapper::~DOMStorageContextWrapper() {
+ DCHECK(!mojo_state_) << "Shutdown should be called before destruction";
+}
void DOMStorageContextWrapper::GetLocalStorageUsage(
const GetLocalStorageUsageCallback& callback) {
DCHECK(context_.get());
if (mojo_state_) {
- mojo_state_->GetStorageUsage(base::BindOnce(
- &DOMStorageContextWrapper::GotMojoLocalStorageUsage, this, callback));
+ // base::Unretained is safe here, because the mojo_state_ won't be deleted
+ // until a ShutdownAndDelete task has been ran on the mojo_task_runner_, and
+ // as soon as that task is posted, mojo_state_ is set to null, preventing
+ // further tasks from being queued.
+ mojo_task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(
+ &LocalStorageContextMojo::GetStorageUsage,
+ base::Unretained(mojo_state_),
+ base::BindOnce(
+ &DOMStorageContextWrapper::GotMojoLocalStorageUsage, this,
+ callback,
+ base::RetainedRef(base::ThreadTaskRunnerHandle::Get()))));
return;
}
context_->task_runner()->PostShutdownBlockingTask(
@@ -179,8 +193,16 @@ void DOMStorageContextWrapper::DeleteLocalStorageForPhysicalOrigin(
FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
base::Bind(&DOMStorageContextImpl::DeleteLocalStorageForPhysicalOrigin,
context_, origin));
- if (mojo_state_)
- mojo_state_->DeleteStorageForPhysicalOrigin(url::Origin(origin));
+ if (mojo_state_) {
+ // base::Unretained is safe here, because the mojo_state_ won't be deleted
+ // until a ShutdownAndDelete task has been ran on the mojo_task_runner_, and
+ // as soon as that task is posted, mojo_state_ is set to null, preventing
+ // further tasks from being queued.
+ mojo_task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(&LocalStorageContextMojo::DeleteStorageForPhysicalOrigin,
+ base::Unretained(mojo_state_), url::Origin(origin)));
+ }
}
void DOMStorageContextWrapper::DeleteLocalStorage(const GURL& origin) {
@@ -189,8 +211,16 @@ void DOMStorageContextWrapper::DeleteLocalStorage(const GURL& origin) {
FROM_HERE,
DOMStorageTaskRunner::PRIMARY_SEQUENCE,
base::Bind(&DOMStorageContextImpl::DeleteLocalStorage, context_, origin));
- if (mojo_state_)
- mojo_state_->DeleteStorage(url::Origin(origin));
+ if (mojo_state_) {
+ // base::Unretained is safe here, because the mojo_state_ won't be deleted
+ // until a ShutdownAndDelete task has been ran on the mojo_task_runner_, and
+ // as soon as that task is posted, mojo_state_ is set to null, preventing
+ // further tasks from being queued.
+ mojo_task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(&LocalStorageContextMojo::DeleteStorage,
+ base::Unretained(mojo_state_), url::Origin(origin)));
+ }
}
void DOMStorageContextWrapper::DeleteSessionStorage(
@@ -230,11 +260,26 @@ void DOMStorageContextWrapper::SetForceKeepSessionState() {
FROM_HERE,
DOMStorageTaskRunner::PRIMARY_SEQUENCE,
base::Bind(&DOMStorageContextImpl::SetForceKeepSessionState, context_));
+ if (mojo_state_) {
+ // base::Unretained is safe here, because the mojo_state_ won't be deleted
+ // until a ShutdownAndDelete task has been ran on the mojo_task_runner_, and
+ // as soon as that task is posted, mojo_state_ is set to null, preventing
+ // further tasks from being queued.
+ mojo_task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(&LocalStorageContextMojo::SetForceKeepSessionState,
+ base::Unretained(mojo_state_)));
+ }
}
void DOMStorageContextWrapper::Shutdown() {
DCHECK(context_.get());
- mojo_state_.reset();
+ if (mojo_state_) {
+ mojo_task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(&LocalStorageContextMojo::ShutdownAndDelete,
+ base::Unretained(mojo_state_)));
+ mojo_state_ = nullptr;
+ }
memory_pressure_listener_.reset();
context_->task_runner()->PostShutdownBlockingTask(
FROM_HERE,
@@ -248,11 +293,19 @@ void DOMStorageContextWrapper::Shutdown() {
void DOMStorageContextWrapper::Flush() {
DCHECK(context_.get());
+
context_->task_runner()->PostShutdownBlockingTask(
FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
base::Bind(&DOMStorageContextImpl::Flush, context_));
- if (mojo_state_)
- mojo_state_->Flush();
+ if (mojo_state_) {
+ // base::Unretained is safe here, because the mojo_state_ won't be deleted
+ // until a ShutdownAndDelete task has been ran on the mojo_task_runner_, and
+ // as soon as that task is posted, mojo_state_ is set to null, preventing
+ // further tasks from being queued.
+ mojo_task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(&LocalStorageContextMojo::Flush,
+ base::Unretained(mojo_state_)));
+ }
}
void DOMStorageContextWrapper::OpenLocalStorage(
@@ -260,7 +313,14 @@ void DOMStorageContextWrapper::OpenLocalStorage(
mojom::LevelDBWrapperRequest request) {
if (!mojo_state_)
return;
- mojo_state_->OpenLocalStorage(origin, std::move(request));
+ // base::Unretained is safe here, because the mojo_state_ won't be deleted
+ // until a ShutdownAndDelete task has been ran on the mojo_task_runner_, and
+ // as soon as that task is posted, mojo_state_ is set to null, preventing
+ // further tasks from being queued.
+ mojo_task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(&LocalStorageContextMojo::OpenLocalStorage,
+ base::Unretained(mojo_state_), origin,
+ std::move(request)));
}
void DOMStorageContextWrapper::OnMemoryPressure(
@@ -283,17 +343,25 @@ void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption
context_->task_runner()->PostTask(
FROM_HERE,
base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option));
- if (mojo_state_ && purge_option == DOMStorageContextImpl::PURGE_AGGRESSIVE)
- mojo_state_->PurgeMemory();
+ if (mojo_state_ && purge_option == DOMStorageContextImpl::PURGE_AGGRESSIVE) {
+ // base::Unretained is safe here, because the mojo_state_ won't be deleted
+ // until a ShutdownAndDelete task has been ran on the mojo_task_runner_, and
+ // as soon as that task is posted, mojo_state_ is set to null, preventing
+ // further tasks from being queued.
+ mojo_task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(&LocalStorageContextMojo::PurgeMemory,
+ base::Unretained(mojo_state_)));
+ }
}
void DOMStorageContextWrapper::GotMojoLocalStorageUsage(
GetLocalStorageUsageCallback callback,
+ base::SingleThreadTaskRunner* reply_task_runner,
std::vector<LocalStorageUsageInfo> usage) {
context_->task_runner()->PostShutdownBlockingTask(
FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
base::Bind(&GetLocalStorageUsageHelper, base::Passed(&usage),
- base::RetainedRef(base::ThreadTaskRunnerHandle::Get()),
+ base::RetainedRef(reply_task_runner),
base::RetainedRef(context_), callback));
}
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_wrapper.h ('k') | content/browser/dom_storage/local_storage_context_mojo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698