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

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

Issue 2554413002: Extract embedder-specific data types from BrowsingDataRemover (Closed)
Patch Set: Android fix Created 4 years 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 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "build/build_config.h"
18 #include "chrome/browser/autofill/personal_data_manager_factory.h"
19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" 17 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
21 #include "chrome/browser/browsing_data/browsing_data_helper.h" 18 #include "chrome/browser/browsing_data/browsing_data_helper.h"
22 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 19 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h"
23 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" 20 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
24 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
26 #include "chrome/browser/domain_reliability/service_factory.h"
27 #include "chrome/browser/download/download_prefs.h" 21 #include "chrome/browser/download/download_prefs.h"
28 #include "chrome/browser/history/history_service_factory.h"
29 #include "chrome/browser/history/web_history_service_factory.h"
30 #include "chrome/browser/io_thread.h" 22 #include "chrome/browser/io_thread.h"
31 #include "chrome/browser/media/media_device_id_salt.h"
32 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
33 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
34 #include "chrome/browser/net/predictor.h"
35 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
36 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
37 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
38 #include "chrome/browser/password_manager/password_store_factory.h"
39 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
40 #include "chrome/browser/prerender/prerender_manager.h"
41 #include "chrome/browser/prerender/prerender_manager_factory.h"
42 #include "chrome/browser/previews/previews_service.h"
43 #include "chrome/browser/previews/previews_service_factory.h"
44 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
45 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
46 #include "chrome/browser/search_engines/template_url_service_factory.h"
47 #include "chrome/browser/sessions/tab_restore_service_factory.h"
48 #include "chrome/browser/web_data_service_factory.h"
49 #include "chrome/common/features.h"
50 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
51 #include "chrome/common/url_constants.h"
52 #include "components/autofill/core/browser/personal_data_manager.h"
53 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
54 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h" 25 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h"
55 #include "components/content_settings/core/browser/host_content_settings_map.h"
56 #include "components/content_settings/core/common/content_settings.h"
57 #include "components/content_settings/core/common/content_settings_pattern.h"
58 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h"
59 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
60 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
61 #include "components/domain_reliability/service.h"
62 #include "components/history/core/browser/history_service.h"
63 #include "components/nacl/browser/nacl_browser.h"
64 #include "components/nacl/browser/pnacl_host.h"
65 #include "components/ntp_snippets/content_suggestions_service.h"
66 #include "components/omnibox/browser/omnibox_pref_names.h"
67 #include "components/password_manager/core/browser/password_store.h"
68 #include "components/prefs/pref_service.h" 26 #include "components/prefs/pref_service.h"
69 #include "components/previews/core/previews_ui_service.h"
70 #include "components/search_engines/template_url_service.h"
71 #include "components/sessions/core/tab_restore_service.h"
72 #include "components/web_cache/browser/web_cache_manager.h" 27 #include "components/web_cache/browser/web_cache_manager.h"
73 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
74 #include "content/public/browser/download_manager.h" 29 #include "content/public/browser/download_manager.h"
75 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
76 #include "content/public/browser/plugin_data_remover.h" 31 #include "content/public/browser/plugin_data_remover.h"
77 #include "content/public/browser/ssl_host_state_delegate.h" 32 #include "content/public/browser/ssl_host_state_delegate.h"
78 #include "content/public/browser/storage_partition.h" 33 #include "content/public/browser/storage_partition.h"
79 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
80 #include "extensions/features/features.h" 35 #include "extensions/features/features.h"
81 #include "media/media_features.h" 36 #include "media/media_features.h"
82 #include "net/base/net_errors.h" 37 #include "net/base/net_errors.h"
83 #include "net/cookies/cookie_store.h" 38 #include "net/cookies/cookie_store.h"
84 #include "net/http/http_network_session.h" 39 #include "net/http/http_network_session.h"
85 #include "net/http/http_transaction_factory.h" 40 #include "net/http/http_transaction_factory.h"
86 #include "net/http/transport_security_state.h" 41 #include "net/http/transport_security_state.h"
87 #include "net/ssl/channel_id_service.h" 42 #include "net/ssl/channel_id_service.h"
88 #include "net/ssl/channel_id_store.h" 43 #include "net/ssl/channel_id_store.h"
89 #include "net/url_request/url_request_context.h" 44 #include "net/url_request/url_request_context.h"
90 #include "net/url_request/url_request_context_getter.h" 45 #include "net/url_request/url_request_context_getter.h"
91 #include "ppapi/features/features.h" 46 #include "ppapi/features/features.h"
92 #include "storage/browser/quota/special_storage_policy.h" 47 #include "storage/browser/quota/special_storage_policy.h"
93 #include "url/origin.h" 48 #include "url/origin.h"
94 49
95 #if BUILDFLAG(ANDROID_JAVA_UI)
96 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
97 #include "chrome/browser/android/webapps/webapp_registry.h"
98 #include "chrome/browser/precache/precache_manager_factory.h"
99 #include "components/offline_pages/core/offline_page_feature.h"
100 #include "components/offline_pages/core/offline_page_model.h"
101 #include "components/precache/content/precache_manager.h"
102 #endif
103
104 #if BUILDFLAG(ENABLE_EXTENSIONS)
105 #include "chrome/browser/extensions/activity_log/activity_log.h"
106 #include "extensions/browser/extension_prefs.h"
107 #endif
108
109 #if BUILDFLAG(ENABLE_PLUGINS) 50 #if BUILDFLAG(ENABLE_PLUGINS)
110 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" 51 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
111 #endif 52 #endif
112 53
113 #if BUILDFLAG(ENABLE_SESSION_SERVICE)
114 #include "chrome/browser/sessions/session_service.h"
115 #include "chrome/browser/sessions/session_service_factory.h"
116 #endif
117
118 #if defined(OS_CHROMEOS)
119 #include "chrome/browser/chromeos/profiles/profile_helper.h"
120 #include "chromeos/attestation/attestation_constants.h"
121 #include "chromeos/cryptohome/cryptohome_parameters.h"
122 #include "chromeos/dbus/cryptohome_client.h"
123 #include "chromeos/dbus/dbus_thread_manager.h"
124 #include "components/user_manager/user.h"
125 #endif
126
127 #if BUILDFLAG(ENABLE_WEBRTC)
128 #include "chrome/browser/media/webrtc/webrtc_log_list.h"
129 #include "chrome/browser/media/webrtc/webrtc_log_util.h"
130 #endif
131
132 using base::UserMetricsAction; 54 using base::UserMetricsAction;
133 using content::BrowserContext; 55 using content::BrowserContext;
134 using content::BrowserThread; 56 using content::BrowserThread;
135 using content::DOMStorageContext; 57 using content::DOMStorageContext;
136 58
137 namespace { 59 namespace {
138 60
139 void UIThreadTrampolineHelper(const base::Closure& callback) {
140 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
141 }
142
143 // Convenience method to create a callback that can be run on any thread and
144 // will post the given |callback| back to the UI thread.
145 base::Closure UIThreadTrampoline(const base::Closure& callback) {
146 // We could directly bind &BrowserThread::PostTask, but that would require
147 // evaluating FROM_HERE when this method is called, as opposed to when the
148 // task is actually posted.
149 return base::Bind(&UIThreadTrampolineHelper, callback);
150 }
151
152 template <typename T> 61 template <typename T>
153 void IgnoreArgumentHelper(const base::Closure& callback, T unused_argument) { 62 void IgnoreArgumentHelper(const base::Closure& callback, T unused_argument) {
154 callback.Run(); 63 callback.Run();
155 } 64 }
156 65
157 // Another convenience method to turn a callback without arguments into one that 66 // Another convenience method to turn a callback without arguments into one that
158 // accepts (and ignores) a single argument. 67 // accepts (and ignores) a single argument.
159 template <typename T> 68 template <typename T>
160 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) { 69 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) {
161 return base::Bind(&IgnoreArgumentHelper<T>, callback); 70 return base::Bind(&IgnoreArgumentHelper<T>, callback);
162 } 71 }
163 72
164 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask. 73 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask.
165 bool DoesOriginMatchMaskAndUrls( 74 bool DoesOriginMatchMaskAndUrls(
166 int origin_type_mask, 75 int origin_type_mask,
167 const base::Callback<bool(const GURL&)>& predicate, 76 const base::Callback<bool(const GURL&)>& predicate,
168 const GURL& origin, 77 const GURL& origin,
169 storage::SpecialStoragePolicy* special_storage_policy) { 78 storage::SpecialStoragePolicy* special_storage_policy) {
170 return predicate.Run(origin) && 79 return predicate.Run(origin) &&
171 BrowsingDataHelper::DoesOriginMatchMask(origin, origin_type_mask, 80 BrowsingDataHelper::DoesOriginMatchMask(origin, origin_type_mask,
172 special_storage_policy); 81 special_storage_policy);
173 } 82 }
174 83
175 bool ForwardPrimaryPatternCallback(
176 const base::Callback<bool(const ContentSettingsPattern&)> predicate,
177 const ContentSettingsPattern& primary_pattern,
178 const ContentSettingsPattern& secondary_pattern) {
179 return predicate.Run(primary_pattern);
180 }
181
182 void ClearHostnameResolutionCacheOnIOThread(
183 IOThread* io_thread,
184 base::Callback<bool(const std::string&)> host_filter) {
185 DCHECK_CURRENTLY_ON(BrowserThread::IO);
186
187 io_thread->ClearHostCache(host_filter);
188 }
189
190 void ClearHttpAuthCacheOnIOThread( 84 void ClearHttpAuthCacheOnIOThread(
191 scoped_refptr<net::URLRequestContextGetter> context_getter, 85 scoped_refptr<net::URLRequestContextGetter> context_getter,
192 base::Time delete_begin) { 86 base::Time delete_begin) {
193 DCHECK_CURRENTLY_ON(BrowserThread::IO); 87 DCHECK_CURRENTLY_ON(BrowserThread::IO);
194 88
195 net::HttpNetworkSession* http_session = context_getter->GetURLRequestContext() 89 net::HttpNetworkSession* http_session = context_getter->GetURLRequestContext()
196 ->http_transaction_factory() 90 ->http_transaction_factory()
197 ->GetSession(); 91 ->GetSession();
198 DCHECK(http_session); 92 DCHECK(http_session);
199 http_session->http_auth_cache()->ClearEntriesAddedWithin(base::Time::Now() - 93 http_session->http_auth_cache()->ClearEntriesAddedWithin(base::Time::Now() -
200 delete_begin); 94 delete_begin);
201 http_session->CloseAllConnections(); 95 http_session->CloseAllConnections();
202 } 96 }
203 97
204 void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) {
205 DCHECK_CURRENTLY_ON(BrowserThread::IO);
206 DCHECK(predictor);
207
208 predictor->DiscardInitialNavigationHistory();
209 predictor->DiscardAllResults();
210 }
211
212 #if !defined(DISABLE_NACL)
213 void ClearNaClCacheOnIOThread(const base::Closure& callback) {
214 DCHECK_CURRENTLY_ON(BrowserThread::IO);
215
216 nacl::NaClBrowser::GetInstance()->ClearValidationCache(callback);
217 }
218
219 void ClearPnaclCacheOnIOThread(base::Time begin,
220 base::Time end,
221 const base::Closure& callback) {
222 DCHECK_CURRENTLY_ON(BrowserThread::IO);
223
224 pnacl::PnaclHost::GetInstance()->ClearTranslationCacheEntriesBetween(
225 begin, end, callback);
226 }
227 #endif
228
229 void ClearCookiesOnIOThread(base::Time delete_begin,
230 base::Time delete_end,
231 net::URLRequestContextGetter* rq_context,
232 const base::Closure& callback) {
233 DCHECK_CURRENTLY_ON(BrowserThread::IO);
234 net::CookieStore* cookie_store =
235 rq_context->GetURLRequestContext()->cookie_store();
236 cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
237 IgnoreArgument<int>(callback));
238 }
239
240 void ClearCookiesWithPredicateOnIOThread(
241 base::Time delete_begin,
242 base::Time delete_end,
243 net::CookieStore::CookiePredicate predicate,
244 net::URLRequestContextGetter* rq_context,
245 const base::Closure& callback) {
246 DCHECK_CURRENTLY_ON(BrowserThread::IO);
247 net::CookieStore* cookie_store =
248 rq_context->GetURLRequestContext()->cookie_store();
249 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
250 delete_begin, delete_end, predicate, IgnoreArgument<int>(callback));
251 }
252
253 void OnClearedChannelIDsOnIOThread(net::URLRequestContextGetter* rq_context, 98 void OnClearedChannelIDsOnIOThread(net::URLRequestContextGetter* rq_context,
254 const base::Closure& callback) { 99 const base::Closure& callback) {
255 DCHECK_CURRENTLY_ON(BrowserThread::IO); 100 DCHECK_CURRENTLY_ON(BrowserThread::IO);
256 101
257 // Need to close open SSL connections which may be using the channel ids we 102 // Need to close open SSL connections which may be using the channel ids we
258 // are deleting. 103 // are deleting.
259 // TODO(mattm): http://crbug.com/166069 Make the server bound cert 104 // TODO(mattm): http://crbug.com/166069 Make the server bound cert
260 // service/store have observers that can notify relevant things directly. 105 // service/store have observers that can notify relevant things directly.
261 rq_context->GetURLRequestContext() 106 rq_context->GetURLRequestContext()
262 ->ssl_config_service() 107 ->ssl_config_service()
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 164
320 BrowsingDataRemover::BrowsingDataRemover( 165 BrowsingDataRemover::BrowsingDataRemover(
321 content::BrowserContext* browser_context) 166 content::BrowserContext* browser_context)
322 : profile_(Profile::FromBrowserContext(browser_context)), 167 : profile_(Profile::FromBrowserContext(browser_context)),
323 remove_mask_(-1), 168 remove_mask_(-1),
324 origin_type_mask_(-1), 169 origin_type_mask_(-1),
325 is_removing_(false), 170 is_removing_(false),
326 #if BUILDFLAG(ENABLE_PLUGINS) 171 #if BUILDFLAG(ENABLE_PLUGINS)
327 flash_lso_helper_(BrowsingDataFlashLSOHelper::Create(profile_)), 172 flash_lso_helper_(BrowsingDataFlashLSOHelper::Create(profile_)),
328 #endif 173 #endif
329 #if BUILDFLAG(ANDROID_JAVA_UI)
330 webapp_registry_(new WebappRegistry()),
331 #endif
332 weak_ptr_factory_(this) { 174 weak_ptr_factory_(this) {
333 DCHECK(browser_context); 175 DCHECK(browser_context);
334 } 176 }
335 177
336 BrowsingDataRemover::~BrowsingDataRemover() { 178 BrowsingDataRemover::~BrowsingDataRemover() {
337 if (!task_queue_.empty()) { 179 if (!task_queue_.empty()) {
338 VLOG(1) << "BrowsingDataRemover shuts down with " << task_queue_.size() 180 VLOG(1) << "BrowsingDataRemover shuts down with " << task_queue_.size()
339 << " pending tasks"; 181 << " pending tasks";
340 } 182 }
341 183
342 // If we are still removing data, notify observers that their task has been 184 // If we are still removing data, notify observers that their task has been
343 // (albeit unsucessfuly) processed, so they can unregister themselves. 185 // (albeit unsucessfuly) processed, so they can unregister themselves.
344 // TODO(bauerb): If it becomes a problem that browsing data might not actually 186 // TODO(bauerb): If it becomes a problem that browsing data might not actually
345 // be fully cleared when an observer is notified, add a success flag. 187 // be fully cleared when an observer is notified, add a success flag.
346 while (!task_queue_.empty()) { 188 while (!task_queue_.empty()) {
347 if (observer_list_.HasObserver(task_queue_.front().observer)) 189 if (observer_list_.HasObserver(task_queue_.front().observer))
348 task_queue_.front().observer->OnBrowsingDataRemoverDone(); 190 task_queue_.front().observer->OnBrowsingDataRemoverDone();
349 task_queue_.pop(); 191 task_queue_.pop();
350 } 192 }
351 } 193 }
352 194
353 void BrowsingDataRemover::Shutdown() { 195 void BrowsingDataRemover::Shutdown() {
354 history_task_tracker_.TryCancelAll(); 196 embedder_delegate_.reset();
355 template_url_sub_.reset();
356 } 197 }
357 198
358 void BrowsingDataRemover::SetRemoving(bool is_removing) { 199 void BrowsingDataRemover::SetRemoving(bool is_removing) {
359 DCHECK_NE(is_removing_, is_removing); 200 DCHECK_NE(is_removing_, is_removing);
360 is_removing_ = is_removing; 201 is_removing_ = is_removing;
361 } 202 }
362 203
363 void BrowsingDataRemover::Remove(const TimeRange& time_range, 204 void BrowsingDataRemover::Remove(const TimeRange& time_range,
364 int remove_mask, 205 int remove_mask,
365 int origin_type_mask) { 206 int origin_type_mask) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 306
466 // crbug.com/140910: Many places were calling this with base::Time() as 307 // crbug.com/140910: Many places were calling this with base::Time() as
467 // delete_end, even though they should've used base::Time::Max(). 308 // delete_end, even though they should've used base::Time::Max().
468 DCHECK_NE(base::Time(), time_range.end); 309 DCHECK_NE(base::Time(), time_range.end);
469 310
470 delete_begin_ = time_range.begin; 311 delete_begin_ = time_range.begin;
471 delete_end_ = time_range.end; 312 delete_end_ = time_range.end;
472 remove_mask_ = remove_mask; 313 remove_mask_ = remove_mask;
473 origin_type_mask_ = origin_type_mask; 314 origin_type_mask_ = origin_type_mask;
474 315
475 base::Callback<bool(const GURL& url)> filter =
476 filter_builder.BuildGeneralFilter();
477 base::Callback<bool(const ContentSettingsPattern& url)> same_pattern_filter =
478 filter_builder.BuildWebsiteSettingsPatternMatchesFilter();
479
480 // Some backends support a filter that |is_null()| to make complete deletion
481 // more efficient.
482 base::Callback<bool(const GURL&)> nullable_filter =
483 filter_builder.IsEmptyBlacklist() ? base::Callback<bool(const GURL&)>()
484 : filter;
485
486 PrefService* prefs = profile_->GetPrefs();
487 bool may_delete_history = prefs->GetBoolean(
488 prefs::kAllowDeletingBrowserHistory);
489
490 // All the UI entry points into the BrowsingDataRemover should be disabled,
491 // but this will fire if something was missed or added.
492 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
493 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
494
495 if (origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 316 if (origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
496 content::RecordAction( 317 content::RecordAction(
497 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb")); 318 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb"));
498 } 319 }
499 if (origin_type_mask_ & BrowsingDataHelper::PROTECTED_WEB) { 320 if (origin_type_mask_ & BrowsingDataHelper::PROTECTED_WEB) {
500 content::RecordAction( 321 content::RecordAction(
501 UserMetricsAction("ClearBrowsingData_MaskContainsProtectedWeb")); 322 UserMetricsAction("ClearBrowsingData_MaskContainsProtectedWeb"));
502 } 323 }
503 if (origin_type_mask_ & BrowsingDataHelper::EXTENSION) { 324 if (origin_type_mask_ & BrowsingDataHelper::EXTENSION) {
504 content::RecordAction( 325 content::RecordAction(
505 UserMetricsAction("ClearBrowsingData_MaskContainsExtension")); 326 UserMetricsAction("ClearBrowsingData_MaskContainsExtension"));
506 } 327 }
507 // If this fires, we added a new BrowsingDataHelper::OriginTypeMask without 328 // If this fires, we added a new BrowsingDataHelper::OriginTypeMask without
508 // updating the user metrics above. 329 // updating the user metrics above.
509 static_assert( 330 static_assert(
510 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB | 331 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB |
511 BrowsingDataHelper::PROTECTED_WEB | 332 BrowsingDataHelper::PROTECTED_WEB |
512 BrowsingDataHelper::EXTENSION), 333 BrowsingDataHelper::EXTENSION),
513 "OriginTypeMask has been updated without updating user metrics"); 334 "OriginTypeMask has been updated without updating user metrics");
514 335
336 // Record the combined deletion of cookies and cache.
337 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE;
338 if (remove_mask & REMOVE_COOKIES &&
339 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
340 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE
341 : ONLY_COOKIES;
342 } else if (remove_mask & REMOVE_CACHE) {
343 choice = ONLY_CACHE;
344 }
345
346 UMA_HISTOGRAM_ENUMERATION(
347 "History.ClearBrowsingData.UserDeletedCookieOrCache",
348 choice, MAX_CHOICE_VALUE);
349
350 // Managed devices and supervised users can have restrictions on history
351 // deletion.
352 PrefService* prefs = profile_->GetPrefs();
353 bool may_delete_history = prefs->GetBoolean(
354 prefs::kAllowDeletingBrowserHistory);
355
356 // All the UI entry points into the BrowsingDataRemover should be disabled,
357 // but this will fire if something was missed or added.
358 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
359 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
360
361 //////////////////////////////////////////////////////////////////////////////
362 // INITIALIZATION
363 base::Callback<bool(const GURL& url)> filter =
364 filter_builder.BuildGeneralFilter();
365
515 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { 366 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
516 history::HistoryService* history_service =
517 HistoryServiceFactory::GetForProfile(
518 profile_, ServiceAccessType::EXPLICIT_ACCESS);
519 if (history_service) {
520 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
521 content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
522 waiting_for_clear_history_ = true;
523 history_service->ExpireLocalAndRemoteHistoryBetween(
524 WebHistoryServiceFactory::GetForProfile(profile_), std::set<GURL>(),
525 delete_begin_, delete_end_,
526 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
527 weak_ptr_factory_.GetWeakPtr()),
528 &history_task_tracker_);
529 }
530
531 ntp_snippets::ContentSuggestionsService* content_suggestions_service =
532 ContentSuggestionsServiceFactory::GetForProfileIfExists(profile_);
533 if (content_suggestions_service) {
534 content_suggestions_service->ClearHistory(delete_begin_, delete_end_,
535 filter);
536 }
537
538 #if BUILDFLAG(ENABLE_EXTENSIONS)
539 // The extension activity log contains details of which websites extensions
540 // were active on. It therefore indirectly stores details of websites a
541 // user has visited so best clean from here as well.
542 // TODO(msramek): Support all backends with filter (crbug.com/589586).
543 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(
544 std::set<GURL>());
545
546 // Clear launch times as they are a form of history.
547 // BrowsingDataFilterBuilder currently doesn't support extension origins.
548 // Therefore, clearing history for a small set of origins (WHITELIST) should
549 // never delete any extension launch times, while clearing for almost all
550 // origins (BLACKLIST) should always delete all of extension launch times.
551 if (filter_builder.mode() == BrowsingDataFilterBuilder::BLACKLIST) {
552 extensions::ExtensionPrefs* extension_prefs =
553 extensions::ExtensionPrefs::Get(profile_);
554 extension_prefs->ClearLastLaunchTimes();
555 }
556 #endif
557
558 // Need to clear the host cache and accumulated speculative data, as it also
559 // reveals some history. We have no mechanism to track when these items were
560 // created, so we'll not honor the time range.
561 // TODO(msramek): We can use the plugin filter here because plugins, same
562 // as the hostname resolution cache, key their entries by hostname. Rename
563 // BuildPluginFilter() to something more general to reflect this use.
564 if (g_browser_process->io_thread()) {
565 waiting_for_clear_hostname_resolution_cache_ = true;
566 BrowserThread::PostTaskAndReply(
567 BrowserThread::IO, FROM_HERE,
568 base::Bind(&ClearHostnameResolutionCacheOnIOThread,
569 g_browser_process->io_thread(),
570 filter_builder.BuildPluginFilter()),
571 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache,
572 weak_ptr_factory_.GetWeakPtr()));
573 }
574 if (profile_->GetNetworkPredictor()) {
575 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
576 waiting_for_clear_network_predictor_ = true;
577 BrowserThread::PostTaskAndReply(
578 BrowserThread::IO, FROM_HERE,
579 base::Bind(&ClearNetworkPredictorOnIOThread,
580 profile_->GetNetworkPredictor()),
581 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor,
582 weak_ptr_factory_.GetWeakPtr()));
583 profile_->GetNetworkPredictor()->ClearPrefsOnUIThread();
584 }
585
586 // As part of history deletion we also delete the auto-generated keywords.
587 TemplateURLService* keywords_model =
588 TemplateURLServiceFactory::GetForProfile(profile_);
589
590 if (keywords_model && !keywords_model->loaded()) {
591 // TODO(msramek): Store filters from the currently executed task on the
592 // object to avoid having to copy them to callback methods.
593 template_url_sub_ = keywords_model->RegisterOnLoadedCallback(
594 base::Bind(&BrowsingDataRemover::OnKeywordsLoaded,
595 weak_ptr_factory_.GetWeakPtr(), filter));
596 keywords_model->Load();
597 waiting_for_clear_keyword_data_ = true;
598 } else if (keywords_model) {
599 keywords_model->RemoveAutoGeneratedForUrlsBetween(filter, delete_begin_,
600 delete_end_);
601 }
602
603 // The PrerenderManager keeps history of prerendered pages, so clear that.
604 // It also may have a prerendered page. If so, the page could be
605 // considered to have a small amount of historical information, so delete
606 // it, too.
607 prerender::PrerenderManager* prerender_manager =
608 prerender::PrerenderManagerFactory::GetForBrowserContext(profile_);
609 if (prerender_manager) {
610 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
611 prerender_manager->ClearData(
612 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
613 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
614 }
615
616 // If the caller is removing history for all hosts, then clear ancillary
617 // historical information.
618 if (filter_builder.IsEmptyBlacklist()) {
619 // We also delete the list of recently closed tabs. Since these expire,
620 // they can't be more than a day old, so we can simply clear them all.
621 sessions::TabRestoreService* tab_service =
622 TabRestoreServiceFactory::GetForProfile(profile_);
623 if (tab_service) {
624 tab_service->ClearEntries();
625 tab_service->DeleteLastSession();
626 }
627
628 #if BUILDFLAG(ENABLE_SESSION_SERVICE)
629 // We also delete the last session when we delete the history.
630 SessionService* session_service =
631 SessionServiceFactory::GetForProfile(profile_);
632 if (session_service)
633 session_service->DeleteLastSession();
634 #endif
635 }
636
637 // The saved Autofill profiles and credit cards can include the origin from
638 // which these profiles and credit cards were learned. These are a form of
639 // history, so clear them as well.
640 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
641 scoped_refptr<autofill::AutofillWebDataService> web_data_service =
642 WebDataServiceFactory::GetAutofillWebDataForProfile(
643 profile_, ServiceAccessType::EXPLICIT_ACCESS);
644 if (web_data_service.get()) {
645 waiting_for_clear_autofill_origin_urls_ = true;
646 web_data_service->RemoveOriginURLsModifiedBetween(
647 delete_begin_, delete_end_);
648 // The above calls are done on the UI thread but do their work on the DB
649 // thread. So wait for it.
650 BrowserThread::PostTaskAndReply(
651 BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
652 base::Bind(&BrowsingDataRemover::OnClearedAutofillOriginURLs,
653 weak_ptr_factory_.GetWeakPtr()));
654
655 autofill::PersonalDataManager* data_manager =
656 autofill::PersonalDataManagerFactory::GetForProfile(profile_);
657 if (data_manager)
658 data_manager->Refresh();
659 }
660
661 #if BUILDFLAG(ENABLE_WEBRTC)
662 waiting_for_clear_webrtc_logs_ = true;
663 BrowserThread::PostTaskAndReply(
664 BrowserThread::FILE, FROM_HERE,
665 base::Bind(
666 &WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles,
667 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()),
668 delete_begin_),
669 base::Bind(&BrowsingDataRemover::OnClearedWebRtcLogs,
670 weak_ptr_factory_.GetWeakPtr()));
671 #endif
672
673 // The SSL Host State that tracks SSL interstitial "proceed" decisions may 367 // The SSL Host State that tracks SSL interstitial "proceed" decisions may
674 // include origins that the user has visited, so it must be cleared. 368 // include origins that the user has visited, so it must be cleared.
675 // TODO(msramek): We can reuse the plugin filter here, since both plugins 369 // TODO(msramek): We can reuse the plugin filter here, since both plugins
676 // and SSL host state are scoped to hosts and represent them as std::string. 370 // and SSL host state are scoped to hosts and represent them as std::string.
677 // Rename the method to indicate its more general usage. 371 // Rename the method to indicate its more general usage.
678 if (profile_->GetSSLHostStateDelegate()) { 372 if (profile_->GetSSLHostStateDelegate()) {
679 profile_->GetSSLHostStateDelegate()->Clear( 373 profile_->GetSSLHostStateDelegate()->Clear(
680 filter_builder.IsEmptyBlacklist() 374 filter_builder.IsEmptyBlacklist()
681 ? base::Callback<bool(const std::string&)>() 375 ? base::Callback<bool(const std::string&)>()
682 : filter_builder.BuildPluginFilter()); 376 : filter_builder.BuildPluginFilter());
683 } 377 }
684
685 #if BUILDFLAG(ANDROID_JAVA_UI)
686 precache::PrecacheManager* precache_manager =
687 precache::PrecacheManagerFactory::GetForBrowserContext(profile_);
688 // |precache_manager| could be nullptr if the profile is off the record.
689 if (!precache_manager) {
690 waiting_for_clear_precache_history_ = true;
691 precache_manager->ClearHistory();
692 // The above calls are done on the UI thread but do their work on the DB
693 // thread. So wait for it.
694 BrowserThread::PostTaskAndReply(
695 BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
696 base::Bind(&BrowsingDataRemover::OnClearedPrecacheHistory,
697 weak_ptr_factory_.GetWeakPtr()));
698 }
699
700 // Clear the history information (last launch time and origin URL) of any
701 // registered webapps.
702 webapp_registry_->ClearWebappHistoryForUrls(filter);
703 #endif
704
705 data_reduction_proxy::DataReductionProxySettings*
706 data_reduction_proxy_settings =
707 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
708 profile_);
709 // |data_reduction_proxy_settings| is null if |profile_| is off the record.
710 if (data_reduction_proxy_settings) {
711 data_reduction_proxy::DataReductionProxyService*
712 data_reduction_proxy_service =
713 data_reduction_proxy_settings->data_reduction_proxy_service();
714 if (data_reduction_proxy_service) {
715 data_reduction_proxy_service->compression_stats()
716 ->DeleteBrowsingHistory(delete_begin_, delete_end_);
717 }
718 }
719
720 // |previews_service| is null if |profile_| is off the record.
721 PreviewsService* previews_service =
722 PreviewsServiceFactory::GetForProfile(profile_);
723 if (previews_service && previews_service->previews_ui_service()) {
724 previews_service->previews_ui_service()->ClearBlackList(delete_begin_,
725 delete_end_);
726 }
727 } 378 }
728 379
380 //////////////////////////////////////////////////////////////////////////////
381 // REMOVE_DOWNLOADS
729 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) { 382 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) {
730 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); 383 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
731 content::DownloadManager* download_manager = 384 content::DownloadManager* download_manager =
732 BrowserContext::GetDownloadManager(profile_); 385 BrowserContext::GetDownloadManager(profile_);
733 download_manager->RemoveDownloadsByURLAndTime(filter, 386 download_manager->RemoveDownloadsByURLAndTime(filter,
734 delete_begin_, delete_end_); 387 delete_begin_, delete_end_);
735 DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager( 388 DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager(
736 download_manager); 389 download_manager);
737 download_prefs->SetSaveFilePath(download_prefs->DownloadPath()); 390 download_prefs->SetSaveFilePath(download_prefs->DownloadPath());
738 } 391 }
739 392
740 uint32_t storage_partition_remove_mask = 0; 393 //////////////////////////////////////////////////////////////////////////////
741 394 // REMOVE_CHANNEL_IDS
742 // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set,
743 // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB
744 // don't accidentally remove the cookies that are associated with the
745 // UNPROTECTED_WEB origin. This is necessary because cookies are not separated
746 // between UNPROTECTED_WEB and PROTECTED_WEB.
747 if (remove_mask & REMOVE_COOKIES &&
748 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
749 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
750
751 storage_partition_remove_mask |=
752 content::StoragePartition::REMOVE_DATA_MASK_COOKIES;
753
754 // Clear the safebrowsing cookies only if time period is for "all time". It
755 // doesn't make sense to apply the time period of deleting in the last X
756 // hours/days to the safebrowsing cookies since they aren't the result of
757 // any user action.
758 if (delete_begin_ == base::Time()) {
759 safe_browsing::SafeBrowsingService* sb_service =
760 g_browser_process->safe_browsing_service();
761 if (sb_service) {
762 scoped_refptr<net::URLRequestContextGetter> sb_context =
763 sb_service->url_request_context();
764 ++waiting_for_clear_cookies_count_;
765 if (filter_builder.IsEmptyBlacklist()) {
766 BrowserThread::PostTask(
767 BrowserThread::IO, FROM_HERE,
768 base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_,
769 base::RetainedRef(std::move(sb_context)),
770 UIThreadTrampoline(
771 base::Bind(&BrowsingDataRemover::OnClearedCookies,
772 weak_ptr_factory_.GetWeakPtr()))));
773 } else {
774 BrowserThread::PostTask(
775 BrowserThread::IO, FROM_HERE,
776 base::Bind(&ClearCookiesWithPredicateOnIOThread, delete_begin_,
777 delete_end_, filter_builder.BuildCookieFilter(),
778 base::RetainedRef(std::move(sb_context)),
779 UIThreadTrampoline(
780 base::Bind(&BrowsingDataRemover::OnClearedCookies,
781 weak_ptr_factory_.GetWeakPtr()))));
782 }
783 }
784 }
785
786 MediaDeviceIDSalt::Reset(profile_->GetPrefs());
787 }
788
789 // Channel IDs are not separated for protected and unprotected web 395 // Channel IDs are not separated for protected and unprotected web
790 // origins. We check the origin_type_mask_ to prevent unintended deletion. 396 // origins. We check the origin_type_mask_ to prevent unintended deletion.
791 if (remove_mask & REMOVE_CHANNEL_IDS && 397 if (remove_mask & REMOVE_CHANNEL_IDS &&
792 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 398 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
793 content::RecordAction( 399 content::RecordAction(
794 UserMetricsAction("ClearBrowsingData_ChannelIDs")); 400 UserMetricsAction("ClearBrowsingData_ChannelIDs"));
795 // Since we are running on the UI thread don't call GetURLRequestContext(). 401 // Since we are running on the UI thread don't call GetURLRequestContext().
796 scoped_refptr<net::URLRequestContextGetter> rq_context = 402 scoped_refptr<net::URLRequestContextGetter> rq_context =
797 content::BrowserContext::GetDefaultStoragePartition(profile_)-> 403 content::BrowserContext::GetDefaultStoragePartition(profile_)->
798 GetURLRequestContext(); 404 GetURLRequestContext();
799 waiting_for_clear_channel_ids_ = true; 405 waiting_for_clear_channel_ids_ = true;
800 BrowserThread::PostTask( 406 BrowserThread::PostTask(
801 BrowserThread::IO, FROM_HERE, 407 BrowserThread::IO, FROM_HERE,
802 base::Bind(&ClearChannelIDsOnIOThread, 408 base::Bind(&ClearChannelIDsOnIOThread,
803 filter_builder.BuildChannelIDFilter(), 409 filter_builder.BuildChannelIDFilter(),
804 delete_begin_, delete_end_, std::move(rq_context), 410 delete_begin_, delete_end_, std::move(rq_context),
805 base::Bind(&BrowsingDataRemover::OnClearedChannelIDs, 411 base::Bind(&BrowsingDataRemover::OnClearedChannelIDs,
806 weak_ptr_factory_.GetWeakPtr()))); 412 weak_ptr_factory_.GetWeakPtr())));
807 } 413 }
808 414
809 if (remove_mask & REMOVE_DURABLE_PERMISSION) { 415 //////////////////////////////////////////////////////////////////////////////
810 HostContentSettingsMapFactory::GetForProfile(profile_) 416 // STORAGE PARTITION DATA
811 ->ClearSettingsForOneTypeWithPredicate( 417 uint32_t storage_partition_remove_mask = 0;
812 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, 418
813 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter)); 419 // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set,
420 // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB
421 // don't accidentally remove the cookies that are associated with the
422 // UNPROTECTED_WEB origin. This is necessary because cookies are not separated
423 // between UNPROTECTED_WEB and PROTECTED_WEB.
424 if (remove_mask & REMOVE_COOKIES &&
425 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
426 storage_partition_remove_mask |=
427 content::StoragePartition::REMOVE_DATA_MASK_COOKIES;
814 } 428 }
815
816 if (remove_mask & REMOVE_LOCAL_STORAGE) { 429 if (remove_mask & REMOVE_LOCAL_STORAGE) {
817 storage_partition_remove_mask |= 430 storage_partition_remove_mask |=
818 content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; 431 content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE;
819 } 432 }
820
821 if (remove_mask & REMOVE_INDEXEDDB) { 433 if (remove_mask & REMOVE_INDEXEDDB) {
822 storage_partition_remove_mask |= 434 storage_partition_remove_mask |=
823 content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; 435 content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB;
824 } 436 }
825 if (remove_mask & REMOVE_WEBSQL) { 437 if (remove_mask & REMOVE_WEBSQL) {
826 storage_partition_remove_mask |= 438 storage_partition_remove_mask |=
827 content::StoragePartition::REMOVE_DATA_MASK_WEBSQL; 439 content::StoragePartition::REMOVE_DATA_MASK_WEBSQL;
828 } 440 }
829 if (remove_mask & REMOVE_APPCACHE) { 441 if (remove_mask & REMOVE_APPCACHE) {
830 storage_partition_remove_mask |= 442 storage_partition_remove_mask |=
831 content::StoragePartition::REMOVE_DATA_MASK_APPCACHE; 443 content::StoragePartition::REMOVE_DATA_MASK_APPCACHE;
832 } 444 }
833 if (remove_mask & REMOVE_SERVICE_WORKERS) { 445 if (remove_mask & REMOVE_SERVICE_WORKERS) {
834 storage_partition_remove_mask |= 446 storage_partition_remove_mask |=
835 content::StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS; 447 content::StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS;
836 } 448 }
837 if (remove_mask & REMOVE_CACHE_STORAGE) { 449 if (remove_mask & REMOVE_CACHE_STORAGE) {
838 storage_partition_remove_mask |= 450 storage_partition_remove_mask |=
839 content::StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE; 451 content::StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE;
840 } 452 }
841 if (remove_mask & REMOVE_FILE_SYSTEMS) { 453 if (remove_mask & REMOVE_FILE_SYSTEMS) {
842 storage_partition_remove_mask |= 454 storage_partition_remove_mask |=
843 content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; 455 content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS;
844 } 456 }
845 457
458 // Content Decryption Modules used by Encrypted Media store licenses in a
459 // private filesystem. These are different than content licenses used by
460 // Flash (which are deleted father down in this method).
461 if (remove_mask & REMOVE_MEDIA_LICENSES) {
462 storage_partition_remove_mask |=
463 content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA;
464 }
465
466 if (storage_partition_remove_mask) {
467 waiting_for_clear_storage_partition_data_ = true;
468
469 content::StoragePartition* storage_partition;
470 if (storage_partition_for_testing_)
471 storage_partition = storage_partition_for_testing_;
472 else
473 storage_partition = BrowserContext::GetDefaultStoragePartition(profile_);
474
475 uint32_t quota_storage_remove_mask =
476 ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
477
478 if (delete_begin_ == base::Time() ||
479 origin_type_mask_ &
480 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
481 // If we're deleting since the beginning of time, or we're removing
482 // protected origins, then remove persistent quota data.
483 quota_storage_remove_mask |=
484 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
485 }
486
487 // If cookies are supposed to be conditionally deleted from the storage
488 // partition, create a cookie matcher function.
489 content::StoragePartition::CookieMatcherFunction cookie_matcher;
490 if (!filter_builder.IsEmptyBlacklist() &&
491 (storage_partition_remove_mask &
492 content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) {
493 cookie_matcher = filter_builder.BuildCookieFilter();
494 }
495
496 storage_partition->ClearData(
497 storage_partition_remove_mask, quota_storage_remove_mask,
498 base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_, filter),
499 cookie_matcher, delete_begin_, delete_end_,
500 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData,
501 weak_ptr_factory_.GetWeakPtr()));
502 }
503
504 //////////////////////////////////////////////////////////////////////////////
505 // REMOVE_PLUGINS
846 #if BUILDFLAG(ENABLE_PLUGINS) 506 #if BUILDFLAG(ENABLE_PLUGINS)
847 // Plugin is data not separated for protected and unprotected web origins. We 507 // Plugin is data not separated for protected and unprotected web origins. We
848 // check the origin_type_mask_ to prevent unintended deletion. 508 // check the origin_type_mask_ to prevent unintended deletion.
849 if (remove_mask & REMOVE_PLUGIN_DATA && 509 if (remove_mask & REMOVE_PLUGIN_DATA &&
850 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 510 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
851 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); 511 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
852 waiting_for_clear_plugin_data_count_ = 1; 512 waiting_for_clear_plugin_data_count_ = 1;
853 513
854 if (filter_builder.IsEmptyBlacklist()) { 514 if (filter_builder.IsEmptyBlacklist()) {
855 DCHECK(!plugin_data_remover_); 515 DCHECK(!plugin_data_remover_);
856 plugin_data_remover_.reset(content::PluginDataRemover::Create(profile_)); 516 plugin_data_remover_.reset(content::PluginDataRemover::Create(profile_));
857 base::WaitableEvent* event = 517 base::WaitableEvent* event =
858 plugin_data_remover_->StartRemoving(delete_begin_); 518 plugin_data_remover_->StartRemoving(delete_begin_);
859 519
860 base::WaitableEventWatcher::EventCallback watcher_callback = 520 base::WaitableEventWatcher::EventCallback watcher_callback =
861 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled, 521 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled,
862 weak_ptr_factory_.GetWeakPtr()); 522 weak_ptr_factory_.GetWeakPtr());
863 watcher_.StartWatching(event, watcher_callback); 523 watcher_.StartWatching(event, watcher_callback);
864 } else { 524 } else {
865 // TODO(msramek): Store filters from the currently executed task on the 525 // TODO(msramek): Store filters from the currently executed task on the
866 // object to avoid having to copy them to callback methods. 526 // object to avoid having to copy them to callback methods.
867 flash_lso_helper_->StartFetching(base::Bind( 527 flash_lso_helper_->StartFetching(base::Bind(
868 &BrowsingDataRemover::OnSitesWithFlashDataFetched, 528 &BrowsingDataRemover::OnSitesWithFlashDataFetched,
869 weak_ptr_factory_.GetWeakPtr(), 529 weak_ptr_factory_.GetWeakPtr(),
870 filter_builder.BuildPluginFilter())); 530 filter_builder.BuildPluginFilter()));
871 } 531 }
872 } 532 }
873 #endif 533 #endif
874 534
875 if (remove_mask & REMOVE_SITE_USAGE_DATA) { 535 //////////////////////////////////////////////////////////////////////////////
876 HostContentSettingsMapFactory::GetForProfile(profile_) 536 // CACHE
877 ->ClearSettingsForOneTypeWithPredicate(
878 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
879 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
880 }
881
882 if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) {
883 HostContentSettingsMapFactory::GetForProfile(profile_)
884 ->ClearSettingsForOneTypeWithPredicate(
885 CONTENT_SETTINGS_TYPE_APP_BANNER,
886 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
887
888 PermissionDecisionAutoBlocker::RemoveCountsByUrl(profile_, filter);
889 }
890
891 if (remove_mask & REMOVE_PASSWORDS) {
892 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
893 password_manager::PasswordStore* password_store =
894 PasswordStoreFactory::GetForProfile(
895 profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
896
897 if (password_store) {
898 waiting_for_clear_passwords_ = true;
899 auto on_cleared_passwords =
900 base::Bind(&BrowsingDataRemover::OnClearedPasswords,
901 weak_ptr_factory_.GetWeakPtr());
902 password_store->RemoveLoginsByURLAndTime(
903 filter, delete_begin_, delete_end_, on_cleared_passwords);
904 }
905 }
906
907 if (remove_mask & REMOVE_COOKIES) {
908 password_manager::PasswordStore* password_store =
909 PasswordStoreFactory::GetForProfile(profile_,
910 ServiceAccessType::EXPLICIT_ACCESS)
911 .get();
912
913 if (password_store) {
914 waiting_for_clear_auto_sign_in_ = true;
915 base::Closure on_cleared_auto_sign_in =
916 base::Bind(&BrowsingDataRemover::OnClearedAutoSignIn,
917 weak_ptr_factory_.GetWeakPtr());
918 password_store->DisableAutoSignInForOrigins(
919 filter, on_cleared_auto_sign_in);
920 }
921 }
922
923 if (remove_mask & REMOVE_HISTORY) {
924 password_manager::PasswordStore* password_store =
925 PasswordStoreFactory::GetForProfile(
926 profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
927
928 if (password_store) {
929 waiting_for_clear_passwords_stats_ = true;
930 password_store->RemoveStatisticsByOriginAndTime(
931 nullable_filter, delete_begin_, delete_end_,
932 base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats,
933 weak_ptr_factory_.GetWeakPtr()));
934 }
935 }
936
937 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
938 if (remove_mask & REMOVE_FORM_DATA) {
939 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
940 scoped_refptr<autofill::AutofillWebDataService> web_data_service =
941 WebDataServiceFactory::GetAutofillWebDataForProfile(
942 profile_, ServiceAccessType::EXPLICIT_ACCESS);
943
944 if (web_data_service.get()) {
945 waiting_for_clear_form_ = true;
946 web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
947 delete_end_);
948 web_data_service->RemoveAutofillDataModifiedBetween(
949 delete_begin_, delete_end_);
950 // The above calls are done on the UI thread but do their work on the DB
951 // thread. So wait for it.
952 BrowserThread::PostTaskAndReply(
953 BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
954 base::Bind(&BrowsingDataRemover::OnClearedFormData,
955 weak_ptr_factory_.GetWeakPtr()));
956
957 autofill::PersonalDataManager* data_manager =
958 autofill::PersonalDataManagerFactory::GetForProfile(profile_);
959 if (data_manager)
960 data_manager->Refresh();
961 }
962 }
963
964 if (remove_mask & REMOVE_CACHE) { 537 if (remove_mask & REMOVE_CACHE) {
965 // Tell the renderers to clear their cache. 538 // Tell the renderers to clear their cache.
966 web_cache::WebCacheManager::GetInstance()->ClearCache(); 539 web_cache::WebCacheManager::GetInstance()->ClearCache();
967 540
968 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); 541 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache"));
969 542
970 waiting_for_clear_cache_ = true; 543 waiting_for_clear_cache_ = true;
971 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. 544 // StoragePartitionHttpCacheDataRemover deletes itself when it is done.
972 if (filter_builder.IsEmptyBlacklist()) { 545 if (filter_builder.IsEmptyBlacklist()) {
973 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( 546 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
974 BrowserContext::GetDefaultStoragePartition(profile_), 547 BrowserContext::GetDefaultStoragePartition(profile_),
975 delete_begin_, delete_end_) 548 delete_begin_, delete_end_)
976 ->Remove(base::Bind(&BrowsingDataRemover::ClearedCache, 549 ->Remove(base::Bind(&BrowsingDataRemover::ClearedCache,
977 weak_ptr_factory_.GetWeakPtr())); 550 weak_ptr_factory_.GetWeakPtr()));
978 } else { 551 } else {
979 browsing_data::StoragePartitionHttpCacheDataRemover:: 552 browsing_data::StoragePartitionHttpCacheDataRemover::
980 CreateForURLsAndRange( 553 CreateForURLsAndRange(
981 BrowserContext::GetDefaultStoragePartition(profile_), 554 BrowserContext::GetDefaultStoragePartition(profile_),
982 filter, delete_begin_, delete_end_) 555 filter, delete_begin_, delete_end_)
983 ->Remove(base::Bind(&BrowsingDataRemover::ClearedCache, 556 ->Remove(base::Bind(&BrowsingDataRemover::ClearedCache,
984 weak_ptr_factory_.GetWeakPtr())); 557 weak_ptr_factory_.GetWeakPtr()));
985 } 558 }
986 559
987 #if !defined(DISABLE_NACL)
988 waiting_for_clear_nacl_cache_ = true;
989
990 BrowserThread::PostTask(
991 BrowserThread::IO, FROM_HERE,
992 base::Bind(&ClearNaClCacheOnIOThread,
993 UIThreadTrampoline(
994 base::Bind(&BrowsingDataRemover::ClearedNaClCache,
995 weak_ptr_factory_.GetWeakPtr()))));
996
997 waiting_for_clear_pnacl_cache_ = true;
998 BrowserThread::PostTask(
999 BrowserThread::IO, FROM_HERE,
1000 base::Bind(&ClearPnaclCacheOnIOThread, delete_begin_, delete_end_,
1001 UIThreadTrampoline(
1002 base::Bind(&BrowsingDataRemover::ClearedPnaclCache,
1003 weak_ptr_factory_.GetWeakPtr()))));
1004 #endif
1005
1006 // The PrerenderManager may have a page actively being prerendered, which
1007 // is essentially a preemptively cached page.
1008 prerender::PrerenderManager* prerender_manager =
1009 prerender::PrerenderManagerFactory::GetForBrowserContext(profile_);
1010 if (prerender_manager) {
1011 prerender_manager->ClearData(
1012 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS);
1013 }
1014
1015 // Tell the shader disk cache to clear. 560 // Tell the shader disk cache to clear.
1016 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); 561 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache"));
1017 storage_partition_remove_mask |= 562 storage_partition_remove_mask |=
1018 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; 563 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE;
1019
1020 // When clearing cache, wipe accumulated network related data
1021 // (TransportSecurityState and HttpServerPropertiesManager data).
1022 waiting_for_clear_networking_history_ = true;
1023 profile_->ClearNetworkingHistorySince(
1024 delete_begin_,
1025 base::Bind(&BrowsingDataRemover::OnClearedNetworkingHistory,
1026 weak_ptr_factory_.GetWeakPtr()));
1027
1028 ntp_snippets::ContentSuggestionsService* content_suggestions_service =
1029 ContentSuggestionsServiceFactory::GetForProfileIfExists(profile_);
1030 if (content_suggestions_service)
1031 content_suggestions_service->ClearAllCachedSuggestions();
1032
1033 // |ui_nqe_service| may be null if |profile_| is not a regular profile.
1034 UINetworkQualityEstimatorService* ui_nqe_service =
1035 UINetworkQualityEstimatorServiceFactory::GetForProfile(profile_);
1036 DCHECK(profile_->GetProfileType() !=
1037 Profile::ProfileType::REGULAR_PROFILE ||
1038 ui_nqe_service != nullptr);
1039 if (ui_nqe_service) {
1040 // Network Quality Estimator (NQE) stores the quality (RTT, bandwidth
1041 // etc.) of different networks in prefs. The stored quality is not
1042 // broken down by URLs or timestamps, so clearing the cache should
1043 // completely clear the prefs.
1044 ui_nqe_service->ClearPrefs();
1045 }
1046 } 564 }
1047 565
566 //////////////////////////////////////////////////////////////////////////////
567 // Auth cache.
1048 if (remove_mask & REMOVE_COOKIES || remove_mask & REMOVE_PASSWORDS) { 568 if (remove_mask & REMOVE_COOKIES || remove_mask & REMOVE_PASSWORDS) {
1049 scoped_refptr<net::URLRequestContextGetter> request_context = 569 scoped_refptr<net::URLRequestContextGetter> request_context =
1050 profile_->GetRequestContext(); 570 profile_->GetRequestContext();
1051 waiting_for_clear_http_auth_cache_ = true; 571 waiting_for_clear_http_auth_cache_ = true;
1052 BrowserThread::PostTaskAndReply( 572 BrowserThread::PostTaskAndReply(
1053 BrowserThread::IO, FROM_HERE, 573 BrowserThread::IO, FROM_HERE,
1054 base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context), 574 base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context),
1055 delete_begin_), 575 delete_begin_),
1056 base::Bind(&BrowsingDataRemover::OnClearedHttpAuthCache, 576 base::Bind(&BrowsingDataRemover::OnClearedHttpAuthCache,
1057 weak_ptr_factory_.GetWeakPtr())); 577 weak_ptr_factory_.GetWeakPtr()));
1058 } 578 }
1059 579
1060 // Content Decryption Modules used by Encrypted Media store licenses in a 580 //////////////////////////////////////////////////////////////////////////////
1061 // private filesystem. These are different than content licenses used by 581 // Embedder data.
1062 // Flash (which are deleted father down in this method). 582 if (embedder_delegate_) {
1063 if (remove_mask & REMOVE_MEDIA_LICENSES) { 583 waiting_for_clear_embedder_data_ = true;
1064 storage_partition_remove_mask |= 584 embedder_delegate_->RemoveEmbedderData(
1065 content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA; 585 delete_begin_,
1066 } 586 delete_end_,
1067 587 remove_mask,
1068 if (storage_partition_remove_mask) { 588 filter_builder,
1069 waiting_for_clear_storage_partition_data_ = true; 589 origin_type_mask,
1070 590 base::Bind(&BrowsingDataRemover::OnClearedEmbedderData,
1071 content::StoragePartition* storage_partition;
1072 if (storage_partition_for_testing_)
1073 storage_partition = storage_partition_for_testing_;
1074 else
1075 storage_partition = BrowserContext::GetDefaultStoragePartition(profile_);
1076
1077 uint32_t quota_storage_remove_mask =
1078 ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1079
1080 if (delete_begin_ == base::Time() ||
1081 origin_type_mask_ &
1082 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
1083 // If we're deleting since the beginning of time, or we're removing
1084 // protected origins, then remove persistent quota data.
1085 quota_storage_remove_mask |=
1086 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1087 }
1088
1089 // If cookies are supposed to be conditionally deleted from the storage
1090 // partition, create a cookie matcher function.
1091 content::StoragePartition::CookieMatcherFunction cookie_matcher;
1092 if (!filter_builder.IsEmptyBlacklist() &&
1093 (storage_partition_remove_mask &
1094 content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) {
1095 cookie_matcher = filter_builder.BuildCookieFilter();
1096 }
1097
1098 storage_partition->ClearData(
1099 storage_partition_remove_mask, quota_storage_remove_mask,
1100 base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_, filter),
1101 cookie_matcher, delete_begin_, delete_end_,
1102 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData,
1103 weak_ptr_factory_.GetWeakPtr())); 591 weak_ptr_factory_.GetWeakPtr()));
1104 } 592 }
1105 593
1106 if (remove_mask & REMOVE_MEDIA_LICENSES) {
1107 // TODO(jrummell): This UMA should be renamed to indicate it is for Media
1108 // Licenses.
1109 content::RecordAction(
1110 UserMetricsAction("ClearBrowsingData_ContentLicenses"));
1111
1112 #if BUILDFLAG(ENABLE_PLUGINS)
1113 waiting_for_clear_flash_content_licenses_ = true;
1114 if (!pepper_flash_settings_manager_.get()) {
1115 pepper_flash_settings_manager_.reset(
1116 new PepperFlashSettingsManager(this, profile_));
1117 }
1118 deauthorize_flash_content_licenses_request_id_ =
1119 pepper_flash_settings_manager_->DeauthorizeContentLicenses(prefs);
1120 #if defined(OS_CHROMEOS)
1121 // On Chrome OS, also delete any content protection platform keys.
1122 const user_manager::User* user =
1123 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
1124 if (!user) {
1125 LOG(WARNING) << "Failed to find user for current profile.";
1126 } else {
1127 chromeos::DBusThreadManager::Get()
1128 ->GetCryptohomeClient()
1129 ->TpmAttestationDeleteKeys(
1130 chromeos::attestation::KEY_USER,
1131 cryptohome::Identification(user->GetAccountId()),
1132 chromeos::attestation::kContentProtectionKeyPrefix,
1133 base::Bind(&BrowsingDataRemover::OnClearPlatformKeys,
1134 weak_ptr_factory_.GetWeakPtr()));
1135 waiting_for_clear_platform_keys_ = true;
1136 }
1137 #endif // defined(OS_CHROMEOS)
1138 #endif // BUILDFLAG(ENABLE_PLUGINS)
1139 }
1140
1141 // Remove omnibox zero-suggest cache results. Filtering is not supported.
1142 // This is not a problem, as deleting more data than necessary will just cause
1143 // another server round-trip; no data is actually lost.
1144 if ((remove_mask & (REMOVE_CACHE | REMOVE_COOKIES)))
1145 prefs->SetString(omnibox::kZeroSuggestCachedResults, std::string());
1146
1147 if (remove_mask & (REMOVE_COOKIES | REMOVE_HISTORY)) {
1148 domain_reliability::DomainReliabilityService* service =
1149 domain_reliability::DomainReliabilityServiceFactory::
1150 GetForBrowserContext(profile_);
1151 if (service) {
1152 domain_reliability::DomainReliabilityClearMode mode;
1153 if (remove_mask & REMOVE_COOKIES)
1154 mode = domain_reliability::CLEAR_CONTEXTS;
1155 else
1156 mode = domain_reliability::CLEAR_BEACONS;
1157
1158 waiting_for_clear_domain_reliability_monitor_ = true;
1159 service->ClearBrowsingData(
1160 mode,
1161 filter,
1162 base::Bind(&BrowsingDataRemover::OnClearedDomainReliabilityMonitor,
1163 weak_ptr_factory_.GetWeakPtr()));
1164 }
1165 }
1166
1167 #if BUILDFLAG(ANDROID_JAVA_UI)
1168 // Clear all data associated with registered webapps.
1169 if (remove_mask & REMOVE_WEBAPP_DATA)
1170 webapp_registry_->UnregisterWebappsForUrls(filter);
1171
1172 // For now we're considering offline pages as cache, so if we're removing
1173 // cache we should remove offline pages as well.
1174 if ((remove_mask & REMOVE_CACHE)) {
1175 waiting_for_clear_offline_page_data_ = true;
1176 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_)
1177 ->DeleteCachedPagesByURLPredicate(
1178 filter, base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData,
1179 weak_ptr_factory_.GetWeakPtr()));
1180 }
1181 #endif
1182
1183 // Record the combined deletion of cookies and cache.
1184 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE;
1185 if (remove_mask & REMOVE_COOKIES &&
1186 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
1187 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE
1188 : ONLY_COOKIES;
1189 } else if (remove_mask & REMOVE_CACHE) {
1190 choice = ONLY_CACHE;
1191 }
1192
1193 // Notify in case all actions taken were synchronous. 594 // Notify in case all actions taken were synchronous.
1194 waiting_for_synchronous_clear_operations_ = false; 595 waiting_for_synchronous_clear_operations_ = false;
1195 NotifyIfDone(); 596 NotifyIfDone();
1196
1197 UMA_HISTOGRAM_ENUMERATION(
1198 "History.ClearBrowsingData.UserDeletedCookieOrCache",
1199 choice, MAX_CHOICE_VALUE);
1200 } 597 }
1201 598
1202 void BrowsingDataRemover::AddObserver(Observer* observer) { 599 void BrowsingDataRemover::AddObserver(Observer* observer) {
1203 observer_list_.AddObserver(observer); 600 observer_list_.AddObserver(observer);
1204 } 601 }
1205 602
1206 void BrowsingDataRemover::RemoveObserver(Observer* observer) { 603 void BrowsingDataRemover::RemoveObserver(Observer* observer) {
1207 observer_list_.RemoveObserver(observer); 604 observer_list_.RemoveObserver(observer);
1208 } 605 }
1209 606
1210 void BrowsingDataRemover::OverrideStoragePartitionForTesting( 607 void BrowsingDataRemover::OverrideStoragePartitionForTesting(
1211 content::StoragePartition* storage_partition) { 608 content::StoragePartition* storage_partition) {
1212 storage_partition_for_testing_ = storage_partition; 609 storage_partition_for_testing_ = storage_partition;
1213 } 610 }
1214 611
1215 #if BUILDFLAG(ANDROID_JAVA_UI)
1216 void BrowsingDataRemover::OverrideWebappRegistryForTesting(
1217 std::unique_ptr<WebappRegistry> webapp_registry) {
1218 webapp_registry_ = std::move(webapp_registry);
1219 }
1220 #endif
1221
1222 #if BUILDFLAG(ENABLE_PLUGINS) 612 #if BUILDFLAG(ENABLE_PLUGINS)
1223 void BrowsingDataRemover::OverrideFlashLSOHelperForTesting( 613 void BrowsingDataRemover::OverrideFlashLSOHelperForTesting(
1224 scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper) { 614 scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper) {
1225 flash_lso_helper_ = flash_lso_helper; 615 flash_lso_helper_ = flash_lso_helper;
1226 } 616 }
1227 #endif 617 #endif
1228 618
1229 const base::Time& BrowsingDataRemover::GetLastUsedBeginTime() { 619 const base::Time& BrowsingDataRemover::GetLastUsedBeginTime() {
1230 return delete_begin_; 620 return delete_begin_;
1231 } 621 }
(...skipping 19 matching lines...) Expand all
1251 : time_range(time_range), 641 : time_range(time_range),
1252 remove_mask(remove_mask), 642 remove_mask(remove_mask),
1253 origin_type_mask(origin_type_mask), 643 origin_type_mask(origin_type_mask),
1254 filter_builder(std::move(filter_builder)), 644 filter_builder(std::move(filter_builder)),
1255 observer(observer) {} 645 observer(observer) {}
1256 646
1257 BrowsingDataRemover::RemovalTask::~RemovalTask() {} 647 BrowsingDataRemover::RemovalTask::~RemovalTask() {}
1258 648
1259 bool BrowsingDataRemover::AllDone() { 649 bool BrowsingDataRemover::AllDone() {
1260 return !waiting_for_synchronous_clear_operations_ && 650 return !waiting_for_synchronous_clear_operations_ &&
1261 !waiting_for_clear_autofill_origin_urls_ && 651 !waiting_for_clear_embedder_data_ &&
1262 !waiting_for_clear_cache_ && 652 !waiting_for_clear_cache_ &&
1263 !waiting_for_clear_flash_content_licenses_ && 653 !waiting_for_clear_channel_ids_ &&
1264 !waiting_for_clear_channel_ids_ && !waiting_for_clear_cookies_count_ &&
1265 !waiting_for_clear_domain_reliability_monitor_ &&
1266 !waiting_for_clear_form_ && !waiting_for_clear_history_ &&
1267 !waiting_for_clear_hostname_resolution_cache_ &&
1268 !waiting_for_clear_http_auth_cache_ && 654 !waiting_for_clear_http_auth_cache_ &&
1269 !waiting_for_clear_keyword_data_ && !waiting_for_clear_nacl_cache_ &&
1270 !waiting_for_clear_network_predictor_ &&
1271 !waiting_for_clear_networking_history_ &&
1272 !waiting_for_clear_passwords_ && !waiting_for_clear_passwords_stats_ &&
1273 !waiting_for_clear_platform_keys_ &&
1274 !waiting_for_clear_plugin_data_count_ &&
1275 !waiting_for_clear_pnacl_cache_ &&
1276 #if BUILDFLAG(ANDROID_JAVA_UI)
1277 !waiting_for_clear_precache_history_ &&
1278 !waiting_for_clear_offline_page_data_ &&
1279 #endif
1280 #if BUILDFLAG(ENABLE_WEBRTC)
1281 !waiting_for_clear_webrtc_logs_ &&
1282 #endif
1283 !waiting_for_clear_storage_partition_data_ && 655 !waiting_for_clear_storage_partition_data_ &&
1284 !waiting_for_clear_auto_sign_in_; 656 !waiting_for_clear_plugin_data_count_;
1285 }
1286
1287 void BrowsingDataRemover::OnKeywordsLoaded(
1288 base::Callback<bool(const GURL&)> url_filter) {
1289 // Deletes the entries from the model, and if we're not waiting on anything
1290 // else notifies observers and deletes this BrowsingDataRemover.
1291 TemplateURLService* model =
1292 TemplateURLServiceFactory::GetForProfile(profile_);
1293 model->RemoveAutoGeneratedForUrlsBetween(url_filter, delete_begin_,
1294 delete_end_);
1295 waiting_for_clear_keyword_data_ = false;
1296 template_url_sub_.reset();
1297 NotifyIfDone();
1298 } 657 }
1299 658
1300 void BrowsingDataRemover::Notify() { 659 void BrowsingDataRemover::Notify() {
1301 // Some tests call |RemoveImpl| directly, without using the task scheduler. 660 // Some tests call |RemoveImpl| directly, without using the task scheduler.
1302 // TODO(msramek): Improve those tests so we don't have to do this. Tests 661 // TODO(msramek): Improve those tests so we don't have to do this. Tests
1303 // relying on |RemoveImpl| do so because they need to pass in 662 // relying on |RemoveImpl| do so because they need to pass in
1304 // BrowsingDataFilterBuilder while still keeping ownership of it. Making 663 // BrowsingDataFilterBuilder while still keeping ownership of it. Making
1305 // BrowsingDataFilterBuilder copyable would solve this. 664 // BrowsingDataFilterBuilder copyable would solve this.
1306 if (!is_removing_) { 665 if (!is_removing_) {
1307 DCHECK(task_queue_.empty()); 666 DCHECK(task_queue_.empty());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 if (completion_inhibitor_) { 704 if (completion_inhibitor_) {
1346 completion_inhibitor_->OnBrowsingDataRemoverWouldComplete( 705 completion_inhibitor_->OnBrowsingDataRemoverWouldComplete(
1347 this, base::Bind(&BrowsingDataRemover::Notify, 706 this, base::Bind(&BrowsingDataRemover::Notify,
1348 weak_ptr_factory_.GetWeakPtr())); 707 weak_ptr_factory_.GetWeakPtr()));
1349 return; 708 return;
1350 } 709 }
1351 710
1352 Notify(); 711 Notify();
1353 } 712 }
1354 713
1355 void BrowsingDataRemover::OnHistoryDeletionDone() {
1356 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1357 waiting_for_clear_history_ = false;
1358 NotifyIfDone();
1359 }
1360
1361 void BrowsingDataRemover::OnClearedHostnameResolutionCache() {
1362 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1363 waiting_for_clear_hostname_resolution_cache_ = false;
1364 NotifyIfDone();
1365 }
1366
1367 void BrowsingDataRemover::OnClearedHttpAuthCache() { 714 void BrowsingDataRemover::OnClearedHttpAuthCache() {
1368 DCHECK_CURRENTLY_ON(BrowserThread::UI); 715 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1369 waiting_for_clear_http_auth_cache_ = false; 716 waiting_for_clear_http_auth_cache_ = false;
1370 NotifyIfDone(); 717 NotifyIfDone();
1371 } 718 }
1372 719
1373 void BrowsingDataRemover::OnClearedNetworkPredictor() {
1374 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1375 waiting_for_clear_network_predictor_ = false;
1376 NotifyIfDone();
1377 }
1378
1379 void BrowsingDataRemover::OnClearedNetworkingHistory() {
1380 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1381 waiting_for_clear_networking_history_ = false;
1382 NotifyIfDone();
1383 }
1384
1385 void BrowsingDataRemover::ClearedCache() { 720 void BrowsingDataRemover::ClearedCache() {
1386 DCHECK_CURRENTLY_ON(BrowserThread::UI); 721 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1387 waiting_for_clear_cache_ = false; 722 waiting_for_clear_cache_ = false;
1388 NotifyIfDone(); 723 NotifyIfDone();
1389 } 724 }
1390 725
1391 #if !defined(DISABLE_NACL)
1392 void BrowsingDataRemover::ClearedNaClCache() {
1393 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1394 waiting_for_clear_nacl_cache_ = false;
1395 NotifyIfDone();
1396 }
1397
1398 void BrowsingDataRemover::ClearedPnaclCache() {
1399 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1400 waiting_for_clear_pnacl_cache_ = false;
1401 NotifyIfDone();
1402 }
1403 #endif
1404
1405 #if BUILDFLAG(ENABLE_PLUGINS) 726 #if BUILDFLAG(ENABLE_PLUGINS)
1406 void BrowsingDataRemover::OnWaitableEventSignaled( 727 void BrowsingDataRemover::OnWaitableEventSignaled(
1407 base::WaitableEvent* waitable_event) { 728 base::WaitableEvent* waitable_event) {
1408 DCHECK_CURRENTLY_ON(BrowserThread::UI); 729 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1409 730
1410 DCHECK_EQ(1, waiting_for_clear_plugin_data_count_); 731 DCHECK_EQ(1, waiting_for_clear_plugin_data_count_);
1411 waiting_for_clear_plugin_data_count_ = 0; 732 waiting_for_clear_plugin_data_count_ = 0;
1412 733
1413 plugin_data_remover_.reset(); 734 plugin_data_remover_.reset();
1414 watcher_.StopWatching(); 735 watcher_.StopWatching();
(...skipping 21 matching lines...) Expand all
1436 weak_ptr_factory_.GetWeakPtr())); 757 weak_ptr_factory_.GetWeakPtr()));
1437 } 758 }
1438 759
1439 NotifyIfDone(); 760 NotifyIfDone();
1440 } 761 }
1441 762
1442 void BrowsingDataRemover::OnFlashDataDeleted() { 763 void BrowsingDataRemover::OnFlashDataDeleted() {
1443 waiting_for_clear_plugin_data_count_--; 764 waiting_for_clear_plugin_data_count_--;
1444 NotifyIfDone(); 765 NotifyIfDone();
1445 } 766 }
1446
1447 void BrowsingDataRemover::OnDeauthorizeFlashContentLicensesCompleted(
1448 uint32_t request_id,
1449 bool /* success */) {
1450 DCHECK(waiting_for_clear_flash_content_licenses_);
1451 DCHECK_EQ(request_id, deauthorize_flash_content_licenses_request_id_);
1452
1453 waiting_for_clear_flash_content_licenses_ = false;
1454 NotifyIfDone();
1455 }
1456 #endif 767 #endif
1457 768
1458 #if defined(OS_CHROMEOS)
1459 void BrowsingDataRemover::OnClearPlatformKeys(
1460 chromeos::DBusMethodCallStatus call_status,
1461 bool result) {
1462 DCHECK(waiting_for_clear_platform_keys_);
1463 LOG_IF(ERROR, call_status != chromeos::DBUS_METHOD_CALL_SUCCESS || !result)
1464 << "Failed to clear platform keys.";
1465 waiting_for_clear_platform_keys_ = false;
1466 NotifyIfDone();
1467 }
1468 #endif
1469
1470
1471 void BrowsingDataRemover::OnClearedPasswords() {
1472 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1473 waiting_for_clear_passwords_ = false;
1474 NotifyIfDone();
1475 }
1476
1477 void BrowsingDataRemover::OnClearedPasswordsStats() {
1478 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1479 waiting_for_clear_passwords_stats_ = false;
1480 NotifyIfDone();
1481 }
1482
1483 void BrowsingDataRemover::OnClearedAutoSignIn() {
1484 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1485 waiting_for_clear_auto_sign_in_ = false;
1486 NotifyIfDone();
1487 }
1488
1489 void BrowsingDataRemover::OnClearedCookies() {
1490 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1491
1492 DCHECK_GT(waiting_for_clear_cookies_count_, 0);
1493 --waiting_for_clear_cookies_count_;
1494 NotifyIfDone();
1495 }
1496
1497 void BrowsingDataRemover::OnClearedChannelIDs() { 769 void BrowsingDataRemover::OnClearedChannelIDs() {
1498 DCHECK_CURRENTLY_ON(BrowserThread::UI); 770 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1499 waiting_for_clear_channel_ids_ = false; 771 waiting_for_clear_channel_ids_ = false;
1500 NotifyIfDone(); 772 NotifyIfDone();
1501 } 773 }
1502 774
1503 void BrowsingDataRemover::OnClearedFormData() {
1504 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1505 waiting_for_clear_form_ = false;
1506 NotifyIfDone();
1507 }
1508
1509 void BrowsingDataRemover::OnClearedAutofillOriginURLs() {
1510 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1511 waiting_for_clear_autofill_origin_urls_ = false;
1512 NotifyIfDone();
1513 }
1514
1515 void BrowsingDataRemover::OnClearedStoragePartitionData() { 775 void BrowsingDataRemover::OnClearedStoragePartitionData() {
1516 DCHECK_CURRENTLY_ON(BrowserThread::UI); 776 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1517 waiting_for_clear_storage_partition_data_ = false; 777 waiting_for_clear_storage_partition_data_ = false;
1518 NotifyIfDone(); 778 NotifyIfDone();
1519 } 779 }
1520 780
1521 #if BUILDFLAG(ENABLE_WEBRTC) 781 void BrowsingDataRemover::OnClearedEmbedderData() {
1522 void BrowsingDataRemover::OnClearedWebRtcLogs() {
1523 DCHECK_CURRENTLY_ON(BrowserThread::UI); 782 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1524 waiting_for_clear_webrtc_logs_ = false; 783 waiting_for_clear_embedder_data_ = false;
1525 NotifyIfDone(); 784 NotifyIfDone();
1526 } 785 }
1527 #endif
1528
1529 #if BUILDFLAG(ANDROID_JAVA_UI)
1530 void BrowsingDataRemover::OnClearedPrecacheHistory() {
1531 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1532 waiting_for_clear_precache_history_ = false;
1533 NotifyIfDone();
1534 }
1535
1536 void BrowsingDataRemover::OnClearedOfflinePageData(
1537 offline_pages::OfflinePageModel::DeletePageResult result) {
1538 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1539 waiting_for_clear_offline_page_data_ = false;
1540 NotifyIfDone();
1541 }
1542 #endif
1543
1544 void BrowsingDataRemover::OnClearedDomainReliabilityMonitor() {
1545 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1546 waiting_for_clear_domain_reliability_monitor_ = false;
1547 NotifyIfDone();
1548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698