| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_PUBLIC_BROWSER_BROWSING_DATA_REMOVER_H_ |
| 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_BROWSING_DATA_REMOVER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 |
| 9 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h" | 14 |
| 14 #include "components/keyed_service/core/keyed_service.h" | 15 class GURL; |
| 16 |
| 17 namespace storage { |
| 18 class SpecialStoragePolicy; |
| 19 } |
| 15 | 20 |
| 16 namespace content { | 21 namespace content { |
| 22 |
| 17 class BrowsingDataFilterBuilder; | 23 class BrowsingDataFilterBuilder; |
| 18 } | 24 class BrowsingDataRemoverDelegate; |
| 19 | 25 |
| 20 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
| 21 // BrowsingDataRemover is responsible for removing data related to browsing: | 27 // BrowsingDataRemover is responsible for removing data related to browsing: |
| 22 // visits in url database, downloads, cookies ... | 28 // visits in url database, downloads, cookies ... |
| 23 // | 29 // |
| 24 // USAGE: | 30 // USAGE: |
| 25 // | 31 // |
| 26 // 0. Instantiation. | 32 // 0. Instantiation. |
| 27 // | 33 // |
| 28 // BrowsingDataRemover* remover = | 34 // content::BrowsingDataRemover* remover = |
| 29 // BrowsingDataRemoverFactory::GetForBrowserContext(browser_context); | 35 // content::BrowserContext::GetBrowsingDataRemover(browser_context); |
| 30 // | 36 // |
| 31 // 1. No observer. | 37 // 1. No observer. |
| 32 // | 38 // |
| 33 // remover->Remove(base::Time(), base::Time::Max(), REMOVE_COOKIES, ALL); | 39 // remover->Remove(base::Time(), base::Time::Max(), REMOVE_COOKIES, ALL); |
| 34 // | 40 // |
| 35 // 2. Using an observer to report when one's own removal task is finished. | 41 // 2. Using an observer to report when one's own removal task is finished. |
| 36 // | 42 // |
| 37 // class CookiesDeleter : public BrowsingDataRemover::Observer { | 43 // class CookiesDeleter : public content::BrowsingDataRemover::Observer { |
| 38 // CookiesDeleter() { remover->AddObserver(this); } | 44 // CookiesDeleter() { remover->AddObserver(this); } |
| 39 // ~CookiesDeleter() { remover->RemoveObserver(this); } | 45 // ~CookiesDeleter() { remover->RemoveObserver(this); } |
| 40 // | 46 // |
| 41 // void DeleteCookies() { | 47 // void DeleteCookies() { |
| 42 // remover->RemoveAndReply(base::Time(), base::Time::Max(), | 48 // remover->RemoveAndReply(base::Time(), base::Time::Max(), |
| 43 // REMOVE_COOKIES, ALL, this); | 49 // REMOVE_COOKIES, ALL, this); |
| 44 // } | 50 // } |
| 45 // | 51 // |
| 46 // void OnBrowsingDataRemoverDone() { | 52 // void OnBrowsingDataRemoverDone() { |
| 47 // LOG(INFO) << "Cookies were deleted."; | 53 // LOG(INFO) << "Cookies were deleted."; |
| 48 // } | 54 // } |
| 49 // } | 55 // } |
| 50 // | 56 // |
| 51 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
| 52 // | 58 // |
| 53 // TODO(crbug.com/668114): BrowsingDataRemover does not currently support plugin | 59 // TODO(crbug.com/668114): BrowsingDataRemover does not currently support plugin |
| 54 // data deletion. Use PluginDataRemover instead. | 60 // data deletion. Use PluginDataRemover instead. |
| 55 class BrowsingDataRemover : public KeyedService { | 61 class BrowsingDataRemover { |
| 56 public: | 62 public: |
| 57 // Mask used for Remove. | 63 // Mask used for Remove. |
| 58 enum DataType { | 64 enum DataType { |
| 59 // Storage datatypes. | 65 // Storage datatypes. |
| 60 DATA_TYPE_APP_CACHE = 1 << 0, | 66 DATA_TYPE_APP_CACHE = 1 << 0, |
| 61 DATA_TYPE_FILE_SYSTEMS = 1 << 1, | 67 DATA_TYPE_FILE_SYSTEMS = 1 << 1, |
| 62 DATA_TYPE_INDEXED_DB = 1 << 2, | 68 DATA_TYPE_INDEXED_DB = 1 << 2, |
| 63 DATA_TYPE_LOCAL_STORAGE = 1 << 3, | 69 DATA_TYPE_LOCAL_STORAGE = 1 << 3, |
| 64 DATA_TYPE_WEB_SQL = 1 << 4, | 70 DATA_TYPE_WEB_SQL = 1 << 4, |
| 65 DATA_TYPE_SERVICE_WORKERS = 1 << 5, | 71 DATA_TYPE_SERVICE_WORKERS = 1 << 5, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 class Observer { | 127 class Observer { |
| 122 public: | 128 public: |
| 123 // Called when a removal task is finished. Note that every removal task can | 129 // Called when a removal task is finished. Note that every removal task can |
| 124 // only have one observer attached to it, and only that one is called. | 130 // only have one observer attached to it, and only that one is called. |
| 125 virtual void OnBrowsingDataRemoverDone() = 0; | 131 virtual void OnBrowsingDataRemoverDone() = 0; |
| 126 | 132 |
| 127 protected: | 133 protected: |
| 128 virtual ~Observer() {} | 134 virtual ~Observer() {} |
| 129 }; | 135 }; |
| 130 | 136 |
| 131 // Called by the embedder to provide the delegate that will take care of | 137 // A delegate that will take care of deleting embedder-specific data. |
| 132 // deleting embedder-specific data. | |
| 133 virtual void SetEmbedderDelegate( | 138 virtual void SetEmbedderDelegate( |
| 134 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) = 0; | 139 BrowsingDataRemoverDelegate* embedder_delegate) = 0; |
| 135 virtual BrowsingDataRemoverDelegate* GetEmbedderDelegate() const = 0; | |
| 136 | 140 |
| 137 // Determines whether |origin| matches the |origin_type_mask| according to | 141 // Determines whether |origin| matches the |origin_type_mask| according to |
| 138 // the |special_storage_policy|. | 142 // the |special_storage_policy|. |
| 139 virtual bool DoesOriginMatchMask( | 143 virtual bool DoesOriginMatchMask( |
| 140 int origin_type_mask, | 144 int origin_type_mask, |
| 141 const GURL& origin, | 145 const GURL& origin, |
| 142 storage::SpecialStoragePolicy* special_storage_policy) const = 0; | 146 storage::SpecialStoragePolicy* special_storage_policy) const = 0; |
| 143 | 147 |
| 144 // Removes browsing data within the given |time_range|, with datatypes being | 148 // Removes browsing data within the given |time_range|, with datatypes being |
| 145 // specified by |remove_mask| and origin types by |origin_type_mask|. | 149 // specified by |remove_mask| and origin types by |origin_type_mask|. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 157 Observer* observer) = 0; | 161 Observer* observer) = 0; |
| 158 | 162 |
| 159 // Like Remove(), but in case of URL-keyed only removes data whose URL match | 163 // Like Remove(), but in case of URL-keyed only removes data whose URL match |
| 160 // |filter_builder| (e.g. are on certain origin or domain). | 164 // |filter_builder| (e.g. are on certain origin or domain). |
| 161 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES. | 165 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES. |
| 162 virtual void RemoveWithFilter( | 166 virtual void RemoveWithFilter( |
| 163 const base::Time& delete_begin, | 167 const base::Time& delete_begin, |
| 164 const base::Time& delete_end, | 168 const base::Time& delete_end, |
| 165 int remove_mask, | 169 int remove_mask, |
| 166 int origin_type_mask, | 170 int origin_type_mask, |
| 167 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder) = 0; | 171 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) = 0; |
| 168 | 172 |
| 169 // A version of the above that in addition informs the |observer| when the | 173 // A version of the above that in addition informs the |observer| when the |
| 170 // removal task is finished. | 174 // removal task is finished. |
| 171 virtual void RemoveWithFilterAndReply( | 175 virtual void RemoveWithFilterAndReply( |
| 172 const base::Time& delete_begin, | 176 const base::Time& delete_begin, |
| 173 const base::Time& delete_end, | 177 const base::Time& delete_end, |
| 174 int remove_mask, | 178 int remove_mask, |
| 175 int origin_type_mask, | 179 int origin_type_mask, |
| 176 std::unique_ptr<content::BrowsingDataFilterBuilder> filter_builder, | 180 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, |
| 177 Observer* observer) = 0; | 181 Observer* observer) = 0; |
| 178 | 182 |
| 179 // Observers. | 183 // Observers. |
| 180 virtual void AddObserver(Observer* observer) = 0; | 184 virtual void AddObserver(Observer* observer) = 0; |
| 181 virtual void RemoveObserver(Observer* observer) = 0; | 185 virtual void RemoveObserver(Observer* observer) = 0; |
| 182 | 186 |
| 183 // A |callback| that will be called just before a deletion task is completed | 187 // A |callback| that will be called just before a deletion task is completed |
| 184 // and observers are notified. The receiver must respond by calling | 188 // and observers are notified. The receiver must respond by calling |
| 185 // |continue_to_completion| to finish the task. Used in tests to artificially | 189 // |continue_to_completion| to finish the task. Used in tests to artificially |
| 186 // prolong execution. | 190 // prolong execution. |
| 187 virtual void SetWouldCompleteCallbackForTesting( | 191 virtual void SetWouldCompleteCallbackForTesting( |
| 188 const base::Callback<void(const base::Closure& continue_to_completion)>& | 192 const base::Callback<void(const base::Closure& continue_to_completion)>& |
| 189 callback) = 0; | 193 callback) = 0; |
| 190 | 194 |
| 191 // Parameters of the last call are exposed to be used by tests. Removal and | 195 // Parameters of the last call are exposed to be used by tests. Removal and |
| 192 // origin type masks equal to -1 mean that no removal has ever been executed. | 196 // origin type masks equal to -1 mean that no removal has ever been executed. |
| 193 // TODO(msramek): If other consumers than tests are interested in this, | 197 // TODO(msramek): If other consumers than tests are interested in this, |
| 194 // consider returning them in OnBrowsingDataRemoverDone() callback. If not, | 198 // consider returning them in OnBrowsingDataRemoverDone() callback. If not, |
| 195 // consider simplifying this interface by removing these methods and changing | 199 // consider simplifying this interface by removing these methods and changing |
| 196 // the tests to record the parameters using GMock instead. | 200 // the tests to record the parameters using GMock instead. |
| 197 virtual const base::Time& GetLastUsedBeginTime() = 0; | 201 virtual const base::Time& GetLastUsedBeginTime() = 0; |
| 198 virtual const base::Time& GetLastUsedEndTime() = 0; | 202 virtual const base::Time& GetLastUsedEndTime() = 0; |
| 199 virtual int GetLastUsedRemovalMask() = 0; | 203 virtual int GetLastUsedRemovalMask() = 0; |
| 200 virtual int GetLastUsedOriginTypeMask() = 0; | 204 virtual int GetLastUsedOriginTypeMask() = 0; |
| 201 }; | 205 }; |
| 202 | 206 |
| 203 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 207 } // namespace content |
| 208 |
| 209 #endif // CONTENT_PUBLIC_BROWSER_BROWSING_DATA_REMOVER_H_ |
| OLD | NEW |