| 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/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
| 14 #include "chrome/browser/autofill/personal_data_manager.h" | 15 #include "chrome/browser/autofill/personal_data_manager.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/download/download_manager.h" | 17 #include "chrome/browser/download/download_manager.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 19 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 19 #include "chrome/browser/history/history.h" | 20 #include "chrome/browser/history/history.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 delete_end_(delete_end), | 65 delete_end_(delete_end), |
| 65 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( | 66 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( |
| 66 this, &BrowsingDataRemover::DoClearCache)), | 67 this, &BrowsingDataRemover::DoClearCache)), |
| 67 next_cache_state_(STATE_NONE), | 68 next_cache_state_(STATE_NONE), |
| 68 cache_(NULL), | 69 cache_(NULL), |
| 69 main_context_getter_(profile->GetRequestContext()), | 70 main_context_getter_(profile->GetRequestContext()), |
| 70 media_context_getter_(profile->GetRequestContextForMedia()), | 71 media_context_getter_(profile->GetRequestContextForMedia()), |
| 71 waiting_for_clear_history_(false), | 72 waiting_for_clear_history_(false), |
| 72 waiting_for_clear_quota_managed_data_(false), | 73 waiting_for_clear_quota_managed_data_(false), |
| 73 waiting_for_clear_networking_history_(false), | 74 waiting_for_clear_networking_history_(false), |
| 75 waiting_for_clear_cookies_(false), |
| 74 waiting_for_clear_cache_(false), | 76 waiting_for_clear_cache_(false), |
| 75 waiting_for_clear_lso_data_(false) { | 77 waiting_for_clear_lso_data_(false) { |
| 76 DCHECK(profile); | 78 DCHECK(profile); |
| 77 } | 79 } |
| 78 | 80 |
| 79 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | 81 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
| 80 TimePeriod time_period, | 82 TimePeriod time_period, |
| 81 base::Time delete_end) | 83 base::Time delete_end) |
| 82 : profile_(profile), | 84 : profile_(profile), |
| 83 quota_manager_(NULL), | 85 quota_manager_(NULL), |
| 84 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | 86 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
| 85 delete_begin_(CalculateBeginDeleteTime(time_period)), | 87 delete_begin_(CalculateBeginDeleteTime(time_period)), |
| 86 delete_end_(delete_end), | 88 delete_end_(delete_end), |
| 87 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( | 89 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( |
| 88 this, &BrowsingDataRemover::DoClearCache)), | 90 this, &BrowsingDataRemover::DoClearCache)), |
| 89 next_cache_state_(STATE_NONE), | 91 next_cache_state_(STATE_NONE), |
| 90 cache_(NULL), | 92 cache_(NULL), |
| 91 main_context_getter_(profile->GetRequestContext()), | 93 main_context_getter_(profile->GetRequestContext()), |
| 92 media_context_getter_(profile->GetRequestContextForMedia()), | 94 media_context_getter_(profile->GetRequestContextForMedia()), |
| 93 waiting_for_clear_history_(false), | 95 waiting_for_clear_history_(false), |
| 94 waiting_for_clear_quota_managed_data_(false), | 96 waiting_for_clear_quota_managed_data_(false), |
| 95 waiting_for_clear_networking_history_(false), | 97 waiting_for_clear_networking_history_(false), |
| 98 waiting_for_clear_cookies_(false), |
| 96 waiting_for_clear_cache_(false), | 99 waiting_for_clear_cache_(false), |
| 97 waiting_for_clear_lso_data_(false) { | 100 waiting_for_clear_lso_data_(false) { |
| 98 DCHECK(profile); | 101 DCHECK(profile); |
| 99 } | 102 } |
| 100 | 103 |
| 101 BrowsingDataRemover::~BrowsingDataRemover() { | 104 BrowsingDataRemover::~BrowsingDataRemover() { |
| 102 DCHECK(all_done()); | 105 DCHECK(all_done()); |
| 103 } | 106 } |
| 104 | 107 |
| 105 void BrowsingDataRemover::Remove(int remove_mask) { | 108 void BrowsingDataRemover::Remove(int remove_mask) { |
| 106 DCHECK(!removing_); | 109 DCHECK(!removing_); |
| 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 107 removing_ = true; | 111 removing_ = true; |
| 108 | 112 |
| 109 if (remove_mask & REMOVE_HISTORY) { | 113 if (remove_mask & REMOVE_HISTORY) { |
| 110 HistoryService* history_service = | 114 HistoryService* history_service = |
| 111 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 115 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 112 if (history_service) { | 116 if (history_service) { |
| 113 std::set<GURL> restrict_urls; | 117 std::set<GURL> restrict_urls; |
| 114 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); | 118 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
| 115 waiting_for_clear_history_ = true; | 119 waiting_for_clear_history_ = true; |
| 116 history_service->ExpireHistoryBetween(restrict_urls, | 120 history_service->ExpireHistoryBetween(restrict_urls, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 if (remove_mask & REMOVE_DOWNLOADS) { | 176 if (remove_mask & REMOVE_DOWNLOADS) { |
| 173 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); | 177 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); |
| 174 DownloadManager* download_manager = profile_->GetDownloadManager(); | 178 DownloadManager* download_manager = profile_->GetDownloadManager(); |
| 175 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); | 179 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); |
| 176 download_manager->ClearLastDownloadPath(); | 180 download_manager->ClearLastDownloadPath(); |
| 177 } | 181 } |
| 178 | 182 |
| 179 if (remove_mask & REMOVE_COOKIES) { | 183 if (remove_mask & REMOVE_COOKIES) { |
| 180 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); | 184 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); |
| 181 // Since we are running on the UI thread don't call GetURLRequestContext(). | 185 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 182 net::CookieMonster* cookie_monster = NULL; | |
| 183 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext(); | 186 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext(); |
| 184 if (rq_context) { | 187 if (rq_context) { |
| 185 cookie_monster = rq_context->DONTUSEME_GetCookieStore()-> | 188 waiting_for_clear_cookies_ = true; |
| 186 GetCookieMonster(); | 189 BrowserThread::PostTask( |
| 190 BrowserThread::IO, FROM_HERE, |
| 191 base::Bind(&BrowsingDataRemover::ClearCookiesOnIOThread, |
| 192 base::Unretained(this), base::Unretained(rq_context))); |
| 187 } | 193 } |
| 188 if (cookie_monster) | |
| 189 cookie_monster->DeleteAllCreatedBetween(delete_begin_, delete_end_, true); | |
| 190 | 194 |
| 191 // REMOVE_COOKIES is actually "cookies and other site data" so we make sure | 195 // REMOVE_COOKIES is actually "cookies and other site data" so we make sure |
| 192 // to remove other data such local databases, STS state, etc. These only can | 196 // to remove other data such local databases, STS state, etc. These only can |
| 193 // be removed if a WEBKIT thread exists, so check that first: | 197 // be removed if a WEBKIT thread exists, so check that first: |
| 194 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT)) { | 198 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT)) { |
| 195 // We assume the end time is now. | 199 // We assume the end time is now. |
| 196 profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_); | 200 profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_); |
| 197 } | 201 } |
| 198 | 202 |
| 199 // We'll start by using the quota system to clear out AppCaches, WebSQL DBs, | 203 // We'll start by using the quota system to clear out AppCaches, WebSQL DBs, |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 NewRunnableMethod( | 529 NewRunnableMethod( |
| 526 this, | 530 this, |
| 527 &BrowsingDataRemover::NotifyAndDeleteIfDone)); | 531 &BrowsingDataRemover::NotifyAndDeleteIfDone)); |
| 528 } | 532 } |
| 529 | 533 |
| 530 void BrowsingDataRemover::OnWaitableEventSignaled( | 534 void BrowsingDataRemover::OnWaitableEventSignaled( |
| 531 base::WaitableEvent* waitable_event) { | 535 base::WaitableEvent* waitable_event) { |
| 532 waiting_for_clear_lso_data_ = false; | 536 waiting_for_clear_lso_data_ = false; |
| 533 NotifyAndDeleteIfDone(); | 537 NotifyAndDeleteIfDone(); |
| 534 } | 538 } |
| 539 |
| 540 void BrowsingDataRemover::OnClearedCookies(int num_deleted) { |
| 541 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 542 BrowserThread::PostTask( |
| 543 BrowserThread::UI, FROM_HERE, |
| 544 base::Bind(&BrowsingDataRemover::OnClearedCookies, |
| 545 base::Unretained(this), num_deleted)); |
| 546 return; |
| 547 } |
| 548 |
| 549 waiting_for_clear_cookies_ = false; |
| 550 NotifyAndDeleteIfDone(); |
| 551 } |
| 552 |
| 553 void BrowsingDataRemover::ClearCookiesOnIOThread( |
| 554 net::URLRequestContextGetter* rq_context) { |
| 555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 556 net::CookieMonster* cookie_monster = rq_context-> |
| 557 GetURLRequestContext()->cookie_store()->GetCookieMonster(); |
| 558 if (cookie_monster) { |
| 559 cookie_monster->DeleteAllCreatedBetweenAsync( |
| 560 delete_begin_, delete_end_, true, |
| 561 base::Bind(&BrowsingDataRemover::OnClearedCookies, |
| 562 base::Unretained(this))); |
| 563 } else { |
| 564 OnClearedCookies(0); |
| 565 } |
| 566 } |
| OLD | NEW |