Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover.h

Issue 2175703002: Implement a task scheduler for BrowsingDataRemover (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bdr-race-condition
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 57
58 namespace net { 58 namespace net {
59 class URLRequestContextGetter; 59 class URLRequestContextGetter;
60 } 60 }
61 61
62 #if BUILDFLAG(ANDROID_JAVA_UI) 62 #if BUILDFLAG(ANDROID_JAVA_UI)
63 class WebappRegistry; 63 class WebappRegistry;
64 #endif 64 #endif
65 65
66 ////////////////////////////////////////////////////////////////////////////////
66 // BrowsingDataRemover is responsible for removing data related to browsing: 67 // BrowsingDataRemover is responsible for removing data related to browsing:
67 // visits in url database, downloads, cookies ... 68 // visits in url database, downloads, cookies ...
69 //
70 // USAGE:
71 //
72 // 0. Instantiation.
73 //
74 // BrowsingDataRemover remover =
75 // BrowsingDataRemoverFactory::GetForBrowserContext(profile);
76 //
77 // 1. No observer.
78 //
79 // remover->Remove(Unbounded(), REMOVE_COOKIES, ALL);
80 //
81 // 2. Using an observer.
Bernhard Bauer 2016/07/26 14:51:38 This doesn't really make it clear what the differe
msramek 2016/07/28 09:57:42 Expanded the descriptions a bit. "One-shot deletio
82 //
83 // class CookiesDeleter : public BrowsingDataRemover::Observer {
84 // CookiesDeleter() { remover->AddObserver(this); }
85 // ~CookiesDeleter() { remover->RemoveObserver(this); }
86 //
87 // void DeleteCookies() {
88 // remover->RemoveAndReply(Unbounded(), REMOVE_COOKIES, ALL, this);
89 // }
90 //
91 // void OnBrowsingDataRemoverDone() {
92 // LOG(INFO) << "Cookies were deleted.";
93 // }
94 // }
95 //
96 // 3. Observing the status of deletions.
97 //
98 // class BrowsingDataRemoverStatusObsever {
99 // BrowsingDataRemoverStatusObserver() { remover->AddObserver(this); }
100 // ~BrowsingDataRemoverStatusObserver() {
101 // remover->RemoveObserver(this);
102 // }
103 //
104 // void OnBrowsingDataRemoving(bool removing) {
105 // LOG(INFO) << "Remover is now " << (removing ? "busy" : "idle");
106 // }
107 // }
108 //
109 ////////////////////////////////////////////////////////////////////////////////
110
68 class BrowsingDataRemover : public KeyedService 111 class BrowsingDataRemover : public KeyedService
69 #if defined(ENABLE_PLUGINS) 112 #if defined(ENABLE_PLUGINS)
70 , public PepperFlashSettingsManager::Client 113 , public PepperFlashSettingsManager::Client
71 #endif 114 #endif
72 { 115 {
73 public: 116 public:
74 // Mask used for Remove. 117 // Mask used for Remove.
75 enum RemoveDataMask { 118 enum RemoveDataMask {
76 REMOVE_APPCACHE = 1 << 0, 119 REMOVE_APPCACHE = 1 << 0,
77 REMOVE_CACHE = 1 << 1, 120 REMOVE_CACHE = 1 << 1,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 189
147 struct TimeRange { 190 struct TimeRange {
148 TimeRange(base::Time begin, base::Time end) : begin(begin), end(end) {} 191 TimeRange(base::Time begin, base::Time end) : begin(begin), end(end) {}
149 bool operator==(const TimeRange& other) const; 192 bool operator==(const TimeRange& other) const;
150 193
151 base::Time begin; 194 base::Time begin;
152 base::Time end; 195 base::Time end;
153 }; 196 };
154 197
155 // Observer is notified when the removal is active and when it's done. 198 // Observer is notified when the removal is active and when it's done.
199 // TODO(msramek): The semantics of the two methods are slightly different;
200 // one is called for every observer at the same time, while the other only
201 // for one observer at a time. Consider splitting the interface.
Bernhard Bauer 2016/07/26 14:51:38 I have to agree: I do find it very weird to have t
msramek 2016/07/28 09:57:42 I strengthened the TODO, and I readded the depreca
156 class Observer { 202 class Observer {
157 public: 203 public:
158 // NOTE: DEPRECATED; talk to dbeam/msramek before using this.
159 //
160 // Whether removal is active. Note that not having an active removal is not 204 // Whether removal is active. Note that not having an active removal is not
161 // same as completing a removal. That is why the removing status is separate 205 // same as completing a removal. That is why the removing status is separate
162 // from the done message. 206 // from the done message.
163 virtual void OnBrowsingDataRemoving(bool is_removing) {} 207 virtual void OnBrowsingDataRemoving(bool is_removing) {}
164 208
165 // Done means keywords have been deleted, cache cleared and all other 209 // Called when a removal task is finished. Note that every removal task can
166 // removal tasks are scheduled. 210 // only have one observer attached to it, and only that one is called.
167 virtual void OnBrowsingDataRemoverDone() {} 211 virtual void OnBrowsingDataRemoverDone() {}
168 212
169 protected: 213 protected:
170 virtual ~Observer() {} 214 virtual ~Observer() {}
171 }; 215 };
172 216
173 // The completion inhibitor can artificially delay completion of the browsing 217 // The completion inhibitor can artificially delay completion of the browsing
174 // data removal process. It is used during testing to simulate scenarios in 218 // data removal process. It is used during testing to simulate scenarios in
175 // which the deletion stalls or takes a very long time. 219 // which the deletion stalls or takes a very long time.
176 class CompletionInhibitor { 220 class CompletionInhibitor {
177 public: 221 public:
178 // Invoked when a |remover| is just about to complete clearing browser data, 222 // Invoked when a |remover| is just about to complete clearing browser data,
179 // and will be prevented from completing until after the callback 223 // and will be prevented from completing until after the callback
180 // |continue_to_completion| is run. 224 // |continue_to_completion| is run.
181 virtual void OnBrowsingDataRemoverWouldComplete( 225 virtual void OnBrowsingDataRemoverWouldComplete(
182 BrowsingDataRemover* remover, 226 BrowsingDataRemover* remover,
183 const base::Closure& continue_to_completion) = 0; 227 const base::Closure& continue_to_completion) = 0;
184 228
185 protected: 229 protected:
186 virtual ~CompletionInhibitor() {} 230 virtual ~CompletionInhibitor() {}
187 }; 231 };
188 232
233 // Represents a single removal task. Contains all parameters needed to execute
234 // it and a pointer to the observer that added it.
235 struct RemovalTask {
Bernhard Bauer 2016/07/26 14:51:38 Does this need to be public?
msramek 2016/07/28 09:57:42 Nope. Done.
236 RemovalTask(const TimeRange& time_range,
237 int remove_mask,
238 int origin_type_mask,
239 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
240 Observer* observer);
241 ~RemovalTask();
242
243 // Move constructor and assignment operator so that RemovalTask can be used
244 // in a queue. Note that this class cannot be copied because of the
245 // contained unique_ptr.
246 RemovalTask(RemovalTask&& removalTask);
247 RemovalTask& operator=(RemovalTask&& removalTask);
248
249 TimeRange time_range;
250 int remove_mask;
251 int origin_type_mask;
252 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder;
253 Observer* observer;
254 };
255
189 static TimeRange Unbounded(); 256 static TimeRange Unbounded();
190 257
191 static TimeRange Period(browsing_data::TimePeriod period); 258 static TimeRange Period(browsing_data::TimePeriod period);
192 259
193 // Is the BrowsingDataRemover currently in the process of removing data? 260 // Is the BrowsingDataRemover currently in the process of removing data?
194 bool is_removing() { return is_removing_; } 261 bool is_removing() { return is_removing_; }
195 262
196 // Sets a CompletionInhibitor, which will be notified each time an instance is 263 // Sets a CompletionInhibitor, which will be notified each time an instance is
197 // about to complete a browsing data removal process, and will be able to 264 // about to complete a browsing data removal process, and will be able to
198 // artificially delay the completion. 265 // artificially delay the completion.
199 // TODO(crbug.com/483528): Make this non-static. 266 // TODO(crbug.com/483528): Make this non-static.
200 static void set_completion_inhibitor_for_testing( 267 static void set_completion_inhibitor_for_testing(
201 CompletionInhibitor* inhibitor) { 268 CompletionInhibitor* inhibitor) {
202 completion_inhibitor_ = inhibitor; 269 completion_inhibitor_ = inhibitor;
203 } 270 }
204 271
205 // Removes the specified items related to browsing for all origins that match 272 // Removes browsing data within the given |time_range|, with datatypes being
206 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). 273 // specified by |remove_mask| and origin types by |origin_type_mask|.
207 void Remove(const TimeRange& time_range, 274 void Remove(const TimeRange& time_range,
208 int remove_mask, 275 int remove_mask,
209 int origin_type_mask); 276 int origin_type_mask);
210 277
211 // Removes the specified items related to browsing for all origins that match 278 // A version of the above that in addition informs the |observer| when the
212 // the provided |origin_type_mask| (see BrowsingDataHelper::OriginTypeMask). 279 // removal task is finished.
213 // The |origin_filter| is used as a final filter for clearing operations. 280 void RemoveAndReply(const TimeRange& time_range,
281 int remove_mask,
282 int origin_type_mask,
283 Observer* observer);
284
285 // Like Remove(), but in case of URL-keyed only removes data whose URL match
286 // |filter_builder| (e.g. are on certain origin or domain).
214 // TODO(dmurph): Support all backends with filter (crbug.com/113621). 287 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
215 // DO NOT USE THIS METHOD UNLESS CALLER KNOWS WHAT THEY'RE DOING. NOT ALL 288 // DO NOT USE THIS METHOD UNLESS CALLER KNOWS WHAT THEY'RE DOING. NOT ALL
216 // BACKENDS ARE SUPPORTED YET, AND MORE DATA THAN EXPECTED COULD BE DELETED. 289 // BACKENDS ARE SUPPORTED YET, AND MORE DATA THAN EXPECTED COULD BE DELETED.
217 virtual void RemoveWithFilter(const TimeRange& time_range, 290 virtual void RemoveWithFilter(
218 int remove_mask, 291 const TimeRange& time_range,
219 int origin_type_mask, 292 int remove_mask,
220 const BrowsingDataFilterBuilder& origin_filter); 293 int origin_type_mask,
294 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder);
295
296 // A version of the above that in addition informs the |observer| when the
297 // removal task is finished.
298 virtual void RemoveWithFilterAndReply(
299 const TimeRange& time_range,
300 int remove_mask,
301 int origin_type_mask,
302 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
303 Observer* observer);
304
305 // Executes the next removal task. Called after the previous task was finished
306 // or directly from Remove() if the task queue was empty.
307 void RunNextTask();
221 308
222 void AddObserver(Observer* observer); 309 void AddObserver(Observer* observer);
223 void RemoveObserver(Observer* observer); 310 void RemoveObserver(Observer* observer);
224 311
225 // Used for testing. 312 // Used for testing.
226 void OverrideStoragePartitionForTesting( 313 void OverrideStoragePartitionForTesting(
227 content::StoragePartition* storage_partition); 314 content::StoragePartition* storage_partition);
228 315
229 #if BUILDFLAG(ANDROID_JAVA_UI) 316 #if BUILDFLAG(ANDROID_JAVA_UI)
230 void OverrideWebappRegistryForTesting( 317 void OverrideWebappRegistryForTesting(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // Removes the specified items related to browsing for a specific host. If the 387 // Removes the specified items related to browsing for a specific host. If the
301 // provided |remove_url| is empty, data is removed for all origins; otherwise, 388 // provided |remove_url| is empty, data is removed for all origins; otherwise,
302 // it is restricted by the origin filter origin (where implemented yet). The 389 // it is restricted by the origin filter origin (where implemented yet). The
303 // |origin_type_mask| parameter defines the set of origins from which data 390 // |origin_type_mask| parameter defines the set of origins from which data
304 // should be removed (protected, unprotected, or both). 391 // should be removed (protected, unprotected, or both).
305 // TODO(ttr314): Remove "(where implemented yet)" constraint above once 392 // TODO(ttr314): Remove "(where implemented yet)" constraint above once
306 // crbug.com/113621 is done. 393 // crbug.com/113621 is done.
307 // TODO(crbug.com/589586): Support all backends w/ origin filter. 394 // TODO(crbug.com/589586): Support all backends w/ origin filter.
308 void RemoveImpl(const TimeRange& time_range, 395 void RemoveImpl(const TimeRange& time_range,
309 int remove_mask, 396 int remove_mask,
310 const BrowsingDataFilterBuilder& origin_filter, 397 const BrowsingDataFilterBuilder& filter_builder,
311 int origin_type_mask); 398 int origin_type_mask);
312 399
313 // Notifies observers and transitions to the idle state. 400 // Notifies observers and transitions to the idle state.
314 void Notify(); 401 void Notify();
315 402
316 // Checks if we are all done, and if so, calls Notify(). 403 // Checks if we are all done, and if so, calls Notify().
317 void NotifyIfDone(); 404 void NotifyIfDone();
318 405
319 // Called when history deletion is done. 406 // Called when history deletion is done.
320 void OnHistoryDeletionDone(); 407 void OnHistoryDeletionDone();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 490
404 // Start time to delete from. 491 // Start time to delete from.
405 base::Time delete_begin_; 492 base::Time delete_begin_;
406 493
407 // End time to delete to. 494 // End time to delete to.
408 base::Time delete_end_; 495 base::Time delete_end_;
409 496
410 // True if Remove has been invoked. 497 // True if Remove has been invoked.
411 bool is_removing_; 498 bool is_removing_;
412 499
500 // Removal tasks to be processed.
501 std::queue<RemovalTask> task_queue_;
502
413 // If non-NULL, the |completion_inhibitor_| is notified each time an instance 503 // If non-NULL, the |completion_inhibitor_| is notified each time an instance
414 // is about to complete a browsing data removal process, and has the ability 504 // is about to complete a browsing data removal process, and has the ability
415 // to artificially delay completion. Used for testing. 505 // to artificially delay completion. Used for testing.
416 static CompletionInhibitor* completion_inhibitor_; 506 static CompletionInhibitor* completion_inhibitor_;
417 507
418 #if defined(ENABLE_PLUGINS) 508 #if defined(ENABLE_PLUGINS)
419 // Used to delete plugin data. 509 // Used to delete plugin data.
420 std::unique_ptr<content::PluginDataRemover> plugin_data_remover_; 510 std::unique_ptr<content::PluginDataRemover> plugin_data_remover_;
421 base::WaitableEventWatcher watcher_; 511 base::WaitableEventWatcher watcher_;
422 512
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 bool waiting_for_clear_webrtc_logs_ = false; 548 bool waiting_for_clear_webrtc_logs_ = false;
459 #endif 549 #endif
460 bool waiting_for_clear_auto_sign_in_ = false; 550 bool waiting_for_clear_auto_sign_in_ = false;
461 551
462 // The removal mask for the current removal operation. 552 // The removal mask for the current removal operation.
463 int remove_mask_ = 0; 553 int remove_mask_ = 0;
464 554
465 // From which types of origins should we remove data? 555 // From which types of origins should we remove data?
466 int origin_type_mask_ = 0; 556 int origin_type_mask_ = 0;
467 557
558 // Observers of the global state and individual tasks.
468 base::ObserverList<Observer, true> observer_list_; 559 base::ObserverList<Observer, true> observer_list_;
469 560
470 // Used if we need to clear history. 561 // Used if we need to clear history.
471 base::CancelableTaskTracker history_task_tracker_; 562 base::CancelableTaskTracker history_task_tracker_;
472 563
473 std::unique_ptr<TemplateURLService::Subscription> template_url_sub_; 564 std::unique_ptr<TemplateURLService::Subscription> template_url_sub_;
474 565
475 // We do not own this. 566 // We do not own this.
476 content::StoragePartition* storage_partition_for_testing_ = nullptr; 567 content::StoragePartition* storage_partition_for_testing_ = nullptr;
477 568
478 #if BUILDFLAG(ANDROID_JAVA_UI) 569 #if BUILDFLAG(ANDROID_JAVA_UI)
479 // WebappRegistry makes calls across the JNI. In unit tests, the Java side is 570 // WebappRegistry makes calls across the JNI. In unit tests, the Java side is
480 // not initialised, so the registry must be mocked out. 571 // not initialised, so the registry must be mocked out.
481 std::unique_ptr<WebappRegistry> webapp_registry_; 572 std::unique_ptr<WebappRegistry> webapp_registry_;
482 #endif 573 #endif
483 574
484 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; 575 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_;
485 576
486 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); 577 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover);
487 }; 578 };
488 579
489 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ 580 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698