Chromium Code Reviews

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

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile gdi. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
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/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/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/cookie_store_map.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"
17 #include "content/public/common/url_constants.h"
16 #include "net/base/completion_callback.h" 18 #include "net/base/completion_callback.h"
17 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
18 #include "net/cookies/cookie_monster.h" 20 #include "net/cookies/cookie_monster.h"
19 #include "net/url_request/url_request_context.h" 21 #include "net/url_request/url_request_context.h"
20 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
21 #include "webkit/browser/database/database_tracker.h" 23 #include "webkit/browser/database/database_tracker.h"
22 #include "webkit/browser/quota/quota_manager.h" 24 #include "webkit/browser/quota/quota_manager.h"
23 #include "webkit/common/dom_storage/dom_storage_types.h" 25 #include "webkit/common/dom_storage/dom_storage_types.h"
24 26
25 namespace content { 27 namespace content {
26 28
27 namespace { 29 namespace {
28 30
29 int GenerateQuotaClientMask(uint32 remove_mask) { 31 int GenerateQuotaClientMask(uint32 remove_mask) {
30 int quota_client_mask = 0; 32 int quota_client_mask = 0;
31 33
32 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS) 34 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS)
33 quota_client_mask |= quota::QuotaClient::kFileSystem; 35 quota_client_mask |= quota::QuotaClient::kFileSystem;
34 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_WEBSQL) 36 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_WEBSQL)
35 quota_client_mask |= quota::QuotaClient::kDatabase; 37 quota_client_mask |= quota::QuotaClient::kDatabase;
36 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_APPCACHE) 38 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_APPCACHE)
37 quota_client_mask |= quota::QuotaClient::kAppcache; 39 quota_client_mask |= quota::QuotaClient::kAppcache;
38 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_INDEXEDDB) 40 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)
39 quota_client_mask |= quota::QuotaClient::kIndexedDatabase; 41 quota_client_mask |= quota::QuotaClient::kIndexedDatabase;
40 42
41 return quota_client_mask; 43 return quota_client_mask;
42 } 44 }
43 45
44 void OnClearedCookies(const base::Closure& callback, int num_deleted) {
45 // The final callback needs to happen from UI thread.
46 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
47 BrowserThread::PostTask(
48 BrowserThread::UI, FROM_HERE,
49 base::Bind(&OnClearedCookies, callback, num_deleted));
50 return;
51 }
52
53 callback.Run();
54 }
55
56 void ClearCookiesOnIOThread(
57 const scoped_refptr<net::URLRequestContextGetter>& rq_context,
58 const base::Time begin,
59 const base::Time end,
60 const base::Closure& callback) {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
62 net::CookieStore* cookie_store = rq_context->
63 GetURLRequestContext()->cookie_store();
64 cookie_store->DeleteAllCreatedBetweenAsync(begin, end,
65 base::Bind(&OnClearedCookies, callback));
66 }
67
68 void OnQuotaManagedOriginDeleted(const GURL& origin, 46 void OnQuotaManagedOriginDeleted(const GURL& origin,
69 quota::StorageType type, 47 quota::StorageType type,
70 size_t* origins_to_delete_count, 48 size_t* origins_to_delete_count,
71 const base::Closure& callback, 49 const base::Closure& callback,
72 quota::QuotaStatusCode status) { 50 quota::QuotaStatusCode status) {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
74 DCHECK_GT(*origins_to_delete_count, 0u); 52 DCHECK_GT(*origins_to_delete_count, 0u);
75 if (status != quota::kQuotaStatusOk) { 53 if (status != quota::kQuotaStatusOk) {
76 DLOG(ERROR) << "Couldn't remove data of type " << type << " for origin " 54 DLOG(ERROR) << "Couldn't remove data of type " << type << " for origin "
77 << origin << ". Status: " << status; 55 << origin << ". Status: " << status;
(...skipping 152 matching lines...)
230 : callback(callback), task_count(0) { 208 : callback(callback), task_count(0) {
231 } 209 }
232 210
233 void IncrementTaskCountOnUI(); 211 void IncrementTaskCountOnUI();
234 void DecrementTaskCountOnUI(); 212 void DecrementTaskCountOnUI();
235 213
236 void ClearDataOnUIThread(uint32 remove_mask, 214 void ClearDataOnUIThread(uint32 remove_mask,
237 uint32 quota_storage_remove_mask, 215 uint32 quota_storage_remove_mask,
238 const GURL& remove_origin, 216 const GURL& remove_origin,
239 const base::FilePath& path, 217 const base::FilePath& path,
240 net::URLRequestContextGetter* rq_context, 218 CookieStoreMapImpl* cookie_store_map,
241 DOMStorageContextImpl* dom_storage_context, 219 DOMStorageContextImpl* dom_storage_context,
242 quota::QuotaManager* quota_manager, 220 quota::QuotaManager* quota_manager,
243 const base::Time begin, 221 const base::Time begin,
244 const base::Time end); 222 const base::Time end);
245 223
246 // Accessed on UI thread. 224 // Accessed on UI thread.
247 const base::Closure callback; 225 const base::Closure callback;
248 // Accessed on UI thread. 226 // Accessed on UI thread.
249 int task_count; 227 int task_count;
250 }; 228 };
(...skipping 14 matching lines...)
265 } 243 }
266 244
267 StoragePartitionImpl::StoragePartitionImpl( 245 StoragePartitionImpl::StoragePartitionImpl(
268 const base::FilePath& partition_path, 246 const base::FilePath& partition_path,
269 quota::QuotaManager* quota_manager, 247 quota::QuotaManager* quota_manager,
270 ChromeAppCacheService* appcache_service, 248 ChromeAppCacheService* appcache_service,
271 fileapi::FileSystemContext* filesystem_context, 249 fileapi::FileSystemContext* filesystem_context,
272 webkit_database::DatabaseTracker* database_tracker, 250 webkit_database::DatabaseTracker* database_tracker,
273 DOMStorageContextImpl* dom_storage_context, 251 DOMStorageContextImpl* dom_storage_context,
274 IndexedDBContextImpl* indexed_db_context, 252 IndexedDBContextImpl* indexed_db_context,
253 scoped_ptr<CookieStoreMapImpl> cookie_store_map,
275 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store) 254 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store)
276 : partition_path_(partition_path), 255 : partition_path_(partition_path),
277 quota_manager_(quota_manager), 256 quota_manager_(quota_manager),
278 appcache_service_(appcache_service), 257 appcache_service_(appcache_service),
279 filesystem_context_(filesystem_context), 258 filesystem_context_(filesystem_context),
280 database_tracker_(database_tracker), 259 database_tracker_(database_tracker),
281 dom_storage_context_(dom_storage_context), 260 dom_storage_context_(dom_storage_context),
282 indexed_db_context_(indexed_db_context), 261 indexed_db_context_(indexed_db_context),
283 webrtc_identity_store_(webrtc_identity_store.Pass()) {} 262 cookie_store_map_(cookie_store_map.Pass()),
263 webrtc_identity_store_(webrtc_identity_store.Pass()) {
264 }
284 265
285 StoragePartitionImpl::~StoragePartitionImpl() { 266 StoragePartitionImpl::~StoragePartitionImpl() {
286 // These message loop checks are just to avoid leaks in unittests. 267 // These message loop checks are just to avoid leaks in unittests.
287 if (GetDatabaseTracker() && 268 if (GetDatabaseTracker() &&
288 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { 269 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
289 BrowserThread::PostTask( 270 BrowserThread::PostTask(
290 BrowserThread::FILE, FROM_HERE, 271 BrowserThread::FILE, FROM_HERE,
291 base::Bind(&webkit_database::DatabaseTracker::Shutdown, 272 base::Bind(&webkit_database::DatabaseTracker::Shutdown,
292 GetDatabaseTracker())); 273 GetDatabaseTracker()));
293 } 274 }
294 275
295 if (GetDOMStorageContext()) 276 if (GetDOMStorageContext())
296 GetDOMStorageContext()->Shutdown(); 277 GetDOMStorageContext()->Shutdown();
297 } 278 }
298 279
299 // TODO(ajwong): Break the direct dependency on |context|. We only 280 // TODO(ajwong): Break the direct dependency on |context|. We only
300 // need 3 pieces of info from it. 281 // need 3 pieces of info from it.
301 StoragePartitionImpl* StoragePartitionImpl::Create( 282 StoragePartitionImpl* StoragePartitionImpl::Create(
302 BrowserContext* context, 283 BrowserContext* context,
303 bool in_memory, 284 bool in_memory,
304 const base::FilePath& partition_path) { 285 const base::FilePath& partition_path,
286 scoped_ptr<CookieStoreMapImpl> cookie_store_map) {
305 // Ensure that these methods are called on the UI thread, except for 287 // Ensure that these methods are called on the UI thread, except for
306 // unittests where a UI thread might not have been created. 288 // unittests where a UI thread might not have been created.
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
308 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); 290 !BrowserThread::IsMessageLoopValid(BrowserThread::UI));
309 291
310 // All of the clients have to be created and registered with the 292 // All of the clients have to be created and registered with the
311 // QuotaManager prior to the QuotaManger being used. We do them 293 // QuotaManager prior to the QuotaManger being used. We do them
312 // all together here prior to handing out a reference to anything 294 // all together here prior to handing out a reference to anything
313 // that utilizes the QuotaManager. 295 // that utilizes the QuotaManager.
314 scoped_refptr<quota::QuotaManager> quota_manager = new quota::QuotaManager( 296 scoped_refptr<quota::QuotaManager> quota_manager = new quota::QuotaManager(
(...skipping 43 matching lines...)
358 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store( 340 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store(
359 new WebRTCIdentityStore()); 341 new WebRTCIdentityStore());
360 342
361 return new StoragePartitionImpl(partition_path, 343 return new StoragePartitionImpl(partition_path,
362 quota_manager.get(), 344 quota_manager.get(),
363 appcache_service.get(), 345 appcache_service.get(),
364 filesystem_context.get(), 346 filesystem_context.get(),
365 database_tracker.get(), 347 database_tracker.get(),
366 dom_storage_context.get(), 348 dom_storage_context.get(),
367 indexed_db_context.get(), 349 indexed_db_context.get(),
350 cookie_store_map.Pass(),
368 webrtc_identity_store.Pass()); 351 webrtc_identity_store.Pass());
369 } 352 }
370 353
371 base::FilePath StoragePartitionImpl::GetPath() { 354 base::FilePath StoragePartitionImpl::GetPath() {
372 return partition_path_; 355 return partition_path_;
373 } 356 }
374 357
375 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() { 358 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() {
376 return url_request_context_.get(); 359 return url_request_context_.get();
377 } 360 }
(...skipping 20 matching lines...)
398 } 381 }
399 382
400 DOMStorageContextImpl* StoragePartitionImpl::GetDOMStorageContext() { 383 DOMStorageContextImpl* StoragePartitionImpl::GetDOMStorageContext() {
401 return dom_storage_context_.get(); 384 return dom_storage_context_.get();
402 } 385 }
403 386
404 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() { 387 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() {
405 return indexed_db_context_.get(); 388 return indexed_db_context_.get();
406 } 389 }
407 390
391 const CookieStoreMapImpl& StoragePartitionImpl::GetCookieStoreMap() {
392 return *cookie_store_map_;
393 }
394
408 void StoragePartitionImpl::ClearDataImpl( 395 void StoragePartitionImpl::ClearDataImpl(
409 uint32 remove_mask, 396 uint32 remove_mask,
410 uint32 quota_storage_remove_mask, 397 uint32 quota_storage_remove_mask,
411 const GURL& remove_origin, 398 const GURL& remove_origin,
412 net::URLRequestContextGetter* rq_context,
413 const base::Time begin, 399 const base::Time begin,
414 const base::Time end, 400 const base::Time end,
415 const base::Closure& callback) { 401 const base::Closure& callback) {
416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
417 DataDeletionHelper* helper = new DataDeletionHelper(callback); 403 DataDeletionHelper* helper = new DataDeletionHelper(callback);
418 // |helper| deletes itself when done in 404 // |helper| deletes itself when done in
419 // DataDeletionHelper::DecrementTaskCountOnUI(). 405 // DataDeletionHelper::DecrementTaskCountOnUI().
420 helper->ClearDataOnUIThread( 406 helper->ClearDataOnUIThread(
421 remove_mask, quota_storage_remove_mask, remove_origin, 407 remove_mask, quota_storage_remove_mask, remove_origin,
422 GetPath(), rq_context, dom_storage_context_, quota_manager_, begin, end); 408 GetPath(), cookie_store_map_.get(), dom_storage_context_, quota_manager_,
409 begin, end);
423 } 410 }
424 411
425 void StoragePartitionImpl:: 412 void StoragePartitionImpl::
426 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() { 413 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() {
427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
428 ++task_count; 415 ++task_count;
429 } 416 }
430 417
431 void StoragePartitionImpl:: 418 void StoragePartitionImpl::
432 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() { 419 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() {
(...skipping 91 matching lines...)
524 callback.Run(); 511 callback.Run();
525 delete this; 512 delete this;
526 } 513 }
527 } 514 }
528 515
529 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( 516 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
530 uint32 remove_mask, 517 uint32 remove_mask,
531 uint32 quota_storage_remove_mask, 518 uint32 quota_storage_remove_mask,
532 const GURL& remove_origin, 519 const GURL& remove_origin,
533 const base::FilePath& path, 520 const base::FilePath& path,
534 net::URLRequestContextGetter* rq_context, 521 CookieStoreMapImpl* cookie_store_map,
535 DOMStorageContextImpl* dom_storage_context, 522 DOMStorageContextImpl* dom_storage_context,
536 quota::QuotaManager* quota_manager, 523 quota::QuotaManager* quota_manager,
537 const base::Time begin, 524 const base::Time begin,
538 const base::Time end) { 525 const base::Time end) {
539 DCHECK_NE(remove_mask, 0u); 526 DCHECK_NE(remove_mask, 0u);
540 DCHECK(!callback.is_null()); 527 DCHECK(!callback.is_null());
541 528
542 IncrementTaskCountOnUI(); 529 IncrementTaskCountOnUI();
543 base::Closure decrement_callback = base::Bind( 530 base::Closure decrement_callback = base::Bind(
544 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); 531 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this));
545 532
546 if (remove_mask & REMOVE_DATA_MASK_COOKIES) { 533 if (remove_mask & REMOVE_DATA_MASK_COOKIES) {
547 // Handle the cookies. 534 // Handle the cookies.
548 IncrementTaskCountOnUI(); 535 IncrementTaskCountOnUI();
549 BrowserThread::PostTask( 536 cookie_store_map->DeleteCookies(remove_origin, begin, end,
550 BrowserThread::IO, FROM_HERE, 537 decrement_callback);
551 base::Bind(&ClearCookiesOnIOThread,
552 make_scoped_refptr(rq_context), begin, end,
553 decrement_callback));
554 } 538 }
555 539
556 if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB || 540 if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB ||
557 remove_mask & REMOVE_DATA_MASK_WEBSQL || 541 remove_mask & REMOVE_DATA_MASK_WEBSQL ||
558 remove_mask & REMOVE_DATA_MASK_APPCACHE || 542 remove_mask & REMOVE_DATA_MASK_APPCACHE ||
559 remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS) { 543 remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS) {
560 IncrementTaskCountOnUI(); 544 IncrementTaskCountOnUI();
561 BrowserThread::PostTask( 545 BrowserThread::PostTask(
562 BrowserThread::IO, FROM_HERE, 546 BrowserThread::IO, FROM_HERE,
563 base::Bind(&ClearQuotaManagedDataOnIOThread, 547 base::Bind(&ClearQuotaManagedDataOnIOThread,
(...skipping 26 matching lines...)
590 path, begin, end, decrement_callback)); 574 path, begin, end, decrement_callback));
591 } 575 }
592 576
593 DecrementTaskCountOnUI(); 577 DecrementTaskCountOnUI();
594 } 578 }
595 579
596 580
597 void StoragePartitionImpl::ClearDataForOrigin( 581 void StoragePartitionImpl::ClearDataForOrigin(
598 uint32 remove_mask, 582 uint32 remove_mask,
599 uint32 quota_storage_remove_mask, 583 uint32 quota_storage_remove_mask,
600 const GURL& storage_origin, 584 const GURL& storage_origin) {
601 net::URLRequestContextGetter* request_context_getter) {
602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
603 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, 586 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin,
604 request_context_getter, base::Time(), base::Time::Max(), 587 base::Time(), base::Time::Max(), base::Bind(&base::DoNothing));
605 base::Bind(&base::DoNothing));
606 } 588 }
607 589
608 void StoragePartitionImpl::ClearDataForUnboundedRange( 590 void StoragePartitionImpl::ClearDataForUnboundedRange(
609 uint32 remove_mask, 591 uint32 remove_mask,
610 uint32 quota_storage_remove_mask) { 592 uint32 quota_storage_remove_mask) {
611 ClearDataImpl(remove_mask, quota_storage_remove_mask, GURL(), 593 ClearDataImpl(remove_mask, quota_storage_remove_mask, GURL(),
612 GetURLRequestContext(), base::Time(), base::Time::Max(), 594 base::Time(), base::Time::Max(), base::Bind(&base::DoNothing));
613 base::Bind(&base::DoNothing));
614 } 595 }
615 596
616 void StoragePartitionImpl::ClearDataForRange(uint32 remove_mask, 597 void StoragePartitionImpl::ClearDataForRange(uint32 remove_mask,
617 uint32 quota_storage_remove_mask, 598 uint32 quota_storage_remove_mask,
618 const base::Time& begin, 599 const base::Time& begin,
619 const base::Time& end, 600 const base::Time& end,
620 const base::Closure& callback) { 601 const base::Closure& callback) {
621 ClearDataImpl(remove_mask, quota_storage_remove_mask, GURL(), 602 ClearDataImpl(remove_mask, quota_storage_remove_mask, GURL(), begin, end,
622 GetURLRequestContext(), begin, end, callback); 603 callback);
623 } 604 }
624 605
625 WebRTCIdentityStore* StoragePartitionImpl::GetWebRTCIdentityStore() { 606 WebRTCIdentityStore* StoragePartitionImpl::GetWebRTCIdentityStore() {
626 return webrtc_identity_store_.get(); 607 return webrtc_identity_store_.get();
627 } 608 }
628 609
629 void StoragePartitionImpl::SetURLRequestContext( 610 void StoragePartitionImpl::SetURLRequestContext(
630 net::URLRequestContextGetter* url_request_context) { 611 net::URLRequestContextGetter* url_request_context) {
631 url_request_context_ = url_request_context; 612 url_request_context_ = url_request_context;
632 } 613 }
633 614
634 void StoragePartitionImpl::SetMediaURLRequestContext( 615 void StoragePartitionImpl::SetMediaURLRequestContext(
635 net::URLRequestContextGetter* media_url_request_context) { 616 net::URLRequestContextGetter* media_url_request_context) {
636 media_url_request_context_ = media_url_request_context; 617 media_url_request_context_ = media_url_request_context;
637 } 618 }
638 619
639 } // namespace content 620 } // namespace content
OLDNEW

Powered by Google App Engine