| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 dom_storage_context_(NULL), | 129 dom_storage_context_(NULL), |
| 130 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | 130 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
| 131 delete_begin_(delete_begin), | 131 delete_begin_(delete_begin), |
| 132 delete_end_(delete_end), | 132 delete_end_(delete_end), |
| 133 next_cache_state_(STATE_NONE), | 133 next_cache_state_(STATE_NONE), |
| 134 cache_(NULL), | 134 cache_(NULL), |
| 135 main_context_getter_(profile->GetRequestContext()), | 135 main_context_getter_(profile->GetRequestContext()), |
| 136 media_context_getter_(profile->GetMediaRequestContext()), | 136 media_context_getter_(profile->GetMediaRequestContext()), |
| 137 deauthorize_content_licenses_request_id_(0), | 137 deauthorize_content_licenses_request_id_(0), |
| 138 waiting_for_clear_cache_(false), | 138 waiting_for_clear_cache_(false), |
| 139 waiting_for_clear_content_licenses_(false), |
| 140 waiting_for_clear_cookies_count_(0), |
| 141 waiting_for_clear_form_(false), |
| 142 waiting_for_clear_history_(false), |
| 143 waiting_for_clear_hostname_resolution_cache_(false), |
| 144 waiting_for_clear_local_storage_(false), |
| 139 waiting_for_clear_nacl_cache_(false), | 145 waiting_for_clear_nacl_cache_(false), |
| 140 waiting_for_clear_cookies_count_(0), | 146 waiting_for_clear_network_predictor_(false), |
| 141 waiting_for_clear_history_(false), | |
| 142 waiting_for_clear_local_storage_(false), | |
| 143 waiting_for_clear_session_storage_(false), | |
| 144 waiting_for_clear_networking_history_(false), | 147 waiting_for_clear_networking_history_(false), |
| 145 waiting_for_clear_server_bound_certs_(false), | |
| 146 waiting_for_clear_plugin_data_(false), | 148 waiting_for_clear_plugin_data_(false), |
| 147 waiting_for_clear_quota_managed_data_(false), | 149 waiting_for_clear_quota_managed_data_(false), |
| 148 waiting_for_clear_content_licenses_(false), | 150 waiting_for_clear_server_bound_certs_(false), |
| 149 waiting_for_clear_form_(false), | 151 waiting_for_clear_session_storage_(false), |
| 150 remove_mask_(0), | 152 remove_mask_(0), |
| 151 remove_origin_(GURL()), | 153 remove_origin_(GURL()), |
| 152 origin_set_mask_(0) { | 154 origin_set_mask_(0) { |
| 153 DCHECK(profile); | 155 DCHECK(profile); |
| 154 // crbug.com/140910: Many places were calling this with base::Time() as | 156 // crbug.com/140910: Many places were calling this with base::Time() as |
| 155 // delete_end, even though they should've used base::Time::Max(). Work around | 157 // delete_end, even though they should've used base::Time::Max(). Work around |
| 156 // it here. New code should use base::Time::Max(). | 158 // it here. New code should use base::Time::Max(). |
| 157 DCHECK(delete_end_ != base::Time()); | 159 DCHECK(delete_end_ != base::Time()); |
| 158 if (delete_end_ == base::Time()) | 160 if (delete_end_ == base::Time()) |
| 159 delete_end_ = base::Time::Max(); | 161 delete_end_ = base::Time::Max(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 delete_begin_, history_end_, | 243 delete_begin_, history_end_, |
| 242 &request_consumer_, | 244 &request_consumer_, |
| 243 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, | 245 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, |
| 244 base::Unretained(this))); | 246 base::Unretained(this))); |
| 245 } | 247 } |
| 246 | 248 |
| 247 // Need to clear the host cache and accumulated speculative data, as it also | 249 // Need to clear the host cache and accumulated speculative data, as it also |
| 248 // reveals some history: we have no mechanism to track when these items were | 250 // reveals some history: we have no mechanism to track when these items were |
| 249 // created, so we'll clear them all. Better safe than sorry. | 251 // created, so we'll clear them all. Better safe than sorry. |
| 250 if (g_browser_process->io_thread()) { | 252 if (g_browser_process->io_thread()) { |
| 251 waiting_for_clear_networking_history_ = true; | 253 waiting_for_clear_hostname_resolution_cache_ = true; |
| 252 BrowserThread::PostTask( | 254 BrowserThread::PostTask( |
| 253 BrowserThread::IO, FROM_HERE, | 255 BrowserThread::IO, FROM_HERE, |
| 254 base::Bind(&BrowsingDataRemover::ClearNetworkingHistory, | 256 base::Bind( |
| 255 base::Unretained(this), g_browser_process->io_thread())); | 257 &BrowsingDataRemover::ClearHostnameResolutionCacheOnIOThread, |
| 258 base::Unretained(this), |
| 259 g_browser_process->io_thread())); |
| 260 } |
| 261 if (profile_->GetNetworkPredictor()) { |
| 262 waiting_for_clear_network_predictor_ = true; |
| 263 BrowserThread::PostTask( |
| 264 BrowserThread::IO, FROM_HERE, |
| 265 base::Bind(&BrowsingDataRemover::ClearNetworkPredictorOnIOThread, |
| 266 base::Unretained(this))); |
| 256 } | 267 } |
| 257 | 268 |
| 258 // As part of history deletion we also delete the auto-generated keywords. | 269 // As part of history deletion we also delete the auto-generated keywords. |
| 259 TemplateURLService* keywords_model = | 270 TemplateURLService* keywords_model = |
| 260 TemplateURLServiceFactory::GetForProfile(profile_); | 271 TemplateURLServiceFactory::GetForProfile(profile_); |
| 261 if (keywords_model && !keywords_model->loaded()) { | 272 if (keywords_model && !keywords_model->loaded()) { |
| 262 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 273 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 263 content::Source<TemplateURLService>(keywords_model)); | 274 content::Source<TemplateURLService>(keywords_model)); |
| 264 keywords_model->Load(); | 275 keywords_model->Load(); |
| 265 } else if (keywords_model) { | 276 } else if (keywords_model) { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 | 494 |
| 484 waiting_for_clear_content_licenses_ = true; | 495 waiting_for_clear_content_licenses_ = true; |
| 485 if (!pepper_flash_settings_manager_.get()) { | 496 if (!pepper_flash_settings_manager_.get()) { |
| 486 pepper_flash_settings_manager_.reset( | 497 pepper_flash_settings_manager_.reset( |
| 487 new PepperFlashSettingsManager(this, profile_)); | 498 new PepperFlashSettingsManager(this, profile_)); |
| 488 } | 499 } |
| 489 deauthorize_content_licenses_request_id_ = | 500 deauthorize_content_licenses_request_id_ = |
| 490 pepper_flash_settings_manager_->DeauthorizeContentLicenses(); | 501 pepper_flash_settings_manager_->DeauthorizeContentLicenses(); |
| 491 } | 502 } |
| 492 | 503 |
| 493 // Also delete cached network related data (like TransportSecurityState, | 504 // Always wipe accumulated network related data (TransportSecurityState and |
| 494 // HttpServerProperties data). | 505 // HttpServerPropertiesManager data). |
| 495 profile_->ClearNetworkingHistorySince(delete_begin_); | 506 waiting_for_clear_networking_history_ = true; |
| 496 | 507 profile_->ClearNetworkingHistorySince( |
| 497 NotifyAndDeleteIfDone(); | 508 delete_begin_, |
| 509 base::Bind(&BrowsingDataRemover::OnClearedNetworkingHistory, |
| 510 base::Unretained(this))); |
| 498 } | 511 } |
| 499 | 512 |
| 500 void BrowsingDataRemover::AddObserver(Observer* observer) { | 513 void BrowsingDataRemover::AddObserver(Observer* observer) { |
| 501 observer_list_.AddObserver(observer); | 514 observer_list_.AddObserver(observer); |
| 502 } | 515 } |
| 503 | 516 |
| 504 void BrowsingDataRemover::RemoveObserver(Observer* observer) { | 517 void BrowsingDataRemover::RemoveObserver(Observer* observer) { |
| 505 observer_list_.RemoveObserver(observer); | 518 observer_list_.RemoveObserver(observer); |
| 506 } | 519 } |
| 507 | 520 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 !waiting_for_clear_nacl_cache_ && | 561 !waiting_for_clear_nacl_cache_ && |
| 549 !waiting_for_clear_cookies_count_&& | 562 !waiting_for_clear_cookies_count_&& |
| 550 !waiting_for_clear_history_ && | 563 !waiting_for_clear_history_ && |
| 551 !waiting_for_clear_local_storage_ && | 564 !waiting_for_clear_local_storage_ && |
| 552 !waiting_for_clear_session_storage_ && | 565 !waiting_for_clear_session_storage_ && |
| 553 !waiting_for_clear_networking_history_ && | 566 !waiting_for_clear_networking_history_ && |
| 554 !waiting_for_clear_server_bound_certs_ && | 567 !waiting_for_clear_server_bound_certs_ && |
| 555 !waiting_for_clear_plugin_data_ && | 568 !waiting_for_clear_plugin_data_ && |
| 556 !waiting_for_clear_quota_managed_data_ && | 569 !waiting_for_clear_quota_managed_data_ && |
| 557 !waiting_for_clear_content_licenses_ && | 570 !waiting_for_clear_content_licenses_ && |
| 558 !waiting_for_clear_form_; | 571 !waiting_for_clear_form_ && |
| 572 !waiting_for_clear_hostname_resolution_cache_ && |
| 573 !waiting_for_clear_network_predictor_; |
| 559 } | 574 } |
| 560 | 575 |
| 561 void BrowsingDataRemover::Observe(int type, | 576 void BrowsingDataRemover::Observe(int type, |
| 562 const content::NotificationSource& source, | 577 const content::NotificationSource& source, |
| 563 const content::NotificationDetails& details) { | 578 const content::NotificationDetails& details) { |
| 564 // TODO(brettw) bug 1139736: This should also observe session | 579 // TODO(brettw) bug 1139736: This should also observe session |
| 565 // clearing (what about other things such as passwords, etc.?) and wait for | 580 // clearing (what about other things such as passwords, etc.?) and wait for |
| 566 // them to complete before continuing. | 581 // them to complete before continuing. |
| 567 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); | 582 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); |
| 568 TemplateURLService* model = content::Source<TemplateURLService>(source).ptr(); | 583 TemplateURLService* model = content::Source<TemplateURLService>(source).ptr(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 588 content::Source<Profile>(profile_), | 603 content::Source<Profile>(profile_), |
| 589 content::Details<BrowsingDataRemover::NotificationDetails>(&details)); | 604 content::Details<BrowsingDataRemover::NotificationDetails>(&details)); |
| 590 | 605 |
| 591 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); | 606 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); |
| 592 | 607 |
| 593 // History requests aren't happy if you delete yourself from the callback. | 608 // History requests aren't happy if you delete yourself from the callback. |
| 594 // As such, we do a delete later. | 609 // As such, we do a delete later. |
| 595 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 610 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 596 } | 611 } |
| 597 | 612 |
| 598 void BrowsingDataRemover::ClearedNetworkHistory() { | 613 void BrowsingDataRemover::OnClearedHostnameResolutionCache() { |
| 599 waiting_for_clear_networking_history_ = false; | 614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 600 | 615 waiting_for_clear_hostname_resolution_cache_ = false; |
| 601 NotifyAndDeleteIfDone(); | 616 NotifyAndDeleteIfDone(); |
| 602 } | 617 } |
| 603 | 618 |
| 604 void BrowsingDataRemover::ClearNetworkingHistory(IOThread* io_thread) { | 619 void BrowsingDataRemover::ClearHostnameResolutionCacheOnIOThread( |
| 605 // This function should be called on the IO thread. | 620 IOThread* io_thread) { |
| 606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 607 | 622 |
| 608 io_thread->ClearHostCache(); | 623 io_thread->ClearHostCache(); |
| 609 | 624 |
| 625 // Notify the UI thread that we are done. |
| 626 BrowserThread::PostTask( |
| 627 BrowserThread::UI, |
| 628 FROM_HERE, |
| 629 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache, |
| 630 base::Unretained(this))); |
| 631 } |
| 632 |
| 633 void BrowsingDataRemover::OnClearedNetworkPredictor() { |
| 634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 635 waiting_for_clear_network_predictor_ = false; |
| 636 NotifyAndDeleteIfDone(); |
| 637 } |
| 638 |
| 639 void BrowsingDataRemover::ClearNetworkPredictorOnIOThread() { |
| 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 641 |
| 610 chrome_browser_net::Predictor* predictor = profile_->GetNetworkPredictor(); | 642 chrome_browser_net::Predictor* predictor = profile_->GetNetworkPredictor(); |
| 611 if (predictor) { | 643 if (predictor) { |
| 612 predictor->DiscardInitialNavigationHistory(); | 644 predictor->DiscardInitialNavigationHistory(); |
| 613 predictor->DiscardAllResults(); | 645 predictor->DiscardAllResults(); |
| 614 } | 646 } |
| 615 | 647 |
| 616 // Notify the UI thread that we are done. | 648 // Notify the UI thread that we are done. |
| 617 BrowserThread::PostTask( | 649 BrowserThread::PostTask( |
| 618 BrowserThread::UI, FROM_HERE, | 650 BrowserThread::UI, |
| 619 base::Bind(&BrowsingDataRemover::ClearedNetworkHistory, | 651 FROM_HERE, |
| 652 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor, |
| 620 base::Unretained(this))); | 653 base::Unretained(this))); |
| 621 } | 654 } |
| 622 | 655 |
| 656 void BrowsingDataRemover::OnClearedNetworkingHistory() { |
| 657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 658 waiting_for_clear_networking_history_ = false; |
| 659 NotifyAndDeleteIfDone(); |
| 660 } |
| 661 |
| 623 void BrowsingDataRemover::ClearedCache() { | 662 void BrowsingDataRemover::ClearedCache() { |
| 624 waiting_for_clear_cache_ = false; | 663 waiting_for_clear_cache_ = false; |
| 625 | 664 |
| 626 NotifyAndDeleteIfDone(); | 665 NotifyAndDeleteIfDone(); |
| 627 } | 666 } |
| 628 | 667 |
| 629 void BrowsingDataRemover::ClearCacheOnIOThread() { | 668 void BrowsingDataRemover::ClearCacheOnIOThread() { |
| 630 // This function should be called on the IO thread. | 669 // This function should be called on the IO thread. |
| 631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 670 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 632 DCHECK_EQ(STATE_NONE, next_cache_state_); | 671 DCHECK_EQ(STATE_NONE, next_cache_state_); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 BrowserThread::UI, FROM_HERE, | 1006 BrowserThread::UI, FROM_HERE, |
| 968 base::Bind(&BrowsingDataRemover::OnClearedFormData, | 1007 base::Bind(&BrowsingDataRemover::OnClearedFormData, |
| 969 base::Unretained(this))); | 1008 base::Unretained(this))); |
| 970 } | 1009 } |
| 971 | 1010 |
| 972 void BrowsingDataRemover::OnClearedFormData() { | 1011 void BrowsingDataRemover::OnClearedFormData() { |
| 973 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1012 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 974 waiting_for_clear_form_ = false; | 1013 waiting_for_clear_form_ = false; |
| 975 NotifyAndDeleteIfDone(); | 1014 NotifyAndDeleteIfDone(); |
| 976 } | 1015 } |
| OLD | NEW |