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/about_protocol_handler.h"
37 #include "chrome/browser/net/chrome_http_user_agent_settings.h"
38 #include "chrome/browser/net/chrome_net_log.h"
39 #include "chrome/browser/net/chrome_network_delegate.h"
40 #include "chrome/browser/net/chrome_url_request_context_getter.h"
41 #include "chrome/browser/net/cookie_store_util.h"
42 #include "chrome/browser/net/proxy_service_factory.h"
43 #include "chrome/browser/net/resource_prefetch_predictor_observer.h"
44 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
45 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
46 #include "chrome/browser/profiles/profile.h"
47 #include "chrome/browser/profiles/profile_manager.h"
48 #include "chrome/browser/ssl/chrome_fraudulent_certificate_reporter.h"
49 #include "chrome/browser/ui/search/new_tab_page_interceptor_service.h"
50 #include "chrome/browser/ui/search/new_tab_page_interceptor_service_factory.h"
51 #include "chrome/common/chrome_paths.h"
52 #include "chrome/common/chrome_switches.h"
53 #include "chrome/common/pref_names.h"
54 #include "chrome/common/url_constants.h"
55 #include "components/content_settings/core/browser/content_settings_provider.h"
56 #include "components/content_settings/core/browser/cookie_settings.h"
57 #include "components/content_settings/core/browser/host_content_settings_map.h"
58 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
59 #include "components/dom_distiller/core/url_constants.h"
60 #include "components/sync_driver/pref_names.h"
61 #include "components/url_fixer/url_fixer.h"
62 #include "content/public/browser/browser_thread.h"
63 #include "content/public/browser/host_zoom_map.h"
64 #include "content/public/browser/notification_service.h"
65 #include "content/public/browser/resource_context.h"
66 #include "net/base/keygen_handler.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/policy/browser_policy_connector_chromeos.h"
122 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
123 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
124 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
125 #include "chrome/browser/chromeos/profiles/profile_helper.h"
126 #include "chrome/browser/chromeos/settings/cros_settings.h"
127 #include "chrome/browser/net/nss_context.h"
128 #include "chromeos/dbus/dbus_thread_manager.h"
129 #include "chromeos/settings/cros_settings_names.h"
130 #include "chromeos/tpm/tpm_token_info_getter.h"
131 #include "components/user_manager/user.h"
132 #include "components/user_manager/user_manager.h"
133 #include "crypto/nss_util.h"
134 #include "crypto/nss_util_internal.h"
135 #include "net/cert/cert_verifier.h"
136 #include "net/cert/multi_threaded_cert_verifier.h"
137 #include "net/ssl/client_cert_store_chromeos.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 #if defined(DEBUG_DEVTOOLS)
160 bool IsSupportedDevToolsURL(const GURL
& url
, base::FilePath
* path
) {
161 std::string
bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath
);
162 bundled_path_prefix
= "/" + bundled_path_prefix
+ "/";
164 if (!url
.SchemeIs(content::kChromeDevToolsScheme
) ||
165 url
.host() != chrome::kChromeUIDevToolsHost
||
166 !base::StartsWith(url
.path(), bundled_path_prefix
,
167 base::CompareCase::INSENSITIVE_ASCII
)) {
171 if (!url
.is_valid()) {
176 // Remove Query and Ref from URL.
178 GURL::Replacements replacements
;
179 replacements
.ClearQuery();
180 replacements
.ClearRef();
181 stripped_url
= url
.ReplaceComponents(replacements
);
183 std::string relative_path
;
184 const std::string
& spec
= stripped_url
.possibly_invalid_spec();
185 const url::Parsed
& parsed
= stripped_url
.parsed_for_possibly_invalid_spec();
186 int offset
= parsed
.CountCharactersBefore(url::Parsed::PATH
, false);
187 if (offset
< static_cast<int>(spec
.size()))
188 relative_path
.assign(spec
.substr(offset
+ bundled_path_prefix
.length()));
190 // Check that |relative_path| is not an absolute path (otherwise
191 // AppendASCII() will DCHECK). The awkward use of StringType is because on
192 // some systems FilePath expects a std::string, but on others a std::wstring.
194 base::FilePath::StringType(relative_path
.begin(), relative_path
.end()));
198 base::FilePath inspector_dir
;
199 if (!PathService::Get(chrome::DIR_INSPECTOR
, &inspector_dir
))
202 if (inspector_dir
.empty())
205 *path
= inspector_dir
.AppendASCII(relative_path
);
209 class DebugDevToolsInterceptor
: public net::URLRequestInterceptor
{
211 // net::URLRequestInterceptor implementation.
212 net::URLRequestJob
* MaybeInterceptRequest(
213 net::URLRequest
* request
,
214 net::NetworkDelegate
* network_delegate
) const override
{
216 if (IsSupportedDevToolsURL(request
->url(), &path
))
217 return new net::URLRequestFileJob(
218 request
, network_delegate
, path
,
219 content::BrowserThread::GetBlockingPool()->
220 GetTaskRunnerWithShutdownBehavior(
221 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
));
226 #endif // defined(DEBUG_DEVTOOLS)
228 #if defined(OS_CHROMEOS)
229 // The following four functions are responsible for initializing NSS for each
230 // profile on ChromeOS, which has a separate NSS database and TPM slot
233 // Initialization basically follows these steps:
234 // 1) Get some info from user_manager::UserManager about the User for this
236 // 2) Tell nss_util to initialize the software slot for this profile.
237 // 3) Wait for the TPM module to be loaded by nss_util if it isn't already.
238 // 4) Ask CryptohomeClient which TPM slot id corresponds to this profile.
239 // 5) Tell nss_util to use that slot id on the TPM module.
241 // Some of these steps must happen on the UI thread, others must happen on the
243 // UI thread IO Thread
245 // ProfileIOData::InitializeOnUIThread
247 // ProfileHelper::Get()->GetUserByProfile()
248 // \---------------------------------------v
249 // StartNSSInitOnIOThread
251 // crypto::InitializeNSSForChromeOSUser
253 // crypto::IsTPMTokenReady
255 // StartTPMSlotInitializationOnIOThread
256 // v---------------------------------------/
257 // GetTPMInfoForUserOnUIThread
259 // chromeos::TPMTokenInfoGetter::Start
261 // DidGetTPMInfoForUserOnUIThread
262 // \---------------------------------------v
263 // crypto::InitializeTPMForChromeOSUser
265 void DidGetTPMInfoForUserOnUIThread(
266 scoped_ptr
<chromeos::TPMTokenInfoGetter
> getter
,
267 const std::string
& username_hash
,
268 const chromeos::TPMTokenInfo
& info
) {
269 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
270 if (info
.tpm_is_enabled
&& info
.token_slot_id
!= -1) {
271 DVLOG(1) << "Got TPM slot for " << username_hash
<< ": "
272 << info
.token_slot_id
;
273 BrowserThread::PostTask(
276 base::Bind(&crypto::InitializeTPMForChromeOSUser
,
277 username_hash
, info
.token_slot_id
));
279 NOTREACHED() << "TPMTokenInfoGetter reported invalid token.";
283 void GetTPMInfoForUserOnUIThread(const std::string
& username
,
284 const std::string
& username_hash
) {
285 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
286 DVLOG(1) << "Getting TPM info from cryptohome for "
287 << " " << username
<< " " << username_hash
;
288 scoped_ptr
<chromeos::TPMTokenInfoGetter
> scoped_token_info_getter
=
289 chromeos::TPMTokenInfoGetter::CreateForUserToken(
291 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(),
292 base::ThreadTaskRunnerHandle::Get());
293 chromeos::TPMTokenInfoGetter
* token_info_getter
=
294 scoped_token_info_getter
.get();
296 // Bind |token_info_getter| to the callback to ensure it does not go away
297 // before TPM token info is fetched.
298 // TODO(tbarzic, pneubeck): Handle this in a nicer way when this logic is
299 // moved to a separate profile service.
300 token_info_getter
->Start(
301 base::Bind(&DidGetTPMInfoForUserOnUIThread
,
302 base::Passed(&scoped_token_info_getter
),
306 void StartTPMSlotInitializationOnIOThread(const std::string
& username
,
307 const std::string
& username_hash
) {
308 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
310 BrowserThread::PostTask(
313 base::Bind(&GetTPMInfoForUserOnUIThread
, username
, username_hash
));
316 void StartNSSInitOnIOThread(const std::string
& username
,
317 const std::string
& username_hash
,
318 const base::FilePath
& path
) {
319 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
320 DVLOG(1) << "Starting NSS init for " << username
321 << " hash:" << username_hash
;
323 // Make sure NSS is initialized for the user.
324 crypto::InitializeNSSForChromeOSUser(username_hash
, path
);
326 // Check if it's OK to initialize TPM for the user before continuing. This
327 // may not be the case if the TPM slot initialization was previously
328 // requested for the same user.
329 if (!crypto::ShouldInitializeTPMForChromeOSUser(username_hash
))
332 crypto::WillInitializeTPMForChromeOSUser(username_hash
);
334 if (crypto::IsTPMTokenEnabledForNSS()) {
335 if (crypto::IsTPMTokenReady(base::Bind(
336 &StartTPMSlotInitializationOnIOThread
, username
, username_hash
))) {
337 StartTPMSlotInitializationOnIOThread(username
, username_hash
);
339 DVLOG(1) << "Waiting for tpm ready ...";
342 crypto::InitializePrivateSoftwareSlotForChromeOSUser(username_hash
);
345 #endif // defined(OS_CHROMEOS)
347 #if defined(USE_NSS_CERTS)
348 void InitializeAndPassKeygenHandler(
349 scoped_ptr
<net::KeygenHandler
> keygen_handler
,
350 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
,
351 scoped_ptr
<ChromeNSSCryptoModuleDelegate
> delegate
) {
353 keygen_handler
->set_crypto_module_delegate(delegate
.Pass());
354 callback
.Run(keygen_handler
.Pass());
356 #endif // defined(USE_NSS_CERTS)
358 // For safe shutdown, must be called before the ProfileIOData is destroyed.
359 void NotifyContextGettersOfShutdownOnIO(
360 scoped_ptr
<ProfileIOData::ChromeURLRequestContextGetterVector
> getters
) {
361 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
362 ProfileIOData::ChromeURLRequestContextGetterVector::iterator iter
;
363 for (auto& chrome_context_getter
: *getters
)
364 chrome_context_getter
->NotifyContextShuttingDown();
369 void ProfileIOData::InitializeOnUIThread(Profile
* profile
) {
370 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
371 PrefService
* pref_service
= profile
->GetPrefs();
372 PrefService
* local_state_pref_service
= g_browser_process
->local_state();
374 scoped_ptr
<ProfileParams
> params(new ProfileParams
);
375 params
->path
= profile
->GetPath();
377 params
->io_thread
= g_browser_process
->io_thread();
379 params
->cookie_settings
= CookieSettingsFactory::GetForProfile(profile
);
380 params
->host_content_settings_map
= profile
->GetHostContentSettingsMap();
381 params
->ssl_config_service
= profile
->GetSSLConfigService();
383 scoped_refptr
<net::CookieMonsterDelegate
> next_cookie_monster_delegate
;
384 #if defined(ENABLE_EXTENSIONS)
385 params
->extension_info_map
=
386 extensions::ExtensionSystem::Get(profile
)->info_map();
387 next_cookie_monster_delegate
= new ExtensionCookieMonsterDelegate(profile
);
389 params
->cookie_monster_delegate
=
390 chrome_browser_net::CreateCookieDelegate(next_cookie_monster_delegate
);
392 if (predictors::ResourcePrefetchPredictor
* predictor
=
393 predictors::ResourcePrefetchPredictorFactory::GetForProfile(
395 resource_prefetch_predictor_observer_
.reset(
396 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor
));
399 ProtocolHandlerRegistry
* protocol_handler_registry
=
400 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile
);
401 DCHECK(protocol_handler_registry
);
403 // The profile instance is only available here in the InitializeOnUIThread
404 // method, so we create the url job factory here, then save it for
405 // later delivery to the job factory in Init().
406 params
->protocol_handler_interceptor
=
407 protocol_handler_registry
->CreateJobInterceptorFactory();
409 NewTabPageInterceptorService
* new_tab_interceptor_service
=
410 NewTabPageInterceptorServiceFactory::GetForProfile(profile
);
411 if (new_tab_interceptor_service
) {
412 params
->new_tab_page_interceptor
=
413 new_tab_interceptor_service
->CreateInterceptor();
416 params
->proxy_config_service
417 .reset(ProxyServiceFactory::CreateProxyConfigService(
418 profile
->GetProxyConfigTracker()));
419 #if defined(ENABLE_SUPERVISED_USERS)
420 SupervisedUserService
* supervised_user_service
=
421 SupervisedUserServiceFactory::GetForProfile(profile
);
422 params
->supervised_user_url_filter
=
423 supervised_user_service
->GetURLFilterForIOThread();
425 #if defined(OS_CHROMEOS)
426 user_manager::UserManager
* user_manager
= user_manager::UserManager::Get();
428 const user_manager::User
* user
=
429 chromeos::ProfileHelper::Get()->GetUserByProfile(profile
);
430 // No need to initialize NSS for users with empty username hash:
431 // Getters for a user's NSS slots always return NULL slot if the user's
432 // username hash is empty, even when the NSS is not initialized for the
434 if (user
&& !user
->username_hash().empty()) {
435 params
->username_hash
= user
->username_hash();
436 DCHECK(!params
->username_hash
.empty());
437 BrowserThread::PostTask(BrowserThread::IO
,
439 base::Bind(&StartNSSInitOnIOThread
,
441 user
->username_hash(),
442 profile
->GetPath()));
444 // Use the device-wide system key slot only if the user is of the same
445 // domain as the device is registered to.
446 policy::BrowserPolicyConnectorChromeOS
* connector
=
447 g_browser_process
->platform_part()
448 ->browser_policy_connector_chromeos();
449 params
->use_system_key_slot
=
450 connector
->GetUserAffiliation(user
->email()) ==
451 policy::USER_AFFILIATION_MANAGED
;
456 params
->profile
= profile
;
457 profile_params_
.reset(params
.release());
459 ChromeNetworkDelegate::InitializePrefsOnUIThread(
461 &enable_do_not_track_
,
462 &force_google_safesearch_
,
463 &force_youtube_safety_mode_
,
466 scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner
=
467 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
);
469 chrome_http_user_agent_settings_
.reset(
470 new ChromeHttpUserAgentSettings(pref_service
));
472 // These members are used only for sign in, which is not enabled
473 // in incognito mode. So no need to initialize them.
474 if (!IsOffTheRecord()) {
475 google_services_user_account_id_
.Init(
476 prefs::kGoogleServicesUserAccountId
, pref_service
);
477 google_services_user_account_id_
.MoveToThread(io_task_runner
);
479 sync_disabled_
.Init(sync_driver::prefs::kSyncManaged
, pref_service
);
480 sync_disabled_
.MoveToThread(io_task_runner
);
482 signin_allowed_
.Init(prefs::kSigninAllowed
, pref_service
);
483 signin_allowed_
.MoveToThread(io_task_runner
);
486 quick_check_enabled_
.Init(prefs::kQuickCheckEnabled
,
487 local_state_pref_service
);
488 quick_check_enabled_
.MoveToThread(io_task_runner
);
490 media_device_id_salt_
= new MediaDeviceIDSalt(pref_service
, IsOffTheRecord());
492 network_prediction_options_
.Init(prefs::kNetworkPredictionOptions
,
495 network_prediction_options_
.MoveToThread(io_task_runner
);
497 #if defined(OS_CHROMEOS)
498 scoped_ptr
<policy::PolicyCertVerifier
> verifier
=
499 policy::PolicyCertServiceFactory::CreateForProfile(profile
);
500 policy_cert_verifier_
= verifier
.get();
501 cert_verifier_
= verifier
.Pass();
503 // The URLBlacklistManager has to be created on the UI thread to register
504 // observers of |pref_service|, and it also has to clean up on
505 // ShutdownOnUIThread to release these observers on the right thread.
506 // Don't pass it in |profile_params_| to make sure it is correctly cleaned up,
507 // in particular when this ProfileIOData isn't |initialized_| during deletion.
508 #if defined(ENABLE_CONFIGURATION_POLICY)
509 policy::URLBlacklist::SegmentURLCallback callback
=
510 static_cast<policy::URLBlacklist::SegmentURLCallback
>(
511 url_fixer::SegmentURL
);
512 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
513 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner
=
514 pool
->GetSequencedTaskRunner(pool
->GetSequenceToken());
515 url_blacklist_manager_
.reset(new policy::URLBlacklistManager(
516 pref_service
, background_task_runner
, io_task_runner
, callback
,
517 base::Bind(policy::OverrideBlacklistForURL
)));
519 if (!IsOffTheRecord()) {
520 // Add policy headers for non-incognito requests.
521 policy::PolicyHeaderService
* policy_header_service
=
522 policy::PolicyHeaderServiceFactory::GetForBrowserContext(profile
);
523 if (policy_header_service
) {
524 policy_header_helper_
=
525 policy_header_service
->CreatePolicyHeaderIOHelper(io_task_runner
);
530 incognito_availibility_pref_
.Init(
531 prefs::kIncognitoModeAvailability
, pref_service
);
532 incognito_availibility_pref_
.MoveToThread(io_task_runner
);
534 initialized_on_UI_thread_
= true;
536 // We need to make sure that content initializes its own data structures that
537 // are associated with each ResourceContext because we might post this
538 // object to the IO thread after this function.
539 BrowserContext::EnsureResourceContextInitialized(profile
);
542 ProfileIOData::MediaRequestContext::MediaRequestContext() {
545 void ProfileIOData::MediaRequestContext::SetHttpTransactionFactory(
546 scoped_ptr
<net::HttpTransactionFactory
> http_factory
) {
547 http_factory_
= http_factory
.Pass();
548 set_http_transaction_factory(http_factory_
.get());
551 ProfileIOData::MediaRequestContext::~MediaRequestContext() {
552 AssertNoURLRequests();
555 ProfileIOData::AppRequestContext::AppRequestContext() {
558 void ProfileIOData::AppRequestContext::SetCookieStore(
559 net::CookieStore
* cookie_store
) {
560 cookie_store_
= cookie_store
;
561 set_cookie_store(cookie_store
);
564 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory(
565 scoped_ptr
<net::HttpTransactionFactory
> http_factory
) {
566 http_factory_
= http_factory
.Pass();
567 set_http_transaction_factory(http_factory_
.get());
570 void ProfileIOData::AppRequestContext::SetJobFactory(
571 scoped_ptr
<net::URLRequestJobFactory
> job_factory
) {
572 job_factory_
= job_factory
.Pass();
573 set_job_factory(job_factory_
.get());
576 ProfileIOData::AppRequestContext::~AppRequestContext() {
577 AssertNoURLRequests();
580 ProfileIOData::ProfileParams::ProfileParams()
582 #if defined(OS_CHROMEOS)
583 use_system_key_slot(false),
588 ProfileIOData::ProfileParams::~ProfileParams() {}
590 ProfileIOData::ProfileIOData(Profile::ProfileType profile_type
)
591 : initialized_(false),
592 #if defined(OS_CHROMEOS)
593 policy_cert_verifier_(NULL
),
594 use_system_key_slot_(false),
596 resource_context_(new ResourceContext(this)),
597 initialized_on_UI_thread_(false),
598 profile_type_(profile_type
) {
599 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
602 ProfileIOData::~ProfileIOData() {
603 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
))
604 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
606 // Pull the contents of the request context maps onto the stack for sanity
607 // checking of values in a minidump. http://crbug.com/260425
608 size_t num_app_contexts
= app_request_context_map_
.size();
609 size_t num_media_contexts
= isolated_media_request_context_map_
.size();
610 size_t current_context
= 0;
611 static const size_t kMaxCachedContexts
= 20;
612 net::URLRequestContext
* app_context_cache
[kMaxCachedContexts
] = {0};
613 void* app_context_vtable_cache
[kMaxCachedContexts
] = {0};
614 net::URLRequestContext
* media_context_cache
[kMaxCachedContexts
] = {0};
615 void* media_context_vtable_cache
[kMaxCachedContexts
] = {0};
616 void* tmp_vtable
= NULL
;
617 base::debug::Alias(&num_app_contexts
);
618 base::debug::Alias(&num_media_contexts
);
619 base::debug::Alias(¤t_context
);
620 base::debug::Alias(app_context_cache
);
621 base::debug::Alias(app_context_vtable_cache
);
622 base::debug::Alias(media_context_cache
);
623 base::debug::Alias(media_context_vtable_cache
);
624 base::debug::Alias(&tmp_vtable
);
627 for (URLRequestContextMap::const_iterator it
=
628 app_request_context_map_
.begin();
629 current_context
< kMaxCachedContexts
&&
630 it
!= app_request_context_map_
.end();
631 ++it
, ++current_context
) {
632 app_context_cache
[current_context
] = it
->second
;
633 memcpy(&app_context_vtable_cache
[current_context
],
634 static_cast<void*>(it
->second
), sizeof(void*));
638 for (URLRequestContextMap::const_iterator it
=
639 isolated_media_request_context_map_
.begin();
640 current_context
< kMaxCachedContexts
&&
641 it
!= isolated_media_request_context_map_
.end();
642 ++it
, ++current_context
) {
643 media_context_cache
[current_context
] = it
->second
;
644 memcpy(&media_context_vtable_cache
[current_context
],
645 static_cast<void*>(it
->second
), sizeof(void*));
648 // Destroy certificate_report_sender_ before main_request_context_,
649 // since the former has a reference to the latter.
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::StringToLowerASCII(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();
750 content::ResourceContext
* ProfileIOData::GetResourceContext() const {
751 return resource_context_
.get();
754 net::URLRequestContext
* ProfileIOData::GetMainRequestContext() const {
755 DCHECK(initialized_
);
756 return main_request_context_
.get();
759 net::URLRequestContext
* ProfileIOData::GetMediaRequestContext() const {
760 DCHECK(initialized_
);
761 net::URLRequestContext
* context
= AcquireMediaRequestContext();
766 net::URLRequestContext
* ProfileIOData::GetExtensionsRequestContext() const {
767 DCHECK(initialized_
);
768 return extensions_request_context_
.get();
771 net::URLRequestContext
* ProfileIOData::GetIsolatedAppRequestContext(
772 net::URLRequestContext
* main_context
,
773 const StoragePartitionDescriptor
& partition_descriptor
,
774 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
775 protocol_handler_interceptor
,
776 content::ProtocolHandlerMap
* protocol_handlers
,
777 content::URLRequestInterceptorScopedVector request_interceptors
) const {
778 DCHECK(initialized_
);
779 net::URLRequestContext
* context
= NULL
;
780 if (ContainsKey(app_request_context_map_
, partition_descriptor
)) {
781 context
= app_request_context_map_
[partition_descriptor
];
784 AcquireIsolatedAppRequestContext(main_context
,
785 partition_descriptor
,
786 protocol_handler_interceptor
.Pass(),
788 request_interceptors
.Pass());
789 app_request_context_map_
[partition_descriptor
] = context
;
795 net::URLRequestContext
* ProfileIOData::GetIsolatedMediaRequestContext(
796 net::URLRequestContext
* app_context
,
797 const StoragePartitionDescriptor
& partition_descriptor
) const {
798 DCHECK(initialized_
);
799 net::URLRequestContext
* context
= NULL
;
800 if (ContainsKey(isolated_media_request_context_map_
, partition_descriptor
)) {
801 context
= isolated_media_request_context_map_
[partition_descriptor
];
803 context
= AcquireIsolatedMediaRequestContext(app_context
,
804 partition_descriptor
);
805 isolated_media_request_context_map_
[partition_descriptor
] = context
;
811 extensions::InfoMap
* ProfileIOData::GetExtensionInfoMap() const {
812 DCHECK(initialized_
) << "ExtensionSystem not initialized";
813 #if defined(ENABLE_EXTENSIONS)
814 return extension_info_map_
.get();
820 extensions::ExtensionThrottleManager
*
821 ProfileIOData::GetExtensionThrottleManager() const {
822 DCHECK(initialized_
) << "ExtensionSystem not initialized";
823 #if defined(ENABLE_EXTENSIONS)
824 return extension_throttle_manager_
.get();
830 content_settings::CookieSettings
* ProfileIOData::GetCookieSettings() const {
831 // Allow either Init() or SetCookieSettingsForTesting() to initialize.
832 DCHECK(initialized_
|| cookie_settings_
.get());
833 return cookie_settings_
.get();
836 HostContentSettingsMap
* ProfileIOData::GetHostContentSettingsMap() const {
837 DCHECK(initialized_
);
838 return host_content_settings_map_
.get();
841 ResourceContext::SaltCallback
ProfileIOData::GetMediaDeviceIDSalt() const {
842 return base::Bind(&MediaDeviceIDSalt::GetSalt
, media_device_id_salt_
);
845 bool ProfileIOData::IsOffTheRecord() const {
846 return profile_type() == Profile::INCOGNITO_PROFILE
847 || profile_type() == Profile::GUEST_PROFILE
;
850 void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() {
851 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
852 #if defined(OS_CHROMEOS)
853 // Just fetch the value from ChromeOS' settings while we're on the UI thread.
854 // TODO(stevet): For now, this value is only set on profile initialization.
855 // We will want to do something similar to the PrefMember method below in the
856 // future to more accurately capture this state.
857 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref
,
859 #elif defined(OS_ANDROID)
860 // TODO(dwkang): rename or unify the pref for UMA once we have conclusion
861 // in crbugs.com/246495.
862 // Android has it's own preferences for metrics / crash uploading.
863 enable_metrics_
.Init(prefs::kCrashReportingEnabled
,
864 g_browser_process
->local_state());
865 enable_metrics_
.MoveToThread(
866 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
868 // Prep the PrefMember and send it to the IO thread, since this value will be
870 enable_metrics_
.Init(prefs::kMetricsReportingEnabled
,
871 g_browser_process
->local_state());
872 enable_metrics_
.MoveToThread(
873 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
874 #endif // defined(OS_CHROMEOS)
877 bool ProfileIOData::GetMetricsEnabledStateOnIOThread() const {
878 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
879 #if defined(OS_CHROMEOS)
880 return enable_metrics_
;
882 return enable_metrics_
.GetValue();
883 #endif // defined(OS_CHROMEOS)
886 bool ProfileIOData::IsDataReductionProxyEnabled() const {
887 return data_reduction_proxy_io_data() &&
888 data_reduction_proxy_io_data()->IsEnabled();
891 void ProfileIOData::set_data_reduction_proxy_io_data(
892 scoped_ptr
<data_reduction_proxy::DataReductionProxyIOData
>
893 data_reduction_proxy_io_data
) const {
894 data_reduction_proxy_io_data_
= data_reduction_proxy_io_data
.Pass();
897 base::WeakPtr
<net::HttpServerProperties
>
898 ProfileIOData::http_server_properties() const {
899 return http_server_properties_
->GetWeakPtr();
902 void ProfileIOData::set_http_server_properties(
903 scoped_ptr
<net::HttpServerProperties
> http_server_properties
) const {
904 http_server_properties_
= http_server_properties
.Pass();
907 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData
* io_data
)
909 host_resolver_(NULL
),
910 request_context_(NULL
) {
914 ProfileIOData::ResourceContext::~ResourceContext() {}
916 net::HostResolver
* ProfileIOData::ResourceContext::GetHostResolver() {
917 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
918 DCHECK(io_data_
->initialized_
);
919 return host_resolver_
;
922 net::URLRequestContext
* ProfileIOData::ResourceContext::GetRequestContext() {
923 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
924 DCHECK(io_data_
->initialized_
);
925 return request_context_
;
928 scoped_ptr
<net::ClientCertStore
>
929 ProfileIOData::ResourceContext::CreateClientCertStore() {
930 if (!io_data_
->client_cert_store_factory_
.is_null())
931 return io_data_
->client_cert_store_factory_
.Run();
932 #if defined(OS_CHROMEOS)
933 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreChromeOS(
934 make_scoped_ptr(new chromeos::ClientCertFilterChromeOS(
935 io_data_
->use_system_key_slot(), io_data_
->username_hash())),
936 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
937 chrome::kCryptoModulePasswordClientAuth
)));
938 #elif defined(USE_NSS_CERTS)
939 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreNSS(
940 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
941 chrome::kCryptoModulePasswordClientAuth
)));
942 #elif defined(OS_WIN)
943 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreWin());
944 #elif defined(OS_MACOSX)
945 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreMac());
946 #elif defined(USE_OPENSSL)
947 // OpenSSL does not use the ClientCertStore infrastructure. On Android client
948 // cert matching is done by the OS as part of the call to show the cert
950 return scoped_ptr
<net::ClientCertStore
>();
952 #error Unknown platform.
956 void ProfileIOData::ResourceContext::CreateKeygenHandler(
957 uint32 key_size_in_bits
,
958 const std::string
& challenge_string
,
960 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
) {
961 DCHECK(!callback
.is_null());
962 #if defined(USE_NSS_CERTS)
963 scoped_ptr
<net::KeygenHandler
> keygen_handler(
964 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
));
966 base::Callback
<void(scoped_ptr
<ChromeNSSCryptoModuleDelegate
>)>
967 got_delegate_callback
= base::Bind(&InitializeAndPassKeygenHandler
,
968 base::Passed(&keygen_handler
),
971 ChromeNSSCryptoModuleDelegate::CreateForResourceContext(
972 chrome::kCryptoModulePasswordKeygen
,
973 net::HostPortPair::FromURL(url
),
975 got_delegate_callback
);
977 callback
.Run(make_scoped_ptr(
978 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
)));
982 ResourceContext::SaltCallback
983 ProfileIOData::ResourceContext::GetMediaDeviceIDSalt() {
984 return io_data_
->GetMediaDeviceIDSalt();
988 std::string
ProfileIOData::GetSSLSessionCacheShard() {
989 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
990 // The SSL session cache is partitioned by setting a string. This returns a
991 // unique string to partition the SSL session cache. Each time we create a
992 // new profile, we'll get a fresh SSL session cache which is separate from
993 // the other profiles.
994 static unsigned ssl_session_cache_instance
= 0;
995 return base::StringPrintf("profile/%u", ssl_session_cache_instance
++);
998 void ProfileIOData::Init(
999 content::ProtocolHandlerMap
* protocol_handlers
,
1000 content::URLRequestInterceptorScopedVector request_interceptors
) const {
1001 // The basic logic is implemented here. The specific initialization
1002 // is done in InitializeInternal(), implemented by subtypes. Static helper
1003 // functions have been provided to assist in common operations.
1004 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1005 DCHECK(!initialized_
);
1007 // TODO(jhawkins): Remove once crbug.com/102004 is fixed.
1008 CHECK(initialized_on_UI_thread_
);
1010 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed.
1011 CHECK(profile_params_
.get());
1013 IOThread
* const io_thread
= profile_params_
->io_thread
;
1014 IOThread::Globals
* const io_thread_globals
= io_thread
->globals();
1015 const base::CommandLine
& command_line
=
1016 *base::CommandLine::ForCurrentProcess();
1018 // Create the common request contexts.
1019 main_request_context_
.reset(new net::URLRequestContext());
1020 extensions_request_context_
.reset(new net::URLRequestContext());
1022 scoped_ptr
<ChromeNetworkDelegate
> network_delegate(
1023 new ChromeNetworkDelegate(
1024 #if defined(ENABLE_EXTENSIONS)
1025 io_thread_globals
->extension_event_router_forwarder
.get(),
1029 &enable_referrers_
));
1030 #if defined(ENABLE_EXTENSIONS)
1031 network_delegate
->set_extension_info_map(
1032 profile_params_
->extension_info_map
.get());
1033 if (!command_line
.HasSwitch(switches::kDisableExtensionsHttpThrottling
)) {
1034 extension_throttle_manager_
.reset(
1035 new extensions::ExtensionThrottleManager());
1039 #if defined(ENABLE_CONFIGURATION_POLICY)
1040 network_delegate
->set_url_blacklist_manager(url_blacklist_manager_
.get());
1042 network_delegate
->set_profile(profile_params_
->profile
);
1043 network_delegate
->set_profile_path(profile_params_
->path
);
1044 network_delegate
->set_cookie_settings(profile_params_
->cookie_settings
.get());
1045 network_delegate
->set_enable_do_not_track(&enable_do_not_track_
);
1046 network_delegate
->set_force_google_safe_search(&force_google_safesearch_
);
1047 network_delegate
->set_force_youtube_safety_mode(&force_youtube_safety_mode_
);
1048 fraudulent_certificate_reporter_
.reset(
1049 new ChromeFraudulentCertificateReporter(main_request_context_
.get()));
1051 // NOTE: Proxy service uses the default io thread network delegate, not the
1052 // delegate just created.
1053 proxy_service_
.reset(
1054 ProxyServiceFactory::CreateProxyService(
1055 io_thread
->net_log(),
1056 io_thread_globals
->proxy_script_fetcher_context
.get(),
1057 io_thread_globals
->system_network_delegate
.get(),
1058 profile_params_
->proxy_config_service
.release(),
1060 quick_check_enabled_
.GetValue()));
1061 transport_security_state_
.reset(new net::TransportSecurityState());
1062 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
1063 transport_security_persister_
.reset(
1064 new net::TransportSecurityPersister(
1065 transport_security_state_
.get(),
1066 profile_params_
->path
,
1067 pool
->GetSequencedTaskRunnerWithShutdownBehavior(
1068 pool
->GetSequenceToken(),
1069 base::SequencedWorkerPool::BLOCK_SHUTDOWN
),
1072 certificate_report_sender_
.reset(new net::CertificateReportSender(
1073 main_request_context_
.get(),
1074 net::CertificateReportSender::DO_NOT_SEND_COOKIES
));
1075 transport_security_state_
->SetReportSender(certificate_report_sender_
.get());
1077 // Take ownership over these parameters.
1078 cookie_settings_
= profile_params_
->cookie_settings
;
1079 host_content_settings_map_
= profile_params_
->host_content_settings_map
;
1080 #if defined(ENABLE_EXTENSIONS)
1081 extension_info_map_
= profile_params_
->extension_info_map
;
1084 resource_context_
->host_resolver_
= io_thread_globals
->host_resolver
.get();
1085 resource_context_
->request_context_
= main_request_context_
.get();
1087 if (profile_params_
->resource_prefetch_predictor_observer_
) {
1088 resource_prefetch_predictor_observer_
.reset(
1089 profile_params_
->resource_prefetch_predictor_observer_
.release());
1092 #if defined(ENABLE_SUPERVISED_USERS)
1093 supervised_user_url_filter_
= profile_params_
->supervised_user_url_filter
;
1096 #if defined(OS_CHROMEOS)
1097 username_hash_
= profile_params_
->username_hash
;
1098 use_system_key_slot_
= profile_params_
->use_system_key_slot
;
1099 if (use_system_key_slot_
)
1100 EnableNSSSystemKeySlotForResourceContext(resource_context_
.get());
1102 crypto::ScopedPK11Slot public_slot
=
1103 crypto::GetPublicSlotForChromeOSUser(username_hash_
);
1104 // The private slot won't be ready by this point. It shouldn't be necessary
1105 // for cert trust purposes anyway.
1106 scoped_refptr
<net::CertVerifyProc
> verify_proc(
1107 new chromeos::CertVerifyProcChromeOS(public_slot
.Pass()));
1108 if (policy_cert_verifier_
) {
1109 DCHECK_EQ(policy_cert_verifier_
, cert_verifier_
.get());
1110 policy_cert_verifier_
->InitializeOnIOThread(verify_proc
);
1112 cert_verifier_
.reset(new net::MultiThreadedCertVerifier(verify_proc
.get()));
1114 main_request_context_
->set_cert_verifier(cert_verifier_
.get());
1116 main_request_context_
->set_cert_verifier(
1117 io_thread_globals
->cert_verifier
.get());
1120 // Install the New Tab Page Interceptor.
1121 if (profile_params_
->new_tab_page_interceptor
.get()) {
1122 request_interceptors
.push_back(
1123 profile_params_
->new_tab_page_interceptor
.release());
1127 network_delegate
.Pass(), profile_params_
.get(),
1128 protocol_handlers
, request_interceptors
.Pass());
1130 profile_params_
.reset();
1131 initialized_
= true;
1134 void ProfileIOData::ApplyProfileParamsToContext(
1135 net::URLRequestContext
* context
) const {
1136 context
->set_http_user_agent_settings(
1137 chrome_http_user_agent_settings_
.get());
1138 context
->set_ssl_config_service(profile_params_
->ssl_config_service
.get());
1141 scoped_ptr
<net::URLRequestJobFactory
> ProfileIOData::SetUpJobFactoryDefaults(
1142 scoped_ptr
<net::URLRequestJobFactoryImpl
> job_factory
,
1143 content::URLRequestInterceptorScopedVector request_interceptors
,
1144 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
1145 protocol_handler_interceptor
,
1146 net::NetworkDelegate
* network_delegate
,
1147 net::FtpTransactionFactory
* ftp_transaction_factory
) const {
1148 // NOTE(willchan): Keep these protocol handlers in sync with
1149 // ProfileIOData::IsHandledProtocol().
1150 bool set_protocol
= job_factory
->SetProtocolHandler(
1152 new net::FileProtocolHandler(
1153 content::BrowserThread::GetBlockingPool()->
1154 GetTaskRunnerWithShutdownBehavior(
1155 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
)));
1156 DCHECK(set_protocol
);
1158 #if defined(ENABLE_EXTENSIONS)
1159 DCHECK(extension_info_map_
.get());
1160 // Check only for incognito (and not Chrome OS guest mode GUEST_PROFILE).
1161 bool is_incognito
= profile_type() == Profile::INCOGNITO_PROFILE
;
1162 set_protocol
= job_factory
->SetProtocolHandler(
1163 extensions::kExtensionScheme
,
1164 extensions::CreateExtensionProtocolHandler(is_incognito
,
1165 extension_info_map_
.get()));
1166 DCHECK(set_protocol
);
1167 set_protocol
= job_factory
->SetProtocolHandler(
1168 extensions::kExtensionResourceScheme
,
1169 CreateExtensionResourceProtocolHandler());
1170 DCHECK(set_protocol
);
1172 set_protocol
= job_factory
->SetProtocolHandler(
1173 url::kDataScheme
, new net::DataProtocolHandler());
1174 DCHECK(set_protocol
);
1175 #if defined(OS_CHROMEOS)
1176 if (profile_params_
) {
1177 set_protocol
= job_factory
->SetProtocolHandler(
1178 content::kExternalFileScheme
,
1179 new chromeos::ExternalFileProtocolHandler(profile_params_
->profile
));
1180 DCHECK(set_protocol
);
1182 #endif // defined(OS_CHROMEOS)
1183 #if defined(OS_ANDROID)
1184 set_protocol
= job_factory
->SetProtocolHandler(
1185 url::kContentScheme
,
1186 content::ContentProtocolHandler::Create(
1187 content::BrowserThread::GetBlockingPool()->
1188 GetTaskRunnerWithShutdownBehavior(
1189 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
)));
1192 job_factory
->SetProtocolHandler(
1193 url::kAboutScheme
, new chrome_browser_net::AboutProtocolHandler());
1194 #if !defined(DISABLE_FTP_SUPPORT)
1195 DCHECK(ftp_transaction_factory
);
1196 job_factory
->SetProtocolHandler(
1198 new net::FtpProtocolHandler(ftp_transaction_factory
));
1199 #endif // !defined(DISABLE_FTP_SUPPORT)
1201 #if defined(DEBUG_DEVTOOLS)
1202 request_interceptors
.push_back(new DebugDevToolsInterceptor
);
1205 // Set up interceptors in the reverse order.
1206 scoped_ptr
<net::URLRequestJobFactory
> top_job_factory
= job_factory
.Pass();
1207 for (content::URLRequestInterceptorScopedVector::reverse_iterator i
=
1208 request_interceptors
.rbegin();
1209 i
!= request_interceptors
.rend();
1211 top_job_factory
.reset(new net::URLRequestInterceptingJobFactory(
1212 top_job_factory
.Pass(), make_scoped_ptr(*i
)));
1214 request_interceptors
.weak_clear();
1216 if (protocol_handler_interceptor
) {
1217 protocol_handler_interceptor
->Chain(top_job_factory
.Pass());
1218 return protocol_handler_interceptor
.Pass();
1220 return top_job_factory
.Pass();
1224 void ProfileIOData::ShutdownOnUIThread(
1225 scoped_ptr
<ChromeURLRequestContextGetterVector
> context_getters
) {
1226 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1228 google_services_user_account_id_
.Destroy();
1229 enable_referrers_
.Destroy();
1230 enable_do_not_track_
.Destroy();
1231 force_google_safesearch_
.Destroy();
1232 force_youtube_safety_mode_
.Destroy();
1233 #if !defined(OS_CHROMEOS)
1234 enable_metrics_
.Destroy();
1236 safe_browsing_enabled_
.Destroy();
1237 sync_disabled_
.Destroy();
1238 signin_allowed_
.Destroy();
1239 network_prediction_options_
.Destroy();
1240 quick_check_enabled_
.Destroy();
1241 if (media_device_id_salt_
.get())
1242 media_device_id_salt_
->ShutdownOnUIThread();
1243 session_startup_pref_
.Destroy();
1244 #if defined(ENABLE_CONFIGURATION_POLICY)
1245 if (url_blacklist_manager_
)
1246 url_blacklist_manager_
->ShutdownOnUIThread();
1248 if (chrome_http_user_agent_settings_
)
1249 chrome_http_user_agent_settings_
->CleanupOnUIThread();
1250 incognito_availibility_pref_
.Destroy();
1252 if (!context_getters
->empty()) {
1253 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
)) {
1254 BrowserThread::PostTask(
1255 BrowserThread::IO
, FROM_HERE
,
1256 base::Bind(&NotifyContextGettersOfShutdownOnIO
,
1257 base::Passed(&context_getters
)));
1261 bool posted
= BrowserThread::DeleteSoon(BrowserThread::IO
, FROM_HERE
, this);
1266 void ProfileIOData::set_channel_id_service(
1267 net::ChannelIDService
* channel_id_service
) const {
1268 channel_id_service_
.reset(channel_id_service
);
1271 void ProfileIOData::DestroyResourceContext() {
1272 resource_context_
.reset();
1275 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateMainHttpFactory(
1276 const ProfileParams
* profile_params
,
1277 net::HttpCache::BackendFactory
* main_backend
) const {
1278 net::HttpNetworkSession::Params params
;
1279 net::URLRequestContext
* context
= main_request_context();
1281 IOThread
* const io_thread
= profile_params
->io_thread
;
1283 io_thread
->InitializeNetworkSessionParams(¶ms
);
1285 params
.host_resolver
= context
->host_resolver();
1286 params
.cert_verifier
= context
->cert_verifier();
1287 params
.channel_id_service
= context
->channel_id_service();
1288 params
.transport_security_state
= context
->transport_security_state();
1289 params
.cert_transparency_verifier
= context
->cert_transparency_verifier();
1290 params
.proxy_service
= context
->proxy_service();
1291 params
.ssl_session_cache_shard
= GetSSLSessionCacheShard();
1292 params
.ssl_config_service
= context
->ssl_config_service();
1293 params
.http_auth_handler_factory
= context
->http_auth_handler_factory();
1294 params
.network_delegate
= context
->network_delegate();
1295 params
.http_server_properties
= context
->http_server_properties();
1296 params
.net_log
= context
->net_log();
1297 if (data_reduction_proxy_io_data_
.get())
1298 params
.proxy_delegate
= data_reduction_proxy_io_data_
->proxy_delegate();
1300 network_controller_
.reset(new DevToolsNetworkController());
1302 net::HttpNetworkSession
* session
= new net::HttpNetworkSession(params
);
1303 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1304 new DevToolsNetworkTransactionFactory(network_controller_
.get(), session
),
1305 context
->net_log(), main_backend
));
1308 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateHttpFactory(
1309 net::HttpNetworkSession
* shared_session
,
1310 net::HttpCache::BackendFactory
* backend
) const {
1311 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1312 new DevToolsNetworkTransactionFactory(
1313 network_controller_
.get(), shared_session
),
1314 shared_session
->net_log(), backend
));
1317 void ProfileIOData::SetCookieSettingsForTesting(
1318 content_settings::CookieSettings
* cookie_settings
) {
1319 DCHECK(!cookie_settings_
.get());
1320 cookie_settings_
= cookie_settings
;