OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_REMOVER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_REMOVER_H_ |
6 #define CHROME_BROWSER_BROWSING_DATA_REMOVER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_REMOVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/synchronization/waitable_event_watcher.h" | 13 #include "base/synchronization/waitable_event_watcher.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "content/browser/appcache/chrome_appcache_service.h" | 15 #include "content/browser/appcache/chrome_appcache_service.h" |
16 #include "content/browser/cancelable_request.h" | 16 #include "content/browser/cancelable_request.h" |
17 #include "content/common/notification_observer.h" | 17 #include "content/common/notification_observer.h" |
18 #include "content/common/notification_registrar.h" | 18 #include "content/common/notification_registrar.h" |
19 #include "webkit/quota/quota_types.h" | |
19 | 20 |
20 class ExtensionSpecialStoragePolicy; | 21 class ExtensionSpecialStoragePolicy; |
21 class IOThread; | 22 class IOThread; |
22 class PluginDataRemover; | 23 class PluginDataRemover; |
23 class Profile; | 24 class Profile; |
24 | 25 |
25 namespace disk_cache { | 26 namespace disk_cache { |
26 class Backend; | 27 class Backend; |
27 } | 28 } |
28 | 29 |
29 namespace net { | 30 namespace net { |
30 class URLRequestContextGetter; | 31 class URLRequestContextGetter; |
31 } | 32 } |
32 | 33 |
33 namespace webkit_database { | 34 namespace webkit_database { |
34 class DatabaseTracker; | 35 class DatabaseTracker; |
35 } | 36 } |
36 | 37 |
38 namespace quota { | |
39 class QuotaManager; | |
40 } | |
41 | |
37 // BrowsingDataRemover is responsible for removing data related to browsing: | 42 // BrowsingDataRemover is responsible for removing data related to browsing: |
38 // visits in url database, downloads, cookies ... | 43 // visits in url database, downloads, cookies ... |
39 | 44 |
40 class BrowsingDataRemover : public NotificationObserver, | 45 class BrowsingDataRemover : public NotificationObserver, |
41 public base::WaitableEventWatcher::Delegate { | 46 public base::WaitableEventWatcher::Delegate { |
42 public: | 47 public: |
43 // Time period ranges available when doing browsing data removals. | 48 // Time period ranges available when doing browsing data removals. |
44 enum TimePeriod { | 49 enum TimePeriod { |
45 LAST_HOUR = 0, | 50 LAST_HOUR = 0, |
46 LAST_DAY, | 51 LAST_DAY, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 void Remove(int remove_mask); | 90 void Remove(int remove_mask); |
86 | 91 |
87 void AddObserver(Observer* observer); | 92 void AddObserver(Observer* observer); |
88 void RemoveObserver(Observer* observer); | 93 void RemoveObserver(Observer* observer); |
89 | 94 |
90 // Called when history deletion is done. | 95 // Called when history deletion is done. |
91 void OnHistoryDeletionDone(); | 96 void OnHistoryDeletionDone(); |
92 | 97 |
93 static bool is_removing() { return removing_; } | 98 static bool is_removing() { return removing_; } |
94 | 99 |
95 // Removes the Gears plugin data. | |
96 static void ClearGearsData(const FilePath& profile_dir); | |
97 | |
98 private: | 100 private: |
99 enum CacheState { | 101 enum CacheState { |
100 STATE_NONE, | 102 STATE_NONE, |
101 STATE_CREATE_MAIN, | 103 STATE_CREATE_MAIN, |
102 STATE_CREATE_MEDIA, | 104 STATE_CREATE_MEDIA, |
103 STATE_DELETE_MAIN, | 105 STATE_DELETE_MAIN, |
104 STATE_DELETE_MEDIA, | 106 STATE_DELETE_MEDIA, |
105 STATE_DONE | 107 STATE_DONE |
106 }; | 108 }; |
107 | 109 |
(...skipping 28 matching lines...) Expand all Loading... | |
136 | 138 |
137 // Callback when the cache has been deleted. Invokes NotifyAndDeleteIfDone. | 139 // Callback when the cache has been deleted. Invokes NotifyAndDeleteIfDone. |
138 void ClearedCache(); | 140 void ClearedCache(); |
139 | 141 |
140 // Invoked on the IO thread to delete from the cache. | 142 // Invoked on the IO thread to delete from the cache. |
141 void ClearCacheOnIOThread(); | 143 void ClearCacheOnIOThread(); |
142 | 144 |
143 // Performs the actual work to delete the cache. | 145 // Performs the actual work to delete the cache. |
144 void DoClearCache(int rv); | 146 void DoClearCache(int rv); |
145 | 147 |
146 // Callback when HTML5 databases have been deleted. Invokes | 148 // Invoked on the IO thread to delete all storage types managed by the quota |
147 // NotifyAndDeleteIfDone. | 149 // system: AppCache, Databases, FileSystems. |
148 void OnClearedDatabases(int rv); | 150 void ClearQuotaManagedDataOnIOThread(); |
149 | 151 |
150 // Invoked on the FILE thread to delete HTML5 databases. | 152 // Callback to respond to QuotaManager::GetOriginsModifiedSince, which is the |
151 void ClearDatabasesOnFILEThread(); | 153 // core of 'ClearQuotaManagedDataOnIOThread'. |
154 void OnGotTemporaryQuotaManagedOrigins(const std::set<GURL>&); | |
152 | 155 |
153 // Callback when HTML5 file systems have been cleared. Invokes | 156 // Callback to respond to QuotaManager::GetOriginsModifiedSince, which is the |
154 // NotifyAndDeleteIfDone. | 157 // core of `ClearQuotaManagedDataOnIOThread` |
155 void OnClearedFileSystems(); | 158 void OnGotPersistentQuotaManagedOrigins(const std::set<GURL>&); |
156 | 159 |
157 // Invoked on the FILE thread to delete HTML5 file systems. | 160 // Callback responding to deletion of a single quota managed origin's |
158 void ClearFileSystemsOnFILEThread(); | 161 // persistent data |
162 void OnQuotaManagedOriginDeletion(quota::QuotaStatusCode); | |
159 | 163 |
160 // Callback when the appcache has been cleared. Invokes | 164 // Called to check whether all temporary and persistent origin data that |
161 // NotifyAndDeleteIfDone. | 165 // should be deleted has been deleted. If everything's good to go, invokes |
162 void OnClearedAppCache(); | 166 // NotifyAndDeleteIfDone on the UI thread. |
163 | 167 void CheckQuotaManagedDataDeletionStatus(); |
164 // Invoked on the IO thread to delete from the AppCache. | |
165 void ClearAppCacheOnIOThread(); | |
166 | |
167 // Lower level helpers. | |
168 void OnGotAppCacheInfo(int rv); | |
169 void OnAppCacheDeleted(int rv); | |
170 | |
171 // Callback when Gears data has been deleted. Invokes NotifyAndDeleteIfDone. | |
172 void OnClearedGearsData(); | |
173 | |
174 // Invoked on the FILE thread to delete old Gears data. | |
175 void ClearGearsDataOnFILEThread(const FilePath& profile_dir); | |
michaeln
2011/07/28 19:17:48
nice to see all this deleted code :)
| |
176 | 168 |
177 // Calculate the begin time for the deletion range specified by |time_period|. | 169 // Calculate the begin time for the deletion range specified by |time_period|. |
178 base::Time CalculateBeginDeleteTime(TimePeriod time_period); | 170 base::Time CalculateBeginDeleteTime(TimePeriod time_period); |
179 | 171 |
180 // Returns true if we're all done. | 172 // Returns true if we're all done. |
181 bool all_done() { | 173 bool all_done() { |
182 return registrar_.IsEmpty() && !waiting_for_clear_cache_ && | 174 return registrar_.IsEmpty() && !waiting_for_clear_cache_ && |
183 !waiting_for_clear_history_ && | 175 !waiting_for_clear_history_ && |
176 !waiting_for_clear_quota_managed_data_ && | |
184 !waiting_for_clear_networking_history_ && | 177 !waiting_for_clear_networking_history_ && |
185 !waiting_for_clear_databases_ && !waiting_for_clear_appcache_ && | 178 !waiting_for_clear_lso_data_; |
186 !waiting_for_clear_lso_data_ && !waiting_for_clear_gears_data_ && | |
187 !waiting_for_clear_file_systems_; | |
188 } | 179 } |
189 | 180 |
190 NotificationRegistrar registrar_; | 181 NotificationRegistrar registrar_; |
191 | 182 |
192 // Profile we're to remove from. | 183 // Profile we're to remove from. |
193 Profile* profile_; | 184 Profile* profile_; |
194 | 185 |
186 // the QuotaManager is owned by the profile; we can use a raw pointer here, | |
michaeln
2011/07/28 19:17:48
capital T in The
| |
187 // and rely on the profile to destroy the object whenever it's reasonable. | |
188 quota::QuotaManager* quota_manager_; | |
189 | |
195 // 'Protected' origins are not subject to data removal. | 190 // 'Protected' origins are not subject to data removal. |
196 scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_; | 191 scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_; |
197 | 192 |
198 // Start time to delete from. | 193 // Start time to delete from. |
199 const base::Time delete_begin_; | 194 const base::Time delete_begin_; |
200 | 195 |
201 // End time to delete to. | 196 // End time to delete to. |
202 const base::Time delete_end_; | 197 const base::Time delete_end_; |
203 | 198 |
204 // True if Remove has been invoked. | 199 // True if Remove has been invoked. |
205 static bool removing_; | 200 static bool removing_; |
206 | 201 |
207 // Reference to database tracker held while deleting databases. | 202 // Used to delete data from the HTTP caches. |
208 scoped_refptr<webkit_database::DatabaseTracker> database_tracker_; | |
209 | |
210 net::CompletionCallbackImpl<BrowsingDataRemover> database_cleared_callback_; | |
211 net::CompletionCallbackImpl<BrowsingDataRemover> cache_callback_; | 203 net::CompletionCallbackImpl<BrowsingDataRemover> cache_callback_; |
212 | |
213 // Used to clear the appcache. | |
214 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
215 net::CompletionCallbackImpl<BrowsingDataRemover> appcache_got_info_callback_; | |
216 net::CompletionCallbackImpl<BrowsingDataRemover> appcache_deleted_callback_; | |
217 scoped_refptr<appcache::AppCacheInfoCollection> appcache_info_; | |
218 int appcaches_to_be_deleted_count_; | |
219 | |
220 // Used to delete data from the HTTP caches. | |
221 CacheState next_cache_state_; | 204 CacheState next_cache_state_; |
222 disk_cache::Backend* cache_; | 205 disk_cache::Backend* cache_; |
223 | 206 |
224 // Used to delete data from HTTP cache and appcache. | 207 // Used to delete data from HTTP cache. |
225 scoped_refptr<net::URLRequestContextGetter> main_context_getter_; | 208 scoped_refptr<net::URLRequestContextGetter> main_context_getter_; |
226 scoped_refptr<net::URLRequestContextGetter> media_context_getter_; | 209 scoped_refptr<net::URLRequestContextGetter> media_context_getter_; |
227 | 210 |
228 // Used to delete plugin data. | 211 // Used to delete plugin data. |
229 scoped_refptr<PluginDataRemover> plugin_data_remover_; | 212 scoped_refptr<PluginDataRemover> plugin_data_remover_; |
230 base::WaitableEventWatcher watcher_; | 213 base::WaitableEventWatcher watcher_; |
231 | 214 |
232 // True if we're waiting for various data to be deleted. | 215 // True if we're waiting for various data to be deleted. |
233 bool waiting_for_clear_databases_; | |
234 bool waiting_for_clear_history_; | 216 bool waiting_for_clear_history_; |
217 bool waiting_for_clear_quota_managed_data_; | |
235 bool waiting_for_clear_networking_history_; | 218 bool waiting_for_clear_networking_history_; |
236 bool waiting_for_clear_cache_; | 219 bool waiting_for_clear_cache_; |
237 bool waiting_for_clear_appcache_; | |
238 bool waiting_for_clear_lso_data_; | 220 bool waiting_for_clear_lso_data_; |
239 bool waiting_for_clear_gears_data_; | 221 |
240 bool waiting_for_clear_file_systems_; | 222 // Tracking how many origins need to be deleted, and whether we're finished |
223 // gathering origins. | |
224 int quota_managed_origins_to_delete_count_; | |
225 bool waiting_for_persistent_quota_managed_origin_list_; | |
226 bool waiting_for_temporary_quota_managed_origin_list_; | |
241 | 227 |
242 ObserverList<Observer> observer_list_; | 228 ObserverList<Observer> observer_list_; |
243 | 229 |
244 // Used if we need to clear history. | 230 // Used if we need to clear history. |
245 CancelableRequestConsumer request_consumer_; | 231 CancelableRequestConsumer request_consumer_; |
246 | 232 |
247 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); | 233 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); |
248 }; | 234 }; |
249 | 235 |
250 #endif // CHROME_BROWSER_BROWSING_DATA_REMOVER_H_ | 236 #endif // CHROME_BROWSER_BROWSING_DATA_REMOVER_H_ |
OLD | NEW |