1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/profiles/profile_io_data.h"
9 #include "base/basictypes.h"
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/callback.h"
13 #include "base/command_line.h"
14 #include "base/compiler_specific.h"
15 #include "base/debug/alias.h"
16 #include "base/logging.h"
17 #include "base/path_service.h"
18 #include "base/prefs/pref_service.h"
19 #include "base/stl_util.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h"
23 #include "base/thread_task_runner_handle.h"
24 #include "base/threading/sequenced_worker_pool.h"
25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/content_settings/cookie_settings_factory.h"
28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
29 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
30 #include "chrome/browser/devtools/devtools_network_controller.h"
31 #include "chrome/browser/devtools/devtools_network_transaction_factory.h"
32 #include "chrome/browser/download/download_service.h"
33 #include "chrome/browser/download/download_service_factory.h"
34 #include "chrome/browser/io_thread.h"
35 #include "chrome/browser/media/media_device_id_salt.h"
36 #include "chrome/browser/net/chrome_http_user_agent_settings.h"
37 #include "chrome/browser/net/chrome_net_log.h"
38 #include "chrome/browser/net/chrome_network_delegate.h"
39 #include "chrome/browser/net/chrome_url_request_context_getter.h"
40 #include "chrome/browser/net/cookie_store_util.h"
41 #include "chrome/browser/net/proxy_service_factory.h"
42 #include "chrome/browser/net/resource_prefetch_predictor_observer.h"
43 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
44 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
45 #include "chrome/browser/profiles/profile.h"
46 #include "chrome/browser/profiles/profile_manager.h"
47 #include "chrome/browser/ui/search/new_tab_page_interceptor_service.h"
48 #include "chrome/browser/ui/search/new_tab_page_interceptor_service_factory.h"
49 #include "chrome/common/chrome_paths.h"
50 #include "chrome/common/chrome_switches.h"
51 #include "chrome/common/pref_names.h"
52 #include "chrome/common/url_constants.h"
53 #include "components/about_handler/about_protocol_handler.h"
54 #include "components/content_settings/core/browser/content_settings_provider.h"
55 #include "components/content_settings/core/browser/cookie_settings.h"
56 #include "components/content_settings/core/browser/host_content_settings_map.h"
57 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
58 #include "components/dom_distiller/core/url_constants.h"
59 #include "components/sync_driver/pref_names.h"
60 #include "components/url_formatter/url_fixer.h"
61 #include "content/public/browser/browser_thread.h"
62 #include "content/public/browser/host_zoom_map.h"
63 #include "content/public/browser/notification_service.h"
64 #include "content/public/browser/resource_context.h"
65 #include "net/base/keygen_handler.h"
66 #include "net/base/network_quality_estimator.h"
67 #include "net/cert/cert_verifier.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/certificate_report_sender.h"
78 #include "net/url_request/data_protocol_handler.h"
79 #include "net/url_request/file_protocol_handler.h"
80 #include "net/url_request/ftp_protocol_handler.h"
81 #include "net/url_request/url_request.h"
82 #include "net/url_request/url_request_context.h"
83 #include "net/url_request/url_request_context_builder.h"
84 #include "net/url_request/url_request_file_job.h"
85 #include "net/url_request/url_request_intercepting_job_factory.h"
86 #include "net/url_request/url_request_interceptor.h"
87 #include "net/url_request/url_request_job_factory_impl.h"
89 #if defined(ENABLE_CONFIGURATION_POLICY)
90 #include "chrome/browser/policy/cloud/policy_header_service_factory.h"
91 #include "chrome/browser/policy/policy_helpers.h"
92 #include "components/policy/core/browser/url_blacklist_manager.h"
93 #include "components/policy/core/common/cloud/policy_header_io_helper.h"
94 #include "components/policy/core/common/cloud/policy_header_service.h"
95 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
98 #if defined(ENABLE_EXTENSIONS)
99 #include "chrome/browser/extensions/extension_cookie_monster_delegate.h"
100 #include "chrome/browser/extensions/extension_resource_protocols.h"
101 #include "extensions/browser/extension_protocols.h"
102 #include "extensions/browser/extension_system.h"
103 #include "extensions/browser/extension_throttle_manager.h"
104 #include "extensions/browser/info_map.h"
105 #include "extensions/common/constants.h"
108 #if defined(ENABLE_SUPERVISED_USERS)
109 #include "chrome/browser/supervised_user/supervised_user_service.h"
110 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
111 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
114 #if defined(OS_ANDROID)
115 #include "content/public/browser/android/content_protocol_handler.h"
116 #endif // defined(OS_ANDROID)
118 #if defined(OS_CHROMEOS)
119 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h"
120 #include "chrome/browser/chromeos/fileapi/external_file_protocol_handler.h"
121 #include "chrome/browser/chromeos/login/startup_utils.h"
122 #include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
123 #include "chrome/browser/chromeos/net/client_cert_filter_chromeos.h"
124 #include "chrome/browser/chromeos/net/client_cert_store_chromeos.h"
125 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
126 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
127 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
128 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
129 #include "chrome/browser/chromeos/profiles/profile_helper.h"
130 #include "chrome/browser/chromeos/settings/cros_settings.h"
131 #include "chrome/browser/net/nss_context.h"
132 #include "chromeos/dbus/dbus_thread_manager.h"
133 #include "chromeos/settings/cros_settings_names.h"
134 #include "chromeos/tpm/tpm_token_info_getter.h"
135 #include "components/user_manager/user.h"
136 #include "components/user_manager/user_manager.h"
137 #include "crypto/nss_util.h"
138 #include "crypto/nss_util_internal.h"
139 #include "net/cert/cert_verifier.h"
140 #include "net/cert/multi_threaded_cert_verifier.h"
141 #endif // defined(OS_CHROMEOS)
143 #if defined(USE_NSS_CERTS)
144 #include "chrome/browser/ui/crypto_module_delegate_nss.h"
145 #include "net/ssl/client_cert_store_nss.h"
149 #include "net/ssl/client_cert_store_win.h"
152 #if defined(OS_MACOSX)
153 #include "net/ssl/client_cert_store_mac.h"
156 using content::BrowserContext
;
157 using content::BrowserThread
;
158 using content::ResourceContext
;
162 net::CertVerifier
* g_cert_verifier_for_testing
= nullptr;
164 #if defined(DEBUG_DEVTOOLS)
165 bool IsSupportedDevToolsURL(const GURL
& url
, base::FilePath
* path
) {
166 std::string
bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath
);
167 bundled_path_prefix
= "/" + bundled_path_prefix
+ "/";
169 if (!url
.SchemeIs(content::kChromeDevToolsScheme
) ||
170 url
.host() != chrome::kChromeUIDevToolsHost
||
171 !base::StartsWith(url
.path(), bundled_path_prefix
,
172 base::CompareCase::INSENSITIVE_ASCII
)) {
176 if (!url
.is_valid()) {
181 // Remove Query and Ref from URL.
183 GURL::Replacements replacements
;
184 replacements
.ClearQuery();
185 replacements
.ClearRef();
186 stripped_url
= url
.ReplaceComponents(replacements
);
188 std::string relative_path
;
189 const std::string
& spec
= stripped_url
.possibly_invalid_spec();
190 const url::Parsed
& parsed
= stripped_url
.parsed_for_possibly_invalid_spec();
191 int offset
= parsed
.CountCharactersBefore(url::Parsed::PATH
, false);
192 if (offset
< static_cast<int>(spec
.size()))
193 relative_path
.assign(spec
.substr(offset
+ bundled_path_prefix
.length()));
195 // Check that |relative_path| is not an absolute path (otherwise
196 // AppendASCII() will DCHECK). The awkward use of StringType is because on
197 // some systems FilePath expects a std::string, but on others a std::wstring.
199 base::FilePath::StringType(relative_path
.begin(), relative_path
.end()));
203 base::FilePath inspector_dir
;
204 if (!PathService::Get(chrome::DIR_INSPECTOR
, &inspector_dir
))
207 if (inspector_dir
.empty())
210 *path
= inspector_dir
.AppendASCII(relative_path
);
214 class DebugDevToolsInterceptor
: public net::URLRequestInterceptor
{
216 // net::URLRequestInterceptor implementation.
217 net::URLRequestJob
* MaybeInterceptRequest(
218 net::URLRequest
* request
,
219 net::NetworkDelegate
* network_delegate
) const override
{
221 if (IsSupportedDevToolsURL(request
->url(), &path
))
222 return new net::URLRequestFileJob(
223 request
, network_delegate
, path
,
224 content::BrowserThread::GetBlockingPool()->
225 GetTaskRunnerWithShutdownBehavior(
226 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
));
231 #endif // defined(DEBUG_DEVTOOLS)
233 #if defined(OS_CHROMEOS)
234 // The following four functions are responsible for initializing NSS for each
235 // profile on ChromeOS, which has a separate NSS database and TPM slot
238 // Initialization basically follows these steps:
239 // 1) Get some info from user_manager::UserManager about the User for this
241 // 2) Tell nss_util to initialize the software slot for this profile.
242 // 3) Wait for the TPM module to be loaded by nss_util if it isn't already.
243 // 4) Ask CryptohomeClient which TPM slot id corresponds to this profile.
244 // 5) Tell nss_util to use that slot id on the TPM module.
246 // Some of these steps must happen on the UI thread, others must happen on the
248 // UI thread IO Thread
250 // ProfileIOData::InitializeOnUIThread
252 // ProfileHelper::Get()->GetUserByProfile()
253 // \---------------------------------------v
254 // StartNSSInitOnIOThread
256 // crypto::InitializeNSSForChromeOSUser
258 // crypto::IsTPMTokenReady
260 // StartTPMSlotInitializationOnIOThread
261 // v---------------------------------------/
262 // GetTPMInfoForUserOnUIThread
264 // chromeos::TPMTokenInfoGetter::Start
266 // DidGetTPMInfoForUserOnUIThread
267 // \---------------------------------------v
268 // crypto::InitializeTPMForChromeOSUser
270 void DidGetTPMInfoForUserOnUIThread(
271 scoped_ptr
<chromeos::TPMTokenInfoGetter
> getter
,
272 const std::string
& username_hash
,
273 const chromeos::TPMTokenInfo
& info
) {
274 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
275 if (info
.tpm_is_enabled
&& info
.token_slot_id
!= -1) {
276 DVLOG(1) << "Got TPM slot for " << username_hash
<< ": "
277 << info
.token_slot_id
;
278 BrowserThread::PostTask(
281 base::Bind(&crypto::InitializeTPMForChromeOSUser
,
282 username_hash
, info
.token_slot_id
));
284 NOTREACHED() << "TPMTokenInfoGetter reported invalid token.";
288 void GetTPMInfoForUserOnUIThread(const std::string
& username
,
289 const std::string
& username_hash
) {
290 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
291 DVLOG(1) << "Getting TPM info from cryptohome for "
292 << " " << username
<< " " << username_hash
;
293 scoped_ptr
<chromeos::TPMTokenInfoGetter
> scoped_token_info_getter
=
294 chromeos::TPMTokenInfoGetter::CreateForUserToken(
296 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(),
297 base::ThreadTaskRunnerHandle::Get());
298 chromeos::TPMTokenInfoGetter
* token_info_getter
=
299 scoped_token_info_getter
.get();
301 // Bind |token_info_getter| to the callback to ensure it does not go away
302 // before TPM token info is fetched.
303 // TODO(tbarzic, pneubeck): Handle this in a nicer way when this logic is
304 // moved to a separate profile service.
305 token_info_getter
->Start(
306 base::Bind(&DidGetTPMInfoForUserOnUIThread
,
307 base::Passed(&scoped_token_info_getter
),
311 void StartTPMSlotInitializationOnIOThread(const std::string
& username
,
312 const std::string
& username_hash
) {
313 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
315 BrowserThread::PostTask(
318 base::Bind(&GetTPMInfoForUserOnUIThread
, username
, username_hash
));
321 void StartNSSInitOnIOThread(const std::string
& username
,
322 const std::string
& username_hash
,
323 const base::FilePath
& path
) {
324 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
325 DVLOG(1) << "Starting NSS init for " << username
326 << " hash:" << username_hash
;
328 // Make sure NSS is initialized for the user.
329 crypto::InitializeNSSForChromeOSUser(username_hash
, path
);
331 // Check if it's OK to initialize TPM for the user before continuing. This
332 // may not be the case if the TPM slot initialization was previously
333 // requested for the same user.
334 if (!crypto::ShouldInitializeTPMForChromeOSUser(username_hash
))
337 crypto::WillInitializeTPMForChromeOSUser(username_hash
);
339 if (crypto::IsTPMTokenEnabledForNSS()) {
340 if (crypto::IsTPMTokenReady(base::Bind(
341 &StartTPMSlotInitializationOnIOThread
, username
, username_hash
))) {
342 StartTPMSlotInitializationOnIOThread(username
, username_hash
);
344 DVLOG(1) << "Waiting for tpm ready ...";
347 crypto::InitializePrivateSoftwareSlotForChromeOSUser(username_hash
);
350 #endif // defined(OS_CHROMEOS)
352 #if defined(USE_NSS_CERTS)
353 void InitializeAndPassKeygenHandler(
354 scoped_ptr
<net::KeygenHandler
> keygen_handler
,
355 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
,
356 scoped_ptr
<ChromeNSSCryptoModuleDelegate
> delegate
) {
358 keygen_handler
->set_crypto_module_delegate(delegate
.Pass());
359 callback
.Run(keygen_handler
.Pass());
361 #endif // defined(USE_NSS_CERTS)
363 // For safe shutdown, must be called before the ProfileIOData is destroyed.
364 void NotifyContextGettersOfShutdownOnIO(
365 scoped_ptr
<ProfileIOData::ChromeURLRequestContextGetterVector
> getters
) {
366 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
367 ProfileIOData::ChromeURLRequestContextGetterVector::iterator iter
;
368 for (auto& chrome_context_getter
: *getters
)
369 chrome_context_getter
->NotifyContextShuttingDown();
374 void ProfileIOData::InitializeOnUIThread(Profile
* profile
) {
375 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
376 PrefService
* pref_service
= profile
->GetPrefs();
377 PrefService
* local_state_pref_service
= g_browser_process
->local_state();
379 scoped_ptr
<ProfileParams
> params(new ProfileParams
);
380 params
->path
= profile
->GetPath();
382 params
->io_thread
= g_browser_process
->io_thread();
384 params
->cookie_settings
= CookieSettingsFactory::GetForProfile(profile
);
385 params
->host_content_settings_map
= profile
->GetHostContentSettingsMap();
386 params
->ssl_config_service
= profile
->GetSSLConfigService();
388 #if defined(ENABLE_EXTENSIONS)
389 params
->extension_info_map
=
390 extensions::ExtensionSystem::Get(profile
)->info_map();
391 params
->cookie_monster_delegate
= new ExtensionCookieMonsterDelegate(profile
);
394 if (predictors::ResourcePrefetchPredictor
* predictor
=
395 predictors::ResourcePrefetchPredictorFactory::GetForProfile(
397 resource_prefetch_predictor_observer_
.reset(
398 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor
));
401 ProtocolHandlerRegistry
* protocol_handler_registry
=
402 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile
);
403 DCHECK(protocol_handler_registry
);
405 // The profile instance is only available here in the InitializeOnUIThread
406 // method, so we create the url job factory here, then save it for
407 // later delivery to the job factory in Init().
408 params
->protocol_handler_interceptor
=
409 protocol_handler_registry
->CreateJobInterceptorFactory();
411 NewTabPageInterceptorService
* new_tab_interceptor_service
=
412 NewTabPageInterceptorServiceFactory::GetForProfile(profile
);
413 if (new_tab_interceptor_service
) {
414 params
->new_tab_page_interceptor
=
415 new_tab_interceptor_service
->CreateInterceptor();
418 params
->proxy_config_service
419 .reset(ProxyServiceFactory::CreateProxyConfigService(
420 profile
->GetProxyConfigTracker()));
421 #if defined(ENABLE_SUPERVISED_USERS)
422 SupervisedUserService
* supervised_user_service
=
423 SupervisedUserServiceFactory::GetForProfile(profile
);
424 params
->supervised_user_url_filter
=
425 supervised_user_service
->GetURLFilterForIOThread();
427 #if defined(OS_CHROMEOS)
428 user_manager::UserManager
* user_manager
= user_manager::UserManager::Get();
430 const user_manager::User
* user
=
431 chromeos::ProfileHelper::Get()->GetUserByProfile(profile
);
432 // No need to initialize NSS for users with empty username hash:
433 // Getters for a user's NSS slots always return NULL slot if the user's
434 // username hash is empty, even when the NSS is not initialized for the
436 if (user
&& !user
->username_hash().empty()) {
437 params
->username_hash
= user
->username_hash();
438 DCHECK(!params
->username_hash
.empty());
439 BrowserThread::PostTask(BrowserThread::IO
,
441 base::Bind(&StartNSSInitOnIOThread
,
443 user
->username_hash(),
444 profile
->GetPath()));
446 // Use the device-wide system key slot only if the user is of the same
447 // domain as the device is registered to.
448 policy::BrowserPolicyConnectorChromeOS
* connector
=
449 g_browser_process
->platform_part()
450 ->browser_policy_connector_chromeos();
451 params
->use_system_key_slot
=
452 connector
->GetUserAffiliation(user
->email()) ==
453 policy::USER_AFFILIATION_MANAGED
;
458 params
->profile
= profile
;
459 profile_params_
.reset(params
.release());
461 ChromeNetworkDelegate::InitializePrefsOnUIThread(
463 &enable_do_not_track_
,
464 &force_google_safesearch_
,
465 &force_youtube_safety_mode_
,
468 scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner
=
469 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
);
471 chrome_http_user_agent_settings_
.reset(
472 new ChromeHttpUserAgentSettings(pref_service
));
474 // These members are used only for sign in, which is not enabled
475 // in incognito mode. So no need to initialize them.
476 if (!IsOffTheRecord()) {
477 google_services_user_account_id_
.Init(
478 prefs::kGoogleServicesUserAccountId
, pref_service
);
479 google_services_user_account_id_
.MoveToThread(io_task_runner
);
481 sync_disabled_
.Init(sync_driver::prefs::kSyncManaged
, pref_service
);
482 sync_disabled_
.MoveToThread(io_task_runner
);
484 signin_allowed_
.Init(prefs::kSigninAllowed
, pref_service
);
485 signin_allowed_
.MoveToThread(io_task_runner
);
488 quick_check_enabled_
.Init(prefs::kQuickCheckEnabled
,
489 local_state_pref_service
);
490 quick_check_enabled_
.MoveToThread(io_task_runner
);
492 media_device_id_salt_
= new MediaDeviceIDSalt(pref_service
, IsOffTheRecord());
494 network_prediction_options_
.Init(prefs::kNetworkPredictionOptions
,
497 network_prediction_options_
.MoveToThread(io_task_runner
);
499 #if defined(OS_CHROMEOS)
500 scoped_ptr
<policy::PolicyCertVerifier
> verifier
=
501 policy::PolicyCertServiceFactory::CreateForProfile(profile
);
502 policy_cert_verifier_
= verifier
.get();
503 cert_verifier_
= verifier
.Pass();
505 // The URLBlacklistManager has to be created on the UI thread to register
506 // observers of |pref_service|, and it also has to clean up on
507 // ShutdownOnUIThread to release these observers on the right thread.
508 // Don't pass it in |profile_params_| to make sure it is correctly cleaned up,
509 // in particular when this ProfileIOData isn't |initialized_| during deletion.
510 #if defined(ENABLE_CONFIGURATION_POLICY)
511 policy::URLBlacklist::SegmentURLCallback callback
=
512 static_cast<policy::URLBlacklist::SegmentURLCallback
>(
513 url_formatter::SegmentURL
);
514 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
515 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner
=
516 pool
->GetSequencedTaskRunner(pool
->GetSequenceToken());
517 url_blacklist_manager_
.reset(new policy::URLBlacklistManager(
518 pref_service
, background_task_runner
, io_task_runner
, callback
,
519 base::Bind(policy::OverrideBlacklistForURL
)));
521 if (!IsOffTheRecord()) {
522 // Add policy headers for non-incognito requests.
523 policy::PolicyHeaderService
* policy_header_service
=
524 policy::PolicyHeaderServiceFactory::GetForBrowserContext(profile
);
525 if (policy_header_service
) {
526 policy_header_helper_
=
527 policy_header_service
->CreatePolicyHeaderIOHelper(io_task_runner
);
532 incognito_availibility_pref_
.Init(
533 prefs::kIncognitoModeAvailability
, pref_service
);
534 incognito_availibility_pref_
.MoveToThread(io_task_runner
);
536 initialized_on_UI_thread_
= true;
538 // We need to make sure that content initializes its own data structures that
539 // are associated with each ResourceContext because we might post this
540 // object to the IO thread after this function.
541 BrowserContext::EnsureResourceContextInitialized(profile
);
544 ProfileIOData::MediaRequestContext::MediaRequestContext() {
547 void ProfileIOData::MediaRequestContext::SetHttpTransactionFactory(
548 scoped_ptr
<net::HttpTransactionFactory
> http_factory
) {
549 http_factory_
= http_factory
.Pass();
550 set_http_transaction_factory(http_factory_
.get());
553 ProfileIOData::MediaRequestContext::~MediaRequestContext() {
554 AssertNoURLRequests();
557 ProfileIOData::AppRequestContext::AppRequestContext() {
560 void ProfileIOData::AppRequestContext::SetCookieStore(
561 net::CookieStore
* cookie_store
) {
562 cookie_store_
= cookie_store
;
563 set_cookie_store(cookie_store
);
566 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory(
567 scoped_ptr
<net::HttpTransactionFactory
> http_factory
) {
568 http_factory_
= http_factory
.Pass();
569 set_http_transaction_factory(http_factory_
.get());
572 void ProfileIOData::AppRequestContext::SetJobFactory(
573 scoped_ptr
<net::URLRequestJobFactory
> job_factory
) {
574 job_factory_
= job_factory
.Pass();
575 set_job_factory(job_factory_
.get());
578 ProfileIOData::AppRequestContext::~AppRequestContext() {
579 AssertNoURLRequests();
582 ProfileIOData::ProfileParams::ProfileParams()
584 #if defined(OS_CHROMEOS)
585 use_system_key_slot(false),
590 ProfileIOData::ProfileParams::~ProfileParams() {}
592 ProfileIOData::ProfileIOData(Profile::ProfileType profile_type
)
593 : initialized_(false),
594 #if defined(OS_CHROMEOS)
595 policy_cert_verifier_(NULL
),
596 use_system_key_slot_(false),
598 resource_context_(new ResourceContext(this)),
599 initialized_on_UI_thread_(false),
600 profile_type_(profile_type
) {
601 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
604 ProfileIOData::~ProfileIOData() {
605 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
))
606 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
608 // Pull the contents of the request context maps onto the stack for sanity
609 // checking of values in a minidump. http://crbug.com/260425
610 size_t num_app_contexts
= app_request_context_map_
.size();
611 size_t num_media_contexts
= isolated_media_request_context_map_
.size();
612 size_t current_context
= 0;
613 static const size_t kMaxCachedContexts
= 20;
614 net::URLRequestContext
* app_context_cache
[kMaxCachedContexts
] = {0};
615 void* app_context_vtable_cache
[kMaxCachedContexts
] = {0};
616 net::URLRequestContext
* media_context_cache
[kMaxCachedContexts
] = {0};
617 void* media_context_vtable_cache
[kMaxCachedContexts
] = {0};
618 void* tmp_vtable
= NULL
;
619 base::debug::Alias(&num_app_contexts
);
620 base::debug::Alias(&num_media_contexts
);
621 base::debug::Alias(¤t_context
);
622 base::debug::Alias(app_context_cache
);
623 base::debug::Alias(app_context_vtable_cache
);
624 base::debug::Alias(media_context_cache
);
625 base::debug::Alias(media_context_vtable_cache
);
626 base::debug::Alias(&tmp_vtable
);
629 for (URLRequestContextMap::const_iterator it
=
630 app_request_context_map_
.begin();
631 current_context
< kMaxCachedContexts
&&
632 it
!= app_request_context_map_
.end();
633 ++it
, ++current_context
) {
634 app_context_cache
[current_context
] = it
->second
;
635 memcpy(&app_context_vtable_cache
[current_context
],
636 static_cast<void*>(it
->second
), sizeof(void*));
640 for (URLRequestContextMap::const_iterator it
=
641 isolated_media_request_context_map_
.begin();
642 current_context
< kMaxCachedContexts
&&
643 it
!= isolated_media_request_context_map_
.end();
644 ++it
, ++current_context
) {
645 media_context_cache
[current_context
] = it
->second
;
646 memcpy(&media_context_vtable_cache
[current_context
],
647 static_cast<void*>(it
->second
), sizeof(void*));
650 // Destroy certificate_report_sender_ before main_request_context_,
651 // since the former has a reference to the latter.
652 if (transport_security_state_
)
653 transport_security_state_
->SetReportSender(nullptr);
654 certificate_report_sender_
.reset();
656 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they
657 // are already done in the URLRequestContext destructor.
658 if (main_request_context_
)
659 main_request_context_
->AssertNoURLRequests();
660 if (extensions_request_context_
)
661 extensions_request_context_
->AssertNoURLRequests();
664 for (URLRequestContextMap::iterator it
= app_request_context_map_
.begin();
665 it
!= app_request_context_map_
.end(); ++it
) {
666 if (current_context
< kMaxCachedContexts
) {
667 CHECK_EQ(app_context_cache
[current_context
], it
->second
);
668 memcpy(&tmp_vtable
, static_cast<void*>(it
->second
), sizeof(void*));
669 CHECK_EQ(app_context_vtable_cache
[current_context
], tmp_vtable
);
671 it
->second
->AssertNoURLRequests();
677 for (URLRequestContextMap::iterator it
=
678 isolated_media_request_context_map_
.begin();
679 it
!= isolated_media_request_context_map_
.end(); ++it
) {
680 if (current_context
< kMaxCachedContexts
) {
681 CHECK_EQ(media_context_cache
[current_context
], it
->second
);
682 memcpy(&tmp_vtable
, static_cast<void*>(it
->second
), sizeof(void*));
683 CHECK_EQ(media_context_vtable_cache
[current_context
], tmp_vtable
);
685 it
->second
->AssertNoURLRequests();
692 ProfileIOData
* ProfileIOData::FromResourceContext(
693 content::ResourceContext
* rc
) {
694 return (static_cast<ResourceContext
*>(rc
))->io_data_
;
698 bool ProfileIOData::IsHandledProtocol(const std::string
& scheme
) {
699 DCHECK_EQ(scheme
, base::ToLowerASCII(scheme
));
700 static const char* const kProtocolList
[] = {
702 content::kChromeDevToolsScheme
,
703 dom_distiller::kDomDistillerScheme
,
704 #if defined(ENABLE_EXTENSIONS)
705 extensions::kExtensionScheme
,
706 extensions::kExtensionResourceScheme
,
708 content::kChromeUIScheme
,
710 #if defined(OS_CHROMEOS)
711 content::kExternalFileScheme
,
712 #endif // defined(OS_CHROMEOS)
714 #if !defined(DISABLE_FTP_SUPPORT)
716 #endif // !defined(DISABLE_FTP_SUPPORT)
718 url::kFileSystemScheme
,
719 chrome::kChromeSearchScheme
,
721 for (size_t i
= 0; i
< arraysize(kProtocolList
); ++i
) {
722 if (scheme
== kProtocolList
[i
])
725 return net::URLRequest::IsHandledProtocol(scheme
);
729 bool ProfileIOData::IsHandledURL(const GURL
& url
) {
730 if (!url
.is_valid()) {
731 // We handle error cases.
735 return IsHandledProtocol(url
.scheme());
739 void ProfileIOData::InstallProtocolHandlers(
740 net::URLRequestJobFactoryImpl
* job_factory
,
741 content::ProtocolHandlerMap
* protocol_handlers
) {
742 for (content::ProtocolHandlerMap::iterator it
=
743 protocol_handlers
->begin();
744 it
!= protocol_handlers
->end();
746 bool set_protocol
= job_factory
->SetProtocolHandler(
747 it
->first
, make_scoped_ptr(it
->second
.release()));
748 DCHECK(set_protocol
);
750 protocol_handlers
->clear();
754 void ProfileIOData::SetCertVerifierForTesting(
755 net::CertVerifier
* cert_verifier
) {
756 g_cert_verifier_for_testing
= cert_verifier
;
759 content::ResourceContext
* ProfileIOData::GetResourceContext() const {
760 return resource_context_
.get();
763 net::URLRequestContext
* ProfileIOData::GetMainRequestContext() const {
764 DCHECK(initialized_
);
765 return main_request_context_
.get();
768 net::URLRequestContext
* ProfileIOData::GetMediaRequestContext() const {
769 DCHECK(initialized_
);
770 net::URLRequestContext
* context
= AcquireMediaRequestContext();
775 net::URLRequestContext
* ProfileIOData::GetExtensionsRequestContext() const {
776 DCHECK(initialized_
);
777 return extensions_request_context_
.get();
780 net::URLRequestContext
* ProfileIOData::GetIsolatedAppRequestContext(
781 net::URLRequestContext
* main_context
,
782 const StoragePartitionDescriptor
& partition_descriptor
,
783 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
784 protocol_handler_interceptor
,
785 content::ProtocolHandlerMap
* protocol_handlers
,
786 content::URLRequestInterceptorScopedVector request_interceptors
) const {
787 DCHECK(initialized_
);
788 net::URLRequestContext
* context
= NULL
;
789 if (ContainsKey(app_request_context_map_
, partition_descriptor
)) {
790 context
= app_request_context_map_
[partition_descriptor
];
793 AcquireIsolatedAppRequestContext(main_context
,
794 partition_descriptor
,
795 protocol_handler_interceptor
.Pass(),
797 request_interceptors
.Pass());
798 app_request_context_map_
[partition_descriptor
] = context
;
804 net::URLRequestContext
* ProfileIOData::GetIsolatedMediaRequestContext(
805 net::URLRequestContext
* app_context
,
806 const StoragePartitionDescriptor
& partition_descriptor
) const {
807 DCHECK(initialized_
);
808 net::URLRequestContext
* context
= NULL
;
809 if (ContainsKey(isolated_media_request_context_map_
, partition_descriptor
)) {
810 context
= isolated_media_request_context_map_
[partition_descriptor
];
812 context
= AcquireIsolatedMediaRequestContext(app_context
,
813 partition_descriptor
);
814 isolated_media_request_context_map_
[partition_descriptor
] = context
;
820 extensions::InfoMap
* ProfileIOData::GetExtensionInfoMap() const {
821 DCHECK(initialized_
) << "ExtensionSystem not initialized";
822 #if defined(ENABLE_EXTENSIONS)
823 return extension_info_map_
.get();
829 extensions::ExtensionThrottleManager
*
830 ProfileIOData::GetExtensionThrottleManager() const {
831 DCHECK(initialized_
) << "ExtensionSystem not initialized";
832 #if defined(ENABLE_EXTENSIONS)
833 return extension_throttle_manager_
.get();
839 content_settings::CookieSettings
* ProfileIOData::GetCookieSettings() const {
840 // Allow either Init() or SetCookieSettingsForTesting() to initialize.
841 DCHECK(initialized_
|| cookie_settings_
.get());
842 return cookie_settings_
.get();
845 HostContentSettingsMap
* ProfileIOData::GetHostContentSettingsMap() const {
846 DCHECK(initialized_
);
847 return host_content_settings_map_
.get();
850 ResourceContext::SaltCallback
ProfileIOData::GetMediaDeviceIDSalt() const {
851 return base::Bind(&MediaDeviceIDSalt::GetSalt
, media_device_id_salt_
);
854 bool ProfileIOData::IsOffTheRecord() const {
855 return profile_type() == Profile::INCOGNITO_PROFILE
856 || profile_type() == Profile::GUEST_PROFILE
;
859 void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() {
860 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
861 #if defined(OS_CHROMEOS)
862 // Just fetch the value from ChromeOS' settings while we're on the UI thread.
863 // TODO(stevet): For now, this value is only set on profile initialization.
864 // We will want to do something similar to the PrefMember method below in the
865 // future to more accurately capture this state.
866 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref
,
868 #elif defined(OS_ANDROID)
869 // TODO(dwkang): rename or unify the pref for UMA once we have conclusion
870 // in crbugs.com/246495.
871 // Android has it's own preferences for metrics / crash uploading.
872 enable_metrics_
.Init(prefs::kCrashReportingEnabled
,
873 g_browser_process
->local_state());
874 enable_metrics_
.MoveToThread(
875 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
877 // Prep the PrefMember and send it to the IO thread, since this value will be
879 enable_metrics_
.Init(prefs::kMetricsReportingEnabled
,
880 g_browser_process
->local_state());
881 enable_metrics_
.MoveToThread(
882 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
883 #endif // defined(OS_CHROMEOS)
886 bool ProfileIOData::GetMetricsEnabledStateOnIOThread() const {
887 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
888 #if defined(OS_CHROMEOS)
889 return enable_metrics_
;
891 return enable_metrics_
.GetValue();
892 #endif // defined(OS_CHROMEOS)
895 bool ProfileIOData::IsDataReductionProxyEnabled() const {
896 return data_reduction_proxy_io_data() &&
897 data_reduction_proxy_io_data()->IsEnabled();
900 void ProfileIOData::set_data_reduction_proxy_io_data(
901 scoped_ptr
<data_reduction_proxy::DataReductionProxyIOData
>
902 data_reduction_proxy_io_data
) const {
903 data_reduction_proxy_io_data_
= data_reduction_proxy_io_data
.Pass();
906 base::WeakPtr
<net::HttpServerProperties
>
907 ProfileIOData::http_server_properties() const {
908 return http_server_properties_
->GetWeakPtr();
911 void ProfileIOData::set_http_server_properties(
912 scoped_ptr
<net::HttpServerProperties
> http_server_properties
) const {
913 http_server_properties_
= http_server_properties
.Pass();
916 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData
* io_data
)
918 host_resolver_(NULL
),
919 request_context_(NULL
) {
923 ProfileIOData::ResourceContext::~ResourceContext() {}
925 net::HostResolver
* ProfileIOData::ResourceContext::GetHostResolver() {
926 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
927 DCHECK(io_data_
->initialized_
);
928 return host_resolver_
;
931 net::URLRequestContext
* ProfileIOData::ResourceContext::GetRequestContext() {
932 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
933 DCHECK(io_data_
->initialized_
);
934 return request_context_
;
937 scoped_ptr
<net::ClientCertStore
>
938 ProfileIOData::ResourceContext::CreateClientCertStore() {
939 if (!io_data_
->client_cert_store_factory_
.is_null())
940 return io_data_
->client_cert_store_factory_
.Run();
941 #if defined(OS_CHROMEOS)
942 return scoped_ptr
<net::ClientCertStore
>(new chromeos::ClientCertStoreChromeOS(
943 nullptr, // no additional provider
944 make_scoped_ptr(new chromeos::ClientCertFilterChromeOS(
945 io_data_
->use_system_key_slot(), io_data_
->username_hash())),
946 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
947 chrome::kCryptoModulePasswordClientAuth
)));
948 #elif defined(USE_NSS_CERTS)
949 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreNSS(
950 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate
,
951 chrome::kCryptoModulePasswordClientAuth
)));
952 #elif defined(OS_WIN)
953 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreWin());
954 #elif defined(OS_MACOSX)
955 return scoped_ptr
<net::ClientCertStore
>(new net::ClientCertStoreMac());
956 #elif defined(OS_ANDROID)
957 // Android does not use the ClientCertStore infrastructure. On Android client
958 // cert matching is done by the OS as part of the call to show the cert
962 #error Unknown platform.
966 void ProfileIOData::ResourceContext::CreateKeygenHandler(
967 uint32 key_size_in_bits
,
968 const std::string
& challenge_string
,
970 const base::Callback
<void(scoped_ptr
<net::KeygenHandler
>)>& callback
) {
971 DCHECK(!callback
.is_null());
972 #if defined(USE_NSS_CERTS)
973 scoped_ptr
<net::KeygenHandler
> keygen_handler(
974 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
));
976 base::Callback
<void(scoped_ptr
<ChromeNSSCryptoModuleDelegate
>)>
977 got_delegate_callback
= base::Bind(&InitializeAndPassKeygenHandler
,
978 base::Passed(&keygen_handler
),
981 ChromeNSSCryptoModuleDelegate::CreateForResourceContext(
982 chrome::kCryptoModulePasswordKeygen
,
983 net::HostPortPair::FromURL(url
),
985 got_delegate_callback
);
987 callback
.Run(make_scoped_ptr(
988 new net::KeygenHandler(key_size_in_bits
, challenge_string
, url
)));
992 ResourceContext::SaltCallback
993 ProfileIOData::ResourceContext::GetMediaDeviceIDSalt() {
994 return io_data_
->GetMediaDeviceIDSalt();
998 std::string
ProfileIOData::GetSSLSessionCacheShard() {
999 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1000 // The SSL session cache is partitioned by setting a string. This returns a
1001 // unique string to partition the SSL session cache. Each time we create a
1002 // new profile, we'll get a fresh SSL session cache which is separate from
1003 // the other profiles.
1004 static unsigned ssl_session_cache_instance
= 0;
1005 return base::StringPrintf("profile/%u", ssl_session_cache_instance
++);
1008 void ProfileIOData::Init(
1009 content::ProtocolHandlerMap
* protocol_handlers
,
1010 content::URLRequestInterceptorScopedVector request_interceptors
) const {
1011 // The basic logic is implemented here. The specific initialization
1012 // is done in InitializeInternal(), implemented by subtypes. Static helper
1013 // functions have been provided to assist in common operations.
1014 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
1015 DCHECK(!initialized_
);
1017 // TODO(jhawkins): Remove once crbug.com/102004 is fixed.
1018 CHECK(initialized_on_UI_thread_
);
1020 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed.
1021 CHECK(profile_params_
.get());
1023 IOThread
* const io_thread
= profile_params_
->io_thread
;
1024 IOThread::Globals
* const io_thread_globals
= io_thread
->globals();
1025 const base::CommandLine
& command_line
=
1026 *base::CommandLine::ForCurrentProcess();
1028 // Create the common request contexts.
1029 main_request_context_
.reset(new net::URLRequestContext());
1030 extensions_request_context_
.reset(new net::URLRequestContext());
1032 scoped_ptr
<ChromeNetworkDelegate
> network_delegate(
1033 new ChromeNetworkDelegate(
1034 #if defined(ENABLE_EXTENSIONS)
1035 io_thread_globals
->extension_event_router_forwarder
.get(),
1039 &enable_referrers_
));
1040 #if defined(ENABLE_EXTENSIONS)
1041 network_delegate
->set_extension_info_map(
1042 profile_params_
->extension_info_map
.get());
1043 if (!command_line
.HasSwitch(switches::kDisableExtensionsHttpThrottling
)) {
1044 extension_throttle_manager_
.reset(
1045 new extensions::ExtensionThrottleManager());
1049 #if defined(ENABLE_CONFIGURATION_POLICY)
1050 network_delegate
->set_url_blacklist_manager(url_blacklist_manager_
.get());
1052 network_delegate
->set_profile(profile_params_
->profile
);
1053 network_delegate
->set_profile_path(profile_params_
->path
);
1054 network_delegate
->set_cookie_settings(profile_params_
->cookie_settings
.get());
1055 network_delegate
->set_enable_do_not_track(&enable_do_not_track_
);
1056 network_delegate
->set_force_google_safe_search(&force_google_safesearch_
);
1057 network_delegate
->set_force_youtube_safety_mode(&force_youtube_safety_mode_
);
1059 // NOTE: Proxy service uses the default io thread network delegate, not the
1060 // delegate just created.
1061 proxy_service_
.reset(
1062 ProxyServiceFactory::CreateProxyService(
1063 io_thread
->net_log(),
1064 io_thread_globals
->proxy_script_fetcher_context
.get(),
1065 io_thread_globals
->system_network_delegate
.get(),
1066 profile_params_
->proxy_config_service
.release(),
1068 quick_check_enabled_
.GetValue()));
1069 transport_security_state_
.reset(new net::TransportSecurityState());
1070 base::SequencedWorkerPool
* pool
= BrowserThread::GetBlockingPool();
1071 transport_security_persister_
.reset(
1072 new net::TransportSecurityPersister(
1073 transport_security_state_
.get(),
1074 profile_params_
->path
,
1075 pool
->GetSequencedTaskRunnerWithShutdownBehavior(
1076 pool
->GetSequenceToken(),
1077 base::SequencedWorkerPool::BLOCK_SHUTDOWN
),
1080 certificate_report_sender_
.reset(new net::CertificateReportSender(
1081 main_request_context_
.get(),
1082 net::CertificateReportSender::DO_NOT_SEND_COOKIES
));
1083 transport_security_state_
->SetReportSender(certificate_report_sender_
.get());
1085 // Take ownership over these parameters.
1086 cookie_settings_
= profile_params_
->cookie_settings
;
1087 host_content_settings_map_
= profile_params_
->host_content_settings_map
;
1088 #if defined(ENABLE_EXTENSIONS)
1089 extension_info_map_
= profile_params_
->extension_info_map
;
1092 resource_context_
->host_resolver_
= io_thread_globals
->host_resolver
.get();
1093 resource_context_
->request_context_
= main_request_context_
.get();
1095 if (profile_params_
->resource_prefetch_predictor_observer_
) {
1096 resource_prefetch_predictor_observer_
.reset(
1097 profile_params_
->resource_prefetch_predictor_observer_
.release());
1100 #if defined(ENABLE_SUPERVISED_USERS)
1101 supervised_user_url_filter_
= profile_params_
->supervised_user_url_filter
;
1104 #if defined(OS_CHROMEOS)
1105 username_hash_
= profile_params_
->username_hash
;
1106 use_system_key_slot_
= profile_params_
->use_system_key_slot
;
1107 if (use_system_key_slot_
)
1108 EnableNSSSystemKeySlotForResourceContext(resource_context_
.get());
1111 if (g_cert_verifier_for_testing
) {
1112 main_request_context_
->set_cert_verifier(g_cert_verifier_for_testing
);
1114 #if defined(OS_CHROMEOS)
1115 crypto::ScopedPK11Slot public_slot
=
1116 crypto::GetPublicSlotForChromeOSUser(username_hash_
);
1117 // The private slot won't be ready by this point. It shouldn't be necessary
1118 // for cert trust purposes anyway.
1119 scoped_refptr
<net::CertVerifyProc
> verify_proc(
1120 new chromeos::CertVerifyProcChromeOS(public_slot
.Pass()));
1121 if (policy_cert_verifier_
) {
1122 DCHECK_EQ(policy_cert_verifier_
, cert_verifier_
.get());
1123 policy_cert_verifier_
->InitializeOnIOThread(verify_proc
);
1125 cert_verifier_
.reset(
1126 new net::MultiThreadedCertVerifier(verify_proc
.get()));
1128 main_request_context_
->set_cert_verifier(cert_verifier_
.get());
1130 main_request_context_
->set_cert_verifier(
1131 io_thread_globals
->cert_verifier
.get());
1135 // Install the New Tab Page Interceptor.
1136 if (profile_params_
->new_tab_page_interceptor
.get()) {
1137 request_interceptors
.push_back(
1138 profile_params_
->new_tab_page_interceptor
.release());
1142 network_delegate
.Pass(), profile_params_
.get(),
1143 protocol_handlers
, request_interceptors
.Pass());
1145 profile_params_
.reset();
1146 initialized_
= true;
1149 void ProfileIOData::ApplyProfileParamsToContext(
1150 net::URLRequestContext
* context
) const {
1151 context
->set_http_user_agent_settings(
1152 chrome_http_user_agent_settings_
.get());
1153 context
->set_ssl_config_service(profile_params_
->ssl_config_service
.get());
1156 scoped_ptr
<net::URLRequestJobFactory
> ProfileIOData::SetUpJobFactoryDefaults(
1157 scoped_ptr
<net::URLRequestJobFactoryImpl
> job_factory
,
1158 content::URLRequestInterceptorScopedVector request_interceptors
,
1159 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
1160 protocol_handler_interceptor
,
1161 net::NetworkDelegate
* network_delegate
,
1162 net::FtpTransactionFactory
* ftp_transaction_factory
) const {
1163 // NOTE(willchan): Keep these protocol handlers in sync with
1164 // ProfileIOData::IsHandledProtocol().
1165 bool set_protocol
= job_factory
->SetProtocolHandler(
1167 make_scoped_ptr(new net::FileProtocolHandler(
1168 content::BrowserThread::GetBlockingPool()
1169 ->GetTaskRunnerWithShutdownBehavior(
1170 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
))));
1171 DCHECK(set_protocol
);
1173 #if defined(ENABLE_EXTENSIONS)
1174 DCHECK(extension_info_map_
.get());
1175 // Check only for incognito (and not Chrome OS guest mode GUEST_PROFILE).
1176 bool is_incognito
= profile_type() == Profile::INCOGNITO_PROFILE
;
1177 set_protocol
= job_factory
->SetProtocolHandler(
1178 extensions::kExtensionScheme
,
1179 extensions::CreateExtensionProtocolHandler(is_incognito
,
1180 extension_info_map_
.get()));
1181 DCHECK(set_protocol
);
1182 set_protocol
= job_factory
->SetProtocolHandler(
1183 extensions::kExtensionResourceScheme
,
1184 CreateExtensionResourceProtocolHandler());
1185 DCHECK(set_protocol
);
1187 set_protocol
= job_factory
->SetProtocolHandler(
1188 url::kDataScheme
, make_scoped_ptr(new net::DataProtocolHandler()));
1189 DCHECK(set_protocol
);
1190 #if defined(OS_CHROMEOS)
1191 if (profile_params_
) {
1192 set_protocol
= job_factory
->SetProtocolHandler(
1193 content::kExternalFileScheme
,
1194 make_scoped_ptr(new chromeos::ExternalFileProtocolHandler(
1195 profile_params_
->profile
)));
1196 DCHECK(set_protocol
);
1198 #endif // defined(OS_CHROMEOS)
1199 #if defined(OS_ANDROID)
1200 set_protocol
= job_factory
->SetProtocolHandler(
1201 url::kContentScheme
,
1202 content::ContentProtocolHandler::Create(
1203 content::BrowserThread::GetBlockingPool()
1204 ->GetTaskRunnerWithShutdownBehavior(
1205 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN
)));
1208 job_factory
->SetProtocolHandler(
1210 make_scoped_ptr(new about_handler::AboutProtocolHandler()));
1211 #if !defined(DISABLE_FTP_SUPPORT)
1212 DCHECK(ftp_transaction_factory
);
1213 job_factory
->SetProtocolHandler(
1215 make_scoped_ptr(new net::FtpProtocolHandler(ftp_transaction_factory
)));
1216 #endif // !defined(DISABLE_FTP_SUPPORT)
1218 #if defined(DEBUG_DEVTOOLS)
1219 request_interceptors
.push_back(new DebugDevToolsInterceptor
);
1222 // Set up interceptors in the reverse order.
1223 scoped_ptr
<net::URLRequestJobFactory
> top_job_factory
= job_factory
.Pass();
1224 for (content::URLRequestInterceptorScopedVector::reverse_iterator i
=
1225 request_interceptors
.rbegin();
1226 i
!= request_interceptors
.rend();
1228 top_job_factory
.reset(new net::URLRequestInterceptingJobFactory(
1229 top_job_factory
.Pass(), make_scoped_ptr(*i
)));
1231 request_interceptors
.weak_clear();
1233 if (protocol_handler_interceptor
) {
1234 protocol_handler_interceptor
->Chain(top_job_factory
.Pass());
1235 return protocol_handler_interceptor
.Pass();
1237 return top_job_factory
.Pass();
1241 void ProfileIOData::ShutdownOnUIThread(
1242 scoped_ptr
<ChromeURLRequestContextGetterVector
> context_getters
) {
1243 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1245 google_services_user_account_id_
.Destroy();
1246 enable_referrers_
.Destroy();
1247 enable_do_not_track_
.Destroy();
1248 force_google_safesearch_
.Destroy();
1249 force_youtube_safety_mode_
.Destroy();
1250 #if !defined(OS_CHROMEOS)
1251 enable_metrics_
.Destroy();
1253 safe_browsing_enabled_
.Destroy();
1254 sync_disabled_
.Destroy();
1255 signin_allowed_
.Destroy();
1256 network_prediction_options_
.Destroy();
1257 quick_check_enabled_
.Destroy();
1258 if (media_device_id_salt_
.get())
1259 media_device_id_salt_
->ShutdownOnUIThread();
1260 session_startup_pref_
.Destroy();
1261 #if defined(ENABLE_CONFIGURATION_POLICY)
1262 if (url_blacklist_manager_
)
1263 url_blacklist_manager_
->ShutdownOnUIThread();
1265 if (chrome_http_user_agent_settings_
)
1266 chrome_http_user_agent_settings_
->CleanupOnUIThread();
1267 incognito_availibility_pref_
.Destroy();
1269 if (!context_getters
->empty()) {
1270 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO
)) {
1271 BrowserThread::PostTask(
1272 BrowserThread::IO
, FROM_HERE
,
1273 base::Bind(&NotifyContextGettersOfShutdownOnIO
,
1274 base::Passed(&context_getters
)));
1278 bool posted
= BrowserThread::DeleteSoon(BrowserThread::IO
, FROM_HERE
, this);
1283 void ProfileIOData::set_channel_id_service(
1284 net::ChannelIDService
* channel_id_service
) const {
1285 channel_id_service_
.reset(channel_id_service
);
1288 void ProfileIOData::DestroyResourceContext() {
1289 resource_context_
.reset();
1292 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateMainHttpFactory(
1293 const ProfileParams
* profile_params
,
1294 net::HttpCache::BackendFactory
* main_backend
) const {
1295 net::HttpNetworkSession::Params params
;
1296 net::URLRequestContext
* context
= main_request_context();
1298 IOThread
* const io_thread
= profile_params
->io_thread
;
1300 io_thread
->InitializeNetworkSessionParams(¶ms
);
1301 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(context
,
1304 params
.ssl_session_cache_shard
= GetSSLSessionCacheShard();
1305 params
.socket_performance_watcher_factory
=
1306 io_thread
->globals()->network_quality_estimator
.get();
1307 if (data_reduction_proxy_io_data_
.get())
1308 params
.proxy_delegate
= data_reduction_proxy_io_data_
->proxy_delegate();
1310 net::HttpNetworkSession
* session
= new net::HttpNetworkSession(params
);
1311 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1312 new DevToolsNetworkTransactionFactory(
1313 network_controller_handle_
.GetController(), session
),
1314 context
->net_log(), main_backend
));
1317 scoped_ptr
<net::HttpCache
> ProfileIOData::CreateHttpFactory(
1318 net::HttpNetworkSession
* shared_session
,
1319 net::HttpCache::BackendFactory
* backend
) const {
1320 return scoped_ptr
<net::HttpCache
>(new net::HttpCache(
1321 new DevToolsNetworkTransactionFactory(
1322 network_controller_handle_
.GetController(), shared_session
),
1323 shared_session
->net_log(), backend
));
1326 void ProfileIOData::SetCookieSettingsForTesting(
1327 content_settings::CookieSettings
* cookie_settings
) {
1328 DCHECK(!cookie_settings_
.get());
1329 cookie_settings_
= cookie_settings
;