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

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

Issue 2578723002: Reduce BrowsingDataRemover's dependencies on Chrome (Closed)
Patch Set: A new callsite appeared through rebase - fixed the compilation error. Created 3 years, 11 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 <queue> 10 #include <queue>
11 #include <set> 11 #include <set>
12 12
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "base/synchronization/waitable_event_watcher.h" 18 #include "base/synchronization/waitable_event_watcher.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h" 21 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h"
22 #include "chrome/common/features.h" 22 #include "chrome/common/features.h"
23 #include "components/browsing_data/core/browsing_data_utils.h"
24 #include "components/keyed_service/core/keyed_service.h" 23 #include "components/keyed_service/core/keyed_service.h"
25 #include "ppapi/features/features.h" 24 #include "ppapi/features/features.h"
26 #include "storage/common/quota/quota_types.h" 25 #include "storage/common/quota/quota_types.h"
27 #include "url/gurl.h" 26 #include "url/gurl.h"
28 27
29 class BrowsingDataFilterBuilder; 28 class BrowsingDataFilterBuilder;
30 class BrowsingDataFlashLSOHelper; 29 class BrowsingDataFlashLSOHelper;
31 class BrowsingDataRemoverFactory; 30 class BrowsingDataRemoverFactory;
32 class Profile;
33 31
34 namespace content { 32 namespace content {
35 class BrowserContext; 33 class BrowserContext;
36 class PluginDataRemover; 34 class PluginDataRemover;
37 class StoragePartition; 35 class StoragePartition;
38 } 36 }
39 37
40 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
41 // BrowsingDataRemover is responsible for removing data related to browsing: 39 // BrowsingDataRemover is responsible for removing data related to browsing:
42 // visits in url database, downloads, cookies ... 40 // visits in url database, downloads, cookies ...
43 // 41 //
44 // USAGE: 42 // USAGE:
45 // 43 //
46 // 0. Instantiation. 44 // 0. Instantiation.
47 // 45 //
48 // BrowsingDataRemover remover = 46 // BrowsingDataRemover remover =
49 // BrowsingDataRemoverFactory::GetForBrowserContext(profile); 47 // BrowsingDataRemoverFactory::GetForBrowserContext(browser_context);
50 // 48 //
51 // 1. No observer. 49 // 1. No observer.
52 // 50 //
53 // remover->Remove(Unbounded(), REMOVE_COOKIES, ALL); 51 // remover->Remove(base::Time(), base::Time::Max(), REMOVE_COOKIES, ALL);
54 // 52 //
55 // 2. Using an observer to report when one's own removal task is finished. 53 // 2. Using an observer to report when one's own removal task is finished.
56 // 54 //
57 // class CookiesDeleter : public BrowsingDataRemover::Observer { 55 // class CookiesDeleter : public BrowsingDataRemover::Observer {
58 // CookiesDeleter() { remover->AddObserver(this); } 56 // CookiesDeleter() { remover->AddObserver(this); }
59 // ~CookiesDeleter() { remover->RemoveObserver(this); } 57 // ~CookiesDeleter() { remover->RemoveObserver(this); }
60 // 58 //
61 // void DeleteCookies() { 59 // void DeleteCookies() {
62 // remover->RemoveAndReply(Unbounded(), REMOVE_COOKIES, ALL, this); 60 // remover->RemoveAndReply(base::Time(), base::Time::Max(),
61 // REMOVE_COOKIES, ALL, this);
63 // } 62 // }
64 // 63 //
65 // void OnBrowsingDataRemoverDone() { 64 // void OnBrowsingDataRemoverDone() {
66 // LOG(INFO) << "Cookies were deleted."; 65 // LOG(INFO) << "Cookies were deleted.";
67 // } 66 // }
68 // } 67 // }
69 // 68 //
70 //////////////////////////////////////////////////////////////////////////////// 69 ////////////////////////////////////////////////////////////////////////////////
71 70
72 class BrowsingDataRemover : public KeyedService { 71 class BrowsingDataRemover : public KeyedService {
(...skipping 11 matching lines...) Expand all
84 REMOVE_HISTORY = 1 << 6, 83 REMOVE_HISTORY = 1 << 6,
85 REMOVE_INDEXEDDB = 1 << 7, 84 REMOVE_INDEXEDDB = 1 << 7,
86 REMOVE_LOCAL_STORAGE = 1 << 8, 85 REMOVE_LOCAL_STORAGE = 1 << 8,
87 REMOVE_PLUGIN_DATA = 1 << 9, 86 REMOVE_PLUGIN_DATA = 1 << 9,
88 REMOVE_PASSWORDS = 1 << 10, 87 REMOVE_PASSWORDS = 1 << 10,
89 REMOVE_WEBSQL = 1 << 11, 88 REMOVE_WEBSQL = 1 << 11,
90 REMOVE_CHANNEL_IDS = 1 << 12, 89 REMOVE_CHANNEL_IDS = 1 << 12,
91 REMOVE_MEDIA_LICENSES = 1 << 13, 90 REMOVE_MEDIA_LICENSES = 1 << 13,
92 REMOVE_SERVICE_WORKERS = 1 << 14, 91 REMOVE_SERVICE_WORKERS = 1 << 14,
93 REMOVE_SITE_USAGE_DATA = 1 << 15, 92 REMOVE_SITE_USAGE_DATA = 1 << 15,
94 // REMOVE_NOCHECKS intentionally does not check if the Profile's prohibited 93 // REMOVE_NOCHECKS intentionally does not check if the browser context is
95 // from deleting history or downloads. 94 // prohibited from deleting history or downloads.
96 REMOVE_NOCHECKS = 1 << 16, 95 REMOVE_NOCHECKS = 1 << 16,
97 REMOVE_CACHE_STORAGE = 1 << 17, 96 REMOVE_CACHE_STORAGE = 1 << 17,
98 #if BUILDFLAG(ANDROID_JAVA_UI) 97 #if BUILDFLAG(ANDROID_JAVA_UI)
99 REMOVE_WEBAPP_DATA = 1 << 18, 98 REMOVE_WEBAPP_DATA = 1 << 18,
100 #endif 99 #endif
101 REMOVE_DURABLE_PERMISSION = 1 << 19, 100 REMOVE_DURABLE_PERMISSION = 1 << 19,
102 101
103 // The following flag is used only in tests. In normal usage, hosted app 102 // The following flag is used only in tests. In normal usage, hosted app
104 // data is controlled by the REMOVE_COOKIES flag, applied to the 103 // data is controlled by the REMOVE_COOKIES flag, applied to the
105 // protected-web origin. 104 // protected-web origin.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // A helper enum to report the deletion of cookies and/or cache. Do not 155 // A helper enum to report the deletion of cookies and/or cache. Do not
157 // reorder the entries, as this enum is passed to UMA. 156 // reorder the entries, as this enum is passed to UMA.
158 enum CookieOrCacheDeletionChoice { 157 enum CookieOrCacheDeletionChoice {
159 NEITHER_COOKIES_NOR_CACHE, 158 NEITHER_COOKIES_NOR_CACHE,
160 ONLY_COOKIES, 159 ONLY_COOKIES,
161 ONLY_CACHE, 160 ONLY_CACHE,
162 BOTH_COOKIES_AND_CACHE, 161 BOTH_COOKIES_AND_CACHE,
163 MAX_CHOICE_VALUE 162 MAX_CHOICE_VALUE
164 }; 163 };
165 164
166 struct TimeRange {
167 TimeRange(base::Time begin, base::Time end) : begin(begin), end(end) {}
168 bool operator==(const TimeRange& other) const;
169
170 base::Time begin;
171 base::Time end;
172 };
173
174 // Observer is notified when its own removal task is done. 165 // Observer is notified when its own removal task is done.
175 class Observer { 166 class Observer {
176 public: 167 public:
177 // Called when a removal task is finished. Note that every removal task can 168 // Called when a removal task is finished. Note that every removal task can
178 // only have one observer attached to it, and only that one is called. 169 // only have one observer attached to it, and only that one is called.
179 virtual void OnBrowsingDataRemoverDone() = 0; 170 virtual void OnBrowsingDataRemoverDone() = 0;
180 171
181 protected: 172 protected:
182 virtual ~Observer() {} 173 virtual ~Observer() {}
183 }; 174 };
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 bool is_pending() const { return is_pending_; } 208 bool is_pending() const { return is_pending_; }
218 209
219 private: 210 private:
220 void CompletionCallback(); 211 void CompletionCallback();
221 212
222 bool is_pending_; 213 bool is_pending_;
223 const base::Closure& forward_callback_; 214 const base::Closure& forward_callback_;
224 base::WeakPtrFactory<SubTask> weak_ptr_factory_; 215 base::WeakPtrFactory<SubTask> weak_ptr_factory_;
225 }; 216 };
226 217
227 static TimeRange Unbounded();
228
229 static TimeRange Period(browsing_data::TimePeriod period);
230
231 // Is the BrowsingDataRemover currently in the process of removing data? 218 // Is the BrowsingDataRemover currently in the process of removing data?
232 bool is_removing() { return is_removing_; } 219 bool is_removing() { return is_removing_; }
233 220
234 // Sets a CompletionInhibitor, which will be notified each time an instance is 221 // Sets a CompletionInhibitor, which will be notified each time an instance is
235 // about to complete a browsing data removal process, and will be able to 222 // about to complete a browsing data removal process, and will be able to
236 // artificially delay the completion. 223 // artificially delay the completion.
237 // TODO(crbug.com/483528): Make this non-static. 224 // TODO(crbug.com/483528): Make this non-static.
238 static void set_completion_inhibitor_for_testing( 225 static void set_completion_inhibitor_for_testing(
239 CompletionInhibitor* inhibitor) { 226 CompletionInhibitor* inhibitor) {
240 completion_inhibitor_ = inhibitor; 227 completion_inhibitor_ = inhibitor;
241 } 228 }
242 229
243 // Called by the embedder to provide the delegate that will take care of 230 // Called by the embedder to provide the delegate that will take care of
244 // deleting embedder-specific data. 231 // deleting embedder-specific data.
245 void set_embedder_delegate( 232 void set_embedder_delegate(
246 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) { 233 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) {
247 embedder_delegate_ = std::move(embedder_delegate); 234 embedder_delegate_ = std::move(embedder_delegate);
248 } 235 }
249 236
250 BrowsingDataRemoverDelegate* get_embedder_delegate() const { 237 BrowsingDataRemoverDelegate* get_embedder_delegate() const {
251 return embedder_delegate_.get(); 238 return embedder_delegate_.get();
252 } 239 }
253 240
254 // Removes browsing data within the given |time_range|, with datatypes being 241 // Removes browsing data within the given |time_range|, with datatypes being
255 // specified by |remove_mask| and origin types by |origin_type_mask|. 242 // specified by |remove_mask| and origin types by |origin_type_mask|.
256 void Remove(const TimeRange& time_range, 243 void Remove(const base::Time& delete_begin,
244 const base::Time& delete_end,
257 int remove_mask, 245 int remove_mask,
258 int origin_type_mask); 246 int origin_type_mask);
259 247
260 // A version of the above that in addition informs the |observer| when the 248 // A version of the above that in addition informs the |observer| when the
261 // removal task is finished. 249 // removal task is finished.
262 void RemoveAndReply(const TimeRange& time_range, 250 void RemoveAndReply(const base::Time& delete_begin,
251 const base::Time& delete_end,
263 int remove_mask, 252 int remove_mask,
264 int origin_type_mask, 253 int origin_type_mask,
265 Observer* observer); 254 Observer* observer);
266 255
267 // Like Remove(), but in case of URL-keyed only removes data whose URL match 256 // Like Remove(), but in case of URL-keyed only removes data whose URL match
268 // |filter_builder| (e.g. are on certain origin or domain). 257 // |filter_builder| (e.g. are on certain origin or domain).
269 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES. 258 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES.
270 void RemoveWithFilter( 259 void RemoveWithFilter(
271 const TimeRange& time_range, 260 const base::Time& delete_begin,
261 const base::Time& delete_end,
272 int remove_mask, 262 int remove_mask,
273 int origin_type_mask, 263 int origin_type_mask,
274 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder); 264 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder);
275 265
276 // A version of the above that in addition informs the |observer| when the 266 // A version of the above that in addition informs the |observer| when the
277 // removal task is finished. 267 // removal task is finished.
278 void RemoveWithFilterAndReply( 268 void RemoveWithFilterAndReply(
279 const TimeRange& time_range, 269 const base::Time& delete_begin,
270 const base::Time& delete_end,
280 int remove_mask, 271 int remove_mask,
281 int origin_type_mask, 272 int origin_type_mask,
282 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 273 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
283 Observer* observer); 274 Observer* observer);
284 275
285 void AddObserver(Observer* observer); 276 void AddObserver(Observer* observer);
286 void RemoveObserver(Observer* observer); 277 void RemoveObserver(Observer* observer);
287 278
288 // Used for testing. 279 // Used for testing.
289 void OverrideStoragePartitionForTesting( 280 void OverrideStoragePartitionForTesting(
(...skipping 14 matching lines...) Expand all
304 int GetLastUsedOriginTypeMask(); 295 int GetLastUsedOriginTypeMask();
305 296
306 protected: 297 protected:
307 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of 298 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of
308 // this class. The constructor is protected so that the class is mockable. 299 // this class. The constructor is protected so that the class is mockable.
309 BrowsingDataRemover(content::BrowserContext* browser_context); 300 BrowsingDataRemover(content::BrowserContext* browser_context);
310 ~BrowsingDataRemover() override; 301 ~BrowsingDataRemover() override;
311 302
312 // A common reduction of all public Remove[WithFilter][AndReply] methods. 303 // A common reduction of all public Remove[WithFilter][AndReply] methods.
313 virtual void RemoveInternal( 304 virtual void RemoveInternal(
314 const TimeRange& time_range, 305 const base::Time& delete_begin,
306 const base::Time& delete_end,
315 int remove_mask, 307 int remove_mask,
316 int origin_type_mask, 308 int origin_type_mask,
317 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 309 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
318 Observer* observer); 310 Observer* observer);
319 311
320 private: 312 private:
321 // Testing the private RemovalTask. 313 // Testing the private RemovalTask.
322 FRIEND_TEST_ALL_PREFIXES(BrowsingDataRemoverTest, MultipleTasks); 314 FRIEND_TEST_ALL_PREFIXES(BrowsingDataRemoverTest, MultipleTasks);
323 315
324 // The BrowsingDataRemover tests need to be able to access the implementation 316 // The BrowsingDataRemover tests need to be able to access the implementation
325 // of Remove(), as it exposes details that aren't yet available in the public 317 // of Remove(), as it exposes details that aren't yet available in the public
326 // API. As soon as those details are exposed via new methods, this should be 318 // API. As soon as those details are exposed via new methods, this should be
327 // removed. 319 // removed.
328 // 320 //
329 // TODO(mkwst): See http://crbug.com/113621 321 // TODO(mkwst): See http://crbug.com/113621
330 friend class BrowsingDataRemoverTest; 322 friend class BrowsingDataRemoverTest;
331 323
332 friend class BrowsingDataRemoverFactory; 324 friend class BrowsingDataRemoverFactory;
333 325
334 // Represents a single removal task. Contains all parameters needed to execute 326 // Represents a single removal task. Contains all parameters needed to execute
335 // it and a pointer to the observer that added it. 327 // it and a pointer to the observer that added it.
336 struct RemovalTask { 328 struct RemovalTask {
337 RemovalTask(const TimeRange& time_range, 329 RemovalTask(const base::Time& delete_begin,
330 const base::Time& delete_end,
338 int remove_mask, 331 int remove_mask,
339 int origin_type_mask, 332 int origin_type_mask,
340 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 333 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
341 Observer* observer); 334 Observer* observer);
342 ~RemovalTask(); 335 ~RemovalTask();
343 336
344 TimeRange time_range; 337 base::Time delete_begin;
338 base::Time delete_end;
345 int remove_mask; 339 int remove_mask;
346 int origin_type_mask; 340 int origin_type_mask;
347 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder; 341 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder;
348 Observer* observer; 342 Observer* observer;
349 }; 343 };
350 344
351 void Shutdown() override; 345 void Shutdown() override;
352 346
353 // Setter for |is_removing_|; DCHECKs that we can only start removing if we're 347 // Setter for |is_removing_|; DCHECKs that we can only start removing if we're
354 // not already removing, and vice-versa. 348 // not already removing, and vice-versa.
(...skipping 17 matching lines...) Expand all
372 void RunNextTask(); 366 void RunNextTask();
373 367
374 // Removes the specified items related to browsing for a specific host. If the 368 // Removes the specified items related to browsing for a specific host. If the
375 // provided |remove_url| is empty, data is removed for all origins; otherwise, 369 // provided |remove_url| is empty, data is removed for all origins; otherwise,
376 // it is restricted by the origin filter origin (where implemented yet). The 370 // it is restricted by the origin filter origin (where implemented yet). The
377 // |origin_type_mask| parameter defines the set of origins from which data 371 // |origin_type_mask| parameter defines the set of origins from which data
378 // should be removed (protected, unprotected, or both). 372 // should be removed (protected, unprotected, or both).
379 // TODO(ttr314): Remove "(where implemented yet)" constraint above once 373 // TODO(ttr314): Remove "(where implemented yet)" constraint above once
380 // crbug.com/113621 is done. 374 // crbug.com/113621 is done.
381 // TODO(crbug.com/589586): Support all backends w/ origin filter. 375 // TODO(crbug.com/589586): Support all backends w/ origin filter.
382 void RemoveImpl(const TimeRange& time_range, 376 void RemoveImpl(const base::Time& delete_begin,
377 const base::Time& delete_end,
383 int remove_mask, 378 int remove_mask,
384 const BrowsingDataFilterBuilder& filter_builder, 379 const BrowsingDataFilterBuilder& filter_builder,
385 int origin_type_mask); 380 int origin_type_mask);
386 381
387 // Notifies observers and transitions to the idle state. 382 // Notifies observers and transitions to the idle state.
388 void Notify(); 383 void Notify();
389 384
390 // Checks if we are all done, and if so, calls Notify(). 385 // Checks if we are all done, and if so, calls Notify().
391 void NotifyIfDone(); 386 void NotifyIfDone();
392 387
393 // Returns true if we're all done. 388 // Returns true if we're all done.
394 bool AllDone(); 389 bool AllDone();
395 390
396 // Profile we're to remove from. 391 // The browser context we're to remove from.
397 Profile* profile_; 392 content::BrowserContext* browser_context_;
398 393
399 // A delegate to delete the embedder-specific data. 394 // A delegate to delete the embedder-specific data.
400 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate_; 395 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate_;
401 396
402 // Start time to delete from. 397 // Start time to delete from.
403 base::Time delete_begin_; 398 base::Time delete_begin_;
404 399
405 // End time to delete to. 400 // End time to delete to.
406 base::Time delete_end_; 401 base::Time delete_end_;
407 402
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 446
452 // We do not own this. 447 // We do not own this.
453 content::StoragePartition* storage_partition_for_testing_ = nullptr; 448 content::StoragePartition* storage_partition_for_testing_ = nullptr;
454 449
455 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; 450 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_;
456 451
457 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); 452 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover);
458 }; 453 };
459 454
460 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ 455 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/signin/signin_manager_android.cc ('k') | chrome/browser/browsing_data/browsing_data_remover.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698