 Chromium Code Reviews
 Chromium Code Reviews Issue 12546016:
  Remove the Extensions URLRequestContext  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 12546016:
  Remove the Extensions URLRequestContext  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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_map.h" | 5 #include "content/browser/storage_partition_impl_map.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/callback.h" | 8 #include "base/callback.h" | 
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" | 
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" | 
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" | 
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" | 
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" | 
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" | 
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" | 
| 16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" | 
| 17 #include "content/browser/appcache/chrome_appcache_service.h" | 17 #include "content/browser/appcache/chrome_appcache_service.h" | 
| 18 #include "content/browser/fileapi/browser_file_system_helper.h" | 18 #include "content/browser/fileapi/browser_file_system_helper.h" | 
| 19 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 19 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 
| 20 #include "content/browser/loader/resource_request_info_impl.h" | 20 #include "content/browser/loader/resource_request_info_impl.h" | 
| 21 #include "content/browser/net/cookie_store_map.h" | |
| 21 #include "content/browser/resource_context_impl.h" | 22 #include "content/browser/resource_context_impl.h" | 
| 22 #include "content/browser/storage_partition_impl.h" | 23 #include "content/browser/storage_partition_impl.h" | 
| 23 #include "content/browser/streams/stream.h" | 24 #include "content/browser/streams/stream.h" | 
| 24 #include "content/browser/streams/stream_context.h" | 25 #include "content/browser/streams/stream_context.h" | 
| 25 #include "content/browser/streams/stream_registry.h" | 26 #include "content/browser/streams/stream_registry.h" | 
| 26 #include "content/browser/streams/stream_url_request_job.h" | 27 #include "content/browser/streams/stream_url_request_job.h" | 
| 27 #include "content/browser/webui/url_data_manager_backend.h" | 28 #include "content/browser/webui/url_data_manager_backend.h" | 
| 28 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" | 
| 29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" | 
| 30 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" | 
| 32 #include "content/public/browser/cookie_store_factory.h" | |
| 31 #include "content/public/browser/storage_partition.h" | 33 #include "content/public/browser/storage_partition.h" | 
| 32 #include "content/public/common/content_constants.h" | 34 #include "content/public/common/content_constants.h" | 
| 33 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" | 
| 34 #include "crypto/sha2.h" | 36 #include "crypto/sha2.h" | 
| 37 #include "net/cookies/cookie_monster.h" | |
| 35 #include "net/url_request/url_request_context.h" | 38 #include "net/url_request/url_request_context.h" | 
| 36 #include "net/url_request/url_request_context_getter.h" | 39 #include "net/url_request/url_request_context_getter.h" | 
| 37 #include "webkit/browser/blob/blob_url_request_job_factory.h" | 40 #include "webkit/browser/blob/blob_url_request_job_factory.h" | 
| 38 #include "webkit/browser/fileapi/file_system_url_request_job_factory.h" | 41 #include "webkit/browser/fileapi/file_system_url_request_job_factory.h" | 
| 39 #include "webkit/common/blob/blob_data.h" | 42 #include "webkit/common/blob/blob_data.h" | 
| 40 | 43 | 
| 41 using appcache::AppCacheService; | 44 using appcache::AppCacheService; | 
| 42 using fileapi::FileSystemContext; | 45 using fileapi::FileSystemContext; | 
| 43 using webkit_blob::BlobStorageController; | 46 using webkit_blob::BlobStorageController; | 
| 44 | 47 | 
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 // can be no colllisions on the move. | 342 // can be no colllisions on the move. | 
| 340 base::Move(path, trash_directory.Append(path.BaseName())); | 343 base::Move(path, trash_directory.Append(path.BaseName())); | 
| 341 } | 344 } | 
| 342 } | 345 } | 
| 343 | 346 | 
| 344 file_access_runner->PostTask( | 347 file_access_runner->PostTask( | 
| 345 FROM_HERE, | 348 FROM_HERE, | 
| 346 base::Bind(base::IgnoreResult(&base::DeleteFile), trash_directory, true)); | 349 base::Bind(base::IgnoreResult(&base::DeleteFile), trash_directory, true)); | 
| 347 } | 350 } | 
| 348 | 351 | 
| 352 void AttachCookieStoreOnIOThread( | |
| 353 const scoped_refptr<net::URLRequestContextGetter>& url_request_context, | |
| 354 const scoped_refptr<net::CookieStore> cookie_store) { | |
| 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 356 url_request_context->GetURLRequestContext()->set_cookie_store( | |
| 357 cookie_store.get()); | |
| 358 } | |
| 359 | |
| 349 } // namespace | 360 } // namespace | 
| 350 | 361 | 
| 351 // static | 362 // static | 
| 352 base::FilePath StoragePartitionImplMap::GetStoragePartitionPath( | 363 base::FilePath StoragePartitionImplMap::GetStoragePartitionPath( | 
| 353 const std::string& partition_domain, | 364 const std::string& partition_domain, | 
| 354 const std::string& partition_name) { | 365 const std::string& partition_name) { | 
| 355 if (partition_domain.empty()) | 366 if (partition_domain.empty()) | 
| 356 return base::FilePath(); | 367 return base::FilePath(); | 
| 357 | 368 | 
| 358 base::FilePath path = GetStoragePartitionDomainPath(partition_domain); | 369 base::FilePath path = GetStoragePartitionDomainPath(partition_domain); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 StoragePartitionConfig partition_config( | 407 StoragePartitionConfig partition_config( | 
| 397 partition_domain, partition_name, in_memory); | 408 partition_domain, partition_name, in_memory); | 
| 398 | 409 | 
| 399 PartitionMap::const_iterator it = partitions_.find(partition_config); | 410 PartitionMap::const_iterator it = partitions_.find(partition_config); | 
| 400 if (it != partitions_.end()) | 411 if (it != partitions_.end()) | 
| 401 return it->second; | 412 return it->second; | 
| 402 | 413 | 
| 403 base::FilePath partition_path = | 414 base::FilePath partition_path = | 
| 404 browser_context_->GetPath().Append( | 415 browser_context_->GetPath().Append( | 
| 405 GetStoragePartitionPath(partition_domain, partition_name)); | 416 GetStoragePartitionPath(partition_domain, partition_name)); | 
| 417 | |
| 418 // Create the cookie stores. | |
| 419 scoped_ptr<CookieStoreMap> cookie_store_map( | |
| 420 CreateCookieStores(partition_path, | |
| 421 in_memory, | |
| 422 partition_domain.empty())); | |
| 423 | |
| 406 StoragePartitionImpl* partition = | 424 StoragePartitionImpl* partition = | 
| 407 StoragePartitionImpl::Create(browser_context_, in_memory, | 425 StoragePartitionImpl::Create(browser_context_, in_memory, | 
| 408 partition_path); | 426 partition_path, cookie_store_map.Pass()); | 
| 409 partitions_[partition_config] = partition; | 427 partitions_[partition_config] = partition; | 
| 410 | 428 | 
| 411 ChromeBlobStorageContext* blob_storage_context = | 429 ChromeBlobStorageContext* blob_storage_context = | 
| 412 ChromeBlobStorageContext::GetFor(browser_context_); | 430 ChromeBlobStorageContext::GetFor(browser_context_); | 
| 413 StreamContext* stream_context = StreamContext::GetFor(browser_context_); | 431 StreamContext* stream_context = StreamContext::GetFor(browser_context_); | 
| 414 ProtocolHandlerMap protocol_handlers; | 432 ProtocolHandlerMap protocol_handlers; | 
| 415 protocol_handlers[chrome::kBlobScheme] = | 433 protocol_handlers[chrome::kBlobScheme] = | 
| 416 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 434 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 
| 417 new BlobProtocolHandler(blob_storage_context, | 435 new BlobProtocolHandler(blob_storage_context, | 
| 418 stream_context, | 436 stream_context, | 
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 // TODO(ajwong): ResourceContexts no longer have any storage related state. | 579 // TODO(ajwong): ResourceContexts no longer have any storage related state. | 
| 562 // We should move this into a place where it is called once per | 580 // We should move this into a place where it is called once per | 
| 563 // BrowserContext creation rather than piggybacking off the default context | 581 // BrowserContext creation rather than piggybacking off the default context | 
| 564 // creation. | 582 // creation. | 
| 565 // Note: moving this into Get() before partitions_[] is set causes reentrency. | 583 // Note: moving this into Get() before partitions_[] is set causes reentrency. | 
| 566 if (!resource_context_initialized_) { | 584 if (!resource_context_initialized_) { | 
| 567 resource_context_initialized_ = true; | 585 resource_context_initialized_ = true; | 
| 568 InitializeResourceContext(browser_context_); | 586 InitializeResourceContext(browser_context_); | 
| 569 } | 587 } | 
| 570 | 588 | 
| 571 // Check first to avoid memory leak in unittests. | 589 // In unittests, BrowserThread::IO may not be valid which would yield a | 
| 572 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 590 // memory leak on a PostTask. Also, in content_unittests, the | 
| 591 // URLRequestContext is NULL. | |
| 592 // | |
| 593 // TODO(ajwong): Should default ContentBrowserClient return a non-null | |
| 594 // URLRequestContext? | |
| 595 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | |
| 596 partition->GetURLRequestContext()) { | |
| 597 // The main URLRequestContextGetter was first created just before | |
| 598 // PostCreateInitialization() is called thus attaching the CookieStore here | |
| 599 // is guaranteed to occur before anyone else can see the main request | |
| 600 // context including the media request context. | |
| 601 BrowserThread::PostTask( | |
| 602 BrowserThread::IO, FROM_HERE, | |
| 603 base::Bind(&AttachCookieStoreOnIOThread, | |
| 604 make_scoped_refptr(partition->GetURLRequestContext()), | |
| 605 make_scoped_refptr( | |
| 606 partition->GetCookieStoreMap().GetForScheme( | |
| 607 chrome::kHttpScheme)))); | |
| 
Charlie Reis
2013/08/17 00:17:22
Ok, I think I follow: you're passing the default c
 
awong
2013/08/17 00:32:52
Yep. Correct. Comment added and name changed.
 | |
| 608 | |
| 573 BrowserThread::PostTask( | 609 BrowserThread::PostTask( | 
| 574 BrowserThread::IO, FROM_HERE, | 610 BrowserThread::IO, FROM_HERE, | 
| 575 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 611 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 
| 576 partition->GetAppCacheService(), | 612 partition->GetAppCacheService(), | 
| 577 in_memory ? base::FilePath() : | 613 in_memory ? base::FilePath() : | 
| 578 partition->GetPath().Append(kAppCacheDirname), | 614 partition->GetPath().Append(kAppCacheDirname), | 
| 579 browser_context_->GetResourceContext(), | 615 browser_context_->GetResourceContext(), | 
| 580 make_scoped_refptr(partition->GetURLRequestContext()), | 616 make_scoped_refptr(partition->GetURLRequestContext()), | 
| 581 make_scoped_refptr( | 617 make_scoped_refptr( | 
| 582 browser_context_->GetSpecialStoragePolicy()))); | 618 browser_context_->GetSpecialStoragePolicy()))); | 
| 583 | 619 | 
| 584 // We do not call InitializeURLRequestContext() for media contexts because, | 620 // We do not initialize the AppCacheService for media contexts because, | 
| 585 // other than the HTTP cache, the media contexts share the same backing | 621 // other than the HTTP cache, the media contexts share the same backing | 
| 586 // objects as their associated "normal" request context. Thus, the previous | 622 // objects as their associated "normal" request context. Thus, the previous | 
| 587 // call serves to initialize the media request context for this storage | 623 // call serves to initialize the media request context for this storage | 
| 588 // partition as well. | 624 // partition as well. | 
| 589 } | 625 } | 
| 590 } | 626 } | 
| 591 | 627 | 
| 628 scoped_ptr<CookieStoreMap> StoragePartitionImplMap::CreateCookieStores( | |
| 629 const base::FilePath& partition_path, | |
| 630 bool in_memory_partition, | |
| 631 bool is_default_partition) { | |
| 632 scoped_ptr<CookieStoreMap> cookie_store_map(new CookieStoreMap()); | |
| 633 std::map<std::string, CookieStoreConfig> cookie_store_configs; | |
| 634 cookie_store_configs[BrowserContext::kDefaultCookieScheme] = | |
| 635 CookieStoreConfig(); | |
| 636 | |
| 637 browser_context_->OverrideCookieStoreConfigs( | |
| 638 partition_path, in_memory_partition, is_default_partition, | |
| 639 &cookie_store_configs); | |
| 640 | |
| 641 for (std::map<std::string, CookieStoreConfig>::const_iterator it = | |
| 642 cookie_store_configs.begin(); | |
| 643 it != cookie_store_configs.end(); | |
| 644 ++it) { | |
| 645 scoped_refptr<net::CookieStore> cookie_store = | |
| 646 CreateCookieStore(it->second); | |
| 647 if (it->first == BrowserContext::kDefaultCookieScheme) { | |
| 648 cookie_store_map->SetForScheme(chrome::kHttpScheme, cookie_store); | |
| 649 cookie_store_map->SetForScheme(chrome::kHttpsScheme, cookie_store); | |
| 650 | |
| 651 // If file scheme is enabled, share the same cookie store as http. This is | |
| 652 // legacy behavior. A complete valid, alternate approach is to use a | |
| 653 // different cookie database. See comments inside CookieMonster about | |
| 654 // separating out file cookies into their own CookieMonster. | |
| 655 if ((cookie_store_configs.find(chrome::kFileScheme) == | |
| 656 cookie_store_configs.end()) | |
| 657 && cookie_store->GetCookieMonster()->IsCookieableScheme( | |
| 658 chrome::kFileScheme)) { | |
| 659 cookie_store_map->SetForScheme(chrome::kFileScheme, cookie_store); | |
| 660 } | |
| 661 } else { | |
| 662 const char* schemes[] = { it->first.c_str() }; | |
| 663 cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 1); | |
| 664 cookie_store_map->SetForScheme(it->first, cookie_store); | |
| 665 } | |
| 666 } | |
| 667 | |
| 668 return cookie_store_map.Pass(); | |
| 669 } | |
| 670 | |
| 592 } // namespace content | 671 } // namespace content | 
| OLD | NEW |