profile_impl_io_data.cc revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_impl_io_data.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/metrics/field_trial.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_member.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/sequenced_task_runner.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/stl_util.h" 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/threading/sequenced_worker_pool.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/worker_pool.h" 187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/custom_handlers/protocol_handler_registry.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/io_thread.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/net/chrome_net_log.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/net/chrome_network_delegate.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/net/connect_interceptor.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/net/http_server_properties_manager.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/net/predictor.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/net/sqlite_server_bound_cert_store.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_constants.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/url_constants.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/browser_thread.h" 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/public/browser/cookie_store_factory.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/resource_context.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/storage_partition.h" 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "extensions/common/constants.h" 39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "net/base/cache_type.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/ftp/ftp_network_layer.h" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_cache.h" 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/ssl/server_bound_cert_service.h" 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/url_request/protocol_intercept_job_factory.h" 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_job_factory_impl.h" 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "webkit/browser/quota/special_storage_policy.h" 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_ANDROID) 4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/app/android/chrome_data_reduction_proxy_android.h" 4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif 5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 51a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace { 52a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 53a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)net::BackendType ChooseCacheBackendType() { 54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { 56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const std::string opt_value = 57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); 58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) if (LowerCaseEqualsASCII(opt_value, "off")) 59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return net::CACHE_BACKEND_BLOCKFILE; 60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) 61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return net::CACHE_BACKEND_SIMPLE; 62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const std::string experiment_name = 64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) base::FieldTrialList::FindFullName("SimpleCacheTrial"); 65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) if (experiment_name == "ExperimentYes" || 66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) experiment_name == "ExperimentYes2") { 67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return net::CACHE_BACKEND_SIMPLE; 68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return net::CACHE_BACKEND_BLOCKFILE; 70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 71a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 72a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} // namespace 73a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::BrowserThread; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::Handle::Handle(Profile* profile) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : io_data_(new ProfileImplIOData), 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) profile_(profile), 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) initialized_(false) { 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(profile); 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::Handle::~Handle() { 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 86b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) if (io_data_->predictor_ != NULL) { 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // io_data_->predictor_ might be NULL if Init() was never called 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (i.e. we shut down before ProfileImpl::DoFinalInit() got called). 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PrefService* user_prefs = profile_->GetPrefs(); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->predictor_->ShutdownOnUIThread(user_prefs); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (io_data_->http_server_properties_manager_) 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) io_data_->http_server_properties_manager_->ShutdownOnUIThread(); 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->ShutdownOnUIThread(); 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ProfileImplIOData::Handle::Init( 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& cookie_path, 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& server_bound_cert_path, 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& cache_path, 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int cache_max_size, 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& media_cache_path, 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int media_cache_max_size, 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& extensions_cookie_path, 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path, 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& infinite_cache_path, 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome_browser_net::Predictor* predictor, 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool restore_old_session_cookies, 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) quota::SpecialStoragePolicy* special_storage_policy) { 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 112b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) DCHECK(!io_data_->lazy_params_); 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(predictor); 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LazyParams* lazy_params = new LazyParams; 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->cookie_path = cookie_path; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->server_bound_cert_path = server_bound_cert_path; 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->cache_path = cache_path; 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->cache_max_size = cache_max_size; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->media_cache_path = media_cache_path; 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->media_cache_max_size = media_cache_max_size; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->extensions_cookie_path = extensions_cookie_path; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->infinite_cache_path = infinite_cache_path; 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->restore_old_session_cookies = restore_old_session_cookies; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params->special_storage_policy = special_storage_policy; 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->lazy_params_.reset(lazy_params); 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Keep track of profile path and cache sizes separately so we can use them 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on demand when creating storage isolated URLRequestContextGetters. 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->profile_path_ = profile_path; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->app_cache_max_size_ = cache_max_size; 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->app_media_cache_max_size_ = media_cache_max_size; 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->predictor_.reset(predictor); 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->InitializeMetricsEnabledStateOnUIThread(); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)content::ResourceContext* 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProfileImplIOData::Handle::GetResourceContext() const { 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LazyInitialize(); 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return GetResourceContextNoInit(); 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)content::ResourceContext* 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::Handle::GetResourceContextNoInit() const { 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't call LazyInitialize here, since the resource context is created at 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the beginning of initalization and is used by some members while they're 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // being initialized (i.e. AppCacheService). 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return io_data_->GetResourceContext(); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_refptr<ChromeURLRequestContextGetter> 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ProfileImplIOData::Handle::CreateMainRequestContextGetter( 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::ProtocolHandlerMap* protocol_handlers, 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PrefService* local_state, 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) IOThread* io_thread) const { 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LazyInitialize(); 164868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DCHECK(!main_request_context_getter_.get()); 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) main_request_context_getter_ = ChromeURLRequestContextGetter::CreateOriginal( 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile_, io_data_, protocol_handlers); 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) io_data_->predictor_ 169868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ->InitNetworkPredictor(profile_->GetPrefs(), 170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) local_state, 171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) io_thread, 172868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) main_request_context_getter_.get()); 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::NotificationService::current()->Notify( 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::Source<Profile>(profile_), 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::NotificationService::NoDetails()); 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return main_request_context_getter_; 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_refptr<ChromeURLRequestContextGetter> 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::Handle::GetMediaRequestContextGetter() const { 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LazyInitialize(); 185868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!media_request_context_getter_.get()) { 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) media_request_context_getter_ = 187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ChromeURLRequestContextGetter::CreateOriginalForMedia(profile_, 188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) io_data_); 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return media_request_context_getter_; 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_refptr<ChromeURLRequestContextGetter> 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::Handle::GetExtensionsRequestContextGetter() const { 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LazyInitialize(); 197868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!extensions_request_context_getter_.get()) { 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extensions_request_context_getter_ = 199868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ChromeURLRequestContextGetter::CreateOriginalForExtensions(profile_, 200868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) io_data_); 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return extensions_request_context_getter_; 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_refptr<ChromeURLRequestContextGetter> 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& partition_path, 2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool in_memory, 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::ProtocolHandlerMap* protocol_handlers) const { 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check that the partition_path is not the same as the base profile path. We 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // expect isolated partition, which will never go to the default profile path. 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(partition_path != profile_->GetPath()); 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LazyInitialize(); 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Keep a map of request context getters, one per requested storage partition. 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StoragePartitionDescriptor descriptor(partition_path, in_memory); 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContextGetterMap::iterator iter = 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app_request_context_getter_map_.find(descriptor); 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (iter != app_request_context_getter_map_.end()) 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return iter->second; 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protocol_handler_interceptor( 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateJobInterceptorFactory()); 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContextGetter* context = 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) profile_, io_data_, descriptor, 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protocol_handler_interceptor.Pass(), 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protocol_handlers); 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app_request_context_getter_map_[descriptor] = context; 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return context; 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_refptr<ChromeURLRequestContextGetter> 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& partition_path, 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool in_memory) const { 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We must have a non-default path, or this will act like the default media 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // context. 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(partition_path != profile_->GetPath()); 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LazyInitialize(); 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Keep a map of request context getters, one per requested storage partition. 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StoragePartitionDescriptor descriptor(partition_path, in_memory); 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContextGetterMap::iterator iter = 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) isolated_media_request_context_getter_map_.find(descriptor); 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (iter != isolated_media_request_context_getter_map_.end()) 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return iter->second; 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the app context as the starting point for the media context, so that 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it uses the app's cookie store. 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ChromeURLRequestContextGetterMap::const_iterator app_iter = 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) app_request_context_getter_map_.find(descriptor); 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(app_iter != app_request_context_getter_map_.end()); 259868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ChromeURLRequestContextGetter* app_context = app_iter->second.get(); 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContextGetter* context = 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) profile_, app_context, io_data_, descriptor); 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) isolated_media_request_context_getter_map_[descriptor] = context; 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return context; 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ProfileImplIOData::Handle::ClearNetworkingHistorySince( 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time time, 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Closure& completion) { 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LazyInitialize(); 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserThread::PostTask( 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserThread::IO, FROM_HERE, 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind( 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread, 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(io_data_), 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) time, 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) completion)); 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ProfileImplIOData::Handle::LazyInitialize() const { 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (initialized_) 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set initialized_ to true at the beginning in case any of the objects 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // below try to get the ResourceContext pointer. 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) initialized_ = true; 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PrefService* pref_service = profile_->GetPrefs(); 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) io_data_->http_server_properties_manager_ = 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new chrome_browser_net::HttpServerPropertiesManager(pref_service); 2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) io_data_->set_http_server_properties( 294ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch scoped_ptr<net::HttpServerProperties>( 295ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch io_data_->http_server_properties_manager_)); 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->session_startup_pref()->Init( 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs::kRestoreOnStartup, pref_service); 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->session_startup_pref()->MoveToThread( 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled, 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_service); 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->safe_browsing_enabled()->MoveToThread( 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_data_->InitializeOnUIThread(profile_); 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::LazyParams::LazyParams() 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : cache_max_size(0), 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) media_cache_max_size(0), 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) restore_old_session_cookies(false) {} 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::LazyParams::~LazyParams() {} 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::ProfileImplIOData() 3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : ProfileIOData(false), 3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) http_server_properties_manager_(NULL) {} 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::~ProfileImplIOData() { 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DestroyResourceContext(); 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 322b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) if (media_request_context_) 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) media_request_context_->AssertNoURLRequests(); 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ProfileImplIOData::InitializeInternal( 3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ProfileParams* profile_params, 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::ProtocolHandlerMap* protocol_handlers) const { 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContext* main_context = main_request_context(); 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IOThread* const io_thread = profile_params->io_thread; 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IOThread::Globals* const io_thread_globals = io_thread->globals(); 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Only allow Record Mode if we are in a Debug build or where we are running 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a cycle, and the user has limited control. 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool record_mode = command_line.HasSwitch(switches::kRecordMode) && 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (chrome::kRecordModeEnabled || 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) command_line.HasSwitch(switches::kVisitURLs)); 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) network_delegate()->set_predictor(predictor_.get()); 3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initialize context members. 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ApplyProfileParamsToContext(main_context); 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (http_server_properties_manager_) 3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) http_server_properties_manager_->InitializeOnIOThread(); 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_transport_security_state(transport_security_state()); 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_net_log(io_thread->net_log()); 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_network_delegate(network_delegate()); 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) main_context->set_http_server_properties(http_server_properties()); 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_host_resolver( 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_thread_globals->host_resolver.get()); 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_http_auth_handler_factory( 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_thread_globals->http_auth_handler_factory.get()); 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_fraudulent_certificate_reporter( 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) fraudulent_certificate_reporter()); 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_throttler_manager( 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) io_thread_globals->throttler_manager.get()); 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_proxy_service(proxy_service()); 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<net::CookieStore> cookie_store = NULL; 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::ServerBoundCertService* server_bound_cert_service = NULL; 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (record_mode || playback_mode) { 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't use existing cookies and use an in-memory store. 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cookie_store = new net::CookieMonster( 376868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL, profile_params->cookie_monster_delegate.get()); 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't use existing server-bound certs and use an in-memory store. 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) server_bound_cert_service = new net::ServerBoundCertService( 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new net::DefaultServerBoundCertStore(NULL), 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::WorkerPool::GetTaskRunner(true)); 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // setup cookie store 384868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!cookie_store.get()) { 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(!lazy_params_->cookie_path.empty()); 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 387c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) cookie_store = content::CreatePersistentCookieStore( 388c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) lazy_params_->cookie_path, 389c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) lazy_params_->restore_old_session_cookies, 390868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) lazy_params_->special_storage_policy.get(), 391868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) profile_params->cookie_monster_delegate.get()); 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) main_context->set_cookie_store(cookie_store.get()); 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Setup server bound cert service. 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!server_bound_cert_service) { 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(!lazy_params_->server_bound_cert_path.empty()); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new SQLiteServerBoundCertStore( 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params_->server_bound_cert_path, 404868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) lazy_params_->special_storage_policy.get()); 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) server_bound_cert_service = new net::ServerBoundCertService( 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::WorkerPool::GetTaskRunner(true)); 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) set_server_bound_cert_service(server_bound_cert_service); 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_server_bound_cert_service(server_bound_cert_service); 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::HttpCache::DefaultBackend* main_backend = 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new net::HttpCache::DefaultBackend( 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::DISK_CACHE, 416a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) ChooseCacheBackendType(), 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params_->cache_path, 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) lazy_params_->cache_max_size, 4197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE) 4207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) .get()); 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::HttpNetworkSession::Params network_session_params; 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PopulateNetworkSessionParams(profile_params, &network_session_params); 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::HttpCache* main_cache = new net::HttpCache( 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) network_session_params, main_backend); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_cache->InitializeInfiniteCache(lazy_params_->infinite_cache_path); 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 42790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_ANDROID) 42890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ChromeDataReductionProxyAndroid::Init(main_cache->GetSession()); 42990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif 43090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (record_mode || playback_mode) { 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_cache->set_mode( 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_http_factory_.reset(main_cache); 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_context->set_http_transaction_factory(main_cache); 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(DISABLE_FTP_SUPPORT) 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ftp_factory_.reset( 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // !defined(DISABLE_FTP_SUPPORT) 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new net::URLRequestJobFactoryImpl()); 4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); 4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) main_job_factory_ = SetUpJobFactoryDefaults( 4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) main_job_factory.Pass(), 4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile_params->protocol_handler_interceptor.Pass(), 4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) network_delegate(), 451b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ftp_factory_.get()); 4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) main_context->set_job_factory(main_job_factory_.get()); 4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(ENABLE_EXTENSIONS) 4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitializeExtensionsRequestContext(profile_params); 4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Create a media request context based on the main context, but using a 4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // media cache. It shares the same job factory as the main context. 4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoragePartitionDescriptor details(profile_path_, false); 4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) media_request_context_.reset(InitializeMediaRequestContext(main_context, 4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) details)); 4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) lazy_params_.reset(); 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ProfileImplIOData:: 4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitializeExtensionsRequestContext(ProfileParams* profile_params) const { 4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ChromeURLRequestContext* extensions_context = extensions_request_context(); 4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) IOThread* const io_thread = profile_params->io_thread; 4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) IOThread::Globals* const io_thread_globals = io_thread->globals(); 4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ApplyProfileParamsToContext(extensions_context); 4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions_context->set_transport_security_state(transport_security_state()); 4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions_context->set_net_log(io_thread->net_log()); 4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions_context->set_throttler_manager( 4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) io_thread_globals->throttler_manager.get()); 4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 481c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) net::CookieStore* extensions_cookie_store = 482c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::CreatePersistentCookieStore( 483c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) lazy_params_->extensions_cookie_path, 484c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) lazy_params_->restore_old_session_cookies, 485c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NULL, 486c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NULL); 4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Enable cookies for devtools and extension URLs. 4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* schemes[] = {chrome::kChromeDevToolsScheme, 4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions::kExtensionScheme}; 490c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); 4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions_context->set_cookie_store(extensions_cookie_store); 4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new net::URLRequestJobFactoryImpl()); 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Without a network_delegate, this protocol handler will never 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // handle file: requests, but as a side effect it makes 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // job_factory::IsHandledProtocol return true, which prevents attempts to 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // handle the protocol externally. We pass NULL in to 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetUpJobFactory() to get this effect. 5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions_job_factory_ = SetUpJobFactoryDefaults( 5022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions_job_factory.Pass(), 5037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), 5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NULL, 505b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ftp_factory_.get()); 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extensions_context->set_job_factory(extensions_job_factory_.get()); 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeURLRequestContext* 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::InitializeAppRequestContext( 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContext* main_context, 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const StoragePartitionDescriptor& partition_descriptor, 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protocol_handler_interceptor, 5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::ProtocolHandlerMap* protocol_handlers) const { 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Copy most state from the main context. 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AppRequestContext* context = new AppRequestContext(load_time_stats()); 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) context->CopyFrom(main_context); 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath cookie_path = partition_descriptor.path.Append( 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::kCookieFilename); 5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath cache_path = 5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) partition_descriptor.path.Append(chrome::kCacheDirname); 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Only allow Record Mode if we are in a Debug build or where we are running 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a cycle, and the user has limited control. 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool record_mode = command_line.HasSwitch(switches::kRecordMode) && 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (chrome::kRecordModeEnabled || 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) command_line.HasSwitch(switches::kVisitURLs)); 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use a separate HTTP disk cache for isolated apps. 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::HttpCache::BackendFactory* app_backend = NULL; 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (partition_descriptor.in_memory) { 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app_backend = net::HttpCache::DefaultBackend::InMemory(0); 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app_backend = new net::HttpCache::DefaultBackend( 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::DISK_CACHE, 540a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) ChooseCacheBackendType(), 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cache_path, 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app_cache_max_size_, 5437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE) 5447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) .get()); 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::HttpNetworkSession* main_network_session = 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_http_factory_->GetSession(); 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::HttpCache* app_http_cache = 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new net::HttpCache(main_network_session, app_backend); 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<net::CookieStore> cookie_store = NULL; 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (partition_descriptor.in_memory) { 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cookie_store = new net::CookieMonster(NULL, NULL); 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else if (record_mode || playback_mode) { 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't use existing cookies and use an in-memory store. 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(creis): We should have a cookie delegate for notifying the cookie 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // extensions API, but we need to update it to understand isolated apps 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // first. 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cookie_store = new net::CookieMonster(NULL, NULL); 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app_http_cache->set_mode( 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use an app-specific cookie store. 565868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!cookie_store.get()) { 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(!cookie_path.empty()); 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(creis): We should have a cookie delegate for notifying the cookie 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // extensions API, but we need to update it to understand isolated apps 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // first. 571c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) cookie_store = content::CreatePersistentCookieStore( 572c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) cookie_path, 573c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) false, 574c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NULL, 575c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NULL); 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Transfer ownership of the cookies and cache to AppRequestContext. 579868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) context->SetCookieStore(cookie_store.get()); 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) context->SetHttpTransactionFactory( 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( 5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new net::URLRequestJobFactoryImpl()); 5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InstallProtocolHandlers(job_factory.get(), protocol_handlers); 5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<net::URLRequestJobFactory> top_job_factory; 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overwrite the job factory that we inherit from the main context so 5882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // that we can later provide our own handlers for storage related protocols. 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Install all the usual protocol handlers unless we are in a browser plugin 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // guest process, in which case only web-safe schemes are allowed. 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!partition_descriptor.in_memory) { 5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) top_job_factory = SetUpJobFactoryDefaults( 5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) job_factory.Pass(), protocol_handler_interceptor.Pass(), 5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) network_delegate(), 595b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ftp_factory_.get()); 5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) top_job_factory = job_factory.PassAs<net::URLRequestJobFactory>(); 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) context->SetJobFactory(top_job_factory.Pass()); 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return context; 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeURLRequestContext* 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::InitializeMediaRequestContext( 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContext* original_context, 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const StoragePartitionDescriptor& partition_descriptor) const { 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If this is for a in_memory partition, we can simply use the original 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // context (like off-the-record mode). 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (partition_descriptor.in_memory) 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return original_context; 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Copy most state from the original context. 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaRequestContext* context = new MediaRequestContext(load_time_stats()); 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) context->CopyFrom(original_context); 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) using content::StoragePartition; 6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath cache_path; 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int cache_max_size = app_media_cache_max_size_; 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (partition_descriptor.path == profile_path_) { 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // lazy_params_ is only valid for the default media context creation. 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cache_path = lazy_params_->media_cache_path; 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cache_max_size = lazy_params_->media_cache_max_size; 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cache_path = partition_descriptor.path.Append(chrome::kMediaCacheDirname); 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use a separate HTTP disk cache for isolated apps. 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::HttpCache::BackendFactory* media_backend = 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new net::HttpCache::DefaultBackend( 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::MEDIA_CACHE, 632a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) ChooseCacheBackendType(), 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cache_path, 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cache_max_size, 6357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE) 6367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) .get()); 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::HttpNetworkSession* main_network_session = 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) main_http_factory_->GetSession(); 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<net::HttpTransactionFactory> media_http_cache( 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new net::HttpCache(main_network_session, media_backend)); 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Transfer ownership of the cache to MediaRequestContext. 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) context->SetHttpTransactionFactory(media_http_cache.Pass()); 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note that we do not create a new URLRequestJobFactory because 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the media context should behave exactly like its parent context 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in all respects except for cache behavior on media subresources. 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The CopyFrom() step above means that our media context will use 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the same URLRequestJobFactory instance that our parent context does. 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return context; 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeURLRequestContext* 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::AcquireMediaRequestContext() const { 656b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) DCHECK(media_request_context_); 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return media_request_context_.get(); 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeURLRequestContext* 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::AcquireIsolatedAppRequestContext( 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContext* main_context, 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const StoragePartitionDescriptor& partition_descriptor, 6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protocol_handler_interceptor, 6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::ProtocolHandlerMap* protocol_handlers) const { 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We create per-app contexts on demand, unlike the others above. 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContext* app_request_context = 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InitializeAppRequestContext(main_context, partition_descriptor, 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protocol_handler_interceptor.Pass(), 6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protocol_handlers); 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(app_request_context); 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return app_request_context; 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeURLRequestContext* 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ProfileImplIOData::AcquireIsolatedMediaRequestContext( 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContext* app_context, 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const StoragePartitionDescriptor& partition_descriptor) const { 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We create per-app media contexts on demand, unlike the others above. 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeURLRequestContext* media_request_context = 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InitializeMediaRequestContext(app_context, partition_descriptor); 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(media_request_context); 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return media_request_context; 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IOThread::Globals* io_thread_globals) const { 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return io_thread_globals->load_time_stats.get(); 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time time, 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Closure& completion) { 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(initialized()); 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(transport_security_state()); 6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Completes synchronously. 7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) transport_security_state()->DeleteAllDynamicDataSince(time); 7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(http_server_properties_manager_); 7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) http_server_properties_manager_->Clear(completion); 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 704