OLD | NEW |
---|---|
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 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
35 std::set<GURL>::const_iterator origin; | |
36 for (std::set<GURL>::const_iterator origin = origins.begin(); | |
37 origin != origins.end(); ++origin) { | |
38 quota_manager->DeleteOriginData(*origin, type, | |
39 quota::QuotaClient::kAllClientsMask, | |
40 base::Bind(&DoNothingStatusCallback)); | |
41 } | |
42 } | |
43 | |
44 void ClearOriginOnIOThread( | |
26 const GURL& storage_origin, | 45 const GURL& storage_origin, |
27 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 46 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
28 const scoped_refptr<ChromeAppCacheService>& appcache_service) { | 47 const scoped_refptr<quota::QuotaManager>& quota_manager) { |
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
30 | 49 |
31 // Handle the cookies. | 50 // Handle the cookies. |
32 net::CookieMonster* cookie_monster = | 51 net::CookieMonster* cookie_monster = |
33 request_context->GetURLRequestContext()->cookie_store()-> | 52 request_context->GetURLRequestContext()->cookie_store()-> |
34 GetCookieMonster(); | 53 GetCookieMonster(); |
35 if (cookie_monster) | 54 if (cookie_monster) |
36 cookie_monster->DeleteAllForHostAsync( | 55 cookie_monster->DeleteAllForHostAsync( |
37 storage_origin, net::CookieMonster::DeleteCallback()); | 56 storage_origin, net::CookieMonster::DeleteCallback()); |
38 | 57 |
39 // Clear out appcache. | 58 // Clear out appcache. |
40 appcache_service->DeleteAppCachesForOrigin(storage_origin, | 59 std::set<GURL> origins; |
41 net::CompletionCallback()); | 60 origins.insert(storage_origin); |
61 ClearQuotaManagedOriginsOnIOThread(quota_manager, origins, | |
62 quota::kStorageTypePersistent); | |
63 ClearQuotaManagedOriginsOnIOThread(quota_manager, origins, | |
64 quota::kStorageTypeTemporary); | |
42 } | 65 } |
43 | 66 |
44 void ClearDataOnFileThread( | 67 void ClearAllDataOnIOThread( |
45 const GURL& storage_origin, | 68 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
46 string16 origin_id, | 69 const scoped_refptr<quota::QuotaManager>& quota_manager) { |
47 const scoped_refptr<webkit_database::DatabaseTracker> &database_tracker, | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
48 const scoped_refptr<fileapi::FileSystemContext>& file_system_context) { | |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
50 | 71 |
51 // Clear out the HTML5 filesystem. | 72 // Handle the cookies. |
52 file_system_context->DeleteDataForOriginOnFileThread(storage_origin); | 73 net::CookieMonster* cookie_monster = |
74 request_context->GetURLRequestContext()->cookie_store()-> | |
75 GetCookieMonster(); | |
76 if (cookie_monster) | |
77 cookie_monster->DeleteAllAsync(net::CookieMonster::DeleteCallback()); | |
53 | 78 |
54 // Clear out the database tracker. We just let this run until completion | 79 // Clear out appcache. |
nasko
2012/11/15 17:48:10
If I get it right ClearQuotaManagedOriginsOnIOThre
awong
2012/11/16 00:36:04
Done.
| |
55 // without notification. | 80 quota_manager->GetOriginsModifiedSince( |
56 int rv = database_tracker->DeleteDataForOrigin( | 81 quota::kStorageTypePersistent, base::Time(), |
57 origin_id, net::CompletionCallback()); | 82 base::Bind(&ClearQuotaManagedOriginsOnIOThread, quota_manager)); |
58 DCHECK(rv == net::OK || rv == net::ERR_IO_PENDING); | 83 quota_manager->GetOriginsModifiedSince( |
84 quota::kStorageTypeTemporary, base::Time(), | |
85 base::Bind(&ClearQuotaManagedOriginsOnIOThread, quota_manager)); | |
86 } | |
87 | |
88 void OnLocalStorageUsageInfo( | |
89 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | |
90 const std::vector<dom_storage::LocalStorageUsageInfo>& infos) { | |
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
92 | |
93 for (size_t i = 0; i < infos.size(); ++i) { | |
94 dom_storage_context->DeleteLocalStorage(infos[i].origin); | |
95 } | |
96 } | |
97 | |
98 void OnSessionStorageUsageInfo( | |
99 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | |
100 const std::vector<dom_storage::SessionStorageUsageInfo>& infos) { | |
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
102 | |
103 for (size_t i = 0; i < infos.size(); ++i) { | |
104 dom_storage_context->DeleteSessionStorage(infos[i]); | |
105 } | |
59 } | 106 } |
60 | 107 |
61 } // namespace | 108 } // namespace |
62 | 109 |
63 StoragePartitionImpl::StoragePartitionImpl( | 110 StoragePartitionImpl::StoragePartitionImpl( |
64 const FilePath& partition_path, | 111 const FilePath& partition_path, |
65 quota::QuotaManager* quota_manager, | 112 quota::QuotaManager* quota_manager, |
66 ChromeAppCacheService* appcache_service, | 113 ChromeAppCacheService* appcache_service, |
67 fileapi::FileSystemContext* filesystem_context, | 114 fileapi::FileSystemContext* filesystem_context, |
68 webkit_database::DatabaseTracker* database_tracker, | 115 webkit_database::DatabaseTracker* database_tracker, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 return indexed_db_context_; | 232 return indexed_db_context_; |
186 } | 233 } |
187 | 234 |
188 void StoragePartitionImpl::AsyncClearDataForOrigin( | 235 void StoragePartitionImpl::AsyncClearDataForOrigin( |
189 const GURL& storage_origin, | 236 const GURL& storage_origin, |
190 net::URLRequestContextGetter* request_context_getter) { | 237 net::URLRequestContextGetter* request_context_getter) { |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
192 | 239 |
193 BrowserThread::PostTask( | 240 BrowserThread::PostTask( |
194 BrowserThread::IO, FROM_HERE, | 241 BrowserThread::IO, FROM_HERE, |
195 base::Bind(&ClearDataOnIOThread, | 242 base::Bind(&ClearOriginOnIOThread, |
196 storage_origin, | 243 storage_origin, |
197 make_scoped_refptr(request_context_getter), | 244 make_scoped_refptr(request_context_getter), |
198 appcache_service_)); | 245 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 | 246 |
209 GetDOMStorageContext()->DeleteLocalStorage(storage_origin); | 247 GetDOMStorageContext()->DeleteLocalStorage(storage_origin); |
248 } | |
210 | 249 |
250 void StoragePartitionImpl::AsyncClearAllData() { | |
251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
252 | |
253 // We ignore the media request context because it shares the same cookie store | |
254 // as the main request context. | |
211 BrowserThread::PostTask( | 255 BrowserThread::PostTask( |
212 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 256 BrowserThread::IO, FROM_HERE, |
213 base::Bind( | 257 base::Bind(&ClearAllDataOnIOThread, url_request_context_, |
214 &IndexedDBContext::DeleteForOrigin, | 258 quota_manager_)); |
215 indexed_db_context_, | 259 |
216 storage_origin)); | 260 dom_storage_context_->GetLocalStorageUsage( |
261 base::Bind(&OnLocalStorageUsageInfo, | |
nasko
2012/11/15 17:48:10
nit: This should fit on a single line.
awong
2012/11/16 00:36:04
Done.
| |
262 dom_storage_context_)); | |
263 dom_storage_context_->GetSessionStorageUsage( | |
264 base::Bind(&OnSessionStorageUsageInfo, | |
265 dom_storage_context_)); | |
217 } | 266 } |
218 | 267 |
219 void StoragePartitionImpl::SetURLRequestContext( | 268 void StoragePartitionImpl::SetURLRequestContext( |
220 net::URLRequestContextGetter* url_request_context) { | 269 net::URLRequestContextGetter* url_request_context) { |
221 url_request_context_ = url_request_context; | 270 url_request_context_ = url_request_context; |
222 } | 271 } |
223 | 272 |
224 void StoragePartitionImpl::SetMediaURLRequestContext( | 273 void StoragePartitionImpl::SetMediaURLRequestContext( |
225 net::URLRequestContextGetter* media_url_request_context) { | 274 net::URLRequestContextGetter* media_url_request_context) { |
226 media_url_request_context_ = media_url_request_context; | 275 media_url_request_context_ = media_url_request_context; |
227 } | 276 } |
228 | 277 |
229 } // namespace content | 278 } // namespace content |
OLD | NEW |