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

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

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change Cookie Override API to not expose the CookieStoreMap. Created 7 years, 4 months 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
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_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_impl.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
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
360 net::CookieStore* CreateInMemoryCookieStore(
361 const CookieStoreConfig& default_config,
362 bool is_default) {
363 // See CreatePersistentCookieStore for note about delegates and |is_default|.
364 if (is_default) {
365 return CreateCookieStore(
366 CookieStoreConfig::InMemoryWithOptions(
367 default_config.storage_policy, default_config.cookie_delegate));
368 } else {
369 return CreateCookieStore(CookieStoreConfig::InMemoryWithOptions(
370 default_config.storage_policy, NULL));
371 }
372 }
373
374 net::CookieStore* CreatePersistentCookieStore(
375 const CookieStoreConfig& default_config,
376 const base::FilePath& partition_path,
377 bool is_default) {
378 // Cookie delegates are not used in the non-default partition. If support
379 // is to be added for other partitions, then the delegate must be modified
380 // so it knows which partition cookie changes are sourcing from.
381 if (is_default) {
382 return CreateCookieStore(default_config);
383 } else {
384 return CreateCookieStore(
385 CookieStoreConfig::Persistent(
386 partition_path.Append(kCookieFilename),
387 default_config.session_cookie_mode));
388 }
389 }
390
349 } // namespace 391 } // namespace
350 392
351 // static 393 // static
352 base::FilePath StoragePartitionImplMap::GetStoragePartitionPath( 394 base::FilePath StoragePartitionImplMap::GetStoragePartitionPath(
353 const std::string& partition_domain, 395 const std::string& partition_domain,
354 const std::string& partition_name) { 396 const std::string& partition_name) {
355 if (partition_domain.empty()) 397 if (partition_domain.empty())
356 return base::FilePath(); 398 return base::FilePath();
357 399
358 base::FilePath path = GetStoragePartitionDomainPath(partition_domain); 400 base::FilePath path = GetStoragePartitionDomainPath(partition_domain);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 StoragePartitionConfig partition_config( 438 StoragePartitionConfig partition_config(
397 partition_domain, partition_name, in_memory); 439 partition_domain, partition_name, in_memory);
398 440
399 PartitionMap::const_iterator it = partitions_.find(partition_config); 441 PartitionMap::const_iterator it = partitions_.find(partition_config);
400 if (it != partitions_.end()) 442 if (it != partitions_.end())
401 return it->second; 443 return it->second;
402 444
403 base::FilePath partition_path = 445 base::FilePath partition_path =
404 browser_context_->GetPath().Append( 446 browser_context_->GetPath().Append(
405 GetStoragePartitionPath(partition_domain, partition_name)); 447 GetStoragePartitionPath(partition_domain, partition_name));
448
449 // TODO(ajwong): How does default_config.in_memory work?
450 // bool in_memory_cookies = in_memory; // || default_config.in_memory;
451 // Create the cookie stores.
452 scoped_ptr<CookieStoreMapImpl> cookie_store_map(
453 CreateCookieStores(partition_path,
454 in_memory,
455 partition_domain.empty()));
456
406 StoragePartitionImpl* partition = 457 StoragePartitionImpl* partition =
407 StoragePartitionImpl::Create(browser_context_, in_memory, 458 StoragePartitionImpl::Create(browser_context_, in_memory,
408 partition_path); 459 partition_path, cookie_store_map.Pass());
409 partitions_[partition_config] = partition; 460 partitions_[partition_config] = partition;
410 461
411 ChromeBlobStorageContext* blob_storage_context = 462 ChromeBlobStorageContext* blob_storage_context =
412 ChromeBlobStorageContext::GetFor(browser_context_); 463 ChromeBlobStorageContext::GetFor(browser_context_);
413 StreamContext* stream_context = StreamContext::GetFor(browser_context_); 464 StreamContext* stream_context = StreamContext::GetFor(browser_context_);
414 ProtocolHandlerMap protocol_handlers; 465 ProtocolHandlerMap protocol_handlers;
415 protocol_handlers[chrome::kBlobScheme] = 466 protocol_handlers[chrome::kBlobScheme] =
416 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( 467 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
417 new BlobProtocolHandler(blob_storage_context, 468 new BlobProtocolHandler(blob_storage_context,
418 stream_context, 469 stream_context,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 // TODO(ajwong): ResourceContexts no longer have any storage related state. 612 // TODO(ajwong): ResourceContexts no longer have any storage related state.
562 // We should move this into a place where it is called once per 613 // We should move this into a place where it is called once per
563 // BrowserContext creation rather than piggybacking off the default context 614 // BrowserContext creation rather than piggybacking off the default context
564 // creation. 615 // creation.
565 // Note: moving this into Get() before partitions_[] is set causes reentrency. 616 // Note: moving this into Get() before partitions_[] is set causes reentrency.
566 if (!resource_context_initialized_) { 617 if (!resource_context_initialized_) {
567 resource_context_initialized_ = true; 618 resource_context_initialized_ = true;
568 InitializeResourceContext(browser_context_); 619 InitializeResourceContext(browser_context_);
569 } 620 }
570 621
571 // Check first to avoid memory leak in unittests. 622 // In unittests, BrowserThread::IO may not be valid which would yield a
572 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { 623 // memory leak on a PostTask. Also, in content_unittests, the
624 // URLRequestContext is NULL.
625 //
626 // TODO(ajwong): Should default ContentBrowserClient return a non-null
627 // URLRequestContext?
628 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) &&
629 partition->GetURLRequestContext()) {
630 // The main URLRequestContextGetter was first created just before
631 // PostCreateInitialization() is called thus attaching the CookieStore here
632 // is guaranteed to occur before anyone else can see the main request
633 // context including the media request context.
634 BrowserThread::PostTask(
635 BrowserThread::IO, FROM_HERE,
636 base::Bind(&AttachCookieStoreOnIOThread,
637 make_scoped_refptr(partition->GetURLRequestContext()),
638 make_scoped_refptr(
639 partition->GetCookieStoreMap().GetForScheme(
640 chrome::kHttpScheme))));
641
573 BrowserThread::PostTask( 642 BrowserThread::PostTask(
574 BrowserThread::IO, FROM_HERE, 643 BrowserThread::IO, FROM_HERE,
575 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, 644 base::Bind(&ChromeAppCacheService::InitializeOnIOThread,
576 partition->GetAppCacheService(), 645 partition->GetAppCacheService(),
577 in_memory ? base::FilePath() : 646 in_memory ? base::FilePath() :
578 partition->GetPath().Append(kAppCacheDirname), 647 partition->GetPath().Append(kAppCacheDirname),
579 browser_context_->GetResourceContext(), 648 browser_context_->GetResourceContext(),
580 make_scoped_refptr(partition->GetURLRequestContext()), 649 make_scoped_refptr(partition->GetURLRequestContext()),
581 make_scoped_refptr( 650 make_scoped_refptr(
582 browser_context_->GetSpecialStoragePolicy()))); 651 browser_context_->GetSpecialStoragePolicy())));
583 652
584 // We do not call InitializeURLRequestContext() for media contexts because, 653 // We do not initialize the AppCacheService for media contexts because,
585 // other than the HTTP cache, the media contexts share the same backing 654 // other than the HTTP cache, the media contexts share the same backing
586 // objects as their associated "normal" request context. Thus, the previous 655 // objects as their associated "normal" request context. Thus, the previous
587 // call serves to initialize the media request context for this storage 656 // call serves to initialize the media request context for this storage
588 // partition as well. 657 // partition as well.
589 } 658 }
590 } 659 }
591 660
661 scoped_ptr<CookieStoreMapImpl> StoragePartitionImplMap::CreateCookieStores(
662 const base::FilePath& partition_path,
663 bool in_memory_partition,
664 bool is_default_partition) {
665 scoped_ptr<CookieStoreMapImpl> cookie_store_map(new CookieStoreMapImpl());
666 std::map<std::string, CookieStoreConfig> cookie_store_configs;
667 cookie_store_configs[BrowserContext::kDefaultCookieScheme]
668 = CookieStoreConfig::InMemory();
669
670 browser_context_->OverrideCookieStoreConfigs(
671 partition_path, in_memory_partition, is_default_partition,
672 &cookie_store_configs);
673
674 for (std::map<std::string, CookieStoreConfig>::const_iterator it =
675 cookie_store_configs.begin();
676 it != cookie_store_configs.end();
677 ++it) {
678 scoped_refptr<net::CookieStore> cookie_store = CreateCookieStore(it->second) ;
679 if (it->first == BrowserContext::kDefaultCookieScheme) {
680 cookie_store_map->SetForScheme(chrome::kHttpScheme, cookie_store);
681 cookie_store_map->SetForScheme(chrome::kHttpsScheme, cookie_store);
682
683 // If file scheme is enabled, share the same cookie store as http. This is
684 // legacy behavior. A complete valid, alternate approach is to use a
685 // different cookie database. See comments inside CookieMonster about
686 // separating out file cookies into their own CookieMonster.
687 if (cookie_store_configs.find(chrome::kFileScheme) == cookie_store_configs .end()
688 && cookie_store->GetCookieMonster()->IsCookieableScheme(
689 chrome::kFileScheme)) {
690 cookie_store_map->SetForScheme(chrome::kFileScheme, cookie_store);
691 }
692 } else {
693 const char* schemes[] = { it->first.c_str() };
694 cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 1);
695 cookie_store_map->SetForScheme(it->first, cookie_store);
696 }
697 }
698
699 return cookie_store_map.Pass();
700 }
701
592 } // namespace content 702 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/storage_partition_impl_map.h ('k') | content/browser/storage_partition_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698