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.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_fraudulent_certificate_reporter.h"
38 #include "chrome/browser/net/chrome_http_user_agent_settings.h"
39 #include "chrome/browser/net/chrome_net_log.h"
40 #include "chrome/browser/net/chrome_network_delegate.h"
41 #include "chrome/browser/net/chrome_url_request_context_getter.h"
42 #include "chrome/browser/net/cookie_store_util.h"
43 #include "chrome/browser/net/proxy_service_factory.h"
44 #include "chrome/browser/net/resource_prefetch_predictor_observer.h"
45 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
46 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
47 #include "chrome/browser/profiles/profile.h"
48 #include "chrome/browser/profiles/profile_manager.h"
49 #include "chrome/browser/signin/signin_names_io_thread.h"
50 #include "chrome/browser/ui/search/new_tab_page_interceptor_service.h"
51 #include "chrome/browser/ui/search/new_tab_page_interceptor_service_factory.h"
52 #include "chrome/common/chrome_paths.h"
53 #include "chrome/common/chrome_switches.h"
54 #include "chrome/common/pref_names.h"
55 #include "chrome/common/url_constants.h"
56 #include "components/content_settings/core/browser/content_settings_provider.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/startup_metric_utils/startup_metric_utils.h"
61 #include "components/sync_driver/pref_names.h"
62 #include "components/url_fixer/url_fixer.h"
63 #include "content/public/browser/browser_thread.h"
64 #include "content/public/browser/host_zoom_map.h"
65 #include "content/public/browser/notification_service.h"
66 #include "content/public/browser/resource_context.h"
67 #include "net/base/keygen_handler.h"
68 #include "net/cookies/canonical_cookie.h"
69 #include "net/http/http_transaction_factory.h"
70 #include "net/http/http_util.h"
71 #include "net/http/transport_security_persister.h"
72 #include "net/proxy/proxy_config_service_fixed.h"
73 #include "net/proxy/proxy_script_fetcher_impl.h"
74 #include "net/proxy/proxy_service.h"
75 #include "net/ssl/channel_id_service.h"
76 #include "net/ssl/client_cert_store.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_resource_protocols.h"
98 #include "extensions/browser/extension_protocols.h"
99 #include "extensions/browser/extension_system.h"
100 #include "extensions/browser/info_map.h"
101 #include "extensions/common/constants.h"
104 #if defined(ENABLE_SUPERVISED_USERS)
105 #include "chrome/browser/supervised_user/supervised_user_service.h"
106 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
107 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
110 #if defined(OS_ANDROID)
111 #include "content/public/browser/android/content_protocol_handler.h"
112 #endif // defined(OS_ANDROID)
114 #if defined(OS_CHROMEOS)
115 #include "chrome/browser/chromeos/fileapi/external_file_protocol_handler.h"
116 #include "chrome/browser/chromeos/login/startup_utils.h"
117 #include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
118 #include "chrome/browser/chromeos/net/client_cert_filter_chromeos.h"
119 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
120 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
121 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
122 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
123 #include "chrome/browser/chromeos/profiles/profile_helper.h"
124 #include "chrome/browser/chromeos/settings/cros_settings.h"
125 #include "chrome/browser/net/nss_context.h"
126 #include "chromeos/dbus/dbus_thread_manager.h"
127 #include "chromeos/settings/cros_settings_names.h"
128 #include "chromeos/tpm/tpm_token_info_getter.h"
129 #include "components/user_manager/user.h"
130 #include "components/user_manager/user_manager.h"
131 #include "crypto/nss_util.h"
132 #include "crypto/nss_util_internal.h"
133 #include "net/cert/cert_verifier.h"
134 #include "net/cert/multi_threaded_cert_verifier.h"
135 #include "net/ssl/client_cert_store_chromeos.h"
136 #endif // defined(OS_CHROMEOS)
139 #include "chrome/browser/ui/crypto_module_delegate_nss.h"
140 #include "net/ssl/client_cert_store_nss.h"
144 #include "net/ssl/client_cert_store_win.h"
147 #if defined(OS_MACOSX)
148 #include "net/ssl/client_cert_store_mac.h"
151 using content::BrowserContext
;
152 using content::BrowserThread
;
153 using content::ResourceContext
;
157 #if defined(DEBUG_DEVTOOLS)
158 bool IsSupportedDevToolsURL(const GURL
& url
, base::FilePath
* path
) {
159 std::string
bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath
);
160 bundled_path_prefix
= "/" + bundled_path_prefix
+ "/";
162 if (!url
.SchemeIs(content::kChromeDevToolsScheme
) ||
163 url
.host() != chrome::kChromeUIDevToolsHost
||
164 !StartsWithASCII(url
.path(), bundled_path_prefix
, false)) {
168 if (!url
.is_valid()) {
173 // Remove Query and Ref from URL.
175 GURL::Replacements replacements
;
176 replacements
.ClearQuery();
177 replacements
.ClearRef();
178 stripped_url
= url
.ReplaceComponents(replacements
);
180 std::string relative_path
;
181 const std::string
& spec
= stripped_url
.possibly_invalid_spec();
182 const url::Parsed
& parsed
= stripped_url
.parsed_for_possibly_invalid_spec();
183 int offset
= parsed
.CountCharactersBefore(url::Parsed::PATH
, false);
184 if (offset
< static_cast<int>(spec
.size()))
185 relative_path
.assign(spec
.substr(offset
+ bundled_path_prefix
.length()));
187 // Check that |relative_path| is not an absolute path (otherwise
188 // AppendASCII() will DCHECK). The awkward use of StringType is because on
189 // some systems FilePath expects a std::string, but on others a std::wstring.
191 base::FilePath::StringType(relative_path
.begin(), relative_path
.end()));
195 base::FilePath inspector_dir
;
196 if (!PathService::Get(chrome::DIR_INSPECTOR
, &inspector_dir
))
199 if (inspector_dir
.empty())
202 *path
= inspector_dir
.AppendASCII(relative_path
);
206 class DebugDevToolsInterceptor
: public net::URLRequestInterceptor
{
208 // net::URLRequestInterceptor implementation.
209 net::URLRequestJob
* MaybeInterceptRequest(
210 net::URLRequest
* request
,
211 net::NetworkDelegate
* network_delegate
) const override
{
213 if (IsSupportedDevToolsURL(request
->url(), &path
))
214 return new net::URLRequestFileJob(
215 request
, network_delegate
, path
,
216 content::BrowserThread::GetBlockingPool()->
217 GetTaskRunnerWithShutdownBehavior(
218 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
));
223 #endif // defined(DEBUG_DEVTOOLS)
225 #if defined(OS_CHROMEOS)
226 // The following four functions are responsible for initializing NSS for each
227 // profile on ChromeOS, which has a separate NSS database and TPM slot
230 // Initialization basically follows these steps:
231 // 1) Get some info from user_manager::UserManager about the User for this
233 // 2) Tell nss_util to initialize the software slot for this profile.
234 // 3) Wait for the TPM module to be loaded by nss_util if it isn't already.
235 // 4) Ask CryptohomeClient which TPM slot id corresponds to this profile.
236 // 5) Tell nss_util to use that slot id on the TPM module.
238 // Some of these steps must happen on the UI thread, others must happen on the
240 // UI thread IO Thread
242 // ProfileIOData::InitializeOnUIThread
244 // ProfileHelper::Get()->GetUserByProfile()
245 // \---------------------------------------v
246 // StartNSSInitOnIOThread
248 // crypto::InitializeNSSForChromeOSUser
250 // crypto::IsTPMTokenReady
252 // StartTPMSlotInitializationOnIOThread
253 // v---------------------------------------/
254 // GetTPMInfoForUserOnUIThread
256 // chromeos::TPMTokenInfoGetter::Start
258 // DidGetTPMInfoForUserOnUIThread
259 // \---------------------------------------v
260 // crypto::InitializeTPMForChromeOSUser
262 void DidGetTPMInfoForUserOnUIThread(
263 scoped_ptr
<chromeos::TPMTokenInfoGetter
> getter
,
264 const std::string
& username_hash
,
265 const chromeos::TPMTokenInfo
& info
) {
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
267 if (info
.tpm_is_enabled
&& info
.token_slot_id
!= -1) {
268 DVLOG(1) << "Got TPM slot for " << username_hash
<< ": "
269 << info
.token_slot_id
;
270 BrowserThread::PostTask(
273 base::Bind(&crypto::InitializeTPMForChromeOSUser
,
274 username_hash
, info
.token_slot_id
));
276 NOTREACHED() << "TPMTokenInfoGetter reported invalid token.";
280 void GetTPMInfoForUserOnUIThread(const std::string
& username
,
281 const std::string
& username_hash
) {
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
283 DVLOG(1) << "Getting TPM info from cryptohome for "
284 << " " << username
<< " " << username_hash
;
285 scoped_ptr
<chromeos::TPMTokenInfoGetter
> scoped_token_info_getter
=
286 chromeos::TPMTokenInfoGetter::CreateForUserToken(
288 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(),
289 base::ThreadTaskRunnerHandle::Get());
290 chromeos::TPMTokenInfoGetter
* token_info_getter
=
291 scoped_token_info_getter
.get();
293 // Bind |token_info_getter| to the callback to ensure it does not go away
294 // before TPM token info is fetched.
295 // TODO(tbarzic, pneubeck): Handle this in a nicer way when this logic is
296 // moved to a separate profile service.
297 token_info_getter
->Start(
298 base::Bind(&DidGetTPMInfoForUserOnUIThread
,
299 base::Passed(&scoped_token_info_getter
),
303 void StartTPMSlotInitializationOnIOThread(const std::string
& username
,
304 const std::string
& username_hash
) {
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
307 BrowserThread::PostTask(
310 base::Bind(&GetTPMInfoForUserOnUIThread
, username
, username_hash
));
313 void StartNSSInitOnIOThread(const std::string
& username
,
314 const std::string
& username_hash
,
315 const base::FilePath
& path
) {
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
317 DVLOG(1) << "Starting NSS init for " << username
318 << " hash:" << username_hash
;
320 // Make sure NSS is initialized for the user.
321 crypto::InitializeNSSForChromeOSUser(username_hash
, path
);
323 // Check if it's OK to initialize TPM for the user before continuing. This
324 // may not be the case if the TPM slot initialization was previously
325 // requested for the same user.
326 if (!crypto::ShouldInitializeTPMForChromeOSUser(username_hash
))
329 crypto::WillInitializeTPMForChromeOSUser(username_hash
);
331 if (crypto::IsTPMTokenEnabledForNSS()) {
332 if (crypto::IsTPMTokenReady(base::Bind(
333 &StartTPMSlotInitializationOnIOThread
, username
, username_hash
))) {
334 StartTPMSlotInitializationOnIOThread(username
, username_hash
);
336 DVLOG(1) << "Waiting for tpm ready ...";
339 crypto::InitializePrivateSoftwareSlotForChromeOSUser(username_hash
);
342 #endif // defined(OS_CHROMEOS)
345 void InitializeAndPassKeygenHandler(
346 scoped_ptr
<net::KeygenHandler
> keygen_handler
,
347 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
,
348 scoped_ptr
<ChromeNSSCryptoModuleDelegate
> delegate
) {
350 keygen_handler
->set_crypto_module_delegate(delegate
.Pass());
351 callback
.Run(keygen_handler
.Pass());
353 #endif // defined(USE_NSS)
355 void InvalidateContextGettersOnIO(
356 scoped_ptr
<ProfileIOData::ChromeURLRequestContextGetterVector
> getters
) {
357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
358 ProfileIOData::ChromeURLRequestContextGetterVector::iterator iter
;
359 for (iter
= getters
->begin(); iter
!= getters
->end(); ++iter
)
360 (*iter
)->Invalidate();
365 void ProfileIOData::InitializeOnUIThread(Profile
* profile
) {
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
367 PrefService
* pref_service
= profile
->GetPrefs();
368 PrefService
* local_state_pref_service
= g_browser_process
->local_state();
370 scoped_ptr
<ProfileParams
> params(new ProfileParams
);
371 params
->path
= profile
->GetPath();
373 params
->io_thread
= g_browser_process
->io_thread();
375 params
->cookie_settings
= CookieSettings::Factory::GetForProfile(profile
);
376 params
->host_content_settings_map
= profile
->GetHostContentSettingsMap();
377 params
->ssl_config_service
= profile
->GetSSLConfigService();
378 params
->cookie_monster_delegate
=
379 chrome_browser_net::CreateCookieDelegate(profile
);
380 #if defined(ENABLE_EXTENSIONS)
381 params
->extension_info_map
=
382 extensions::ExtensionSystem::Get(profile
)->info_map();
385 if (predictors::ResourcePrefetchPredictor
* predictor
=
386 predictors::ResourcePrefetchPredictorFactory::GetForProfile(
388 resource_prefetch_predictor_observer_
.reset(
389 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor
));
392 ProtocolHandlerRegistry
* protocol_handler_registry
=
393 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile
);
394 DCHECK(protocol_handler_registry
);
396 // The profile instance is only available here in the InitializeOnUIThread
397 // method, so we create the url job factory here, then save it for
398 // later delivery to the job factory in Init().
399 params
->protocol_handler_interceptor
=
400 protocol_handler_registry
->CreateJobInterceptorFactory();
402 NewTabPageInterceptorService
* new_tab_interceptor_service
=
403 NewTabPageInterceptorServiceFactory::GetForProfile(profile
);
404 if (new_tab_interceptor_service
) {
405 params
->new_tab_page_interceptor
=
406 new_tab_interceptor_service
->CreateInterceptor();
409 params
->proxy_config_service
410 .reset(ProxyServiceFactory::CreateProxyConfigService(
411 profile
->GetProxyConfigTracker()));
412 #if defined(ENABLE_SUPERVISED_USERS)
413 SupervisedUserService
* supervised_user_service
=
414 SupervisedUserServiceFactory::GetForProfile(profile
);
415 params
->supervised_user_url_filter
=
416 supervised_user_service
->GetURLFilterForIOThread();
418 #if defined(OS_CHROMEOS)
419 user_manager::UserManager
* user_manager
= user_manager::UserManager::Get();
421 const user_manager::User
* user
=
422 chromeos::ProfileHelper::Get()->GetUserByProfile(profile
);
423 // No need to initialize NSS for users with empty username hash:
424 // Getters for a user's NSS slots always return NULL slot if the user's
425 // username hash is empty, even when the NSS is not initialized for the
427 if (user
&& !user
->username_hash().empty()) {
428 params
->username_hash
= user
->username_hash();
429 DCHECK(!params
->username_hash
.empty());
430 BrowserThread::PostTask(BrowserThread::IO
,
432 base::Bind(&StartNSSInitOnIOThread
,
434 user
->username_hash(),
435 profile
->GetPath()));
437 // Use the device-wide system key slot only if the user is of the same
438 // domain as the device is registered to.
439 policy::BrowserPolicyConnectorChromeOS
* connector
=
440 g_browser_process
->platform_part()
441 ->browser_policy_connector_chromeos();
442 params
->use_system_key_slot
=
443 connector
->GetUserAffiliation(user
->email()) ==
444 policy::USER_AFFILIATION_MANAGED
;
449 params
->profile
= profile
;
450 profile_params_
.reset(params
.release());
452 ChromeNetworkDelegate::InitializePrefsOnUIThread(
454 &enable_do_not_track_
,
455 &force_google_safesearch_
,
456 &force_youtube_safety_mode_
,
459 scoped_refptr
<base::MessageLoopProxy
> io_message_loop_proxy
=
460 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
);
462 chrome_http_user_agent_settings_
.reset(
463 new ChromeHttpUserAgentSettings(pref_service
));
465 // These members are used only for one click sign in, which is not enabled
466 // in incognito mode. So no need to initialize them.
467 if (!IsOffTheRecord()) {
468 signin_names_
.reset(new SigninNamesOnIOThread());
470 google_services_user_account_id_
.Init(
471 prefs::kGoogleServicesUserAccountId
, pref_service
);
472 google_services_user_account_id_
.MoveToThread(io_message_loop_proxy
);
474 sync_disabled_
.Init(sync_driver::prefs::kSyncManaged
, pref_service
);
475 sync_disabled_
.MoveToThread(io_message_loop_proxy
);
477 signin_allowed_
.Init(prefs::kSigninAllowed
, pref_service
);
478 signin_allowed_
.MoveToThread(io_message_loop_proxy
);
481 quick_check_enabled_
.Init(prefs::kQuickCheckEnabled
,
482 local_state_pref_service
);
483 quick_check_enabled_
.MoveToThread(io_message_loop_proxy
);
485 media_device_id_salt_
= new MediaDeviceIDSalt(pref_service
, IsOffTheRecord());
487 network_prediction_options_
.Init(prefs::kNetworkPredictionOptions
,
490 network_prediction_options_
.MoveToThread(io_message_loop_proxy
);
492 #if defined(OS_CHROMEOS)
493 scoped_ptr
<policy::PolicyCertVerifier
> verifier
=
494 policy::PolicyCertServiceFactory::CreateForProfile(profile
);
495 policy_cert_verifier_
= verifier
.get();
496 cert_verifier_
= verifier
.Pass();
498 // The URLBlacklistManager has to be created on the UI thread to register
499 // observers of |pref_service|, and it also has to clean up on
500 // ShutdownOnUIThread to release these observers on the right thread.
501 // Don't pass it in |profile_params_| to make sure it is correctly cleaned up,
502 // in particular when this ProfileIOData isn't |initialized_| during deletion.
503 #if defined(ENABLE_CONFIGURATION_POLICY)
504 policy::URLBlacklist::SegmentURLCallback callback
=
505 static_cast<policy::URLBlacklist::SegmentURLCallback
>(
506 url_fixer::SegmentURL
);
507 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
508 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner
=
509 pool
->GetSequencedTaskRunner(pool
->GetSequenceToken());
510 url_blacklist_manager_
.reset(
511 new policy::URLBlacklistManager(
513 background_task_runner
,
514 io_message_loop_proxy
,
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_
= policy_header_service
->CreatePolicyHeaderIOHelper(
524 io_message_loop_proxy
);
529 incognito_availibility_pref_
.Init(
530 prefs::kIncognitoModeAvailability
, pref_service
);
531 incognito_availibility_pref_
.MoveToThread(io_message_loop_proxy
);
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(BrowserThread::CurrentlyOn(BrowserThread::UI
));
601 ProfileIOData::~ProfileIOData() {
602 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
))
603 DCHECK(BrowserThread::CurrentlyOn(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 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they
648 // are already done in the URLRequestContext destructor.
649 if (main_request_context_
)
650 main_request_context_
->AssertNoURLRequests();
651 if (extensions_request_context_
)
652 extensions_request_context_
->AssertNoURLRequests();
655 for (URLRequestContextMap::iterator it
= app_request_context_map_
.begin();
656 it
!= app_request_context_map_
.end(); ++it
) {
657 if (current_context
< kMaxCachedContexts
) {
658 CHECK_EQ(app_context_cache
[current_context
], it
->second
);
659 memcpy(&tmp_vtable
, static_cast<void*>(it
->second
), sizeof(void*));
660 CHECK_EQ(app_context_vtable_cache
[current_context
], tmp_vtable
);
662 it
->second
->AssertNoURLRequests();
668 for (URLRequestContextMap::iterator it
=
669 isolated_media_request_context_map_
.begin();
670 it
!= isolated_media_request_context_map_
.end(); ++it
) {
671 if (current_context
< kMaxCachedContexts
) {
672 CHECK_EQ(media_context_cache
[current_context
], it
->second
);
673 memcpy(&tmp_vtable
, static_cast<void*>(it
->second
), sizeof(void*));
674 CHECK_EQ(media_context_vtable_cache
[current_context
], tmp_vtable
);
676 it
->second
->AssertNoURLRequests();
683 ProfileIOData
* ProfileIOData::FromResourceContext(
684 content::ResourceContext
* rc
) {
685 return (static_cast<ResourceContext
*>(rc
))->io_data_
;
689 bool ProfileIOData::IsHandledProtocol(const std::string
& scheme
) {
690 DCHECK_EQ(scheme
, base::StringToLowerASCII(scheme
));
691 static const char* const kProtocolList
[] = {
693 content::kChromeDevToolsScheme
,
694 dom_distiller::kDomDistillerScheme
,
695 #if defined(ENABLE_EXTENSIONS)
696 extensions::kExtensionScheme
,
697 extensions::kExtensionResourceScheme
,
699 content::kChromeUIScheme
,
701 #if defined(OS_CHROMEOS)
702 content::kExternalFileScheme
,
703 #endif // defined(OS_CHROMEOS)
705 #if !defined(DISABLE_FTP_SUPPORT)
707 #endif // !defined(DISABLE_FTP_SUPPORT)
709 url::kFileSystemScheme
,
710 chrome::kChromeSearchScheme
,
712 for (size_t i
= 0; i
< arraysize(kProtocolList
); ++i
) {
713 if (scheme
== kProtocolList
[i
])
716 return net::URLRequest::IsHandledProtocol(scheme
);
720 bool ProfileIOData::IsHandledURL(const GURL
& url
) {
721 if (!url
.is_valid()) {
722 // We handle error cases.
726 return IsHandledProtocol(url
.scheme());
730 void ProfileIOData::InstallProtocolHandlers(
731 net::URLRequestJobFactoryImpl
* job_factory
,
732 content::ProtocolHandlerMap
* protocol_handlers
) {
733 for (content::ProtocolHandlerMap::iterator it
=
734 protocol_handlers
->begin();
735 it
!= protocol_handlers
->end();
737 bool set_protocol
= job_factory
->SetProtocolHandler(
738 it
->first
, it
->second
.release());
739 DCHECK(set_protocol
);
741 protocol_handlers
->clear();
744 content::ResourceContext
* ProfileIOData::GetResourceContext() const {
745 return resource_context_
.get();
748 net::URLRequestContext
* ProfileIOData::GetMainRequestContext() const {
749 DCHECK(initialized_
);
750 return main_request_context_
.get();
753 net::URLRequestContext
* ProfileIOData::GetMediaRequestContext() const {
754 DCHECK(initialized_
);
755 net::URLRequestContext
* context
= AcquireMediaRequestContext();
760 net::URLRequestContext
* ProfileIOData::GetExtensionsRequestContext() const {
761 DCHECK(initialized_
);
762 return extensions_request_context_
.get();
765 net::URLRequestContext
* ProfileIOData::GetIsolatedAppRequestContext(
766 net::URLRequestContext
* main_context
,
767 const StoragePartitionDescriptor
& partition_descriptor
,
768 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
769 protocol_handler_interceptor
,
770 content::ProtocolHandlerMap
* protocol_handlers
,
771 content::URLRequestInterceptorScopedVector request_interceptors
) const {
772 DCHECK(initialized_
);
773 net::URLRequestContext
* context
= NULL
;
774 if (ContainsKey(app_request_context_map_
, partition_descriptor
)) {
775 context
= app_request_context_map_
[partition_descriptor
];
778 AcquireIsolatedAppRequestContext(main_context
,
779 partition_descriptor
,
780 protocol_handler_interceptor
.Pass(),
782 request_interceptors
.Pass());
783 app_request_context_map_
[partition_descriptor
] = context
;
789 net::URLRequestContext
* ProfileIOData::GetIsolatedMediaRequestContext(
790 net::URLRequestContext
* app_context
,
791 const StoragePartitionDescriptor
& partition_descriptor
) const {
792 DCHECK(initialized_
);
793 net::URLRequestContext
* context
= NULL
;
794 if (ContainsKey(isolated_media_request_context_map_
, partition_descriptor
)) {
795 context
= isolated_media_request_context_map_
[partition_descriptor
];
797 context
= AcquireIsolatedMediaRequestContext(app_context
,
798 partition_descriptor
);
799 isolated_media_request_context_map_
[partition_descriptor
] = context
;
805 extensions::InfoMap
* ProfileIOData::GetExtensionInfoMap() const {
806 DCHECK(initialized_
) << "ExtensionSystem not initialized";
807 #if defined(ENABLE_EXTENSIONS)
808 return extension_info_map_
.get();
814 CookieSettings
* ProfileIOData::GetCookieSettings() const {
815 // Allow either Init() or SetCookieSettingsForTesting() to initialize.
816 DCHECK(initialized_
|| cookie_settings_
.get());
817 return cookie_settings_
.get();
820 HostContentSettingsMap
* ProfileIOData::GetHostContentSettingsMap() const {
821 DCHECK(initialized_
);
822 return host_content_settings_map_
.get();
825 ResourceContext::SaltCallback
ProfileIOData::GetMediaDeviceIDSalt() const {
826 return base::Bind(&MediaDeviceIDSalt::GetSalt
, media_device_id_salt_
);
829 bool ProfileIOData::IsOffTheRecord() const {
830 return profile_type() == Profile::INCOGNITO_PROFILE
831 || profile_type() == Profile::GUEST_PROFILE
;
834 void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() {
835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
836 #if defined(OS_CHROMEOS)
837 // Just fetch the value from ChromeOS' settings while we're on the UI thread.
838 // TODO(stevet): For now, this value is only set on profile initialization.
839 // We will want to do something similar to the PrefMember method below in the
840 // future to more accurately capture this state.
841 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref
,
843 #elif defined(OS_ANDROID)
844 // TODO(dwkang): rename or unify the pref for UMA once we have conclusion
845 // in crbugs.com/246495.
846 // Android has it's own preferences for metrics / crash uploading.
847 enable_metrics_
.Init(prefs::kCrashReportingEnabled
,
848 g_browser_process
->local_state());
849 enable_metrics_
.MoveToThread(
850 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
852 // Prep the PrefMember and send it to the IO thread, since this value will be
854 enable_metrics_
.Init(prefs::kMetricsReportingEnabled
,
855 g_browser_process
->local_state());
856 enable_metrics_
.MoveToThread(
857 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
858 #endif // defined(OS_CHROMEOS)
861 bool ProfileIOData::GetMetricsEnabledStateOnIOThread() const {
862 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
863 #if defined(OS_CHROMEOS)
864 return enable_metrics_
;
866 return enable_metrics_
.GetValue();
867 #endif // defined(OS_CHROMEOS)
870 bool ProfileIOData::IsDataReductionProxyEnabled() const {
871 return data_reduction_proxy_io_data()->IsEnabled();
874 void ProfileIOData::set_data_reduction_proxy_io_data(
875 scoped_ptr
<data_reduction_proxy::DataReductionProxyIOData
>
876 data_reduction_proxy_io_data
) const {
877 data_reduction_proxy_io_data_
= data_reduction_proxy_io_data
.Pass();
880 base::WeakPtr
<net::HttpServerProperties
>
881 ProfileIOData::http_server_properties() const {
882 return http_server_properties_
->GetWeakPtr();
885 void ProfileIOData::set_http_server_properties(
886 scoped_ptr
<net::HttpServerProperties
> http_server_properties
) const {
887 http_server_properties_
= http_server_properties
.Pass();
890 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData
* io_data
)
892 host_resolver_(NULL
),
893 request_context_(NULL
) {
897 ProfileIOData::ResourceContext::~ResourceContext() {}
899 net::HostResolver
* ProfileIOData::ResourceContext::GetHostResolver() {
900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
901 DCHECK(io_data_
->initialized_
);
902 return host_resolver_
;
905 net::URLRequestContext
* ProfileIOData::ResourceContext::GetRequestContext() {
906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
907 DCHECK(io_data_
->initialized_
);
908 return request_context_
;
911 scoped_ptr
<net::ClientCertStore
>
912 ProfileIOData::ResourceContext::CreateClientCertStore() {
913 if (!io_data_
->client_cert_store_factory_
.is_null())
914 return io_data_
->client_cert_store_factory_
.Run();
915 #if defined(OS_CHROMEOS)
916 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreChromeOS(
917 make_scoped_ptr(new chromeos::ClientCertFilterChromeOS(
918 io_data_
->use_system_key_slot(), io_data_
->username_hash())),
919 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
920 chrome::kCryptoModulePasswordClientAuth
)));
921 #elif defined(USE_NSS)
922 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreNSS(
923 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
924 chrome::kCryptoModulePasswordClientAuth
)));
925 #elif defined(OS_WIN)
926 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreWin());
927 #elif defined(OS_MACOSX)
928 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreMac());
929 #elif defined(USE_OPENSSL)
930 // OpenSSL does not use the ClientCertStore infrastructure. On Android client
931 // cert matching is done by the OS as part of the call to show the cert
933 return scoped_ptr
<net::ClientCertStore
>();
935 #error Unknown platform.
939 void ProfileIOData::ResourceContext::CreateKeygenHandler(
940 uint32 key_size_in_bits
,
941 const std::string
& challenge_string
,
943 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
) {
944 DCHECK(!callback
.is_null());
946 scoped_ptr
<net::KeygenHandler
> keygen_handler(
947 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
));
949 base::Callback
<void(scoped_ptr
<ChromeNSSCryptoModuleDelegate
>)>
950 got_delegate_callback
= base::Bind(&InitializeAndPassKeygenHandler
,
951 base::Passed(&keygen_handler
),
954 ChromeNSSCryptoModuleDelegate::CreateForResourceContext(
955 chrome::kCryptoModulePasswordKeygen
,
956 net::HostPortPair::FromURL(url
),
958 got_delegate_callback
);
960 callback
.Run(make_scoped_ptr(
961 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
)));
965 ResourceContext::SaltCallback
966 ProfileIOData::ResourceContext::GetMediaDeviceIDSalt() {
967 return io_data_
->GetMediaDeviceIDSalt();
971 std::string
ProfileIOData::GetSSLSessionCacheShard() {
972 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
973 // The SSL session cache is partitioned by setting a string. This returns a
974 // unique string to partition the SSL session cache. Each time we create a
975 // new profile, we'll get a fresh SSL session cache which is separate from
976 // the other profiles.
977 static unsigned ssl_session_cache_instance
= 0;
978 return base::StringPrintf("profile/%u", ssl_session_cache_instance
++);
981 void ProfileIOData::Init(
982 content::ProtocolHandlerMap
* protocol_handlers
,
983 content::URLRequestInterceptorScopedVector request_interceptors
) const {
984 // The basic logic is implemented here. The specific initialization
985 // is done in InitializeInternal(), implemented by subtypes. Static helper
986 // functions have been provided to assist in common operations.
987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
988 DCHECK(!initialized_
);
990 startup_metric_utils::ScopedSlowStartupUMA
991 scoped_timer("Startup.SlowStartupProfileIODataInit");
993 // TODO(jhawkins): Remove once crbug.com/102004 is fixed.
994 CHECK(initialized_on_UI_thread_
);
996 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed.
997 CHECK(profile_params_
.get());
999 IOThread
* const io_thread
= profile_params_
->io_thread
;
1000 IOThread::Globals
* const io_thread_globals
= io_thread
->globals();
1001 const base::CommandLine
& command_line
=
1002 *base::CommandLine::ForCurrentProcess();
1004 // Create the common request contexts.
1005 main_request_context_
.reset(new net::URLRequestContext());
1006 extensions_request_context_
.reset(new net::URLRequestContext());
1008 scoped_ptr
<ChromeNetworkDelegate
> network_delegate(
1009 new ChromeNetworkDelegate(
1010 #if defined(ENABLE_EXTENSIONS)
1011 io_thread_globals
->extension_event_router_forwarder
.get(),
1015 &enable_referrers_
));
1016 #if defined(ENABLE_EXTENSIONS)
1017 network_delegate
->set_extension_info_map(
1018 profile_params_
->extension_info_map
.get());
1020 #if defined(ENABLE_CONFIGURATION_POLICY)
1021 network_delegate
->set_url_blacklist_manager(url_blacklist_manager_
.get());
1023 network_delegate
->set_profile(profile_params_
->profile
);
1024 network_delegate
->set_profile_path(profile_params_
->path
);
1025 network_delegate
->set_cookie_settings(profile_params_
->cookie_settings
.get());
1026 network_delegate
->set_enable_do_not_track(&enable_do_not_track_
);
1027 network_delegate
->set_force_google_safe_search(&force_google_safesearch_
);
1028 network_delegate
->set_force_youtube_safety_mode(&force_youtube_safety_mode_
);
1029 fraudulent_certificate_reporter_
.reset(
1030 new chrome_browser_net::ChromeFraudulentCertificateReporter(
1031 main_request_context_
.get()));
1033 // NOTE: Proxy service uses the default io thread network delegate, not the
1034 // delegate just created.
1035 proxy_service_
.reset(
1036 ProxyServiceFactory::CreateProxyService(
1037 io_thread
->net_log(),
1038 io_thread_globals
->proxy_script_fetcher_context
.get(),
1039 io_thread_globals
->system_network_delegate
.get(),
1040 profile_params_
->proxy_config_service
.release(),
1042 quick_check_enabled_
.GetValue()));
1043 transport_security_state_
.reset(new net::TransportSecurityState());
1044 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
1045 transport_security_persister_
.reset(
1046 new net::TransportSecurityPersister(
1047 transport_security_state_
.get(),
1048 profile_params_
->path
,
1049 pool
->GetSequencedTaskRunnerWithShutdownBehavior(
1050 pool
->GetSequenceToken(),
1051 base::SequencedWorkerPool::BLOCK_SHUTDOWN
),
1054 // Take ownership over these parameters.
1055 cookie_settings_
= profile_params_
->cookie_settings
;
1056 host_content_settings_map_
= profile_params_
->host_content_settings_map
;
1057 #if defined(ENABLE_EXTENSIONS)
1058 extension_info_map_
= profile_params_
->extension_info_map
;
1061 resource_context_
->host_resolver_
= io_thread_globals
->host_resolver
.get();
1062 resource_context_
->request_context_
= main_request_context_
.get();
1064 if (profile_params_
->resource_prefetch_predictor_observer_
) {
1065 resource_prefetch_predictor_observer_
.reset(
1066 profile_params_
->resource_prefetch_predictor_observer_
.release());
1069 #if defined(ENABLE_SUPERVISED_USERS)
1070 supervised_user_url_filter_
= profile_params_
->supervised_user_url_filter
;
1073 #if defined(OS_CHROMEOS)
1074 username_hash_
= profile_params_
->username_hash
;
1075 use_system_key_slot_
= profile_params_
->use_system_key_slot
;
1076 if (use_system_key_slot_
)
1077 EnableNSSSystemKeySlotForResourceContext(resource_context_
.get());
1079 crypto::ScopedPK11Slot public_slot
=
1080 crypto::GetPublicSlotForChromeOSUser(username_hash_
);
1081 // The private slot won't be ready by this point. It shouldn't be necessary
1082 // for cert trust purposes anyway.
1083 scoped_refptr
<net::CertVerifyProc
> verify_proc(
1084 new chromeos::CertVerifyProcChromeOS(public_slot
.Pass()));
1085 if (policy_cert_verifier_
) {
1086 DCHECK_EQ(policy_cert_verifier_
, cert_verifier_
.get());
1087 policy_cert_verifier_
->InitializeOnIOThread(verify_proc
);
1089 cert_verifier_
.reset(new net::MultiThreadedCertVerifier(verify_proc
.get()));
1091 main_request_context_
->set_cert_verifier(cert_verifier_
.get());
1093 main_request_context_
->set_cert_verifier(
1094 io_thread_globals
->cert_verifier
.get());
1097 // Install the New Tab Page Interceptor.
1098 if (profile_params_
->new_tab_page_interceptor
.get()) {
1099 request_interceptors
.push_back(
1100 profile_params_
->new_tab_page_interceptor
.release());
1104 network_delegate
.Pass(), profile_params_
.get(),
1105 protocol_handlers
, request_interceptors
.Pass());
1107 profile_params_
.reset();
1108 initialized_
= true;
1111 void ProfileIOData::ApplyProfileParamsToContext(
1112 net::URLRequestContext
* context
) const {
1113 context
->set_http_user_agent_settings(
1114 chrome_http_user_agent_settings_
.get());
1115 context
->set_ssl_config_service(profile_params_
->ssl_config_service
.get());
1118 scoped_ptr
<net::URLRequestJobFactory
> ProfileIOData::SetUpJobFactoryDefaults(
1119 scoped_ptr
<net::URLRequestJobFactoryImpl
> job_factory
,
1120 content::URLRequestInterceptorScopedVector request_interceptors
,
1121 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
1122 protocol_handler_interceptor
,
1123 net::NetworkDelegate
* network_delegate
,
1124 net::FtpTransactionFactory
* ftp_transaction_factory
) const {
1125 // NOTE(willchan): Keep these protocol handlers in sync with
1126 // ProfileIOData::IsHandledProtocol().
1127 bool set_protocol
= job_factory
->SetProtocolHandler(
1129 new net::FileProtocolHandler(
1130 content::BrowserThread::GetBlockingPool()->
1131 GetTaskRunnerWithShutdownBehavior(
1132 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
)));
1133 DCHECK(set_protocol
);
1135 #if defined(ENABLE_EXTENSIONS)
1136 DCHECK(extension_info_map_
.get());
1137 // Check only for incognito (and not Chrome OS guest mode GUEST_PROFILE).
1138 bool is_incognito
= profile_type() == Profile::INCOGNITO_PROFILE
;
1139 set_protocol
= job_factory
->SetProtocolHandler(
1140 extensions::kExtensionScheme
,
1141 extensions::CreateExtensionProtocolHandler(is_incognito
,
1142 extension_info_map_
.get()));
1143 DCHECK(set_protocol
);
1144 set_protocol
= job_factory
->SetProtocolHandler(
1145 extensions::kExtensionResourceScheme
,
1146 CreateExtensionResourceProtocolHandler());
1147 DCHECK(set_protocol
);
1149 set_protocol
= job_factory
->SetProtocolHandler(
1150 url::kDataScheme
, new net::DataProtocolHandler());
1151 DCHECK(set_protocol
);
1152 #if defined(OS_CHROMEOS)
1153 if (profile_params_
) {
1154 set_protocol
= job_factory
->SetProtocolHandler(
1155 content::kExternalFileScheme
,
1156 new chromeos::ExternalFileProtocolHandler(profile_params_
->profile
));
1157 DCHECK(set_protocol
);
1159 #endif // defined(OS_CHROMEOS)
1160 #if defined(OS_ANDROID)
1161 set_protocol
= job_factory
->SetProtocolHandler(
1162 url::kContentScheme
,
1163 content::ContentProtocolHandler::Create(
1164 content::BrowserThread::GetBlockingPool()->
1165 GetTaskRunnerWithShutdownBehavior(
1166 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
)));
1169 job_factory
->SetProtocolHandler(
1170 url::kAboutScheme
, new chrome_browser_net::AboutProtocolHandler());
1171 #if !defined(DISABLE_FTP_SUPPORT)
1172 DCHECK(ftp_transaction_factory
);
1173 job_factory
->SetProtocolHandler(
1175 new net::FtpProtocolHandler(ftp_transaction_factory
));
1176 #endif // !defined(DISABLE_FTP_SUPPORT)
1178 #if defined(DEBUG_DEVTOOLS)
1179 request_interceptors
.push_back(new DebugDevToolsInterceptor
);
1182 // Set up interceptors in the reverse order.
1183 scoped_ptr
<net::URLRequestJobFactory
> top_job_factory
= job_factory
.Pass();
1184 for (content::URLRequestInterceptorScopedVector::reverse_iterator i
=
1185 request_interceptors
.rbegin();
1186 i
!= request_interceptors
.rend();
1188 top_job_factory
.reset(new net::URLRequestInterceptingJobFactory(
1189 top_job_factory
.Pass(), make_scoped_ptr(*i
)));
1191 request_interceptors
.weak_clear();
1193 if (protocol_handler_interceptor
) {
1194 protocol_handler_interceptor
->Chain(top_job_factory
.Pass());
1195 return protocol_handler_interceptor
.Pass();
1197 return top_job_factory
.Pass();
1201 void ProfileIOData::ShutdownOnUIThread(
1202 scoped_ptr
<ChromeURLRequestContextGetterVector
> context_getters
) {
1203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1206 signin_names_
->ReleaseResourcesOnUIThread();
1208 google_services_user_account_id_
.Destroy();
1209 enable_referrers_
.Destroy();
1210 enable_do_not_track_
.Destroy();
1211 force_google_safesearch_
.Destroy();
1212 force_youtube_safety_mode_
.Destroy();
1213 #if !defined(OS_CHROMEOS)
1214 enable_metrics_
.Destroy();
1216 safe_browsing_enabled_
.Destroy();
1217 sync_disabled_
.Destroy();
1218 signin_allowed_
.Destroy();
1219 network_prediction_options_
.Destroy();
1220 quick_check_enabled_
.Destroy();
1221 if (media_device_id_salt_
.get())
1222 media_device_id_salt_
->ShutdownOnUIThread();
1223 session_startup_pref_
.Destroy();
1224 #if defined(ENABLE_CONFIGURATION_POLICY)
1225 if (url_blacklist_manager_
)
1226 url_blacklist_manager_
->ShutdownOnUIThread();
1228 if (chrome_http_user_agent_settings_
)
1229 chrome_http_user_agent_settings_
->CleanupOnUIThread();
1230 incognito_availibility_pref_
.Destroy();
1232 if (!context_getters
->empty()) {
1233 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
)) {
1234 BrowserThread::PostTask(
1235 BrowserThread::IO
, FROM_HERE
,
1236 base::Bind(&InvalidateContextGettersOnIO
,
1237 base::Passed(&context_getters
)));
1241 bool posted
= BrowserThread::DeleteSoon(BrowserThread::IO
, FROM_HERE
, this);
1246 void ProfileIOData::set_channel_id_service(
1247 net::ChannelIDService
* channel_id_service
) const {
1248 channel_id_service_
.reset(channel_id_service
);
1251 void ProfileIOData::DestroyResourceContext() {
1252 resource_context_
.reset();
1255 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateMainHttpFactory(
1256 const ProfileParams
* profile_params
,
1257 net::HttpCache::BackendFactory
* main_backend
) const {
1258 net::HttpNetworkSession::Params params
;
1259 net::URLRequestContext
* context
= main_request_context();
1261 IOThread
* const io_thread
= profile_params
->io_thread
;
1263 io_thread
->InitializeNetworkSessionParams(¶ms
);
1265 params
.host_resolver
= context
->host_resolver();
1266 params
.cert_verifier
= context
->cert_verifier();
1267 params
.channel_id_service
= context
->channel_id_service();
1268 params
.transport_security_state
= context
->transport_security_state();
1269 params
.cert_transparency_verifier
= context
->cert_transparency_verifier();
1270 params
.proxy_service
= context
->proxy_service();
1271 params
.ssl_session_cache_shard
= GetSSLSessionCacheShard();
1272 params
.ssl_config_service
= context
->ssl_config_service();
1273 params
.http_auth_handler_factory
= context
->http_auth_handler_factory();
1274 params
.network_delegate
= context
->network_delegate();
1275 params
.http_server_properties
= context
->http_server_properties();
1276 params
.net_log
= context
->net_log();
1277 if (data_reduction_proxy_io_data_
.get())
1278 params
.proxy_delegate
= data_reduction_proxy_io_data_
->proxy_delegate();
1280 network_controller_
.reset(new DevToolsNetworkController());
1282 net::HttpNetworkSession
* session
= new net::HttpNetworkSession(params
);
1283 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1284 new DevToolsNetworkTransactionFactory(network_controller_
.get(), session
),
1285 context
->net_log(), main_backend
));
1288 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateHttpFactory(
1289 net::HttpNetworkSession
* shared_session
,
1290 net::HttpCache::BackendFactory
* backend
) const {
1291 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1292 new DevToolsNetworkTransactionFactory(
1293 network_controller_
.get(), shared_session
),
1294 shared_session
->net_log(), backend
));
1297 void ProfileIOData::SetCookieSettingsForTesting(
1298 CookieSettings
* cookie_settings
) {
1299 DCHECK(!cookie_settings_
.get());
1300 cookie_settings_
= cookie_settings
;
1303 void ProfileIOData::set_signin_names_for_testing(
1304 SigninNamesOnIOThread
* signin_names
) {
1305 signin_names_
.reset(signin_names
);