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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // A helper enum to report the deletion of cookies and/or cache. Do not | 137 // A helper enum to report the deletion of cookies and/or cache. Do not |
138 // reorder the entries, as this enum is passed to UMA. | 138 // reorder the entries, as this enum is passed to UMA. |
139 enum CookieOrCacheDeletionChoice { | 139 enum CookieOrCacheDeletionChoice { |
140 NEITHER_COOKIES_NOR_CACHE, | 140 NEITHER_COOKIES_NOR_CACHE, |
141 ONLY_COOKIES, | 141 ONLY_COOKIES, |
142 ONLY_CACHE, | 142 ONLY_CACHE, |
143 BOTH_COOKIES_AND_CACHE, | 143 BOTH_COOKIES_AND_CACHE, |
144 MAX_CHOICE_VALUE | 144 MAX_CHOICE_VALUE |
145 }; | 145 }; |
146 | 146 |
147 // When BrowsingDataRemover successfully removes data, a notification of type | |
148 // NOTIFICATION_BROWSING_DATA_REMOVED is triggered with a Details object of | |
149 // this type. | |
150 struct NotificationDetails { | |
151 NotificationDetails(); | |
152 NotificationDetails(const NotificationDetails& details); | |
153 NotificationDetails(base::Time removal_begin, | |
154 int removal_mask, | |
155 int origin_type_mask); | |
156 ~NotificationDetails(); | |
157 | |
158 // The beginning of the removal time range. | |
159 base::Time removal_begin; | |
160 | |
161 // The removal mask (see the RemoveDataMask enum for details). | |
162 int removal_mask; | |
163 | |
164 // The origin type mask (see BrowsingDataHelper::OriginTypeMask for | |
165 // details). | |
166 int origin_type_mask; | |
167 }; | |
168 | |
169 struct TimeRange { | 147 struct TimeRange { |
170 TimeRange(base::Time begin, base::Time end) : begin(begin), end(end) {} | 148 TimeRange(base::Time begin, base::Time end) : begin(begin), end(end) {} |
171 bool operator==(const TimeRange& other) const; | 149 bool operator==(const TimeRange& other) const; |
172 | 150 |
173 base::Time begin; | 151 base::Time begin; |
174 base::Time end; | 152 base::Time end; |
175 }; | 153 }; |
176 | 154 |
177 // Observer is notified when the removal is active and when it's done. | 155 // Observer is notified when the removal is active and when it's done. |
178 class Observer { | 156 class Observer { |
179 public: | 157 public: |
180 // NOTE: DEPRECATED; talk to dbeam/msramek before using this. | 158 // NOTE: DEPRECATED; talk to dbeam/msramek before using this. |
181 // | 159 // |
182 // Whether removal is active. Note that not having an active removal is not | 160 // Whether removal is active. Note that not having an active removal is not |
183 // same as completing a removal. That is why the removing status is separate | 161 // same as completing a removal. That is why the removing status is separate |
184 // from the done message. | 162 // from the done message. |
185 virtual void OnBrowsingDataRemoving(bool is_removing) {} | 163 virtual void OnBrowsingDataRemoving(bool is_removing) {} |
186 | 164 |
187 // Done means keywords have been deleted, cache cleared and all other | 165 // Done means keywords have been deleted, cache cleared and all other |
188 // removal tasks are scheduled. | 166 // removal tasks are scheduled. |
189 virtual void OnBrowsingDataRemoverDone() {} | 167 virtual void OnBrowsingDataRemoverDone() {} |
190 | 168 |
191 protected: | 169 protected: |
192 virtual ~Observer() {} | 170 virtual ~Observer() {} |
193 }; | 171 }; |
194 | 172 |
195 using Callback = base::Callback<void(const NotificationDetails&)>; | |
196 using CallbackSubscription = std::unique_ptr< | |
197 base::CallbackList<void(const NotificationDetails&)>::Subscription>; | |
198 | |
199 // The completion inhibitor can artificially delay completion of the browsing | 173 // The completion inhibitor can artificially delay completion of the browsing |
200 // data removal process. It is used during testing to simulate scenarios in | 174 // data removal process. It is used during testing to simulate scenarios in |
201 // which the deletion stalls or takes a very long time. | 175 // which the deletion stalls or takes a very long time. |
202 class CompletionInhibitor { | 176 class CompletionInhibitor { |
203 public: | 177 public: |
204 // Invoked when a |remover| is just about to complete clearing browser data, | 178 // Invoked when a |remover| is just about to complete clearing browser data, |
205 // and will be prevented from completing until after the callback | 179 // and will be prevented from completing until after the callback |
206 // |continue_to_completion| is run. | 180 // |continue_to_completion| is run. |
207 virtual void OnBrowsingDataRemoverWouldComplete( | 181 virtual void OnBrowsingDataRemoverWouldComplete( |
208 BrowsingDataRemover* remover, | 182 BrowsingDataRemover* remover, |
(...skipping 12 matching lines...) Expand all Loading... |
221 | 195 |
222 // Sets a CompletionInhibitor, which will be notified each time an instance is | 196 // Sets a CompletionInhibitor, which will be notified each time an instance is |
223 // about to complete a browsing data removal process, and will be able to | 197 // about to complete a browsing data removal process, and will be able to |
224 // artificially delay the completion. | 198 // artificially delay the completion. |
225 // TODO(crbug.com/483528): Make this non-static. | 199 // TODO(crbug.com/483528): Make this non-static. |
226 static void set_completion_inhibitor_for_testing( | 200 static void set_completion_inhibitor_for_testing( |
227 CompletionInhibitor* inhibitor) { | 201 CompletionInhibitor* inhibitor) { |
228 completion_inhibitor_ = inhibitor; | 202 completion_inhibitor_ = inhibitor; |
229 } | 203 } |
230 | 204 |
231 // Add a callback to the list of callbacks to be called during a browsing data | |
232 // removal event. Returns a subscription object that can be used to | |
233 // un-register the callback. | |
234 // TODO(crbug.com/483528): Make this non-static and merge it with the Observer | |
235 // interface. | |
236 static CallbackSubscription RegisterOnBrowsingDataRemovedCallback( | |
237 const Callback& callback); | |
238 | |
239 // Removes the specified items related to browsing for all origins that match | 205 // Removes the specified items related to browsing for all origins that match |
240 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). | 206 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). |
241 void Remove(const TimeRange& time_range, | 207 void Remove(const TimeRange& time_range, |
242 int remove_mask, | 208 int remove_mask, |
243 int origin_type_mask); | 209 int origin_type_mask); |
244 | 210 |
245 // Removes the specified items related to browsing for all origins that match | 211 // Removes the specified items related to browsing for all origins that match |
246 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). | 212 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). |
247 // The |origin_filter| is used as a final filter for clearing operations. | 213 // The |origin_filter| is used as a final filter for clearing operations. |
248 // TODO(dmurph): Support all backends with filter (crbug.com/113621). | 214 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
249 // DO NOT USE THIS METHOD UNLESS CALLER KNOWS WHAT THEY'RE DOING. NOT ALL | 215 // DO NOT USE THIS METHOD UNLESS CALLER KNOWS WHAT THEY'RE DOING. NOT ALL |
250 // BACKENDS ARE SUPPORTED YET, AND MORE DATA THAN EXPECTED COULD BE DELETED. | 216 // BACKENDS ARE SUPPORTED YET, AND MORE DATA THAN EXPECTED COULD BE DELETED. |
251 virtual void RemoveWithFilter(const TimeRange& time_range, | 217 virtual void RemoveWithFilter(const TimeRange& time_range, |
252 int remove_mask, | 218 int remove_mask, |
253 int origin_type_mask, | 219 int origin_type_mask, |
254 const BrowsingDataFilterBuilder& origin_filter); | 220 const BrowsingDataFilterBuilder& origin_filter); |
255 | 221 |
256 void AddObserver(Observer* observer); | 222 void AddObserver(Observer* observer); |
257 void RemoveObserver(Observer* observer); | 223 void RemoveObserver(Observer* observer); |
258 | 224 |
259 // Used for testing. | 225 // Used for testing. |
260 void OverrideStoragePartitionForTesting( | 226 void OverrideStoragePartitionForTesting( |
261 content::StoragePartition* storage_partition); | 227 content::StoragePartition* storage_partition); |
262 | 228 |
263 #if BUILDFLAG(ANDROID_JAVA_UI) | 229 #if BUILDFLAG(ANDROID_JAVA_UI) |
264 void OverrideWebappRegistryForTesting( | 230 void OverrideWebappRegistryForTesting( |
265 std::unique_ptr<WebappRegistry> webapp_registry); | 231 std::unique_ptr<WebappRegistry> webapp_registry); |
266 #endif | 232 #endif |
267 | 233 |
| 234 // Parameters of the last call are exposed to be used by tests. Removal and |
| 235 // origin type masks equal to -1 mean that no removal has ever been executed. |
| 236 // TODO(msramek): If other consumers than tests are interested in this, |
| 237 // consider returning them in OnBrowsingDataRemoverDone() callback. |
| 238 const base::Time& GetLastUsedBeginTime(); |
| 239 const base::Time& GetLastUsedEndTime(); |
| 240 int GetLastUsedRemovalMask(); |
| 241 int GetLastUsedOriginTypeMask(); |
| 242 |
268 protected: | 243 protected: |
269 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of | 244 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of |
270 // this class. The constructor is protected so that the class is mockable. | 245 // this class. The constructor is protected so that the class is mockable. |
271 BrowsingDataRemover(content::BrowserContext* browser_context); | 246 BrowsingDataRemover(content::BrowserContext* browser_context); |
272 ~BrowsingDataRemover() override; | 247 ~BrowsingDataRemover() override; |
273 | 248 |
274 private: | 249 private: |
275 // The clear API needs to be able to toggle removing_ in order to test that | 250 // The clear API needs to be able to toggle removing_ in order to test that |
276 // only one BrowsingDataRemover instance can be called at a time. | 251 // only one BrowsingDataRemover instance can be called at a time. |
277 FRIEND_TEST_ALL_PREFIXES(ExtensionBrowsingDataTest, OneAtATime); | 252 FRIEND_TEST_ALL_PREFIXES(ExtensionBrowsingDataTest, OneAtATime); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 // not initialised, so the registry must be mocked out. | 481 // not initialised, so the registry must be mocked out. |
507 std::unique_ptr<WebappRegistry> webapp_registry_; | 482 std::unique_ptr<WebappRegistry> webapp_registry_; |
508 #endif | 483 #endif |
509 | 484 |
510 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; | 485 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; |
511 | 486 |
512 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); | 487 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); |
513 }; | 488 }; |
514 | 489 |
515 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ | 490 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ |
OLD | NEW |