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_file_job.h"
83 #include "net/url_request/url_request_intercepting_job_factory.h"
84 #include "net/url_request/url_request_interceptor.h"
85 #include "net/url_request/url_request_job_factory_impl.h"
87 #if defined(ENABLE_CONFIGURATION_POLICY)
88 #include "chrome/browser/policy/cloud/policy_header_service_factory.h"
89 #include "chrome/browser/policy/policy_helpers.h"
90 #include "components/policy/core/browser/url_blacklist_manager.h"
91 #include "components/policy/core/common/cloud/policy_header_io_helper.h"
92 #include "components/policy/core/common/cloud/policy_header_service.h"
93 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
96 #if defined(ENABLE_EXTENSIONS)
97 #include "chrome/browser/extensions/extension_cookie_monster_delegate.h"
98 #include "chrome/browser/extensions/extension_resource_protocols.h"
99 #include "extensions/browser/extension_protocols.h"
100 #include "extensions/browser/extension_system.h"
101 #include "extensions/browser/extension_throttle_manager.h"
102 #include "extensions/browser/info_map.h"
103 #include "extensions/common/constants.h"
106 #if defined(ENABLE_SUPERVISED_USERS)
107 #include "chrome/browser/supervised_user/supervised_user_service.h"
108 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
109 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
112 #if defined(OS_ANDROID)
113 #include "content/public/browser/android/content_protocol_handler.h"
114 #endif // defined(OS_ANDROID)
116 #if defined(OS_CHROMEOS)
117 #include "chrome/browser/chromeos/fileapi/external_file_protocol_handler.h"
118 #include "chrome/browser/chromeos/login/startup_utils.h"
119 #include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
120 #include "chrome/browser/chromeos/net/client_cert_filter_chromeos.h"
121 #include "chrome/browser/chromeos/net/client_cert_store_chromeos.h"
122 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
123 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
124 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
125 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
126 #include "chrome/browser/chromeos/profiles/profile_helper.h"
127 #include "chrome/browser/chromeos/settings/cros_settings.h"
128 #include "chrome/browser/net/nss_context.h"
129 #include "chromeos/dbus/dbus_thread_manager.h"
130 #include "chromeos/settings/cros_settings_names.h"
131 #include "chromeos/tpm/tpm_token_info_getter.h"
132 #include "components/user_manager/user.h"
133 #include "components/user_manager/user_manager.h"
134 #include "crypto/nss_util.h"
135 #include "crypto/nss_util_internal.h"
136 #include "net/cert/cert_verifier.h"
137 #include "net/cert/multi_threaded_cert_verifier.h"
138 #endif // defined(OS_CHROMEOS)
140 #if defined(USE_NSS_CERTS)
141 #include "chrome/browser/ui/crypto_module_delegate_nss.h"
142 #include "net/ssl/client_cert_store_nss.h"
146 #include "net/ssl/client_cert_store_win.h"
149 #if defined(OS_MACOSX)
150 #include "net/ssl/client_cert_store_mac.h"
153 using content::BrowserContext
;
154 using content::BrowserThread
;
155 using content::ResourceContext
;
159 net::CertVerifier
* g_cert_verifier_for_testing
= nullptr;
161 #if defined(DEBUG_DEVTOOLS)
162 bool IsSupportedDevToolsURL(const GURL
& url
, base::FilePath
* path
) {
163 std::string
bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath
);
164 bundled_path_prefix
= "/" + bundled_path_prefix
+ "/";
166 if (!url
.SchemeIs(content::kChromeDevToolsScheme
) ||
167 url
.host() != chrome::kChromeUIDevToolsHost
||
168 !base::StartsWith(url
.path(), bundled_path_prefix
,
169 base::CompareCase::INSENSITIVE_ASCII
)) {
173 if (!url
.is_valid()) {
178 // Remove Query and Ref from URL.
180 GURL::Replacements replacements
;
181 replacements
.ClearQuery();
182 replacements
.ClearRef();
183 stripped_url
= url
.ReplaceComponents(replacements
);
185 std::string relative_path
;
186 const std::string
& spec
= stripped_url
.possibly_invalid_spec();
187 const url::Parsed
& parsed
= stripped_url
.parsed_for_possibly_invalid_spec();
188 int offset
= parsed
.CountCharactersBefore(url::Parsed::PATH
, false);
189 if (offset
< static_cast<int>(spec
.size()))
190 relative_path
.assign(spec
.substr(offset
+ bundled_path_prefix
.length()));
192 // Check that |relative_path| is not an absolute path (otherwise
193 // AppendASCII() will DCHECK). The awkward use of StringType is because on
194 // some systems FilePath expects a std::string, but on others a std::wstring.
196 base::FilePath::StringType(relative_path
.begin(), relative_path
.end()));
200 base::FilePath inspector_dir
;
201 if (!PathService::Get(chrome::DIR_INSPECTOR
, &inspector_dir
))
204 if (inspector_dir
.empty())
207 *path
= inspector_dir
.AppendASCII(relative_path
);
211 class DebugDevToolsInterceptor
: public net::URLRequestInterceptor
{
213 // net::URLRequestInterceptor implementation.
214 net::URLRequestJob
* MaybeInterceptRequest(
215 net::URLRequest
* request
,
216 net::NetworkDelegate
* network_delegate
) const override
{
218 if (IsSupportedDevToolsURL(request
->url(), &path
))
219 return new net::URLRequestFileJob(
220 request
, network_delegate
, path
,
221 content::BrowserThread::GetBlockingPool()->
222 GetTaskRunnerWithShutdownBehavior(
223 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
));
228 #endif // defined(DEBUG_DEVTOOLS)
230 #if defined(OS_CHROMEOS)
231 // The following four functions are responsible for initializing NSS for each
232 // profile on ChromeOS, which has a separate NSS database and TPM slot
235 // Initialization basically follows these steps:
236 // 1) Get some info from user_manager::UserManager about the User for this
238 // 2) Tell nss_util to initialize the software slot for this profile.
239 // 3) Wait for the TPM module to be loaded by nss_util if it isn't already.
240 // 4) Ask CryptohomeClient which TPM slot id corresponds to this profile.
241 // 5) Tell nss_util to use that slot id on the TPM module.
243 // Some of these steps must happen on the UI thread, others must happen on the
245 // UI thread IO Thread
247 // ProfileIOData::InitializeOnUIThread
249 // ProfileHelper::Get()->GetUserByProfile()
250 // \---------------------------------------v
251 // StartNSSInitOnIOThread
253 // crypto::InitializeNSSForChromeOSUser
255 // crypto::IsTPMTokenReady
257 // StartTPMSlotInitializationOnIOThread
258 // v---------------------------------------/
259 // GetTPMInfoForUserOnUIThread
261 // chromeos::TPMTokenInfoGetter::Start
263 // DidGetTPMInfoForUserOnUIThread
264 // \---------------------------------------v
265 // crypto::InitializeTPMForChromeOSUser
267 void DidGetTPMInfoForUserOnUIThread(
268 scoped_ptr
<chromeos::TPMTokenInfoGetter
> getter
,
269 const std::string
& username_hash
,
270 const chromeos::TPMTokenInfo
& info
) {
271 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
272 if (info
.tpm_is_enabled
&& info
.token_slot_id
!= -1) {
273 DVLOG(1) << "Got TPM slot for " << username_hash
<< ": "
274 << info
.token_slot_id
;
275 BrowserThread::PostTask(
278 base::Bind(&crypto::InitializeTPMForChromeOSUser
,
279 username_hash
, info
.token_slot_id
));
281 NOTREACHED() << "TPMTokenInfoGetter reported invalid token.";
285 void GetTPMInfoForUserOnUIThread(const std::string
& username
,
286 const std::string
& username_hash
) {
287 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
288 DVLOG(1) << "Getting TPM info from cryptohome for "
289 << " " << username
<< " " << username_hash
;
290 scoped_ptr
<chromeos::TPMTokenInfoGetter
> scoped_token_info_getter
=
291 chromeos::TPMTokenInfoGetter::CreateForUserToken(
293 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(),
294 base::ThreadTaskRunnerHandle::Get());
295 chromeos::TPMTokenInfoGetter
* token_info_getter
=
296 scoped_token_info_getter
.get();
298 // Bind |token_info_getter| to the callback to ensure it does not go away
299 // before TPM token info is fetched.
300 // TODO(tbarzic, pneubeck): Handle this in a nicer way when this logic is
301 // moved to a separate profile service.
302 token_info_getter
->Start(
303 base::Bind(&DidGetTPMInfoForUserOnUIThread
,
304 base::Passed(&scoped_token_info_getter
),
308 void StartTPMSlotInitializationOnIOThread(const std::string
& username
,
309 const std::string
& username_hash
) {
310 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
312 BrowserThread::PostTask(
315 base::Bind(&GetTPMInfoForUserOnUIThread
, username
, username_hash
));
318 void StartNSSInitOnIOThread(const std::string
& username
,
319 const std::string
& username_hash
,
320 const base::FilePath
& path
) {
321 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
322 DVLOG(1) << "Starting NSS init for " << username
323 << " hash:" << username_hash
;
325 // Make sure NSS is initialized for the user.
326 crypto::InitializeNSSForChromeOSUser(username_hash
, path
);
328 // Check if it's OK to initialize TPM for the user before continuing. This
329 // may not be the case if the TPM slot initialization was previously
330 // requested for the same user.
331 if (!crypto::ShouldInitializeTPMForChromeOSUser(username_hash
))
334 crypto::WillInitializeTPMForChromeOSUser(username_hash
);
336 if (crypto::IsTPMTokenEnabledForNSS()) {
337 if (crypto::IsTPMTokenReady(base::Bind(
338 &StartTPMSlotInitializationOnIOThread
, username
, username_hash
))) {
339 StartTPMSlotInitializationOnIOThread(username
, username_hash
);
341 DVLOG(1) << "Waiting for tpm ready ...";
344 crypto::InitializePrivateSoftwareSlotForChromeOSUser(username_hash
);
347 #endif // defined(OS_CHROMEOS)
349 #if defined(USE_NSS_CERTS)
350 void InitializeAndPassKeygenHandler(
351 scoped_ptr
<net::KeygenHandler
> keygen_handler
,
352 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
,
353 scoped_ptr
<ChromeNSSCryptoModuleDelegate
> delegate
) {
355 keygen_handler
->set_crypto_module_delegate(delegate
.Pass());
356 callback
.Run(keygen_handler
.Pass());
358 #endif // defined(USE_NSS_CERTS)
360 // For safe shutdown, must be called before the ProfileIOData is destroyed.
361 void NotifyContextGettersOfShutdownOnIO(
362 scoped_ptr
<ProfileIOData::ChromeURLRequestContextGetterVector
> getters
) {
363 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
364 ProfileIOData::ChromeURLRequestContextGetterVector::iterator iter
;
365 for (auto& chrome_context_getter
: *getters
)
366 chrome_context_getter
->NotifyContextShuttingDown();
371 void ProfileIOData::InitializeOnUIThread(Profile
* profile
) {
372 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
373 PrefService
* pref_service
= profile
->GetPrefs();
374 PrefService
* local_state_pref_service
= g_browser_process
->local_state();
376 scoped_ptr
<ProfileParams
> params(new ProfileParams
);
377 params
->path
= profile
->GetPath();
379 params
->io_thread
= g_browser_process
->io_thread();
381 params
->cookie_settings
= CookieSettingsFactory::GetForProfile(profile
);
382 params
->host_content_settings_map
= profile
->GetHostContentSettingsMap();
383 params
->ssl_config_service
= profile
->GetSSLConfigService();
385 #if defined(ENABLE_EXTENSIONS)
386 params
->extension_info_map
=
387 extensions::ExtensionSystem::Get(profile
)->info_map();
388 params
->cookie_monster_delegate
= new ExtensionCookieMonsterDelegate(profile
);
391 if (predictors::ResourcePrefetchPredictor
* predictor
=
392 predictors::ResourcePrefetchPredictorFactory::GetForProfile(
394 resource_prefetch_predictor_observer_
.reset(
395 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor
));
398 ProtocolHandlerRegistry
* protocol_handler_registry
=
399 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile
);
400 DCHECK(protocol_handler_registry
);
402 // The profile instance is only available here in the InitializeOnUIThread
403 // method, so we create the url job factory here, then save it for
404 // later delivery to the job factory in Init().
405 params
->protocol_handler_interceptor
=
406 protocol_handler_registry
->CreateJobInterceptorFactory();
408 NewTabPageInterceptorService
* new_tab_interceptor_service
=
409 NewTabPageInterceptorServiceFactory::GetForProfile(profile
);
410 if (new_tab_interceptor_service
) {
411 params
->new_tab_page_interceptor
=
412 new_tab_interceptor_service
->CreateInterceptor();
415 params
->proxy_config_service
416 .reset(ProxyServiceFactory::CreateProxyConfigService(
417 profile
->GetProxyConfigTracker()));
418 #if defined(ENABLE_SUPERVISED_USERS)
419 SupervisedUserService
* supervised_user_service
=
420 SupervisedUserServiceFactory::GetForProfile(profile
);
421 params
->supervised_user_url_filter
=
422 supervised_user_service
->GetURLFilterForIOThread();
424 #if defined(OS_CHROMEOS)
425 user_manager::UserManager
* user_manager
= user_manager::UserManager::Get();
427 const user_manager::User
* user
=
428 chromeos::ProfileHelper::Get()->GetUserByProfile(profile
);
429 // No need to initialize NSS for users with empty username hash:
430 // Getters for a user's NSS slots always return NULL slot if the user's
431 // username hash is empty, even when the NSS is not initialized for the
433 if (user
&& !user
->username_hash().empty()) {
434 params
->username_hash
= user
->username_hash();
435 DCHECK(!params
->username_hash
.empty());
436 BrowserThread::PostTask(BrowserThread::IO
,
438 base::Bind(&StartNSSInitOnIOThread
,
440 user
->username_hash(),
441 profile
->GetPath()));
443 // Use the device-wide system key slot only if the user is of the same
444 // domain as the device is registered to.
445 policy::BrowserPolicyConnectorChromeOS
* connector
=
446 g_browser_process
->platform_part()
447 ->browser_policy_connector_chromeos();
448 params
->use_system_key_slot
=
449 connector
->GetUserAffiliation(user
->email()) ==
450 policy::USER_AFFILIATION_MANAGED
;
455 params
->profile
= profile
;
456 profile_params_
.reset(params
.release());
458 ChromeNetworkDelegate::InitializePrefsOnUIThread(
460 &enable_do_not_track_
,
461 &force_google_safesearch_
,
462 &force_youtube_safety_mode_
,
465 scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner
=
466 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
);
468 chrome_http_user_agent_settings_
.reset(
469 new ChromeHttpUserAgentSettings(pref_service
));
471 // These members are used only for sign in, which is not enabled
472 // in incognito mode. So no need to initialize them.
473 if (!IsOffTheRecord()) {
474 google_services_user_account_id_
.Init(
475 prefs::kGoogleServicesUserAccountId
, pref_service
);
476 google_services_user_account_id_
.MoveToThread(io_task_runner
);
478 sync_disabled_
.Init(sync_driver::prefs::kSyncManaged
, pref_service
);
479 sync_disabled_
.MoveToThread(io_task_runner
);
481 signin_allowed_
.Init(prefs::kSigninAllowed
, pref_service
);
482 signin_allowed_
.MoveToThread(io_task_runner
);
485 quick_check_enabled_
.Init(prefs::kQuickCheckEnabled
,
486 local_state_pref_service
);
487 quick_check_enabled_
.MoveToThread(io_task_runner
);
489 media_device_id_salt_
= new MediaDeviceIDSalt(pref_service
, IsOffTheRecord());
491 network_prediction_options_
.Init(prefs::kNetworkPredictionOptions
,
494 network_prediction_options_
.MoveToThread(io_task_runner
);
496 #if defined(OS_CHROMEOS)
497 scoped_ptr
<policy::PolicyCertVerifier
> verifier
=
498 policy::PolicyCertServiceFactory::CreateForProfile(profile
);
499 policy_cert_verifier_
= verifier
.get();
500 cert_verifier_
= verifier
.Pass();
502 // The URLBlacklistManager has to be created on the UI thread to register
503 // observers of |pref_service|, and it also has to clean up on
504 // ShutdownOnUIThread to release these observers on the right thread.
505 // Don't pass it in |profile_params_| to make sure it is correctly cleaned up,
506 // in particular when this ProfileIOData isn't |initialized_| during deletion.
507 #if defined(ENABLE_CONFIGURATION_POLICY)
508 policy::URLBlacklist::SegmentURLCallback callback
=
509 static_cast<policy::URLBlacklist::SegmentURLCallback
>(
510 url_formatter::SegmentURL
);
511 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
512 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner
=
513 pool
->GetSequencedTaskRunner(pool
->GetSequenceToken());
514 url_blacklist_manager_
.reset(new policy::URLBlacklistManager(
515 pref_service
, background_task_runner
, io_task_runner
, callback
,
516 base::Bind(policy::OverrideBlacklistForURL
)));
518 if (!IsOffTheRecord()) {
519 // Add policy headers for non-incognito requests.
520 policy::PolicyHeaderService
* policy_header_service
=
521 policy::PolicyHeaderServiceFactory::GetForBrowserContext(profile
);
522 if (policy_header_service
) {
523 policy_header_helper_
=
524 policy_header_service
->CreatePolicyHeaderIOHelper(io_task_runner
);
529 incognito_availibility_pref_
.Init(
530 prefs::kIncognitoModeAvailability
, pref_service
);
531 incognito_availibility_pref_
.MoveToThread(io_task_runner
);
533 initialized_on_UI_thread_
= true;
535 // We need to make sure that content initializes its own data structures that
536 // are associated with each ResourceContext because we might post this
537 // object to the IO thread after this function.
538 BrowserContext::EnsureResourceContextInitialized(profile
);
541 ProfileIOData::MediaRequestContext::MediaRequestContext() {
544 void ProfileIOData::MediaRequestContext::SetHttpTransactionFactory(
545 scoped_ptr
<net::HttpTransactionFactory
> http_factory
) {
546 http_factory_
= http_factory
.Pass();
547 set_http_transaction_factory(http_factory_
.get());
550 ProfileIOData::MediaRequestContext::~MediaRequestContext() {
551 AssertNoURLRequests();
554 ProfileIOData::AppRequestContext::AppRequestContext() {
557 void ProfileIOData::AppRequestContext::SetCookieStore(
558 net::CookieStore
* cookie_store
) {
559 cookie_store_
= cookie_store
;
560 set_cookie_store(cookie_store
);
563 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory(
564 scoped_ptr
<net::HttpTransactionFactory
> http_factory
) {
565 http_factory_
= http_factory
.Pass();
566 set_http_transaction_factory(http_factory_
.get());
569 void ProfileIOData::AppRequestContext::SetJobFactory(
570 scoped_ptr
<net::URLRequestJobFactory
> job_factory
) {
571 job_factory_
= job_factory
.Pass();
572 set_job_factory(job_factory_
.get());
575 ProfileIOData::AppRequestContext::~AppRequestContext() {
576 AssertNoURLRequests();
579 ProfileIOData::ProfileParams::ProfileParams()
581 #if defined(OS_CHROMEOS)
582 use_system_key_slot(false),
587 ProfileIOData::ProfileParams::~ProfileParams() {}
589 ProfileIOData::ProfileIOData(Profile::ProfileType profile_type
)
590 : initialized_(false),
591 #if defined(OS_CHROMEOS)
592 policy_cert_verifier_(NULL
),
593 use_system_key_slot_(false),
595 resource_context_(new ResourceContext(this)),
596 initialized_on_UI_thread_(false),
597 profile_type_(profile_type
) {
598 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
601 ProfileIOData::~ProfileIOData() {
602 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
))
603 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
605 // Pull the contents of the request context maps onto the stack for sanity
606 // checking of values in a minidump. http://crbug.com/260425
607 size_t num_app_contexts
= app_request_context_map_
.size();
608 size_t num_media_contexts
= isolated_media_request_context_map_
.size();
609 size_t current_context
= 0;
610 static const size_t kMaxCachedContexts
= 20;
611 net::URLRequestContext
* app_context_cache
[kMaxCachedContexts
] = {0};
612 void* app_context_vtable_cache
[kMaxCachedContexts
] = {0};
613 net::URLRequestContext
* media_context_cache
[kMaxCachedContexts
] = {0};
614 void* media_context_vtable_cache
[kMaxCachedContexts
] = {0};
615 void* tmp_vtable
= NULL
;
616 base::debug::Alias(&num_app_contexts
);
617 base::debug::Alias(&num_media_contexts
);
618 base::debug::Alias(¤t_context
);
619 base::debug::Alias(app_context_cache
);
620 base::debug::Alias(app_context_vtable_cache
);
621 base::debug::Alias(media_context_cache
);
622 base::debug::Alias(media_context_vtable_cache
);
623 base::debug::Alias(&tmp_vtable
);
626 for (URLRequestContextMap::const_iterator it
=
627 app_request_context_map_
.begin();
628 current_context
< kMaxCachedContexts
&&
629 it
!= app_request_context_map_
.end();
630 ++it
, ++current_context
) {
631 app_context_cache
[current_context
] = it
->second
;
632 memcpy(&app_context_vtable_cache
[current_context
],
633 static_cast<void*>(it
->second
), sizeof(void*));
637 for (URLRequestContextMap::const_iterator it
=
638 isolated_media_request_context_map_
.begin();
639 current_context
< kMaxCachedContexts
&&
640 it
!= isolated_media_request_context_map_
.end();
641 ++it
, ++current_context
) {
642 media_context_cache
[current_context
] = it
->second
;
643 memcpy(&media_context_vtable_cache
[current_context
],
644 static_cast<void*>(it
->second
), sizeof(void*));
647 // Destroy certificate_report_sender_ before main_request_context_,
648 // since the former has a reference to the latter.
649 if (transport_security_state_
)
650 transport_security_state_
->SetReportSender(nullptr);
651 certificate_report_sender_
.reset();
653 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they
654 // are already done in the URLRequestContext destructor.
655 if (main_request_context_
)
656 main_request_context_
->AssertNoURLRequests();
657 if (extensions_request_context_
)
658 extensions_request_context_
->AssertNoURLRequests();
661 for (URLRequestContextMap::iterator it
= app_request_context_map_
.begin();
662 it
!= app_request_context_map_
.end(); ++it
) {
663 if (current_context
< kMaxCachedContexts
) {
664 CHECK_EQ(app_context_cache
[current_context
], it
->second
);
665 memcpy(&tmp_vtable
, static_cast<void*>(it
->second
), sizeof(void*));
666 CHECK_EQ(app_context_vtable_cache
[current_context
], tmp_vtable
);
668 it
->second
->AssertNoURLRequests();
674 for (URLRequestContextMap::iterator it
=
675 isolated_media_request_context_map_
.begin();
676 it
!= isolated_media_request_context_map_
.end(); ++it
) {
677 if (current_context
< kMaxCachedContexts
) {
678 CHECK_EQ(media_context_cache
[current_context
], it
->second
);
679 memcpy(&tmp_vtable
, static_cast<void*>(it
->second
), sizeof(void*));
680 CHECK_EQ(media_context_vtable_cache
[current_context
], tmp_vtable
);
682 it
->second
->AssertNoURLRequests();
689 ProfileIOData
* ProfileIOData::FromResourceContext(
690 content::ResourceContext
* rc
) {
691 return (static_cast<ResourceContext
*>(rc
))->io_data_
;
695 bool ProfileIOData::IsHandledProtocol(const std::string
& scheme
) {
696 DCHECK_EQ(scheme
, base::ToLowerASCII(scheme
));
697 static const char* const kProtocolList
[] = {
699 content::kChromeDevToolsScheme
,
700 dom_distiller::kDomDistillerScheme
,
701 #if defined(ENABLE_EXTENSIONS)
702 extensions::kExtensionScheme
,
703 extensions::kExtensionResourceScheme
,
705 content::kChromeUIScheme
,
707 #if defined(OS_CHROMEOS)
708 content::kExternalFileScheme
,
709 #endif // defined(OS_CHROMEOS)
711 #if !defined(DISABLE_FTP_SUPPORT)
713 #endif // !defined(DISABLE_FTP_SUPPORT)
715 url::kFileSystemScheme
,
716 chrome::kChromeSearchScheme
,
718 for (size_t i
= 0; i
< arraysize(kProtocolList
); ++i
) {
719 if (scheme
== kProtocolList
[i
])
722 return net::URLRequest::IsHandledProtocol(scheme
);
726 bool ProfileIOData::IsHandledURL(const GURL
& url
) {
727 if (!url
.is_valid()) {
728 // We handle error cases.
732 return IsHandledProtocol(url
.scheme());
736 void ProfileIOData::InstallProtocolHandlers(
737 net::URLRequestJobFactoryImpl
* job_factory
,
738 content::ProtocolHandlerMap
* protocol_handlers
) {
739 for (content::ProtocolHandlerMap::iterator it
=
740 protocol_handlers
->begin();
741 it
!= protocol_handlers
->end();
743 bool set_protocol
= job_factory
->SetProtocolHandler(
744 it
->first
, it
->second
.release());
745 DCHECK(set_protocol
);
747 protocol_handlers
->clear();
751 void ProfileIOData::SetCertVerifierForTesting(
752 net::CertVerifier
* cert_verifier
) {
753 g_cert_verifier_for_testing
= cert_verifier
;
756 content::ResourceContext
* ProfileIOData::GetResourceContext() const {
757 return resource_context_
.get();
760 net::URLRequestContext
* ProfileIOData::GetMainRequestContext() const {
761 DCHECK(initialized_
);
762 return main_request_context_
.get();
765 net::URLRequestContext
* ProfileIOData::GetMediaRequestContext() const {
766 DCHECK(initialized_
);
767 net::URLRequestContext
* context
= AcquireMediaRequestContext();
772 net::URLRequestContext
* ProfileIOData::GetExtensionsRequestContext() const {
773 DCHECK(initialized_
);
774 return extensions_request_context_
.get();
777 net::URLRequestContext
* ProfileIOData::GetIsolatedAppRequestContext(
778 net::URLRequestContext
* main_context
,
779 const StoragePartitionDescriptor
& partition_descriptor
,
780 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
781 protocol_handler_interceptor
,
782 content::ProtocolHandlerMap
* protocol_handlers
,
783 content::URLRequestInterceptorScopedVector request_interceptors
) const {
784 DCHECK(initialized_
);
785 net::URLRequestContext
* context
= NULL
;
786 if (ContainsKey(app_request_context_map_
, partition_descriptor
)) {
787 context
= app_request_context_map_
[partition_descriptor
];
790 AcquireIsolatedAppRequestContext(main_context
,
791 partition_descriptor
,
792 protocol_handler_interceptor
.Pass(),
794 request_interceptors
.Pass());
795 app_request_context_map_
[partition_descriptor
] = context
;
801 net::URLRequestContext
* ProfileIOData::GetIsolatedMediaRequestContext(
802 net::URLRequestContext
* app_context
,
803 const StoragePartitionDescriptor
& partition_descriptor
) const {
804 DCHECK(initialized_
);
805 net::URLRequestContext
* context
= NULL
;
806 if (ContainsKey(isolated_media_request_context_map_
, partition_descriptor
)) {
807 context
= isolated_media_request_context_map_
[partition_descriptor
];
809 context
= AcquireIsolatedMediaRequestContext(app_context
,
810 partition_descriptor
);
811 isolated_media_request_context_map_
[partition_descriptor
] = context
;
817 extensions::InfoMap
* ProfileIOData::GetExtensionInfoMap() const {
818 DCHECK(initialized_
) << "ExtensionSystem not initialized";
819 #if defined(ENABLE_EXTENSIONS)
820 return extension_info_map_
.get();
826 extensions::ExtensionThrottleManager
*
827 ProfileIOData::GetExtensionThrottleManager() const {
828 DCHECK(initialized_
) << "ExtensionSystem not initialized";
829 #if defined(ENABLE_EXTENSIONS)
830 return extension_throttle_manager_
.get();
836 content_settings::CookieSettings
* ProfileIOData::GetCookieSettings() const {
837 // Allow either Init() or SetCookieSettingsForTesting() to initialize.
838 DCHECK(initialized_
|| cookie_settings_
.get());
839 return cookie_settings_
.get();
842 HostContentSettingsMap
* ProfileIOData::GetHostContentSettingsMap() const {
843 DCHECK(initialized_
);
844 return host_content_settings_map_
.get();
847 ResourceContext::SaltCallback
ProfileIOData::GetMediaDeviceIDSalt() const {
848 return base::Bind(&MediaDeviceIDSalt::GetSalt
, media_device_id_salt_
);
851 bool ProfileIOData::IsOffTheRecord() const {
852 return profile_type() == Profile::INCOGNITO_PROFILE
853 || profile_type() == Profile::GUEST_PROFILE
;
856 void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() {
857 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
858 #if defined(OS_CHROMEOS)
859 // Just fetch the value from ChromeOS' settings while we're on the UI thread.
860 // TODO(stevet): For now, this value is only set on profile initialization.
861 // We will want to do something similar to the PrefMember method below in the
862 // future to more accurately capture this state.
863 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref
,
865 #elif defined(OS_ANDROID)
866 // TODO(dwkang): rename or unify the pref for UMA once we have conclusion
867 // in crbugs.com/246495.
868 // Android has it's own preferences for metrics / crash uploading.
869 enable_metrics_
.Init(prefs::kCrashReportingEnabled
,
870 g_browser_process
->local_state());
871 enable_metrics_
.MoveToThread(
872 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
874 // Prep the PrefMember and send it to the IO thread, since this value will be
876 enable_metrics_
.Init(prefs::kMetricsReportingEnabled
,
877 g_browser_process
->local_state());
878 enable_metrics_
.MoveToThread(
879 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
880 #endif // defined(OS_CHROMEOS)
883 bool ProfileIOData::GetMetricsEnabledStateOnIOThread() const {
884 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
885 #if defined(OS_CHROMEOS)
886 return enable_metrics_
;
888 return enable_metrics_
.GetValue();
889 #endif // defined(OS_CHROMEOS)
892 bool ProfileIOData::IsDataReductionProxyEnabled() const {
893 return data_reduction_proxy_io_data() &&
894 data_reduction_proxy_io_data()->IsEnabled();
897 void ProfileIOData::set_data_reduction_proxy_io_data(
898 scoped_ptr
<data_reduction_proxy::DataReductionProxyIOData
>
899 data_reduction_proxy_io_data
) const {
900 data_reduction_proxy_io_data_
= data_reduction_proxy_io_data
.Pass();
903 base::WeakPtr
<net::HttpServerProperties
>
904 ProfileIOData::http_server_properties() const {
905 return http_server_properties_
->GetWeakPtr();
908 void ProfileIOData::set_http_server_properties(
909 scoped_ptr
<net::HttpServerProperties
> http_server_properties
) const {
910 http_server_properties_
= http_server_properties
.Pass();
913 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData
* io_data
)
915 host_resolver_(NULL
),
916 request_context_(NULL
) {
920 ProfileIOData::ResourceContext::~ResourceContext() {}
922 net::HostResolver
* ProfileIOData::ResourceContext::GetHostResolver() {
923 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
924 DCHECK(io_data_
->initialized_
);
925 return host_resolver_
;
928 net::URLRequestContext
* ProfileIOData::ResourceContext::GetRequestContext() {
929 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
930 DCHECK(io_data_
->initialized_
);
931 return request_context_
;
934 scoped_ptr
<net::ClientCertStore
>
935 ProfileIOData::ResourceContext::CreateClientCertStore() {
936 if (!io_data_
->client_cert_store_factory_
.is_null())
937 return io_data_
->client_cert_store_factory_
.Run();
938 #if defined(OS_CHROMEOS)
939 return scoped_ptr
<net::ClientCertStore
>(new chromeos::ClientCertStoreChromeOS(
940 make_scoped_ptr(new chromeos::ClientCertFilterChromeOS(
941 io_data_
->use_system_key_slot(), io_data_
->username_hash())),
942 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
943 chrome::kCryptoModulePasswordClientAuth
)));
944 #elif defined(USE_NSS_CERTS)
945 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreNSS(
946 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
947 chrome::kCryptoModulePasswordClientAuth
)));
948 #elif defined(OS_WIN)
949 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreWin());
950 #elif defined(OS_MACOSX)
951 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreMac());
952 #elif defined(USE_OPENSSL)
953 // OpenSSL does not use the ClientCertStore infrastructure. On Android client
954 // cert matching is done by the OS as part of the call to show the cert
956 return scoped_ptr
<net::ClientCertStore
>();
958 #error Unknown platform.
962 void ProfileIOData::ResourceContext::CreateKeygenHandler(
963 uint32 key_size_in_bits
,
964 const std::string
& challenge_string
,
966 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
) {
967 DCHECK(!callback
.is_null());
968 #if defined(USE_NSS_CERTS)
969 scoped_ptr
<net::KeygenHandler
> keygen_handler(
970 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
));
972 base::Callback
<void(scoped_ptr
<ChromeNSSCryptoModuleDelegate
>)>
973 got_delegate_callback
= base::Bind(&InitializeAndPassKeygenHandler
,
974 base::Passed(&keygen_handler
),
977 ChromeNSSCryptoModuleDelegate::CreateForResourceContext(
978 chrome::kCryptoModulePasswordKeygen
,
979 net::HostPortPair::FromURL(url
),
981 got_delegate_callback
);
983 callback
.Run(make_scoped_ptr(
984 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
)));
988 ResourceContext::SaltCallback
989 ProfileIOData::ResourceContext::GetMediaDeviceIDSalt() {
990 return io_data_
->GetMediaDeviceIDSalt();
994 std::string
ProfileIOData::GetSSLSessionCacheShard() {
995 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
996 // The SSL session cache is partitioned by setting a string. This returns a
997 // unique string to partition the SSL session cache. Each time we create a
998 // new profile, we'll get a fresh SSL session cache which is separate from
999 // the other profiles.
1000 static unsigned ssl_session_cache_instance
= 0;
1001 return base::StringPrintf("profile/%u", ssl_session_cache_instance
++);
1004 void ProfileIOData::Init(
1005 content::ProtocolHandlerMap
* protocol_handlers
,
1006 content::URLRequestInterceptorScopedVector request_interceptors
) const {
1007 // The basic logic is implemented here. The specific initialization
1008 // is done in InitializeInternal(), implemented by subtypes. Static helper
1009 // functions have been provided to assist in common operations.
1010 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1011 DCHECK(!initialized_
);
1013 // TODO(jhawkins): Remove once crbug.com/102004 is fixed.
1014 CHECK(initialized_on_UI_thread_
);
1016 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed.
1017 CHECK(profile_params_
.get());
1019 IOThread
* const io_thread
= profile_params_
->io_thread
;
1020 IOThread::Globals
* const io_thread_globals
= io_thread
->globals();
1021 const base::CommandLine
& command_line
=
1022 *base::CommandLine::ForCurrentProcess();
1024 // Create the common request contexts.
1025 main_request_context_
.reset(new net::URLRequestContext());
1026 extensions_request_context_
.reset(new net::URLRequestContext());
1028 scoped_ptr
<ChromeNetworkDelegate
> network_delegate(
1029 new ChromeNetworkDelegate(
1030 #if defined(ENABLE_EXTENSIONS)
1031 io_thread_globals
->extension_event_router_forwarder
.get(),
1035 &enable_referrers_
));
1036 #if defined(ENABLE_EXTENSIONS)
1037 network_delegate
->set_extension_info_map(
1038 profile_params_
->extension_info_map
.get());
1039 if (!command_line
.HasSwitch(switches::kDisableExtensionsHttpThrottling
)) {
1040 extension_throttle_manager_
.reset(
1041 new extensions::ExtensionThrottleManager());
1045 #if defined(ENABLE_CONFIGURATION_POLICY)
1046 network_delegate
->set_url_blacklist_manager(url_blacklist_manager_
.get());
1048 network_delegate
->set_profile(profile_params_
->profile
);
1049 network_delegate
->set_profile_path(profile_params_
->path
);
1050 network_delegate
->set_cookie_settings(profile_params_
->cookie_settings
.get());
1051 network_delegate
->set_enable_do_not_track(&enable_do_not_track_
);
1052 network_delegate
->set_force_google_safe_search(&force_google_safesearch_
);
1053 network_delegate
->set_force_youtube_safety_mode(&force_youtube_safety_mode_
);
1055 // NOTE: Proxy service uses the default io thread network delegate, not the
1056 // delegate just created.
1057 proxy_service_
.reset(
1058 ProxyServiceFactory::CreateProxyService(
1059 io_thread
->net_log(),
1060 io_thread_globals
->proxy_script_fetcher_context
.get(),
1061 io_thread_globals
->system_network_delegate
.get(),
1062 profile_params_
->proxy_config_service
.release(),
1064 quick_check_enabled_
.GetValue()));
1065 transport_security_state_
.reset(new net::TransportSecurityState());
1066 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
1067 transport_security_persister_
.reset(
1068 new net::TransportSecurityPersister(
1069 transport_security_state_
.get(),
1070 profile_params_
->path
,
1071 pool
->GetSequencedTaskRunnerWithShutdownBehavior(
1072 pool
->GetSequenceToken(),
1073 base::SequencedWorkerPool::BLOCK_SHUTDOWN
),
1076 certificate_report_sender_
.reset(new net::CertificateReportSender(
1077 main_request_context_
.get(),
1078 net::CertificateReportSender::DO_NOT_SEND_COOKIES
));
1079 transport_security_state_
->SetReportSender(certificate_report_sender_
.get());
1081 // Take ownership over these parameters.
1082 cookie_settings_
= profile_params_
->cookie_settings
;
1083 host_content_settings_map_
= profile_params_
->host_content_settings_map
;
1084 #if defined(ENABLE_EXTENSIONS)
1085 extension_info_map_
= profile_params_
->extension_info_map
;
1088 resource_context_
->host_resolver_
= io_thread_globals
->host_resolver
.get();
1089 resource_context_
->request_context_
= main_request_context_
.get();
1091 if (profile_params_
->resource_prefetch_predictor_observer_
) {
1092 resource_prefetch_predictor_observer_
.reset(
1093 profile_params_
->resource_prefetch_predictor_observer_
.release());
1096 #if defined(ENABLE_SUPERVISED_USERS)
1097 supervised_user_url_filter_
= profile_params_
->supervised_user_url_filter
;
1100 #if defined(OS_CHROMEOS)
1101 username_hash_
= profile_params_
->username_hash
;
1102 use_system_key_slot_
= profile_params_
->use_system_key_slot
;
1103 if (use_system_key_slot_
)
1104 EnableNSSSystemKeySlotForResourceContext(resource_context_
.get());
1107 if (g_cert_verifier_for_testing
) {
1108 main_request_context_
->set_cert_verifier(g_cert_verifier_for_testing
);
1110 #if defined(OS_CHROMEOS)
1111 crypto::ScopedPK11Slot public_slot
=
1112 crypto::GetPublicSlotForChromeOSUser(username_hash_
);
1113 // The private slot won't be ready by this point. It shouldn't be necessary
1114 // for cert trust purposes anyway.
1115 scoped_refptr
<net::CertVerifyProc
> verify_proc(
1116 new chromeos::CertVerifyProcChromeOS(public_slot
.Pass()));
1117 if (policy_cert_verifier_
) {
1118 DCHECK_EQ(policy_cert_verifier_
, cert_verifier_
.get());
1119 policy_cert_verifier_
->InitializeOnIOThread(verify_proc
);
1121 cert_verifier_
.reset(
1122 new net::MultiThreadedCertVerifier(verify_proc
.get()));
1124 main_request_context_
->set_cert_verifier(cert_verifier_
.get());
1126 main_request_context_
->set_cert_verifier(
1127 io_thread_globals
->cert_verifier
.get());
1131 // Install the New Tab Page Interceptor.
1132 if (profile_params_
->new_tab_page_interceptor
.get()) {
1133 request_interceptors
.push_back(
1134 profile_params_
->new_tab_page_interceptor
.release());
1138 network_delegate
.Pass(), profile_params_
.get(),
1139 protocol_handlers
, request_interceptors
.Pass());
1141 profile_params_
.reset();
1142 initialized_
= true;
1145 void ProfileIOData::ApplyProfileParamsToContext(
1146 net::URLRequestContext
* context
) const {
1147 context
->set_http_user_agent_settings(
1148 chrome_http_user_agent_settings_
.get());
1149 context
->set_ssl_config_service(profile_params_
->ssl_config_service
.get());
1152 scoped_ptr
<net::URLRequestJobFactory
> ProfileIOData::SetUpJobFactoryDefaults(
1153 scoped_ptr
<net::URLRequestJobFactoryImpl
> job_factory
,
1154 content::URLRequestInterceptorScopedVector request_interceptors
,
1155 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
1156 protocol_handler_interceptor
,
1157 net::NetworkDelegate
* network_delegate
,
1158 net::FtpTransactionFactory
* ftp_transaction_factory
) const {
1159 // NOTE(willchan): Keep these protocol handlers in sync with
1160 // ProfileIOData::IsHandledProtocol().
1161 bool set_protocol
= job_factory
->SetProtocolHandler(
1163 new net::FileProtocolHandler(
1164 content::BrowserThread::GetBlockingPool()->
1165 GetTaskRunnerWithShutdownBehavior(
1166 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
)));
1167 DCHECK(set_protocol
);
1169 #if defined(ENABLE_EXTENSIONS)
1170 DCHECK(extension_info_map_
.get());
1171 // Check only for incognito (and not Chrome OS guest mode GUEST_PROFILE).
1172 bool is_incognito
= profile_type() == Profile::INCOGNITO_PROFILE
;
1173 set_protocol
= job_factory
->SetProtocolHandler(
1174 extensions::kExtensionScheme
,
1175 extensions::CreateExtensionProtocolHandler(is_incognito
,
1176 extension_info_map_
.get()));
1177 DCHECK(set_protocol
);
1178 set_protocol
= job_factory
->SetProtocolHandler(
1179 extensions::kExtensionResourceScheme
,
1180 CreateExtensionResourceProtocolHandler());
1181 DCHECK(set_protocol
);
1183 set_protocol
= job_factory
->SetProtocolHandler(
1184 url::kDataScheme
, new net::DataProtocolHandler());
1185 DCHECK(set_protocol
);
1186 #if defined(OS_CHROMEOS)
1187 if (profile_params_
) {
1188 set_protocol
= job_factory
->SetProtocolHandler(
1189 content::kExternalFileScheme
,
1190 new chromeos::ExternalFileProtocolHandler(profile_params_
->profile
));
1191 DCHECK(set_protocol
);
1193 #endif // defined(OS_CHROMEOS)
1194 #if defined(OS_ANDROID)
1195 set_protocol
= job_factory
->SetProtocolHandler(
1196 url::kContentScheme
,
1197 content::ContentProtocolHandler::Create(
1198 content::BrowserThread::GetBlockingPool()->
1199 GetTaskRunnerWithShutdownBehavior(
1200 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
)));
1203 job_factory
->SetProtocolHandler(url::kAboutScheme
,
1204 new about_handler::AboutProtocolHandler());
1205 #if !defined(DISABLE_FTP_SUPPORT)
1206 DCHECK(ftp_transaction_factory
);
1207 job_factory
->SetProtocolHandler(
1209 new net::FtpProtocolHandler(ftp_transaction_factory
));
1210 #endif // !defined(DISABLE_FTP_SUPPORT)
1212 #if defined(DEBUG_DEVTOOLS)
1213 request_interceptors
.push_back(new DebugDevToolsInterceptor
);
1216 // Set up interceptors in the reverse order.
1217 scoped_ptr
<net::URLRequestJobFactory
> top_job_factory
= job_factory
.Pass();
1218 for (content::URLRequestInterceptorScopedVector::reverse_iterator i
=
1219 request_interceptors
.rbegin();
1220 i
!= request_interceptors
.rend();
1222 top_job_factory
.reset(new net::URLRequestInterceptingJobFactory(
1223 top_job_factory
.Pass(), make_scoped_ptr(*i
)));
1225 request_interceptors
.weak_clear();
1227 if (protocol_handler_interceptor
) {
1228 protocol_handler_interceptor
->Chain(top_job_factory
.Pass());
1229 return protocol_handler_interceptor
.Pass();
1231 return top_job_factory
.Pass();
1235 void ProfileIOData::ShutdownOnUIThread(
1236 scoped_ptr
<ChromeURLRequestContextGetterVector
> context_getters
) {
1237 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1239 google_services_user_account_id_
.Destroy();
1240 enable_referrers_
.Destroy();
1241 enable_do_not_track_
.Destroy();
1242 force_google_safesearch_
.Destroy();
1243 force_youtube_safety_mode_
.Destroy();
1244 #if !defined(OS_CHROMEOS)
1245 enable_metrics_
.Destroy();
1247 safe_browsing_enabled_
.Destroy();
1248 sync_disabled_
.Destroy();
1249 signin_allowed_
.Destroy();
1250 network_prediction_options_
.Destroy();
1251 quick_check_enabled_
.Destroy();
1252 if (media_device_id_salt_
.get())
1253 media_device_id_salt_
->ShutdownOnUIThread();
1254 session_startup_pref_
.Destroy();
1255 #if defined(ENABLE_CONFIGURATION_POLICY)
1256 if (url_blacklist_manager_
)
1257 url_blacklist_manager_
->ShutdownOnUIThread();
1259 if (chrome_http_user_agent_settings_
)
1260 chrome_http_user_agent_settings_
->CleanupOnUIThread();
1261 incognito_availibility_pref_
.Destroy();
1263 if (!context_getters
->empty()) {
1264 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
)) {
1265 BrowserThread::PostTask(
1266 BrowserThread::IO
, FROM_HERE
,
1267 base::Bind(&NotifyContextGettersOfShutdownOnIO
,
1268 base::Passed(&context_getters
)));
1272 bool posted
= BrowserThread::DeleteSoon(BrowserThread::IO
, FROM_HERE
, this);
1277 void ProfileIOData::set_channel_id_service(
1278 net::ChannelIDService
* channel_id_service
) const {
1279 channel_id_service_
.reset(channel_id_service
);
1282 void ProfileIOData::DestroyResourceContext() {
1283 resource_context_
.reset();
1286 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateMainHttpFactory(
1287 const ProfileParams
* profile_params
,
1288 net::HttpCache::BackendFactory
* main_backend
) const {
1289 net::HttpNetworkSession::Params params
;
1290 net::URLRequestContext
* context
= main_request_context();
1292 IOThread
* const io_thread
= profile_params
->io_thread
;
1294 io_thread
->InitializeNetworkSessionParams(¶ms
);
1296 params
.host_resolver
= context
->host_resolver();
1297 params
.cert_verifier
= context
->cert_verifier();
1298 params
.channel_id_service
= context
->channel_id_service();
1299 params
.transport_security_state
= context
->transport_security_state();
1300 params
.cert_transparency_verifier
= context
->cert_transparency_verifier();
1301 params
.proxy_service
= context
->proxy_service();
1302 params
.ssl_session_cache_shard
= GetSSLSessionCacheShard();
1303 params
.ssl_config_service
= context
->ssl_config_service();
1304 params
.http_auth_handler_factory
= context
->http_auth_handler_factory();
1305 params
.network_delegate
= context
->network_delegate();
1306 params
.http_server_properties
= context
->http_server_properties();
1307 params
.net_log
= context
->net_log();
1308 if (data_reduction_proxy_io_data_
.get())
1309 params
.proxy_delegate
= data_reduction_proxy_io_data_
->proxy_delegate();
1311 net::HttpNetworkSession
* session
= new net::HttpNetworkSession(params
);
1312 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1313 new DevToolsNetworkTransactionFactory(
1314 network_controller_handle_
.GetController(), session
),
1315 context
->net_log(), main_backend
));
1318 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateHttpFactory(
1319 net::HttpNetworkSession
* shared_session
,
1320 net::HttpCache::BackendFactory
* backend
) const {
1321 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1322 new DevToolsNetworkTransactionFactory(
1323 network_controller_handle_
.GetController(), shared_session
),
1324 shared_session
->net_log(), backend
));
1327 void ProfileIOData::SetCookieSettingsForTesting(
1328 content_settings::CookieSettings
* cookie_settings
) {
1329 DCHECK(!cookie_settings_
.get());
1330 cookie_settings_
= cookie_settings
;