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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data_remover.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/logging.h"
11
10 #include "base/callback.h" 12 #include "base/callback.h"
11 #include "base/file_util.h" 13 #include "base/file_util.h"
12 #include "base/platform_file.h" 14 #include "base/platform_file.h"
13 #include "chrome/browser/autofill/personal_data_manager.h" 15 #include "chrome/browser/autofill/personal_data_manager.h"
14 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/download/download_manager.h" 17 #include "chrome/browser/download/download_manager.h"
16 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_special_storage_policy.h" 19 #include "chrome/browser/extensions/extension_special_storage_policy.h"
18 #include "chrome/browser/history/history.h" 20 #include "chrome/browser/history/history.h"
19 #include "chrome/browser/io_thread.h" 21 #include "chrome/browser/io_thread.h"
(...skipping 22 matching lines...) Expand all
42 #include "net/base/transport_security_state.h" 44 #include "net/base/transport_security_state.h"
43 #include "net/disk_cache/disk_cache.h" 45 #include "net/disk_cache/disk_cache.h"
44 #include "net/http/http_cache.h" 46 #include "net/http/http_cache.h"
45 #include "net/url_request/url_request_context.h" 47 #include "net/url_request/url_request_context.h"
46 #include "net/url_request/url_request_context_getter.h" 48 #include "net/url_request/url_request_context_getter.h"
47 #include "webkit/database/database_tracker.h" 49 #include "webkit/database/database_tracker.h"
48 #include "webkit/database/database_util.h" 50 #include "webkit/database/database_util.h"
49 #include "webkit/fileapi/file_system_context.h" 51 #include "webkit/fileapi/file_system_context.h"
50 #include "webkit/fileapi/file_system_operation_context.h" 52 #include "webkit/fileapi/file_system_operation_context.h"
51 #include "webkit/fileapi/sandbox_mount_point_provider.h" 53 #include "webkit/fileapi/sandbox_mount_point_provider.h"
54 #include "webkit/quota/quota_types.h"
55 #include "webkit/quota/quota_manager.h"
52 56
53 // Done so that we can use PostTask on BrowsingDataRemovers and not have 57 // Done so that we can use PostTask on BrowsingDataRemovers and not have
54 // BrowsingDataRemover implement RefCounted. 58 // BrowsingDataRemover implement RefCounted.
55 DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowsingDataRemover); 59 DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowsingDataRemover);
56 60
57 bool BrowsingDataRemover::removing_ = false; 61 bool BrowsingDataRemover::removing_ = false;
58 62
59 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, 63 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
60 base::Time delete_begin, 64 base::Time delete_begin,
61 base::Time delete_end) 65 base::Time delete_end)
(...skipping 13 matching lines...) Expand all
75 next_cache_state_(STATE_NONE), 79 next_cache_state_(STATE_NONE),
76 cache_(NULL), 80 cache_(NULL),
77 main_context_getter_(profile->GetRequestContext()), 81 main_context_getter_(profile->GetRequestContext()),
78 media_context_getter_(profile->GetRequestContextForMedia()), 82 media_context_getter_(profile->GetRequestContextForMedia()),
79 waiting_for_clear_databases_(false), 83 waiting_for_clear_databases_(false),
80 waiting_for_clear_history_(false), 84 waiting_for_clear_history_(false),
81 waiting_for_clear_networking_history_(false), 85 waiting_for_clear_networking_history_(false),
82 waiting_for_clear_cache_(false), 86 waiting_for_clear_cache_(false),
83 waiting_for_clear_appcache_(false), 87 waiting_for_clear_appcache_(false),
84 waiting_for_clear_gears_data_(false), 88 waiting_for_clear_gears_data_(false),
85 waiting_for_clear_file_systems_(false) { 89 waiting_for_clear_file_systems_(false),
90 temporary_quota_origins_to_delete_count_(0) {
86 DCHECK(profile); 91 DCHECK(profile);
87 } 92 }
88 93
89 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, 94 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
90 TimePeriod time_period, 95 TimePeriod time_period,
91 base::Time delete_end) 96 base::Time delete_end)
92 : profile_(profile), 97 : profile_(profile),
93 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), 98 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()),
94 delete_begin_(CalculateBeginDeleteTime(time_period)), 99 delete_begin_(CalculateBeginDeleteTime(time_period)),
95 delete_end_(delete_end), 100 delete_end_(delete_end),
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 --appcaches_to_be_deleted_count_; 568 --appcaches_to_be_deleted_count_;
564 if (!appcaches_to_be_deleted_count_) 569 if (!appcaches_to_be_deleted_count_)
565 OnClearedAppCache(); 570 OnClearedAppCache();
566 } 571 }
567 572
568 void BrowsingDataRemover::ClearFileSystemsOnFILEThread() { 573 void BrowsingDataRemover::ClearFileSystemsOnFILEThread() {
569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
570 DCHECK(waiting_for_clear_file_systems_); 575 DCHECK(waiting_for_clear_file_systems_);
571 scoped_refptr<fileapi::FileSystemContext> 576 scoped_refptr<fileapi::FileSystemContext>
572 fs_context(profile_->GetFileSystemContext()); 577 fs_context(profile_->GetFileSystemContext());
578
579 // We own the reference to the OriginEnumerator, so we wrap it in a scoped_ptr
580 // to ensure that it's destroyed when we leave the FILE thread.
573 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> 581 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator>
574 origin_enumerator(fs_context->path_manager()->sandbox_provider()-> 582 origins(fs_context->path_manager()->sandbox_provider()->
575 CreateOriginEnumerator()); 583 CreateOriginEnumerator());
576 584
577 GURL origin; 585 if (delete_begin_ == base::Time()) {
578 while (!(origin = origin_enumerator->Next()).is_empty()) { 586 // If the user chooses to delete browsing data "since the beginning of
579 if (special_storage_policy_->IsStorageProtected(origin)) 587 // time" remove both temporary and persistent file systems entirely by
580 continue; 588 // walking through all origins and deleting them if they're unprotected.
581 if (delete_begin_ == base::Time()) { 589 GURL origin;
582 // If the user chooses to delete browsing data "since the beginning of 590 while (!(origin = origins->Next()).is_empty()) {
583 // time" remove both temporary and persistent file systems entirely. 591 if (special_storage_policy_->IsStorageProtected(origin))
584 fs_context->DeleteDataForOriginAndTypeOnFileThread(origin, 592 continue;
585 fileapi::kFileSystemTypeTemporary); 593 fs_context->DeleteDataForOriginOnFileThread(origin);
586 fs_context->DeleteDataForOriginAndTypeOnFileThread(origin,
587 fileapi::kFileSystemTypePersistent);
588 } 594 }
589 // TODO(mkwst): Else? Decide what to do for time-based deletion: crbug/63700 595 BrowserThread::PostTask(
596 BrowserThread::UI, FROM_HERE,
597 NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems));
598 } else {
599 // Otherwise, ask the QuotaManager for all origins with temporary quota
600 // modified within the user-specified timeframe, and deal with the resulting
601 // set in ProcessTemporaryQuotaModifiedInTimeframe().
602 temporary_quota_origins_to_delete_count_ = 0;
603 profile_->GetQuotaManager()->GetOriginsModifiedSince(
604 quota::kStorageTypeTemporary, delete_begin_, NewCallback(this,
605 &BrowsingDataRemover::ProcessTemporaryQuotaModifiedInTimeframe));
590 } 606 }
591
592 BrowserThread::PostTask(
593 BrowserThread::UI, FROM_HERE,
594 NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems));
595 } 607 }
596 608
597 void BrowsingDataRemover::OnClearedFileSystems() { 609 void BrowsingDataRemover::OnClearedFileSystems() {
598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
599 waiting_for_clear_file_systems_ = false; 611 waiting_for_clear_file_systems_ = false;
600 NotifyAndDeleteIfDone(); 612 NotifyAndDeleteIfDone();
601 } 613 }
602 614
615 void BrowsingDataRemover::ProcessTemporaryQuotaModifiedInTimeframe(
616 const std::set<GURL>& origins) {
617 // The QuotaManager is owned by the profile; we can use a raw pointer here,
618 // and rely on the profile to destroy the object whenever it's reasonable.
619 quota::QuotaManager* quota_manager = profile_->GetQuotaManager();
620
621 // Walk through the origins passed in, delete temporary quota from each that
622 // isn't protected.
623 std::set<GURL>::iterator origin;
624 for (origin = origins.begin(); origin != origins.end(); ++origin) {
625 if (special_storage_policy_->IsStorageProtected(*origin))
626 continue;
627 ++temporary_quota_origins_to_delete_count_;
628 quota_manager->DeleteOriginData(*origin, quota::kStorageTypeTemporary,
629 NewCallback(this, &BrowsingDataRemover::DeleteOriginDataCallback));
630 }
631 if (temporary_quota_origins_to_delete_count_ == 0) {
632 BrowserThread::PostTask(
633 BrowserThread::UI, FROM_HERE,
634 NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems));
635 }
636 }
637
638 void BrowsingDataRemover::DeleteOriginDataCallback(
639 quota::QuotaStatusCode status) {
640 if (status != quota::kQuotaStatusOk) {
641 // TODO(mkwst): Not really anything pretty I can think of to do here.
642 }
643
644 --temporary_quota_origins_to_delete_count_;
645
646 if (temporary_quota_origins_to_delete_count_ == 0) {
647 BrowserThread::PostTask(
648 BrowserThread::UI, FROM_HERE,
649 NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems));
650 }
651 }
652
603 // static 653 // static
604 void BrowsingDataRemover::ClearGearsData(const FilePath& profile_dir) { 654 void BrowsingDataRemover::ClearGearsData(const FilePath& profile_dir) {
605 FilePath plugin_data = profile_dir.AppendASCII("Plugin Data"); 655 FilePath plugin_data = profile_dir.AppendASCII("Plugin Data");
606 if (file_util::DirectoryExists(plugin_data)) 656 if (file_util::DirectoryExists(plugin_data))
607 file_util::Delete(plugin_data, true); 657 file_util::Delete(plugin_data, true);
608 } 658 }
609 659
610 void BrowsingDataRemover::OnClearedGearsData() { 660 void BrowsingDataRemover::OnClearedGearsData() {
611 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 661 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
612 bool result = BrowserThread::PostTask( 662 bool result = BrowserThread::PostTask(
(...skipping 13 matching lines...) Expand all
626 676
627 ClearGearsData(profile_dir); 677 ClearGearsData(profile_dir);
628 OnClearedGearsData(); 678 OnClearedGearsData();
629 } 679 }
630 680
631 void BrowsingDataRemover::OnWaitableEventSignaled( 681 void BrowsingDataRemover::OnWaitableEventSignaled(
632 base::WaitableEvent* waitable_event) { 682 base::WaitableEvent* waitable_event) {
633 waiting_for_clear_lso_data_ = false; 683 waiting_for_clear_lso_data_ = false;
634 NotifyAndDeleteIfDone(); 684 NotifyAndDeleteIfDone();
635 } 685 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698