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