Chromium Code Reviews| 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_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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 quota_client_mask |= quota::QuotaClient::kDatabase; | 150 quota_client_mask |= quota::QuotaClient::kDatabase; |
| 151 if (remove_mask & BrowsingDataRemover::REMOVE_APPCACHE) | 151 if (remove_mask & BrowsingDataRemover::REMOVE_APPCACHE) |
| 152 quota_client_mask |= quota::QuotaClient::kAppcache; | 152 quota_client_mask |= quota::QuotaClient::kAppcache; |
| 153 if (remove_mask & BrowsingDataRemover::REMOVE_INDEXEDDB) | 153 if (remove_mask & BrowsingDataRemover::REMOVE_INDEXEDDB) |
| 154 quota_client_mask |= quota::QuotaClient::kIndexedDatabase; | 154 quota_client_mask |= quota::QuotaClient::kIndexedDatabase; |
| 155 | 155 |
| 156 return quota_client_mask; | 156 return quota_client_mask; |
| 157 } | 157 } |
| 158 | 158 |
| 159 void BrowsingDataRemover::Remove(int remove_mask) { | 159 void BrowsingDataRemover::Remove(int remove_mask) { |
| 160 Remove(remove_mask, GURL()); | |
| 161 } | |
| 162 | |
| 163 void BrowsingDataRemover::Remove(int remove_mask, const GURL& origin) { | |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 161 set_removing(true); | 165 set_removing(true); |
| 162 remove_mask_ = remove_mask; | 166 remove_mask_ = remove_mask; |
| 167 remove_origin_ = origin; | |
| 163 | 168 |
| 164 if (remove_mask & REMOVE_HISTORY) { | 169 if (remove_mask & REMOVE_HISTORY) { |
| 165 HistoryService* history_service = | 170 HistoryService* history_service = |
| 166 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 171 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 167 if (history_service) { | 172 if (history_service) { |
| 168 std::set<GURL> restrict_urls; | 173 std::set<GURL> restrict_urls; |
| 174 if (!remove_origin_.is_empty()) | |
| 175 restrict_urls.insert(remove_origin_); | |
| 169 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); | 176 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
| 170 waiting_for_clear_history_ = true; | 177 waiting_for_clear_history_ = true; |
| 171 history_service->ExpireHistoryBetween(restrict_urls, | 178 history_service->ExpireHistoryBetween(restrict_urls, |
| 172 delete_begin_, delete_end_, | 179 delete_begin_, delete_end_, |
| 173 &request_consumer_, | 180 &request_consumer_, |
| 174 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, | 181 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, |
| 175 base::Unretained(this))); | 182 base::Unretained(this))); |
| 176 } | 183 } |
| 177 | 184 |
| 178 // Need to clear the host cache and accumulated speculative data, as it also | 185 // If the caller is removing history for all hosts, then clear ancillary |
| 179 // reveals some history. | 186 // historical information. |
|
Bernhard Bauer
2012/02/10 19:50:57
This means of course we have to be careful, as the
| |
| 180 if (g_browser_process->io_thread()) { | 187 if (!remove_origin_.is_empty()) { |
| 181 waiting_for_clear_networking_history_ = true; | 188 // Need to clear the host cache and accumulated speculative data, as it |
| 182 BrowserThread::PostTask( | 189 // also reveals some history. |
| 183 BrowserThread::IO, FROM_HERE, | 190 if (g_browser_process->io_thread()) { |
| 184 base::Bind(&BrowsingDataRemover::ClearNetworkingHistory, | 191 waiting_for_clear_networking_history_ = true; |
| 185 base::Unretained(this), g_browser_process->io_thread())); | 192 BrowserThread::PostTask( |
| 186 } | 193 BrowserThread::IO, FROM_HERE, |
| 194 base::Bind(&BrowsingDataRemover::ClearNetworkingHistory, | |
| 195 base::Unretained(this), g_browser_process->io_thread())); | |
| 196 } | |
| 187 | 197 |
| 188 // As part of history deletion we also delete the auto-generated keywords. | 198 // As part of history deletion we also delete the auto-generated keywords. |
| 189 TemplateURLService* keywords_model = | 199 TemplateURLService* keywords_model = |
| 190 TemplateURLServiceFactory::GetForProfile(profile_); | 200 TemplateURLServiceFactory::GetForProfile(profile_); |
| 191 if (keywords_model && !keywords_model->loaded()) { | 201 if (keywords_model && !keywords_model->loaded()) { |
| 192 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 202 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 193 content::Source<TemplateURLService>(keywords_model)); | 203 content::Source<TemplateURLService>(keywords_model)); |
| 194 keywords_model->Load(); | 204 keywords_model->Load(); |
| 195 } else if (keywords_model) { | 205 } else if (keywords_model) { |
| 196 keywords_model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); | 206 keywords_model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); |
| 197 } | 207 } |
| 198 | 208 |
| 199 // We also delete the list of recently closed tabs. Since these expire, | 209 // We also delete the list of recently closed tabs. Since these expire, |
| 200 // they can't be more than a day old, so we can simply clear them all. | 210 // they can't be more than a day old, so we can simply clear them all. |
| 201 TabRestoreService* tab_service = | 211 TabRestoreService* tab_service = |
| 202 TabRestoreServiceFactory::GetForProfile(profile_); | 212 TabRestoreServiceFactory::GetForProfile(profile_); |
| 203 if (tab_service) { | 213 if (tab_service) { |
| 204 tab_service->ClearEntries(); | 214 tab_service->ClearEntries(); |
| 205 tab_service->DeleteLastSession(); | 215 tab_service->DeleteLastSession(); |
| 206 } | 216 } |
| 207 | 217 |
| 208 // We also delete the last session when we delete the history. | 218 // We also delete the last session when we delete the history. |
| 209 SessionService* session_service = | 219 SessionService* session_service = |
| 210 SessionServiceFactory::GetForProfile(profile_); | 220 SessionServiceFactory::GetForProfile(profile_); |
| 211 if (session_service) | 221 if (session_service) |
| 212 session_service->DeleteLastSession(); | 222 session_service->DeleteLastSession(); |
| 213 | 223 |
| 214 // The PrerenderManager keeps history of prerendered pages, so clear that. | 224 // The PrerenderManager keeps history of prerendered pages, so clear that. |
| 215 // It also may have a prerendered page. If so, the page could be considered | 225 // It also may have a prerendered page. If so, the page could be |
| 216 // to have a small amount of historical information, so delete it, too. | 226 // considered to have a small amount of historical information, so delete |
| 217 prerender::PrerenderManager* prerender_manager = | 227 // it, too. |
| 218 prerender::PrerenderManagerFactory::GetForProfile(profile_); | 228 prerender::PrerenderManager* prerender_manager = |
| 219 if (prerender_manager) { | 229 prerender::PrerenderManagerFactory::GetForProfile(profile_); |
| 220 prerender_manager->ClearData( | 230 if (prerender_manager) { |
| 221 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | | 231 prerender_manager->ClearData( |
| 222 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); | 232 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | |
| 233 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); | |
| 234 } | |
| 223 } | 235 } |
| 224 } | 236 } |
| 225 | 237 |
| 226 if (remove_mask & REMOVE_DOWNLOADS) { | 238 if (remove_mask & REMOVE_DOWNLOADS) { |
| 227 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); | 239 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); |
| 228 DownloadManager* download_manager = | 240 DownloadManager* download_manager = |
| 229 DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager(); | 241 DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager(); |
| 230 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); | 242 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); |
| 231 download_manager->ClearLastDownloadPath(); | 243 download_manager->ClearLastDownloadPath(); |
| 232 } | 244 } |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 BrowserThread::UI, FROM_HERE, | 678 BrowserThread::UI, FROM_HERE, |
| 667 base::Bind(&BrowsingDataRemover::OnClearedOriginBoundCerts, | 679 base::Bind(&BrowsingDataRemover::OnClearedOriginBoundCerts, |
| 668 base::Unretained(this))); | 680 base::Unretained(this))); |
| 669 } | 681 } |
| 670 | 682 |
| 671 void BrowsingDataRemover::OnClearedOriginBoundCerts() { | 683 void BrowsingDataRemover::OnClearedOriginBoundCerts() { |
| 672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 673 waiting_for_clear_origin_bound_certs_ = false; | 685 waiting_for_clear_origin_bound_certs_ = false; |
| 674 NotifyAndDeleteIfDone(); | 686 NotifyAndDeleteIfDone(); |
| 675 } | 687 } |
| OLD | NEW |