| 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 17 matching lines...) Expand all Loading... |
| 320 content::RecordAction(UserMetricsAction("ClearBrowsingData_Everything")); | 282 content::RecordAction(UserMetricsAction("ClearBrowsingData_Everything")); |
| 321 break; | 283 break; |
| 322 } | 284 } |
| 323 return TimeRange(CalculateBeginDeleteTime(period), base::Time::Max()); | 285 return TimeRange(CalculateBeginDeleteTime(period), base::Time::Max()); |
| 324 } | 286 } |
| 325 | 287 |
| 326 BrowsingDataRemover::BrowsingDataRemover( | 288 BrowsingDataRemover::BrowsingDataRemover( |
| 327 content::BrowserContext* browser_context) | 289 content::BrowserContext* browser_context) |
| 328 : profile_(Profile::FromBrowserContext(browser_context)), | 290 : profile_(Profile::FromBrowserContext(browser_context)), |
| 329 is_removing_(false), | 291 is_removing_(false), |
| 292 remove_mask_(-1), |
| 293 origin_type_mask_(-1), |
| 330 #if BUILDFLAG(ANDROID_JAVA_UI) | 294 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 331 webapp_registry_(new WebappRegistry()), | 295 webapp_registry_(new WebappRegistry()), |
| 332 #endif | 296 #endif |
| 333 weak_ptr_factory_(this) { | 297 weak_ptr_factory_(this) { |
| 334 DCHECK(browser_context); | 298 DCHECK(browser_context); |
| 335 } | 299 } |
| 336 | 300 |
| 337 BrowsingDataRemover::~BrowsingDataRemover() { | 301 BrowsingDataRemover::~BrowsingDataRemover() { |
| 338 // If we are still removing data, notify observers so they can remove | 302 // If we are still removing data, notify observers so they can remove |
| 339 // themselves from the observer list. | 303 // themselves from the observer list. |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 storage_partition_for_testing_ = storage_partition; | 1026 storage_partition_for_testing_ = storage_partition; |
| 1063 } | 1027 } |
| 1064 | 1028 |
| 1065 #if BUILDFLAG(ANDROID_JAVA_UI) | 1029 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 1066 void BrowsingDataRemover::OverrideWebappRegistryForTesting( | 1030 void BrowsingDataRemover::OverrideWebappRegistryForTesting( |
| 1067 std::unique_ptr<WebappRegistry> webapp_registry) { | 1031 std::unique_ptr<WebappRegistry> webapp_registry) { |
| 1068 webapp_registry_.reset(webapp_registry.release()); | 1032 webapp_registry_.reset(webapp_registry.release()); |
| 1069 } | 1033 } |
| 1070 #endif | 1034 #endif |
| 1071 | 1035 |
| 1036 const base::Time& BrowsingDataRemover::GetLastUsedBeginTime() { |
| 1037 return delete_begin_; |
| 1038 } |
| 1039 |
| 1040 const base::Time& BrowsingDataRemover::GetLastUsedEndTime() { |
| 1041 return delete_end_; |
| 1042 } |
| 1043 |
| 1044 int BrowsingDataRemover::GetLastUsedRemovalMask() { |
| 1045 return remove_mask_; |
| 1046 } |
| 1047 |
| 1048 int BrowsingDataRemover::GetLastUsedOriginTypeMask() { |
| 1049 return origin_type_mask_; |
| 1050 } |
| 1051 |
| 1052 |
| 1072 void BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( | 1053 void BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( |
| 1073 HostContentSettingsMap* content_settings_map, | 1054 HostContentSettingsMap* content_settings_map, |
| 1074 ContentSettingsType content_type, | 1055 ContentSettingsType content_type, |
| 1075 const base::Callback<bool(const ContentSettingsPattern& primary_pattern, | 1056 const base::Callback<bool(const ContentSettingsPattern& primary_pattern, |
| 1076 const ContentSettingsPattern& secondary_pattern)>& | 1057 const ContentSettingsPattern& secondary_pattern)>& |
| 1077 predicate) { | 1058 predicate) { |
| 1078 ContentSettingsForOneType settings; | 1059 ContentSettingsForOneType settings; |
| 1079 content_settings_map->GetSettingsForOneType(content_type, std::string(), | 1060 content_settings_map->GetSettingsForOneType(content_type, std::string(), |
| 1080 &settings); | 1061 &settings); |
| 1081 for (const ContentSettingPatternSource& setting : settings) { | 1062 for (const ContentSettingPatternSource& setting : settings) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 TemplateURLService* model = | 1102 TemplateURLService* model = |
| 1122 TemplateURLServiceFactory::GetForProfile(profile_); | 1103 TemplateURLServiceFactory::GetForProfile(profile_); |
| 1123 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); | 1104 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); |
| 1124 waiting_for_clear_keyword_data_ = false; | 1105 waiting_for_clear_keyword_data_ = false; |
| 1125 template_url_sub_.reset(); | 1106 template_url_sub_.reset(); |
| 1126 NotifyIfDone(); | 1107 NotifyIfDone(); |
| 1127 } | 1108 } |
| 1128 | 1109 |
| 1129 void BrowsingDataRemover::Notify() { | 1110 void BrowsingDataRemover::Notify() { |
| 1130 SetRemoving(false); | 1111 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()); | 1112 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); |
| 1139 } | 1113 } |
| 1140 | 1114 |
| 1141 void BrowsingDataRemover::NotifyIfDone() { | 1115 void BrowsingDataRemover::NotifyIfDone() { |
| 1142 // TODO(brettw) http://crbug.com/305259: This should also observe session | 1116 // TODO(brettw) http://crbug.com/305259: This should also observe session |
| 1143 // clearing (what about other things such as passwords, etc.?) and wait for | 1117 // clearing (what about other things such as passwords, etc.?) and wait for |
| 1144 // them to complete before continuing. | 1118 // them to complete before continuing. |
| 1145 | 1119 |
| 1146 if (!AllDone()) | 1120 if (!AllDone()) |
| 1147 return; | 1121 return; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 waiting_for_clear_offline_page_data_ = false; | 1291 waiting_for_clear_offline_page_data_ = false; |
| 1318 NotifyIfDone(); | 1292 NotifyIfDone(); |
| 1319 } | 1293 } |
| 1320 #endif | 1294 #endif |
| 1321 | 1295 |
| 1322 void BrowsingDataRemover::OnClearedDomainReliabilityMonitor() { | 1296 void BrowsingDataRemover::OnClearedDomainReliabilityMonitor() { |
| 1323 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1297 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1324 waiting_for_clear_domain_reliability_monitor_ = false; | 1298 waiting_for_clear_domain_reliability_monitor_ = false; |
| 1325 NotifyIfDone(); | 1299 NotifyIfDone(); |
| 1326 } | 1300 } |
| 1327 | |
| 1328 // static | |
| 1329 BrowsingDataRemover::CallbackSubscription | |
| 1330 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | |
| 1331 const BrowsingDataRemover::Callback& callback) { | |
| 1332 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); | |
| 1333 } | |
| OLD | NEW |