| OLD | NEW |
| 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 Loading... |
| 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.ChangeMode(OriginFilterBuilder::WHITELIST) |
| 356 ->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 Loading... |
| 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): Investigate whether history deletion, especially in the |
| 400 // case of web history, understands an origin parameter as the deletion |
| 401 // of all URLs from that origin, or just the URL with empty path. |
| 402 // TODO(msramek): Replace |remove_url| with a GURL->bool predicate. |
| 382 std::set<GURL> restrict_urls; | 403 std::set<GURL> restrict_urls; |
| 383 if (!remove_url.is_empty()) | 404 if (!remove_url.is_empty()) |
| 384 restrict_urls.insert(remove_url); | 405 restrict_urls.insert(remove_url); |
| 385 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); | 406 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
| 386 waiting_for_clear_history_ = true; | 407 waiting_for_clear_history_ = true; |
| 387 | 408 |
| 388 history_service->ExpireLocalAndRemoteHistoryBetween( | 409 history_service->ExpireLocalAndRemoteHistoryBetween( |
| 389 WebHistoryServiceFactory::GetForProfile(profile_), restrict_urls, | 410 WebHistoryServiceFactory::GetForProfile(profile_), restrict_urls, |
| 390 delete_begin_, delete_end_, | 411 delete_begin_, delete_end_, |
| 391 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, | 412 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 data_reduction_proxy_service->compression_stats() | 573 data_reduction_proxy_service->compression_stats() |
| 553 ->DeleteBrowsingHistory(delete_begin_, delete_end_); | 574 ->DeleteBrowsingHistory(delete_begin_, delete_end_); |
| 554 } | 575 } |
| 555 } | 576 } |
| 556 } | 577 } |
| 557 | 578 |
| 558 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) { | 579 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) { |
| 559 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); | 580 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); |
| 560 content::DownloadManager* download_manager = | 581 content::DownloadManager* download_manager = |
| 561 BrowserContext::GetDownloadManager(profile_); | 582 BrowserContext::GetDownloadManager(profile_); |
| 562 if (remove_url.is_empty()) { | 583 download_manager->RemoveDownloadsByURLAndTime( |
| 563 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); | 584 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( | 585 DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager( |
| 569 download_manager); | 586 download_manager); |
| 570 download_prefs->SetSaveFilePath(download_prefs->DownloadPath()); | 587 download_prefs->SetSaveFilePath(download_prefs->DownloadPath()); |
| 571 } | 588 } |
| 572 | 589 |
| 573 uint32_t storage_partition_remove_mask = 0; | 590 uint32_t storage_partition_remove_mask = 0; |
| 574 | 591 |
| 575 // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set, | 592 // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set, |
| 576 // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB | 593 // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB |
| 577 // don't accidentally remove the cookies that are associated with the | 594 // don't accidentally remove the cookies that are associated with the |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 waiting_for_clear_domain_reliability_monitor_ = false; | 1212 waiting_for_clear_domain_reliability_monitor_ = false; |
| 1196 NotifyIfDone(); | 1213 NotifyIfDone(); |
| 1197 } | 1214 } |
| 1198 | 1215 |
| 1199 // static | 1216 // static |
| 1200 BrowsingDataRemover::CallbackSubscription | 1217 BrowsingDataRemover::CallbackSubscription |
| 1201 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | 1218 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( |
| 1202 const BrowsingDataRemover::Callback& callback) { | 1219 const BrowsingDataRemover::Callback& callback) { |
| 1203 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); | 1220 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); |
| 1204 } | 1221 } |
| OLD | NEW |