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

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

Issue 1603903002: Add an OriginFilterBuilder class for [white|black]listing origins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase over 1246583002 Created 4 years, 10 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/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
23 #include "chrome/browser/domain_reliability/service_factory.h" 24 #include "chrome/browser/domain_reliability/service_factory.h"
24 #include "chrome/browser/download/download_prefs.h" 25 #include "chrome/browser/download/download_prefs.h"
25 #include "chrome/browser/history/history_service_factory.h" 26 #include "chrome/browser/history/history_service_factory.h"
26 #include "chrome/browser/history/web_history_service_factory.h" 27 #include "chrome/browser/history/web_history_service_factory.h"
27 #include "chrome/browser/io_thread.h" 28 #include "chrome/browser/io_thread.h"
28 #include "chrome/browser/media/media_device_id_salt.h" 29 #include "chrome/browser/media/media_device_id_salt.h"
29 #include "chrome/browser/net/predictor.h" 30 #include "chrome/browser/net/predictor.h"
30 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 31 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 337
337 // crbug.com/140910: Many places were calling this with base::Time() as 338 // crbug.com/140910: Many places were calling this with base::Time() as
338 // delete_end, even though they should've used base::Time::Max(). 339 // delete_end, even though they should've used base::Time::Max().
339 DCHECK_NE(base::Time(), time_range.end); 340 DCHECK_NE(base::Time(), time_range.end);
340 341
341 SetRemoving(true); 342 SetRemoving(true);
342 delete_begin_ = time_range.begin; 343 delete_begin_ = time_range.begin;
343 delete_end_ = time_range.end; 344 delete_end_ = time_range.end;
344 remove_mask_ = remove_mask; 345 remove_mask_ = remove_mask;
345 origin_type_mask_ = origin_type_mask; 346 origin_type_mask_ = origin_type_mask;
347
348 // TODO(msramek): Replace |remove_origin| with |filter| in all backends.
346 const url::Origin remove_origin(remove_url); 349 const url::Origin remove_origin(remove_url);
350 OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
351 if (!remove_url.is_empty()) {
352 // Make sure that only URLs representing origins, with no extra components,
353 // are passed to this class.
354 DCHECK_EQ(remove_url, remove_url.GetOrigin());
355 builder.SetMode(OriginFilterBuilder::WHITELIST);
356 builder.AddOrigin(url::Origin(remove_origin));
357 }
358 base::Callback<bool(const GURL& url)> same_origin_filter =
359 builder.BuildSameOriginFilter();
347 360
348 PrefService* prefs = profile_->GetPrefs(); 361 PrefService* prefs = profile_->GetPrefs();
349 bool may_delete_history = prefs->GetBoolean( 362 bool may_delete_history = prefs->GetBoolean(
350 prefs::kAllowDeletingBrowserHistory); 363 prefs::kAllowDeletingBrowserHistory);
351 364
352 // All the UI entry points into the BrowsingDataRemover should be disabled, 365 // All the UI entry points into the BrowsingDataRemover should be disabled,
353 // but this will fire if something was missed or added. 366 // but this will fire if something was missed or added.
354 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) || 367 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
355 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS))); 368 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
356 369
(...skipping 15 matching lines...) Expand all
372 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB | 385 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB |
373 BrowsingDataHelper::PROTECTED_WEB | 386 BrowsingDataHelper::PROTECTED_WEB |
374 BrowsingDataHelper::EXTENSION), 387 BrowsingDataHelper::EXTENSION),
375 "OriginTypeMask has been updated without updating user metrics"); 388 "OriginTypeMask has been updated without updating user metrics");
376 389
377 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { 390 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
378 history::HistoryService* history_service = 391 history::HistoryService* history_service =
379 HistoryServiceFactory::GetForProfile( 392 HistoryServiceFactory::GetForProfile(
380 profile_, ServiceAccessType::EXPLICIT_ACCESS); 393 profile_, ServiceAccessType::EXPLICIT_ACCESS);
381 if (history_service) { 394 if (history_service) {
395 // Selective history deletion is currently done through HistoryUI ->
396 // HistoryBackend -> HistoryService, and that is for individual URLs,
397 // not origins. The code below is currently unused, as the only callsite
398 // supplying |remove_url| is the unittest.
399 // TODO(msramek): Make it possible to delete history per origin, not just
400 // per URL, and use that functionality here.
382 std::set<GURL> restrict_urls; 401 std::set<GURL> restrict_urls;
383 if (!remove_url.is_empty()) 402 if (!remove_url.is_empty())
384 restrict_urls.insert(remove_url); 403 restrict_urls.insert(remove_url);
385 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); 404 content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
386 waiting_for_clear_history_ = true; 405 waiting_for_clear_history_ = true;
387 406
388 history_service->ExpireLocalAndRemoteHistoryBetween( 407 history_service->ExpireLocalAndRemoteHistoryBetween(
389 WebHistoryServiceFactory::GetForProfile(profile_), restrict_urls, 408 WebHistoryServiceFactory::GetForProfile(profile_), restrict_urls,
390 delete_begin_, delete_end_, 409 delete_begin_, delete_end_,
391 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, 410 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 data_reduction_proxy_service->compression_stats() 571 data_reduction_proxy_service->compression_stats()
553 ->DeleteBrowsingHistory(delete_begin_, delete_end_); 572 ->DeleteBrowsingHistory(delete_begin_, delete_end_);
554 } 573 }
555 } 574 }
556 } 575 }
557 576
558 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) { 577 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) {
559 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); 578 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
560 content::DownloadManager* download_manager = 579 content::DownloadManager* download_manager =
561 BrowserContext::GetDownloadManager(profile_); 580 BrowserContext::GetDownloadManager(profile_);
562 if (remove_url.is_empty()) { 581 download_manager->RemoveDownloadsByURLAndTime(
563 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); 582 same_origin_filter, delete_begin_, delete_end_);
564 } else {
565 download_manager->RemoveDownloadsByOriginAndTime(
566 remove_origin, delete_begin_, delete_end_);
567 }
568 DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager( 583 DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager(
569 download_manager); 584 download_manager);
570 download_prefs->SetSaveFilePath(download_prefs->DownloadPath()); 585 download_prefs->SetSaveFilePath(download_prefs->DownloadPath());
571 } 586 }
572 587
573 uint32_t storage_partition_remove_mask = 0; 588 uint32_t storage_partition_remove_mask = 0;
574 589
575 // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set, 590 // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set,
576 // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB 591 // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB
577 // don't accidentally remove the cookies that are associated with the 592 // don't accidentally remove the cookies that are associated with the
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 waiting_for_clear_domain_reliability_monitor_ = false; 1210 waiting_for_clear_domain_reliability_monitor_ = false;
1196 NotifyIfDone(); 1211 NotifyIfDone();
1197 } 1212 }
1198 1213
1199 // static 1214 // static
1200 BrowsingDataRemover::CallbackSubscription 1215 BrowsingDataRemover::CallbackSubscription
1201 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( 1216 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
1202 const BrowsingDataRemover::Callback& callback) { 1217 const BrowsingDataRemover::Callback& callback) {
1203 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); 1218 return GetOnBrowsingDataRemovedCallbacks()->Add(callback);
1204 } 1219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698