OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/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/bind.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 #include "webkit/browser/quota/special_storage_policy.h" | 80 #include "webkit/browser/quota/special_storage_policy.h" |
81 #include "webkit/common/quota/quota_types.h" | 81 #include "webkit/common/quota/quota_types.h" |
82 | 82 |
83 using content::BrowserContext; | 83 using content::BrowserContext; |
84 using content::BrowserThread; | 84 using content::BrowserThread; |
85 using content::DOMStorageContext; | 85 using content::DOMStorageContext; |
86 using content::UserMetricsAction; | 86 using content::UserMetricsAction; |
87 | 87 |
88 bool BrowsingDataRemover::is_removing_ = false; | 88 bool BrowsingDataRemover::is_removing_ = false; |
89 | 89 |
| 90 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask. |
| 91 // Static. |
| 92 bool DoesOriginMatchMask(int origin_set_mask, |
| 93 const GURL& origin, |
| 94 quota::SpecialStoragePolicy* special_storage_policy) { |
| 95 return BrowsingDataHelper::DoesOriginMatchMask( |
| 96 origin, origin_set_mask, |
| 97 static_cast<ExtensionSpecialStoragePolicy*>(special_storage_policy)); |
| 98 } |
| 99 |
90 BrowsingDataRemover::NotificationDetails::NotificationDetails() | 100 BrowsingDataRemover::NotificationDetails::NotificationDetails() |
91 : removal_begin(base::Time()), | 101 : removal_begin(base::Time()), |
92 removal_mask(-1), | 102 removal_mask(-1), |
93 origin_set_mask(-1) { | 103 origin_set_mask(-1) { |
94 } | 104 } |
95 | 105 |
96 BrowsingDataRemover::NotificationDetails::NotificationDetails( | 106 BrowsingDataRemover::NotificationDetails::NotificationDetails( |
97 const BrowsingDataRemover::NotificationDetails& details) | 107 const BrowsingDataRemover::NotificationDetails& details) |
98 : removal_begin(details.removal_begin), | 108 : removal_begin(details.removal_begin), |
99 removal_mask(details.removal_mask), | 109 removal_mask(details.removal_mask), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } | 160 } |
151 return new BrowsingDataRemover(profile, | 161 return new BrowsingDataRemover(profile, |
152 BrowsingDataRemover::CalculateBeginDeleteTime(period), | 162 BrowsingDataRemover::CalculateBeginDeleteTime(period), |
153 base::Time::Max()); | 163 base::Time::Max()); |
154 } | 164 } |
155 | 165 |
156 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | 166 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
157 base::Time delete_begin, | 167 base::Time delete_begin, |
158 base::Time delete_end) | 168 base::Time delete_end) |
159 : profile_(profile), | 169 : profile_(profile), |
160 quota_manager_(NULL), | |
161 dom_storage_context_(NULL), | |
162 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | 170 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
163 delete_begin_(delete_begin), | 171 delete_begin_(delete_begin), |
164 delete_end_(delete_end), | 172 delete_end_(delete_end), |
165 next_cache_state_(STATE_NONE), | 173 next_cache_state_(STATE_NONE), |
166 cache_(NULL), | 174 cache_(NULL), |
167 main_context_getter_(profile->GetRequestContext()), | 175 main_context_getter_(profile->GetRequestContext()), |
168 media_context_getter_(profile->GetMediaRequestContext()), | 176 media_context_getter_(profile->GetMediaRequestContext()), |
169 deauthorize_content_licenses_request_id_(0), | 177 deauthorize_content_licenses_request_id_(0), |
170 waiting_for_clear_autofill_origin_urls_(false), | 178 waiting_for_clear_autofill_origin_urls_(false), |
171 waiting_for_clear_cache_(false), | 179 waiting_for_clear_cache_(false), |
172 waiting_for_clear_content_licenses_(false), | 180 waiting_for_clear_content_licenses_(false), |
173 waiting_for_clear_cookies_count_(0), | 181 waiting_for_clear_cookies_count_(0), |
174 waiting_for_clear_form_(false), | 182 waiting_for_clear_form_(false), |
175 waiting_for_clear_history_(false), | 183 waiting_for_clear_history_(false), |
176 waiting_for_clear_hostname_resolution_cache_(false), | 184 waiting_for_clear_hostname_resolution_cache_(false), |
177 waiting_for_clear_local_storage_(false), | 185 waiting_for_clear_keyword_data_(false), |
178 waiting_for_clear_logged_in_predictor_(false), | 186 waiting_for_clear_logged_in_predictor_(false), |
179 waiting_for_clear_nacl_cache_(false), | 187 waiting_for_clear_nacl_cache_(false), |
180 waiting_for_clear_network_predictor_(false), | 188 waiting_for_clear_network_predictor_(false), |
181 waiting_for_clear_networking_history_(false), | 189 waiting_for_clear_networking_history_(false), |
| 190 waiting_for_clear_platform_keys_(false), |
182 waiting_for_clear_plugin_data_(false), | 191 waiting_for_clear_plugin_data_(false), |
183 waiting_for_clear_pnacl_cache_(false), | 192 waiting_for_clear_pnacl_cache_(false), |
184 waiting_for_clear_quota_managed_data_(false), | |
185 waiting_for_clear_server_bound_certs_(false), | 193 waiting_for_clear_server_bound_certs_(false), |
186 waiting_for_clear_session_storage_(false), | 194 waiting_for_clear_storage_partition_data_(false), |
187 waiting_for_clear_shader_cache_(false), | |
188 waiting_for_clear_webrtc_identity_store_(false), | |
189 waiting_for_clear_keyword_data_(false), | |
190 waiting_for_clear_platform_keys_(false), | |
191 remove_mask_(0), | 195 remove_mask_(0), |
192 remove_origin_(GURL()), | 196 remove_origin_(GURL()), |
193 origin_set_mask_(0) { | 197 origin_set_mask_(0), |
| 198 storage_partition_for_testing_(NULL) { |
194 DCHECK(profile); | 199 DCHECK(profile); |
195 // crbug.com/140910: Many places were calling this with base::Time() as | 200 // crbug.com/140910: Many places were calling this with base::Time() as |
196 // delete_end, even though they should've used base::Time::Max(). Work around | 201 // delete_end, even though they should've used base::Time::Max(). Work around |
197 // it here. New code should use base::Time::Max(). | 202 // it here. New code should use base::Time::Max(). |
198 DCHECK(delete_end_ != base::Time()); | 203 DCHECK(delete_end_ != base::Time()); |
199 if (delete_end_ == base::Time()) | 204 if (delete_end_ == base::Time()) |
200 delete_end_ = base::Time::Max(); | 205 delete_end_ = base::Time::Max(); |
201 } | 206 } |
202 | 207 |
203 BrowsingDataRemover::~BrowsingDataRemover() { | 208 BrowsingDataRemover::~BrowsingDataRemover() { |
204 DCHECK(AllDone()); | 209 DCHECK(AllDone()); |
205 } | 210 } |
206 | 211 |
207 // Static. | 212 // Static. |
208 void BrowsingDataRemover::set_removing(bool is_removing) { | 213 void BrowsingDataRemover::set_removing(bool is_removing) { |
209 DCHECK(is_removing_ != is_removing); | 214 DCHECK(is_removing_ != is_removing); |
210 is_removing_ = is_removing; | 215 is_removing_ = is_removing; |
211 } | 216 } |
212 | 217 |
213 // Static. | |
214 int BrowsingDataRemover::GenerateQuotaClientMask(int remove_mask) { | |
215 int quota_client_mask = 0; | |
216 if (remove_mask & BrowsingDataRemover::REMOVE_FILE_SYSTEMS) | |
217 quota_client_mask |= quota::QuotaClient::kFileSystem; | |
218 if (remove_mask & BrowsingDataRemover::REMOVE_WEBSQL) | |
219 quota_client_mask |= quota::QuotaClient::kDatabase; | |
220 if (remove_mask & BrowsingDataRemover::REMOVE_APPCACHE) | |
221 quota_client_mask |= quota::QuotaClient::kAppcache; | |
222 if (remove_mask & BrowsingDataRemover::REMOVE_INDEXEDDB) | |
223 quota_client_mask |= quota::QuotaClient::kIndexedDatabase; | |
224 | |
225 return quota_client_mask; | |
226 } | |
227 | |
228 void BrowsingDataRemover::Remove(int remove_mask, int origin_set_mask) { | 218 void BrowsingDataRemover::Remove(int remove_mask, int origin_set_mask) { |
229 RemoveImpl(remove_mask, GURL(), origin_set_mask); | 219 RemoveImpl(remove_mask, GURL(), origin_set_mask); |
230 } | 220 } |
231 | 221 |
232 void BrowsingDataRemover::RemoveImpl(int remove_mask, | 222 void BrowsingDataRemover::RemoveImpl(int remove_mask, |
233 const GURL& origin, | 223 const GURL& origin, |
234 int origin_set_mask) { | 224 int origin_set_mask) { |
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
236 set_removing(true); | 226 set_removing(true); |
237 remove_mask_ = remove_mask; | 227 remove_mask_ = remove_mask; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) { | 376 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) { |
387 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); | 377 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); |
388 content::DownloadManager* download_manager = | 378 content::DownloadManager* download_manager = |
389 BrowserContext::GetDownloadManager(profile_); | 379 BrowserContext::GetDownloadManager(profile_); |
390 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); | 380 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); |
391 DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager( | 381 DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager( |
392 download_manager); | 382 download_manager); |
393 download_prefs->SetSaveFilePath(download_prefs->DownloadPath()); | 383 download_prefs->SetSaveFilePath(download_prefs->DownloadPath()); |
394 } | 384 } |
395 | 385 |
| 386 uint32 storage_partition_remove_mask = 0; |
| 387 |
396 // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set, | 388 // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set, |
397 // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB | 389 // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB |
398 // don't accidentally remove the cookies that are associated with the | 390 // don't accidentally remove the cookies that are associated with the |
399 // UNPROTECTED_WEB origin. This is necessary because cookies are not separated | 391 // UNPROTECTED_WEB origin. This is necessary because cookies are not separated |
400 // between UNPROTECTED_WEB and PROTECTED_WEB. | 392 // between UNPROTECTED_WEB and PROTECTED_WEB. |
401 if (remove_mask & REMOVE_COOKIES && | 393 if (remove_mask & REMOVE_COOKIES && |
402 origin_set_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { | 394 origin_set_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { |
403 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); | 395 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); |
404 // Since we are running on the UI thread don't call GetURLRequestContext(). | 396 |
405 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext(); | 397 storage_partition_remove_mask |= |
406 if (rq_context) { | 398 content::StoragePartition::REMOVE_DATA_MASK_COOKIES; |
407 ++waiting_for_clear_cookies_count_; | 399 |
408 BrowserThread::PostTask( | |
409 BrowserThread::IO, FROM_HERE, | |
410 base::Bind(&BrowsingDataRemover::ClearCookiesOnIOThread, | |
411 base::Unretained(this), base::Unretained(rq_context))); | |
412 } | |
413 // Also delete the LoggedIn Predictor, which tries to keep track of which | 400 // Also delete the LoggedIn Predictor, which tries to keep track of which |
414 // sites a user is logged into. | 401 // sites a user is logged into. |
415 ClearLoggedInPredictor(); | 402 ClearLoggedInPredictor(); |
416 | 403 |
417 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) | 404 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) |
418 // Clear the safebrowsing cookies only if time period is for "all time". It | 405 // Clear the safebrowsing cookies only if time period is for "all time". It |
419 // doesn't make sense to apply the time period of deleting in the last X | 406 // doesn't make sense to apply the time period of deleting in the last X |
420 // hours/days to the safebrowsing cookies since they aren't the result of | 407 // hours/days to the safebrowsing cookies since they aren't the result of |
421 // any user action. | 408 // any user action. |
422 if (delete_begin_ == base::Time()) { | 409 if (delete_begin_ == base::Time()) { |
(...skipping 23 matching lines...) Expand all Loading... |
446 if (rq_context) { | 433 if (rq_context) { |
447 waiting_for_clear_server_bound_certs_ = true; | 434 waiting_for_clear_server_bound_certs_ = true; |
448 BrowserThread::PostTask( | 435 BrowserThread::PostTask( |
449 BrowserThread::IO, FROM_HERE, | 436 BrowserThread::IO, FROM_HERE, |
450 base::Bind(&BrowsingDataRemover::ClearServerBoundCertsOnIOThread, | 437 base::Bind(&BrowsingDataRemover::ClearServerBoundCertsOnIOThread, |
451 base::Unretained(this), base::Unretained(rq_context))); | 438 base::Unretained(this), base::Unretained(rq_context))); |
452 } | 439 } |
453 } | 440 } |
454 | 441 |
455 if (remove_mask & REMOVE_LOCAL_STORAGE) { | 442 if (remove_mask & REMOVE_LOCAL_STORAGE) { |
456 waiting_for_clear_local_storage_ = true; | 443 storage_partition_remove_mask |= |
457 waiting_for_clear_session_storage_ = true; | 444 content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; |
458 if (!dom_storage_context_) { | |
459 dom_storage_context_ = | |
460 BrowserContext::GetDefaultStoragePartition(profile_)-> | |
461 GetDOMStorageContext(); | |
462 } | |
463 ClearLocalStorageOnUIThread(); | |
464 ClearSessionStorageOnUIThread(); | |
465 } | 445 } |
466 | 446 |
467 if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL || | 447 if (remove_mask & REMOVE_INDEXEDDB) { |
468 remove_mask & REMOVE_APPCACHE || remove_mask & REMOVE_FILE_SYSTEMS) { | 448 storage_partition_remove_mask |= |
469 if (!quota_manager_) { | 449 content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; |
470 quota_manager_ = | 450 } |
471 BrowserContext::GetDefaultStoragePartition(profile_)-> | 451 if (remove_mask & REMOVE_WEBSQL) { |
472 GetQuotaManager(); | 452 storage_partition_remove_mask |= |
473 } | 453 content::StoragePartition::REMOVE_DATA_MASK_WEBSQL; |
474 waiting_for_clear_quota_managed_data_ = true; | 454 } |
475 BrowserThread::PostTask( | 455 if (remove_mask & REMOVE_APPCACHE) { |
476 BrowserThread::IO, FROM_HERE, | 456 storage_partition_remove_mask |= |
477 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread, | 457 content::StoragePartition::REMOVE_DATA_MASK_APPCACHE; |
478 base::Unretained(this))); | 458 } |
| 459 if (remove_mask & REMOVE_FILE_SYSTEMS) { |
| 460 storage_partition_remove_mask |= |
| 461 content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; |
479 } | 462 } |
480 | 463 |
481 #if defined(ENABLE_PLUGINS) | 464 #if defined(ENABLE_PLUGINS) |
482 // Plugin is data not separated for protected and unprotected web origins. We | 465 // Plugin is data not separated for protected and unprotected web origins. We |
483 // check the origin_set_mask_ to prevent unintended deletion. | 466 // check the origin_set_mask_ to prevent unintended deletion. |
484 if (remove_mask & REMOVE_PLUGIN_DATA && | 467 if (remove_mask & REMOVE_PLUGIN_DATA && |
485 origin_set_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { | 468 origin_set_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { |
486 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); | 469 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); |
487 | 470 |
488 waiting_for_clear_plugin_data_ = true; | 471 waiting_for_clear_plugin_data_ = true; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 // The PrerenderManager may have a page actively being prerendered, which | 547 // The PrerenderManager may have a page actively being prerendered, which |
565 // is essentially a preemptively cached page. | 548 // is essentially a preemptively cached page. |
566 prerender::PrerenderManager* prerender_manager = | 549 prerender::PrerenderManager* prerender_manager = |
567 prerender::PrerenderManagerFactory::GetForProfile(profile_); | 550 prerender::PrerenderManagerFactory::GetForProfile(profile_); |
568 if (prerender_manager) { | 551 if (prerender_manager) { |
569 prerender_manager->ClearData( | 552 prerender_manager->ClearData( |
570 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS); | 553 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS); |
571 } | 554 } |
572 | 555 |
573 // Tell the shader disk cache to clear. | 556 // Tell the shader disk cache to clear. |
574 waiting_for_clear_shader_cache_ = true; | |
575 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); | 557 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); |
| 558 storage_partition_remove_mask |= |
| 559 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; |
576 | 560 |
577 ClearShaderCacheOnUIThread(); | 561 storage_partition_remove_mask |= |
| 562 content::StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY; |
| 563 } |
578 | 564 |
579 waiting_for_clear_webrtc_identity_store_ = true; | 565 if (storage_partition_remove_mask) { |
580 BrowserContext::GetDefaultStoragePartition(profile_)->ClearDataForRange( | 566 waiting_for_clear_storage_partition_data_ = true; |
581 content::StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY, | 567 |
582 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 568 content::StoragePartition* storage_partition; |
| 569 if (storage_partition_for_testing_) |
| 570 storage_partition = storage_partition_for_testing_; |
| 571 else |
| 572 storage_partition = BrowserContext::GetDefaultStoragePartition(profile_); |
| 573 |
| 574 uint32 quota_storage_remove_mask = |
| 575 ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; |
| 576 |
| 577 if (delete_begin_ == base::Time() || |
| 578 origin_set_mask_ & |
| 579 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) { |
| 580 // If we're deleting since the beginning of time, or we're removing |
| 581 // protected origins, then remove persistent quota data. |
| 582 quota_storage_remove_mask |= |
| 583 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; |
| 584 } |
| 585 |
| 586 storage_partition->ClearData( |
| 587 storage_partition_remove_mask, |
| 588 quota_storage_remove_mask, |
| 589 &remove_origin_, |
| 590 base::Bind(&DoesOriginMatchMask, origin_set_mask_), |
583 delete_begin_, | 591 delete_begin_, |
584 delete_end_, | 592 delete_end_, |
585 base::Bind(&BrowsingDataRemover::OnClearWebRTCIdentityStore, | 593 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData, |
586 base::Unretained(this))); | 594 base::Unretained(this))); |
587 } | 595 } |
588 | 596 |
589 #if defined(ENABLE_PLUGINS) | 597 #if defined(ENABLE_PLUGINS) |
590 if (remove_mask & REMOVE_CONTENT_LICENSES) { | 598 if (remove_mask & REMOVE_CONTENT_LICENSES) { |
591 content::RecordAction( | 599 content::RecordAction( |
592 UserMetricsAction("ClearBrowsingData_ContentLicenses")); | 600 UserMetricsAction("ClearBrowsingData_ContentLicenses")); |
593 | 601 |
594 waiting_for_clear_content_licenses_ = true; | 602 waiting_for_clear_content_licenses_ = true; |
595 if (!pepper_flash_settings_manager_.get()) { | 603 if (!pepper_flash_settings_manager_.get()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 | 641 |
634 void BrowsingDataRemover::RemoveObserver(Observer* observer) { | 642 void BrowsingDataRemover::RemoveObserver(Observer* observer) { |
635 observer_list_.RemoveObserver(observer); | 643 observer_list_.RemoveObserver(observer); |
636 } | 644 } |
637 | 645 |
638 void BrowsingDataRemover::OnHistoryDeletionDone() { | 646 void BrowsingDataRemover::OnHistoryDeletionDone() { |
639 waiting_for_clear_history_ = false; | 647 waiting_for_clear_history_ = false; |
640 NotifyAndDeleteIfDone(); | 648 NotifyAndDeleteIfDone(); |
641 } | 649 } |
642 | 650 |
643 void BrowsingDataRemover::OverrideQuotaManagerForTesting( | 651 void BrowsingDataRemover::OverrideStoragePartitionForTesting( |
644 quota::QuotaManager* quota_manager) { | 652 content::StoragePartition* storage_partition) { |
645 quota_manager_ = quota_manager; | 653 storage_partition_for_testing_ = storage_partition; |
646 } | 654 } |
647 | 655 |
648 base::Time BrowsingDataRemover::CalculateBeginDeleteTime( | 656 base::Time BrowsingDataRemover::CalculateBeginDeleteTime( |
649 TimePeriod time_period) { | 657 TimePeriod time_period) { |
650 base::TimeDelta diff; | 658 base::TimeDelta diff; |
651 base::Time delete_begin_time = base::Time::Now(); | 659 base::Time delete_begin_time = base::Time::Now(); |
652 switch (time_period) { | 660 switch (time_period) { |
653 case LAST_HOUR: | 661 case LAST_HOUR: |
654 diff = base::TimeDelta::FromHours(1); | 662 diff = base::TimeDelta::FromHours(1); |
655 break; | 663 break; |
(...skipping 14 matching lines...) Expand all Loading... |
670 break; | 678 break; |
671 } | 679 } |
672 return delete_begin_time - diff; | 680 return delete_begin_time - diff; |
673 } | 681 } |
674 | 682 |
675 bool BrowsingDataRemover::AllDone() { | 683 bool BrowsingDataRemover::AllDone() { |
676 return !waiting_for_clear_keyword_data_ && | 684 return !waiting_for_clear_keyword_data_ && |
677 !waiting_for_clear_autofill_origin_urls_ && | 685 !waiting_for_clear_autofill_origin_urls_ && |
678 !waiting_for_clear_cache_ && !waiting_for_clear_nacl_cache_ && | 686 !waiting_for_clear_cache_ && !waiting_for_clear_nacl_cache_ && |
679 !waiting_for_clear_cookies_count_ && !waiting_for_clear_history_ && | 687 !waiting_for_clear_cookies_count_ && !waiting_for_clear_history_ && |
680 !waiting_for_clear_local_storage_ && | |
681 !waiting_for_clear_logged_in_predictor_ && | 688 !waiting_for_clear_logged_in_predictor_ && |
682 !waiting_for_clear_session_storage_ && | |
683 !waiting_for_clear_networking_history_ && | 689 !waiting_for_clear_networking_history_ && |
684 !waiting_for_clear_server_bound_certs_ && | 690 !waiting_for_clear_server_bound_certs_ && |
685 !waiting_for_clear_plugin_data_ && | 691 !waiting_for_clear_plugin_data_ && |
686 !waiting_for_clear_pnacl_cache_ && | 692 !waiting_for_clear_pnacl_cache_ && |
687 !waiting_for_clear_quota_managed_data_ && | |
688 !waiting_for_clear_content_licenses_ && !waiting_for_clear_form_ && | 693 !waiting_for_clear_content_licenses_ && !waiting_for_clear_form_ && |
689 !waiting_for_clear_hostname_resolution_cache_ && | 694 !waiting_for_clear_hostname_resolution_cache_ && |
690 !waiting_for_clear_network_predictor_ && | 695 !waiting_for_clear_network_predictor_ && |
691 !waiting_for_clear_shader_cache_ && | 696 !waiting_for_clear_platform_keys_ && |
692 !waiting_for_clear_webrtc_identity_store_ && | 697 !waiting_for_clear_storage_partition_data_; |
693 !waiting_for_clear_platform_keys_; | |
694 } | 698 } |
695 | 699 |
696 void BrowsingDataRemover::OnKeywordsLoaded() { | 700 void BrowsingDataRemover::OnKeywordsLoaded() { |
697 // Deletes the entries from the model, and if we're not waiting on anything | 701 // Deletes the entries from the model, and if we're not waiting on anything |
698 // else notifies observers and deletes this BrowsingDataRemover. | 702 // else notifies observers and deletes this BrowsingDataRemover. |
699 TemplateURLService* model = | 703 TemplateURLService* model = |
700 TemplateURLServiceFactory::GetForProfile(profile_); | 704 TemplateURLServiceFactory::GetForProfile(profile_); |
701 DCHECK_EQ(profile_, model->profile()); | 705 DCHECK_EQ(profile_, model->profile()); |
702 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); | 706 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); |
703 waiting_for_clear_keyword_data_ = false; | 707 waiting_for_clear_keyword_data_ = false; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 } | 893 } |
890 default: { | 894 default: { |
891 NOTREACHED() << "bad state"; | 895 NOTREACHED() << "bad state"; |
892 next_cache_state_ = STATE_NONE; // Stop looping. | 896 next_cache_state_ = STATE_NONE; // Stop looping. |
893 return; | 897 return; |
894 } | 898 } |
895 } | 899 } |
896 } | 900 } |
897 } | 901 } |
898 | 902 |
899 void BrowsingDataRemover::ClearedShaderCache() { | |
900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
901 | |
902 waiting_for_clear_shader_cache_ = false; | |
903 NotifyAndDeleteIfDone(); | |
904 } | |
905 | |
906 void BrowsingDataRemover::ClearShaderCacheOnUIThread() { | |
907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
908 | |
909 BrowserContext::GetDefaultStoragePartition(profile_)->ClearDataForRange( | |
910 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, | |
911 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | |
912 delete_begin_, delete_end_, | |
913 base::Bind(&BrowsingDataRemover::ClearedShaderCache, | |
914 base::Unretained(this))); | |
915 } | |
916 | |
917 #if !defined(DISABLE_NACL) | 903 #if !defined(DISABLE_NACL) |
918 void BrowsingDataRemover::ClearedNaClCache() { | 904 void BrowsingDataRemover::ClearedNaClCache() { |
919 // This function should be called on the UI thread. | 905 // This function should be called on the UI thread. |
920 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
921 | 907 |
922 waiting_for_clear_nacl_cache_ = false; | 908 waiting_for_clear_nacl_cache_ = false; |
923 | 909 |
924 NotifyAndDeleteIfDone(); | 910 NotifyAndDeleteIfDone(); |
925 } | 911 } |
926 | 912 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 base::Time end) { | 953 base::Time end) { |
968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 954 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
969 | 955 |
970 PnaclHost::GetInstance()->ClearTranslationCacheEntriesBetween( | 956 PnaclHost::GetInstance()->ClearTranslationCacheEntriesBetween( |
971 begin, end, | 957 begin, end, |
972 base::Bind(&BrowsingDataRemover::ClearedPnaclCacheOnIOThread, | 958 base::Bind(&BrowsingDataRemover::ClearedPnaclCacheOnIOThread, |
973 base::Unretained(this))); | 959 base::Unretained(this))); |
974 } | 960 } |
975 #endif | 961 #endif |
976 | 962 |
977 void BrowsingDataRemover::ClearLocalStorageOnUIThread() { | |
978 DCHECK(waiting_for_clear_local_storage_); | |
979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
980 dom_storage_context_->GetLocalStorageUsage( | |
981 base::Bind(&BrowsingDataRemover::OnGotLocalStorageUsageInfo, | |
982 base::Unretained(this))); | |
983 } | |
984 | |
985 void BrowsingDataRemover::OnGotLocalStorageUsageInfo( | |
986 const std::vector<content::LocalStorageUsageInfo>& infos) { | |
987 DCHECK(waiting_for_clear_local_storage_); | |
988 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
989 | |
990 for (size_t i = 0; i < infos.size(); ++i) { | |
991 if (!BrowsingDataHelper::DoesOriginMatchMask( | |
992 infos[i].origin, origin_set_mask_, special_storage_policy_.get())) | |
993 continue; | |
994 | |
995 if (infos[i].last_modified >= delete_begin_ && | |
996 infos[i].last_modified <= delete_end_) { | |
997 dom_storage_context_->DeleteLocalStorage(infos[i].origin); | |
998 } | |
999 } | |
1000 waiting_for_clear_local_storage_ = false; | |
1001 NotifyAndDeleteIfDone(); | |
1002 } | |
1003 | |
1004 void BrowsingDataRemover::ClearSessionStorageOnUIThread() { | |
1005 DCHECK(waiting_for_clear_session_storage_); | |
1006 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1007 | |
1008 dom_storage_context_->GetSessionStorageUsage( | |
1009 base::Bind(&BrowsingDataRemover::OnGotSessionStorageUsageInfo, | |
1010 base::Unretained(this))); | |
1011 } | |
1012 | |
1013 void BrowsingDataRemover::OnGotSessionStorageUsageInfo( | |
1014 const std::vector<content::SessionStorageUsageInfo>& infos) { | |
1015 DCHECK(waiting_for_clear_session_storage_); | |
1016 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1017 | |
1018 for (size_t i = 0; i < infos.size(); ++i) { | |
1019 if (!BrowsingDataHelper::DoesOriginMatchMask( | |
1020 infos[i].origin, origin_set_mask_, special_storage_policy_.get())) | |
1021 continue; | |
1022 | |
1023 dom_storage_context_->DeleteSessionStorage(infos[i]); | |
1024 } | |
1025 waiting_for_clear_session_storage_ = false; | |
1026 NotifyAndDeleteIfDone(); | |
1027 } | |
1028 | |
1029 void BrowsingDataRemover::ClearQuotaManagedDataOnIOThread() { | |
1030 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
1031 | |
1032 // Ask the QuotaManager for all origins with temporary quota modified within | |
1033 // the user-specified timeframe, and deal with the resulting set in | |
1034 // OnGotQuotaManagedOrigins(). | |
1035 quota_managed_origins_to_delete_count_ = 0; | |
1036 quota_managed_storage_types_to_delete_count_ = 0; | |
1037 | |
1038 if (delete_begin_ == base::Time() || | |
1039 origin_set_mask_ & | |
1040 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) { | |
1041 // If we're deleting since the beginning of time, or we're removing | |
1042 // protected origins, then ask the QuotaManager for all origins with | |
1043 // persistent quota modified within the user-specified timeframe, and deal | |
1044 // with the resulting set in OnGotQuotaManagedOrigins. | |
1045 ++quota_managed_storage_types_to_delete_count_; | |
1046 quota_manager_->GetOriginsModifiedSince( | |
1047 quota::kStorageTypePersistent, delete_begin_, | |
1048 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, | |
1049 base::Unretained(this))); | |
1050 } | |
1051 | |
1052 // Do the same for temporary quota. | |
1053 ++quota_managed_storage_types_to_delete_count_; | |
1054 quota_manager_->GetOriginsModifiedSince( | |
1055 quota::kStorageTypeTemporary, delete_begin_, | |
1056 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, | |
1057 base::Unretained(this))); | |
1058 | |
1059 // Do the same for syncable quota. | |
1060 ++quota_managed_storage_types_to_delete_count_; | |
1061 quota_manager_->GetOriginsModifiedSince( | |
1062 quota::kStorageTypeSyncable, delete_begin_, | |
1063 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, | |
1064 base::Unretained(this))); | |
1065 } | |
1066 | |
1067 void BrowsingDataRemover::OnGotQuotaManagedOrigins( | |
1068 const std::set<GURL>& origins, quota::StorageType type) { | |
1069 DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0); | |
1070 // Walk through the origins passed in, delete quota of |type| from each that | |
1071 // matches the |origin_set_mask_|. | |
1072 std::set<GURL>::const_iterator origin; | |
1073 for (origin = origins.begin(); origin != origins.end(); ++origin) { | |
1074 // TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746 | |
1075 if (!remove_origin_.is_empty() && remove_origin_ != origin->GetOrigin()) | |
1076 continue; | |
1077 | |
1078 if (!BrowsingDataHelper::DoesOriginMatchMask(origin->GetOrigin(), | |
1079 origin_set_mask_, | |
1080 special_storage_policy_.get())) | |
1081 continue; | |
1082 | |
1083 ++quota_managed_origins_to_delete_count_; | |
1084 quota_manager_->DeleteOriginData( | |
1085 origin->GetOrigin(), type, | |
1086 BrowsingDataRemover::GenerateQuotaClientMask(remove_mask_), | |
1087 base::Bind(&BrowsingDataRemover::OnQuotaManagedOriginDeletion, | |
1088 base::Unretained(this), origin->GetOrigin(), type)); | |
1089 } | |
1090 | |
1091 --quota_managed_storage_types_to_delete_count_; | |
1092 CheckQuotaManagedDataDeletionStatus(); | |
1093 } | |
1094 | |
1095 void BrowsingDataRemover::OnQuotaManagedOriginDeletion( | |
1096 const GURL& origin, | |
1097 quota::StorageType type, | |
1098 quota::QuotaStatusCode status) { | |
1099 DCHECK_GT(quota_managed_origins_to_delete_count_, 0); | |
1100 if (status != quota::kQuotaStatusOk) { | |
1101 DLOG(ERROR) << "Couldn't remove data of type " << type << " for origin " | |
1102 << origin << ". Status: " << status; | |
1103 } | |
1104 | |
1105 --quota_managed_origins_to_delete_count_; | |
1106 CheckQuotaManagedDataDeletionStatus(); | |
1107 } | |
1108 | |
1109 void BrowsingDataRemover::CheckQuotaManagedDataDeletionStatus() { | |
1110 if (quota_managed_storage_types_to_delete_count_ != 0 || | |
1111 quota_managed_origins_to_delete_count_ != 0) { | |
1112 return; | |
1113 } | |
1114 | |
1115 BrowserThread::PostTask( | |
1116 BrowserThread::UI, FROM_HERE, | |
1117 base::Bind(&BrowsingDataRemover::OnQuotaManagedDataDeleted, | |
1118 base::Unretained(this))); | |
1119 } | |
1120 | |
1121 void BrowsingDataRemover::OnQuotaManagedDataDeleted() { | |
1122 DCHECK(waiting_for_clear_quota_managed_data_); | |
1123 waiting_for_clear_quota_managed_data_ = false; | |
1124 NotifyAndDeleteIfDone(); | |
1125 } | |
1126 | |
1127 void BrowsingDataRemover::OnWaitableEventSignaled( | 963 void BrowsingDataRemover::OnWaitableEventSignaled( |
1128 base::WaitableEvent* waitable_event) { | 964 base::WaitableEvent* waitable_event) { |
1129 waiting_for_clear_plugin_data_ = false; | 965 waiting_for_clear_plugin_data_ = false; |
1130 NotifyAndDeleteIfDone(); | 966 NotifyAndDeleteIfDone(); |
1131 } | 967 } |
1132 | 968 |
1133 #if defined(ENABLE_PLUGINS) | 969 #if defined(ENABLE_PLUGINS) |
1134 void BrowsingDataRemover::OnDeauthorizeContentLicensesCompleted( | 970 void BrowsingDataRemover::OnDeauthorizeContentLicensesCompleted( |
1135 uint32 request_id, | 971 uint32 request_id, |
1136 bool /* success */) { | 972 bool /* success */) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 waiting_for_clear_form_ = false; | 1052 waiting_for_clear_form_ = false; |
1217 NotifyAndDeleteIfDone(); | 1053 NotifyAndDeleteIfDone(); |
1218 } | 1054 } |
1219 | 1055 |
1220 void BrowsingDataRemover::OnClearedAutofillOriginURLs() { | 1056 void BrowsingDataRemover::OnClearedAutofillOriginURLs() { |
1221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1222 waiting_for_clear_autofill_origin_urls_ = false; | 1058 waiting_for_clear_autofill_origin_urls_ = false; |
1223 NotifyAndDeleteIfDone(); | 1059 NotifyAndDeleteIfDone(); |
1224 } | 1060 } |
1225 | 1061 |
1226 void BrowsingDataRemover::OnClearWebRTCIdentityStore() { | 1062 void BrowsingDataRemover::OnClearedStoragePartitionData() { |
1227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1063 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1228 waiting_for_clear_webrtc_identity_store_ = false; | 1064 waiting_for_clear_storage_partition_data_ = false; |
1229 NotifyAndDeleteIfDone(); | 1065 NotifyAndDeleteIfDone(); |
1230 } | 1066 } |
OLD | NEW |