OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 #include "chrome/browser/media/webrtc_log_util.h" | 113 #include "chrome/browser/media/webrtc_log_util.h" |
114 #endif | 114 #endif |
115 | 115 |
116 using base::UserMetricsAction; | 116 using base::UserMetricsAction; |
117 using content::BrowserContext; | 117 using content::BrowserContext; |
118 using content::BrowserThread; | 118 using content::BrowserThread; |
119 using content::DOMStorageContext; | 119 using content::DOMStorageContext; |
120 | 120 |
121 namespace { | 121 namespace { |
122 | 122 |
123 using CallbackList = | |
124 base::CallbackList<void(const BrowsingDataRemover::NotificationDetails&)>; | |
125 | |
126 // Contains all registered callbacks for browsing data removed notifications. | |
127 CallbackList* g_on_browsing_data_removed_callbacks = nullptr; | |
128 | |
129 // Accessor for |*g_on_browsing_data_removed_callbacks|. Creates a new object | |
130 // the first time so that it always returns a valid object. | |
131 CallbackList* GetOnBrowsingDataRemovedCallbacks() { | |
132 if (!g_on_browsing_data_removed_callbacks) | |
133 g_on_browsing_data_removed_callbacks = new CallbackList(); | |
134 return g_on_browsing_data_removed_callbacks; | |
135 } | |
136 | |
137 void UIThreadTrampolineHelper(const base::Closure& callback) { | 123 void UIThreadTrampolineHelper(const base::Closure& callback) { |
138 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 124 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
139 } | 125 } |
140 | 126 |
141 // Convenience method to create a callback that can be run on any thread and | 127 // Convenience method to create a callback that can be run on any thread and |
142 // will post the given |callback| back to the UI thread. | 128 // will post the given |callback| back to the UI thread. |
143 base::Closure UIThreadTrampoline(const base::Closure& callback) { | 129 base::Closure UIThreadTrampoline(const base::Closure& callback) { |
144 // We could directly bind &BrowserThread::PostTask, but that would require | 130 // We could directly bind &BrowserThread::PostTask, but that would require |
145 // evaluating FROM_HERE when this method is called, as opposed to when the | 131 // evaluating FROM_HERE when this method is called, as opposed to when the |
146 // task is actually posted. | 132 // task is actually posted. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 domain_predicate, delete_begin, delete_end, | 245 domain_predicate, delete_begin, delete_end, |
260 base::Bind(&OnClearedChannelIDsOnIOThread, | 246 base::Bind(&OnClearedChannelIDsOnIOThread, |
261 base::RetainedRef(std::move(rq_context)), callback)); | 247 base::RetainedRef(std::move(rq_context)), callback)); |
262 } | 248 } |
263 | 249 |
264 } // namespace | 250 } // namespace |
265 | 251 |
266 BrowsingDataRemover::CompletionInhibitor* | 252 BrowsingDataRemover::CompletionInhibitor* |
267 BrowsingDataRemover::completion_inhibitor_ = nullptr; | 253 BrowsingDataRemover::completion_inhibitor_ = nullptr; |
268 | 254 |
269 BrowsingDataRemover::NotificationDetails::NotificationDetails() | |
270 : removal_begin(base::Time()), | |
271 removal_mask(-1), | |
272 origin_type_mask(-1) { | |
273 } | |
274 | |
275 BrowsingDataRemover::NotificationDetails::NotificationDetails( | |
276 const BrowsingDataRemover::NotificationDetails& details) | |
277 : removal_begin(details.removal_begin), | |
278 removal_mask(details.removal_mask), | |
279 origin_type_mask(details.origin_type_mask) { | |
280 } | |
281 | |
282 BrowsingDataRemover::NotificationDetails::NotificationDetails( | |
283 base::Time removal_begin, | |
284 int removal_mask, | |
285 int origin_type_mask) | |
286 : removal_begin(removal_begin), | |
287 removal_mask(removal_mask), | |
288 origin_type_mask(origin_type_mask) { | |
289 } | |
290 | |
291 BrowsingDataRemover::NotificationDetails::~NotificationDetails() {} | |
292 | |
293 bool BrowsingDataRemover::TimeRange::operator==( | 255 bool BrowsingDataRemover::TimeRange::operator==( |
294 const BrowsingDataRemover::TimeRange& other) const { | 256 const BrowsingDataRemover::TimeRange& other) const { |
295 return begin == other.begin && end == other.end; | 257 return begin == other.begin && end == other.end; |
296 } | 258 } |
297 | 259 |
298 // static | 260 // static |
299 BrowsingDataRemover::TimeRange BrowsingDataRemover::Unbounded() { | 261 BrowsingDataRemover::TimeRange BrowsingDataRemover::Unbounded() { |
300 return TimeRange(base::Time(), base::Time::Max()); | 262 return TimeRange(base::Time(), base::Time::Max()); |
301 } | 263 } |
302 | 264 |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 storage_partition_for_testing_ = storage_partition; | 1024 storage_partition_for_testing_ = storage_partition; |
1063 } | 1025 } |
1064 | 1026 |
1065 #if BUILDFLAG(ANDROID_JAVA_UI) | 1027 #if BUILDFLAG(ANDROID_JAVA_UI) |
1066 void BrowsingDataRemover::OverrideWebappRegistryForTesting( | 1028 void BrowsingDataRemover::OverrideWebappRegistryForTesting( |
1067 std::unique_ptr<WebappRegistry> webapp_registry) { | 1029 std::unique_ptr<WebappRegistry> webapp_registry) { |
1068 webapp_registry_.reset(webapp_registry.release()); | 1030 webapp_registry_.reset(webapp_registry.release()); |
1069 } | 1031 } |
1070 #endif | 1032 #endif |
1071 | 1033 |
| 1034 const base::Time& BrowsingDataRemover::GetLastUsedBeginTime() { |
| 1035 return delete_begin_; |
| 1036 } |
| 1037 |
| 1038 const base::Time& BrowsingDataRemover::GetLastUsedEndTime() { |
| 1039 return delete_end_; |
| 1040 } |
| 1041 |
| 1042 int BrowsingDataRemover::GetLastUsedRemovalMask() { |
| 1043 return remove_mask_; |
| 1044 } |
| 1045 |
| 1046 int BrowsingDataRemover::GetLastUsedOriginTypeMask() { |
| 1047 return origin_type_mask_; |
| 1048 } |
| 1049 |
| 1050 |
1072 void BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( | 1051 void BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( |
1073 HostContentSettingsMap* content_settings_map, | 1052 HostContentSettingsMap* content_settings_map, |
1074 ContentSettingsType content_type, | 1053 ContentSettingsType content_type, |
1075 const base::Callback<bool(const ContentSettingsPattern& primary_pattern, | 1054 const base::Callback<bool(const ContentSettingsPattern& primary_pattern, |
1076 const ContentSettingsPattern& secondary_pattern)>& | 1055 const ContentSettingsPattern& secondary_pattern)>& |
1077 predicate) { | 1056 predicate) { |
1078 ContentSettingsForOneType settings; | 1057 ContentSettingsForOneType settings; |
1079 content_settings_map->GetSettingsForOneType(content_type, std::string(), | 1058 content_settings_map->GetSettingsForOneType(content_type, std::string(), |
1080 &settings); | 1059 &settings); |
1081 for (const ContentSettingPatternSource& setting : settings) { | 1060 for (const ContentSettingPatternSource& setting : settings) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 TemplateURLService* model = | 1100 TemplateURLService* model = |
1122 TemplateURLServiceFactory::GetForProfile(profile_); | 1101 TemplateURLServiceFactory::GetForProfile(profile_); |
1123 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); | 1102 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); |
1124 waiting_for_clear_keyword_data_ = false; | 1103 waiting_for_clear_keyword_data_ = false; |
1125 template_url_sub_.reset(); | 1104 template_url_sub_.reset(); |
1126 NotifyIfDone(); | 1105 NotifyIfDone(); |
1127 } | 1106 } |
1128 | 1107 |
1129 void BrowsingDataRemover::Notify() { | 1108 void BrowsingDataRemover::Notify() { |
1130 SetRemoving(false); | 1109 SetRemoving(false); |
1131 | |
1132 // Notify observers. | |
1133 BrowsingDataRemover::NotificationDetails details(delete_begin_, remove_mask_, | |
1134 origin_type_mask_); | |
1135 | |
1136 GetOnBrowsingDataRemovedCallbacks()->Notify(details); | |
1137 | |
1138 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); | 1110 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); |
1139 } | 1111 } |
1140 | 1112 |
1141 void BrowsingDataRemover::NotifyIfDone() { | 1113 void BrowsingDataRemover::NotifyIfDone() { |
1142 // TODO(brettw) http://crbug.com/305259: This should also observe session | 1114 // TODO(brettw) http://crbug.com/305259: This should also observe session |
1143 // clearing (what about other things such as passwords, etc.?) and wait for | 1115 // clearing (what about other things such as passwords, etc.?) and wait for |
1144 // them to complete before continuing. | 1116 // them to complete before continuing. |
1145 | 1117 |
1146 if (!AllDone()) | 1118 if (!AllDone()) |
1147 return; | 1119 return; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 waiting_for_clear_offline_page_data_ = false; | 1289 waiting_for_clear_offline_page_data_ = false; |
1318 NotifyIfDone(); | 1290 NotifyIfDone(); |
1319 } | 1291 } |
1320 #endif | 1292 #endif |
1321 | 1293 |
1322 void BrowsingDataRemover::OnClearedDomainReliabilityMonitor() { | 1294 void BrowsingDataRemover::OnClearedDomainReliabilityMonitor() { |
1323 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1295 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1324 waiting_for_clear_domain_reliability_monitor_ = false; | 1296 waiting_for_clear_domain_reliability_monitor_ = false; |
1325 NotifyIfDone(); | 1297 NotifyIfDone(); |
1326 } | 1298 } |
1327 | |
1328 // static | |
1329 BrowsingDataRemover::CallbackSubscription | |
1330 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | |
1331 const BrowsingDataRemover::Callback& callback) { | |
1332 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); | |
1333 } | |
OLD | NEW |