| OLD | NEW |
| 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/bind.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "chrome/browser/sessions/tab_restore_service.h" | 38 #include "chrome/browser/sessions/tab_restore_service.h" |
| 39 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 39 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 40 #include "chrome/browser/webdata/web_data_service.h" | 40 #include "chrome/browser/webdata/web_data_service.h" |
| 41 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
| 42 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
| 44 #include "content/browser/download/download_manager.h" | 44 #include "content/browser/download/download_manager.h" |
| 45 #include "content/browser/in_process_webkit/webkit_context.h" | 45 #include "content/browser/in_process_webkit/webkit_context.h" |
| 46 #include "content/browser/user_metrics.h" | 46 #include "content/browser/user_metrics.h" |
| 47 #include "content/public/browser/browser_thread.h" | 47 #include "content/public/browser/browser_thread.h" |
| 48 #include "content/public/browser/notification_source.h" | 48 #include "content/public/browser/notification_service.h" |
| 49 #include "content/public/browser/plugin_data_remover.h" | 49 #include "content/public/browser/plugin_data_remover.h" |
| 50 #include "net/base/cookie_monster.h" | 50 #include "net/base/cookie_monster.h" |
| 51 #include "net/base/net_errors.h" | 51 #include "net/base/net_errors.h" |
| 52 #include "net/base/transport_security_state.h" | 52 #include "net/base/transport_security_state.h" |
| 53 #include "net/disk_cache/disk_cache.h" | 53 #include "net/disk_cache/disk_cache.h" |
| 54 #include "net/http/http_cache.h" | 54 #include "net/http/http_cache.h" |
| 55 #include "net/url_request/url_request_context.h" | 55 #include "net/url_request/url_request_context.h" |
| 56 #include "net/url_request/url_request_context_getter.h" | 56 #include "net/url_request/url_request_context_getter.h" |
| 57 #include "webkit/quota/quota_manager.h" | 57 #include "webkit/quota/quota_manager.h" |
| 58 #include "webkit/quota/quota_types.h" | 58 #include "webkit/quota/quota_types.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 77 this, &BrowsingDataRemover::DoClearCache)), | 77 this, &BrowsingDataRemover::DoClearCache)), |
| 78 next_cache_state_(STATE_NONE), | 78 next_cache_state_(STATE_NONE), |
| 79 cache_(NULL), | 79 cache_(NULL), |
| 80 main_context_getter_(profile->GetRequestContext()), | 80 main_context_getter_(profile->GetRequestContext()), |
| 81 media_context_getter_(profile->GetRequestContextForMedia()), | 81 media_context_getter_(profile->GetRequestContextForMedia()), |
| 82 waiting_for_clear_history_(false), | 82 waiting_for_clear_history_(false), |
| 83 waiting_for_clear_quota_managed_data_(false), | 83 waiting_for_clear_quota_managed_data_(false), |
| 84 waiting_for_clear_networking_history_(false), | 84 waiting_for_clear_networking_history_(false), |
| 85 waiting_for_clear_cookies_(false), | 85 waiting_for_clear_cookies_(false), |
| 86 waiting_for_clear_cache_(false), | 86 waiting_for_clear_cache_(false), |
| 87 waiting_for_clear_lso_data_(false) { | 87 waiting_for_clear_lso_data_(false), |
| 88 remove_mask_(0) { |
| 88 DCHECK(profile); | 89 DCHECK(profile); |
| 89 } | 90 } |
| 90 | 91 |
| 91 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | 92 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
| 92 TimePeriod time_period, | 93 TimePeriod time_period, |
| 93 base::Time delete_end) | 94 base::Time delete_end) |
| 94 : profile_(profile), | 95 : profile_(profile), |
| 95 quota_manager_(NULL), | 96 quota_manager_(NULL), |
| 96 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | 97 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
| 97 delete_begin_(CalculateBeginDeleteTime(time_period)), | 98 delete_begin_(CalculateBeginDeleteTime(time_period)), |
| 98 delete_end_(delete_end), | 99 delete_end_(delete_end), |
| 99 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( | 100 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( |
| 100 this, &BrowsingDataRemover::DoClearCache)), | 101 this, &BrowsingDataRemover::DoClearCache)), |
| 101 next_cache_state_(STATE_NONE), | 102 next_cache_state_(STATE_NONE), |
| 102 cache_(NULL), | 103 cache_(NULL), |
| 103 main_context_getter_(profile->GetRequestContext()), | 104 main_context_getter_(profile->GetRequestContext()), |
| 104 media_context_getter_(profile->GetRequestContextForMedia()), | 105 media_context_getter_(profile->GetRequestContextForMedia()), |
| 105 waiting_for_clear_history_(false), | 106 waiting_for_clear_history_(false), |
| 106 waiting_for_clear_quota_managed_data_(false), | 107 waiting_for_clear_quota_managed_data_(false), |
| 107 waiting_for_clear_networking_history_(false), | 108 waiting_for_clear_networking_history_(false), |
| 108 waiting_for_clear_cookies_(false), | 109 waiting_for_clear_cookies_(false), |
| 109 waiting_for_clear_cache_(false), | 110 waiting_for_clear_cache_(false), |
| 110 waiting_for_clear_lso_data_(false) { | 111 waiting_for_clear_lso_data_(false), |
| 112 remove_mask_(0) { |
| 111 DCHECK(profile); | 113 DCHECK(profile); |
| 112 } | 114 } |
| 113 | 115 |
| 114 BrowsingDataRemover::~BrowsingDataRemover() { | 116 BrowsingDataRemover::~BrowsingDataRemover() { |
| 115 DCHECK(all_done()); | 117 DCHECK(all_done()); |
| 116 } | 118 } |
| 117 | 119 |
| 118 // Static. | 120 // Static. |
| 119 void BrowsingDataRemover::set_removing(bool removing) { | 121 void BrowsingDataRemover::set_removing(bool removing) { |
| 120 DCHECK(removing_ != removing); | 122 DCHECK(removing_ != removing); |
| 121 removing_ = removing; | 123 removing_ = removing; |
| 122 } | 124 } |
| 123 | 125 |
| 124 void BrowsingDataRemover::Remove(int remove_mask) { | 126 void BrowsingDataRemover::Remove(int remove_mask) { |
| 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 126 set_removing(true); | 128 set_removing(true); |
| 129 remove_mask_ = remove_mask; |
| 127 | 130 |
| 128 if (remove_mask & REMOVE_HISTORY) { | 131 if (remove_mask & REMOVE_HISTORY) { |
| 129 HistoryService* history_service = | 132 HistoryService* history_service = |
| 130 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 133 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 131 if (history_service) { | 134 if (history_service) { |
| 132 std::set<GURL> restrict_urls; | 135 std::set<GURL> restrict_urls; |
| 133 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); | 136 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
| 134 waiting_for_clear_history_ = true; | 137 waiting_for_clear_history_ = true; |
| 135 history_service->ExpireHistoryBetween(restrict_urls, | 138 history_service->ExpireHistoryBetween(restrict_urls, |
| 136 delete_begin_, delete_end_, | 139 delete_begin_, delete_end_, |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 return; | 366 return; |
| 364 | 367 |
| 365 // The NetLog contains download history, but may also contain form data, | 368 // The NetLog contains download history, but may also contain form data, |
| 366 // cookies and passwords. Simplest just to always clear it. Must be cleared | 369 // cookies and passwords. Simplest just to always clear it. Must be cleared |
| 367 // after the cache, as cleaning up the disk cache exposes some of the history | 370 // after the cache, as cleaning up the disk cache exposes some of the history |
| 368 // in the NetLog. | 371 // in the NetLog. |
| 369 if (g_browser_process->net_log()) | 372 if (g_browser_process->net_log()) |
| 370 g_browser_process->net_log()->ClearAllPassivelyCapturedEvents(); | 373 g_browser_process->net_log()->ClearAllPassivelyCapturedEvents(); |
| 371 | 374 |
| 372 set_removing(false); | 375 set_removing(false); |
| 376 |
| 377 // Send global notification, then notify any explicit observers. |
| 378 BrowsingDataRemoverNotificationDetail details(delete_begin_, remove_mask_); |
| 379 content::NotificationService::current()->Notify( |
| 380 chrome::NOTIFICATION_BROWSING_DATA_REMOVED, |
| 381 content::Source<Profile>(profile_->GetOriginalProfile()), |
| 382 content::Details<BrowsingDataRemoverNotificationDetail>(&details)); |
| 383 |
| 373 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); | 384 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); |
| 374 | 385 |
| 375 // History requests aren't happy if you delete yourself from the callback. | 386 // History requests aren't happy if you delete yourself from the callback. |
| 376 // As such, we do a delete later. | 387 // As such, we do a delete later. |
| 377 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 388 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 378 } | 389 } |
| 379 | 390 |
| 380 void BrowsingDataRemover::ClearedNetworkHistory() { | 391 void BrowsingDataRemover::ClearedNetworkHistory() { |
| 381 waiting_for_clear_networking_history_ = false; | 392 waiting_for_clear_networking_history_ = false; |
| 382 | 393 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 GetURLRequestContext()->cookie_store()->GetCookieMonster(); | 597 GetURLRequestContext()->cookie_store()->GetCookieMonster(); |
| 587 if (cookie_monster) { | 598 if (cookie_monster) { |
| 588 cookie_monster->DeleteAllCreatedBetweenAsync( | 599 cookie_monster->DeleteAllCreatedBetweenAsync( |
| 589 delete_begin_, delete_end_, | 600 delete_begin_, delete_end_, |
| 590 base::Bind(&BrowsingDataRemover::OnClearedCookies, | 601 base::Bind(&BrowsingDataRemover::OnClearedCookies, |
| 591 base::Unretained(this))); | 602 base::Unretained(this))); |
| 592 } else { | 603 } else { |
| 593 OnClearedCookies(0); | 604 OnClearedCookies(0); |
| 594 } | 605 } |
| 595 } | 606 } |
| OLD | NEW |