forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowsing_data_remover.cc
1345 lines (1181 loc) · 51.3 KB
/
browsing_data_remover.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include <map>
#include <set>
#include <string>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
#include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/domain_reliability/service_factory.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/media/media_device_id_salt.h"
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/web_data_service_factory.h"
#include "chrome/common/features.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/browsing_data/storage_partition_http_cache_data_remover.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/domain_reliability/service.h"
#include "components/history/core/browser/history_service.h"
#include "components/nacl/browser/nacl_browser.h"
#include "components/nacl/browser/pnacl_host.h"
#include "components/omnibox/browser/omnibox_pref_names.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/power/origin_power_map.h"
#include "components/power/origin_power_map_factory.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/template_url_service.h"
#include "components/sessions/core/tab_restore_service.h"
#include "components/web_cache/browser/web_cache_manager.h"
#include "content/public/browser/browser_thread.h"
#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 "net/base/net_errors.h"
#include "net/cookies/cookie_store.h"
#include "net/http/transport_security_state.h"
#include "net/ssl/channel_id_service.h"
#include "net/ssl/channel_id_store.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "storage/browser/quota/special_storage_policy.h"
#include "url/origin.h"
#if BUILDFLAG(ANDROID_JAVA_UI)
#include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
#include "chrome/browser/android/webapps/webapp_registry.h"
#include "chrome/browser/precache/precache_manager_factory.h"
#include "components/offline_pages/offline_page_feature.h"
#include "components/offline_pages/offline_page_model.h"
#include "components/precache/content/precache_manager.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chromeos/attestation/attestation_constants.h"
#include "chromeos/cryptohome/cryptohome_parameters.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "components/user_manager/user.h"
#endif
#if defined(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/activity_log/activity_log.h"
#include "extensions/browser/extension_prefs.h"
#endif
#if defined(ENABLE_SESSION_SERVICE)
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
#endif
#if defined(ENABLE_WEBRTC)
#include "chrome/browser/media/webrtc_log_list.h"
#include "chrome/browser/media/webrtc_log_util.h"
#endif
using base::UserMetricsAction;
using content::BrowserContext;
using content::BrowserThread;
using content::DOMStorageContext;
namespace {
using CallbackList =
base::CallbackList<void(const BrowsingDataRemover::NotificationDetails&)>;
// Contains all registered callbacks for browsing data removed notifications.
CallbackList* g_on_browsing_data_removed_callbacks = nullptr;
// Accessor for |*g_on_browsing_data_removed_callbacks|. Creates a new object
// the first time so that it always returns a valid object.
CallbackList* GetOnBrowsingDataRemovedCallbacks() {
if (!g_on_browsing_data_removed_callbacks)
g_on_browsing_data_removed_callbacks = new CallbackList();
return g_on_browsing_data_removed_callbacks;
}
void UIThreadTrampolineHelper(const base::Closure& callback) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
}
// Convenience method to create a callback that can be run on any thread and
// will post the given |callback| back to the UI thread.
base::Closure UIThreadTrampoline(const base::Closure& callback) {
// We could directly bind &BrowserThread::PostTask, but that would require
// evaluating FROM_HERE when this method is called, as opposed to when the
// task is actually posted.
return base::Bind(&UIThreadTrampolineHelper, callback);
}
template <typename T>
void IgnoreArgumentHelper(const base::Closure& callback, T unused_argument) {
callback.Run();
}
// Another convenience method to turn a callback without arguments into one that
// accepts (and ignores) a single argument.
template <typename T>
base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) {
return base::Bind(&IgnoreArgumentHelper<T>, callback);
}
// Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask.
bool DoesOriginMatchMaskAndUrls(
int origin_type_mask,
const base::Callback<bool(const GURL&)>& predicate,
const GURL& origin,
storage::SpecialStoragePolicy* special_storage_policy) {
return predicate.Run(origin) &&
BrowsingDataHelper::DoesOriginMatchMask(origin, origin_type_mask,
special_storage_policy);
}
bool ForwardPrimaryPatternCallback(
const base::Callback<bool(const ContentSettingsPattern&)> predicate,
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern) {
return predicate.Run(primary_pattern);
}
void ClearHostnameResolutionCacheOnIOThread(IOThread* io_thread) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
io_thread->ClearHostCache();
}
void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(predictor);
predictor->DiscardInitialNavigationHistory();
predictor->DiscardAllResults();
}
#if !defined(DISABLE_NACL)
void ClearNaClCacheOnIOThread(const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
nacl::NaClBrowser::GetInstance()->ClearValidationCache(callback);
}
void ClearPnaclCacheOnIOThread(base::Time begin,
base::Time end,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
pnacl::PnaclHost::GetInstance()->ClearTranslationCacheEntriesBetween(
begin, end, callback);
}
#endif
void ClearCookiesOnIOThread(base::Time delete_begin,
base::Time delete_end,
net::URLRequestContextGetter* rq_context,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
net::CookieStore* cookie_store =
rq_context->GetURLRequestContext()->cookie_store();
cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
IgnoreArgument<int>(callback));
}
void ClearCookiesWithPredicateOnIOThread(
base::Time delete_begin,
base::Time delete_end,
net::CookieStore::CookiePredicate predicate,
net::URLRequestContextGetter* rq_context,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
net::CookieStore* cookie_store =
rq_context->GetURLRequestContext()->cookie_store();
cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
delete_begin, delete_end, predicate, IgnoreArgument<int>(callback));
}
void OnClearedChannelIDsOnIOThread(net::URLRequestContextGetter* rq_context,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// Need to close open SSL connections which may be using the channel ids we
// are deleting.
// TODO(mattm): http://crbug.com/166069 Make the server bound cert
// service/store have observers that can notify relevant things directly.
rq_context->GetURLRequestContext()
->ssl_config_service()
->NotifySSLConfigChange();
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
}
void ClearChannelIDsOnIOThread(
const base::Callback<bool(const std::string&)>& domain_predicate,
base::Time delete_begin,
base::Time delete_end,
scoped_refptr<net::URLRequestContextGetter> rq_context,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
net::ChannelIDService* channel_id_service =
rq_context->GetURLRequestContext()->channel_id_service();
channel_id_service->GetChannelIDStore()->DeleteForDomainsCreatedBetween(
domain_predicate, delete_begin, delete_end,
base::Bind(&OnClearedChannelIDsOnIOThread,
base::RetainedRef(std::move(rq_context)), callback));
}
} // namespace
BrowsingDataRemover::CompletionInhibitor*
BrowsingDataRemover::completion_inhibitor_ = nullptr;
BrowsingDataRemover::NotificationDetails::NotificationDetails()
: removal_begin(base::Time()),
removal_mask(-1),
origin_type_mask(-1) {
}
BrowsingDataRemover::NotificationDetails::NotificationDetails(
const BrowsingDataRemover::NotificationDetails& details)
: removal_begin(details.removal_begin),
removal_mask(details.removal_mask),
origin_type_mask(details.origin_type_mask) {
}
BrowsingDataRemover::NotificationDetails::NotificationDetails(
base::Time removal_begin,
int removal_mask,
int origin_type_mask)
: removal_begin(removal_begin),
removal_mask(removal_mask),
origin_type_mask(origin_type_mask) {
}
BrowsingDataRemover::NotificationDetails::~NotificationDetails() {}
// static
BrowsingDataRemover::TimeRange BrowsingDataRemover::Unbounded() {
return TimeRange(base::Time(), base::Time::Max());
}
// static
BrowsingDataRemover::TimeRange BrowsingDataRemover::Period(TimePeriod period) {
switch (period) {
case LAST_HOUR:
content::RecordAction(
UserMetricsAction("ClearBrowsingData_LastHour"));
break;
case LAST_DAY:
content::RecordAction(
UserMetricsAction("ClearBrowsingData_LastDay"));
break;
case LAST_WEEK:
content::RecordAction(
UserMetricsAction("ClearBrowsingData_LastWeek"));
break;
case FOUR_WEEKS:
content::RecordAction(
UserMetricsAction("ClearBrowsingData_LastMonth"));
break;
case EVERYTHING:
content::RecordAction(
UserMetricsAction("ClearBrowsingData_Everything"));
break;
}
return TimeRange(CalculateBeginDeleteTime(period), base::Time::Max());
}
BrowsingDataRemover::BrowsingDataRemover(
content::BrowserContext* browser_context)
: profile_(Profile::FromBrowserContext(browser_context)),
is_removing_(false),
#if BUILDFLAG(ANDROID_JAVA_UI)
webapp_registry_(new WebappRegistry()),
#endif
weak_ptr_factory_(this) {
DCHECK(browser_context);
}
BrowsingDataRemover::~BrowsingDataRemover() {
// If we are still removing data, notify observers so they can remove
// themselves from the observer list.
// TODO(bauerb): If it becomes a problem that browsing data might not actually
// be fully cleared when an observer is notified, add a success flag.
if (is_removing_)
Notify();
}
void BrowsingDataRemover::Shutdown() {
history_task_tracker_.TryCancelAll();
template_url_sub_.reset();
}
void BrowsingDataRemover::SetRemoving(bool is_removing) {
DCHECK_NE(is_removing_, is_removing);
is_removing_ = is_removing;
}
void BrowsingDataRemover::Remove(const TimeRange& time_range,
int remove_mask,
int origin_type_mask) {
// Any instance of BrowsingDataFilterBuilder that |IsEmptyBlacklist()|
// is OK to pass here.
RegistrableDomainFilterBuilder builder(
RegistrableDomainFilterBuilder::BLACKLIST);
DCHECK(builder.IsEmptyBlacklist());
RemoveImpl(time_range, remove_mask, builder, origin_type_mask);
}
void BrowsingDataRemover::RemoveWithFilter(
const TimeRange& time_range,
int remove_mask,
int origin_type_mask,
const BrowsingDataFilterBuilder& filter_builder) {
RemoveImpl(time_range, remove_mask, filter_builder, origin_type_mask);
}
void BrowsingDataRemover::RemoveImpl(
const TimeRange& time_range,
int remove_mask,
const BrowsingDataFilterBuilder& filter_builder,
int origin_type_mask) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// crbug.com/140910: Many places were calling this with base::Time() as
// delete_end, even though they should've used base::Time::Max().
DCHECK_NE(base::Time(), time_range.end);
SetRemoving(true);
delete_begin_ = time_range.begin;
delete_end_ = time_range.end;
remove_mask_ = remove_mask;
origin_type_mask_ = origin_type_mask;
base::Callback<bool(const GURL& url)> filter =
filter_builder.BuildGeneralFilter();
base::Callback<bool(const ContentSettingsPattern& url)> same_pattern_filter =
filter_builder.BuildWebsiteSettingsPatternMatchesFilter();
PrefService* prefs = profile_->GetPrefs();
bool may_delete_history = prefs->GetBoolean(
prefs::kAllowDeletingBrowserHistory);
// All the UI entry points into the BrowsingDataRemover 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)));
if (origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
content::RecordAction(
UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb"));
}
if (origin_type_mask_ & BrowsingDataHelper::PROTECTED_WEB) {
content::RecordAction(
UserMetricsAction("ClearBrowsingData_MaskContainsProtectedWeb"));
}
if (origin_type_mask_ & BrowsingDataHelper::EXTENSION) {
content::RecordAction(
UserMetricsAction("ClearBrowsingData_MaskContainsExtension"));
}
// If this fires, we added a new BrowsingDataHelper::OriginTypeMask without
// updating the user metrics above.
static_assert(
BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB |
BrowsingDataHelper::PROTECTED_WEB |
BrowsingDataHelper::EXTENSION),
"OriginTypeMask has been updated without updating user metrics");
if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
history::HistoryService* history_service =
HistoryServiceFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
if (history_service) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
waiting_for_clear_history_ = true;
history_service->ExpireLocalAndRemoteHistoryBetween(
WebHistoryServiceFactory::GetForProfile(profile_), std::set<GURL>(),
delete_begin_, delete_end_,
base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
weak_ptr_factory_.GetWeakPtr()),
&history_task_tracker_);
#if defined(ENABLE_EXTENSIONS)
// The extension activity contains details of which websites extensions
// were active on. It therefore indirectly stores details of websites a
// user has visited so best clean from here as well.
extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(
std::set<GURL>());
#endif
}
#if defined(ENABLE_EXTENSIONS)
// Clear launch times as they are a form of history.
extensions::ExtensionPrefs* extension_prefs =
extensions::ExtensionPrefs::Get(profile_);
extension_prefs->ClearLastLaunchTimes();
#endif
// The power consumption history by origin contains details of websites
// that were visited.
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
power::OriginPowerMap* origin_power_map =
power::OriginPowerMapFactory::GetForBrowserContext(profile_);
if (origin_power_map)
origin_power_map->ClearOriginMap();
// Need to clear the host cache and accumulated speculative data, as it also
// reveals some history: we have no mechanism to track when these items were
// created, so we'll clear them all. Better safe than sorry.
if (g_browser_process->io_thread()) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
waiting_for_clear_hostname_resolution_cache_ = true;
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearHostnameResolutionCacheOnIOThread,
g_browser_process->io_thread()),
base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache,
weak_ptr_factory_.GetWeakPtr()));
}
if (profile_->GetNetworkPredictor()) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
waiting_for_clear_network_predictor_ = true;
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearNetworkPredictorOnIOThread,
profile_->GetNetworkPredictor()),
base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor,
weak_ptr_factory_.GetWeakPtr()));
}
// As part of history deletion we also delete the auto-generated keywords.
TemplateURLService* keywords_model =
TemplateURLServiceFactory::GetForProfile(profile_);
if (keywords_model && !keywords_model->loaded()) {
template_url_sub_ = keywords_model->RegisterOnLoadedCallback(
base::Bind(&BrowsingDataRemover::OnKeywordsLoaded,
weak_ptr_factory_.GetWeakPtr()));
keywords_model->Load();
waiting_for_clear_keyword_data_ = true;
} else if (keywords_model) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
keywords_model->RemoveAutoGeneratedForOriginBetween(GURL(), delete_begin_,
delete_end_);
}
// The PrerenderManager keeps history of prerendered pages, so clear that.
// It also may have a prerendered page. If so, the page could be
// considered to have a small amount of historical information, so delete
// it, too.
prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForProfile(profile_);
if (prerender_manager) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
prerender_manager->ClearData(
prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
}
// If the caller is removing history for all hosts, then clear ancillary
// historical information.
if (filter_builder.IsEmptyBlacklist()) {
// We also delete the list of recently closed tabs. Since these expire,
// they can't be more than a day old, so we can simply clear them all.
sessions::TabRestoreService* tab_service =
TabRestoreServiceFactory::GetForProfile(profile_);
if (tab_service) {
tab_service->ClearEntries();
tab_service->DeleteLastSession();
}
#if defined(ENABLE_SESSION_SERVICE)
// We also delete the last session when we delete the history.
SessionService* session_service =
SessionServiceFactory::GetForProfile(profile_);
if (session_service)
session_service->DeleteLastSession();
#endif
}
// The saved Autofill profiles and credit cards can include the origin from
// which these profiles and credit cards were learned. These are a form of
// history, so clear them as well.
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
WebDataServiceFactory::GetAutofillWebDataForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
if (web_data_service.get()) {
waiting_for_clear_autofill_origin_urls_ = true;
web_data_service->RemoveOriginURLsModifiedBetween(
delete_begin_, delete_end_);
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
BrowserThread::PostTaskAndReply(
BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
base::Bind(&BrowsingDataRemover::OnClearedAutofillOriginURLs,
weak_ptr_factory_.GetWeakPtr()));
autofill::PersonalDataManager* data_manager =
autofill::PersonalDataManagerFactory::GetForProfile(profile_);
if (data_manager)
data_manager->Refresh();
}
#if defined(ENABLE_WEBRTC)
waiting_for_clear_webrtc_logs_ = true;
BrowserThread::PostTaskAndReply(
BrowserThread::FILE, FROM_HERE,
base::Bind(
&WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles,
WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()),
delete_begin_),
base::Bind(&BrowsingDataRemover::OnClearedWebRtcLogs,
weak_ptr_factory_.GetWeakPtr()));
#endif
// The SSL Host State that tracks SSL interstitial "proceed" decisions may
// include origins that the user has visited, so it must be cleared.
if (profile_->GetSSLHostStateDelegate())
profile_->GetSSLHostStateDelegate()->Clear();
#if BUILDFLAG(ANDROID_JAVA_UI)
precache::PrecacheManager* precache_manager =
precache::PrecacheManagerFactory::GetForBrowserContext(profile_);
// |precache_manager| could be nullptr if the profile is off the record.
if (!precache_manager) {
waiting_for_clear_precache_history_ = true;
precache_manager->ClearHistory();
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
BrowserThread::PostTaskAndReply(
BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
base::Bind(&BrowsingDataRemover::OnClearedPrecacheHistory,
weak_ptr_factory_.GetWeakPtr()));
}
// Clear the history information (last launch time and origin URL) of any
// registered webapps. The webapp_registry makes a JNI call into a Java-side
// AsyncTask, so don't wait for the reply.
waiting_for_clear_webapp_history_ = true;
webapp_registry_->ClearWebappHistory(
base::Bind(&BrowsingDataRemover::OnClearedWebappHistory,
weak_ptr_factory_.GetWeakPtr()));
#endif
data_reduction_proxy::DataReductionProxySettings*
data_reduction_proxy_settings =
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
profile_);
// |data_reduction_proxy_settings| is null if |profile_| is off the record.
if (data_reduction_proxy_settings) {
data_reduction_proxy::DataReductionProxyService*
data_reduction_proxy_service =
data_reduction_proxy_settings->data_reduction_proxy_service();
if (data_reduction_proxy_service) {
data_reduction_proxy_service->compression_stats()
->DeleteBrowsingHistory(delete_begin_, delete_end_);
}
}
}
if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
content::DownloadManager* download_manager =
BrowserContext::GetDownloadManager(profile_);
download_manager->RemoveDownloadsByURLAndTime(filter,
delete_begin_, delete_end_);
DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager(
download_manager);
download_prefs->SetSaveFilePath(download_prefs->DownloadPath());
}
uint32_t storage_partition_remove_mask = 0;
// We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set,
// so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB
// don't accidentally remove the cookies that are associated with the
// UNPROTECTED_WEB origin. This is necessary because cookies are not separated
// between UNPROTECTED_WEB and PROTECTED_WEB.
if (remove_mask & REMOVE_COOKIES &&
origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_COOKIES;
// Clear the safebrowsing cookies only if time period is for "all time". It
// doesn't make sense to apply the time period of deleting in the last X
// hours/days to the safebrowsing cookies since they aren't the result of
// any user action.
if (delete_begin_ == base::Time()) {
safe_browsing::SafeBrowsingService* sb_service =
g_browser_process->safe_browsing_service();
if (sb_service) {
scoped_refptr<net::URLRequestContextGetter> sb_context =
sb_service->url_request_context();
++waiting_for_clear_cookies_count_;
if (filter_builder.IsEmptyBlacklist()) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_,
base::RetainedRef(std::move(sb_context)),
UIThreadTrampoline(
base::Bind(&BrowsingDataRemover::OnClearedCookies,
weak_ptr_factory_.GetWeakPtr()))));
} else {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearCookiesWithPredicateOnIOThread, delete_begin_,
delete_end_, filter_builder.BuildCookieFilter(),
base::RetainedRef(std::move(sb_context)),
UIThreadTrampoline(
base::Bind(&BrowsingDataRemover::OnClearedCookies,
weak_ptr_factory_.GetWeakPtr()))));
}
}
}
MediaDeviceIDSalt::Reset(profile_->GetPrefs());
}
// Channel IDs are not separated for protected and unprotected web
// origins. We check the origin_type_mask_ to prevent unintended deletion.
if (remove_mask & REMOVE_CHANNEL_IDS &&
origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
content::RecordAction(
UserMetricsAction("ClearBrowsingData_ChannelIDs"));
// Since we are running on the UI thread don't call GetURLRequestContext().
scoped_refptr<net::URLRequestContextGetter> rq_context =
content::BrowserContext::GetDefaultStoragePartition(profile_)->
GetURLRequestContext();
waiting_for_clear_channel_ids_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearChannelIDsOnIOThread,
filter_builder.BuildChannelIDFilter(),
delete_begin_, delete_end_, std::move(rq_context),
base::Bind(&BrowsingDataRemover::OnClearedChannelIDs,
weak_ptr_factory_.GetWeakPtr())));
}
if (remove_mask & REMOVE_LOCAL_STORAGE) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE;
}
if (remove_mask & REMOVE_INDEXEDDB) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB;
}
if (remove_mask & REMOVE_WEBSQL) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_WEBSQL;
}
if (remove_mask & REMOVE_APPCACHE) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_APPCACHE;
}
if (remove_mask & REMOVE_SERVICE_WORKERS) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS;
}
if (remove_mask & REMOVE_CACHE_STORAGE) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE;
}
if (remove_mask & REMOVE_FILE_SYSTEMS) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS;
}
#if defined(ENABLE_PLUGINS)
// Plugin is data not separated for protected and unprotected web origins. We
// check the origin_type_mask_ to prevent unintended deletion.
if (remove_mask & REMOVE_PLUGIN_DATA &&
origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
waiting_for_clear_plugin_data_ = true;
DCHECK(!plugin_data_remover_);
plugin_data_remover_.reset(content::PluginDataRemover::Create(profile_));
base::WaitableEvent* event =
plugin_data_remover_->StartRemoving(delete_begin_);
base::WaitableEventWatcher::EventCallback watcher_callback =
base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled,
weak_ptr_factory_.GetWeakPtr());
watcher_.StartWatching(event, watcher_callback);
}
#endif
if (remove_mask & REMOVE_SITE_USAGE_DATA) {
ClearSettingsForOneTypeWithPredicate(
HostContentSettingsMapFactory::GetForProfile(profile_),
CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
}
if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) {
ClearSettingsForOneTypeWithPredicate(
HostContentSettingsMapFactory::GetForProfile(profile_),
CONTENT_SETTINGS_TYPE_APP_BANNER,
base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
}
if (remove_mask & REMOVE_PASSWORDS) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
if (password_store) {
waiting_for_clear_passwords_ = true;
auto on_cleared_passwords =
base::Bind(&BrowsingDataRemover::OnClearedPasswords,
weak_ptr_factory_.GetWeakPtr());
password_store->RemoveLoginsByURLAndTime(
filter, delete_begin_, delete_end_, on_cleared_passwords);
}
}
if (remove_mask & REMOVE_COOKIES) {
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(profile_,
ServiceAccessType::EXPLICIT_ACCESS)
.get();
if (password_store) {
waiting_for_clear_auto_sign_in_ = true;
base::Closure on_cleared_auto_sign_in =
base::Bind(&BrowsingDataRemover::OnClearedAutoSignIn,
weak_ptr_factory_.GetWeakPtr());
password_store->DisableAutoSignInForAllLogins(on_cleared_auto_sign_in);
}
}
if (remove_mask & REMOVE_HISTORY) {
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
if (password_store) {
waiting_for_clear_passwords_stats_ = true;
password_store->RemoveStatisticsCreatedBetween(
delete_begin_, delete_end_,
base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats,
weak_ptr_factory_.GetWeakPtr()));
}
}
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
if (remove_mask & REMOVE_FORM_DATA) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
WebDataServiceFactory::GetAutofillWebDataForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
if (web_data_service.get()) {
waiting_for_clear_form_ = true;
web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
delete_end_);
web_data_service->RemoveAutofillDataModifiedBetween(
delete_begin_, delete_end_);
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
BrowserThread::PostTaskAndReply(
BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
base::Bind(&BrowsingDataRemover::OnClearedFormData,
weak_ptr_factory_.GetWeakPtr()));
autofill::PersonalDataManager* data_manager =
autofill::PersonalDataManagerFactory::GetForProfile(profile_);
if (data_manager)
data_manager->Refresh();
}
}
if (remove_mask & REMOVE_CACHE) {
// Tell the renderers to clear their cache.
web_cache::WebCacheManager::GetInstance()->ClearCache();
content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache"));
waiting_for_clear_cache_ = true;
// StoragePartitionHttpCacheDataRemover deletes itself when it is done.
if (filter_builder.IsEmptyBlacklist()) {
browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
BrowserContext::GetDefaultStoragePartition(profile_),
delete_begin_, delete_end_)
->Remove(base::Bind(&BrowsingDataRemover::ClearedCache,
weak_ptr_factory_.GetWeakPtr()));
} else {
browsing_data::StoragePartitionHttpCacheDataRemover::
CreateForURLsAndRange(
BrowserContext::GetDefaultStoragePartition(profile_),
filter, delete_begin_, delete_end_)
->Remove(base::Bind(&BrowsingDataRemover::ClearedCache,
weak_ptr_factory_.GetWeakPtr()));
}
#if !defined(DISABLE_NACL)
waiting_for_clear_nacl_cache_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearNaClCacheOnIOThread,
UIThreadTrampoline(
base::Bind(&BrowsingDataRemover::ClearedNaClCache,
weak_ptr_factory_.GetWeakPtr()))));
waiting_for_clear_pnacl_cache_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearPnaclCacheOnIOThread, delete_begin_, delete_end_,
UIThreadTrampoline(
base::Bind(&BrowsingDataRemover::ClearedPnaclCache,
weak_ptr_factory_.GetWeakPtr()))));
#endif
// The PrerenderManager may have a page actively being prerendered, which
// is essentially a preemptively cached page.
prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForProfile(profile_);
if (prerender_manager) {
prerender_manager->ClearData(
prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS);
}
// Tell the shader disk cache to clear.
content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache"));
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE;
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY;
// When clearing cache, wipe accumulated network related data
// (TransportSecurityState and HttpServerPropertiesManager data).
waiting_for_clear_networking_history_ = true;
profile_->ClearNetworkingHistorySince(
delete_begin_,
base::Bind(&BrowsingDataRemover::OnClearedNetworkingHistory,
weak_ptr_factory_.GetWeakPtr()));
}
if (remove_mask & REMOVE_WEBRTC_IDENTITY) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY;
}
if (storage_partition_remove_mask) {
waiting_for_clear_storage_partition_data_ = true;
content::StoragePartition* storage_partition;
if (storage_partition_for_testing_)
storage_partition = storage_partition_for_testing_;
else
storage_partition = BrowserContext::GetDefaultStoragePartition(profile_);
uint32_t quota_storage_remove_mask =
~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
if (delete_begin_ == base::Time() ||
origin_type_mask_ &
(BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
// If we're deleting since the beginning of time, or we're removing
// protected origins, then remove persistent quota data.
quota_storage_remove_mask |=
content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
}
// If cookies are supposed to be conditionally deleted from the storage
// partition, create a cookie matcher function.
content::StoragePartition::CookieMatcherFunction cookie_matcher;
if (!filter_builder.IsEmptyBlacklist() &&
(storage_partition_remove_mask &
content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) {
cookie_matcher = filter_builder.BuildCookieFilter();
}
storage_partition->ClearData(
storage_partition_remove_mask, quota_storage_remove_mask,
base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_, filter),
cookie_matcher, delete_begin_, delete_end_,
base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData,
weak_ptr_factory_.GetWeakPtr()));
}
#if defined(ENABLE_PLUGINS)
if (remove_mask & REMOVE_CONTENT_LICENSES) {
content::RecordAction(
UserMetricsAction("ClearBrowsingData_ContentLicenses"));
waiting_for_clear_content_licenses_ = true;
if (!pepper_flash_settings_manager_.get()) {
pepper_flash_settings_manager_.reset(
new PepperFlashSettingsManager(this, profile_));
}
deauthorize_content_licenses_request_id_ =
pepper_flash_settings_manager_->DeauthorizeContentLicenses(prefs);
#if defined(OS_CHROMEOS)
// On Chrome OS, also delete any content protection platform keys.
const user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
if (!user) {
LOG(WARNING) << "Failed to find user for current profile.";
} else {
chromeos::DBusThreadManager::Get()
->GetCryptohomeClient()
->TpmAttestationDeleteKeys(
chromeos::attestation::KEY_USER,
cryptohome::Identification(user->GetAccountId()),
chromeos::attestation::kContentProtectionKeyPrefix,
base::Bind(&BrowsingDataRemover::OnClearPlatformKeys,
weak_ptr_factory_.GetWeakPtr()));
waiting_for_clear_platform_keys_ = true;
}
#endif
}
#endif
// Remove omnibox zero-suggest cache results.
if ((remove_mask & (REMOVE_CACHE | REMOVE_COOKIES)))
prefs->SetString(omnibox::kZeroSuggestCachedResults, std::string());
if (remove_mask & (REMOVE_COOKIES | REMOVE_HISTORY)) {
domain_reliability::DomainReliabilityService* service =
domain_reliability::DomainReliabilityServiceFactory::
GetForBrowserContext(profile_);
if (service) {
domain_reliability::DomainReliabilityClearMode mode;
if (remove_mask & REMOVE_COOKIES)
mode = domain_reliability::CLEAR_CONTEXTS;
else
mode = domain_reliability::CLEAR_BEACONS;
waiting_for_clear_domain_reliability_monitor_ = true;
service->ClearBrowsingData(
mode,
base::Bind(&BrowsingDataRemover::OnClearedDomainReliabilityMonitor,
weak_ptr_factory_.GetWeakPtr()));
}
}