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

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

Issue 2613833004: Split BrowsingDataRemover into an abstract interface and implementation. (Closed)
Patch Set: Removed unnecessary instantiations. 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_IMPL_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_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"
14 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 14 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h" 16 #include "base/observer_list.h"
18 #include "base/synchronization/waitable_event_watcher.h" 17 #include "base/synchronization/waitable_event_watcher.h"
19 #include "base/time/time.h" 18 #include "base/time/time.h"
20 #include "build/build_config.h" 19 #include "build/build_config.h"
21 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h" 20 #include "chrome/browser/browsing_data/browsing_data_remover.h"
22 #include "chrome/common/features.h" 21 #include "chrome/common/features.h"
23 #include "components/keyed_service/core/keyed_service.h" 22 #include "components/keyed_service/core/keyed_service.h"
24 #include "ppapi/features/features.h" 23 #include "ppapi/features/features.h"
25 #include "storage/common/quota/quota_types.h" 24 #include "storage/common/quota/quota_types.h"
26 #include "url/gurl.h" 25 #include "url/gurl.h"
27 26
28 class BrowsingDataFilterBuilder; 27 class BrowsingDataFilterBuilder;
29 class BrowsingDataFlashLSOHelper; 28 class BrowsingDataFlashLSOHelper;
30 class BrowsingDataRemoverFactory; 29 class BrowsingDataRemoverFactory;
31 30
32 namespace content { 31 namespace content {
33 class BrowserContext; 32 class BrowserContext;
34 class PluginDataRemover; 33 class PluginDataRemover;
35 class StoragePartition; 34 class StoragePartition;
36 } 35 }
37 36
38 //////////////////////////////////////////////////////////////////////////////// 37 class BrowsingDataRemoverImpl :
39 // BrowsingDataRemover is responsible for removing data related to browsing: 38 public BrowsingDataRemover,
40 // visits in url database, downloads, cookies ... 39 public KeyedService {
41 //
42 // USAGE:
43 //
44 // 0. Instantiation.
45 //
46 // BrowsingDataRemover remover =
47 // BrowsingDataRemoverFactory::GetForBrowserContext(browser_context);
48 //
49 // 1. No observer.
50 //
51 // remover->Remove(base::Time(), base::Time::Max(), REMOVE_COOKIES, ALL);
52 //
53 // 2. Using an observer to report when one's own removal task is finished.
54 //
55 // class CookiesDeleter : public BrowsingDataRemover::Observer {
56 // CookiesDeleter() { remover->AddObserver(this); }
57 // ~CookiesDeleter() { remover->RemoveObserver(this); }
58 //
59 // void DeleteCookies() {
60 // remover->RemoveAndReply(base::Time(), base::Time::Max(),
61 // REMOVE_COOKIES, ALL, this);
62 // }
63 //
64 // void OnBrowsingDataRemoverDone() {
65 // LOG(INFO) << "Cookies were deleted.";
66 // }
67 // }
68 //
69 ////////////////////////////////////////////////////////////////////////////////
70
71 class BrowsingDataRemover : public KeyedService {
72 public: 40 public:
73 // Mask used for Remove.
74 enum RemoveDataMask {
75 REMOVE_APPCACHE = 1 << 0,
76 REMOVE_CACHE = 1 << 1,
77 REMOVE_COOKIES = 1 << 2,
78 REMOVE_DOWNLOADS = 1 << 3,
79 REMOVE_FILE_SYSTEMS = 1 << 4,
80 REMOVE_FORM_DATA = 1 << 5,
81 // In addition to visits, REMOVE_HISTORY removes keywords, last session and
82 // passwords UI statistics.
83 REMOVE_HISTORY = 1 << 6,
84 REMOVE_INDEXEDDB = 1 << 7,
85 REMOVE_LOCAL_STORAGE = 1 << 8,
86 REMOVE_PLUGIN_DATA = 1 << 9,
87 REMOVE_PASSWORDS = 1 << 10,
88 REMOVE_WEBSQL = 1 << 11,
89 REMOVE_CHANNEL_IDS = 1 << 12,
90 REMOVE_MEDIA_LICENSES = 1 << 13,
91 REMOVE_SERVICE_WORKERS = 1 << 14,
92 REMOVE_SITE_USAGE_DATA = 1 << 15,
93 // REMOVE_NOCHECKS intentionally does not check if the browser context is
94 // prohibited from deleting history or downloads.
95 REMOVE_NOCHECKS = 1 << 16,
96 REMOVE_CACHE_STORAGE = 1 << 17,
97 #if BUILDFLAG(ANDROID_JAVA_UI)
98 REMOVE_WEBAPP_DATA = 1 << 18,
99 #endif
100 REMOVE_DURABLE_PERMISSION = 1 << 19,
101
102 // The following flag is used only in tests. In normal usage, hosted app
103 // data is controlled by the REMOVE_COOKIES flag, applied to the
104 // protected-web origin.
105 REMOVE_HOSTED_APP_DATA_TESTONLY = 1 << 31,
106
107 // "Site data" includes cookies, appcache, file systems, indexedDBs, local
108 // storage, webSQL, service workers, cache storage, plugin data, web app
109 // data (on Android) and statistics about passwords.
110 REMOVE_SITE_DATA = REMOVE_APPCACHE | REMOVE_COOKIES | REMOVE_FILE_SYSTEMS |
111 REMOVE_INDEXEDDB |
112 REMOVE_LOCAL_STORAGE |
113 REMOVE_PLUGIN_DATA |
114 REMOVE_SERVICE_WORKERS |
115 REMOVE_CACHE_STORAGE |
116 REMOVE_WEBSQL |
117 REMOVE_CHANNEL_IDS |
118 #if BUILDFLAG(ANDROID_JAVA_UI)
119 REMOVE_WEBAPP_DATA |
120 #endif
121 REMOVE_SITE_USAGE_DATA |
122 REMOVE_DURABLE_PERMISSION,
123
124 // Datatypes protected by Important Sites.
125 IMPORTANT_SITES_DATATYPES = REMOVE_SITE_DATA |
126 REMOVE_CACHE,
127
128 // Datatypes that can be deleted partially per URL / origin / domain,
129 // whichever makes sense.
130 FILTERABLE_DATATYPES = REMOVE_SITE_DATA |
131 REMOVE_CACHE |
132 REMOVE_DOWNLOADS,
133
134 // Includes all the available remove options. Meant to be used by clients
135 // that wish to wipe as much data as possible from a Profile, to make it
136 // look like a new Profile.
137 REMOVE_ALL = REMOVE_SITE_DATA | REMOVE_CACHE | REMOVE_DOWNLOADS |
138 REMOVE_FORM_DATA |
139 REMOVE_HISTORY |
140 REMOVE_PASSWORDS |
141 REMOVE_MEDIA_LICENSES,
142
143 // Includes all available remove options. Meant to be used when the Profile
144 // is scheduled to be deleted, and all possible data should be wiped from
145 // disk as soon as possible.
146 REMOVE_WIPE_PROFILE = REMOVE_ALL | REMOVE_NOCHECKS,
147 };
148
149 // Important sites protect a small set of sites from the deletion of certain
150 // datatypes. Therefore, those datatypes must be filterable by
151 // url/origin/domain.
152 static_assert(0 == (IMPORTANT_SITES_DATATYPES & ~FILTERABLE_DATATYPES),
153 "All important sites datatypes must be filterable.");
154
155 // A helper enum to report the deletion of cookies and/or cache. Do not
156 // reorder the entries, as this enum is passed to UMA.
157 enum CookieOrCacheDeletionChoice {
158 NEITHER_COOKIES_NOR_CACHE,
159 ONLY_COOKIES,
160 ONLY_CACHE,
161 BOTH_COOKIES_AND_CACHE,
162 MAX_CHOICE_VALUE
163 };
164
165 // Observer is notified when its own removal task is done.
166 class Observer {
167 public:
168 // Called when a removal task is finished. Note that every removal task can
169 // only have one observer attached to it, and only that one is called.
170 virtual void OnBrowsingDataRemoverDone() = 0;
171
172 protected:
173 virtual ~Observer() {}
174 };
175
176 // The completion inhibitor can artificially delay completion of the browsing 41 // The completion inhibitor can artificially delay completion of the browsing
177 // data removal process. It is used during testing to simulate scenarios in 42 // data removal process. It is used during testing to simulate scenarios in
178 // which the deletion stalls or takes a very long time. 43 // which the deletion stalls or takes a very long time.
179 class CompletionInhibitor { 44 class CompletionInhibitor {
180 public: 45 public:
181 // Invoked when a |remover| is just about to complete clearing browser data, 46 // Invoked when a |remover| is just about to complete clearing browser data,
182 // and will be prevented from completing until after the callback 47 // and will be prevented from completing until after the callback
183 // |continue_to_completion| is run. 48 // |continue_to_completion| is run.
184 virtual void OnBrowsingDataRemoverWouldComplete( 49 virtual void OnBrowsingDataRemoverWouldComplete(
185 BrowsingDataRemover* remover, 50 BrowsingDataRemoverImpl* remover,
186 const base::Closure& continue_to_completion) = 0; 51 const base::Closure& continue_to_completion) = 0;
187 52
188 protected: 53 protected:
189 virtual ~CompletionInhibitor() {} 54 virtual ~CompletionInhibitor() {}
190 }; 55 };
191 56
192 // Used to track the deletion of a single data storage backend. 57 // Used to track the deletion of a single data storage backend.
193 class SubTask { 58 class SubTask {
194 public: 59 public:
195 // Creates a SubTask that calls |forward_callback| when completed. 60 // Creates a SubTask that calls |forward_callback| when completed.
(...skipping 12 matching lines...) Expand all
208 bool is_pending() const { return is_pending_; } 73 bool is_pending() const { return is_pending_; }
209 74
210 private: 75 private:
211 void CompletionCallback(); 76 void CompletionCallback();
212 77
213 bool is_pending_; 78 bool is_pending_;
214 const base::Closure& forward_callback_; 79 const base::Closure& forward_callback_;
215 base::WeakPtrFactory<SubTask> weak_ptr_factory_; 80 base::WeakPtrFactory<SubTask> weak_ptr_factory_;
216 }; 81 };
217 82
218 // Is the BrowsingDataRemover currently in the process of removing data? 83 // Is the BrowsingDataRemoverImpl currently in the process of removing data?
219 bool is_removing() { return is_removing_; } 84 bool is_removing() { return is_removing_; }
220 85
221 // Sets a CompletionInhibitor, which will be notified each time an instance is 86 // Sets a CompletionInhibitor, which will be notified each time an instance is
222 // about to complete a browsing data removal process, and will be able to 87 // about to complete a browsing data removal process, and will be able to
223 // artificially delay the completion. 88 // artificially delay the completion.
224 // TODO(crbug.com/483528): Make this non-static. 89 // TODO(crbug.com/483528): Make this non-static.
225 static void set_completion_inhibitor_for_testing( 90 static void set_completion_inhibitor_for_testing(
226 CompletionInhibitor* inhibitor) { 91 CompletionInhibitor* inhibitor) {
227 completion_inhibitor_ = inhibitor; 92 completion_inhibitor_ = inhibitor;
228 } 93 }
229 94
230 // Called by the embedder to provide the delegate that will take care of 95 // BrowsingDataRemover implementation:
231 // deleting embedder-specific data. 96 void SetEmbedderDelegate(
232 void set_embedder_delegate( 97 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) override;
233 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) { 98 BrowsingDataRemoverDelegate* GetEmbedderDelegate() const override;
234 embedder_delegate_ = std::move(embedder_delegate);
235 }
236 99
237 BrowsingDataRemoverDelegate* get_embedder_delegate() const {
238 return embedder_delegate_.get();
239 }
240
241 // Removes browsing data within the given |time_range|, with datatypes being
242 // specified by |remove_mask| and origin types by |origin_type_mask|.
243 void Remove(const base::Time& delete_begin, 100 void Remove(const base::Time& delete_begin,
244 const base::Time& delete_end, 101 const base::Time& delete_end,
245 int remove_mask, 102 int remove_mask,
246 int origin_type_mask); 103 int origin_type_mask) override;
247
248 // A version of the above that in addition informs the |observer| when the
249 // removal task is finished.
250 void RemoveAndReply(const base::Time& delete_begin, 104 void RemoveAndReply(const base::Time& delete_begin,
251 const base::Time& delete_end, 105 const base::Time& delete_end,
252 int remove_mask, 106 int remove_mask,
253 int origin_type_mask, 107 int origin_type_mask,
254 Observer* observer); 108 Observer* observer) override;
255
256 // Like Remove(), but in case of URL-keyed only removes data whose URL match
257 // |filter_builder| (e.g. are on certain origin or domain).
258 // RemoveWithFilter() currently only works with FILTERABLE_DATATYPES.
259 void RemoveWithFilter( 109 void RemoveWithFilter(
260 const base::Time& delete_begin, 110 const base::Time& delete_begin,
261 const base::Time& delete_end, 111 const base::Time& delete_end,
262 int remove_mask, 112 int remove_mask,
263 int origin_type_mask, 113 int origin_type_mask,
264 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder); 114 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) override;
265
266 // A version of the above that in addition informs the |observer| when the
267 // removal task is finished.
268 void RemoveWithFilterAndReply( 115 void RemoveWithFilterAndReply(
269 const base::Time& delete_begin, 116 const base::Time& delete_begin,
270 const base::Time& delete_end, 117 const base::Time& delete_end,
271 int remove_mask, 118 int remove_mask,
272 int origin_type_mask, 119 int origin_type_mask,
273 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 120 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
274 Observer* observer); 121 Observer* observer) override;
275 122
276 void AddObserver(Observer* observer); 123 void AddObserver(Observer* observer) override;
277 void RemoveObserver(Observer* observer); 124 void RemoveObserver(Observer* observer) override;
125
126 const base::Time& GetLastUsedBeginTime() override;
127 const base::Time& GetLastUsedEndTime() override;
128 int GetLastUsedRemovalMask() override;
129 int GetLastUsedOriginTypeMask() override;
278 130
279 // Used for testing. 131 // Used for testing.
280 void OverrideStoragePartitionForTesting( 132 void OverrideStoragePartitionForTesting(
281 content::StoragePartition* storage_partition); 133 content::StoragePartition* storage_partition);
282 134
283 #if BUILDFLAG(ENABLE_PLUGINS) 135 #if BUILDFLAG(ENABLE_PLUGINS)
284 void OverrideFlashLSOHelperForTesting( 136 void OverrideFlashLSOHelperForTesting(
285 scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper); 137 scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper);
286 #endif 138 #endif
287 139
288 // Parameters of the last call are exposed to be used by tests. Removal and
289 // origin type masks equal to -1 mean that no removal has ever been executed.
290 // TODO(msramek): If other consumers than tests are interested in this,
291 // consider returning them in OnBrowsingDataRemoverDone() callback.
292 const base::Time& GetLastUsedBeginTime();
293 const base::Time& GetLastUsedEndTime();
294 int GetLastUsedRemovalMask();
295 int GetLastUsedOriginTypeMask();
296
297 protected: 140 protected:
298 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of 141 // Use BrowsingDataRemoverFactory::GetForBrowserContext to get an instance of
299 // this class. The constructor is protected so that the class is mockable. 142 // this class. The constructor is protected so that the class is mockable.
300 BrowsingDataRemover(content::BrowserContext* browser_context); 143 explicit BrowsingDataRemoverImpl(content::BrowserContext* browser_context);
301 ~BrowsingDataRemover() override; 144 ~BrowsingDataRemoverImpl() override;
302 145
303 // A common reduction of all public Remove[WithFilter][AndReply] methods. 146 // A common reduction of all public Remove[WithFilter][AndReply] methods.
304 virtual void RemoveInternal( 147 virtual void RemoveInternal(
305 const base::Time& delete_begin, 148 const base::Time& delete_begin,
306 const base::Time& delete_end, 149 const base::Time& delete_end,
307 int remove_mask, 150 int remove_mask,
308 int origin_type_mask, 151 int origin_type_mask,
309 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 152 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
310 Observer* observer); 153 Observer* observer);
311 154
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 // Counts the number of plugin data tasks. Should be the number of LSO cookies 283 // Counts the number of plugin data tasks. Should be the number of LSO cookies
441 // to be deleted, or 1 while we're fetching LSO cookies or deleting in bulk. 284 // to be deleted, or 1 while we're fetching LSO cookies or deleting in bulk.
442 int clear_plugin_data_count_ = 0; 285 int clear_plugin_data_count_ = 0;
443 286
444 // Observers of the global state and individual tasks. 287 // Observers of the global state and individual tasks.
445 base::ObserverList<Observer, true> observer_list_; 288 base::ObserverList<Observer, true> observer_list_;
446 289
447 // We do not own this. 290 // We do not own this.
448 content::StoragePartition* storage_partition_for_testing_ = nullptr; 291 content::StoragePartition* storage_partition_for_testing_ = nullptr;
449 292
450 base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; 293 base::WeakPtrFactory<BrowsingDataRemoverImpl> weak_ptr_factory_;
451 294
452 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); 295 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImpl);
453 }; 296 };
454 297
455 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_H_ 298 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698