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
3 // found in the LICENSE file.
5 #include "chrome/browser/profiles/profile_io_data.h"
9 #include "base/basictypes.h"
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/callback.h"
13 #include "base/command_line.h"
14 #include "base/compiler_specific.h"
15 #include "base/debug/alias.h"
16 #include "base/logging.h"
17 #include "base/path_service.h"
18 #include "base/prefs/pref_service.h"
19 #include "base/stl_util.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h"
23 #include "base/thread_task_runner_handle.h"
24 #include "base/threading/sequenced_worker_pool.h"
25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/content_settings/cookie_settings_factory.h"
28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
29 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
30 #include "chrome/browser/devtools/devtools_network_controller.h"
31 #include "chrome/browser/devtools/devtools_network_transaction_factory.h"
32 #include "chrome/browser/download/download_service.h"
33 #include "chrome/browser/download/download_service_factory.h"
34 #include "chrome/browser/io_thread.h"
35 #include "chrome/browser/media/media_device_id_salt.h"
36 #include "chrome/browser/net/chrome_http_user_agent_settings.h"
37 #include "chrome/browser/net/chrome_net_log.h"
38 #include "chrome/browser/net/chrome_network_delegate.h"
39 #include "chrome/browser/net/chrome_url_request_context_getter.h"
40 #include "chrome/browser/net/cookie_store_util.h"
41 #include "chrome/browser/net/proxy_service_factory.h"
42 #include "chrome/browser/net/resource_prefetch_predictor_observer.h"
43 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
44 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
45 #include "chrome/browser/profiles/profile.h"
46 #include "chrome/browser/profiles/profile_manager.h"
47 #include "chrome/browser/ui/search/new_tab_page_interceptor_service.h"
48 #include "chrome/browser/ui/search/new_tab_page_interceptor_service_factory.h"
49 #include "chrome/common/chrome_paths.h"
50 #include "chrome/common/chrome_switches.h"
51 #include "chrome/common/pref_names.h"
52 #include "chrome/common/url_constants.h"
53 #include "components/about_handler/about_protocol_handler.h"
54 #include "components/content_settings/core/browser/content_settings_provider.h"
55 #include "components/content_settings/core/browser/cookie_settings.h"
56 #include "components/content_settings/core/browser/host_content_settings_map.h"
57 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
58 #include "components/dom_distiller/core/url_constants.h"
59 #include "components/sync_driver/pref_names.h"
60 #include "components/url_formatter/url_fixer.h"
61 #include "content/public/browser/browser_thread.h"
62 #include "content/public/browser/host_zoom_map.h"
63 #include "content/public/browser/notification_service.h"
64 #include "content/public/browser/resource_context.h"
65 #include "net/base/keygen_handler.h"
66 #include "net/cert/cert_verifier.h"
67 #include "net/cookies/canonical_cookie.h"
68 #include "net/http/http_transaction_factory.h"
69 #include "net/http/http_util.h"
70 #include "net/http/transport_security_persister.h"
71 #include "net/proxy/proxy_config_service_fixed.h"
72 #include "net/proxy/proxy_script_fetcher_impl.h"
73 #include "net/proxy/proxy_service.h"
74 #include "net/ssl/channel_id_service.h"
75 #include "net/ssl/client_cert_store.h"
76 #include "net/url_request/certificate_report_sender.h"
77 #include "net/url_request/data_protocol_handler.h"
78 #include "net/url_request/file_protocol_handler.h"
79 #include "net/url_request/ftp_protocol_handler.h"
80 #include "net/url_request/url_request.h"
81 #include "net/url_request/url_request_context.h"
82 #include "net/url_request/url_request_context_builder.h"
83 #include "net/url_request/url_request_file_job.h"
84 #include "net/url_request/url_request_intercepting_job_factory.h"
85 #include "net/url_request/url_request_interceptor.h"
86 #include "net/url_request/url_request_job_factory_impl.h"
88 #if defined(ENABLE_CONFIGURATION_POLICY)
89 #include "chrome/browser/policy/cloud/policy_header_service_factory.h"
90 #include "chrome/browser/policy/policy_helpers.h"
91 #include "components/policy/core/browser/url_blacklist_manager.h"
92 #include "components/policy/core/common/cloud/policy_header_io_helper.h"
93 #include "components/policy/core/common/cloud/policy_header_service.h"
94 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
97 #if defined(ENABLE_EXTENSIONS)
98 #include "chrome/browser/extensions/extension_cookie_monster_delegate.h"
99 #include "chrome/browser/extensions/extension_resource_protocols.h"
100 #include "extensions/browser/extension_protocols.h"
101 #include "extensions/browser/extension_system.h"
102 #include "extensions/browser/extension_throttle_manager.h"
103 #include "extensions/browser/info_map.h"
104 #include "extensions/common/constants.h"
107 #if defined(ENABLE_SUPERVISED_USERS)
108 #include "chrome/browser/supervised_user/supervised_user_service.h"
109 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
110 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
113 #if defined(OS_ANDROID)
114 #include "content/public/browser/android/content_protocol_handler.h"
115 #endif // defined(OS_ANDROID)
117 #if defined(OS_CHROMEOS)
118 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h"
119 #include "chrome/browser/chromeos/fileapi/external_file_protocol_handler.h"
120 #include "chrome/browser/chromeos/login/startup_utils.h"
121 #include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
122 #include "chrome/browser/chromeos/net/client_cert_filter_chromeos.h"
123 #include "chrome/browser/chromeos/net/client_cert_store_chromeos.h"
124 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
125 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
126 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
127 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
128 #include "chrome/browser/chromeos/profiles/profile_helper.h"
129 #include "chrome/browser/chromeos/settings/cros_settings.h"
130 #include "chrome/browser/net/nss_context.h"
131 #include "chromeos/dbus/dbus_thread_manager.h"
132 #include "chromeos/settings/cros_settings_names.h"
133 #include "chromeos/tpm/tpm_token_info_getter.h"
134 #include "components/user_manager/user.h"
135 #include "components/user_manager/user_manager.h"
136 #include "crypto/nss_util.h"
137 #include "crypto/nss_util_internal.h"
138 #include "net/cert/cert_verifier.h"
139 #include "net/cert/multi_threaded_cert_verifier.h"
140 #endif // defined(OS_CHROMEOS)
142 #if defined(USE_NSS_CERTS)
143 #include "chrome/browser/ui/crypto_module_delegate_nss.h"
144 #include "net/ssl/client_cert_store_nss.h"
148 #include "net/ssl/client_cert_store_win.h"
151 #if defined(OS_MACOSX)
152 #include "net/ssl/client_cert_store_mac.h"
155 using content::BrowserContext
;
156 using content::BrowserThread
;
157 using content::ResourceContext
;
161 net::CertVerifier
* g_cert_verifier_for_testing
= nullptr;
163 #if defined(DEBUG_DEVTOOLS)
164 bool IsSupportedDevToolsURL(const GURL
& url
, base::FilePath
* path
) {
165 std::string
bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath
);
166 bundled_path_prefix
= "/" + bundled_path_prefix
+ "/";
168 if (!url
.SchemeIs(content::kChromeDevToolsScheme
) ||
169 url
.host() != chrome::kChromeUIDevToolsHost
||
170 !base::StartsWith(url
.path(), bundled_path_prefix
,
171 base::CompareCase::INSENSITIVE_ASCII
)) {
175 if (!url
.is_valid()) {
180 // Remove Query and Ref from URL.
182 GURL::Replacements replacements
;
183 replacements
.ClearQuery();
184 replacements
.ClearRef();
185 stripped_url
= url
.ReplaceComponents(replacements
);
187 std::string relative_path
;
188 const std::string
& spec
= stripped_url
.possibly_invalid_spec();
189 const url::Parsed
& parsed
= stripped_url
.parsed_for_possibly_invalid_spec();
190 int offset
= parsed
.CountCharactersBefore(url::Parsed::PATH
, false);
191 if (offset
< static_cast<int>(spec
.size()))
192 relative_path
.assign(spec
.substr(offset
+ bundled_path_prefix
.length()));
194 // Check that |relative_path| is not an absolute path (otherwise
195 // AppendASCII() will DCHECK). The awkward use of StringType is because on
196 // some systems FilePath expects a std::string, but on others a std::wstring.
198 base::FilePath::StringType(relative_path
.begin(), relative_path
.end()));
202 base::FilePath inspector_dir
;
203 if (!PathService::Get(chrome::DIR_INSPECTOR
, &inspector_dir
))
206 if (inspector_dir
.empty())
209 *path
= inspector_dir
.AppendASCII(relative_path
);
213 class DebugDevToolsInterceptor
: public net::URLRequestInterceptor
{
215 // net::URLRequestInterceptor implementation.
216 net::URLRequestJob
* MaybeInterceptRequest(
217 net::URLRequest
* request
,
218 net::NetworkDelegate
* network_delegate
) const override
{
220 if (IsSupportedDevToolsURL(request
->url(), &path
))
221 return new net::URLRequestFileJob(
222 request
, network_delegate
, path
,
223 content::BrowserThread::GetBlockingPool()->
224 GetTaskRunnerWithShutdownBehavior(
225 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
));
230 #endif // defined(DEBUG_DEVTOOLS)
232 #if defined(OS_CHROMEOS)
233 // The following four functions are responsible for initializing NSS for each
234 // profile on ChromeOS, which has a separate NSS database and TPM slot
237 // Initialization basically follows these steps:
238 // 1) Get some info from user_manager::UserManager about the User for this
240 // 2) Tell nss_util to initialize the software slot for this profile.
241 // 3) Wait for the TPM module to be loaded by nss_util if it isn't already.
242 // 4) Ask CryptohomeClient which TPM slot id corresponds to this profile.
243 // 5) Tell nss_util to use that slot id on the TPM module.
245 // Some of these steps must happen on the UI thread, others must happen on the
247 // UI thread IO Thread
249 // ProfileIOData::InitializeOnUIThread
251 // ProfileHelper::Get()->GetUserByProfile()
252 // \---------------------------------------v
253 // StartNSSInitOnIOThread
255 // crypto::InitializeNSSForChromeOSUser
257 // crypto::IsTPMTokenReady
259 // StartTPMSlotInitializationOnIOThread
260 // v---------------------------------------/
261 // GetTPMInfoForUserOnUIThread
263 // chromeos::TPMTokenInfoGetter::Start
265 // DidGetTPMInfoForUserOnUIThread
266 // \---------------------------------------v
267 // crypto::InitializeTPMForChromeOSUser
269 void DidGetTPMInfoForUserOnUIThread(
270 scoped_ptr
<chromeos::TPMTokenInfoGetter
> getter
,
271 const std::string
& username_hash
,
272 const chromeos::TPMTokenInfo
& info
) {
273 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
274 if (info
.tpm_is_enabled
&& info
.token_slot_id
!= -1) {
275 DVLOG(1) << "Got TPM slot for " << username_hash
<< ": "
276 << info
.token_slot_id
;
277 BrowserThread::PostTask(
280 base::Bind(&crypto::InitializeTPMForChromeOSUser
,
281 username_hash
, info
.token_slot_id
));
283 NOTREACHED() << "TPMTokenInfoGetter reported invalid token.";
287 void GetTPMInfoForUserOnUIThread(const std::string
& username
,
288 const std::string
& username_hash
) {
289 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
290 DVLOG(1) << "Getting TPM info from cryptohome for "
291 << " " << username
<< " " << username_hash
;
292 scoped_ptr
<chromeos::TPMTokenInfoGetter
> scoped_token_info_getter
=
293 chromeos::TPMTokenInfoGetter::CreateForUserToken(
295 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(),
296 base::ThreadTaskRunnerHandle::Get());
297 chromeos::TPMTokenInfoGetter
* token_info_getter
=
298 scoped_token_info_getter
.get();
300 // Bind |token_info_getter| to the callback to ensure it does not go away
301 // before TPM token info is fetched.
302 // TODO(tbarzic, pneubeck): Handle this in a nicer way when this logic is
303 // moved to a separate profile service.
304 token_info_getter
->Start(
305 base::Bind(&DidGetTPMInfoForUserOnUIThread
,
306 base::Passed(&scoped_token_info_getter
),
310 void StartTPMSlotInitializationOnIOThread(const std::string
& username
,
311 const std::string
& username_hash
) {
312 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
314 BrowserThread::PostTask(
317 base::Bind(&GetTPMInfoForUserOnUIThread
, username
, username_hash
));
320 void StartNSSInitOnIOThread(const std::string
& username
,
321 const std::string
& username_hash
,
322 const base::FilePath
& path
) {
323 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
324 DVLOG(1) << "Starting NSS init for " << username
325 << " hash:" << username_hash
;
327 // Make sure NSS is initialized for the user.
328 crypto::InitializeNSSForChromeOSUser(username_hash
, path
);
330 // Check if it's OK to initialize TPM for the user before continuing. This
331 // may not be the case if the TPM slot initialization was previously
332 // requested for the same user.
333 if (!crypto::ShouldInitializeTPMForChromeOSUser(username_hash
))
336 crypto::WillInitializeTPMForChromeOSUser(username_hash
);
338 if (crypto::IsTPMTokenEnabledForNSS()) {
339 if (crypto::IsTPMTokenReady(base::Bind(
340 &StartTPMSlotInitializationOnIOThread
, username
, username_hash
))) {
341 StartTPMSlotInitializationOnIOThread(username
, username_hash
);
343 DVLOG(1) << "Waiting for tpm ready ...";
346 crypto::InitializePrivateSoftwareSlotForChromeOSUser(username_hash
);
349 #endif // defined(OS_CHROMEOS)
351 #if defined(USE_NSS_CERTS)
352 void InitializeAndPassKeygenHandler(
353 scoped_ptr
<net::KeygenHandler
> keygen_handler
,
354 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
,
355 scoped_ptr
<ChromeNSSCryptoModuleDelegate
> delegate
) {
357 keygen_handler
->set_crypto_module_delegate(delegate
.Pass());
358 callback
.Run(keygen_handler
.Pass());
360 #endif // defined(USE_NSS_CERTS)
362 // For safe shutdown, must be called before the ProfileIOData is destroyed.
363 void NotifyContextGettersOfShutdownOnIO(
364 scoped_ptr
<ProfileIOData::ChromeURLRequestContextGetterVector
> getters
) {
365 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
366 ProfileIOData::ChromeURLRequestContextGetterVector::iterator iter
;
367 for (auto& chrome_context_getter
: *getters
)
368 chrome_context_getter
->NotifyContextShuttingDown();
373 void ProfileIOData::InitializeOnUIThread(Profile
* profile
) {
374 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
375 PrefService
* pref_service
= profile
->GetPrefs();
376 PrefService
* local_state_pref_service
= g_browser_process
->local_state();
378 scoped_ptr
<ProfileParams
> params(new ProfileParams
);
379 params
->path
= profile
->GetPath();
381 params
->io_thread
= g_browser_process
->io_thread();
383 params
->cookie_settings
= CookieSettingsFactory::GetForProfile(profile
);
384 params
->host_content_settings_map
= profile
->GetHostContentSettingsMap();
385 params
->ssl_config_service
= profile
->GetSSLConfigService();
387 #if defined(ENABLE_EXTENSIONS)
388 params
->extension_info_map
=
389 extensions::ExtensionSystem::Get(profile
)->info_map();
390 params
->cookie_monster_delegate
= new ExtensionCookieMonsterDelegate(profile
);
393 if (predictors::ResourcePrefetchPredictor
* predictor
=
394 predictors::ResourcePrefetchPredictorFactory::GetForProfile(
396 resource_prefetch_predictor_observer_
.reset(
397 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor
));
400 ProtocolHandlerRegistry
* protocol_handler_registry
=
401 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile
);
402 DCHECK(protocol_handler_registry
);
404 // The profile instance is only available here in the InitializeOnUIThread
405 // method, so we create the url job factory here, then save it for
406 // later delivery to the job factory in Init().
407 params
->protocol_handler_interceptor
=
408 protocol_handler_registry
->CreateJobInterceptorFactory();
410 NewTabPageInterceptorService
* new_tab_interceptor_service
=
411 NewTabPageInterceptorServiceFactory::GetForProfile(profile
);
412 if (new_tab_interceptor_service
) {
413 params
->new_tab_page_interceptor
=
414 new_tab_interceptor_service
->CreateInterceptor();
417 params
->proxy_config_service
418 .reset(ProxyServiceFactory::CreateProxyConfigService(
419 profile
->GetProxyConfigTracker()));
420 #if defined(ENABLE_SUPERVISED_USERS)
421 SupervisedUserService
* supervised_user_service
=
422 SupervisedUserServiceFactory::GetForProfile(profile
);
423 params
->supervised_user_url_filter
=
424 supervised_user_service
->GetURLFilterForIOThread();
426 #if defined(OS_CHROMEOS)
427 user_manager::UserManager
* user_manager
= user_manager::UserManager::Get();
429 const user_manager::User
* user
=
430 chromeos::ProfileHelper::Get()->GetUserByProfile(profile
);
431 // No need to initialize NSS for users with empty username hash:
432 // Getters for a user's NSS slots always return NULL slot if the user's
433 // username hash is empty, even when the NSS is not initialized for the
435 if (user
&& !user
->username_hash().empty()) {
436 params
->username_hash
= user
->username_hash();
437 DCHECK(!params
->username_hash
.empty());
438 BrowserThread::PostTask(BrowserThread::IO
,
440 base::Bind(&StartNSSInitOnIOThread
,
442 user
->username_hash(),
443 profile
->GetPath()));
445 // Use the device-wide system key slot only if the user is of the same
446 // domain as the device is registered to.
447 policy::BrowserPolicyConnectorChromeOS
* connector
=
448 g_browser_process
->platform_part()
449 ->browser_policy_connector_chromeos();
450 params
->use_system_key_slot
=
451 connector
->GetUserAffiliation(user
->email()) ==
452 policy::USER_AFFILIATION_MANAGED
;
457 params
->profile
= profile
;
458 profile_params_
.reset(params
.release());
460 ChromeNetworkDelegate::InitializePrefsOnUIThread(
462 &enable_do_not_track_
,
463 &force_google_safesearch_
,
464 &force_youtube_safety_mode_
,
467 scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner
=
468 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
);
470 chrome_http_user_agent_settings_
.reset(
471 new ChromeHttpUserAgentSettings(pref_service
));
473 // These members are used only for sign in, which is not enabled
474 // in incognito mode. So no need to initialize them.
475 if (!IsOffTheRecord()) {
476 google_services_user_account_id_
.Init(
477 prefs::kGoogleServicesUserAccountId
, pref_service
);
478 google_services_user_account_id_
.MoveToThread(io_task_runner
);
480 sync_disabled_
.Init(sync_driver::prefs::kSyncManaged
, pref_service
);
481 sync_disabled_
.MoveToThread(io_task_runner
);
483 signin_allowed_
.Init(prefs::kSigninAllowed
, pref_service
);
484 signin_allowed_
.MoveToThread(io_task_runner
);
487 quick_check_enabled_
.Init(prefs::kQuickCheckEnabled
,
488 local_state_pref_service
);
489 quick_check_enabled_
.MoveToThread(io_task_runner
);
491 media_device_id_salt_
= new MediaDeviceIDSalt(pref_service
, IsOffTheRecord());
493 network_prediction_options_
.Init(prefs::kNetworkPredictionOptions
,
496 network_prediction_options_
.MoveToThread(io_task_runner
);
498 #if defined(OS_CHROMEOS)
499 scoped_ptr
<policy::PolicyCertVerifier
> verifier
=
500 policy::PolicyCertServiceFactory::CreateForProfile(profile
);
501 policy_cert_verifier_
= verifier
.get();
502 cert_verifier_
= verifier
.Pass();
504 // The URLBlacklistManager has to be created on the UI thread to register
505 // observers of |pref_service|, and it also has to clean up on
506 // ShutdownOnUIThread to release these observers on the right thread.
507 // Don't pass it in |profile_params_| to make sure it is correctly cleaned up,
508 // in particular when this ProfileIOData isn't |initialized_| during deletion.
509 #if defined(ENABLE_CONFIGURATION_POLICY)
510 policy::URLBlacklist::SegmentURLCallback callback
=
511 static_cast<policy::URLBlacklist::SegmentURLCallback
>(
512 url_formatter::SegmentURL
);
513 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
514 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner
=
515 pool
->GetSequencedTaskRunner(pool
->GetSequenceToken());
516 url_blacklist_manager_
.reset(new policy::URLBlacklistManager(
517 pref_service
, background_task_runner
, io_task_runner
, callback
,
518 base::Bind(policy::OverrideBlacklistForURL
)));
520 if (!IsOffTheRecord()) {
521 // Add policy headers for non-incognito requests.
522 policy::PolicyHeaderService
* policy_header_service
=
523 policy::PolicyHeaderServiceFactory::GetForBrowserContext(profile
);
524 if (policy_header_service
) {
525 policy_header_helper_
=
526 policy_header_service
->CreatePolicyHeaderIOHelper(io_task_runner
);
531 incognito_availibility_pref_
.Init(
532 prefs::kIncognitoModeAvailability
, pref_service
);
533 incognito_availibility_pref_
.MoveToThread(io_task_runner
);
535 initialized_on_UI_thread_
= true;
537 // We need to make sure that content initializes its own data structures that
538 // are associated with each ResourceContext because we might post this
539 // object to the IO thread after this function.
540 BrowserContext::EnsureResourceContextInitialized(profile
);
543 ProfileIOData::MediaRequestContext::MediaRequestContext() {
546 void ProfileIOData::MediaRequestContext::SetHttpTransactionFactory(
547 scoped_ptr
<net::HttpTransactionFactory
> http_factory
) {
548 http_factory_
= http_factory
.Pass();
549 set_http_transaction_factory(http_factory_
.get());
552 ProfileIOData::MediaRequestContext::~MediaRequestContext() {
553 AssertNoURLRequests();
556 ProfileIOData::AppRequestContext::AppRequestContext() {
559 void ProfileIOData::AppRequestContext::SetCookieStore(
560 net::CookieStore
* cookie_store
) {
561 cookie_store_
= cookie_store
;
562 set_cookie_store(cookie_store
);
565 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory(
566 scoped_ptr
<net::HttpTransactionFactory
> http_factory
) {
567 http_factory_
= http_factory
.Pass();
568 set_http_transaction_factory(http_factory_
.get());
571 void ProfileIOData::AppRequestContext::SetJobFactory(
572 scoped_ptr
<net::URLRequestJobFactory
> job_factory
) {
573 job_factory_
= job_factory
.Pass();
574 set_job_factory(job_factory_
.get());
577 ProfileIOData::AppRequestContext::~AppRequestContext() {
578 AssertNoURLRequests();
581 ProfileIOData::ProfileParams::ProfileParams()
583 #if defined(OS_CHROMEOS)
584 use_system_key_slot(false),
589 ProfileIOData::ProfileParams::~ProfileParams() {}
591 ProfileIOData::ProfileIOData(Profile::ProfileType profile_type
)
592 : initialized_(false),
593 #if defined(OS_CHROMEOS)
594 policy_cert_verifier_(NULL
),
595 use_system_key_slot_(false),
597 resource_context_(new ResourceContext(this)),
598 initialized_on_UI_thread_(false),
599 profile_type_(profile_type
) {
600 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
603 ProfileIOData::~ProfileIOData() {
604 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
))
605 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
607 // Pull the contents of the request context maps onto the stack for sanity
608 // checking of values in a minidump. http://crbug.com/260425
609 size_t num_app_contexts
= app_request_context_map_
.size();
610 size_t num_media_contexts
= isolated_media_request_context_map_
.size();
611 size_t current_context
= 0;
612 static const size_t kMaxCachedContexts
= 20;
613 net::URLRequestContext
* app_context_cache
[kMaxCachedContexts
] = {0};
614 void* app_context_vtable_cache
[kMaxCachedContexts
] = {0};
615 net::URLRequestContext
* media_context_cache
[kMaxCachedContexts
] = {0};
616 void* media_context_vtable_cache
[kMaxCachedContexts
] = {0};
617 void* tmp_vtable
= NULL
;
618 base::debug::Alias(&num_app_contexts
);
619 base::debug::Alias(&num_media_contexts
);
620 base::debug::Alias(¤t_context
);
621 base::debug::Alias(app_context_cache
);
622 base::debug::Alias(app_context_vtable_cache
);
623 base::debug::Alias(media_context_cache
);
624 base::debug::Alias(media_context_vtable_cache
);
625 base::debug::Alias(&tmp_vtable
);
628 for (URLRequestContextMap::const_iterator it
=
629 app_request_context_map_
.begin();
630 current_context
< kMaxCachedContexts
&&
631 it
!= app_request_context_map_
.end();
632 ++it
, ++current_context
) {
633 app_context_cache
[current_context
] = it
->second
;
634 memcpy(&app_context_vtable_cache
[current_context
],
635 static_cast<void*>(it
->second
), sizeof(void*));
639 for (URLRequestContextMap::const_iterator it
=
640 isolated_media_request_context_map_
.begin();
641 current_context
< kMaxCachedContexts
&&
642 it
!= isolated_media_request_context_map_
.end();
643 ++it
, ++current_context
) {
644 media_context_cache
[current_context
] = it
->second
;
645 memcpy(&media_context_vtable_cache
[current_context
],
646 static_cast<void*>(it
->second
), sizeof(void*));
649 // Destroy certificate_report_sender_ before main_request_context_,
650 // since the former has a reference to the latter.
651 if (transport_security_state_
)
652 transport_security_state_
->SetReportSender(nullptr);
653 certificate_report_sender_
.reset();
655 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they
656 // are already done in the URLRequestContext destructor.
657 if (main_request_context_
)
658 main_request_context_
->AssertNoURLRequests();
659 if (extensions_request_context_
)
660 extensions_request_context_
->AssertNoURLRequests();
663 for (URLRequestContextMap::iterator it
= app_request_context_map_
.begin();
664 it
!= app_request_context_map_
.end(); ++it
) {
665 if (current_context
< kMaxCachedContexts
) {
666 CHECK_EQ(app_context_cache
[current_context
], it
->second
);
667 memcpy(&tmp_vtable
, static_cast<void*>(it
->second
), sizeof(void*));
668 CHECK_EQ(app_context_vtable_cache
[current_context
], tmp_vtable
);
670 it
->second
->AssertNoURLRequests();
676 for (URLRequestContextMap::iterator it
=
677 isolated_media_request_context_map_
.begin();
678 it
!= isolated_media_request_context_map_
.end(); ++it
) {
679 if (current_context
< kMaxCachedContexts
) {
680 CHECK_EQ(media_context_cache
[current_context
], it
->second
);
681 memcpy(&tmp_vtable
, static_cast<void*>(it
->second
), sizeof(void*));
682 CHECK_EQ(media_context_vtable_cache
[current_context
], tmp_vtable
);
684 it
->second
->AssertNoURLRequests();
691 ProfileIOData
* ProfileIOData::FromResourceContext(
692 content::ResourceContext
* rc
) {
693 return (static_cast<ResourceContext
*>(rc
))->io_data_
;
697 bool ProfileIOData::IsHandledProtocol(const std::string
& scheme
) {
698 DCHECK_EQ(scheme
, base::ToLowerASCII(scheme
));
699 static const char* const kProtocolList
[] = {
701 content::kChromeDevToolsScheme
,
702 dom_distiller::kDomDistillerScheme
,
703 #if defined(ENABLE_EXTENSIONS)
704 extensions::kExtensionScheme
,
705 extensions::kExtensionResourceScheme
,
707 content::kChromeUIScheme
,
709 #if defined(OS_CHROMEOS)
710 content::kExternalFileScheme
,
711 #endif // defined(OS_CHROMEOS)
713 #if !defined(DISABLE_FTP_SUPPORT)
715 #endif // !defined(DISABLE_FTP_SUPPORT)
717 url::kFileSystemScheme
,
718 chrome::kChromeSearchScheme
,
720 for (size_t i
= 0; i
< arraysize(kProtocolList
); ++i
) {
721 if (scheme
== kProtocolList
[i
])
724 return net::URLRequest::IsHandledProtocol(scheme
);
728 bool ProfileIOData::IsHandledURL(const GURL
& url
) {
729 if (!url
.is_valid()) {
730 // We handle error cases.
734 return IsHandledProtocol(url
.scheme());
738 void ProfileIOData::InstallProtocolHandlers(
739 net::URLRequestJobFactoryImpl
* job_factory
,
740 content::ProtocolHandlerMap
* protocol_handlers
) {
741 for (content::ProtocolHandlerMap::iterator it
=
742 protocol_handlers
->begin();
743 it
!= protocol_handlers
->end();
745 bool set_protocol
= job_factory
->SetProtocolHandler(
746 it
->first
, make_scoped_ptr(it
->second
.release()));
747 DCHECK(set_protocol
);
749 protocol_handlers
->clear();
753 void ProfileIOData::SetCertVerifierForTesting(
754 net::CertVerifier
* cert_verifier
) {
755 g_cert_verifier_for_testing
= cert_verifier
;
758 content::ResourceContext
* ProfileIOData::GetResourceContext() const {
759 return resource_context_
.get();
762 net::URLRequestContext
* ProfileIOData::GetMainRequestContext() const {
763 DCHECK(initialized_
);
764 return main_request_context_
.get();
767 net::URLRequestContext
* ProfileIOData::GetMediaRequestContext() const {
768 DCHECK(initialized_
);
769 net::URLRequestContext
* context
= AcquireMediaRequestContext();
774 net::URLRequestContext
* ProfileIOData::GetExtensionsRequestContext() const {
775 DCHECK(initialized_
);
776 return extensions_request_context_
.get();
779 net::URLRequestContext
* ProfileIOData::GetIsolatedAppRequestContext(
780 net::URLRequestContext
* main_context
,
781 const StoragePartitionDescriptor
& partition_descriptor
,
782 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
783 protocol_handler_interceptor
,
784 content::ProtocolHandlerMap
* protocol_handlers
,
785 content::URLRequestInterceptorScopedVector request_interceptors
) const {
786 DCHECK(initialized_
);
787 net::URLRequestContext
* context
= NULL
;
788 if (ContainsKey(app_request_context_map_
, partition_descriptor
)) {
789 context
= app_request_context_map_
[partition_descriptor
];
792 AcquireIsolatedAppRequestContext(main_context
,
793 partition_descriptor
,
794 protocol_handler_interceptor
.Pass(),
796 request_interceptors
.Pass());
797 app_request_context_map_
[partition_descriptor
] = context
;
803 net::URLRequestContext
* ProfileIOData::GetIsolatedMediaRequestContext(
804 net::URLRequestContext
* app_context
,
805 const StoragePartitionDescriptor
& partition_descriptor
) const {
806 DCHECK(initialized_
);
807 net::URLRequestContext
* context
= NULL
;
808 if (ContainsKey(isolated_media_request_context_map_
, partition_descriptor
)) {
809 context
= isolated_media_request_context_map_
[partition_descriptor
];
811 context
= AcquireIsolatedMediaRequestContext(app_context
,
812 partition_descriptor
);
813 isolated_media_request_context_map_
[partition_descriptor
] = context
;
819 extensions::InfoMap
* ProfileIOData::GetExtensionInfoMap() const {
820 DCHECK(initialized_
) << "ExtensionSystem not initialized";
821 #if defined(ENABLE_EXTENSIONS)
822 return extension_info_map_
.get();
828 extensions::ExtensionThrottleManager
*
829 ProfileIOData::GetExtensionThrottleManager() const {
830 DCHECK(initialized_
) << "ExtensionSystem not initialized";
831 #if defined(ENABLE_EXTENSIONS)
832 return extension_throttle_manager_
.get();
838 content_settings::CookieSettings
* ProfileIOData::GetCookieSettings() const {
839 // Allow either Init() or SetCookieSettingsForTesting() to initialize.
840 DCHECK(initialized_
|| cookie_settings_
.get());
841 return cookie_settings_
.get();
844 HostContentSettingsMap
* ProfileIOData::GetHostContentSettingsMap() const {
845 DCHECK(initialized_
);
846 return host_content_settings_map_
.get();
849 ResourceContext::SaltCallback
ProfileIOData::GetMediaDeviceIDSalt() const {
850 return base::Bind(&MediaDeviceIDSalt::GetSalt
, media_device_id_salt_
);
853 bool ProfileIOData::IsOffTheRecord() const {
854 return profile_type() == Profile::INCOGNITO_PROFILE
855 || profile_type() == Profile::GUEST_PROFILE
;
858 void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() {
859 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
860 #if defined(OS_CHROMEOS)
861 // Just fetch the value from ChromeOS' settings while we're on the UI thread.
862 // TODO(stevet): For now, this value is only set on profile initialization.
863 // We will want to do something similar to the PrefMember method below in the
864 // future to more accurately capture this state.
865 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref
,
867 #elif defined(OS_ANDROID)
868 // TODO(dwkang): rename or unify the pref for UMA once we have conclusion
869 // in crbugs.com/246495.
870 // Android has it's own preferences for metrics / crash uploading.
871 enable_metrics_
.Init(prefs::kCrashReportingEnabled
,
872 g_browser_process
->local_state());
873 enable_metrics_
.MoveToThread(
874 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
876 // Prep the PrefMember and send it to the IO thread, since this value will be
878 enable_metrics_
.Init(prefs::kMetricsReportingEnabled
,
879 g_browser_process
->local_state());
880 enable_metrics_
.MoveToThread(
881 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
882 #endif // defined(OS_CHROMEOS)
885 bool ProfileIOData::GetMetricsEnabledStateOnIOThread() const {
886 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
887 #if defined(OS_CHROMEOS)
888 return enable_metrics_
;
890 return enable_metrics_
.GetValue();
891 #endif // defined(OS_CHROMEOS)
894 bool ProfileIOData::IsDataReductionProxyEnabled() const {
895 return data_reduction_proxy_io_data() &&
896 data_reduction_proxy_io_data()->IsEnabled();
899 void ProfileIOData::set_data_reduction_proxy_io_data(
900 scoped_ptr
<data_reduction_proxy::DataReductionProxyIOData
>
901 data_reduction_proxy_io_data
) const {
902 data_reduction_proxy_io_data_
= data_reduction_proxy_io_data
.Pass();
905 base::WeakPtr
<net::HttpServerProperties
>
906 ProfileIOData::http_server_properties() const {
907 return http_server_properties_
->GetWeakPtr();
910 void ProfileIOData::set_http_server_properties(
911 scoped_ptr
<net::HttpServerProperties
> http_server_properties
) const {
912 http_server_properties_
= http_server_properties
.Pass();
915 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData
* io_data
)
917 host_resolver_(NULL
),
918 request_context_(NULL
) {
922 ProfileIOData::ResourceContext::~ResourceContext() {}
924 net::HostResolver
* ProfileIOData::ResourceContext::GetHostResolver() {
925 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
926 DCHECK(io_data_
->initialized_
);
927 return host_resolver_
;
930 net::URLRequestContext
* ProfileIOData::ResourceContext::GetRequestContext() {
931 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
932 DCHECK(io_data_
->initialized_
);
933 return request_context_
;
936 scoped_ptr
<net::ClientCertStore
>
937 ProfileIOData::ResourceContext::CreateClientCertStore() {
938 if (!io_data_
->client_cert_store_factory_
.is_null())
939 return io_data_
->client_cert_store_factory_
.Run();
940 #if defined(OS_CHROMEOS)
941 return scoped_ptr
<net::ClientCertStore
>(new chromeos::ClientCertStoreChromeOS(
942 nullptr, // no additional provider
943 make_scoped_ptr(new chromeos::ClientCertFilterChromeOS(
944 io_data_
->use_system_key_slot(), io_data_
->username_hash())),
945 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
946 chrome::kCryptoModulePasswordClientAuth
)));
947 #elif defined(USE_NSS_CERTS)
948 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreNSS(
949 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
950 chrome::kCryptoModulePasswordClientAuth
)));
951 #elif defined(OS_WIN)
952 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreWin());
953 #elif defined(OS_MACOSX)
954 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreMac());
955 #elif defined(USE_OPENSSL)
956 // OpenSSL does not use the ClientCertStore infrastructure. On Android client
957 // cert matching is done by the OS as part of the call to show the cert
959 return scoped_ptr
<net::ClientCertStore
>();
961 #error Unknown platform.
965 void ProfileIOData::ResourceContext::CreateKeygenHandler(
966 uint32 key_size_in_bits
,
967 const std::string
& challenge_string
,
969 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
) {
970 DCHECK(!callback
.is_null());
971 #if defined(USE_NSS_CERTS)
972 scoped_ptr
<net::KeygenHandler
> keygen_handler(
973 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
));
975 base::Callback
<void(scoped_ptr
<ChromeNSSCryptoModuleDelegate
>)>
976 got_delegate_callback
= base::Bind(&InitializeAndPassKeygenHandler
,
977 base::Passed(&keygen_handler
),
980 ChromeNSSCryptoModuleDelegate::CreateForResourceContext(
981 chrome::kCryptoModulePasswordKeygen
,
982 net::HostPortPair::FromURL(url
),
984 got_delegate_callback
);
986 callback
.Run(make_scoped_ptr(
987 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
)));
991 ResourceContext::SaltCallback
992 ProfileIOData::ResourceContext::GetMediaDeviceIDSalt() {
993 return io_data_
->GetMediaDeviceIDSalt();
997 std::string
ProfileIOData::GetSSLSessionCacheShard() {
998 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
999 // The SSL session cache is partitioned by setting a string. This returns a
1000 // unique string to partition the SSL session cache. Each time we create a
1001 // new profile, we'll get a fresh SSL session cache which is separate from
1002 // the other profiles.
1003 static unsigned ssl_session_cache_instance
= 0;
1004 return base::StringPrintf("profile/%u", ssl_session_cache_instance
++);
1007 void ProfileIOData::Init(
1008 content::ProtocolHandlerMap
* protocol_handlers
,
1009 content::URLRequestInterceptorScopedVector request_interceptors
) const {
1010 // The basic logic is implemented here. The specific initialization
1011 // is done in InitializeInternal(), implemented by subtypes. Static helper
1012 // functions have been provided to assist in common operations.
1013 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1014 DCHECK(!initialized_
);
1016 // TODO(jhawkins): Remove once crbug.com/102004 is fixed.
1017 CHECK(initialized_on_UI_thread_
);
1019 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed.
1020 CHECK(profile_params_
.get());
1022 IOThread
* const io_thread
= profile_params_
->io_thread
;
1023 IOThread::Globals
* const io_thread_globals
= io_thread
->globals();
1024 const base::CommandLine
& command_line
=
1025 *base::CommandLine::ForCurrentProcess();
1027 // Create the common request contexts.
1028 main_request_context_
.reset(new net::URLRequestContext());
1029 extensions_request_context_
.reset(new net::URLRequestContext());
1031 scoped_ptr
<ChromeNetworkDelegate
> network_delegate(
1032 new ChromeNetworkDelegate(
1033 #if defined(ENABLE_EXTENSIONS)
1034 io_thread_globals
->extension_event_router_forwarder
.get(),
1038 &enable_referrers_
));
1039 #if defined(ENABLE_EXTENSIONS)
1040 network_delegate
->set_extension_info_map(
1041 profile_params_
->extension_info_map
.get());
1042 if (!command_line
.HasSwitch(switches::kDisableExtensionsHttpThrottling
)) {
1043 extension_throttle_manager_
.reset(
1044 new extensions::ExtensionThrottleManager());
1048 #if defined(ENABLE_CONFIGURATION_POLICY)
1049 network_delegate
->set_url_blacklist_manager(url_blacklist_manager_
.get());
1051 network_delegate
->set_profile(profile_params_
->profile
);
1052 network_delegate
->set_profile_path(profile_params_
->path
);
1053 network_delegate
->set_cookie_settings(profile_params_
->cookie_settings
.get());
1054 network_delegate
->set_enable_do_not_track(&enable_do_not_track_
);
1055 network_delegate
->set_force_google_safe_search(&force_google_safesearch_
);
1056 network_delegate
->set_force_youtube_safety_mode(&force_youtube_safety_mode_
);
1058 // NOTE: Proxy service uses the default io thread network delegate, not the
1059 // delegate just created.
1060 proxy_service_
.reset(
1061 ProxyServiceFactory::CreateProxyService(
1062 io_thread
->net_log(),
1063 io_thread_globals
->proxy_script_fetcher_context
.get(),
1064 io_thread_globals
->system_network_delegate
.get(),
1065 profile_params_
->proxy_config_service
.release(),
1067 quick_check_enabled_
.GetValue()));
1068 transport_security_state_
.reset(new net::TransportSecurityState());
1069 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
1070 transport_security_persister_
.reset(
1071 new net::TransportSecurityPersister(
1072 transport_security_state_
.get(),
1073 profile_params_
->path
,
1074 pool
->GetSequencedTaskRunnerWithShutdownBehavior(
1075 pool
->GetSequenceToken(),
1076 base::SequencedWorkerPool::BLOCK_SHUTDOWN
),
1079 certificate_report_sender_
.reset(new net::CertificateReportSender(
1080 main_request_context_
.get(),
1081 net::CertificateReportSender::DO_NOT_SEND_COOKIES
));
1082 transport_security_state_
->SetReportSender(certificate_report_sender_
.get());
1084 // Take ownership over these parameters.
1085 cookie_settings_
= profile_params_
->cookie_settings
;
1086 host_content_settings_map_
= profile_params_
->host_content_settings_map
;
1087 #if defined(ENABLE_EXTENSIONS)
1088 extension_info_map_
= profile_params_
->extension_info_map
;
1091 resource_context_
->host_resolver_
= io_thread_globals
->host_resolver
.get();
1092 resource_context_
->request_context_
= main_request_context_
.get();
1094 if (profile_params_
->resource_prefetch_predictor_observer_
) {
1095 resource_prefetch_predictor_observer_
.reset(
1096 profile_params_
->resource_prefetch_predictor_observer_
.release());
1099 #if defined(ENABLE_SUPERVISED_USERS)
1100 supervised_user_url_filter_
= profile_params_
->supervised_user_url_filter
;
1103 #if defined(OS_CHROMEOS)
1104 username_hash_
= profile_params_
->username_hash
;
1105 use_system_key_slot_
= profile_params_
->use_system_key_slot
;
1106 if (use_system_key_slot_
)
1107 EnableNSSSystemKeySlotForResourceContext(resource_context_
.get());
1110 if (g_cert_verifier_for_testing
) {
1111 main_request_context_
->set_cert_verifier(g_cert_verifier_for_testing
);
1113 #if defined(OS_CHROMEOS)
1114 crypto::ScopedPK11Slot public_slot
=
1115 crypto::GetPublicSlotForChromeOSUser(username_hash_
);
1116 // The private slot won't be ready by this point. It shouldn't be necessary
1117 // for cert trust purposes anyway.
1118 scoped_refptr
<net::CertVerifyProc
> verify_proc(
1119 new chromeos::CertVerifyProcChromeOS(public_slot
.Pass()));
1120 if (policy_cert_verifier_
) {
1121 DCHECK_EQ(policy_cert_verifier_
, cert_verifier_
.get());
1122 policy_cert_verifier_
->InitializeOnIOThread(verify_proc
);
1124 cert_verifier_
.reset(
1125 new net::MultiThreadedCertVerifier(verify_proc
.get()));
1127 main_request_context_
->set_cert_verifier(cert_verifier_
.get());
1129 main_request_context_
->set_cert_verifier(
1130 io_thread_globals
->cert_verifier
.get());
1134 // Install the New Tab Page Interceptor.
1135 if (profile_params_
->new_tab_page_interceptor
.get()) {
1136 request_interceptors
.push_back(
1137 profile_params_
->new_tab_page_interceptor
.release());
1141 network_delegate
.Pass(), profile_params_
.get(),
1142 protocol_handlers
, request_interceptors
.Pass());
1144 profile_params_
.reset();
1145 initialized_
= true;
1148 void ProfileIOData::ApplyProfileParamsToContext(
1149 net::URLRequestContext
* context
) const {
1150 context
->set_http_user_agent_settings(
1151 chrome_http_user_agent_settings_
.get());
1152 context
->set_ssl_config_service(profile_params_
->ssl_config_service
.get());
1155 scoped_ptr
<net::URLRequestJobFactory
> ProfileIOData::SetUpJobFactoryDefaults(
1156 scoped_ptr
<net::URLRequestJobFactoryImpl
> job_factory
,
1157 content::URLRequestInterceptorScopedVector request_interceptors
,
1158 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
1159 protocol_handler_interceptor
,
1160 net::NetworkDelegate
* network_delegate
,
1161 net::FtpTransactionFactory
* ftp_transaction_factory
) const {
1162 // NOTE(willchan): Keep these protocol handlers in sync with
1163 // ProfileIOData::IsHandledProtocol().
1164 bool set_protocol
= job_factory
->SetProtocolHandler(
1166 make_scoped_ptr(new net::FileProtocolHandler(
1167 content::BrowserThread::GetBlockingPool()
1168 ->GetTaskRunnerWithShutdownBehavior(
1169 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
))));
1170 DCHECK(set_protocol
);
1172 #if defined(ENABLE_EXTENSIONS)
1173 DCHECK(extension_info_map_
.get());
1174 // Check only for incognito (and not Chrome OS guest mode GUEST_PROFILE).
1175 bool is_incognito
= profile_type() == Profile::INCOGNITO_PROFILE
;
1176 set_protocol
= job_factory
->SetProtocolHandler(
1177 extensions::kExtensionScheme
,
1178 extensions::CreateExtensionProtocolHandler(is_incognito
,
1179 extension_info_map_
.get()));
1180 DCHECK(set_protocol
);
1181 set_protocol
= job_factory
->SetProtocolHandler(
1182 extensions::kExtensionResourceScheme
,
1183 CreateExtensionResourceProtocolHandler());
1184 DCHECK(set_protocol
);
1186 set_protocol
= job_factory
->SetProtocolHandler(
1187 url::kDataScheme
, make_scoped_ptr(new net::DataProtocolHandler()));
1188 DCHECK(set_protocol
);
1189 #if defined(OS_CHROMEOS)
1190 if (profile_params_
) {
1191 set_protocol
= job_factory
->SetProtocolHandler(
1192 content::kExternalFileScheme
,
1193 make_scoped_ptr(new chromeos::ExternalFileProtocolHandler(
1194 profile_params_
->profile
)));
1195 DCHECK(set_protocol
);
1197 #endif // defined(OS_CHROMEOS)
1198 #if defined(OS_ANDROID)
1199 set_protocol
= job_factory
->SetProtocolHandler(
1200 url::kContentScheme
,
1201 content::ContentProtocolHandler::Create(
1202 content::BrowserThread::GetBlockingPool()
1203 ->GetTaskRunnerWithShutdownBehavior(
1204 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
)));
1207 job_factory
->SetProtocolHandler(
1209 make_scoped_ptr(new about_handler::AboutProtocolHandler()));
1210 #if !defined(DISABLE_FTP_SUPPORT)
1211 DCHECK(ftp_transaction_factory
);
1212 job_factory
->SetProtocolHandler(
1214 make_scoped_ptr(new net::FtpProtocolHandler(ftp_transaction_factory
)));
1215 #endif // !defined(DISABLE_FTP_SUPPORT)
1217 #if defined(DEBUG_DEVTOOLS)
1218 request_interceptors
.push_back(new DebugDevToolsInterceptor
);
1221 // Set up interceptors in the reverse order.
1222 scoped_ptr
<net::URLRequestJobFactory
> top_job_factory
= job_factory
.Pass();
1223 for (content::URLRequestInterceptorScopedVector::reverse_iterator i
=
1224 request_interceptors
.rbegin();
1225 i
!= request_interceptors
.rend();
1227 top_job_factory
.reset(new net::URLRequestInterceptingJobFactory(
1228 top_job_factory
.Pass(), make_scoped_ptr(*i
)));
1230 request_interceptors
.weak_clear();
1232 if (protocol_handler_interceptor
) {
1233 protocol_handler_interceptor
->Chain(top_job_factory
.Pass());
1234 return protocol_handler_interceptor
.Pass();
1236 return top_job_factory
.Pass();
1240 void ProfileIOData::ShutdownOnUIThread(
1241 scoped_ptr
<ChromeURLRequestContextGetterVector
> context_getters
) {
1242 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1244 google_services_user_account_id_
.Destroy();
1245 enable_referrers_
.Destroy();
1246 enable_do_not_track_
.Destroy();
1247 force_google_safesearch_
.Destroy();
1248 force_youtube_safety_mode_
.Destroy();
1249 #if !defined(OS_CHROMEOS)
1250 enable_metrics_
.Destroy();
1252 safe_browsing_enabled_
.Destroy();
1253 sync_disabled_
.Destroy();
1254 signin_allowed_
.Destroy();
1255 network_prediction_options_
.Destroy();
1256 quick_check_enabled_
.Destroy();
1257 if (media_device_id_salt_
.get())
1258 media_device_id_salt_
->ShutdownOnUIThread();
1259 session_startup_pref_
.Destroy();
1260 #if defined(ENABLE_CONFIGURATION_POLICY)
1261 if (url_blacklist_manager_
)
1262 url_blacklist_manager_
->ShutdownOnUIThread();
1264 if (chrome_http_user_agent_settings_
)
1265 chrome_http_user_agent_settings_
->CleanupOnUIThread();
1266 incognito_availibility_pref_
.Destroy();
1268 if (!context_getters
->empty()) {
1269 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
)) {
1270 BrowserThread::PostTask(
1271 BrowserThread::IO
, FROM_HERE
,
1272 base::Bind(&NotifyContextGettersOfShutdownOnIO
,
1273 base::Passed(&context_getters
)));
1277 bool posted
= BrowserThread::DeleteSoon(BrowserThread::IO
, FROM_HERE
, this);
1282 void ProfileIOData::set_channel_id_service(
1283 net::ChannelIDService
* channel_id_service
) const {
1284 channel_id_service_
.reset(channel_id_service
);
1287 void ProfileIOData::DestroyResourceContext() {
1288 resource_context_
.reset();
1291 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateMainHttpFactory(
1292 const ProfileParams
* profile_params
,
1293 net::HttpCache::BackendFactory
* main_backend
) const {
1294 net::HttpNetworkSession::Params params
;
1295 net::URLRequestContext
* context
= main_request_context();
1297 IOThread
* const io_thread
= profile_params
->io_thread
;
1299 io_thread
->InitializeNetworkSessionParams(¶ms
);
1300 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(context
,
1303 params
.ssl_session_cache_shard
= GetSSLSessionCacheShard();
1304 if (data_reduction_proxy_io_data_
.get())
1305 params
.proxy_delegate
= data_reduction_proxy_io_data_
->proxy_delegate();
1307 net::HttpNetworkSession
* session
= new net::HttpNetworkSession(params
);
1308 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1309 new DevToolsNetworkTransactionFactory(
1310 network_controller_handle_
.GetController(), session
),
1311 context
->net_log(), main_backend
));
1314 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateHttpFactory(
1315 net::HttpNetworkSession
* shared_session
,
1316 net::HttpCache::BackendFactory
* backend
) const {
1317 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1318 new DevToolsNetworkTransactionFactory(
1319 network_controller_handle_
.GetController(), shared_session
),
1320 shared_session
->net_log(), backend
));
1323 void ProfileIOData::SetCookieSettingsForTesting(
1324 content_settings::CookieSettings
* cookie_settings
) {
1325 DCHECK(!cookie_settings_
.get());
1326 cookie_settings_
= cookie_settings
;