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

Side by Side Diff: content/browser/storage_partition_impl.cc

Issue 11362268: Implement the ability to obliterate a storage partition from disk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: source control is hard, let's go shopping! Created 8 years, 1 month 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
« no previous file with comments | « content/browser/storage_partition_impl.h ('k') | content/browser/storage_partition_impl_map.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "content/browser/storage_partition_impl.h" 5 #include "content/browser/storage_partition_impl.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "content/browser/fileapi/browser_file_system_helper.h" 8 #include "content/browser/fileapi/browser_file_system_helper.h"
9 #include "content/public/browser/dom_storage_context.h"
9 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/indexed_db_context.h" 12 #include "content/public/browser/indexed_db_context.h"
12 #include "net/base/completion_callback.h" 13 #include "net/base/completion_callback.h"
13 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
14 #include "net/cookies/cookie_monster.h" 15 #include "net/cookies/cookie_monster.h"
15 #include "net/url_request/url_request_context_getter.h" 16 #include "net/url_request/url_request_context_getter.h"
16 #include "net/url_request/url_request_context.h" 17 #include "net/url_request/url_request_context.h"
18 #include "webkit/dom_storage/dom_storage_types.h"
17 #include "webkit/database/database_tracker.h" 19 #include "webkit/database/database_tracker.h"
18 #include "webkit/database/database_util.h"
19 #include "webkit/quota/quota_manager.h" 20 #include "webkit/quota/quota_manager.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 namespace { 24 namespace {
24 25
25 void ClearDataOnIOThread( 26 void DoNothingStatusCallback(quota::QuotaStatusCode status) {
27 // Do nothing.
28 }
29
30 void ClearQuotaManagedOriginsOnIOThread(
31 const scoped_refptr<quota::QuotaManager>& quota_manager,
32 const std::set<GURL>& origins,
33 quota::StorageType type) {
34 // The QuotaManager manages all storage other than cookies, LocalStorage,
35 // and SessionStorage. This loop wipes out most HTML5 storage for the given
36 // origins.
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
38 std::set<GURL>::const_iterator origin;
39 for (std::set<GURL>::const_iterator origin = origins.begin();
40 origin != origins.end(); ++origin) {
41 quota_manager->DeleteOriginData(*origin, type,
42 quota::QuotaClient::kAllClientsMask,
43 base::Bind(&DoNothingStatusCallback));
44 }
45 }
46
47 void ClearOriginOnIOThread(
26 const GURL& storage_origin, 48 const GURL& storage_origin,
27 const scoped_refptr<net::URLRequestContextGetter>& request_context, 49 const scoped_refptr<net::URLRequestContextGetter>& request_context,
28 const scoped_refptr<ChromeAppCacheService>& appcache_service) { 50 const scoped_refptr<quota::QuotaManager>& quota_manager) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
30 52
31 // Handle the cookies. 53 // Handle the cookies.
32 net::CookieMonster* cookie_monster = 54 net::CookieMonster* cookie_monster =
33 request_context->GetURLRequestContext()->cookie_store()-> 55 request_context->GetURLRequestContext()->cookie_store()->
34 GetCookieMonster(); 56 GetCookieMonster();
35 if (cookie_monster) 57 if (cookie_monster)
36 cookie_monster->DeleteAllForHostAsync( 58 cookie_monster->DeleteAllForHostAsync(
37 storage_origin, net::CookieMonster::DeleteCallback()); 59 storage_origin, net::CookieMonster::DeleteCallback());
38 60
39 // Clear out appcache. 61 // Handle all HTML5 storage other than DOMStorageContext.
40 appcache_service->DeleteAppCachesForOrigin(storage_origin, 62 std::set<GURL> origins;
41 net::CompletionCallback()); 63 origins.insert(storage_origin);
64 ClearQuotaManagedOriginsOnIOThread(quota_manager, origins,
65 quota::kStorageTypePersistent);
66 ClearQuotaManagedOriginsOnIOThread(quota_manager, origins,
67 quota::kStorageTypeTemporary);
42 } 68 }
43 69
44 void ClearDataOnFileThread( 70 void ClearAllDataOnIOThread(
45 const GURL& storage_origin, 71 const scoped_refptr<net::URLRequestContextGetter>& request_context,
46 string16 origin_id, 72 const scoped_refptr<quota::QuotaManager>& quota_manager) {
47 const scoped_refptr<webkit_database::DatabaseTracker> &database_tracker, 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
48 const scoped_refptr<fileapi::FileSystemContext>& file_system_context) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
50 74
51 // Clear out the HTML5 filesystem. 75 // Handle the cookies.
52 file_system_context->DeleteDataForOriginOnFileThread(storage_origin); 76 net::CookieMonster* cookie_monster =
77 request_context->GetURLRequestContext()->cookie_store()->
78 GetCookieMonster();
79 if (cookie_monster)
80 cookie_monster->DeleteAllAsync(net::CookieMonster::DeleteCallback());
53 81
54 // Clear out the database tracker. We just let this run until completion 82 // Handle all HTML5 storage other than DOMStorageContext.
55 // without notification. 83 quota_manager->GetOriginsModifiedSince(
56 int rv = database_tracker->DeleteDataForOrigin( 84 quota::kStorageTypePersistent, base::Time(),
57 origin_id, net::CompletionCallback()); 85 base::Bind(&ClearQuotaManagedOriginsOnIOThread, quota_manager));
58 DCHECK(rv == net::OK || rv == net::ERR_IO_PENDING); 86 quota_manager->GetOriginsModifiedSince(
87 quota::kStorageTypeTemporary, base::Time(),
88 base::Bind(&ClearQuotaManagedOriginsOnIOThread, quota_manager));
89 }
90
91 void OnLocalStorageUsageInfo(
92 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context,
93 const std::vector<dom_storage::LocalStorageUsageInfo>& infos) {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
95
96 for (size_t i = 0; i < infos.size(); ++i) {
97 dom_storage_context->DeleteLocalStorage(infos[i].origin);
98 }
99 }
100
101 void OnSessionStorageUsageInfo(
102 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context,
103 const std::vector<dom_storage::SessionStorageUsageInfo>& infos) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
105
106 for (size_t i = 0; i < infos.size(); ++i) {
107 dom_storage_context->DeleteSessionStorage(infos[i]);
108 }
59 } 109 }
60 110
61 } // namespace 111 } // namespace
62 112
63 StoragePartitionImpl::StoragePartitionImpl( 113 StoragePartitionImpl::StoragePartitionImpl(
64 const FilePath& partition_path, 114 const FilePath& partition_path,
65 quota::QuotaManager* quota_manager, 115 quota::QuotaManager* quota_manager,
66 ChromeAppCacheService* appcache_service, 116 ChromeAppCacheService* appcache_service,
67 fileapi::FileSystemContext* filesystem_context, 117 fileapi::FileSystemContext* filesystem_context,
68 webkit_database::DatabaseTracker* database_tracker, 118 webkit_database::DatabaseTracker* database_tracker,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 return indexed_db_context_; 235 return indexed_db_context_;
186 } 236 }
187 237
188 void StoragePartitionImpl::AsyncClearDataForOrigin( 238 void StoragePartitionImpl::AsyncClearDataForOrigin(
189 const GURL& storage_origin, 239 const GURL& storage_origin,
190 net::URLRequestContextGetter* request_context_getter) { 240 net::URLRequestContextGetter* request_context_getter) {
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
192 242
193 BrowserThread::PostTask( 243 BrowserThread::PostTask(
194 BrowserThread::IO, FROM_HERE, 244 BrowserThread::IO, FROM_HERE,
195 base::Bind(&ClearDataOnIOThread, 245 base::Bind(&ClearOriginOnIOThread,
196 storage_origin, 246 storage_origin,
197 make_scoped_refptr(request_context_getter), 247 make_scoped_refptr(request_context_getter),
198 appcache_service_)); 248 quota_manager_));
199
200 string16 origin_id =
201 webkit_database::DatabaseUtil::GetOriginIdentifier(storage_origin);
202 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
203 base::Bind(&ClearDataOnFileThread,
204 storage_origin,
205 origin_id,
206 database_tracker_,
207 filesystem_context_));
208 249
209 GetDOMStorageContext()->DeleteLocalStorage(storage_origin); 250 GetDOMStorageContext()->DeleteLocalStorage(storage_origin);
251 }
210 252
253 void StoragePartitionImpl::AsyncClearAllData() {
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
255
256 // We ignore the media request context because it shares the same cookie store
257 // as the main request context.
211 BrowserThread::PostTask( 258 BrowserThread::PostTask(
212 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, 259 BrowserThread::IO, FROM_HERE,
213 base::Bind( 260 base::Bind(&ClearAllDataOnIOThread, url_request_context_,
214 &IndexedDBContext::DeleteForOrigin, 261 quota_manager_));
215 indexed_db_context_, 262
216 storage_origin)); 263 dom_storage_context_->GetLocalStorageUsage(
264 base::Bind(&OnLocalStorageUsageInfo, dom_storage_context_));
265 dom_storage_context_->GetSessionStorageUsage(
266 base::Bind(&OnSessionStorageUsageInfo, dom_storage_context_));
217 } 267 }
218 268
219 void StoragePartitionImpl::SetURLRequestContext( 269 void StoragePartitionImpl::SetURLRequestContext(
220 net::URLRequestContextGetter* url_request_context) { 270 net::URLRequestContextGetter* url_request_context) {
221 url_request_context_ = url_request_context; 271 url_request_context_ = url_request_context;
222 } 272 }
223 273
224 void StoragePartitionImpl::SetMediaURLRequestContext( 274 void StoragePartitionImpl::SetMediaURLRequestContext(
225 net::URLRequestContextGetter* media_url_request_context) { 275 net::URLRequestContextGetter* media_url_request_context) {
226 media_url_request_context_ = media_url_request_context; 276 media_url_request_context_ = media_url_request_context;
227 } 277 }
228 278
229 } // namespace content 279 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/storage_partition_impl.h ('k') | content/browser/storage_partition_impl_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698