chromeos: bluetooth: tie Proxy lifetime to object, not observer
[chromium-blink-merge.git] / chrome / browser / browsing_data_remover.cc
blob9273f01ae3b63134f0a9a15e0f49457e42152aab
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/browsing_data_remover.h"
7 #include <map>
8 #include <set>
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/callback.h"
13 #include "base/file_util.h"
14 #include "base/logging.h"
15 #include "base/platform_file.h"
16 #include "chrome/browser/autofill/personal_data_manager.h"
17 #include "chrome/browser/autofill/personal_data_manager_factory.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/download/download_service.h"
20 #include "chrome/browser/download/download_service_factory.h"
21 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/extension_special_storage_policy.h"
23 #include "chrome/browser/history/history.h"
24 #include "chrome/browser/io_thread.h"
25 #include "chrome/browser/net/chrome_net_log.h"
26 #include "chrome/browser/net/chrome_url_request_context.h"
27 #include "chrome/browser/net/predictor.h"
28 #include "chrome/browser/password_manager/password_store.h"
29 #include "chrome/browser/prefs/pref_member.h"
30 #include "chrome/browser/prerender/prerender_manager.h"
31 #include "chrome/browser/prerender/prerender_manager_factory.h"
32 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/renderer_host/web_cache_manager.h"
34 #include "chrome/browser/search_engines/template_url_service.h"
35 #include "chrome/browser/search_engines/template_url_service_factory.h"
36 #include "chrome/browser/sessions/session_service.h"
37 #include "chrome/browser/sessions/session_service_factory.h"
38 #include "chrome/browser/sessions/tab_restore_service.h"
39 #include "chrome/browser/sessions/tab_restore_service_factory.h"
40 #include "chrome/browser/webdata/web_data_service.h"
41 #include "chrome/common/chrome_notification_types.h"
42 #include "chrome/common/pref_names.h"
43 #include "chrome/common/url_constants.h"
44 #include "content/browser/in_process_webkit/webkit_context.h"
45 #include "content/public/browser/browser_thread.h"
46 #include "content/public/browser/download_manager.h"
47 #include "content/public/browser/notification_service.h"
48 #include "content/public/browser/plugin_data_remover.h"
49 #include "content/public/browser/user_metrics.h"
50 #include "net/base/cookie_store.h"
51 #include "net/base/net_errors.h"
52 #include "net/base/origin_bound_cert_service.h"
53 #include "net/base/origin_bound_cert_store.h"
54 #include "net/base/transport_security_state.h"
55 #include "net/disk_cache/disk_cache.h"
56 #include "net/http/http_cache.h"
57 #include "net/url_request/url_request_context.h"
58 #include "net/url_request/url_request_context_getter.h"
59 #include "webkit/quota/quota_manager.h"
60 #include "webkit/quota/quota_types.h"
62 using content::BrowserThread;
63 using content::DownloadManager;
64 using content::UserMetricsAction;
66 bool BrowsingDataRemover::removing_ = false;
68 BrowsingDataRemover::NotificationDetails::NotificationDetails()
69 : removal_begin(base::Time()),
70 removal_mask(-1) {
73 BrowsingDataRemover::NotificationDetails::NotificationDetails(
74 const BrowsingDataRemover::NotificationDetails& details)
75 : removal_begin(details.removal_begin),
76 removal_mask(details.removal_mask) {
79 BrowsingDataRemover::NotificationDetails::NotificationDetails(
80 base::Time removal_begin,
81 int removal_mask)
82 : removal_begin(removal_begin),
83 removal_mask(removal_mask) {
86 BrowsingDataRemover::NotificationDetails::~NotificationDetails() {}
88 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
89 base::Time delete_begin,
90 base::Time delete_end)
91 : profile_(profile),
92 quota_manager_(NULL),
93 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()),
94 delete_begin_(delete_begin),
95 delete_end_(delete_end),
96 next_cache_state_(STATE_NONE),
97 cache_(NULL),
98 main_context_getter_(profile->GetRequestContext()),
99 media_context_getter_(profile->GetRequestContextForMedia()),
100 waiting_for_clear_cache_(false),
101 waiting_for_clear_cookies_(false),
102 waiting_for_clear_history_(false),
103 waiting_for_clear_networking_history_(false),
104 waiting_for_clear_origin_bound_certs_(false),
105 waiting_for_clear_plugin_data_(false),
106 waiting_for_clear_quota_managed_data_(false),
107 remove_mask_(0) {
108 DCHECK(profile);
111 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
112 TimePeriod time_period,
113 base::Time delete_end)
114 : profile_(profile),
115 quota_manager_(NULL),
116 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()),
117 delete_begin_(CalculateBeginDeleteTime(time_period)),
118 delete_end_(delete_end),
119 next_cache_state_(STATE_NONE),
120 cache_(NULL),
121 main_context_getter_(profile->GetRequestContext()),
122 media_context_getter_(profile->GetRequestContextForMedia()),
123 waiting_for_clear_cache_(false),
124 waiting_for_clear_cookies_(false),
125 waiting_for_clear_history_(false),
126 waiting_for_clear_networking_history_(false),
127 waiting_for_clear_origin_bound_certs_(false),
128 waiting_for_clear_plugin_data_(false),
129 waiting_for_clear_quota_managed_data_(false),
130 remove_mask_(0) {
131 DCHECK(profile);
134 BrowsingDataRemover::~BrowsingDataRemover() {
135 DCHECK(all_done());
138 // Static.
139 void BrowsingDataRemover::set_removing(bool removing) {
140 DCHECK(removing_ != removing);
141 removing_ = removing;
144 void BrowsingDataRemover::Remove(int remove_mask) {
145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
146 set_removing(true);
147 remove_mask_ = remove_mask;
149 if (remove_mask & REMOVE_HISTORY) {
150 HistoryService* history_service =
151 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
152 if (history_service) {
153 std::set<GURL> restrict_urls;
154 content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
155 waiting_for_clear_history_ = true;
156 history_service->ExpireHistoryBetween(restrict_urls,
157 delete_begin_, delete_end_,
158 &request_consumer_,
159 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
160 base::Unretained(this)));
163 // Need to clear the host cache and accumulated speculative data, as it also
164 // reveals some history.
165 if (g_browser_process->io_thread()) {
166 waiting_for_clear_networking_history_ = true;
167 BrowserThread::PostTask(
168 BrowserThread::IO, FROM_HERE,
169 base::Bind(&BrowsingDataRemover::ClearNetworkingHistory,
170 base::Unretained(this), g_browser_process->io_thread()));
173 // As part of history deletion we also delete the auto-generated keywords.
174 TemplateURLService* keywords_model =
175 TemplateURLServiceFactory::GetForProfile(profile_);
176 if (keywords_model && !keywords_model->loaded()) {
177 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
178 content::Source<TemplateURLService>(keywords_model));
179 keywords_model->Load();
180 } else if (keywords_model) {
181 keywords_model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_);
184 // We also delete the list of recently closed tabs. Since these expire,
185 // they can't be more than a day old, so we can simply clear them all.
186 TabRestoreService* tab_service =
187 TabRestoreServiceFactory::GetForProfile(profile_);
188 if (tab_service) {
189 tab_service->ClearEntries();
190 tab_service->DeleteLastSession();
193 // We also delete the last session when we delete the history.
194 SessionService* session_service =
195 SessionServiceFactory::GetForProfile(profile_);
196 if (session_service)
197 session_service->DeleteLastSession();
199 // The PrerenderManager keeps history of prerendered pages, so clear that.
200 // It also may have a prerendered page. If so, the page could be considered
201 // to have a small amount of historical information, so delete it, too.
202 prerender::PrerenderManager* prerender_manager =
203 prerender::PrerenderManagerFactory::GetForProfile(profile_);
204 if (prerender_manager) {
205 prerender_manager->ClearData(
206 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
207 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
211 if (remove_mask & REMOVE_DOWNLOADS) {
212 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
213 DownloadManager* download_manager =
214 DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager();
215 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_);
216 download_manager->ClearLastDownloadPath();
219 if (remove_mask & REMOVE_COOKIES) {
220 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
221 // Since we are running on the UI thread don't call GetURLRequestContext().
222 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext();
223 if (rq_context) {
224 waiting_for_clear_cookies_ = true;
225 BrowserThread::PostTask(
226 BrowserThread::IO, FROM_HERE,
227 base::Bind(&BrowsingDataRemover::ClearCookiesOnIOThread,
228 base::Unretained(this), base::Unretained(rq_context)));
232 if (remove_mask & REMOVE_ORIGIN_BOUND_CERTS) {
233 content::RecordAction(
234 UserMetricsAction("ClearBrowsingData_OriginBoundCerts"));
235 // Since we are running on the UI thread don't call GetURLRequestContext().
236 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext();
237 if (rq_context) {
238 waiting_for_clear_origin_bound_certs_ = true;
239 BrowserThread::PostTask(
240 BrowserThread::IO, FROM_HERE,
241 base::Bind(&BrowsingDataRemover::ClearOriginBoundCertsOnIOThread,
242 base::Unretained(this), base::Unretained(rq_context)));
246 if (remove_mask & REMOVE_LOCAL_STORAGE) {
247 // Remove data such as local databases, STS state, etc. These only can
248 // be removed if a WEBKIT thread exists, so check that first:
249 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) {
250 // We assume the end time is now.
251 profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_);
255 if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL ||
256 remove_mask & REMOVE_APPCACHE || remove_mask & REMOVE_FILE_SYSTEMS) {
257 // TODO(mkwst): At the moment, we don't have the ability to pass a mask into
258 // QuotaManager. Until then, we'll clear all quota-managed data types if any
259 // ought to be cleared.
260 quota_manager_ = profile_->GetQuotaManager();
261 if (quota_manager_) {
262 waiting_for_clear_quota_managed_data_ = true;
263 BrowserThread::PostTask(
264 BrowserThread::IO, FROM_HERE,
265 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread,
266 base::Unretained(this)));
270 if (remove_mask & REMOVE_PLUGIN_DATA) {
271 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
273 waiting_for_clear_plugin_data_ = true;
274 if (!plugin_data_remover_.get()) {
275 plugin_data_remover_.reset(
276 content::PluginDataRemover::Create(profile_->GetResourceContext()));
278 base::WaitableEvent* event =
279 plugin_data_remover_->StartRemoving(delete_begin_);
280 watcher_.StartWatching(event, this);
283 if (remove_mask & REMOVE_PASSWORDS) {
284 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
285 PasswordStore* password_store =
286 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS);
288 if (password_store)
289 password_store->RemoveLoginsCreatedBetween(delete_begin_, delete_end_);
292 if (remove_mask & REMOVE_FORM_DATA) {
293 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
294 WebDataService* web_data_service =
295 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
297 if (web_data_service) {
298 web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
299 delete_end_);
300 web_data_service->RemoveAutofillProfilesAndCreditCardsModifiedBetween(
301 delete_begin_, delete_end_);
302 PersonalDataManager* data_manager =
303 PersonalDataManagerFactory::GetForProfile(profile_);
304 if (data_manager) {
305 data_manager->Refresh();
310 if (remove_mask & REMOVE_CACHE) {
311 // Tell the renderers to clear their cache.
312 WebCacheManager::GetInstance()->ClearCache();
314 // Invoke DoClearCache on the IO thread.
315 waiting_for_clear_cache_ = true;
316 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache"));
318 BrowserThread::PostTask(
319 BrowserThread::IO, FROM_HERE,
320 base::Bind(&BrowsingDataRemover::ClearCacheOnIOThread,
321 base::Unretained(this)));
323 // The PrerenderManager may have a page actively being prerendered, which
324 // is essentially a preemptively cached page.
325 prerender::PrerenderManager* prerender_manager =
326 prerender::PrerenderManagerFactory::GetForProfile(profile_);
327 if (prerender_manager) {
328 prerender_manager->ClearData(
329 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS);
333 // Also delete cached network related data (like TransportSecurityState,
334 // HttpServerProperties data).
335 profile_->ClearNetworkingHistorySince(delete_begin_);
337 NotifyAndDeleteIfDone();
340 void BrowsingDataRemover::AddObserver(Observer* observer) {
341 observer_list_.AddObserver(observer);
344 void BrowsingDataRemover::RemoveObserver(Observer* observer) {
345 observer_list_.RemoveObserver(observer);
348 void BrowsingDataRemover::OnHistoryDeletionDone() {
349 waiting_for_clear_history_ = false;
350 NotifyAndDeleteIfDone();
353 base::Time BrowsingDataRemover::CalculateBeginDeleteTime(
354 TimePeriod time_period) {
355 base::TimeDelta diff;
356 base::Time delete_begin_time = base::Time::Now();
357 switch (time_period) {
358 case LAST_HOUR:
359 diff = base::TimeDelta::FromHours(1);
360 break;
361 case LAST_DAY:
362 diff = base::TimeDelta::FromHours(24);
363 break;
364 case LAST_WEEK:
365 diff = base::TimeDelta::FromHours(7*24);
366 break;
367 case FOUR_WEEKS:
368 diff = base::TimeDelta::FromHours(4*7*24);
369 break;
370 case EVERYTHING:
371 delete_begin_time = base::Time();
372 break;
373 default:
374 NOTREACHED() << L"Missing item";
375 break;
377 return delete_begin_time - diff;
380 void BrowsingDataRemover::Observe(int type,
381 const content::NotificationSource& source,
382 const content::NotificationDetails& details) {
383 // TODO(brettw) bug 1139736: This should also observe session
384 // clearing (what about other things such as passwords, etc.?) and wait for
385 // them to complete before continuing.
386 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED);
387 TemplateURLService* model = content::Source<TemplateURLService>(source).ptr();
388 if (model->profile() == profile_) {
389 registrar_.RemoveAll();
390 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_);
391 NotifyAndDeleteIfDone();
395 void BrowsingDataRemover::NotifyAndDeleteIfDone() {
396 // TODO(brettw) bug 1139736: see TODO in Observe() above.
397 if (!all_done())
398 return;
400 // The NetLog contains download history, but may also contain form data,
401 // cookies and passwords. Simplest just to always clear it. Must be cleared
402 // after the cache, as cleaning up the disk cache exposes some of the history
403 // in the NetLog.
404 if (g_browser_process->net_log())
405 g_browser_process->net_log()->ClearAllPassivelyCapturedEvents();
407 set_removing(false);
409 // Send global notification, then notify any explicit observers.
410 BrowsingDataRemover::NotificationDetails details(delete_begin_, remove_mask_);
411 content::NotificationService::current()->Notify(
412 chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
413 content::Source<Profile>(profile_),
414 content::Details<BrowsingDataRemover::NotificationDetails>(&details));
416 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone());
418 // History requests aren't happy if you delete yourself from the callback.
419 // As such, we do a delete later.
420 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
423 void BrowsingDataRemover::ClearedNetworkHistory() {
424 waiting_for_clear_networking_history_ = false;
426 NotifyAndDeleteIfDone();
429 void BrowsingDataRemover::ClearNetworkingHistory(IOThread* io_thread) {
430 // This function should be called on the IO thread.
431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
433 io_thread->ClearHostCache();
435 chrome_browser_net::Predictor* predictor = profile_->GetNetworkPredictor();
436 if (predictor) {
437 predictor->DiscardInitialNavigationHistory();
438 predictor->DiscardAllResults();
441 // Notify the UI thread that we are done.
442 BrowserThread::PostTask(
443 BrowserThread::UI, FROM_HERE,
444 base::Bind(&BrowsingDataRemover::ClearedNetworkHistory,
445 base::Unretained(this)));
448 void BrowsingDataRemover::ClearedCache() {
449 waiting_for_clear_cache_ = false;
451 NotifyAndDeleteIfDone();
454 void BrowsingDataRemover::ClearCacheOnIOThread() {
455 // This function should be called on the IO thread.
456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
457 DCHECK_EQ(STATE_NONE, next_cache_state_);
458 DCHECK(main_context_getter_);
459 DCHECK(media_context_getter_);
461 next_cache_state_ = STATE_CREATE_MAIN;
462 DoClearCache(net::OK);
465 // The expected state sequence is STATE_NONE --> STATE_CREATE_MAIN -->
466 // STATE_DELETE_MAIN --> STATE_CREATE_MEDIA --> STATE_DELETE_MEDIA -->
467 // STATE_DONE, and any errors are ignored.
468 void BrowsingDataRemover::DoClearCache(int rv) {
469 DCHECK_NE(STATE_NONE, next_cache_state_);
471 while (rv != net::ERR_IO_PENDING && next_cache_state_ != STATE_NONE) {
472 switch (next_cache_state_) {
473 case STATE_CREATE_MAIN:
474 case STATE_CREATE_MEDIA: {
475 // Get a pointer to the cache.
476 net::URLRequestContextGetter* getter =
477 (next_cache_state_ == STATE_CREATE_MAIN) ?
478 main_context_getter_ : media_context_getter_;
479 net::HttpTransactionFactory* factory =
480 getter->GetURLRequestContext()->http_transaction_factory();
482 rv = factory->GetCache()->GetBackend(
483 &cache_, base::Bind(&BrowsingDataRemover::DoClearCache,
484 base::Unretained(this)));
485 next_cache_state_ = (next_cache_state_ == STATE_CREATE_MAIN) ?
486 STATE_DELETE_MAIN : STATE_DELETE_MEDIA;
487 break;
489 case STATE_DELETE_MAIN:
490 case STATE_DELETE_MEDIA: {
491 // |cache_| can be null if it cannot be initialized.
492 if (cache_) {
493 if (delete_begin_.is_null()) {
494 rv = cache_->DoomAllEntries(
495 base::Bind(&BrowsingDataRemover::DoClearCache,
496 base::Unretained(this)));
497 } else {
498 rv = cache_->DoomEntriesBetween(
499 delete_begin_, delete_end_,
500 base::Bind(&BrowsingDataRemover::DoClearCache,
501 base::Unretained(this)));
503 cache_ = NULL;
505 next_cache_state_ = (next_cache_state_ == STATE_DELETE_MAIN) ?
506 STATE_CREATE_MEDIA : STATE_DONE;
507 break;
509 case STATE_DONE: {
510 cache_ = NULL;
512 // Notify the UI thread that we are done.
513 BrowserThread::PostTask(
514 BrowserThread::UI, FROM_HERE,
515 base::Bind(&BrowsingDataRemover::ClearedCache,
516 base::Unretained(this)));
518 next_cache_state_ = STATE_NONE;
519 break;
521 default: {
522 NOTREACHED() << "bad state";
523 next_cache_state_ = STATE_NONE; // Stop looping.
524 break;
530 void BrowsingDataRemover::ClearQuotaManagedDataOnIOThread() {
531 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
533 // Ask the QuotaManager for all origins with temporary quota modified within
534 // the user-specified timeframe, and deal with the resulting set in
535 // OnGotQuotaManagedOrigins().
536 quota_managed_origins_to_delete_count_ = 0;
537 quota_managed_storage_types_to_delete_count_ = 2;
539 if (delete_begin_ == base::Time()) {
540 // If we're deleting since the beginning of time, ask the QuotaManager for
541 // all origins with persistent quota modified within the user-specified
542 // timeframe, and deal with the resulting set in
543 // OnGotPersistentQuotaManagedOrigins.
544 profile_->GetQuotaManager()->GetOriginsModifiedSince(
545 quota::kStorageTypePersistent, delete_begin_,
546 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins,
547 base::Unretained(this)));
548 } else {
549 // Otherwise, we don't need to deal with persistent storage.
550 --quota_managed_storage_types_to_delete_count_;
553 // Do the same for temporary quota, regardless, passing the resulting set into
554 // OnGotTemporaryQuotaManagedOrigins.
555 profile_->GetQuotaManager()->GetOriginsModifiedSince(
556 quota::kStorageTypeTemporary, delete_begin_,
557 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins,
558 base::Unretained(this)));
561 void BrowsingDataRemover::OnGotQuotaManagedOrigins(
562 const std::set<GURL>& origins, quota::StorageType type) {
563 DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0);
564 // Walk through the origins passed in, delete quota of |type| from each that
565 // isn't protected.
566 std::set<GURL>::const_iterator origin;
567 for (origin = origins.begin(); origin != origins.end(); ++origin) {
568 if (special_storage_policy_->IsStorageProtected(origin->GetOrigin()))
569 continue;
570 ++quota_managed_origins_to_delete_count_;
571 quota_manager_->DeleteOriginData(
572 origin->GetOrigin(), type,
573 base::Bind(&BrowsingDataRemover::OnQuotaManagedOriginDeletion,
574 base::Unretained(this)));
577 --quota_managed_storage_types_to_delete_count_;
578 CheckQuotaManagedDataDeletionStatus();
581 void BrowsingDataRemover::OnQuotaManagedOriginDeletion(
582 quota::QuotaStatusCode status) {
583 DCHECK_GT(quota_managed_origins_to_delete_count_, 0);
584 if (status != quota::kQuotaStatusOk) {
585 // TODO(mkwst): We should add the GURL to StatusCallback; this is a pretty
586 // worthless error message otherwise.
587 DLOG(ERROR) << "Couldn't remove origin. Status: " << status;
590 --quota_managed_origins_to_delete_count_;
591 CheckQuotaManagedDataDeletionStatus();
594 void BrowsingDataRemover::CheckQuotaManagedDataDeletionStatus() {
595 if (quota_managed_storage_types_to_delete_count_ != 0 ||
596 quota_managed_origins_to_delete_count_ != 0) {
597 return;
600 BrowserThread::PostTask(
601 BrowserThread::UI, FROM_HERE,
602 base::Bind(&BrowsingDataRemover::OnQuotaManagedDataDeleted,
603 base::Unretained(this)));
606 void BrowsingDataRemover::OnQuotaManagedDataDeleted() {
607 DCHECK(waiting_for_clear_quota_managed_data_);
608 waiting_for_clear_quota_managed_data_ = false;
609 NotifyAndDeleteIfDone();
612 void BrowsingDataRemover::OnWaitableEventSignaled(
613 base::WaitableEvent* waitable_event) {
614 waiting_for_clear_plugin_data_ = false;
615 NotifyAndDeleteIfDone();
618 void BrowsingDataRemover::OnClearedCookies(int num_deleted) {
619 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
620 BrowserThread::PostTask(
621 BrowserThread::UI, FROM_HERE,
622 base::Bind(&BrowsingDataRemover::OnClearedCookies,
623 base::Unretained(this), num_deleted));
624 return;
627 waiting_for_clear_cookies_ = false;
628 NotifyAndDeleteIfDone();
631 void BrowsingDataRemover::ClearCookiesOnIOThread(
632 net::URLRequestContextGetter* rq_context) {
633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
634 net::CookieStore* cookie_store = rq_context->
635 GetURLRequestContext()->cookie_store();
636 cookie_store->DeleteAllCreatedBetweenAsync(
637 delete_begin_, delete_end_,
638 base::Bind(&BrowsingDataRemover::OnClearedCookies,
639 base::Unretained(this)));
642 void BrowsingDataRemover::ClearOriginBoundCertsOnIOThread(
643 net::URLRequestContextGetter* rq_context) {
644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
645 net::OriginBoundCertService* origin_bound_cert_service =
646 rq_context->GetURLRequestContext()->origin_bound_cert_service();
647 origin_bound_cert_service->GetCertStore()->DeleteAllCreatedBetween(
648 delete_begin_, delete_end_);
649 BrowserThread::PostTask(
650 BrowserThread::UI, FROM_HERE,
651 base::Bind(&BrowsingDataRemover::OnClearedOriginBoundCerts,
652 base::Unretained(this)));
655 void BrowsingDataRemover::OnClearedOriginBoundCerts() {
656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
657 waiting_for_clear_origin_bound_certs_ = false;
658 NotifyAndDeleteIfDone();