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 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ |
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // The removal mask (see the RemoveDataMask enum for details). | 163 // The removal mask (see the RemoveDataMask enum for details). |
164 int removal_mask; | 164 int removal_mask; |
165 | 165 |
166 // The origin type mask (see BrowsingDataHelper::OriginTypeMask for | 166 // The origin type mask (see BrowsingDataHelper::OriginTypeMask for |
167 // details). | 167 // details). |
168 int origin_type_mask; | 168 int origin_type_mask; |
169 }; | 169 }; |
170 | 170 |
171 struct TimeRange { | 171 struct TimeRange { |
172 TimeRange(base::Time begin, base::Time end) : begin(begin), end(end) {} | 172 TimeRange(base::Time begin, base::Time end) : begin(begin), end(end) {} |
| 173 bool operator==(const TimeRange& other) const; |
173 | 174 |
174 base::Time begin; | 175 base::Time begin; |
175 base::Time end; | 176 base::Time end; |
176 }; | 177 }; |
177 | 178 |
178 // Observer is notified when the removal is done. Done means keywords have | 179 // Observer is notified when the removal is done. Done means keywords have |
179 // been deleted, cache cleared and all other tasks scheduled. | 180 // been deleted, cache cleared and all other tasks scheduled. |
180 class Observer { | 181 class Observer { |
181 public: | 182 public: |
182 virtual void OnBrowsingDataRemoverDone() = 0; | 183 virtual void OnBrowsingDataRemoverDone() = 0; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void Remove(const TimeRange& time_range, | 235 void Remove(const TimeRange& time_range, |
235 int remove_mask, | 236 int remove_mask, |
236 int origin_type_mask); | 237 int origin_type_mask); |
237 | 238 |
238 // Removes the specified items related to browsing for all origins that match | 239 // Removes the specified items related to browsing for all origins that match |
239 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). | 240 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). |
240 // The |origin_filter| is used as a final filter for clearing operations. | 241 // The |origin_filter| is used as a final filter for clearing operations. |
241 // TODO(dmurph): Support all backends with filter (crbug.com/113621). | 242 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
242 // DO NOT USE THIS METHOD UNLESS CALLER KNOWS WHAT THEY'RE DOING. NOT ALL | 243 // DO NOT USE THIS METHOD UNLESS CALLER KNOWS WHAT THEY'RE DOING. NOT ALL |
243 // BACKENDS ARE SUPPORTED YET, AND MORE DATA THAN EXPECTED COULD BE DELETED. | 244 // BACKENDS ARE SUPPORTED YET, AND MORE DATA THAN EXPECTED COULD BE DELETED. |
244 void RemoveWithFilter(const TimeRange& time_range, | 245 virtual void RemoveWithFilter(const TimeRange& time_range, |
245 int remove_mask, | 246 int remove_mask, |
246 int origin_type_mask, | 247 int origin_type_mask, |
247 const BrowsingDataFilterBuilder& origin_filter); | 248 const BrowsingDataFilterBuilder& origin_filter); |
248 | 249 |
249 void AddObserver(Observer* observer); | 250 void AddObserver(Observer* observer); |
250 void RemoveObserver(Observer* observer); | 251 void RemoveObserver(Observer* observer); |
251 | 252 |
252 // Used for testing. | 253 // Used for testing. |
253 void OverrideStoragePartitionForTesting( | 254 void OverrideStoragePartitionForTesting( |
254 content::StoragePartition* storage_partition); | 255 content::StoragePartition* storage_partition); |
255 | 256 |
256 #if BUILDFLAG(ANDROID_JAVA_UI) | 257 #if BUILDFLAG(ANDROID_JAVA_UI) |
257 void OverrideWebappRegistryForTesting( | 258 void OverrideWebappRegistryForTesting( |
258 std::unique_ptr<WebappRegistry> webapp_registry); | 259 std::unique_ptr<WebappRegistry> webapp_registry); |
259 #endif | 260 #endif |
260 | 261 |
| 262 protected: |
| 263 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of |
| 264 // this class. The constructor is protected so that the class is mockable. |
| 265 BrowsingDataRemover(content::BrowserContext* browser_context); |
| 266 ~BrowsingDataRemover() override; |
| 267 |
261 private: | 268 private: |
262 // The clear API needs to be able to toggle removing_ in order to test that | 269 // The clear API needs to be able to toggle removing_ in order to test that |
263 // only one BrowsingDataRemover instance can be called at a time. | 270 // only one BrowsingDataRemover instance can be called at a time. |
264 FRIEND_TEST_ALL_PREFIXES(ExtensionBrowsingDataTest, OneAtATime); | 271 FRIEND_TEST_ALL_PREFIXES(ExtensionBrowsingDataTest, OneAtATime); |
265 // Testing our static method, ClearSettingsForOneTypeWithPredicate. | 272 // Testing our static method, ClearSettingsForOneTypeWithPredicate. |
266 FRIEND_TEST_ALL_PREFIXES(BrowsingDataRemoverTest, ClearWithPredicate); | 273 FRIEND_TEST_ALL_PREFIXES(BrowsingDataRemoverTest, ClearWithPredicate); |
267 | 274 |
268 // The BrowsingDataRemover tests need to be able to access the implementation | 275 // The BrowsingDataRemover tests need to be able to access the implementation |
269 // of Remove(), as it exposes details that aren't yet available in the public | 276 // of Remove(), as it exposes details that aren't yet available in the public |
270 // API. As soon as those details are exposed via new methods, this should be | 277 // API. As soon as those details are exposed via new methods, this should be |
271 // removed. | 278 // removed. |
272 // | 279 // |
273 // TODO(mkwst): See http://crbug.com/113621 | 280 // TODO(mkwst): See http://crbug.com/113621 |
274 friend class BrowsingDataRemoverTest; | 281 friend class BrowsingDataRemoverTest; |
275 | 282 |
276 friend class BrowsingDataRemoverFactory; | 283 friend class BrowsingDataRemoverFactory; |
277 | 284 |
278 // Clears all host-specific settings for one content type that satisfy the | 285 // Clears all host-specific settings for one content type that satisfy the |
279 // given predicate. | 286 // given predicate. |
280 // | 287 // |
281 // This should only be called on the UI thread. | 288 // This should only be called on the UI thread. |
282 static void ClearSettingsForOneTypeWithPredicate( | 289 static void ClearSettingsForOneTypeWithPredicate( |
283 HostContentSettingsMap* content_settings_map, | 290 HostContentSettingsMap* content_settings_map, |
284 ContentSettingsType content_type, | 291 ContentSettingsType content_type, |
285 const base::Callback< | 292 const base::Callback< |
286 bool(const ContentSettingsPattern& primary_pattern, | 293 bool(const ContentSettingsPattern& primary_pattern, |
287 const ContentSettingsPattern& secondary_pattern)>& predicate); | 294 const ContentSettingsPattern& secondary_pattern)>& predicate); |
288 | 295 |
289 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of | |
290 // this class. | |
291 BrowsingDataRemover(content::BrowserContext* browser_context); | |
292 ~BrowsingDataRemover() override; | |
293 | |
294 void Shutdown() override; | 296 void Shutdown() override; |
295 | 297 |
296 // Setter for |is_removing_|; DCHECKs that we can only start removing if we're | 298 // Setter for |is_removing_|; DCHECKs that we can only start removing if we're |
297 // not already removing, and vice-versa. | 299 // not already removing, and vice-versa. |
298 void SetRemoving(bool is_removing); | 300 void SetRemoving(bool is_removing); |
299 | 301 |
300 // Callback for when TemplateURLService has finished loading. Clears the data, | 302 // Callback for when TemplateURLService has finished loading. Clears the data, |
301 // clears the respective waiting flag, and invokes NotifyIfDone. | 303 // clears the respective waiting flag, and invokes NotifyIfDone. |
302 void OnKeywordsLoaded(); | 304 void OnKeywordsLoaded(); |
303 | 305 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 // not initialised, so the registry must be mocked out. | 499 // not initialised, so the registry must be mocked out. |
498 std::unique_ptr<WebappRegistry> webapp_registry_; | 500 std::unique_ptr<WebappRegistry> webapp_registry_; |
499 #endif | 501 #endif |
500 | 502 |
501 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; | 503 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; |
502 | 504 |
503 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); | 505 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); |
504 }; | 506 }; |
505 | 507 |
506 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 508 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ |
OLD | NEW |