Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/callback_forward.h" | |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 17 #include "base/sequenced_task_runner_helpers.h" | 18 #include "base/sequenced_task_runner_helpers.h" |
| 18 #include "base/synchronization/waitable_event_watcher.h" | 19 #include "base/synchronization/waitable_event_watcher.h" |
| 19 #include "base/task/cancelable_task_tracker.h" | 20 #include "base/task/cancelable_task_tracker.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 22 #include "chrome/common/features.h" | 23 #include "chrome/common/features.h" |
| 24 #include "components/content_settings/core/common/content_settings_pattern.h" | |
| 25 #include "components/content_settings/core/common/content_settings_types.h" | |
| 23 #include "components/keyed_service/core/keyed_service.h" | 26 #include "components/keyed_service/core/keyed_service.h" |
| 24 #include "components/prefs/pref_member.h" | 27 #include "components/prefs/pref_member.h" |
| 25 #include "components/search_engines/template_url_service.h" | 28 #include "components/search_engines/template_url_service.h" |
| 26 #include "storage/common/quota/quota_types.h" | 29 #include "storage/common/quota/quota_types.h" |
| 27 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 28 | 31 |
| 29 #if defined(ENABLE_PLUGINS) | 32 #if defined(ENABLE_PLUGINS) |
| 30 #include "chrome/browser/pepper_flash_settings_manager.h" | 33 #include "chrome/browser/pepper_flash_settings_manager.h" |
| 31 #endif | 34 #endif |
| 32 | 35 |
| 33 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 34 #include "chromeos/dbus/dbus_method_call_status.h" | 37 #include "chromeos/dbus/dbus_method_call_status.h" |
| 35 #endif | 38 #endif |
| 36 | 39 |
| 37 class BrowsingDataRemoverFactory; | 40 class BrowsingDataRemoverFactory; |
| 41 class HostContentSettingsMap; | |
| 38 class IOThread; | 42 class IOThread; |
| 43 class BrowsingDataRemoverFilter; | |
| 39 class Profile; | 44 class Profile; |
| 40 | 45 |
| 41 namespace chrome_browser_net { | 46 namespace chrome_browser_net { |
| 42 class Predictor; | 47 class Predictor; |
| 43 } | 48 } |
| 44 | 49 |
| 45 namespace content { | 50 namespace content { |
| 46 class BrowserContext; | 51 class BrowserContext; |
| 47 class PluginDataRemover; | 52 class PluginDataRemover; |
| 48 class StoragePartition; | 53 class StoragePartition; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 // interface. | 248 // interface. |
| 244 static CallbackSubscription RegisterOnBrowsingDataRemovedCallback( | 249 static CallbackSubscription RegisterOnBrowsingDataRemovedCallback( |
| 245 const Callback& callback); | 250 const Callback& callback); |
| 246 | 251 |
| 247 // Removes the specified items related to browsing for all origins that match | 252 // Removes the specified items related to browsing for all origins that match |
| 248 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). | 253 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). |
| 249 void Remove(const TimeRange& time_range, | 254 void Remove(const TimeRange& time_range, |
| 250 int remove_mask, | 255 int remove_mask, |
| 251 int origin_type_mask); | 256 int origin_type_mask); |
| 252 | 257 |
| 258 // Removes the specified items related to browsing for all origins that match | |
| 259 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). | |
| 260 // The |origin_filter| is used as a final filter for clearing operations. | |
| 261 // TODO(dmurph): Support all backends with filter (crbug.com/113621). | |
| 262 // DO NOT USE THIS METHOD UNLESS CALLER KNOWS WHAT THEY'RE DOING. NOT ALL | |
| 263 // BACKENDS ARE SUPPORTED YET, AND MORE DATA THAN EXPECTED COULD BE DELETED. | |
|
kinuko
2016/04/07 09:03:08
Phew...
| |
| 264 void RemoveWithFilter(const TimeRange& time_range, | |
| 265 int remove_mask, | |
| 266 int origin_type_mask, | |
| 267 const BrowsingDataRemoverFilter& origin_filter); | |
| 268 | |
| 253 void AddObserver(Observer* observer); | 269 void AddObserver(Observer* observer); |
| 254 void RemoveObserver(Observer* observer); | 270 void RemoveObserver(Observer* observer); |
| 255 | 271 |
| 256 // Used for testing. | 272 // Used for testing. |
| 257 void OverrideStoragePartitionForTesting( | 273 void OverrideStoragePartitionForTesting( |
| 258 content::StoragePartition* storage_partition); | 274 content::StoragePartition* storage_partition); |
| 259 | 275 |
| 260 #if BUILDFLAG(ANDROID_JAVA_UI) | 276 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 261 void OverrideWebappRegistryForTesting( | 277 void OverrideWebappRegistryForTesting( |
| 262 scoped_ptr<WebappRegistry> webapp_registry); | 278 scoped_ptr<WebappRegistry> webapp_registry); |
| 263 #endif | 279 #endif |
| 264 | 280 |
| 265 private: | 281 private: |
| 266 // The clear API needs to be able to toggle removing_ in order to test that | 282 // The clear API needs to be able to toggle removing_ in order to test that |
| 267 // only one BrowsingDataRemover instance can be called at a time. | 283 // only one BrowsingDataRemover instance can be called at a time. |
| 268 FRIEND_TEST_ALL_PREFIXES(ExtensionBrowsingDataTest, OneAtATime); | 284 FRIEND_TEST_ALL_PREFIXES(ExtensionBrowsingDataTest, OneAtATime); |
| 285 // Testing our static method, ClearSettingsForOneTypeWithPredicate. | |
| 286 FRIEND_TEST_ALL_PREFIXES(BrowsingDataRemoverTest, ClearWithPredicate); | |
| 269 | 287 |
| 270 // The BrowsingDataRemover tests need to be able to access the implementation | 288 // The BrowsingDataRemover tests need to be able to access the implementation |
| 271 // of Remove(), as it exposes details that aren't yet available in the public | 289 // of Remove(), as it exposes details that aren't yet available in the public |
| 272 // API. As soon as those details are exposed via new methods, this should be | 290 // API. As soon as those details are exposed via new methods, this should be |
| 273 // removed. | 291 // removed. |
| 274 // | 292 // |
| 275 // TODO(mkwst): See http://crbug.com/113621 | 293 // TODO(mkwst): See http://crbug.com/113621 |
| 276 friend class BrowsingDataRemoverTest; | 294 friend class BrowsingDataRemoverTest; |
| 277 | 295 |
| 278 friend class BrowsingDataRemoverFactory; | 296 friend class BrowsingDataRemoverFactory; |
| 279 | 297 |
| 298 // Clears all host-specific settings for one content type that satisfy the | |
| 299 // given predicate. | |
| 300 // | |
| 301 // This should only be called on the UI thread. | |
| 302 static void ClearSettingsForOneTypeWithPredicate( | |
| 303 HostContentSettingsMap* content_settings_map, | |
| 304 ContentSettingsType content_type, | |
| 305 const base::Callback< | |
| 306 bool(const ContentSettingsPattern& primary_pattern, | |
| 307 const ContentSettingsPattern& secondary_pattern)>& predicate); | |
| 308 | |
| 280 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of | 309 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of |
| 281 // this class. | 310 // this class. |
| 282 BrowsingDataRemover(content::BrowserContext* browser_context); | 311 BrowsingDataRemover(content::BrowserContext* browser_context); |
| 283 ~BrowsingDataRemover() override; | 312 ~BrowsingDataRemover() override; |
| 284 | 313 |
| 285 void Shutdown() override; | 314 void Shutdown() override; |
| 286 | 315 |
| 287 // Setter for |is_removing_|; DCHECKs that we can only start removing if we're | 316 // Setter for |is_removing_|; DCHECKs that we can only start removing if we're |
| 288 // not already removing, and vice-versa. | 317 // not already removing, and vice-versa. |
| 289 void SetRemoving(bool is_removing); | 318 void SetRemoving(bool is_removing); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 301 bool success) override; | 330 bool success) override; |
| 302 #endif | 331 #endif |
| 303 | 332 |
| 304 #if defined (OS_CHROMEOS) | 333 #if defined (OS_CHROMEOS) |
| 305 void OnClearPlatformKeys(chromeos::DBusMethodCallStatus call_status, | 334 void OnClearPlatformKeys(chromeos::DBusMethodCallStatus call_status, |
| 306 bool result); | 335 bool result); |
| 307 #endif | 336 #endif |
| 308 | 337 |
| 309 // Removes the specified items related to browsing for a specific host. If the | 338 // Removes the specified items related to browsing for a specific host. If the |
| 310 // provided |remove_url| is empty, data is removed for all origins; otherwise, | 339 // provided |remove_url| is empty, data is removed for all origins; otherwise, |
| 311 // it is restricted by origin (where implemented yet). The | 340 // it is restricted by the origin filter origin (where implemented yet). The |
| 312 // |origin_type_mask| parameter defines the set of origins from which data | 341 // |origin_type_mask| parameter defines the set of origins from which data |
| 313 // should be removed (protected, unprotected, or both). | 342 // should be removed (protected, unprotected, or both). |
| 314 // TODO(ttr314): Remove "(where implemented yet)" constraint above once | 343 // TODO(ttr314): Remove "(where implemented yet)" constraint above once |
| 315 // crbug.com/113621 is done. | 344 // crbug.com/113621 is done. |
| 345 // TODO(crbug.com/589586): Support all backends w/ origin filter. | |
| 316 void RemoveImpl(const TimeRange& time_range, | 346 void RemoveImpl(const TimeRange& time_range, |
| 317 int remove_mask, | 347 int remove_mask, |
| 318 const GURL& remove_url, | 348 const BrowsingDataRemoverFilter& origin_filter, |
| 319 int origin_type_mask); | 349 int origin_type_mask); |
| 320 | 350 |
| 321 // Notifies observers and transitions to the idle state. | 351 // Notifies observers and transitions to the idle state. |
| 322 void Notify(); | 352 void Notify(); |
| 323 | 353 |
| 324 // Checks if we are all done, and if so, calls Notify(). | 354 // Checks if we are all done, and if so, calls Notify(). |
| 325 void NotifyIfDone(); | 355 void NotifyIfDone(); |
| 326 | 356 |
| 327 // Called when history deletion is done. | 357 // Called when history deletion is done. |
| 328 void OnHistoryDeletionDone(); | 358 void OnHistoryDeletionDone(); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 // not initialised, so the registry must be mocked out. | 520 // not initialised, so the registry must be mocked out. |
| 491 scoped_ptr<WebappRegistry> webapp_registry_; | 521 scoped_ptr<WebappRegistry> webapp_registry_; |
| 492 #endif | 522 #endif |
| 493 | 523 |
| 494 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; | 524 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; |
| 495 | 525 |
| 496 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); | 526 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); |
| 497 }; | 527 }; |
| 498 | 528 |
| 499 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 529 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ |
| OLD | NEW |