Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover.cc

Issue 1741123002: Add removal filter support for Cookies, Storage, and Content Settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed class, comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data/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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/browser/autofill/personal_data_manager_factory.h" 17 #include "chrome/browser/autofill/personal_data_manager_factory.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browsing_data/browsing_data_helper.h" 19 #include "chrome/browser/browsing_data/browsing_data_helper.h"
20 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 20 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
21 #include "chrome/browser/browsing_data/origin_filter_builder.h" 21 #include "chrome/browser/browsing_data/browsing_data_remover_filter.h"
22 #include "chrome/browser/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
24 #include "chrome/browser/domain_reliability/service_factory.h" 24 #include "chrome/browser/domain_reliability/service_factory.h"
25 #include "chrome/browser/download/download_prefs.h" 25 #include "chrome/browser/download/download_prefs.h"
26 #include "chrome/browser/history/history_service_factory.h" 26 #include "chrome/browser/history/history_service_factory.h"
27 #include "chrome/browser/history/web_history_service_factory.h" 27 #include "chrome/browser/history/web_history_service_factory.h"
28 #include "chrome/browser/io_thread.h" 28 #include "chrome/browser/io_thread.h"
29 #include "chrome/browser/media/media_device_id_salt.h" 29 #include "chrome/browser/media/media_device_id_salt.h"
30 #include "chrome/browser/net/predictor.h" 30 #include "chrome/browser/net/predictor.h"
31 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 31 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
32 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 32 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
33 #include "chrome/browser/password_manager/password_store_factory.h" 33 #include "chrome/browser/password_manager/password_store_factory.h"
34 #include "chrome/browser/prerender/prerender_manager.h" 34 #include "chrome/browser/prerender/prerender_manager.h"
35 #include "chrome/browser/prerender/prerender_manager_factory.h" 35 #include "chrome/browser/prerender/prerender_manager_factory.h"
36 #include "chrome/browser/profiles/profile.h" 36 #include "chrome/browser/profiles/profile.h"
37 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 37 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
38 #include "chrome/browser/search_engines/template_url_service_factory.h" 38 #include "chrome/browser/search_engines/template_url_service_factory.h"
39 #include "chrome/browser/sessions/tab_restore_service_factory.h" 39 #include "chrome/browser/sessions/tab_restore_service_factory.h"
40 #include "chrome/browser/web_data_service_factory.h" 40 #include "chrome/browser/web_data_service_factory.h"
41 #include "chrome/common/features.h" 41 #include "chrome/common/features.h"
42 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
43 #include "chrome/common/url_constants.h" 43 #include "chrome/common/url_constants.h"
44 #include "components/autofill/core/browser/personal_data_manager.h" 44 #include "components/autofill/core/browser/personal_data_manager.h"
45 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 45 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
46 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" 46 #include "components/browsing_data/storage_partition_http_cache_data_remover.h"
47 #include "components/content_settings/core/browser/host_content_settings_map.h" 47 #include "components/content_settings/core/browser/host_content_settings_map.h"
48 #include "components/content_settings/core/common/content_settings.h"
49 #include "components/content_settings/core/common/content_settings_pattern.h"
48 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h" 50 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h"
49 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" 51 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
50 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" 52 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
51 #include "components/domain_reliability/service.h" 53 #include "components/domain_reliability/service.h"
52 #include "components/history/core/browser/history_service.h" 54 #include "components/history/core/browser/history_service.h"
53 #include "components/nacl/browser/nacl_browser.h" 55 #include "components/nacl/browser/nacl_browser.h"
54 #include "components/nacl/browser/pnacl_host.h" 56 #include "components/nacl/browser/pnacl_host.h"
55 #include "components/omnibox/browser/omnibox_pref_names.h" 57 #include "components/omnibox/browser/omnibox_pref_names.h"
56 #include "components/password_manager/core/browser/password_store.h" 58 #include "components/password_manager/core/browser/password_store.h"
57 #include "components/power/origin_power_map.h" 59 #include "components/power/origin_power_map.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 152 }
151 153
152 // Another convenience method to turn a callback without arguments into one that 154 // Another convenience method to turn a callback without arguments into one that
153 // accepts (and ignores) a single argument. 155 // accepts (and ignores) a single argument.
154 template <typename T> 156 template <typename T>
155 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) { 157 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) {
156 return base::Bind(&IgnoreArgumentHelper<T>, callback); 158 return base::Bind(&IgnoreArgumentHelper<T>, callback);
157 } 159 }
158 160
159 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask. 161 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask.
160 bool DoesOriginMatchMask( 162 bool DoesOriginMatchMaskAndUrls(
161 int origin_type_mask, 163 int origin_type_mask,
164 const base::Callback<bool(const GURL&)>& predicate,
162 const GURL& origin, 165 const GURL& origin,
163 storage::SpecialStoragePolicy* special_storage_policy) { 166 storage::SpecialStoragePolicy* special_storage_policy) {
164 return BrowsingDataHelper::DoesOriginMatchMask( 167 return predicate.Run(origin) &&
165 origin, origin_type_mask, special_storage_policy); 168 BrowsingDataHelper::DoesOriginMatchMask(origin, origin_type_mask,
169 special_storage_policy);
170 }
171
172 bool ForwardPrimaryPatternCallback(
173 const base::Callback<bool(const ContentSettingsPattern&)> predicate,
174 const ContentSettingsPattern& primary_pattern,
175 const ContentSettingsPattern& secondary_pattern) {
176 return predicate.Run(primary_pattern);
166 } 177 }
167 178
168 void ClearHostnameResolutionCacheOnIOThread(IOThread* io_thread) { 179 void ClearHostnameResolutionCacheOnIOThread(IOThread* io_thread) {
169 DCHECK_CURRENTLY_ON(BrowserThread::IO); 180 DCHECK_CURRENTLY_ON(BrowserThread::IO);
170 181
171 io_thread->ClearHostCache(); 182 io_thread->ClearHostCache();
172 } 183 }
173 184
174 void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) { 185 void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) {
175 DCHECK_CURRENTLY_ON(BrowserThread::IO); 186 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 24 matching lines...) Expand all
200 base::Time delete_end, 211 base::Time delete_end,
201 net::URLRequestContextGetter* rq_context, 212 net::URLRequestContextGetter* rq_context,
202 const base::Closure& callback) { 213 const base::Closure& callback) {
203 DCHECK_CURRENTLY_ON(BrowserThread::IO); 214 DCHECK_CURRENTLY_ON(BrowserThread::IO);
204 net::CookieStore* cookie_store = 215 net::CookieStore* cookie_store =
205 rq_context->GetURLRequestContext()->cookie_store(); 216 rq_context->GetURLRequestContext()->cookie_store();
206 cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, 217 cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
207 IgnoreArgument<int>(callback)); 218 IgnoreArgument<int>(callback));
208 } 219 }
209 220
221 void ClearCookiesWithPredicateOnIOThread(
222 base::Time delete_begin,
223 base::Time delete_end,
224 net::CookieStore::CookiePredicate predicate,
225 net::URLRequestContextGetter* rq_context,
226 const base::Closure& callback) {
227 DCHECK_CURRENTLY_ON(BrowserThread::IO);
228 net::CookieStore* cookie_store =
229 rq_context->GetURLRequestContext()->cookie_store();
230 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
231 delete_begin, delete_end, predicate, IgnoreArgument<int>(callback));
232 }
233
210 void OnClearedChannelIDsOnIOThread(net::URLRequestContextGetter* rq_context, 234 void OnClearedChannelIDsOnIOThread(net::URLRequestContextGetter* rq_context,
211 const base::Closure& callback) { 235 const base::Closure& callback) {
212 DCHECK_CURRENTLY_ON(BrowserThread::IO); 236 DCHECK_CURRENTLY_ON(BrowserThread::IO);
213 237
214 // Need to close open SSL connections which may be using the channel ids we 238 // Need to close open SSL connections which may be using the channel ids we
215 // are deleting. 239 // are deleting.
216 // TODO(mattm): http://crbug.com/166069 Make the server bound cert 240 // TODO(mattm): http://crbug.com/166069 Make the server bound cert
217 // service/store have observers that can notify relevant things directly. 241 // service/store have observers that can notify relevant things directly.
218 rq_context->GetURLRequestContext() 242 rq_context->GetURLRequestContext()
219 ->ssl_config_service() 243 ->ssl_config_service()
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 348 }
325 349
326 void BrowsingDataRemover::SetRemoving(bool is_removing) { 350 void BrowsingDataRemover::SetRemoving(bool is_removing) {
327 DCHECK_NE(is_removing_, is_removing); 351 DCHECK_NE(is_removing_, is_removing);
328 is_removing_ = is_removing; 352 is_removing_ = is_removing;
329 } 353 }
330 354
331 void BrowsingDataRemover::Remove(const TimeRange& time_range, 355 void BrowsingDataRemover::Remove(const TimeRange& time_range,
332 int remove_mask, 356 int remove_mask,
333 int origin_type_mask) { 357 int origin_type_mask) {
334 RemoveImpl(time_range, remove_mask, GURL(), origin_type_mask); 358 BrowsingDataRemoverFilter builder(BrowsingDataRemoverFilter::BLACKLIST);
359 RemoveImpl(time_range, remove_mask, builder, origin_type_mask);
335 } 360 }
336 361
337 void BrowsingDataRemover::RemoveImpl(const TimeRange& time_range, 362 void BrowsingDataRemover::RemoveWithFilter(
338 int remove_mask, 363 const TimeRange& time_range,
339 const GURL& remove_url, 364 int remove_mask,
340 int origin_type_mask) { 365 int origin_type_mask,
366 const BrowsingDataRemoverFilter& origin_filter) {
msramek 2016/04/07 16:19:12 nit: rename the parameter to match the new class n
dmurph 2016/04/08 23:33:44 Done.
367 RemoveImpl(time_range, remove_mask, origin_filter, origin_type_mask);
368 }
369
370 void BrowsingDataRemover::RemoveImpl(
371 const TimeRange& time_range,
372 int remove_mask,
373 const BrowsingDataRemoverFilter& origin_filter,
374 int origin_type_mask) {
341 DCHECK_CURRENTLY_ON(BrowserThread::UI); 375 DCHECK_CURRENTLY_ON(BrowserThread::UI);
342 376
343 // crbug.com/140910: Many places were calling this with base::Time() as 377 // crbug.com/140910: Many places were calling this with base::Time() as
344 // delete_end, even though they should've used base::Time::Max(). 378 // delete_end, even though they should've used base::Time::Max().
345 DCHECK_NE(base::Time(), time_range.end); 379 DCHECK_NE(base::Time(), time_range.end);
346 380
347 SetRemoving(true); 381 SetRemoving(true);
348 delete_begin_ = time_range.begin; 382 delete_begin_ = time_range.begin;
349 delete_end_ = time_range.end; 383 delete_end_ = time_range.end;
350 remove_mask_ = remove_mask; 384 remove_mask_ = remove_mask;
351 origin_type_mask_ = origin_type_mask; 385 origin_type_mask_ = origin_type_mask;
352 386
353 // TODO(msramek): Replace |remove_origin| with |filter| in all backends.
354 const url::Origin remove_origin(remove_url);
355 OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
356 if (!remove_url.is_empty()) {
357 // Make sure that only URLs representing origins, with no extra components,
358 // are passed to this class.
359 DCHECK_EQ(remove_url, remove_url.GetOrigin());
360 builder.SetMode(OriginFilterBuilder::WHITELIST);
361 builder.AddOrigin(url::Origin(remove_origin));
362 }
363 base::Callback<bool(const GURL& url)> same_origin_filter = 387 base::Callback<bool(const GURL& url)> same_origin_filter =
364 builder.BuildSameOriginFilter(); 388 origin_filter.BuildSameOriginOrDomainFilter();
389 base::Callback<bool(const ContentSettingsPattern& url)> same_pattern_filter =
390 origin_filter.BuildWebsiteSettingsPatternMatchesFilter();
365 391
366 PrefService* prefs = profile_->GetPrefs(); 392 PrefService* prefs = profile_->GetPrefs();
367 bool may_delete_history = prefs->GetBoolean( 393 bool may_delete_history = prefs->GetBoolean(
368 prefs::kAllowDeletingBrowserHistory); 394 prefs::kAllowDeletingBrowserHistory);
369 395
370 // All the UI entry points into the BrowsingDataRemover should be disabled, 396 // All the UI entry points into the BrowsingDataRemover should be disabled,
371 // but this will fire if something was missed or added. 397 // but this will fire if something was missed or added.
372 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) || 398 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
373 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS))); 399 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
374 400
(...skipping 15 matching lines...) Expand all
390 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB | 416 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB |
391 BrowsingDataHelper::PROTECTED_WEB | 417 BrowsingDataHelper::PROTECTED_WEB |
392 BrowsingDataHelper::EXTENSION), 418 BrowsingDataHelper::EXTENSION),
393 "OriginTypeMask has been updated without updating user metrics"); 419 "OriginTypeMask has been updated without updating user metrics");
394 420
395 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { 421 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
396 history::HistoryService* history_service = 422 history::HistoryService* history_service =
397 HistoryServiceFactory::GetForProfile( 423 HistoryServiceFactory::GetForProfile(
398 profile_, ServiceAccessType::EXPLICIT_ACCESS); 424 profile_, ServiceAccessType::EXPLICIT_ACCESS);
399 if (history_service) { 425 if (history_service) {
400 // Selective history deletion is currently done through HistoryUI -> 426 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
401 // HistoryBackend -> HistoryService, and that is for individual URLs,
402 // not origins. The code below is currently unused, as the only callsite
403 // supplying |remove_url| is the unittest.
404 // TODO(msramek): Make it possible to delete history per origin, not just
405 // per URL, and use that functionality here.
406 std::set<GURL> restrict_urls;
407 if (!remove_url.is_empty())
408 restrict_urls.insert(remove_url);
409 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); 427 content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
410 waiting_for_clear_history_ = true; 428 waiting_for_clear_history_ = true;
411
412 history_service->ExpireLocalAndRemoteHistoryBetween( 429 history_service->ExpireLocalAndRemoteHistoryBetween(
413 WebHistoryServiceFactory::GetForProfile(profile_), restrict_urls, 430 WebHistoryServiceFactory::GetForProfile(profile_), std::set<GURL>(),
414 delete_begin_, delete_end_, 431 delete_begin_, delete_end_,
415 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, 432 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
416 weak_ptr_factory_.GetWeakPtr()), 433 weak_ptr_factory_.GetWeakPtr()),
417 &history_task_tracker_); 434 &history_task_tracker_);
418 435
419 #if defined(ENABLE_EXTENSIONS) 436 #if defined(ENABLE_EXTENSIONS)
420 // The extension activity contains details of which websites extensions 437 // The extension activity contains details of which websites extensions
421 // were active on. It therefore indirectly stores details of websites a 438 // were active on. It therefore indirectly stores details of websites a
422 // user has visited so best clean from here as well. 439 // user has visited so best clean from here as well.
423 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(restrict_urls); 440 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(
441 std::set<GURL>());
424 #endif 442 #endif
425 } 443 }
426 444
427 #if defined(ENABLE_EXTENSIONS) 445 #if defined(ENABLE_EXTENSIONS)
428 // Clear launch times as they are a form of history. 446 // Clear launch times as they are a form of history.
429 extensions::ExtensionPrefs* extension_prefs = 447 extensions::ExtensionPrefs* extension_prefs =
430 extensions::ExtensionPrefs::Get(profile_); 448 extensions::ExtensionPrefs::Get(profile_);
431 extension_prefs->ClearLastLaunchTimes(); 449 extension_prefs->ClearLastLaunchTimes();
432 #endif 450 #endif
433 451
434 // The power consumption history by origin contains details of websites 452 // The power consumption history by origin contains details of websites
435 // that were visited. 453 // that were visited.
454 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
436 power::OriginPowerMap* origin_power_map = 455 power::OriginPowerMap* origin_power_map =
437 power::OriginPowerMapFactory::GetForBrowserContext(profile_); 456 power::OriginPowerMapFactory::GetForBrowserContext(profile_);
438 if (origin_power_map) 457 if (origin_power_map)
439 origin_power_map->ClearOriginMap(); 458 origin_power_map->ClearOriginMap();
440 459
441 // Need to clear the host cache and accumulated speculative data, as it also 460 // Need to clear the host cache and accumulated speculative data, as it also
442 // reveals some history: we have no mechanism to track when these items were 461 // reveals some history: we have no mechanism to track when these items were
443 // created, so we'll clear them all. Better safe than sorry. 462 // created, so we'll clear them all. Better safe than sorry.
444 if (g_browser_process->io_thread()) { 463 if (g_browser_process->io_thread()) {
464 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
445 waiting_for_clear_hostname_resolution_cache_ = true; 465 waiting_for_clear_hostname_resolution_cache_ = true;
446 BrowserThread::PostTaskAndReply( 466 BrowserThread::PostTaskAndReply(
447 BrowserThread::IO, FROM_HERE, 467 BrowserThread::IO, FROM_HERE,
448 base::Bind(&ClearHostnameResolutionCacheOnIOThread, 468 base::Bind(&ClearHostnameResolutionCacheOnIOThread,
449 g_browser_process->io_thread()), 469 g_browser_process->io_thread()),
450 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache, 470 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache,
451 weak_ptr_factory_.GetWeakPtr())); 471 weak_ptr_factory_.GetWeakPtr()));
452 } 472 }
453 if (profile_->GetNetworkPredictor()) { 473 if (profile_->GetNetworkPredictor()) {
474 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
454 waiting_for_clear_network_predictor_ = true; 475 waiting_for_clear_network_predictor_ = true;
455 BrowserThread::PostTaskAndReply( 476 BrowserThread::PostTaskAndReply(
456 BrowserThread::IO, FROM_HERE, 477 BrowserThread::IO, FROM_HERE,
457 base::Bind(&ClearNetworkPredictorOnIOThread, 478 base::Bind(&ClearNetworkPredictorOnIOThread,
458 profile_->GetNetworkPredictor()), 479 profile_->GetNetworkPredictor()),
459 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor, 480 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor,
460 weak_ptr_factory_.GetWeakPtr())); 481 weak_ptr_factory_.GetWeakPtr()));
461 } 482 }
462 483
463 // As part of history deletion we also delete the auto-generated keywords. 484 // As part of history deletion we also delete the auto-generated keywords.
464 TemplateURLService* keywords_model = 485 TemplateURLService* keywords_model =
465 TemplateURLServiceFactory::GetForProfile(profile_); 486 TemplateURLServiceFactory::GetForProfile(profile_);
487
466 if (keywords_model && !keywords_model->loaded()) { 488 if (keywords_model && !keywords_model->loaded()) {
467 template_url_sub_ = keywords_model->RegisterOnLoadedCallback( 489 template_url_sub_ = keywords_model->RegisterOnLoadedCallback(
468 base::Bind(&BrowsingDataRemover::OnKeywordsLoaded, 490 base::Bind(&BrowsingDataRemover::OnKeywordsLoaded,
469 weak_ptr_factory_.GetWeakPtr())); 491 weak_ptr_factory_.GetWeakPtr()));
470 keywords_model->Load(); 492 keywords_model->Load();
471 waiting_for_clear_keyword_data_ = true; 493 waiting_for_clear_keyword_data_ = true;
472 } else if (keywords_model) { 494 } else if (keywords_model) {
473 keywords_model->RemoveAutoGeneratedForOriginBetween( 495 keywords_model->RemoveAutoGeneratedForOriginBetween(GURL(), delete_begin_,
msramek 2016/04/07 16:19:12 This deletion very explicitly ignores the filter b
dmurph 2016/04/08 23:33:45 Done.
474 remove_url, delete_begin_, delete_end_); 496 delete_end_);
475 } 497 }
476 498
477 // The PrerenderManager keeps history of prerendered pages, so clear that. 499 // The PrerenderManager keeps history of prerendered pages, so clear that.
478 // It also may have a prerendered page. If so, the page could be 500 // It also may have a prerendered page. If so, the page could be
479 // considered to have a small amount of historical information, so delete 501 // considered to have a small amount of historical information, so delete
480 // it, too. 502 // it, too.
481 prerender::PrerenderManager* prerender_manager = 503 prerender::PrerenderManager* prerender_manager =
482 prerender::PrerenderManagerFactory::GetForProfile(profile_); 504 prerender::PrerenderManagerFactory::GetForProfile(profile_);
483 if (prerender_manager) { 505 if (prerender_manager) {
506 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
484 prerender_manager->ClearData( 507 prerender_manager->ClearData(
485 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | 508 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
486 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); 509 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
487 } 510 }
488 511
489 // If the caller is removing history for all hosts, then clear ancillary 512 // If the caller is removing history for all hosts, then clear ancillary
490 // historical information. 513 // historical information.
491 if (remove_url.is_empty()) { 514 if (origin_filter.IsEmptyBlacklist()) {
492 // We also delete the list of recently closed tabs. Since these expire, 515 // We also delete the list of recently closed tabs. Since these expire,
493 // they can't be more than a day old, so we can simply clear them all. 516 // they can't be more than a day old, so we can simply clear them all.
494 sessions::TabRestoreService* tab_service = 517 sessions::TabRestoreService* tab_service =
495 TabRestoreServiceFactory::GetForProfile(profile_); 518 TabRestoreServiceFactory::GetForProfile(profile_);
496 if (tab_service) { 519 if (tab_service) {
497 tab_service->ClearEntries(); 520 tab_service->ClearEntries();
498 tab_service->DeleteLastSession(); 521 tab_service->DeleteLastSession();
499 } 522 }
500 523
501 #if defined(ENABLE_SESSION_SERVICE) 524 #if defined(ENABLE_SESSION_SERVICE)
502 // We also delete the last session when we delete the history. 525 // We also delete the last session when we delete the history.
503 SessionService* session_service = 526 SessionService* session_service =
504 SessionServiceFactory::GetForProfile(profile_); 527 SessionServiceFactory::GetForProfile(profile_);
505 if (session_service) 528 if (session_service)
506 session_service->DeleteLastSession(); 529 session_service->DeleteLastSession();
507 #endif 530 #endif
508 } 531 }
509 532
510 // The saved Autofill profiles and credit cards can include the origin from 533 // The saved Autofill profiles and credit cards can include the origin from
511 // which these profiles and credit cards were learned. These are a form of 534 // which these profiles and credit cards were learned. These are a form of
512 // history, so clear them as well. 535 // history, so clear them as well.
536 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
513 scoped_refptr<autofill::AutofillWebDataService> web_data_service = 537 scoped_refptr<autofill::AutofillWebDataService> web_data_service =
514 WebDataServiceFactory::GetAutofillWebDataForProfile( 538 WebDataServiceFactory::GetAutofillWebDataForProfile(
515 profile_, ServiceAccessType::EXPLICIT_ACCESS); 539 profile_, ServiceAccessType::EXPLICIT_ACCESS);
516 if (web_data_service.get()) { 540 if (web_data_service.get()) {
517 waiting_for_clear_autofill_origin_urls_ = true; 541 waiting_for_clear_autofill_origin_urls_ = true;
518 web_data_service->RemoveOriginURLsModifiedBetween( 542 web_data_service->RemoveOriginURLsModifiedBetween(
519 delete_begin_, delete_end_); 543 delete_begin_, delete_end_);
520 // The above calls are done on the UI thread but do their work on the DB 544 // The above calls are done on the UI thread but do their work on the DB
521 // thread. So wait for it. 545 // thread. So wait for it.
522 BrowserThread::PostTaskAndReply( 546 BrowserThread::PostTaskAndReply(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 // doesn't make sense to apply the time period of deleting in the last X 640 // doesn't make sense to apply the time period of deleting in the last X
617 // hours/days to the safebrowsing cookies since they aren't the result of 641 // hours/days to the safebrowsing cookies since they aren't the result of
618 // any user action. 642 // any user action.
619 if (delete_begin_ == base::Time()) { 643 if (delete_begin_ == base::Time()) {
620 safe_browsing::SafeBrowsingService* sb_service = 644 safe_browsing::SafeBrowsingService* sb_service =
621 g_browser_process->safe_browsing_service(); 645 g_browser_process->safe_browsing_service();
622 if (sb_service) { 646 if (sb_service) {
623 scoped_refptr<net::URLRequestContextGetter> sb_context = 647 scoped_refptr<net::URLRequestContextGetter> sb_context =
624 sb_service->url_request_context(); 648 sb_service->url_request_context();
625 ++waiting_for_clear_cookies_count_; 649 ++waiting_for_clear_cookies_count_;
626 BrowserThread::PostTask( 650 if (origin_filter.IsEmptyBlacklist()) {
627 BrowserThread::IO, FROM_HERE, 651 BrowserThread::PostTask(
628 base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_, 652 BrowserThread::IO, FROM_HERE,
629 base::RetainedRef(std::move(sb_context)), 653 base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_,
630 UIThreadTrampoline( 654 base::RetainedRef(std::move(sb_context)),
631 base::Bind(&BrowsingDataRemover::OnClearedCookies, 655 UIThreadTrampoline(
632 weak_ptr_factory_.GetWeakPtr())))); 656 base::Bind(&BrowsingDataRemover::OnClearedCookies,
657 weak_ptr_factory_.GetWeakPtr()))));
658 } else {
659 BrowserThread::PostTask(
660 BrowserThread::IO, FROM_HERE,
661 base::Bind(&ClearCookiesWithPredicateOnIOThread, delete_begin_,
662 delete_end_, origin_filter.BuildDomainCookieFilter(),
663 base::RetainedRef(std::move(sb_context)),
664 UIThreadTrampoline(
665 base::Bind(&BrowsingDataRemover::OnClearedCookies,
666 weak_ptr_factory_.GetWeakPtr()))));
667 }
633 } 668 }
634 } 669 }
635 670
636 MediaDeviceIDSalt::Reset(profile_->GetPrefs()); 671 MediaDeviceIDSalt::Reset(profile_->GetPrefs());
637 } 672 }
638 673
639 // Channel IDs are not separated for protected and unprotected web 674 // Channel IDs are not separated for protected and unprotected web
640 // origins. We check the origin_type_mask_ to prevent unintended deletion. 675 // origins. We check the origin_type_mask_ to prevent unintended deletion.
641 if (remove_mask & REMOVE_CHANNEL_IDS && 676 if (remove_mask & REMOVE_CHANNEL_IDS &&
642 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 677 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 plugin_data_remover_->StartRemoving(delete_begin_); 735 plugin_data_remover_->StartRemoving(delete_begin_);
701 736
702 base::WaitableEventWatcher::EventCallback watcher_callback = 737 base::WaitableEventWatcher::EventCallback watcher_callback =
703 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled, 738 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled,
704 weak_ptr_factory_.GetWeakPtr()); 739 weak_ptr_factory_.GetWeakPtr());
705 watcher_.StartWatching(event, watcher_callback); 740 watcher_.StartWatching(event, watcher_callback);
706 } 741 }
707 #endif 742 #endif
708 743
709 if (remove_mask & REMOVE_SITE_USAGE_DATA) { 744 if (remove_mask & REMOVE_SITE_USAGE_DATA) {
710 HostContentSettingsMapFactory::GetForProfile(profile_) 745 ClearSettingsForOneTypeWithPredicate(
711 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT); 746 HostContentSettingsMapFactory::GetForProfile(profile_),
747 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
748 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
712 } 749 }
713 750
714 if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) { 751 if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) {
715 HostContentSettingsMapFactory::GetForProfile(profile_) 752 ClearSettingsForOneTypeWithPredicate(
716 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_APP_BANNER); 753 HostContentSettingsMapFactory::GetForProfile(profile_),
754 CONTENT_SETTINGS_TYPE_APP_BANNER,
755 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
717 } 756 }
718 757
719 if (remove_mask & REMOVE_PASSWORDS) { 758 if (remove_mask & REMOVE_PASSWORDS) {
720 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords")); 759 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
721 password_manager::PasswordStore* password_store = 760 password_manager::PasswordStore* password_store =
722 PasswordStoreFactory::GetForProfile( 761 PasswordStoreFactory::GetForProfile(
723 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); 762 profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
724 763
725 if (password_store) { 764 if (password_store) {
726 waiting_for_clear_passwords_ = true; 765 waiting_for_clear_passwords_ = true;
(...skipping 27 matching lines...) Expand all
754 793
755 if (password_store) { 794 if (password_store) {
756 waiting_for_clear_passwords_stats_ = true; 795 waiting_for_clear_passwords_stats_ = true;
757 password_store->RemoveStatisticsCreatedBetween( 796 password_store->RemoveStatisticsCreatedBetween(
758 delete_begin_, delete_end_, 797 delete_begin_, delete_end_,
759 base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats, 798 base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats,
760 weak_ptr_factory_.GetWeakPtr())); 799 weak_ptr_factory_.GetWeakPtr()));
761 } 800 }
762 } 801 }
763 802
803 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
764 if (remove_mask & REMOVE_FORM_DATA) { 804 if (remove_mask & REMOVE_FORM_DATA) {
765 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill")); 805 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
766 scoped_refptr<autofill::AutofillWebDataService> web_data_service = 806 scoped_refptr<autofill::AutofillWebDataService> web_data_service =
767 WebDataServiceFactory::GetAutofillWebDataForProfile( 807 WebDataServiceFactory::GetAutofillWebDataForProfile(
768 profile_, ServiceAccessType::EXPLICIT_ACCESS); 808 profile_, ServiceAccessType::EXPLICIT_ACCESS);
769 809
770 if (web_data_service.get()) { 810 if (web_data_service.get()) {
771 waiting_for_clear_form_ = true; 811 waiting_for_clear_form_ = true;
772 web_data_service->RemoveFormElementsAddedBetween(delete_begin_, 812 web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
773 delete_end_); 813 delete_end_);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 897
858 if (delete_begin_ == base::Time() || 898 if (delete_begin_ == base::Time() ||
859 origin_type_mask_ & 899 origin_type_mask_ &
860 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) { 900 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
861 // If we're deleting since the beginning of time, or we're removing 901 // If we're deleting since the beginning of time, or we're removing
862 // protected origins, then remove persistent quota data. 902 // protected origins, then remove persistent quota data.
863 quota_storage_remove_mask |= 903 quota_storage_remove_mask |=
864 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 904 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
865 } 905 }
866 906
907 content::StoragePartition::CookieMatcherFunction cookie_matcher;
908 if (!origin_filter.IsEmptyBlacklist()) {
909 cookie_matcher = origin_filter.BuildDomainCookieFilter();
910 }
867 storage_partition->ClearData( 911 storage_partition->ClearData(
868 storage_partition_remove_mask, quota_storage_remove_mask, remove_url, 912 storage_partition_remove_mask, quota_storage_remove_mask,
869 base::Bind(&DoesOriginMatchMask, origin_type_mask_), delete_begin_, 913 base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_,
870 delete_end_, 914 same_origin_filter),
915 cookie_matcher, delete_begin_, delete_end_,
871 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData, 916 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData,
872 weak_ptr_factory_.GetWeakPtr())); 917 weak_ptr_factory_.GetWeakPtr()));
873 } 918 }
874 919
875 #if defined(ENABLE_PLUGINS) 920 #if defined(ENABLE_PLUGINS)
876 if (remove_mask & REMOVE_CONTENT_LICENSES) { 921 if (remove_mask & REMOVE_CONTENT_LICENSES) {
877 content::RecordAction( 922 content::RecordAction(
878 UserMetricsAction("ClearBrowsingData_ContentLicenses")); 923 UserMetricsAction("ClearBrowsingData_ContentLicenses"));
879 924
880 waiting_for_clear_content_licenses_ = true; 925 waiting_for_clear_content_licenses_ = true;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 waiting_for_clear_webapp_data_ = true; 988 waiting_for_clear_webapp_data_ = true;
944 webapp_registry_->UnregisterWebapps( 989 webapp_registry_->UnregisterWebapps(
945 base::Bind(&BrowsingDataRemover::OnClearedWebappData, 990 base::Bind(&BrowsingDataRemover::OnClearedWebappData,
946 weak_ptr_factory_.GetWeakPtr())); 991 weak_ptr_factory_.GetWeakPtr()));
947 } 992 }
948 993
949 if ((remove_mask & REMOVE_OFFLINE_PAGE_DATA) && 994 if ((remove_mask & REMOVE_OFFLINE_PAGE_DATA) &&
950 offline_pages::IsOfflinePagesEnabled()) { 995 offline_pages::IsOfflinePagesEnabled()) {
951 waiting_for_clear_offline_page_data_ = true; 996 waiting_for_clear_offline_page_data_ = true;
952 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_) 997 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_)
953 ->ClearAll(base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData, 998 ->ClearWithURLPredicate(
954 weak_ptr_factory_.GetWeakPtr())); 999 same_origin_filter,
1000 base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData,
1001 weak_ptr_factory_.GetWeakPtr()));
955 } 1002 }
956 #endif 1003 #endif
957 1004
958 // Record the combined deletion of cookies and cache. 1005 // Record the combined deletion of cookies and cache.
959 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE; 1006 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE;
960 if (remove_mask & REMOVE_COOKIES && 1007 if (remove_mask & REMOVE_COOKIES &&
961 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 1008 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
962 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE 1009 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE
963 : ONLY_COOKIES; 1010 : ONLY_COOKIES;
964 } else if (remove_mask & REMOVE_CACHE) { 1011 } else if (remove_mask & REMOVE_CACHE) {
(...skipping 18 matching lines...) Expand all
983 storage_partition_for_testing_ = storage_partition; 1030 storage_partition_for_testing_ = storage_partition;
984 } 1031 }
985 1032
986 #if BUILDFLAG(ANDROID_JAVA_UI) 1033 #if BUILDFLAG(ANDROID_JAVA_UI)
987 void BrowsingDataRemover::OverrideWebappRegistryForTesting( 1034 void BrowsingDataRemover::OverrideWebappRegistryForTesting(
988 scoped_ptr<WebappRegistry> webapp_registry) { 1035 scoped_ptr<WebappRegistry> webapp_registry) {
989 webapp_registry_.reset(webapp_registry.release()); 1036 webapp_registry_.reset(webapp_registry.release());
990 } 1037 }
991 #endif 1038 #endif
992 1039
1040 void BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate(
1041 HostContentSettingsMap* content_settings_map,
1042 ContentSettingsType content_type,
1043 const base::Callback<bool(const ContentSettingsPattern& primary_pattern,
1044 const ContentSettingsPattern& secondary_pattern)>&
1045 predicate) {
1046 ContentSettingsForOneType settings;
1047 content_settings_map->GetSettingsForOneType(content_type, std::string(),
1048 &settings);
1049 for (const ContentSettingPatternSource& setting : settings) {
1050 if (predicate.Run(setting.primary_pattern, setting.secondary_pattern)) {
1051 content_settings_map->SetWebsiteSettingCustomScope(
1052 setting.primary_pattern, setting.secondary_pattern, content_type,
1053 std::string(), nullptr);
1054 }
1055 }
1056 }
1057
993 base::Time BrowsingDataRemover::CalculateBeginDeleteTime( 1058 base::Time BrowsingDataRemover::CalculateBeginDeleteTime(
994 TimePeriod time_period) { 1059 TimePeriod time_period) {
995 base::TimeDelta diff; 1060 base::TimeDelta diff;
996 base::Time delete_begin_time = base::Time::Now(); 1061 base::Time delete_begin_time = base::Time::Now();
997 switch (time_period) { 1062 switch (time_period) {
998 case LAST_HOUR: 1063 case LAST_HOUR:
999 diff = base::TimeDelta::FromHours(1); 1064 diff = base::TimeDelta::FromHours(1);
1000 break; 1065 break;
1001 case LAST_DAY: 1066 case LAST_DAY:
1002 diff = base::TimeDelta::FromHours(24); 1067 diff = base::TimeDelta::FromHours(24);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 waiting_for_clear_domain_reliability_monitor_ = false; 1313 waiting_for_clear_domain_reliability_monitor_ = false;
1249 NotifyIfDone(); 1314 NotifyIfDone();
1250 } 1315 }
1251 1316
1252 // static 1317 // static
1253 BrowsingDataRemover::CallbackSubscription 1318 BrowsingDataRemover::CallbackSubscription
1254 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( 1319 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
1255 const BrowsingDataRemover::Callback& callback) { 1320 const BrowsingDataRemover::Callback& callback) {
1256 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); 1321 return GetOnBrowsingDataRemovedCallbacks()->Add(callback);
1257 } 1322 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698