Commit 8733eb80 authored by msramek's avatar msramek Committed by Commit bot

Move HISTORY and PASSWORDS from BrowsingDataRemover to the delegate

In https://codereview.chromium.org/2554413002/, BrowsingDataRemover was
split into content-related and embedder-specific datatypes
(BrowsingDataRemover[Impl] and [Chrome]BrowsingDataRemoverDelegate,
respectively).

The split was done according to where the relevant data storage backends
resided. This CL intends to make the split more precise by looking at it
more semantically.

1. While SSLHostStateDelegate lives in content/, it's state is deleted
   as a part of the HISTORY datatype, which is not a content/ concept.
   Therefore, this was moved to ChromeBrowsingDataRemoverDelegate.

2. The DCHECK verifying that all UI entrypoints to history deletion
   were disabled if !|may_delete_history| was also moved to
   ChromeBrowsingDataRemoverDelegate, as UI is also not a content/
   concept.

3. The deletion of auth cache is done in BrowsingDataRemoverDelegate
   for both the COOKIES and PASSWORDS datatypes. However, PASSWORDS
   are not a content/ concept. Therefore, BrowsingDataRemoverImpl now
   deletes the auth cache for COOKIES, and
   ChromeBrowsingDataRemoverDelegate for PASSWORDS. This is currently
   done by the duplication of the code, as some duplication is
   necessary anyway, and only about ~10 lines of code are duplicated
   unnecessarily; this seems to be too few to justify creating a new
   file in content/public to be shared between content/ and chrome/.

   TODO: This is the second duplication between the two classes. If
   this keeps happenning, consider putting the shared functionality
   to content/public anyway.

BUG=668114

Review-Url: https://codereview.chromium.org/2617403005
Cr-Commit-Position: refs/heads/master@{#443233}
parent 5cb986a6
......@@ -30,7 +30,6 @@
#include "content/public/browser/download_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/plugin_data_remover.h"
#include "content/public/browser/ssl_host_state_delegate.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/user_metrics.h"
#include "extensions/features/features.h"
......@@ -377,30 +376,11 @@ void BrowsingDataRemoverImpl::RemoveImpl(
bool may_delete_history =
prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
// All the UI entry points into the BrowsingDataRemoverImpl should be
// disabled, but this will fire if something was missed or added.
DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
(!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
//////////////////////////////////////////////////////////////////////////////
// INITIALIZATION
base::Callback<bool(const GURL& url)> filter =
filter_builder.BuildGeneralFilter();
if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
// The SSL Host State that tracks SSL interstitial "proceed" decisions may
// include origins that the user has visited, so it must be cleared.
// TODO(msramek): We can reuse the plugin filter here, since both plugins
// and SSL host state are scoped to hosts and represent them as std::string.
// Rename the method to indicate its more general usage.
if (browser_context_->GetSSLHostStateDelegate()) {
browser_context_->GetSSLHostStateDelegate()->Clear(
filter_builder.IsEmptyBlacklist()
? base::Callback<bool(const std::string&)>()
: filter_builder.BuildPluginFilter());
}
}
//////////////////////////////////////////////////////////////////////////////
// REMOVE_DOWNLOADS
if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) {
......@@ -585,7 +565,7 @@ void BrowsingDataRemoverImpl::RemoveImpl(
//////////////////////////////////////////////////////////////////////////////
// Auth cache.
if (remove_mask & REMOVE_COOKIES || remove_mask & REMOVE_PASSWORDS) {
if (remove_mask & REMOVE_COOKIES) {
scoped_refptr<net::URLRequestContextGetter> request_context =
BrowserContext::GetDefaultStoragePartition(browser_context_)
->GetURLRequestContext();
......
......@@ -64,8 +64,11 @@
#include "components/previews/core/previews_ui_service.h"
#include "components/search_engines/template_url_service.h"
#include "components/sessions/core/tab_restore_service.h"
#include "content/public/browser/ssl_host_state_delegate.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/user_metrics.h"
#include "net/cookies/cookie_store.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
......@@ -207,6 +210,20 @@ void ClearHostnameResolutionCacheOnIOThread(
io_thread->ClearHostCache(host_filter);
}
void ClearHttpAuthCacheOnIOThread(
scoped_refptr<net::URLRequestContextGetter> context_getter,
base::Time delete_begin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
net::HttpNetworkSession* http_session = context_getter->GetURLRequestContext()
->http_transaction_factory()
->GetSession();
DCHECK(http_session);
http_session->http_auth_cache()->ClearEntriesAddedWithin(base::Time::Now() -
delete_begin);
http_session->CloseAllConnections();
}
} // namespace
ChromeBrowsingDataRemoverDelegate::SubTask::SubTask(
......@@ -260,6 +277,7 @@ ChromeBrowsingDataRemoverDelegate::ChromeBrowsingDataRemoverDelegate(
clear_networking_history_(sub_task_forward_callback_),
clear_passwords_(sub_task_forward_callback_),
clear_passwords_stats_(sub_task_forward_callback_),
clear_http_auth_cache_(sub_task_forward_callback_),
clear_platform_keys_(sub_task_forward_callback_),
#if defined(OS_ANDROID)
clear_precache_history_(sub_task_forward_callback_),
......@@ -309,6 +327,13 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
bool may_delete_history = prefs->GetBoolean(
prefs::kAllowDeletingBrowserHistory);
// All the UI entry points into the BrowsingDataRemoverImpl should be
// disabled, but this will fire if something was missed or added.
DCHECK(may_delete_history ||
(remove_mask & BrowsingDataRemover::REMOVE_NOCHECKS) ||
(!(remove_mask & BrowsingDataRemover::REMOVE_HISTORY) &&
!(remove_mask & BrowsingDataRemover::REMOVE_DOWNLOADS)));
//////////////////////////////////////////////////////////////////////////////
// REMOVE_HISTORY
if ((remove_mask & BrowsingDataRemover::REMOVE_HISTORY) &&
......@@ -515,6 +540,18 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
previews_service->previews_ui_service()->ClearBlackList(delete_begin_,
delete_end_);
}
// The SSL Host State that tracks SSL interstitial "proceed" decisions may
// include origins that the user has visited, so it must be cleared.
// TODO(msramek): We can reuse the plugin filter here, since both plugins
// and SSL host state are scoped to hosts and represent them as std::string.
// Rename the method to indicate its more general usage.
if (profile_->GetSSLHostStateDelegate()) {
profile_->GetSSLHostStateDelegate()->Clear(
filter_builder.IsEmptyBlacklist()
? base::Callback<bool(const std::string&)>()
: filter_builder.BuildPluginFilter());
}
}
//////////////////////////////////////////////////////////////////////////////
......@@ -618,6 +655,16 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
filter, delete_begin_, delete_end_,
clear_passwords_.GetCompletionCallback());
}
scoped_refptr<net::URLRequestContextGetter> request_context =
BrowserContext::GetDefaultStoragePartition(profile_)
->GetURLRequestContext();
clear_http_auth_cache_.Start();
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context),
delete_begin_),
clear_http_auth_cache_.GetCompletionCallback());
}
if (remove_mask & BrowsingDataRemover::REMOVE_COOKIES) {
......@@ -847,6 +894,7 @@ bool ChromeBrowsingDataRemoverDelegate::AllDone() {
!clear_networking_history_.is_pending() &&
!clear_passwords_.is_pending() &&
!clear_passwords_stats_.is_pending() &&
!clear_http_auth_cache_.is_pending() &&
!clear_platform_keys_.is_pending() &&
#if defined(OS_ANDROID)
!clear_precache_history_.is_pending() &&
......
......@@ -146,6 +146,7 @@ class ChromeBrowsingDataRemoverDelegate : public BrowsingDataRemoverDelegate
SubTask clear_networking_history_;
SubTask clear_passwords_;
SubTask clear_passwords_stats_;
SubTask clear_http_auth_cache_;
SubTask clear_platform_keys_;
#if defined(OS_ANDROID)
SubTask clear_precache_history_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment