OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
| 6 |
| 7 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" |
| 11 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 12 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 15 #include "chrome/browser/domain_reliability/service_factory.h" |
| 16 #include "chrome/browser/history/history_service_factory.h" |
| 17 #include "chrome/browser/history/web_history_service_factory.h" |
| 18 #include "chrome/browser/io_thread.h" |
| 19 #include "chrome/browser/media/media_device_id_salt.h" |
| 20 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" |
| 21 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h" |
| 22 #include "chrome/browser/net/predictor.h" |
| 23 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 24 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
| 25 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" |
| 26 #include "chrome/browser/password_manager/password_store_factory.h" |
| 27 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
| 28 #include "chrome/browser/prerender/prerender_manager.h" |
| 29 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 30 #include "chrome/browser/previews/previews_service.h" |
| 31 #include "chrome/browser/previews/previews_service_factory.h" |
| 32 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 34 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 35 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 36 #include "chrome/browser/web_data_service_factory.h" |
| 37 #include "chrome/common/features.h" |
| 38 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/common/url_constants.h" |
| 40 #include "components/autofill/core/browser/personal_data_manager.h" |
| 41 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 42 #include "components/bookmarks/browser/bookmark_model.h" |
| 43 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 44 #include "components/content_settings/core/common/content_settings.h" |
| 45 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 46 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp
ression_stats.h" |
| 47 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
| 48 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" |
| 49 #include "components/domain_reliability/service.h" |
| 50 #include "components/history/core/browser/history_service.h" |
| 51 #include "components/nacl/browser/nacl_browser.h" |
| 52 #include "components/nacl/browser/pnacl_host.h" |
| 53 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h" |
| 54 #include "components/ntp_snippets/content_suggestions_service.h" |
| 55 #include "components/omnibox/browser/omnibox_pref_names.h" |
| 56 #include "components/password_manager/core/browser/password_store.h" |
| 57 #include "components/prefs/pref_service.h" |
| 58 #include "components/previews/core/previews_ui_service.h" |
| 59 #include "components/search_engines/template_url_service.h" |
| 60 #include "components/sessions/core/tab_restore_service.h" |
| 61 #include "content/public/browser/user_metrics.h" |
| 62 #include "net/cookies/cookie_store.h" |
| 63 #include "net/url_request/url_request_context.h" |
| 64 #include "net/url_request/url_request_context_getter.h" |
| 65 |
| 66 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 67 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 68 #include "chrome/browser/android/webapps/webapp_registry.h" |
| 69 #include "chrome/browser/precache/precache_manager_factory.h" |
| 70 #include "components/offline_pages/core/offline_page_feature.h" |
| 71 #include "components/offline_pages/core/offline_page_model.h" |
| 72 #include "components/precache/content/precache_manager.h" |
| 73 #endif |
| 74 |
| 75 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 76 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 77 #include "extensions/browser/extension_prefs.h" |
| 78 #endif |
| 79 |
| 80 #if BUILDFLAG(ENABLE_SESSION_SERVICE) |
| 81 #include "chrome/browser/sessions/session_service.h" |
| 82 #include "chrome/browser/sessions/session_service_factory.h" |
| 83 #endif |
| 84 |
| 85 #if defined(OS_CHROMEOS) |
| 86 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 87 #include "chromeos/attestation/attestation_constants.h" |
| 88 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 89 #include "chromeos/dbus/cryptohome_client.h" |
| 90 #include "chromeos/dbus/dbus_thread_manager.h" |
| 91 #include "components/user_manager/user.h" |
| 92 #endif |
| 93 |
| 94 #if BUILDFLAG(ENABLE_WEBRTC) |
| 95 #include "chrome/browser/media/webrtc/webrtc_log_list.h" |
| 96 #include "chrome/browser/media/webrtc/webrtc_log_util.h" |
| 97 #endif |
| 98 |
| 99 using base::UserMetricsAction; |
| 100 using content::BrowserContext; |
| 101 using content::BrowserThread; |
| 102 |
| 103 namespace { |
| 104 |
| 105 void UIThreadTrampolineHelper(const base::Closure& callback) { |
| 106 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
| 107 } |
| 108 |
| 109 // Convenience method to create a callback that can be run on any thread and |
| 110 // will post the given |callback| back to the UI thread. |
| 111 base::Closure UIThreadTrampoline(const base::Closure& callback) { |
| 112 // We could directly bind &BrowserThread::PostTask, but that would require |
| 113 // evaluating FROM_HERE when this method is called, as opposed to when the |
| 114 // task is actually posted. |
| 115 return base::Bind(&UIThreadTrampolineHelper, callback); |
| 116 } |
| 117 |
| 118 template <typename T> |
| 119 void IgnoreArgumentHelper(const base::Closure& callback, T unused_argument) { |
| 120 callback.Run(); |
| 121 } |
| 122 |
| 123 // Another convenience method to turn a callback without arguments into one that |
| 124 // accepts (and ignores) a single argument. |
| 125 template <typename T> |
| 126 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) { |
| 127 return base::Bind(&IgnoreArgumentHelper<T>, callback); |
| 128 } |
| 129 |
| 130 bool ForwardPrimaryPatternCallback( |
| 131 const base::Callback<bool(const ContentSettingsPattern&)> predicate, |
| 132 const ContentSettingsPattern& primary_pattern, |
| 133 const ContentSettingsPattern& secondary_pattern) { |
| 134 return predicate.Run(primary_pattern); |
| 135 } |
| 136 |
| 137 #if !defined(DISABLE_NACL) |
| 138 void ClearNaClCacheOnIOThread(const base::Closure& callback) { |
| 139 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 140 |
| 141 nacl::NaClBrowser::GetInstance()->ClearValidationCache(callback); |
| 142 } |
| 143 |
| 144 void ClearPnaclCacheOnIOThread(base::Time begin, |
| 145 base::Time end, |
| 146 const base::Closure& callback) { |
| 147 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 148 |
| 149 pnacl::PnaclHost::GetInstance()->ClearTranslationCacheEntriesBetween( |
| 150 begin, end, callback); |
| 151 } |
| 152 #endif |
| 153 |
| 154 void ClearCookiesOnIOThread(base::Time delete_begin, |
| 155 base::Time delete_end, |
| 156 net::URLRequestContextGetter* rq_context, |
| 157 const base::Closure& callback) { |
| 158 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 159 net::CookieStore* cookie_store = |
| 160 rq_context->GetURLRequestContext()->cookie_store(); |
| 161 cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, |
| 162 IgnoreArgument<int>(callback)); |
| 163 } |
| 164 |
| 165 void ClearCookiesWithPredicateOnIOThread( |
| 166 base::Time delete_begin, |
| 167 base::Time delete_end, |
| 168 net::CookieStore::CookiePredicate predicate, |
| 169 net::URLRequestContextGetter* rq_context, |
| 170 const base::Closure& callback) { |
| 171 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 172 net::CookieStore* cookie_store = |
| 173 rq_context->GetURLRequestContext()->cookie_store(); |
| 174 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( |
| 175 delete_begin, delete_end, predicate, IgnoreArgument<int>(callback)); |
| 176 } |
| 177 |
| 178 void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) { |
| 179 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 180 DCHECK(predictor); |
| 181 |
| 182 predictor->DiscardInitialNavigationHistory(); |
| 183 predictor->DiscardAllResults(); |
| 184 } |
| 185 |
| 186 void ClearHostnameResolutionCacheOnIOThread( |
| 187 IOThread* io_thread, |
| 188 base::Callback<bool(const std::string&)> host_filter) { |
| 189 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 190 |
| 191 io_thread->ClearHostCache(host_filter); |
| 192 } |
| 193 |
| 194 } // namespace |
| 195 |
| 196 ChromeBrowsingDataRemoverDelegate::ChromeBrowsingDataRemoverDelegate( |
| 197 BrowserContext* browser_context) |
| 198 : profile_(Profile::FromBrowserContext(browser_context)), |
| 199 sub_task_forward_callback_( |
| 200 base::Bind(&ChromeBrowsingDataRemoverDelegate::NotifyIfDone, |
| 201 base::Unretained(this))), |
| 202 synchronous_clear_operations_(sub_task_forward_callback_), |
| 203 clear_autofill_origin_urls_(sub_task_forward_callback_), |
| 204 clear_flash_content_licenses_(sub_task_forward_callback_), |
| 205 clear_domain_reliability_monitor_(sub_task_forward_callback_), |
| 206 clear_form_(sub_task_forward_callback_), |
| 207 clear_history_(sub_task_forward_callback_), |
| 208 clear_keyword_data_(sub_task_forward_callback_), |
| 209 #if !defined(DISABLE_NACL) |
| 210 clear_nacl_cache_(sub_task_forward_callback_), |
| 211 clear_pnacl_cache_(sub_task_forward_callback_), |
| 212 #endif |
| 213 clear_hostname_resolution_cache_(sub_task_forward_callback_), |
| 214 clear_network_predictor_(sub_task_forward_callback_), |
| 215 clear_networking_history_(sub_task_forward_callback_), |
| 216 clear_passwords_(sub_task_forward_callback_), |
| 217 clear_passwords_stats_(sub_task_forward_callback_), |
| 218 clear_platform_keys_(sub_task_forward_callback_), |
| 219 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 220 clear_precache_history_(sub_task_forward_callback_), |
| 221 clear_offline_page_data_(sub_task_forward_callback_), |
| 222 #endif |
| 223 #if BUILDFLAG(ENABLE_WEBRTC) |
| 224 clear_webrtc_logs_(sub_task_forward_callback_), |
| 225 #endif |
| 226 clear_auto_sign_in_(sub_task_forward_callback_), |
| 227 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 228 webapp_registry_(new WebappRegistry()), |
| 229 #endif |
| 230 weak_ptr_factory_(this) {} |
| 231 |
| 232 ChromeBrowsingDataRemoverDelegate::~ChromeBrowsingDataRemoverDelegate() { |
| 233 history_task_tracker_.TryCancelAll(); |
| 234 template_url_sub_.reset(); |
| 235 } |
| 236 |
| 237 void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData( |
| 238 const base::Time& delete_begin, |
| 239 const base::Time& delete_end, |
| 240 int remove_mask, |
| 241 const BrowsingDataFilterBuilder& filter_builder, |
| 242 int origin_type_mask, |
| 243 const base::Closure& callback) { |
| 244 ////////////////////////////////////////////////////////////////////////////// |
| 245 // INITIALIZATION |
| 246 synchronous_clear_operations_.Start(); |
| 247 callback_ = callback; |
| 248 |
| 249 delete_begin_ = delete_begin; |
| 250 delete_end_ = delete_end; |
| 251 |
| 252 base::Callback<bool(const GURL& url)> filter = |
| 253 filter_builder.BuildGeneralFilter(); |
| 254 base::Callback<bool(const ContentSettingsPattern& url)> same_pattern_filter = |
| 255 filter_builder.BuildWebsiteSettingsPatternMatchesFilter(); |
| 256 |
| 257 // Some backends support a filter that |is_null()| to make complete deletion |
| 258 // more efficient. |
| 259 base::Callback<bool(const GURL&)> nullable_filter = |
| 260 filter_builder.IsEmptyBlacklist() ? base::Callback<bool(const GURL&)>() |
| 261 : filter; |
| 262 |
| 263 // Managed devices and supervised users can have restrictions on history |
| 264 // deletion. |
| 265 PrefService* prefs = profile_->GetPrefs(); |
| 266 bool may_delete_history = prefs->GetBoolean( |
| 267 prefs::kAllowDeletingBrowserHistory); |
| 268 |
| 269 ////////////////////////////////////////////////////////////////////////////// |
| 270 // REMOVE_HISTORY |
| 271 if ((remove_mask & BrowsingDataRemover::REMOVE_HISTORY) && |
| 272 may_delete_history) { |
| 273 history::HistoryService* history_service = |
| 274 HistoryServiceFactory::GetForProfile( |
| 275 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 276 if (history_service) { |
| 277 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 278 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
| 279 clear_history_.Start(); |
| 280 history_service->ExpireLocalAndRemoteHistoryBetween( |
| 281 WebHistoryServiceFactory::GetForProfile(profile_), std::set<GURL>(), |
| 282 delete_begin_, delete_end_, |
| 283 clear_history_.GetCompletionCallback(), |
| 284 &history_task_tracker_); |
| 285 } |
| 286 |
| 287 // Currently, ContentSuggestionService instance exists only on Android. |
| 288 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 289 ContentSuggestionsServiceFactory::GetForProfileIfExists(profile_); |
| 290 if (content_suggestions_service) { |
| 291 content_suggestions_service->ClearHistory(delete_begin_, delete_end_, |
| 292 filter); |
| 293 } |
| 294 |
| 295 // Remove the last visit dates meta-data from the bookmark model. |
| 296 // TODO(vitaliii): Do not remove all dates, but only the ones matched by the |
| 297 // time range and the filter. |
| 298 bookmarks::BookmarkModel* bookmark_model = |
| 299 BookmarkModelFactory::GetForBrowserContext(profile_); |
| 300 if (bookmark_model) |
| 301 ntp_snippets::RemoveAllLastVisitDates(bookmark_model); |
| 302 |
| 303 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 304 // The extension activity log contains details of which websites extensions |
| 305 // were active on. It therefore indirectly stores details of websites a |
| 306 // user has visited so best clean from here as well. |
| 307 // TODO(msramek): Support all backends with filter (crbug.com/589586). |
| 308 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs( |
| 309 std::set<GURL>()); |
| 310 |
| 311 // Clear launch times as they are a form of history. |
| 312 // BrowsingDataFilterBuilder currently doesn't support extension origins. |
| 313 // Therefore, clearing history for a small set of origins (WHITELIST) should |
| 314 // never delete any extension launch times, while clearing for almost all |
| 315 // origins (BLACKLIST) should always delete all of extension launch times. |
| 316 if (filter_builder.mode() == BrowsingDataFilterBuilder::BLACKLIST) { |
| 317 extensions::ExtensionPrefs* extension_prefs = |
| 318 extensions::ExtensionPrefs::Get(profile_); |
| 319 extension_prefs->ClearLastLaunchTimes(); |
| 320 } |
| 321 #endif |
| 322 |
| 323 // Need to clear the host cache and accumulated speculative data, as it also |
| 324 // reveals some history. We have no mechanism to track when these items were |
| 325 // created, so we'll not honor the time range. |
| 326 // TODO(msramek): We can use the plugin filter here because plugins, same |
| 327 // as the hostname resolution cache, key their entries by hostname. Rename |
| 328 // BuildPluginFilter() to something more general to reflect this use. |
| 329 if (g_browser_process->io_thread()) { |
| 330 clear_hostname_resolution_cache_.Start(); |
| 331 BrowserThread::PostTaskAndReply( |
| 332 BrowserThread::IO, FROM_HERE, |
| 333 base::Bind(&ClearHostnameResolutionCacheOnIOThread, |
| 334 g_browser_process->io_thread(), |
| 335 filter_builder.BuildPluginFilter()), |
| 336 clear_hostname_resolution_cache_.GetCompletionCallback()); |
| 337 } |
| 338 if (profile_->GetNetworkPredictor()) { |
| 339 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 340 clear_network_predictor_.Start(); |
| 341 BrowserThread::PostTaskAndReply( |
| 342 BrowserThread::IO, FROM_HERE, |
| 343 base::Bind(&ClearNetworkPredictorOnIOThread, |
| 344 profile_->GetNetworkPredictor()), |
| 345 clear_network_predictor_.GetCompletionCallback()); |
| 346 profile_->GetNetworkPredictor()->ClearPrefsOnUIThread(); |
| 347 } |
| 348 |
| 349 // As part of history deletion we also delete the auto-generated keywords. |
| 350 TemplateURLService* keywords_model = |
| 351 TemplateURLServiceFactory::GetForProfile(profile_); |
| 352 |
| 353 if (keywords_model && !keywords_model->loaded()) { |
| 354 // TODO(msramek): Store filters from the currently executed task on the |
| 355 // object to avoid having to copy them to callback methods. |
| 356 template_url_sub_ = keywords_model->RegisterOnLoadedCallback( |
| 357 base::Bind(&ChromeBrowsingDataRemoverDelegate::OnKeywordsLoaded, |
| 358 weak_ptr_factory_.GetWeakPtr(), filter)); |
| 359 keywords_model->Load(); |
| 360 clear_keyword_data_.Start(); |
| 361 } else if (keywords_model) { |
| 362 keywords_model->RemoveAutoGeneratedForUrlsBetween(filter, delete_begin_, |
| 363 delete_end_); |
| 364 } |
| 365 |
| 366 // The PrerenderManager keeps history of prerendered pages, so clear that. |
| 367 // It also may have a prerendered page. If so, the page could be |
| 368 // considered to have a small amount of historical information, so delete |
| 369 // it, too. |
| 370 prerender::PrerenderManager* prerender_manager = |
| 371 prerender::PrerenderManagerFactory::GetForBrowserContext(profile_); |
| 372 if (prerender_manager) { |
| 373 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 374 prerender_manager->ClearData( |
| 375 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | |
| 376 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); |
| 377 } |
| 378 |
| 379 // If the caller is removing history for all hosts, then clear ancillary |
| 380 // historical information. |
| 381 if (filter_builder.IsEmptyBlacklist()) { |
| 382 // We also delete the list of recently closed tabs. Since these expire, |
| 383 // they can't be more than a day old, so we can simply clear them all. |
| 384 sessions::TabRestoreService* tab_service = |
| 385 TabRestoreServiceFactory::GetForProfile(profile_); |
| 386 if (tab_service) { |
| 387 tab_service->ClearEntries(); |
| 388 tab_service->DeleteLastSession(); |
| 389 } |
| 390 |
| 391 #if BUILDFLAG(ENABLE_SESSION_SERVICE) |
| 392 // We also delete the last session when we delete the history. |
| 393 SessionService* session_service = |
| 394 SessionServiceFactory::GetForProfile(profile_); |
| 395 if (session_service) |
| 396 session_service->DeleteLastSession(); |
| 397 #endif |
| 398 } |
| 399 |
| 400 // The saved Autofill profiles and credit cards can include the origin from |
| 401 // which these profiles and credit cards were learned. These are a form of |
| 402 // history, so clear them as well. |
| 403 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 404 scoped_refptr<autofill::AutofillWebDataService> web_data_service = |
| 405 WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 406 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 407 if (web_data_service.get()) { |
| 408 clear_autofill_origin_urls_.Start(); |
| 409 web_data_service->RemoveOriginURLsModifiedBetween( |
| 410 delete_begin_, delete_end_); |
| 411 // The above calls are done on the UI thread but do their work on the DB |
| 412 // thread. So wait for it. |
| 413 BrowserThread::PostTaskAndReply( |
| 414 BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing), |
| 415 clear_autofill_origin_urls_.GetCompletionCallback()); |
| 416 |
| 417 autofill::PersonalDataManager* data_manager = |
| 418 autofill::PersonalDataManagerFactory::GetForProfile(profile_); |
| 419 if (data_manager) |
| 420 data_manager->Refresh(); |
| 421 } |
| 422 |
| 423 #if BUILDFLAG(ENABLE_WEBRTC) |
| 424 clear_webrtc_logs_.Start(); |
| 425 BrowserThread::PostTaskAndReply( |
| 426 BrowserThread::FILE, FROM_HERE, |
| 427 base::Bind( |
| 428 &WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles, |
| 429 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()), |
| 430 delete_begin_), |
| 431 clear_webrtc_logs_.GetCompletionCallback()); |
| 432 #endif |
| 433 |
| 434 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 435 precache::PrecacheManager* precache_manager = |
| 436 precache::PrecacheManagerFactory::GetForBrowserContext(profile_); |
| 437 // |precache_manager| could be nullptr if the profile is off the record. |
| 438 if (!precache_manager) { |
| 439 clear_precache_history_.Start(); |
| 440 precache_manager->ClearHistory(); |
| 441 // The above calls are done on the UI thread but do their work on the DB |
| 442 // thread. So wait for it. |
| 443 BrowserThread::PostTaskAndReply( |
| 444 BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing), |
| 445 clear_precache_history_.GetCompletionCallback()); |
| 446 } |
| 447 |
| 448 // Clear the history information (last launch time and origin URL) of any |
| 449 // registered webapps. |
| 450 webapp_registry_->ClearWebappHistoryForUrls(filter); |
| 451 #endif |
| 452 |
| 453 data_reduction_proxy::DataReductionProxySettings* |
| 454 data_reduction_proxy_settings = |
| 455 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 456 profile_); |
| 457 // |data_reduction_proxy_settings| is null if |profile_| is off the record. |
| 458 if (data_reduction_proxy_settings) { |
| 459 data_reduction_proxy::DataReductionProxyService* |
| 460 data_reduction_proxy_service = |
| 461 data_reduction_proxy_settings->data_reduction_proxy_service(); |
| 462 if (data_reduction_proxy_service) { |
| 463 data_reduction_proxy_service->compression_stats() |
| 464 ->DeleteBrowsingHistory(delete_begin_, delete_end_); |
| 465 } |
| 466 } |
| 467 |
| 468 // |previews_service| is null if |profile_| is off the record. |
| 469 PreviewsService* previews_service = |
| 470 PreviewsServiceFactory::GetForProfile(profile_); |
| 471 if (previews_service && previews_service->previews_ui_service()) { |
| 472 previews_service->previews_ui_service()->ClearBlackList(delete_begin_, |
| 473 delete_end_); |
| 474 } |
| 475 } |
| 476 |
| 477 ////////////////////////////////////////////////////////////////////////////// |
| 478 // REMOVE_COOKIES |
| 479 // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set, |
| 480 // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB |
| 481 // don't accidentally remove the cookies that are associated with the |
| 482 // UNPROTECTED_WEB origin. This is necessary because cookies are not separated |
| 483 // between UNPROTECTED_WEB and PROTECTED_WEB. |
| 484 if (remove_mask & BrowsingDataRemover::REMOVE_COOKIES && |
| 485 origin_type_mask & BrowsingDataHelper::UNPROTECTED_WEB) { |
| 486 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); |
| 487 |
| 488 // Clear the safebrowsing cookies only if time period is for "all time". It |
| 489 // doesn't make sense to apply the time period of deleting in the last X |
| 490 // hours/days to the safebrowsing cookies since they aren't the result of |
| 491 // any user action. |
| 492 if (delete_begin_ == base::Time()) { |
| 493 safe_browsing::SafeBrowsingService* sb_service = |
| 494 g_browser_process->safe_browsing_service(); |
| 495 if (sb_service) { |
| 496 scoped_refptr<net::URLRequestContextGetter> sb_context = |
| 497 sb_service->url_request_context(); |
| 498 ++clear_cookies_count_; |
| 499 if (filter_builder.IsEmptyBlacklist()) { |
| 500 BrowserThread::PostTask( |
| 501 BrowserThread::IO, FROM_HERE, |
| 502 base::Bind( |
| 503 &ClearCookiesOnIOThread, delete_begin_, delete_end_, |
| 504 base::RetainedRef(std::move(sb_context)), |
| 505 UIThreadTrampoline( |
| 506 base::Bind( |
| 507 &ChromeBrowsingDataRemoverDelegate::OnClearedCookies, |
| 508 weak_ptr_factory_.GetWeakPtr())))); |
| 509 } else { |
| 510 BrowserThread::PostTask( |
| 511 BrowserThread::IO, FROM_HERE, |
| 512 base::Bind( |
| 513 &ClearCookiesWithPredicateOnIOThread, delete_begin_, |
| 514 delete_end_, filter_builder.BuildCookieFilter(), |
| 515 base::RetainedRef(std::move(sb_context)), |
| 516 UIThreadTrampoline( |
| 517 base::Bind( |
| 518 &ChromeBrowsingDataRemoverDelegate::OnClearedCookies, |
| 519 weak_ptr_factory_.GetWeakPtr())))); |
| 520 } |
| 521 } |
| 522 } |
| 523 |
| 524 MediaDeviceIDSalt::Reset(profile_->GetPrefs()); |
| 525 } |
| 526 |
| 527 ////////////////////////////////////////////////////////////////////////////// |
| 528 // REMOVE_DURABLE_PERMISSION |
| 529 if (remove_mask & BrowsingDataRemover::REMOVE_DURABLE_PERMISSION) { |
| 530 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 531 ->ClearSettingsForOneTypeWithPredicate( |
| 532 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, |
| 533 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter)); |
| 534 } |
| 535 |
| 536 ////////////////////////////////////////////////////////////////////////////// |
| 537 // REMOVE_SITE_USAGE_DATA |
| 538 if (remove_mask & BrowsingDataRemover::REMOVE_SITE_USAGE_DATA) { |
| 539 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 540 ->ClearSettingsForOneTypeWithPredicate( |
| 541 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
| 542 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter)); |
| 543 } |
| 544 |
| 545 if ((remove_mask & BrowsingDataRemover::REMOVE_SITE_USAGE_DATA) || |
| 546 (remove_mask & BrowsingDataRemover::REMOVE_HISTORY)) { |
| 547 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 548 ->ClearSettingsForOneTypeWithPredicate( |
| 549 CONTENT_SETTINGS_TYPE_APP_BANNER, |
| 550 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter)); |
| 551 |
| 552 PermissionDecisionAutoBlocker::RemoveCountsByUrl(profile_, filter); |
| 553 } |
| 554 |
| 555 ////////////////////////////////////////////////////////////////////////////// |
| 556 // Password manager |
| 557 if (remove_mask & BrowsingDataRemover::REMOVE_PASSWORDS) { |
| 558 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords")); |
| 559 password_manager::PasswordStore* password_store = |
| 560 PasswordStoreFactory::GetForProfile( |
| 561 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); |
| 562 |
| 563 if (password_store) { |
| 564 clear_passwords_.Start(); |
| 565 password_store->RemoveLoginsByURLAndTime( |
| 566 filter, delete_begin_, delete_end_, |
| 567 clear_passwords_.GetCompletionCallback()); |
| 568 } |
| 569 } |
| 570 |
| 571 if (remove_mask & BrowsingDataRemover::REMOVE_COOKIES) { |
| 572 password_manager::PasswordStore* password_store = |
| 573 PasswordStoreFactory::GetForProfile(profile_, |
| 574 ServiceAccessType::EXPLICIT_ACCESS) |
| 575 .get(); |
| 576 |
| 577 if (password_store) { |
| 578 clear_auto_sign_in_.Start(); |
| 579 password_store->DisableAutoSignInForOrigins( |
| 580 filter, clear_auto_sign_in_.GetCompletionCallback()); |
| 581 } |
| 582 } |
| 583 |
| 584 if (remove_mask & BrowsingDataRemover::REMOVE_HISTORY) { |
| 585 password_manager::PasswordStore* password_store = |
| 586 PasswordStoreFactory::GetForProfile( |
| 587 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); |
| 588 |
| 589 if (password_store) { |
| 590 clear_passwords_stats_.Start(); |
| 591 password_store->RemoveStatisticsByOriginAndTime( |
| 592 nullable_filter, delete_begin_, delete_end_, |
| 593 clear_passwords_stats_.GetCompletionCallback()); |
| 594 } |
| 595 } |
| 596 |
| 597 ////////////////////////////////////////////////////////////////////////////// |
| 598 // REMOVE_FORM_DATA |
| 599 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 600 if (remove_mask & BrowsingDataRemover::REMOVE_FORM_DATA) { |
| 601 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill")); |
| 602 scoped_refptr<autofill::AutofillWebDataService> web_data_service = |
| 603 WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 604 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 605 |
| 606 if (web_data_service.get()) { |
| 607 clear_form_.Start(); |
| 608 web_data_service->RemoveFormElementsAddedBetween(delete_begin_, |
| 609 delete_end_); |
| 610 web_data_service->RemoveAutofillDataModifiedBetween( |
| 611 delete_begin_, delete_end_); |
| 612 // The above calls are done on the UI thread but do their work on the DB |
| 613 // thread. So wait for it. |
| 614 BrowserThread::PostTaskAndReply( |
| 615 BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing), |
| 616 clear_form_.GetCompletionCallback()); |
| 617 |
| 618 autofill::PersonalDataManager* data_manager = |
| 619 autofill::PersonalDataManagerFactory::GetForProfile(profile_); |
| 620 if (data_manager) |
| 621 data_manager->Refresh(); |
| 622 } |
| 623 } |
| 624 |
| 625 ////////////////////////////////////////////////////////////////////////////// |
| 626 // REMOVE_CACHE |
| 627 if (remove_mask & BrowsingDataRemover::REMOVE_CACHE) { |
| 628 #if !defined(DISABLE_NACL) |
| 629 clear_nacl_cache_.Start(); |
| 630 |
| 631 BrowserThread::PostTask( |
| 632 BrowserThread::IO, FROM_HERE, |
| 633 base::Bind(&ClearNaClCacheOnIOThread, |
| 634 UIThreadTrampoline( |
| 635 clear_nacl_cache_.GetCompletionCallback()))); |
| 636 |
| 637 clear_pnacl_cache_.Start(); |
| 638 BrowserThread::PostTask( |
| 639 BrowserThread::IO, FROM_HERE, |
| 640 base::Bind( |
| 641 &ClearPnaclCacheOnIOThread, delete_begin_, delete_end_, |
| 642 UIThreadTrampoline(clear_pnacl_cache_.GetCompletionCallback()))); |
| 643 #endif |
| 644 |
| 645 // The PrerenderManager may have a page actively being prerendered, which |
| 646 // is essentially a preemptively cached page. |
| 647 prerender::PrerenderManager* prerender_manager = |
| 648 prerender::PrerenderManagerFactory::GetForBrowserContext(profile_); |
| 649 if (prerender_manager) { |
| 650 prerender_manager->ClearData( |
| 651 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS); |
| 652 } |
| 653 |
| 654 // When clearing cache, wipe accumulated network related data |
| 655 // (TransportSecurityState and HttpServerPropertiesManager data). |
| 656 clear_networking_history_.Start(); |
| 657 profile_->ClearNetworkingHistorySince( |
| 658 delete_begin_, |
| 659 clear_networking_history_.GetCompletionCallback()); |
| 660 |
| 661 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 662 ContentSuggestionsServiceFactory::GetForProfileIfExists(profile_); |
| 663 if (content_suggestions_service) |
| 664 content_suggestions_service->ClearAllCachedSuggestions(); |
| 665 |
| 666 // |ui_nqe_service| may be null if |profile_| is not a regular profile. |
| 667 UINetworkQualityEstimatorService* ui_nqe_service = |
| 668 UINetworkQualityEstimatorServiceFactory::GetForProfile(profile_); |
| 669 DCHECK(profile_->GetProfileType() != |
| 670 Profile::ProfileType::REGULAR_PROFILE || |
| 671 ui_nqe_service != nullptr); |
| 672 if (ui_nqe_service) { |
| 673 // Network Quality Estimator (NQE) stores the quality (RTT, bandwidth |
| 674 // etc.) of different networks in prefs. The stored quality is not |
| 675 // broken down by URLs or timestamps, so clearing the cache should |
| 676 // completely clear the prefs. |
| 677 ui_nqe_service->ClearPrefs(); |
| 678 } |
| 679 |
| 680 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 681 // For now we're considering offline pages as cache, so if we're removing |
| 682 // cache we should remove offline pages as well. |
| 683 if ((remove_mask & BrowsingDataRemover::REMOVE_CACHE)) { |
| 684 clear_offline_page_data_.Start(); |
| 685 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_) |
| 686 ->DeleteCachedPagesByURLPredicate( |
| 687 filter, |
| 688 IgnoreArgument<offline_pages::OfflinePageModel::DeletePageResult>( |
| 689 clear_offline_page_data_.GetCompletionCallback())); |
| 690 } |
| 691 #endif |
| 692 } |
| 693 |
| 694 ////////////////////////////////////////////////////////////////////////////// |
| 695 // REMOVE_MEDIA_LICENSES |
| 696 if (remove_mask & BrowsingDataRemover::REMOVE_MEDIA_LICENSES) { |
| 697 // TODO(jrummell): This UMA should be renamed to indicate it is for Media |
| 698 // Licenses. |
| 699 content::RecordAction( |
| 700 UserMetricsAction("ClearBrowsingData_ContentLicenses")); |
| 701 |
| 702 #if BUILDFLAG(ENABLE_PLUGINS) |
| 703 clear_flash_content_licenses_.Start(); |
| 704 if (!pepper_flash_settings_manager_.get()) { |
| 705 pepper_flash_settings_manager_.reset( |
| 706 new PepperFlashSettingsManager(this, profile_)); |
| 707 } |
| 708 deauthorize_flash_content_licenses_request_id_ = |
| 709 pepper_flash_settings_manager_->DeauthorizeContentLicenses(prefs); |
| 710 #if defined(OS_CHROMEOS) |
| 711 // On Chrome OS, also delete any content protection platform keys. |
| 712 const user_manager::User* user = |
| 713 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| 714 if (!user) { |
| 715 LOG(WARNING) << "Failed to find user for current profile."; |
| 716 } else { |
| 717 clear_platform_keys_.Start(); |
| 718 chromeos::DBusThreadManager::Get() |
| 719 ->GetCryptohomeClient() |
| 720 ->TpmAttestationDeleteKeys( |
| 721 chromeos::attestation::KEY_USER, |
| 722 cryptohome::Identification(user->GetAccountId()), |
| 723 chromeos::attestation::kContentProtectionKeyPrefix, |
| 724 base::Bind( |
| 725 &ChromeBrowsingDataRemoverDelegate::OnClearPlatformKeys, |
| 726 weak_ptr_factory_.GetWeakPtr())); |
| 727 } |
| 728 #endif // defined(OS_CHROMEOS) |
| 729 #endif // BUILDFLAG(ENABLE_PLUGINS) |
| 730 } |
| 731 |
| 732 ////////////////////////////////////////////////////////////////////////////// |
| 733 // Zero suggest. |
| 734 // Remove omnibox zero-suggest cache results. Filtering is not supported. |
| 735 // This is not a problem, as deleting more data than necessary will just cause |
| 736 // another server round-trip; no data is actually lost. |
| 737 if ((remove_mask & (BrowsingDataRemover::REMOVE_CACHE | |
| 738 BrowsingDataRemover::REMOVE_COOKIES))) { |
| 739 prefs->SetString(omnibox::kZeroSuggestCachedResults, std::string()); |
| 740 } |
| 741 |
| 742 ////////////////////////////////////////////////////////////////////////////// |
| 743 // Domain reliability service. |
| 744 if (remove_mask & (BrowsingDataRemover::REMOVE_COOKIES | |
| 745 BrowsingDataRemover::REMOVE_HISTORY)) { |
| 746 domain_reliability::DomainReliabilityService* service = |
| 747 domain_reliability::DomainReliabilityServiceFactory:: |
| 748 GetForBrowserContext(profile_); |
| 749 if (service) { |
| 750 domain_reliability::DomainReliabilityClearMode mode; |
| 751 if (remove_mask & BrowsingDataRemover::REMOVE_COOKIES) |
| 752 mode = domain_reliability::CLEAR_CONTEXTS; |
| 753 else |
| 754 mode = domain_reliability::CLEAR_BEACONS; |
| 755 |
| 756 clear_domain_reliability_monitor_.Start(); |
| 757 service->ClearBrowsingData( |
| 758 mode, |
| 759 filter, |
| 760 clear_domain_reliability_monitor_.GetCompletionCallback()); |
| 761 } |
| 762 } |
| 763 |
| 764 ////////////////////////////////////////////////////////////////////////////// |
| 765 // REMOVE_WEBAPP_DATA |
| 766 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 767 // Clear all data associated with registered webapps. |
| 768 if (remove_mask & BrowsingDataRemover::REMOVE_WEBAPP_DATA) |
| 769 webapp_registry_->UnregisterWebappsForUrls(filter); |
| 770 #endif |
| 771 |
| 772 synchronous_clear_operations_.GetCompletionCallback().Run(); |
| 773 } |
| 774 |
| 775 void ChromeBrowsingDataRemoverDelegate::NotifyIfDone() { |
| 776 if (!AllDone()) |
| 777 return; |
| 778 |
| 779 DCHECK(!callback_.is_null()); |
| 780 callback_.Run(); |
| 781 } |
| 782 |
| 783 bool ChromeBrowsingDataRemoverDelegate::AllDone() { |
| 784 return !clear_cookies_count_ && |
| 785 !synchronous_clear_operations_.is_pending() && |
| 786 !clear_autofill_origin_urls_.is_pending() && |
| 787 !clear_flash_content_licenses_.is_pending() && |
| 788 !clear_domain_reliability_monitor_.is_pending() && |
| 789 !clear_form_.is_pending() && |
| 790 !clear_history_.is_pending() && |
| 791 !clear_hostname_resolution_cache_.is_pending() && |
| 792 !clear_keyword_data_.is_pending() && |
| 793 #if !defined(DISABLE_NACL) |
| 794 !clear_nacl_cache_.is_pending() && |
| 795 !clear_pnacl_cache_.is_pending() && |
| 796 #endif |
| 797 !clear_network_predictor_.is_pending() && |
| 798 !clear_networking_history_.is_pending() && |
| 799 !clear_passwords_.is_pending() && |
| 800 !clear_passwords_stats_.is_pending() && |
| 801 !clear_platform_keys_.is_pending() && |
| 802 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 803 !clear_precache_history_.is_pending() && |
| 804 !clear_offline_page_data_.is_pending() && |
| 805 #endif |
| 806 #if BUILDFLAG(ENABLE_WEBRTC) |
| 807 !clear_webrtc_logs_.is_pending() && |
| 808 #endif |
| 809 !clear_auto_sign_in_.is_pending(); |
| 810 } |
| 811 |
| 812 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 813 void ChromeBrowsingDataRemoverDelegate::OverrideWebappRegistryForTesting( |
| 814 std::unique_ptr<WebappRegistry> webapp_registry) { |
| 815 webapp_registry_ = std::move(webapp_registry); |
| 816 } |
| 817 #endif |
| 818 |
| 819 void ChromeBrowsingDataRemoverDelegate::OnKeywordsLoaded( |
| 820 base::Callback<bool(const GURL&)> url_filter) { |
| 821 // Deletes the entries from the model. |
| 822 TemplateURLService* model = |
| 823 TemplateURLServiceFactory::GetForProfile(profile_); |
| 824 model->RemoveAutoGeneratedForUrlsBetween(url_filter, delete_begin_, |
| 825 delete_end_); |
| 826 template_url_sub_.reset(); |
| 827 clear_keyword_data_.GetCompletionCallback().Run(); |
| 828 } |
| 829 |
| 830 void ChromeBrowsingDataRemoverDelegate::OnClearedCookies() { |
| 831 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 832 |
| 833 DCHECK_GT(clear_cookies_count_, 0); |
| 834 --clear_cookies_count_; |
| 835 NotifyIfDone(); |
| 836 } |
| 837 |
| 838 #if BUILDFLAG(ENABLE_PLUGINS) |
| 839 void ChromeBrowsingDataRemoverDelegate:: |
| 840 OnDeauthorizeFlashContentLicensesCompleted( |
| 841 uint32_t request_id, |
| 842 bool /* success */) { |
| 843 DCHECK_EQ(request_id, deauthorize_flash_content_licenses_request_id_); |
| 844 clear_flash_content_licenses_.GetCompletionCallback().Run(); |
| 845 } |
| 846 #endif |
| 847 |
| 848 #if defined(OS_CHROMEOS) |
| 849 void ChromeBrowsingDataRemoverDelegate::OnClearPlatformKeys( |
| 850 chromeos::DBusMethodCallStatus call_status, |
| 851 bool result) { |
| 852 LOG_IF(ERROR, call_status != chromeos::DBUS_METHOD_CALL_SUCCESS || !result) |
| 853 << "Failed to clear platform keys."; |
| 854 clear_platform_keys_.GetCompletionCallback().Run(); |
| 855 } |
| 856 #endif |
OLD | NEW |