| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h" | 5 #include "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DCHECK(AllDone()); | 119 DCHECK(AllDone()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Static. | 122 // Static. |
| 123 void IOSChromeBrowsingDataRemover::set_removing(bool is_removing) { | 123 void IOSChromeBrowsingDataRemover::set_removing(bool is_removing) { |
| 124 DCHECK(is_removing_ != is_removing); | 124 DCHECK(is_removing_ != is_removing); |
| 125 is_removing_ = is_removing; | 125 is_removing_ = is_removing; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void IOSChromeBrowsingDataRemover::Remove(int remove_mask) { | 128 void IOSChromeBrowsingDataRemover::Remove(int remove_mask) { |
| 129 RemoveImpl(remove_mask, GURL()); | 129 RemoveImpl(remove_mask); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void IOSChromeBrowsingDataRemover::RemoveImpl(int remove_mask, | 132 void IOSChromeBrowsingDataRemover::RemoveImpl(int remove_mask) { |
| 133 const GURL& remove_url) { | |
| 134 DCHECK_CURRENTLY_ON(WebThread::UI); | 133 DCHECK_CURRENTLY_ON(WebThread::UI); |
| 135 set_removing(true); | 134 set_removing(true); |
| 136 remove_mask_ = remove_mask; | 135 remove_mask_ = remove_mask; |
| 137 | 136 |
| 138 // On other platforms, it is possible to specify different types of origins | 137 // On other platforms, it is possible to specify different types of origins |
| 139 // to clear data for (e.g., unprotected web vs. extensions). On iOS, this | 138 // to clear data for (e.g., unprotected web vs. extensions). On iOS, this |
| 140 // mask is always implicitly the unprotected web, which is the only type that | 139 // mask is always implicitly the unprotected web, which is the only type that |
| 141 // is relevant. This metric is left here for historical consistency. | 140 // is relevant. This metric is left here for historical consistency. |
| 142 web::RecordAction( | 141 web::RecordAction( |
| 143 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb")); | 142 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb")); |
| 144 | 143 |
| 145 if (remove_mask & REMOVE_HISTORY) { | 144 if (remove_mask & REMOVE_HISTORY) { |
| 146 history::HistoryService* history_service = | 145 history::HistoryService* history_service = |
| 147 ios::HistoryServiceFactory::GetForBrowserState( | 146 ios::HistoryServiceFactory::GetForBrowserState( |
| 148 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); | 147 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); |
| 149 if (history_service) { | 148 if (history_service) { |
| 150 std::set<GURL> restrict_urls; | 149 std::set<GURL> restrict_urls; |
| 151 if (!remove_url.is_empty()) | |
| 152 restrict_urls.insert(remove_url); | |
| 153 web::RecordAction(UserMetricsAction("ClearBrowsingData_History")); | 150 web::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
| 154 waiting_for_clear_history_ = true; | 151 waiting_for_clear_history_ = true; |
| 155 | 152 |
| 156 history_service->ExpireLocalAndRemoteHistoryBetween( | 153 history_service->ExpireLocalAndRemoteHistoryBetween( |
| 157 ios::WebHistoryServiceFactory::GetForBrowserState(browser_state_), | 154 ios::WebHistoryServiceFactory::GetForBrowserState(browser_state_), |
| 158 restrict_urls, delete_begin_, delete_end_, | 155 restrict_urls, delete_begin_, delete_end_, |
| 159 base::Bind(&IOSChromeBrowsingDataRemover::OnHistoryDeletionDone, | 156 base::Bind(&IOSChromeBrowsingDataRemover::OnHistoryDeletionDone, |
| 160 base::Unretained(this)), | 157 base::Unretained(this)), |
| 161 &history_task_tracker_); | 158 &history_task_tracker_); |
| 162 } | 159 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 184 TemplateURLService* keywords_model = | 181 TemplateURLService* keywords_model = |
| 185 ios::TemplateURLServiceFactory::GetForBrowserState(browser_state_); | 182 ios::TemplateURLServiceFactory::GetForBrowserState(browser_state_); |
| 186 if (keywords_model && !keywords_model->loaded()) { | 183 if (keywords_model && !keywords_model->loaded()) { |
| 187 template_url_sub_ = keywords_model->RegisterOnLoadedCallback( | 184 template_url_sub_ = keywords_model->RegisterOnLoadedCallback( |
| 188 base::Bind(&IOSChromeBrowsingDataRemover::OnKeywordsLoaded, | 185 base::Bind(&IOSChromeBrowsingDataRemover::OnKeywordsLoaded, |
| 189 base::Unretained(this))); | 186 base::Unretained(this))); |
| 190 keywords_model->Load(); | 187 keywords_model->Load(); |
| 191 waiting_for_clear_keyword_data_ = true; | 188 waiting_for_clear_keyword_data_ = true; |
| 192 } else if (keywords_model) { | 189 } else if (keywords_model) { |
| 193 keywords_model->RemoveAutoGeneratedForOriginBetween( | 190 keywords_model->RemoveAutoGeneratedForOriginBetween( |
| 194 remove_url, delete_begin_, delete_end_); | 191 GURL(), delete_begin_, delete_end_); |
| 195 } | 192 } |
| 196 } | 193 } |
| 197 | 194 |
| 198 // If the caller is removing history for all hosts, then clear ancillary | 195 // If the caller is removing history for all hosts, then clear ancillary |
| 199 // historical information. | 196 // historical information. |
| 200 if (remove_url.is_empty()) { | 197 // We also delete the list of recently closed tabs. Since these expire, |
| 201 // We also delete the list of recently closed tabs. Since these expire, | 198 // they can't be more than a day old, so we can simply clear them all. |
| 202 // they can't be more than a day old, so we can simply clear them all. | 199 sessions::TabRestoreService* tab_service = |
| 203 sessions::TabRestoreService* tab_service = | 200 IOSChromeTabRestoreServiceFactory::GetForBrowserState(browser_state_); |
| 204 IOSChromeTabRestoreServiceFactory::GetForBrowserState(browser_state_); | 201 if (tab_service) { |
| 205 if (tab_service) { | 202 tab_service->ClearEntries(); |
| 206 tab_service->ClearEntries(); | 203 tab_service->DeleteLastSession(); |
| 207 tab_service->DeleteLastSession(); | |
| 208 } | |
| 209 } | 204 } |
| 210 | 205 |
| 211 // The saved Autofill profiles and credit cards can include the origin from | 206 // The saved Autofill profiles and credit cards can include the origin from |
| 212 // which these profiles and credit cards were learned. These are a form of | 207 // which these profiles and credit cards were learned. These are a form of |
| 213 // history, so clear them as well. | 208 // history, so clear them as well. |
| 214 scoped_refptr<autofill::AutofillWebDataService> web_data_service = | 209 scoped_refptr<autofill::AutofillWebDataService> web_data_service = |
| 215 ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState( | 210 ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState( |
| 216 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); | 211 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); |
| 217 if (web_data_service.get()) { | 212 if (web_data_service.get()) { |
| 218 waiting_for_clear_autofill_origin_urls_ = true; | 213 waiting_for_clear_autofill_origin_urls_ = true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 233 | 228 |
| 234 } | 229 } |
| 235 | 230 |
| 236 if (remove_mask & REMOVE_COOKIES) { | 231 if (remove_mask & REMOVE_COOKIES) { |
| 237 web::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); | 232 web::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); |
| 238 | 233 |
| 239 ++waiting_for_clear_cookies_count_; | 234 ++waiting_for_clear_cookies_count_; |
| 240 WebThread::PostTask( | 235 WebThread::PostTask( |
| 241 WebThread::IO, FROM_HERE, | 236 WebThread::IO, FROM_HERE, |
| 242 base::Bind(&IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread, | 237 base::Bind(&IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread, |
| 243 base::Unretained(this), main_context_getter_, remove_url)); | 238 base::Unretained(this), main_context_getter_)); |
| 244 | 239 |
| 245 // TODO(mkwst): If we're not removing passwords, then clear the 'zero-click' | 240 // TODO(mkwst): If we're not removing passwords, then clear the 'zero-click' |
| 246 // flag for all credentials in the password store. | 241 // flag for all credentials in the password store. |
| 247 } | 242 } |
| 248 | 243 |
| 249 if (remove_mask & REMOVE_CHANNEL_IDS) { | 244 if (remove_mask & REMOVE_CHANNEL_IDS) { |
| 250 web::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs")); | 245 web::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs")); |
| 251 if (main_context_getter_) { | 246 if (main_context_getter_) { |
| 252 waiting_for_clear_channel_ids_ = true; | 247 waiting_for_clear_channel_ids_ = true; |
| 253 WebThread::PostTask( | 248 WebThread::PostTask( |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 base::Unretained(this), num_deleted)); | 442 base::Unretained(this), num_deleted)); |
| 448 return; | 443 return; |
| 449 } | 444 } |
| 450 | 445 |
| 451 DCHECK_GT(waiting_for_clear_cookies_count_, 0); | 446 DCHECK_GT(waiting_for_clear_cookies_count_, 0); |
| 452 --waiting_for_clear_cookies_count_; | 447 --waiting_for_clear_cookies_count_; |
| 453 NotifyAndDeleteIfDone(); | 448 NotifyAndDeleteIfDone(); |
| 454 } | 449 } |
| 455 | 450 |
| 456 void IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread( | 451 void IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread( |
| 457 const scoped_refptr<net::URLRequestContextGetter>& rq_context, | 452 const scoped_refptr<net::URLRequestContextGetter>& rq_context) { |
| 458 const GURL& storage_url) { | |
| 459 DCHECK_CURRENTLY_ON(WebThread::IO); | 453 DCHECK_CURRENTLY_ON(WebThread::IO); |
| 460 net::CookieStore* cookie_store = | 454 net::CookieStore* cookie_store = |
| 461 rq_context->GetURLRequestContext()->cookie_store(); | 455 rq_context->GetURLRequestContext()->cookie_store(); |
| 462 if (storage_url.is_empty()) { | 456 cookie_store->DeleteAllCreatedBetweenAsync( |
| 463 cookie_store->DeleteAllCreatedBetweenAsync( | 457 delete_begin_, delete_end_, |
| 464 delete_begin_, delete_end_, | 458 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedCookies, |
| 465 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedCookies, | 459 base::Unretained(this))); |
| 466 base::Unretained(this))); | |
| 467 } else { | |
| 468 cookie_store->DeleteAllCreatedBetweenForHostAsync( | |
| 469 delete_begin_, delete_end_, storage_url, | |
| 470 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedCookies, | |
| 471 base::Unretained(this))); | |
| 472 } | |
| 473 } | 460 } |
| 474 | 461 |
| 475 void IOSChromeBrowsingDataRemover::ClearChannelIDsOnIOThread( | 462 void IOSChromeBrowsingDataRemover::ClearChannelIDsOnIOThread( |
| 476 const scoped_refptr<net::URLRequestContextGetter>& rq_context) { | 463 const scoped_refptr<net::URLRequestContextGetter>& rq_context) { |
| 477 DCHECK_CURRENTLY_ON(WebThread::IO); | 464 DCHECK_CURRENTLY_ON(WebThread::IO); |
| 478 net::ChannelIDService* channel_id_service = | 465 net::ChannelIDService* channel_id_service = |
| 479 rq_context->GetURLRequestContext()->channel_id_service(); | 466 rq_context->GetURLRequestContext()->channel_id_service(); |
| 480 channel_id_service->GetChannelIDStore()->DeleteAllCreatedBetween( | 467 channel_id_service->GetChannelIDStore()->DeleteAllCreatedBetween( |
| 481 delete_begin_, delete_end_, | 468 delete_begin_, delete_end_, |
| 482 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedChannelIDsOnIOThread, | 469 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedChannelIDsOnIOThread, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 waiting_for_clear_autofill_origin_urls_ = false; | 502 waiting_for_clear_autofill_origin_urls_ = false; |
| 516 NotifyAndDeleteIfDone(); | 503 NotifyAndDeleteIfDone(); |
| 517 } | 504 } |
| 518 | 505 |
| 519 // static | 506 // static |
| 520 IOSChromeBrowsingDataRemover::CallbackSubscription | 507 IOSChromeBrowsingDataRemover::CallbackSubscription |
| 521 IOSChromeBrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | 508 IOSChromeBrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( |
| 522 const IOSChromeBrowsingDataRemover::Callback& callback) { | 509 const IOSChromeBrowsingDataRemover::Callback& callback) { |
| 523 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); | 510 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); |
| 524 } | 511 } |
| OLD | NEW |