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

Side by Side Diff: chrome/browser/browsing_data_remover.cc

Issue 7210034: Update BrowsingDataRemover with the asynchronous CookieMonster API. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' 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/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/file_util.h" 12 #include "base/file_util.h"
12 #include "base/platform_file.h" 13 #include "base/platform_file.h"
13 #include "chrome/browser/autofill/personal_data_manager.h" 14 #include "chrome/browser/autofill/personal_data_manager.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/download/download_manager.h" 16 #include "chrome/browser/download/download_manager.h"
16 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_special_storage_policy.h" 18 #include "chrome/browser/extensions/extension_special_storage_policy.h"
18 #include "chrome/browser/history/history.h" 19 #include "chrome/browser/history/history.h"
19 #include "chrome/browser/io_thread.h" 20 #include "chrome/browser/io_thread.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( 73 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_(
73 this, &BrowsingDataRemover::OnAppCacheDeleted)), 74 this, &BrowsingDataRemover::OnAppCacheDeleted)),
74 appcaches_to_be_deleted_count_(0), 75 appcaches_to_be_deleted_count_(0),
75 next_cache_state_(STATE_NONE), 76 next_cache_state_(STATE_NONE),
76 cache_(NULL), 77 cache_(NULL),
77 main_context_getter_(profile->GetRequestContext()), 78 main_context_getter_(profile->GetRequestContext()),
78 media_context_getter_(profile->GetRequestContextForMedia()), 79 media_context_getter_(profile->GetRequestContextForMedia()),
79 waiting_for_clear_databases_(false), 80 waiting_for_clear_databases_(false),
80 waiting_for_clear_history_(false), 81 waiting_for_clear_history_(false),
81 waiting_for_clear_networking_history_(false), 82 waiting_for_clear_networking_history_(false),
83 waiting_for_clear_cookies_(false),
82 waiting_for_clear_cache_(false), 84 waiting_for_clear_cache_(false),
83 waiting_for_clear_appcache_(false), 85 waiting_for_clear_appcache_(false),
84 waiting_for_clear_gears_data_(false), 86 waiting_for_clear_gears_data_(false),
85 waiting_for_clear_file_systems_(false) { 87 waiting_for_clear_file_systems_(false) {
86 DCHECK(profile); 88 DCHECK(profile);
87 } 89 }
88 90
89 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, 91 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
90 TimePeriod time_period, 92 TimePeriod time_period,
91 base::Time delete_end) 93 base::Time delete_end)
(...skipping 10 matching lines...) Expand all
102 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( 104 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_(
103 this, &BrowsingDataRemover::OnAppCacheDeleted)), 105 this, &BrowsingDataRemover::OnAppCacheDeleted)),
104 appcaches_to_be_deleted_count_(0), 106 appcaches_to_be_deleted_count_(0),
105 next_cache_state_(STATE_NONE), 107 next_cache_state_(STATE_NONE),
106 cache_(NULL), 108 cache_(NULL),
107 main_context_getter_(profile->GetRequestContext()), 109 main_context_getter_(profile->GetRequestContext()),
108 media_context_getter_(profile->GetRequestContextForMedia()), 110 media_context_getter_(profile->GetRequestContextForMedia()),
109 waiting_for_clear_databases_(false), 111 waiting_for_clear_databases_(false),
110 waiting_for_clear_history_(false), 112 waiting_for_clear_history_(false),
111 waiting_for_clear_networking_history_(false), 113 waiting_for_clear_networking_history_(false),
114 waiting_for_clear_cookies_(false),
112 waiting_for_clear_cache_(false), 115 waiting_for_clear_cache_(false),
113 waiting_for_clear_appcache_(false), 116 waiting_for_clear_appcache_(false),
114 waiting_for_clear_lso_data_(false), 117 waiting_for_clear_lso_data_(false),
115 waiting_for_clear_gears_data_(false), 118 waiting_for_clear_gears_data_(false),
116 waiting_for_clear_file_systems_(false) { 119 waiting_for_clear_file_systems_(false) {
117 DCHECK(profile); 120 DCHECK(profile);
118 } 121 }
119 122
120 BrowsingDataRemover::~BrowsingDataRemover() { 123 BrowsingDataRemover::~BrowsingDataRemover() {
121 DCHECK(all_done()); 124 DCHECK(all_done());
122 } 125 }
123 126
124 void BrowsingDataRemover::Remove(int remove_mask) { 127 void BrowsingDataRemover::Remove(int remove_mask) {
125 DCHECK(!removing_); 128 DCHECK(!removing_);
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
126 removing_ = true; 130 removing_ = true;
127 131
128 if (remove_mask & REMOVE_HISTORY) { 132 if (remove_mask & REMOVE_HISTORY) {
129 HistoryService* history_service = 133 HistoryService* history_service =
130 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 134 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
131 if (history_service) { 135 if (history_service) {
132 std::set<GURL> restrict_urls; 136 std::set<GURL> restrict_urls;
133 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); 137 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
134 waiting_for_clear_history_ = true; 138 waiting_for_clear_history_ = true;
135 history_service->ExpireHistoryBetween(restrict_urls, 139 history_service->ExpireHistoryBetween(restrict_urls,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (remove_mask & REMOVE_DOWNLOADS) { 195 if (remove_mask & REMOVE_DOWNLOADS) {
192 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); 196 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
193 DownloadManager* download_manager = profile_->GetDownloadManager(); 197 DownloadManager* download_manager = profile_->GetDownloadManager();
194 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); 198 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_);
195 download_manager->ClearLastDownloadPath(); 199 download_manager->ClearLastDownloadPath();
196 } 200 }
197 201
198 if (remove_mask & REMOVE_COOKIES) { 202 if (remove_mask & REMOVE_COOKIES) {
199 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); 203 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
200 // Since we are running on the UI thread don't call GetURLRequestContext(). 204 // Since we are running on the UI thread don't call GetURLRequestContext().
201 net::CookieMonster* cookie_monster = NULL;
202 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext(); 205 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext();
203 if (rq_context) { 206 if (rq_context) {
204 cookie_monster = rq_context->DONTUSEME_GetCookieStore()-> 207 waiting_for_clear_cookies_ = true;
205 GetCookieMonster(); 208 BrowserThread::PostTask(
209 BrowserThread::IO, FROM_HERE,
210 base::Bind(&BrowsingDataRemover::ClearCookieOnIOThread,
211 base::Unretained(this), base::Unretained(rq_context)));
206 } 212 }
207 if (cookie_monster)
208 cookie_monster->DeleteAllCreatedBetween(delete_begin_, delete_end_, true);
209 213
210 // REMOVE_COOKIES is actually "cookies and other site data" so we make sure 214 // REMOVE_COOKIES is actually "cookies and other site data" so we make sure
211 // to remove other data such local databases, STS state, etc. These only can 215 // to remove other data such local databases, STS state, etc. These only can
212 // be removed if a WEBKIT thread exists, so check that first: 216 // be removed if a WEBKIT thread exists, so check that first:
213 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT)) { 217 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT)) {
214 // We assume the end time is now. 218 // We assume the end time is now.
215 profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_); 219 profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_);
216 } 220 }
217 221
218 database_tracker_ = profile_->GetDatabaseTracker(); 222 database_tracker_ = profile_->GetDatabaseTracker();
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 630
627 ClearGearsData(profile_dir); 631 ClearGearsData(profile_dir);
628 OnClearedGearsData(); 632 OnClearedGearsData();
629 } 633 }
630 634
631 void BrowsingDataRemover::OnWaitableEventSignaled( 635 void BrowsingDataRemover::OnWaitableEventSignaled(
632 base::WaitableEvent* waitable_event) { 636 base::WaitableEvent* waitable_event) {
633 waiting_for_clear_lso_data_ = false; 637 waiting_for_clear_lso_data_ = false;
634 NotifyAndDeleteIfDone(); 638 NotifyAndDeleteIfDone();
635 } 639 }
640
641 void BrowsingDataRemover::OnClearedCookie(int num_deleted) {
erikwright (departed) 2011/07/25 16:27:16 nit: OnClearedCookie->OnClearedCookies
642 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
643 BrowserThread::PostTask(
644 BrowserThread::UI, FROM_HERE,
645 base::Bind(&BrowsingDataRemover::OnClearedCookie,
646 base::Unretained(this), num_deleted));
647 return;
648 }
649
650 waiting_for_clear_cookies_ = false;
651 NotifyAndDeleteIfDone();
652 }
653
654 void BrowsingDataRemover::ClearCookieOnIOThread(
erikwright (departed) 2011/07/25 16:27:16 nit: ClearCookie->ClearCookies
655 net::URLRequestContextGetter* rq_context) {
656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
657 net::CookieMonster* cookie_monster = rq_context->
658 GetURLRequestContext()->cookie_store()->GetCookieMonster();
659 if (cookie_monster) {
660 cookie_monster->DeleteAllCreatedBetweenAsync(
661 delete_begin_, delete_end_, true,
662 base::Bind(&BrowsingDataRemover::OnClearedCookie,
663 base::Unretained(this)));
664 } else {
665 OnClearedCookie(0);
666 }
667 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698