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/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/browser/browser_main_loop.h" | 9 #include "content/browser/browser_main_loop.h" |
10 #include "content/browser/fileapi/browser_file_system_helper.h" | 10 #include "content/browser/fileapi/browser_file_system_helper.h" |
11 #include "content/browser/gpu/shader_disk_cache.h" | 11 #include "content/browser/gpu/shader_disk_cache.h" |
| 12 #include "content/common/dom_storage/dom_storage_types.h" |
12 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/dom_storage_context.h" | 15 #include "content/public/browser/dom_storage_context.h" |
15 #include "content/public/browser/indexed_db_context.h" | 16 #include "content/public/browser/indexed_db_context.h" |
16 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
18 #include "net/cookies/cookie_monster.h" | 19 #include "net/cookies/cookie_monster.h" |
19 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
21 #include "webkit/browser/database/database_tracker.h" | 22 #include "webkit/browser/database/database_tracker.h" |
22 #include "webkit/browser/quota/quota_manager.h" | 23 #include "webkit/browser/quota/quota_manager.h" |
23 #include "webkit/common/dom_storage/dom_storage_types.h" | |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 int GenerateQuotaClientMask(uint32 remove_mask) { | 29 int GenerateQuotaClientMask(uint32 remove_mask) { |
30 int quota_client_mask = 0; | 30 int quota_client_mask = 0; |
31 | 31 |
32 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS) | 32 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS) |
33 quota_client_mask |= quota::QuotaClient::kFileSystem; | 33 quota_client_mask |= quota::QuotaClient::kFileSystem; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 void ClearShaderCacheOnIOThread(const base::FilePath& path, | 126 void ClearShaderCacheOnIOThread(const base::FilePath& path, |
127 const base::Time begin, | 127 const base::Time begin, |
128 const base::Time end, | 128 const base::Time end, |
129 const base::Closure& callback) { | 129 const base::Closure& callback) { |
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
131 ShaderCacheFactory::GetInstance()->ClearByPath( | 131 ShaderCacheFactory::GetInstance()->ClearByPath( |
132 path, begin, end, base::Bind(&ClearedShaderCache, callback)); | 132 path, begin, end, base::Bind(&ClearedShaderCache, callback)); |
133 } | 133 } |
134 | 134 |
135 void OnLocalStorageUsageInfo( | 135 void OnLocalStorageUsageInfo( |
136 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | 136 const scoped_refptr<DOMStorageContextProxy>& dom_storage_context, |
137 const base::Time delete_begin, | 137 const base::Time delete_begin, |
138 const base::Time delete_end, | 138 const base::Time delete_end, |
139 const base::Closure& callback, | 139 const base::Closure& callback, |
140 const std::vector<dom_storage::LocalStorageUsageInfo>& infos) { | 140 const std::vector<LocalStorageUsageInfo>& infos) { |
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
142 | 142 |
143 for (size_t i = 0; i < infos.size(); ++i) { | 143 for (size_t i = 0; i < infos.size(); ++i) { |
144 if (infos[i].last_modified >= delete_begin && | 144 if (infos[i].last_modified >= delete_begin && |
145 infos[i].last_modified <= delete_end) { | 145 infos[i].last_modified <= delete_end) { |
146 dom_storage_context->DeleteLocalStorage(infos[i].origin); | 146 dom_storage_context->DeleteLocalStorage(infos[i].origin); |
147 } | 147 } |
148 } | 148 } |
149 callback.Run(); | 149 callback.Run(); |
150 } | 150 } |
151 | 151 |
152 void OnSessionStorageUsageInfo( | 152 void OnSessionStorageUsageInfo( |
153 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | 153 const scoped_refptr<DOMStorageContextProxy>& dom_storage_context, |
154 const base::Closure& callback, | 154 const base::Closure& callback, |
155 const std::vector<dom_storage::SessionStorageUsageInfo>& infos) { | 155 const std::vector<SessionStorageUsageInfo>& infos) { |
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
157 | 157 |
158 for (size_t i = 0; i < infos.size(); ++i) | 158 for (size_t i = 0; i < infos.size(); ++i) |
159 dom_storage_context->DeleteSessionStorage(infos[i]); | 159 dom_storage_context->DeleteSessionStorage(infos[i]); |
160 | 160 |
161 callback.Run(); | 161 callback.Run(); |
162 } | 162 } |
163 | 163 |
164 void ClearLocalStorageOnUIThread( | 164 void ClearLocalStorageOnUIThread( |
165 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | 165 const scoped_refptr<DOMStorageContextProxy>& dom_storage_context, |
166 const GURL& remove_origin, | 166 const GURL& remove_origin, |
167 const base::Time begin, | 167 const base::Time begin, |
168 const base::Time end, | 168 const base::Time end, |
169 const base::Closure& callback) { | 169 const base::Closure& callback) { |
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
171 | 171 |
172 if (!remove_origin.is_empty()) { | 172 if (!remove_origin.is_empty()) { |
173 dom_storage_context->DeleteLocalStorage(remove_origin); | 173 dom_storage_context->DeleteLocalStorage(remove_origin); |
174 callback.Run(); | 174 callback.Run(); |
175 return; | 175 return; |
176 } | 176 } |
177 | 177 |
178 dom_storage_context->GetLocalStorageUsage( | 178 dom_storage_context->GetLocalStorageUsage( |
179 base::Bind(&OnLocalStorageUsageInfo, | 179 base::Bind(&OnLocalStorageUsageInfo, |
180 dom_storage_context, begin, end, callback)); | 180 dom_storage_context, begin, end, callback)); |
181 } | 181 } |
182 | 182 |
183 void ClearSessionStorageOnUIThread( | 183 void ClearSessionStorageOnUIThread( |
184 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | 184 const scoped_refptr<DOMStorageContextProxy>& dom_storage_context, |
185 const base::Closure& callback) { | 185 const base::Closure& callback) { |
186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
187 | 187 |
188 dom_storage_context->GetSessionStorageUsage( | 188 dom_storage_context->GetSessionStorageUsage( |
189 base::Bind(&OnSessionStorageUsageInfo, dom_storage_context, callback)); | 189 base::Bind(&OnSessionStorageUsageInfo, dom_storage_context, callback)); |
190 } | 190 } |
191 | 191 |
192 } // namespace | 192 } // namespace |
193 | 193 |
194 // Helper for deleting quota managed data from a partition. | 194 // Helper for deleting quota managed data from a partition. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 231 } |
232 | 232 |
233 void IncrementTaskCountOnUI(); | 233 void IncrementTaskCountOnUI(); |
234 void DecrementTaskCountOnUI(); | 234 void DecrementTaskCountOnUI(); |
235 | 235 |
236 void ClearDataOnUIThread(uint32 remove_mask, | 236 void ClearDataOnUIThread(uint32 remove_mask, |
237 uint32 quota_storage_remove_mask, | 237 uint32 quota_storage_remove_mask, |
238 const GURL& remove_origin, | 238 const GURL& remove_origin, |
239 const base::FilePath& path, | 239 const base::FilePath& path, |
240 net::URLRequestContextGetter* rq_context, | 240 net::URLRequestContextGetter* rq_context, |
241 DOMStorageContextImpl* dom_storage_context, | 241 DOMStorageContextProxy* dom_storage_context, |
242 quota::QuotaManager* quota_manager, | 242 quota::QuotaManager* quota_manager, |
243 const base::Time begin, | 243 const base::Time begin, |
244 const base::Time end); | 244 const base::Time end); |
245 | 245 |
246 // Accessed on UI thread. | 246 // Accessed on UI thread. |
247 const base::Closure callback; | 247 const base::Closure callback; |
248 // Accessed on UI thread. | 248 // Accessed on UI thread. |
249 int task_count; | 249 int task_count; |
250 }; | 250 }; |
251 | 251 |
(...skipping 11 matching lines...) Expand all Loading... |
263 helper->ClearDataOnIOThread(quota_manager, begin, | 263 helper->ClearDataOnIOThread(quota_manager, begin, |
264 remove_mask, quota_storage_remove_mask, remove_origin); | 264 remove_mask, quota_storage_remove_mask, remove_origin); |
265 } | 265 } |
266 | 266 |
267 StoragePartitionImpl::StoragePartitionImpl( | 267 StoragePartitionImpl::StoragePartitionImpl( |
268 const base::FilePath& partition_path, | 268 const base::FilePath& partition_path, |
269 quota::QuotaManager* quota_manager, | 269 quota::QuotaManager* quota_manager, |
270 ChromeAppCacheService* appcache_service, | 270 ChromeAppCacheService* appcache_service, |
271 fileapi::FileSystemContext* filesystem_context, | 271 fileapi::FileSystemContext* filesystem_context, |
272 webkit_database::DatabaseTracker* database_tracker, | 272 webkit_database::DatabaseTracker* database_tracker, |
273 DOMStorageContextImpl* dom_storage_context, | 273 DOMStorageContextProxy* dom_storage_context, |
274 IndexedDBContextImpl* indexed_db_context, | 274 IndexedDBContextImpl* indexed_db_context, |
275 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store) | 275 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store) |
276 : partition_path_(partition_path), | 276 : partition_path_(partition_path), |
277 quota_manager_(quota_manager), | 277 quota_manager_(quota_manager), |
278 appcache_service_(appcache_service), | 278 appcache_service_(appcache_service), |
279 filesystem_context_(filesystem_context), | 279 filesystem_context_(filesystem_context), |
280 database_tracker_(database_tracker), | 280 database_tracker_(database_tracker), |
281 dom_storage_context_(dom_storage_context), | 281 dom_storage_context_(dom_storage_context), |
282 indexed_db_context_(indexed_db_context), | 282 indexed_db_context_(indexed_db_context), |
283 webrtc_identity_store_(webrtc_identity_store.Pass()) {} | 283 webrtc_identity_store_(webrtc_identity_store.Pass()) {} |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = | 328 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = |
329 new webkit_database::DatabaseTracker( | 329 new webkit_database::DatabaseTracker( |
330 partition_path, | 330 partition_path, |
331 in_memory, | 331 in_memory, |
332 context->GetSpecialStoragePolicy(), | 332 context->GetSpecialStoragePolicy(), |
333 quota_manager->proxy(), | 333 quota_manager->proxy(), |
334 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) | 334 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) |
335 .get()); | 335 .get()); |
336 | 336 |
337 base::FilePath path = in_memory ? base::FilePath() : partition_path; | 337 base::FilePath path = in_memory ? base::FilePath() : partition_path; |
338 scoped_refptr<DOMStorageContextImpl> dom_storage_context = | 338 scoped_refptr<DOMStorageContextProxy> dom_storage_context = |
339 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); | 339 new DOMStorageContextProxy(path, context->GetSpecialStoragePolicy()); |
340 | 340 |
341 // BrowserMainLoop may not be initialized in unit tests. Tests will | 341 // BrowserMainLoop may not be initialized in unit tests. Tests will |
342 // need to inject their own task runner into the IndexedDBContext. | 342 // need to inject their own task runner into the IndexedDBContext. |
343 base::SequencedTaskRunner* idb_task_runner = | 343 base::SequencedTaskRunner* idb_task_runner = |
344 BrowserThread::CurrentlyOn(BrowserThread::UI) && | 344 BrowserThread::CurrentlyOn(BrowserThread::UI) && |
345 BrowserMainLoop::GetInstance() | 345 BrowserMainLoop::GetInstance() |
346 ? BrowserMainLoop::GetInstance()->indexed_db_thread() | 346 ? BrowserMainLoop::GetInstance()->indexed_db_thread() |
347 ->message_loop_proxy().get() | 347 ->message_loop_proxy().get() |
348 : NULL; | 348 : NULL; |
349 scoped_refptr<IndexedDBContextImpl> indexed_db_context = | 349 scoped_refptr<IndexedDBContextImpl> indexed_db_context = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 390 } |
391 | 391 |
392 fileapi::FileSystemContext* StoragePartitionImpl::GetFileSystemContext() { | 392 fileapi::FileSystemContext* StoragePartitionImpl::GetFileSystemContext() { |
393 return filesystem_context_.get(); | 393 return filesystem_context_.get(); |
394 } | 394 } |
395 | 395 |
396 webkit_database::DatabaseTracker* StoragePartitionImpl::GetDatabaseTracker() { | 396 webkit_database::DatabaseTracker* StoragePartitionImpl::GetDatabaseTracker() { |
397 return database_tracker_.get(); | 397 return database_tracker_.get(); |
398 } | 398 } |
399 | 399 |
400 DOMStorageContextImpl* StoragePartitionImpl::GetDOMStorageContext() { | 400 DOMStorageContextProxy* StoragePartitionImpl::GetDOMStorageContext() { |
401 return dom_storage_context_.get(); | 401 return dom_storage_context_.get(); |
402 } | 402 } |
403 | 403 |
404 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() { | 404 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() { |
405 return indexed_db_context_.get(); | 405 return indexed_db_context_.get(); |
406 } | 406 } |
407 | 407 |
408 void StoragePartitionImpl::ClearDataImpl( | 408 void StoragePartitionImpl::ClearDataImpl( |
409 uint32 remove_mask, | 409 uint32 remove_mask, |
410 uint32 quota_storage_remove_mask, | 410 uint32 quota_storage_remove_mask, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 delete this; | 525 delete this; |
526 } | 526 } |
527 } | 527 } |
528 | 528 |
529 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( | 529 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( |
530 uint32 remove_mask, | 530 uint32 remove_mask, |
531 uint32 quota_storage_remove_mask, | 531 uint32 quota_storage_remove_mask, |
532 const GURL& remove_origin, | 532 const GURL& remove_origin, |
533 const base::FilePath& path, | 533 const base::FilePath& path, |
534 net::URLRequestContextGetter* rq_context, | 534 net::URLRequestContextGetter* rq_context, |
535 DOMStorageContextImpl* dom_storage_context, | 535 DOMStorageContextProxy* dom_storage_context, |
536 quota::QuotaManager* quota_manager, | 536 quota::QuotaManager* quota_manager, |
537 const base::Time begin, | 537 const base::Time begin, |
538 const base::Time end) { | 538 const base::Time end) { |
539 DCHECK_NE(remove_mask, 0u); | 539 DCHECK_NE(remove_mask, 0u); |
540 DCHECK(!callback.is_null()); | 540 DCHECK(!callback.is_null()); |
541 | 541 |
542 IncrementTaskCountOnUI(); | 542 IncrementTaskCountOnUI(); |
543 base::Closure decrement_callback = base::Bind( | 543 base::Closure decrement_callback = base::Bind( |
544 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); | 544 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); |
545 | 545 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 net::URLRequestContextGetter* url_request_context) { | 630 net::URLRequestContextGetter* url_request_context) { |
631 url_request_context_ = url_request_context; | 631 url_request_context_ = url_request_context; |
632 } | 632 } |
633 | 633 |
634 void StoragePartitionImpl::SetMediaURLRequestContext( | 634 void StoragePartitionImpl::SetMediaURLRequestContext( |
635 net::URLRequestContextGetter* media_url_request_context) { | 635 net::URLRequestContextGetter* media_url_request_context) { |
636 media_url_request_context_ = media_url_request_context; | 636 media_url_request_context_ = media_url_request_context; |
637 } | 637 } |
638 | 638 |
639 } // namespace content | 639 } // namespace content |
OLD | NEW |