| 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 17 matching lines...) Expand all Loading... |
| 28 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 28 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 29 #include "ios/chrome/browser/history/history_service_factory.h" | 29 #include "ios/chrome/browser/history/history_service_factory.h" |
| 30 #include "ios/chrome/browser/history/web_history_service_factory.h" | 30 #include "ios/chrome/browser/history/web_history_service_factory.h" |
| 31 #include "ios/chrome/browser/ios_chrome_io_thread.h" | 31 #include "ios/chrome/browser/ios_chrome_io_thread.h" |
| 32 #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h" | 32 #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h" |
| 33 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" | 33 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" |
| 34 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" | 34 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" |
| 35 #include "ios/chrome/browser/web_data_service_factory.h" | 35 #include "ios/chrome/browser/web_data_service_factory.h" |
| 36 #include "ios/net/http_cache_helper.h" | 36 #include "ios/net/http_cache_helper.h" |
| 37 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 37 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 38 #include "ios/web/public/user_metrics.h" | |
| 39 #include "ios/web/public/web_thread.h" | 38 #include "ios/web/public/web_thread.h" |
| 40 #include "net/base/net_errors.h" | 39 #include "net/base/net_errors.h" |
| 41 #include "net/cookies/cookie_store.h" | 40 #include "net/cookies/cookie_store.h" |
| 42 #include "net/http/transport_security_state.h" | 41 #include "net/http/transport_security_state.h" |
| 43 #include "net/ssl/channel_id_service.h" | 42 #include "net/ssl/channel_id_service.h" |
| 44 #include "net/ssl/channel_id_store.h" | 43 #include "net/ssl/channel_id_store.h" |
| 45 #include "net/url_request/url_request_context.h" | 44 #include "net/url_request/url_request_context.h" |
| 46 #include "net/url_request/url_request_context_getter.h" | 45 #include "net/url_request/url_request_context_getter.h" |
| 47 | 46 |
| 48 using base::UserMetricsAction; | 47 using base::UserMetricsAction; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 : removal_begin(removal_begin), removal_mask(removal_mask) {} | 85 : removal_begin(removal_begin), removal_mask(removal_mask) {} |
| 87 | 86 |
| 88 IOSChromeBrowsingDataRemover::NotificationDetails::~NotificationDetails() {} | 87 IOSChromeBrowsingDataRemover::NotificationDetails::~NotificationDetails() {} |
| 89 | 88 |
| 90 // Static. | 89 // Static. |
| 91 IOSChromeBrowsingDataRemover* IOSChromeBrowsingDataRemover::CreateForPeriod( | 90 IOSChromeBrowsingDataRemover* IOSChromeBrowsingDataRemover::CreateForPeriod( |
| 92 ios::ChromeBrowserState* browser_state, | 91 ios::ChromeBrowserState* browser_state, |
| 93 TimePeriod period) { | 92 TimePeriod period) { |
| 94 switch (period) { | 93 switch (period) { |
| 95 case EVERYTHING: | 94 case EVERYTHING: |
| 96 web::RecordAction(UserMetricsAction("ClearBrowsingData_Everything")); | 95 base::RecordAction(UserMetricsAction("ClearBrowsingData_Everything")); |
| 97 break; | 96 break; |
| 98 } | 97 } |
| 99 return new IOSChromeBrowsingDataRemover( | 98 return new IOSChromeBrowsingDataRemover( |
| 100 browser_state, | 99 browser_state, |
| 101 IOSChromeBrowsingDataRemover::CalculateBeginDeleteTime(period), | 100 IOSChromeBrowsingDataRemover::CalculateBeginDeleteTime(period), |
| 102 base::Time::Max()); | 101 base::Time::Max()); |
| 103 } | 102 } |
| 104 | 103 |
| 105 IOSChromeBrowsingDataRemover::IOSChromeBrowsingDataRemover( | 104 IOSChromeBrowsingDataRemover::IOSChromeBrowsingDataRemover( |
| 106 ios::ChromeBrowserState* browser_state, | 105 ios::ChromeBrowserState* browser_state, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 135 | 134 |
| 136 void IOSChromeBrowsingDataRemover::RemoveImpl(int remove_mask) { | 135 void IOSChromeBrowsingDataRemover::RemoveImpl(int remove_mask) { |
| 137 DCHECK_CURRENTLY_ON(WebThread::UI); | 136 DCHECK_CURRENTLY_ON(WebThread::UI); |
| 138 set_removing(true); | 137 set_removing(true); |
| 139 remove_mask_ = remove_mask; | 138 remove_mask_ = remove_mask; |
| 140 | 139 |
| 141 // On other platforms, it is possible to specify different types of origins | 140 // On other platforms, it is possible to specify different types of origins |
| 142 // to clear data for (e.g., unprotected web vs. extensions). On iOS, this | 141 // to clear data for (e.g., unprotected web vs. extensions). On iOS, this |
| 143 // mask is always implicitly the unprotected web, which is the only type that | 142 // mask is always implicitly the unprotected web, which is the only type that |
| 144 // is relevant. This metric is left here for historical consistency. | 143 // is relevant. This metric is left here for historical consistency. |
| 145 web::RecordAction( | 144 base::RecordAction( |
| 146 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb")); | 145 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb")); |
| 147 | 146 |
| 148 if (remove_mask & REMOVE_HISTORY) { | 147 if (remove_mask & REMOVE_HISTORY) { |
| 149 history::HistoryService* history_service = | 148 history::HistoryService* history_service = |
| 150 ios::HistoryServiceFactory::GetForBrowserState( | 149 ios::HistoryServiceFactory::GetForBrowserState( |
| 151 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); | 150 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); |
| 152 if (history_service) { | 151 if (history_service) { |
| 153 std::set<GURL> restrict_urls; | 152 std::set<GURL> restrict_urls; |
| 154 web::RecordAction(UserMetricsAction("ClearBrowsingData_History")); | 153 base::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
| 155 waiting_for_clear_history_ = true; | 154 waiting_for_clear_history_ = true; |
| 156 | 155 |
| 157 history_service->ExpireLocalAndRemoteHistoryBetween( | 156 history_service->ExpireLocalAndRemoteHistoryBetween( |
| 158 ios::WebHistoryServiceFactory::GetForBrowserState(browser_state_), | 157 ios::WebHistoryServiceFactory::GetForBrowserState(browser_state_), |
| 159 restrict_urls, delete_begin_, delete_end_, | 158 restrict_urls, delete_begin_, delete_end_, |
| 160 base::Bind(&IOSChromeBrowsingDataRemover::OnHistoryDeletionDone, | 159 base::Bind(&IOSChromeBrowsingDataRemover::OnHistoryDeletionDone, |
| 161 base::Unretained(this)), | 160 base::Unretained(this)), |
| 162 &history_task_tracker_); | 161 &history_task_tracker_); |
| 163 } | 162 } |
| 164 | 163 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 225 |
| 227 autofill::PersonalDataManager* data_manager = | 226 autofill::PersonalDataManager* data_manager = |
| 228 PersonalDataManagerFactory::GetForBrowserState(browser_state_); | 227 PersonalDataManagerFactory::GetForBrowserState(browser_state_); |
| 229 if (data_manager) | 228 if (data_manager) |
| 230 data_manager->Refresh(); | 229 data_manager->Refresh(); |
| 231 } | 230 } |
| 232 | 231 |
| 233 } | 232 } |
| 234 | 233 |
| 235 if (remove_mask & REMOVE_COOKIES) { | 234 if (remove_mask & REMOVE_COOKIES) { |
| 236 web::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); | 235 base::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); |
| 237 | 236 |
| 238 ++waiting_for_clear_cookies_count_; | 237 ++waiting_for_clear_cookies_count_; |
| 239 WebThread::PostTask( | 238 WebThread::PostTask( |
| 240 WebThread::IO, FROM_HERE, | 239 WebThread::IO, FROM_HERE, |
| 241 base::Bind(&IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread, | 240 base::Bind(&IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread, |
| 242 base::Unretained(this), main_context_getter_)); | 241 base::Unretained(this), main_context_getter_)); |
| 243 | 242 |
| 244 // TODO(mkwst): If we're not removing passwords, then clear the 'zero-click' | 243 // TODO(mkwst): If we're not removing passwords, then clear the 'zero-click' |
| 245 // flag for all credentials in the password store. | 244 // flag for all credentials in the password store. |
| 246 } | 245 } |
| 247 | 246 |
| 248 if (remove_mask & REMOVE_CHANNEL_IDS) { | 247 if (remove_mask & REMOVE_CHANNEL_IDS) { |
| 249 web::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs")); | 248 base::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs")); |
| 250 if (main_context_getter_) { | 249 if (main_context_getter_) { |
| 251 waiting_for_clear_channel_ids_ = true; | 250 waiting_for_clear_channel_ids_ = true; |
| 252 WebThread::PostTask( | 251 WebThread::PostTask( |
| 253 WebThread::IO, FROM_HERE, | 252 WebThread::IO, FROM_HERE, |
| 254 base::Bind(&IOSChromeBrowsingDataRemover::ClearChannelIDsOnIOThread, | 253 base::Bind(&IOSChromeBrowsingDataRemover::ClearChannelIDsOnIOThread, |
| 255 base::Unretained(this), main_context_getter_)); | 254 base::Unretained(this), main_context_getter_)); |
| 256 } | 255 } |
| 257 } | 256 } |
| 258 | 257 |
| 259 if (remove_mask & REMOVE_PASSWORDS) { | 258 if (remove_mask & REMOVE_PASSWORDS) { |
| 260 web::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords")); | 259 base::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords")); |
| 261 password_manager::PasswordStore* password_store = | 260 password_manager::PasswordStore* password_store = |
| 262 IOSChromePasswordStoreFactory::GetForBrowserState( | 261 IOSChromePasswordStoreFactory::GetForBrowserState( |
| 263 browser_state_, ServiceAccessType::EXPLICIT_ACCESS) | 262 browser_state_, ServiceAccessType::EXPLICIT_ACCESS) |
| 264 .get(); | 263 .get(); |
| 265 | 264 |
| 266 if (password_store) { | 265 if (password_store) { |
| 267 waiting_for_clear_passwords_ = true; | 266 waiting_for_clear_passwords_ = true; |
| 268 password_store->RemoveLoginsCreatedBetween( | 267 password_store->RemoveLoginsCreatedBetween( |
| 269 delete_begin_, delete_end_, | 268 delete_begin_, delete_end_, |
| 270 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedPasswords, | 269 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedPasswords, |
| 271 base::Unretained(this))); | 270 base::Unretained(this))); |
| 272 } | 271 } |
| 273 } | 272 } |
| 274 | 273 |
| 275 if (remove_mask & REMOVE_FORM_DATA) { | 274 if (remove_mask & REMOVE_FORM_DATA) { |
| 276 web::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill")); | 275 base::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill")); |
| 277 scoped_refptr<autofill::AutofillWebDataService> web_data_service = | 276 scoped_refptr<autofill::AutofillWebDataService> web_data_service = |
| 278 ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState( | 277 ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState( |
| 279 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); | 278 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); |
| 280 | 279 |
| 281 if (web_data_service.get()) { | 280 if (web_data_service.get()) { |
| 282 waiting_for_clear_form_ = true; | 281 waiting_for_clear_form_ = true; |
| 283 web_data_service->RemoveFormElementsAddedBetween(delete_begin_, | 282 web_data_service->RemoveFormElementsAddedBetween(delete_begin_, |
| 284 delete_end_); | 283 delete_end_); |
| 285 web_data_service->RemoveAutofillDataModifiedBetween(delete_begin_, | 284 web_data_service->RemoveAutofillDataModifiedBetween(delete_begin_, |
| 286 delete_end_); | 285 delete_end_); |
| 287 // The above calls are done on the UI thread but do their work on the DB | 286 // The above calls are done on the UI thread but do their work on the DB |
| 288 // thread. So wait for it. | 287 // thread. So wait for it. |
| 289 WebThread::PostTaskAndReply( | 288 WebThread::PostTaskAndReply( |
| 290 WebThread::DB, FROM_HERE, base::Bind(&base::DoNothing), | 289 WebThread::DB, FROM_HERE, base::Bind(&base::DoNothing), |
| 291 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedFormData, | 290 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedFormData, |
| 292 base::Unretained(this))); | 291 base::Unretained(this))); |
| 293 | 292 |
| 294 autofill::PersonalDataManager* data_manager = | 293 autofill::PersonalDataManager* data_manager = |
| 295 PersonalDataManagerFactory::GetForBrowserState(browser_state_); | 294 PersonalDataManagerFactory::GetForBrowserState(browser_state_); |
| 296 if (data_manager) | 295 if (data_manager) |
| 297 data_manager->Refresh(); | 296 data_manager->Refresh(); |
| 298 } | 297 } |
| 299 } | 298 } |
| 300 | 299 |
| 301 if (remove_mask & REMOVE_CACHE) { | 300 if (remove_mask & REMOVE_CACHE) { |
| 302 web::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); | 301 base::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); |
| 303 | 302 |
| 304 waiting_for_clear_cache_ = true; | 303 waiting_for_clear_cache_ = true; |
| 305 DCHECK(delete_begin_.is_null()) << "Partial clearing not supported"; | 304 DCHECK(delete_begin_.is_null()) << "Partial clearing not supported"; |
| 306 ClearHttpCache(browser_state_->GetRequestContext(), | 305 ClearHttpCache(browser_state_->GetRequestContext(), |
| 307 WebThread::GetTaskRunnerForThread(WebThread::IO), | 306 WebThread::GetTaskRunnerForThread(WebThread::IO), |
| 308 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedCache, | 307 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedCache, |
| 309 base::Unretained(this))); | 308 base::Unretained(this))); |
| 310 } | 309 } |
| 311 | 310 |
| 312 // Remove omnibox zero-suggest cache results. | 311 // Remove omnibox zero-suggest cache results. |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 waiting_for_clear_autofill_origin_urls_ = false; | 505 waiting_for_clear_autofill_origin_urls_ = false; |
| 507 NotifyAndDeleteIfDone(); | 506 NotifyAndDeleteIfDone(); |
| 508 } | 507 } |
| 509 | 508 |
| 510 // static | 509 // static |
| 511 IOSChromeBrowsingDataRemover::CallbackSubscription | 510 IOSChromeBrowsingDataRemover::CallbackSubscription |
| 512 IOSChromeBrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | 511 IOSChromeBrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( |
| 513 const IOSChromeBrowsingDataRemover::Callback& callback) { | 512 const IOSChromeBrowsingDataRemover::Callback& callback) { |
| 514 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); | 513 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); |
| 515 } | 514 } |
| OLD | NEW |