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

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

Issue 10805015: Move browsing_data_helper files into a separate directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix chrome_frame build Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_BROWSING_DATA_REMOVER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_REMOVER_H_
7
8 #include <set>
9
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/observer_list.h"
13 #include "base/sequenced_task_runner_helpers.h"
14 #include "base/synchronization/waitable_event_watcher.h"
15 #include "base/time.h"
16 #include "chrome/browser/cancelable_request.h"
17 #include "chrome/browser/pepper_flash_settings_manager.h"
18 #include "chrome/browser/prefs/pref_member.h"
19 #include "content/public/browser/dom_storage_context.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "googleurl/src/gurl.h"
23 #include "webkit/dom_storage/dom_storage_context.h"
24 #include "webkit/quota/quota_types.h"
25
26 class ExtensionSpecialStoragePolicy;
27 class IOThread;
28 class Profile;
29
30 namespace content {
31 class PluginDataRemover;
32 }
33
34 namespace disk_cache {
35 class Backend;
36 }
37
38 namespace net {
39 class URLRequestContextGetter;
40 }
41
42 namespace quota {
43 class QuotaManager;
44 }
45
46 // BrowsingDataRemover is responsible for removing data related to browsing:
47 // visits in url database, downloads, cookies ...
48
49 class BrowsingDataRemover : public content::NotificationObserver,
50 public base::WaitableEventWatcher::Delegate,
51 public PepperFlashSettingsManager::Client {
52 public:
53 // Time period ranges available when doing browsing data removals.
54 enum TimePeriod {
55 LAST_HOUR = 0,
56 LAST_DAY,
57 LAST_WEEK,
58 FOUR_WEEKS,
59 EVERYTHING
60 };
61
62 // Mask used for Remove.
63 enum RemoveDataMask {
64 REMOVE_APPCACHE = 1 << 0,
65 REMOVE_CACHE = 1 << 1,
66 REMOVE_COOKIES = 1 << 2,
67 REMOVE_DOWNLOADS = 1 << 3,
68 REMOVE_FILE_SYSTEMS = 1 << 4,
69 REMOVE_FORM_DATA = 1 << 5,
70 // In addition to visits, REMOVE_HISTORY removes keywords and last session.
71 REMOVE_HISTORY = 1 << 6,
72 REMOVE_INDEXEDDB = 1 << 7,
73 REMOVE_LOCAL_STORAGE = 1 << 8,
74 REMOVE_PLUGIN_DATA = 1 << 9,
75 REMOVE_PASSWORDS = 1 << 10,
76 REMOVE_WEBSQL = 1 << 11,
77 REMOVE_SERVER_BOUND_CERTS = 1 << 12,
78 REMOVE_CONTENT_LICENSES = 1 << 13,
79
80 // "Site data" includes cookies, appcache, file systems, indexedDBs, local
81 // storage, webSQL, and plugin data.
82 REMOVE_SITE_DATA = REMOVE_APPCACHE | REMOVE_COOKIES | REMOVE_FILE_SYSTEMS |
83 REMOVE_INDEXEDDB | REMOVE_LOCAL_STORAGE |
84 REMOVE_PLUGIN_DATA | REMOVE_WEBSQL |
85 REMOVE_SERVER_BOUND_CERTS
86 };
87
88 // When BrowsingDataRemover successfully removes data, a notification of type
89 // NOTIFICATION_BROWSING_DATA_REMOVED is triggered with a Details object of
90 // this type.
91 struct NotificationDetails {
92 NotificationDetails();
93 NotificationDetails(const NotificationDetails& details);
94 NotificationDetails(base::Time removal_begin,
95 int removal_mask,
96 int origin_set_mask);
97 ~NotificationDetails();
98
99 // The beginning of the removal time range.
100 base::Time removal_begin;
101
102 // The removal mask (see the RemoveDataMask enum for details).
103 int removal_mask;
104
105 // The origin set mask (see BrowsingDataHelper::OriginSetMask for details).
106 int origin_set_mask;
107 };
108
109 // Observer is notified when the removal is done. Done means keywords have
110 // been deleted, cache cleared and all other tasks scheduled.
111 class Observer {
112 public:
113 virtual void OnBrowsingDataRemoverDone() = 0;
114
115 protected:
116 virtual ~Observer() {}
117 };
118
119 // Creates a BrowsingDataRemover to remove browser data from the specified
120 // profile in the specified time range. Use Remove to initiate the removal.
121 BrowsingDataRemover(Profile* profile, base::Time delete_begin,
122 base::Time delete_end);
123
124 // Creates a BrowsingDataRemover to remove browser data from the specified
125 // profile in the specified time range.
126 BrowsingDataRemover(Profile* profile, TimePeriod time_period,
127 base::Time delete_end);
128
129 // Removes the specified items related to browsing for all origins that match
130 // the provided |origin_set_mask| (see BrowsingDataHelper::OriginSetMask).
131 void Remove(int remove_mask, int origin_set_mask);
132
133 void AddObserver(Observer* observer);
134 void RemoveObserver(Observer* observer);
135
136 // Called when history deletion is done.
137 void OnHistoryDeletionDone();
138
139 // Quota managed data uses a different bitmask for types than
140 // BrowsingDataRemover uses. This method generates that mask.
141 static int GenerateQuotaClientMask(int remove_mask);
142
143 // Used for testing.
144 void OverrideQuotaManagerForTesting(quota::QuotaManager* quota_manager);
145
146 static bool is_removing() { return removing_; }
147
148 private:
149 // The clear API needs to be able to toggle removing_ in order to test that
150 // only one BrowsingDataRemover instance can be called at a time.
151 FRIEND_TEST_ALL_PREFIXES(ExtensionBrowsingDataTest, OneAtATime);
152
153 // The BrowsingDataRemover tests need to be able to access the implementation
154 // of Remove(), as it exposes details that aren't yet available in the public
155 // API. As soon as those details are exposed via new methods, this should be
156 // removed.
157 //
158 // TODO(mkwst): See http://crbug.com/113621
159 friend class BrowsingDataRemoverTest;
160
161 enum CacheState {
162 STATE_NONE,
163 STATE_CREATE_MAIN,
164 STATE_CREATE_MEDIA,
165 STATE_DELETE_MAIN,
166 STATE_DELETE_MEDIA,
167 STATE_DONE
168 };
169
170 // BrowsingDataRemover deletes itself (using DeleteHelper) and is not supposed
171 // to be deleted by other objects so make destructor private and DeleteHelper
172 // a friend.
173 friend class base::DeleteHelper<BrowsingDataRemover>;
174 virtual ~BrowsingDataRemover();
175
176 // content::NotificationObserver method. Callback when TemplateURLService has
177 // finished loading. Deletes the entries from the model, and if we're not
178 // waiting on anything else notifies observers and deletes this
179 // BrowsingDataRemover.
180 virtual void Observe(int type,
181 const content::NotificationSource& source,
182 const content::NotificationDetails& details) OVERRIDE;
183
184 // WaitableEventWatcher implementation.
185 // Called when plug-in data has been cleared. Invokes NotifyAndDeleteIfDone.
186 virtual void OnWaitableEventSignaled(
187 base::WaitableEvent* waitable_event) OVERRIDE;
188
189 // PepperFlashSettingsManager::Client implementation.
190 virtual void OnDeauthorizeContentLicensesCompleted(uint32 request_id,
191 bool success) OVERRIDE;
192
193 // Removes the specified items related to browsing for a specific host. If the
194 // provided |origin| is empty, data is removed for all origins. The
195 // |origin_set_mask| parameter defines the set of origins from which data
196 // should be removed (protected, unprotected, or both).
197 void RemoveImpl(int remove_mask,
198 const GURL& origin,
199 int origin_set_mask);
200
201 // If we're not waiting on anything, notifies observers and deletes this
202 // object.
203 void NotifyAndDeleteIfDone();
204
205 // Callback when the network history has been deleted. Invokes
206 // NotifyAndDeleteIfDone.
207 void ClearedNetworkHistory();
208
209 // Invoked on the IO thread to clear the HostCache, speculative data about
210 // subresources on visited sites, and initial navigation history.
211 void ClearNetworkingHistory(IOThread* io_thread);
212
213 // Callback when the cache has been deleted. Invokes NotifyAndDeleteIfDone.
214 void ClearedCache();
215
216 // Invoked on the IO thread to delete from the cache.
217 void ClearCacheOnIOThread();
218
219 // Performs the actual work to delete the cache.
220 void DoClearCache(int rv);
221
222 #if !defined(DISABLE_NACL)
223 // Callback for when the NaCl cache has been deleted. Invokes
224 // NotifyAndDeleteIfDone.
225 void ClearedNaClCache();
226
227 // Invokes the ClearedNaClCache on the UI thread.
228 void ClearedNaClCacheOnIOThread();
229
230 // Invoked on the IO thread to delete the NaCl cache.
231 void ClearNaClCacheOnIOThread();
232 #endif
233
234 // Invoked on the UI thread to delete local storage.
235 void ClearLocalStorageOnUIThread();
236
237 // Callback to deal with the list gathered in ClearLocalStorageOnUIThread.
238 void OnGotLocalStorageUsageInfo(
239 const std::vector<dom_storage::DomStorageContext::UsageInfo>& infos);
240
241 // Callback on deletion of local storage data. Invokes NotifyAndDeleteIfDone.
242 void OnLocalStorageCleared();
243
244 // Invoked on the IO thread to delete all storage types managed by the quota
245 // system: AppCache, Databases, FileSystems.
246 void ClearQuotaManagedDataOnIOThread();
247
248 // Callback to respond to QuotaManager::GetOriginsModifiedSince, which is the
249 // core of 'ClearQuotaManagedDataOnIOThread'.
250 void OnGotQuotaManagedOrigins(const std::set<GURL>& origins,
251 quota::StorageType type);
252
253 // Callback responding to deletion of a single quota managed origin's
254 // persistent data
255 void OnQuotaManagedOriginDeletion(const GURL& origin,
256 quota::StorageType type,
257 quota::QuotaStatusCode);
258
259 // Called to check whether all temporary and persistent origin data that
260 // should be deleted has been deleted. If everything's good to go, invokes
261 // OnQuotaManagedDataDeleted on the UI thread.
262 void CheckQuotaManagedDataDeletionStatus();
263
264 // Completion handler that runs on the UI thread once persistent data has been
265 // deleted. Updates the waiting flag and invokes NotifyAndDeleteIfDone.
266 void OnQuotaManagedDataDeleted();
267
268 // Callback when Cookies has been deleted. Invokes NotifyAndDeleteIfDone.
269 void OnClearedCookies(int num_deleted);
270
271 // Invoked on the IO thread to delete cookies.
272 void ClearCookiesOnIOThread(net::URLRequestContextGetter* rq_context);
273
274 // Invoked on the IO thread to delete server bound certs.
275 void ClearServerBoundCertsOnIOThread(
276 net::URLRequestContextGetter* rq_context);
277
278 // Callback when server bound certs have been deleted. Invokes
279 // NotifyAndDeleteIfDone.
280 void OnClearedServerBoundCerts();
281
282 // Calculate the begin time for the deletion range specified by |time_period|.
283 base::Time CalculateBeginDeleteTime(TimePeriod time_period);
284
285 // Returns true if we're all done.
286 bool AllDone();
287
288 // Setter for removing_; DCHECKs that we can only start removing if we're not
289 // already removing, and vice-versa.
290 static void set_removing(bool removing);
291
292 content::NotificationRegistrar registrar_;
293
294 // Profile we're to remove from.
295 Profile* profile_;
296
297 // The QuotaManager is owned by the profile; we can use a raw pointer here,
298 // and rely on the profile to destroy the object whenever it's reasonable.
299 quota::QuotaManager* quota_manager_;
300
301 // The DOMStorageContext is owned by the profile; we'll store a raw pointer.
302 content::DOMStorageContext* dom_storage_context_;
303
304 // 'Protected' origins are not subject to data removal.
305 scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_;
306
307 // Start time to delete from.
308 const base::Time delete_begin_;
309
310 // End time to delete to.
311 const base::Time delete_end_;
312
313 // True if Remove has been invoked.
314 static bool removing_;
315
316 CacheState next_cache_state_;
317 disk_cache::Backend* cache_;
318
319 // Used to delete data from HTTP cache.
320 scoped_refptr<net::URLRequestContextGetter> main_context_getter_;
321 scoped_refptr<net::URLRequestContextGetter> media_context_getter_;
322
323 // Used to delete plugin data.
324 scoped_ptr<content::PluginDataRemover> plugin_data_remover_;
325 base::WaitableEventWatcher watcher_;
326
327 // Used to deauthorize content licenses for Pepper Flash.
328 scoped_ptr<PepperFlashSettingsManager> pepper_flash_settings_manager_;
329 uint32 deauthorize_content_licenses_request_id_;
330
331 // True if we're waiting for various data to be deleted.
332 // These may only be accessed from UI thread in order to avoid races!
333 bool waiting_for_clear_cache_;
334 bool waiting_for_clear_nacl_cache_;
335 // Non-zero if waiting for cookies to be cleared.
336 int waiting_for_clear_cookies_count_;
337 bool waiting_for_clear_history_;
338 bool waiting_for_clear_local_storage_;
339 bool waiting_for_clear_networking_history_;
340 bool waiting_for_clear_server_bound_certs_;
341 bool waiting_for_clear_plugin_data_;
342 bool waiting_for_clear_quota_managed_data_;
343 bool waiting_for_clear_content_licenses_;
344
345 // Tracking how many origins need to be deleted, and whether we're finished
346 // gathering origins.
347 int quota_managed_origins_to_delete_count_;
348 int quota_managed_storage_types_to_delete_count_;
349
350 // The removal mask for the current removal operation.
351 int remove_mask_;
352
353 // The origin for the current removal operation.
354 GURL remove_origin_;
355
356 // From which types of origins should we remove data?
357 int origin_set_mask_;
358
359 ObserverList<Observer> observer_list_;
360
361 // Used if we need to clear history.
362 CancelableRequestConsumer request_consumer_;
363
364 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover);
365 };
366
367 #endif // CHROME_BROWSER_BROWSING_DATA_REMOVER_H_
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_quota_helper_unittest.cc ('k') | chrome/browser/browsing_data_remover.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698