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

Unified Diff: chrome/browser/browsing_data_remover.cc

Issue 7129018: Time-based removal of temporary file systems via BrowsingDataRemover (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: QuotaManager. Created 9 years, 5 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: chrome/browser/browsing_data_remover.cc
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc
index 70083fec65abd80c63ab05dcb2768e0dac006baf..21656b62754b6e06b3b336e12c0742039a62b535 100644
--- a/chrome/browser/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data_remover.cc
@@ -7,6 +7,8 @@
#include <map>
#include <set>
+#include "base/logging.h"
+
#include "base/callback.h"
#include "base/file_util.h"
#include "base/platform_file.h"
@@ -49,6 +51,8 @@
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
+#include "webkit/quota/quota_types.h"
+#include "webkit/quota/quota_manager.h"
// Done so that we can use PostTask on BrowsingDataRemovers and not have
// BrowsingDataRemover implement RefCounted.
@@ -82,7 +86,8 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
waiting_for_clear_cache_(false),
waiting_for_clear_appcache_(false),
waiting_for_clear_gears_data_(false),
- waiting_for_clear_file_systems_(false) {
+ waiting_for_clear_file_systems_(false),
+ temporary_quota_origins_to_delete_count_(0) {
DCHECK(profile);
}
@@ -570,28 +575,35 @@ void BrowsingDataRemover::ClearFileSystemsOnFILEThread() {
DCHECK(waiting_for_clear_file_systems_);
scoped_refptr<fileapi::FileSystemContext>
fs_context(profile_->GetFileSystemContext());
+
+ // We own the reference to the OriginEnumerator, so we wrap it in a scoped_ptr
+ // to ensure that it's destroyed when we leave the FILE thread.
scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator>
- origin_enumerator(fs_context->path_manager()->sandbox_provider()->
+ origins(fs_context->path_manager()->sandbox_provider()->
CreateOriginEnumerator());
- GURL origin;
- while (!(origin = origin_enumerator->Next()).is_empty()) {
- if (special_storage_policy_->IsStorageProtected(origin))
- continue;
- if (delete_begin_ == base::Time()) {
- // If the user chooses to delete browsing data "since the beginning of
- // time" remove both temporary and persistent file systems entirely.
- fs_context->DeleteDataForOriginAndTypeOnFileThread(origin,
- fileapi::kFileSystemTypeTemporary);
- fs_context->DeleteDataForOriginAndTypeOnFileThread(origin,
- fileapi::kFileSystemTypePersistent);
+ if (delete_begin_ == base::Time()) {
+ // If the user chooses to delete browsing data "since the beginning of
+ // time" remove both temporary and persistent file systems entirely by
+ // walking through all origins and deleting them if they're unprotected.
+ GURL origin;
+ while (!(origin = origins->Next()).is_empty()) {
+ if (special_storage_policy_->IsStorageProtected(origin))
+ continue;
+ fs_context->DeleteDataForOriginOnFileThread(origin);
}
- // TODO(mkwst): Else? Decide what to do for time-based deletion: crbug/63700
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems));
+ } else {
+ // Otherwise, ask the QuotaManager for all origins with temporary quota
+ // modified within the user-specified timeframe, and deal with the resulting
+ // set in ProcessTemporaryQuotaModifiedInTimeframe().
+ temporary_quota_origins_to_delete_count_ = 0;
+ profile_->GetQuotaManager()->GetOriginsModifiedSince(
+ quota::kStorageTypeTemporary, delete_begin_, NewCallback(this,
+ &BrowsingDataRemover::ProcessTemporaryQuotaModifiedInTimeframe));
}
-
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems));
}
void BrowsingDataRemover::OnClearedFileSystems() {
@@ -600,6 +612,44 @@ void BrowsingDataRemover::OnClearedFileSystems() {
NotifyAndDeleteIfDone();
}
+void BrowsingDataRemover::ProcessTemporaryQuotaModifiedInTimeframe(
+ const std::set<GURL>& origins) {
+ // The QuotaManager is owned by the profile; we can use a raw pointer here,
+ // and rely on the profile to destroy the object whenever it's reasonable.
+ quota::QuotaManager* quota_manager = profile_->GetQuotaManager();
+
+ // Walk through the origins passed in, delete temporary quota from each that
+ // isn't protected.
+ std::set<GURL>::iterator origin;
+ for (origin = origins.begin(); origin != origins.end(); ++origin) {
+ if (special_storage_policy_->IsStorageProtected(*origin))
+ continue;
+ ++temporary_quota_origins_to_delete_count_;
+ quota_manager->DeleteOriginData(*origin, quota::kStorageTypeTemporary,
+ NewCallback(this, &BrowsingDataRemover::DeleteOriginDataCallback));
+ }
+ if (temporary_quota_origins_to_delete_count_ == 0) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems));
+ }
+}
+
+void BrowsingDataRemover::DeleteOriginDataCallback(
+ quota::QuotaStatusCode status) {
+ if (status != quota::kQuotaStatusOk) {
+ // TODO(mkwst): Not really anything pretty I can think of to do here.
+ }
+
+ --temporary_quota_origins_to_delete_count_;
+
+ if (temporary_quota_origins_to_delete_count_ == 0) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems));
+ }
+}
+
// static
void BrowsingDataRemover::ClearGearsData(const FilePath& profile_dir) {
FilePath plugin_data = profile_dir.AppendASCII("Plugin Data");

Powered by Google App Engine
This is Rietveld 408576698