profile_io_data.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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.
4
5#include "chrome/browser/profiles/profile_io_data.h"
6
7#include <string>
8
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/threading/sequenced_worker_pool.h"
24#include "chrome/browser/browser_process.h"
25#include "chrome/browser/chrome_notification_types.h"
26#include "chrome/browser/content_settings/content_settings_provider.h"
27#include "chrome/browser/content_settings/cookie_settings.h"
28#include "chrome/browser/content_settings/host_content_settings_map.h"
29#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
30#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
31#include "chrome/browser/download/download_service.h"
32#include "chrome/browser/download/download_service_factory.h"
33#include "chrome/browser/extensions/extension_protocols.h"
34#include "chrome/browser/extensions/extension_resource_protocols.h"
35#include "chrome/browser/extensions/extension_system.h"
36#include "chrome/browser/io_thread.h"
37#include "chrome/browser/media/media_device_id_salt.h"
38#include "chrome/browser/net/about_protocol_handler.h"
39#include "chrome/browser/net/chrome_cookie_notification_details.h"
40#include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h"
41#include "chrome/browser/net/chrome_http_user_agent_settings.h"
42#include "chrome/browser/net/chrome_net_log.h"
43#include "chrome/browser/net/chrome_network_delegate.h"
44#include "chrome/browser/net/evicted_domain_cookie_counter.h"
45#include "chrome/browser/net/load_time_stats.h"
46#include "chrome/browser/net/proxy_service_factory.h"
47#include "chrome/browser/net/resource_prefetch_predictor_observer.h"
48#include "chrome/browser/policy/url_blacklist_manager.h"
49#include "chrome/browser/predictors/resource_prefetch_predictor.h"
50#include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
51#include "chrome/browser/profiles/profile.h"
52#include "chrome/browser/profiles/profile_manager.h"
53#include "chrome/browser/signin/signin_names_io_thread.h"
54#include "chrome/common/chrome_paths.h"
55#include "chrome/common/chrome_switches.h"
56#include "chrome/common/pref_names.h"
57#include "chrome/common/url_constants.h"
58#include "components/startup_metric_utils/startup_metric_utils.h"
59#include "content/public/browser/browser_thread.h"
60#include "content/public/browser/host_zoom_map.h"
61#include "content/public/browser/notification_service.h"
62#include "content/public/browser/resource_context.h"
63#include "extensions/browser/info_map.h"
64#include "extensions/common/constants.h"
65#include "net/cookies/canonical_cookie.h"
66#include "net/cookies/cookie_monster.h"
67#include "net/http/http_transaction_factory.h"
68#include "net/http/http_util.h"
69#include "net/http/transport_security_persister.h"
70#include "net/proxy/proxy_config_service_fixed.h"
71#include "net/proxy/proxy_script_fetcher_impl.h"
72#include "net/proxy/proxy_service.h"
73#include "net/ssl/client_cert_store.h"
74#include "net/ssl/server_bound_cert_service.h"
75#include "net/url_request/data_protocol_handler.h"
76#include "net/url_request/file_protocol_handler.h"
77#include "net/url_request/ftp_protocol_handler.h"
78#include "net/url_request/protocol_intercept_job_factory.h"
79#include "net/url_request/url_request.h"
80#include "net/url_request/url_request_file_job.h"
81#include "net/url_request/url_request_job_factory_impl.h"
82
83#if defined(ENABLE_CONFIGURATION_POLICY)
84#include "chrome/browser/policy/cloud/policy_header_service.h"
85#include "chrome/browser/policy/cloud/policy_header_service_factory.h"
86#include "chrome/browser/policy/cloud/user_cloud_policy_manager.h"
87#include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
88#include "components/policy/core/browser/policy_header_io_helper.h"
89#endif
90
91#if defined(ENABLE_MANAGED_USERS)
92#include "chrome/browser/managed_mode/managed_mode_url_filter.h"
93#include "chrome/browser/managed_mode/managed_user_service.h"
94#include "chrome/browser/managed_mode/managed_user_service_factory.h"
95#endif
96
97#if defined(OS_CHROMEOS)
98#include "chrome/browser/chromeos/drive/drive_protocol_handler.h"
99#include "chrome/browser/chromeos/login/user.h"
100#include "chrome/browser/chromeos/login/user_manager.h"
101#include "chrome/browser/chromeos/policy/policy_cert_service.h"
102#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
103#include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
104#include "chrome/browser/chromeos/settings/cros_settings.h"
105#include "chromeos/dbus/cryptohome_client.h"
106#include "chromeos/dbus/dbus_thread_manager.h"
107#include "chromeos/settings/cros_settings_names.h"
108#include "crypto/nss_util.h"
109#include "crypto/nss_util_internal.h"
110#endif  // defined(OS_CHROMEOS)
111
112#if defined(USE_NSS)
113#include "chrome/browser/ui/crypto_module_password_dialog.h"
114#include "net/ssl/client_cert_store_nss.h"
115#endif
116
117#if defined(OS_WIN)
118#include "net/ssl/client_cert_store_win.h"
119#endif
120
121#if defined(OS_MACOSX)
122#include "net/ssl/client_cert_store_mac.h"
123#endif
124
125using content::BrowserContext;
126using content::BrowserThread;
127using content::ResourceContext;
128
129namespace {
130
131// ----------------------------------------------------------------------------
132// CookieMonster::Delegate implementation
133// ----------------------------------------------------------------------------
134class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate {
135 public:
136  explicit ChromeCookieMonsterDelegate(
137      const base::Callback<Profile*(void)>& profile_getter)
138      : profile_getter_(profile_getter) {
139    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
140  }
141
142  // net::CookieMonster::Delegate implementation.
143  virtual void OnCookieChanged(
144      const net::CanonicalCookie& cookie,
145      bool removed,
146      net::CookieMonster::Delegate::ChangeCause cause) OVERRIDE {
147    BrowserThread::PostTask(
148        BrowserThread::UI, FROM_HERE,
149        base::Bind(&ChromeCookieMonsterDelegate::OnCookieChangedAsyncHelper,
150                   this, cookie, removed, cause));
151  }
152
153 private:
154  virtual ~ChromeCookieMonsterDelegate() {}
155
156  void OnCookieChangedAsyncHelper(
157      const net::CanonicalCookie& cookie,
158      bool removed,
159      net::CookieMonster::Delegate::ChangeCause cause) {
160    Profile* profile = profile_getter_.Run();
161    if (profile) {
162      ChromeCookieDetails cookie_details(&cookie, removed, cause);
163      content::NotificationService::current()->Notify(
164          chrome::NOTIFICATION_COOKIE_CHANGED,
165          content::Source<Profile>(profile),
166          content::Details<ChromeCookieDetails>(&cookie_details));
167    }
168  }
169
170  const base::Callback<Profile*(void)> profile_getter_;
171};
172
173Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) {
174  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
175  DCHECK(profile);
176  if (profile_manager->IsValidProfile(profile))
177    return profile;
178  return NULL;
179}
180
181#if defined(DEBUG_DEVTOOLS)
182bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) {
183  std::string bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath);
184  bundled_path_prefix = "/" + bundled_path_prefix + "/";
185
186  if (!url.SchemeIs(chrome::kChromeDevToolsScheme) ||
187      url.host() != chrome::kChromeUIDevToolsHost ||
188      !StartsWithASCII(url.path(), bundled_path_prefix, false)) {
189    return false;
190  }
191
192  if (!url.is_valid()) {
193    NOTREACHED();
194    return false;
195  }
196
197  // Remove Query and Ref from URL.
198  GURL stripped_url;
199  GURL::Replacements replacements;
200  replacements.ClearQuery();
201  replacements.ClearRef();
202  stripped_url = url.ReplaceComponents(replacements);
203
204  std::string relative_path;
205  const std::string& spec = stripped_url.possibly_invalid_spec();
206  const url_parse::Parsed& parsed =
207      stripped_url.parsed_for_possibly_invalid_spec();
208  int offset = parsed.CountCharactersBefore(url_parse::Parsed::PATH, false);
209  if (offset < static_cast<int>(spec.size()))
210    relative_path.assign(spec.substr(offset + bundled_path_prefix.length()));
211
212  // Check that |relative_path| is not an absolute path (otherwise
213  // AppendASCII() will DCHECK).  The awkward use of StringType is because on
214  // some systems FilePath expects a std::string, but on others a std::wstring.
215  base::FilePath p(
216      base::FilePath::StringType(relative_path.begin(), relative_path.end()));
217  if (p.IsAbsolute())
218    return false;
219
220  base::FilePath inspector_dir;
221  if (!PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir))
222    return false;
223
224  if (inspector_dir.empty())
225    return false;
226
227  *path = inspector_dir.AppendASCII(relative_path);
228  return true;
229}
230
231class DebugDevToolsInterceptor
232    : public net::URLRequestJobFactory::ProtocolHandler {
233 public:
234  DebugDevToolsInterceptor() {}
235  virtual ~DebugDevToolsInterceptor() {}
236
237  virtual net::URLRequestJob* MaybeCreateJob(
238      net::URLRequest* request,
239      net::NetworkDelegate* network_delegate) const OVERRIDE {
240    base::FilePath path;
241    if (IsSupportedDevToolsURL(request->url(), &path))
242      return new net::URLRequestFileJob(
243          request, network_delegate, path,
244          content::BrowserThread::GetBlockingPool()->
245              GetTaskRunnerWithShutdownBehavior(
246                  base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
247
248    return NULL;
249  }
250};
251#endif  // defined(DEBUG_DEVTOOLS)
252
253#if defined(OS_CHROMEOS)
254// The following four functions are responsible for initializing NSS for each
255// profile on ChromeOS, which has a separate NSS database and TPM slot
256// per-profile.
257//
258// Initialization basically follows these steps:
259// 1) Get some info from chromeos::UserManager about the User for this profile.
260// 2) Tell nss_util to initialize the software slot for this profile.
261// 3) Wait for the TPM module to be loaded by nss_util if it isn't already.
262// 4) Ask CryptohomeClient which TPM slot id corresponds to this profile.
263// 5) Tell nss_util to use that slot id on the TPM module.
264//
265// Some of these steps must happen on the UI thread, others must happen on the
266// IO thread:
267//               UI thread                              IO Thread
268//
269//  ProfileIOData::InitializeOnUIThread
270//                   |
271// chromeos::UserManager::GetUserByProfile
272//                   \---------------------------------------v
273//                                                 StartNSSInitOnIOThread
274//                                                           |
275//                                          crypto::InitializeNSSForChromeOSUser
276//                                                           |
277//                                                crypto::IsTPMTokenReady
278//                                                           |
279//                                          StartTPMSlotInitializationOnIOThread
280//                   v---------------------------------------/
281//     GetTPMInfoForUserOnUIThread
282//                   |
283// CryptohomeClient::Pkcs11GetTpmTokenInfoForUser
284//                   |
285//     DidGetTPMInfoForUserOnUIThread
286//                   \---------------------------------------v
287//                                          crypto::InitializeTPMForChromeOSUser
288
289void DidGetTPMInfoForUserOnUIThread(const std::string& username_hash,
290                                    chromeos::DBusMethodCallStatus call_status,
291                                    const std::string& label,
292                                    const std::string& user_pin,
293                                    int slot_id) {
294  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
295  if (call_status == chromeos::DBUS_METHOD_CALL_FAILURE) {
296    NOTREACHED() << "dbus error getting TPM info for " << username_hash;
297    return;
298  }
299  DVLOG(1) << "Got TPM slot for " << username_hash << ": " << slot_id;
300  BrowserThread::PostTask(
301      BrowserThread::IO,
302      FROM_HERE,
303      base::Bind(
304          &crypto::InitializeTPMForChromeOSUser, username_hash, slot_id));
305}
306
307void GetTPMInfoForUserOnUIThread(const std::string& username,
308                                 const std::string& username_hash) {
309  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
310  DVLOG(1) << "Getting TPM info from cryptohome for "
311           << " " << username << " " << username_hash;
312  chromeos::DBusThreadManager::Get()
313      ->GetCryptohomeClient()
314      ->Pkcs11GetTpmTokenInfoForUser(
315            username,
316            base::Bind(&DidGetTPMInfoForUserOnUIThread, username_hash));
317}
318
319void StartTPMSlotInitializationOnIOThread(const std::string& username,
320                                          const std::string& username_hash) {
321  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
322
323  BrowserThread::PostTask(
324      BrowserThread::UI,
325      FROM_HERE,
326      base::Bind(&GetTPMInfoForUserOnUIThread, username, username_hash));
327}
328
329void StartNSSInitOnIOThread(const std::string& username,
330                            const std::string& username_hash,
331                            const base::FilePath& path,
332                            bool is_primary_user) {
333  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
334  DVLOG(1) << "Starting NSS init for " << username
335           << "  hash:" << username_hash
336           << "  is_primary_user:" << is_primary_user;
337
338  if (!crypto::InitializeNSSForChromeOSUser(
339           username, username_hash, is_primary_user, path)) {
340    // If the user already exists in nss_util's map, it is already initialized
341    // or in the process of being initialized. In either case, there's no need
342    // to do anything.
343    return;
344  }
345
346  if (crypto::IsTPMTokenEnabledForNSS()) {
347    if (crypto::IsTPMTokenReady(base::Bind(
348            &StartTPMSlotInitializationOnIOThread, username, username_hash))) {
349      StartTPMSlotInitializationOnIOThread(username, username_hash);
350    } else {
351      DVLOG(1) << "Waiting for tpm ready ...";
352    }
353  } else {
354    crypto::InitializePrivateSoftwareSlotForChromeOSUser(username_hash);
355  }
356}
357#endif  // defined(OS_CHROMEOS)
358
359}  // namespace
360
361void ProfileIOData::InitializeOnUIThread(Profile* profile) {
362  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
363  PrefService* pref_service = profile->GetPrefs();
364  PrefService* local_state_pref_service = g_browser_process->local_state();
365
366  scoped_ptr<ProfileParams> params(new ProfileParams);
367  params->path = profile->GetPath();
368
369  params->io_thread = g_browser_process->io_thread();
370
371  params->cookie_settings = CookieSettings::Factory::GetForProfile(profile);
372  params->host_content_settings_map = profile->GetHostContentSettingsMap();
373  params->ssl_config_service = profile->GetSSLConfigService();
374  base::Callback<Profile*(void)> profile_getter =
375      base::Bind(&GetProfileOnUI, g_browser_process->profile_manager(),
376                 profile);
377  params->cookie_monster_delegate =
378      new chrome_browser_net::EvictedDomainCookieCounter(
379          new ChromeCookieMonsterDelegate(profile_getter));
380  params->extension_info_map =
381      extensions::ExtensionSystem::Get(profile)->info_map();
382
383  if (predictors::ResourcePrefetchPredictor* predictor =
384          predictors::ResourcePrefetchPredictorFactory::GetForProfile(
385              profile)) {
386    resource_prefetch_predictor_observer_.reset(
387        new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor));
388  }
389
390  ProtocolHandlerRegistry* protocol_handler_registry =
391      ProtocolHandlerRegistryFactory::GetForProfile(profile);
392  DCHECK(protocol_handler_registry);
393
394  // The profile instance is only available here in the InitializeOnUIThread
395  // method, so we create the url job factory here, then save it for
396  // later delivery to the job factory in Init().
397  params->protocol_handler_interceptor =
398      protocol_handler_registry->CreateJobInterceptorFactory();
399
400  params->proxy_config_service
401      .reset(ProxyServiceFactory::CreateProxyConfigService(
402           profile->GetProxyConfigTracker()));
403#if defined(ENABLE_MANAGED_USERS)
404  ManagedUserService* managed_user_service =
405      ManagedUserServiceFactory::GetForProfile(profile);
406  params->managed_mode_url_filter =
407      managed_user_service->GetURLFilterForIOThread();
408#endif
409#if defined(OS_CHROMEOS)
410  chromeos::UserManager* user_manager = chromeos::UserManager::Get();
411  if (user_manager) {
412    chromeos::User* user = user_manager->GetUserByProfile(profile);
413    if (user) {
414      params->username_hash = user->username_hash();
415      bool is_primary_user = (user_manager->GetPrimaryUser() == user);
416      BrowserThread::PostTask(BrowserThread::IO,
417                              FROM_HERE,
418                              base::Bind(&StartNSSInitOnIOThread,
419                                         user->email(),
420                                         user->username_hash(),
421                                         profile->GetPath(),
422                                         is_primary_user));
423    }
424  }
425  if (params->username_hash.empty())
426    LOG(WARNING) << "no username_hash";
427#endif
428
429  params->profile = profile;
430  profile_params_.reset(params.release());
431
432  ChromeNetworkDelegate::InitializePrefsOnUIThread(
433      &enable_referrers_,
434      &enable_do_not_track_,
435      &force_safesearch_,
436      pref_service);
437
438  scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy =
439      BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
440#if defined(ENABLE_PRINTING)
441  printing_enabled_.Init(prefs::kPrintingEnabled, pref_service);
442  printing_enabled_.MoveToThread(io_message_loop_proxy);
443#endif
444
445  chrome_http_user_agent_settings_.reset(
446      new ChromeHttpUserAgentSettings(pref_service));
447
448  // These members are used only for one click sign in, which is not enabled
449  // in incognito mode.  So no need to initialize them.
450  if (!is_incognito()) {
451    signin_names_.reset(new SigninNamesOnIOThread());
452
453    google_services_user_account_id_.Init(
454        prefs::kGoogleServicesUserAccountId, pref_service);
455    google_services_user_account_id_.MoveToThread(io_message_loop_proxy);
456
457    google_services_username_.Init(
458        prefs::kGoogleServicesUsername, pref_service);
459    google_services_username_.MoveToThread(io_message_loop_proxy);
460
461    google_services_username_pattern_.Init(
462        prefs::kGoogleServicesUsernamePattern, local_state_pref_service);
463    google_services_username_pattern_.MoveToThread(io_message_loop_proxy);
464
465    reverse_autologin_enabled_.Init(
466        prefs::kReverseAutologinEnabled, pref_service);
467    reverse_autologin_enabled_.MoveToThread(io_message_loop_proxy);
468
469    one_click_signin_rejected_email_list_.Init(
470        prefs::kReverseAutologinRejectedEmailList, pref_service);
471    one_click_signin_rejected_email_list_.MoveToThread(io_message_loop_proxy);
472
473    sync_disabled_.Init(prefs::kSyncManaged, pref_service);
474    sync_disabled_.MoveToThread(io_message_loop_proxy);
475
476    signin_allowed_.Init(prefs::kSigninAllowed, pref_service);
477    signin_allowed_.MoveToThread(io_message_loop_proxy);
478  }
479
480  media_device_id_salt_.reset(new MediaDeviceIDSalt(pref_service,
481                                                    is_incognito()));
482
483#if defined(OS_CHROMEOS)
484  cert_verifier_ = policy::PolicyCertServiceFactory::CreateForProfile(profile);
485#endif
486  // The URLBlacklistManager has to be created on the UI thread to register
487  // observers of |pref_service|, and it also has to clean up on
488  // ShutdownOnUIThread to release these observers on the right thread.
489  // Don't pass it in |profile_params_| to make sure it is correctly cleaned up,
490  // in particular when this ProfileIOData isn't |initialized_| during deletion.
491#if defined(ENABLE_CONFIGURATION_POLICY)
492  url_blacklist_manager_.reset(new policy::URLBlacklistManager(pref_service));
493
494  if (!is_incognito()) {
495    // Add policy headers for non-incognito requests.
496    policy::PolicyHeaderService* policy_header_service =
497        policy::PolicyHeaderServiceFactory::GetForBrowserContext(profile);
498    if (policy_header_service) {
499      policy_header_helper_ = policy_header_service->CreatePolicyHeaderIOHelper(
500          io_message_loop_proxy);
501    }
502  }
503#endif
504
505  initialized_on_UI_thread_ = true;
506
507  // We need to make sure that content initializes its own data structures that
508  // are associated with each ResourceContext because we might post this
509  // object to the IO thread after this function.
510  BrowserContext::EnsureResourceContextInitialized(profile);
511}
512
513ProfileIOData::MediaRequestContext::MediaRequestContext(
514    chrome_browser_net::LoadTimeStats* load_time_stats)
515    : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_MEDIA,
516                              load_time_stats) {
517}
518
519void ProfileIOData::MediaRequestContext::SetHttpTransactionFactory(
520    scoped_ptr<net::HttpTransactionFactory> http_factory) {
521  http_factory_ = http_factory.Pass();
522  set_http_transaction_factory(http_factory_.get());
523}
524
525ProfileIOData::MediaRequestContext::~MediaRequestContext() {}
526
527ProfileIOData::AppRequestContext::AppRequestContext(
528    chrome_browser_net::LoadTimeStats* load_time_stats)
529    : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_APP,
530                              load_time_stats) {
531}
532
533void ProfileIOData::AppRequestContext::SetCookieStore(
534    net::CookieStore* cookie_store) {
535  cookie_store_ = cookie_store;
536  set_cookie_store(cookie_store);
537}
538
539void ProfileIOData::AppRequestContext::SetHttpTransactionFactory(
540    scoped_ptr<net::HttpTransactionFactory> http_factory) {
541  http_factory_ = http_factory.Pass();
542  set_http_transaction_factory(http_factory_.get());
543}
544
545void ProfileIOData::AppRequestContext::SetJobFactory(
546    scoped_ptr<net::URLRequestJobFactory> job_factory) {
547  job_factory_ = job_factory.Pass();
548  set_job_factory(job_factory_.get());
549}
550
551ProfileIOData::AppRequestContext::~AppRequestContext() {}
552
553ProfileIOData::ProfileParams::ProfileParams()
554    : io_thread(NULL),
555      profile(NULL) {
556}
557
558ProfileIOData::ProfileParams::~ProfileParams() {}
559
560ProfileIOData::ProfileIOData(bool is_incognito)
561    : initialized_(false),
562      resource_context_(new ResourceContext(this)),
563      load_time_stats_(NULL),
564      initialized_on_UI_thread_(false),
565      is_incognito_(is_incognito) {
566  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
567}
568
569ProfileIOData::~ProfileIOData() {
570  if (BrowserThread::IsMessageLoopValid(BrowserThread::IO))
571    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
572
573  // Pull the contents of the request context maps onto the stack for sanity
574  // checking of values in a minidump. http://crbug.com/260425
575  size_t num_app_contexts = app_request_context_map_.size();
576  size_t num_media_contexts = isolated_media_request_context_map_.size();
577  size_t current_context = 0;
578  static const size_t kMaxCachedContexts = 20;
579  ChromeURLRequestContext* app_context_cache[kMaxCachedContexts] = {0};
580  void* app_context_vtable_cache[kMaxCachedContexts] = {0};
581  ChromeURLRequestContext* media_context_cache[kMaxCachedContexts] = {0};
582  void* media_context_vtable_cache[kMaxCachedContexts] = {0};
583  void* tmp_vtable = NULL;
584  base::debug::Alias(&num_app_contexts);
585  base::debug::Alias(&num_media_contexts);
586  base::debug::Alias(&current_context);
587  base::debug::Alias(app_context_cache);
588  base::debug::Alias(app_context_vtable_cache);
589  base::debug::Alias(media_context_cache);
590  base::debug::Alias(media_context_vtable_cache);
591  base::debug::Alias(&tmp_vtable);
592
593  current_context = 0;
594  for (URLRequestContextMap::const_iterator it =
595           app_request_context_map_.begin();
596       current_context < kMaxCachedContexts &&
597           it != app_request_context_map_.end();
598       ++it, ++current_context) {
599    app_context_cache[current_context] = it->second;
600    memcpy(&app_context_vtable_cache[current_context],
601           static_cast<void*>(it->second), sizeof(void*));
602  }
603
604  current_context = 0;
605  for (URLRequestContextMap::const_iterator it =
606           isolated_media_request_context_map_.begin();
607       current_context < kMaxCachedContexts &&
608           it != isolated_media_request_context_map_.end();
609       ++it, ++current_context) {
610    media_context_cache[current_context] = it->second;
611    memcpy(&media_context_vtable_cache[current_context],
612           static_cast<void*>(it->second), sizeof(void*));
613  }
614
615  // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they
616  // are already done in the URLRequestContext destructor.
617  if (main_request_context_)
618    main_request_context_->AssertNoURLRequests();
619  if (extensions_request_context_)
620    extensions_request_context_->AssertNoURLRequests();
621
622  current_context = 0;
623  for (URLRequestContextMap::iterator it = app_request_context_map_.begin();
624       it != app_request_context_map_.end(); ++it) {
625    if (current_context < kMaxCachedContexts) {
626      CHECK_EQ(app_context_cache[current_context], it->second);
627      memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*));
628      CHECK_EQ(app_context_vtable_cache[current_context], tmp_vtable);
629    }
630    it->second->AssertNoURLRequests();
631    delete it->second;
632    current_context++;
633  }
634
635  current_context = 0;
636  for (URLRequestContextMap::iterator it =
637           isolated_media_request_context_map_.begin();
638       it != isolated_media_request_context_map_.end(); ++it) {
639    if (current_context < kMaxCachedContexts) {
640      CHECK_EQ(media_context_cache[current_context], it->second);
641      memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*));
642      CHECK_EQ(media_context_vtable_cache[current_context], tmp_vtable);
643    }
644    it->second->AssertNoURLRequests();
645    delete it->second;
646    current_context++;
647  }
648}
649
650// static
651ProfileIOData* ProfileIOData::FromResourceContext(
652    content::ResourceContext* rc) {
653  return (static_cast<ResourceContext*>(rc))->io_data_;
654}
655
656// static
657bool ProfileIOData::IsHandledProtocol(const std::string& scheme) {
658  DCHECK_EQ(scheme, StringToLowerASCII(scheme));
659  static const char* const kProtocolList[] = {
660    chrome::kFileScheme,
661    chrome::kChromeDevToolsScheme,
662    extensions::kExtensionScheme,
663    chrome::kExtensionResourceScheme,
664    chrome::kChromeUIScheme,
665    chrome::kDataScheme,
666#if defined(OS_CHROMEOS)
667    chrome::kDriveScheme,
668#endif  // defined(OS_CHROMEOS)
669    chrome::kAboutScheme,
670#if !defined(DISABLE_FTP_SUPPORT)
671    content::kFtpScheme,
672#endif  // !defined(DISABLE_FTP_SUPPORT)
673    chrome::kBlobScheme,
674    chrome::kFileSystemScheme,
675    chrome::kChromeSearchScheme,
676  };
677  for (size_t i = 0; i < arraysize(kProtocolList); ++i) {
678    if (scheme == kProtocolList[i])
679      return true;
680  }
681  return net::URLRequest::IsHandledProtocol(scheme);
682}
683
684// static
685bool ProfileIOData::IsHandledURL(const GURL& url) {
686  if (!url.is_valid()) {
687    // We handle error cases.
688    return true;
689  }
690
691  return IsHandledProtocol(url.scheme());
692}
693
694// static
695void ProfileIOData::InstallProtocolHandlers(
696    net::URLRequestJobFactoryImpl* job_factory,
697    content::ProtocolHandlerMap* protocol_handlers) {
698  for (content::ProtocolHandlerMap::iterator it =
699           protocol_handlers->begin();
700       it != protocol_handlers->end();
701       ++it) {
702    bool set_protocol = job_factory->SetProtocolHandler(
703        it->first, it->second.release());
704    DCHECK(set_protocol);
705  }
706  protocol_handlers->clear();
707}
708
709content::ResourceContext* ProfileIOData::GetResourceContext() const {
710  return resource_context_.get();
711}
712
713ChromeURLRequestContext* ProfileIOData::GetMainRequestContext() const {
714  DCHECK(initialized_);
715  return main_request_context_.get();
716}
717
718ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const {
719  DCHECK(initialized_);
720  ChromeURLRequestContext* context = AcquireMediaRequestContext();
721  DCHECK(context);
722  return context;
723}
724
725ChromeURLRequestContext* ProfileIOData::GetExtensionsRequestContext() const {
726  DCHECK(initialized_);
727  return extensions_request_context_.get();
728}
729
730ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext(
731    ChromeURLRequestContext* main_context,
732    const StoragePartitionDescriptor& partition_descriptor,
733    scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
734        protocol_handler_interceptor,
735    content::ProtocolHandlerMap* protocol_handlers) const {
736  DCHECK(initialized_);
737  ChromeURLRequestContext* context = NULL;
738  if (ContainsKey(app_request_context_map_, partition_descriptor)) {
739    context = app_request_context_map_[partition_descriptor];
740  } else {
741    context = AcquireIsolatedAppRequestContext(
742        main_context, partition_descriptor, protocol_handler_interceptor.Pass(),
743        protocol_handlers);
744    app_request_context_map_[partition_descriptor] = context;
745  }
746  DCHECK(context);
747  return context;
748}
749
750ChromeURLRequestContext* ProfileIOData::GetIsolatedMediaRequestContext(
751    ChromeURLRequestContext* app_context,
752    const StoragePartitionDescriptor& partition_descriptor) const {
753  DCHECK(initialized_);
754  ChromeURLRequestContext* context = NULL;
755  if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) {
756    context = isolated_media_request_context_map_[partition_descriptor];
757  } else {
758    context = AcquireIsolatedMediaRequestContext(app_context,
759                                                 partition_descriptor);
760    isolated_media_request_context_map_[partition_descriptor] = context;
761  }
762  DCHECK(context);
763  return context;
764}
765
766extensions::InfoMap* ProfileIOData::GetExtensionInfoMap() const {
767  DCHECK(initialized_) << "ExtensionSystem not initialized";
768  return extension_info_map_.get();
769}
770
771CookieSettings* ProfileIOData::GetCookieSettings() const {
772  // Allow either Init() or SetCookieSettingsForTesting() to initialize.
773  DCHECK(initialized_ || cookie_settings_.get());
774  return cookie_settings_.get();
775}
776
777HostContentSettingsMap* ProfileIOData::GetHostContentSettingsMap() const {
778  DCHECK(initialized_);
779  return host_content_settings_map_.get();
780}
781
782std::string ProfileIOData::GetMediaDeviceIDSalt() const {
783  return media_device_id_salt_->GetSalt();
784}
785
786void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() {
787  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
788#if defined(OS_CHROMEOS)
789  // Just fetch the value from ChromeOS' settings while we're on the UI thread.
790  // TODO(stevet): For now, this value is only set on profile initialization.
791  // We will want to do something similar to the PrefMember method below in the
792  // future to more accurately capture this state.
793  chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
794                                            &enable_metrics_);
795#elif defined(OS_ANDROID)
796  // TODO(dwkang): rename or unify the pref for UMA once we have conclusion
797  // in crbugs.com/246495.
798  // Android has it's own preferences for metrics / crash uploading.
799  enable_metrics_.Init(prefs::kCrashReportingEnabled,
800                       g_browser_process->local_state());
801  enable_metrics_.MoveToThread(
802      BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
803#else
804  // Prep the PrefMember and send it to the IO thread, since this value will be
805  // read from there.
806  enable_metrics_.Init(prefs::kMetricsReportingEnabled,
807                       g_browser_process->local_state());
808  enable_metrics_.MoveToThread(
809      BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
810#endif  // defined(OS_CHROMEOS)
811}
812
813bool ProfileIOData::GetMetricsEnabledStateOnIOThread() const {
814  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
815#if defined(OS_CHROMEOS)
816  return enable_metrics_;
817#else
818  return enable_metrics_.GetValue();
819#endif  // defined(OS_CHROMEOS)
820}
821
822base::WeakPtr<net::HttpServerProperties>
823ProfileIOData::http_server_properties() const {
824  return http_server_properties_->GetWeakPtr();
825}
826
827void ProfileIOData::set_http_server_properties(
828    scoped_ptr<net::HttpServerProperties> http_server_properties) const {
829  http_server_properties_ = http_server_properties.Pass();
830}
831
832ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data)
833    : io_data_(io_data),
834      host_resolver_(NULL),
835      request_context_(NULL) {
836  DCHECK(io_data);
837}
838
839ProfileIOData::ResourceContext::~ResourceContext() {}
840
841net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver()  {
842  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
843  DCHECK(io_data_->initialized_);
844  return host_resolver_;
845}
846
847net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext()  {
848  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
849  DCHECK(io_data_->initialized_);
850  return request_context_;
851}
852
853scoped_ptr<net::ClientCertStore>
854ProfileIOData::ResourceContext::CreateClientCertStore() {
855#if defined(USE_NSS)
856  return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreNSS(
857      base::Bind(&chrome::NewCryptoModuleBlockingDialogDelegate,
858                 chrome::kCryptoModulePasswordClientAuth)));
859#elif defined(OS_WIN)
860  return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreWin());
861#elif defined(OS_MACOSX)
862  return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreMac());
863#elif defined(USE_OPENSSL)
864  // OpenSSL does not use the ClientCertStore infrastructure. On Android client
865  // cert matching is done by the OS as part of the call to show the cert
866  // selection dialog.
867  return scoped_ptr<net::ClientCertStore>();
868#else
869#error Unknown platform.
870#endif
871}
872
873bool ProfileIOData::ResourceContext::AllowMicAccess(const GURL& origin) {
874  return AllowContentAccess(origin, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
875}
876
877bool ProfileIOData::ResourceContext::AllowCameraAccess(const GURL& origin) {
878  return AllowContentAccess(origin, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
879}
880
881bool ProfileIOData::ResourceContext::AllowContentAccess(
882    const GURL& origin, ContentSettingsType type) {
883  HostContentSettingsMap* content_settings =
884      io_data_->GetHostContentSettingsMap();
885  ContentSetting setting = content_settings->GetContentSetting(
886      origin, origin, type, NO_RESOURCE_IDENTIFIER);
887  return setting == CONTENT_SETTING_ALLOW;
888}
889
890std::string ProfileIOData::ResourceContext::GetMediaDeviceIDSalt() {
891  return io_data_->GetMediaDeviceIDSalt();
892}
893
894// static
895std::string ProfileIOData::GetSSLSessionCacheShard() {
896  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
897  // The SSL session cache is partitioned by setting a string. This returns a
898  // unique string to partition the SSL session cache. Each time we create a
899  // new profile, we'll get a fresh SSL session cache which is separate from
900  // the other profiles.
901  static unsigned ssl_session_cache_instance = 0;
902  return base::StringPrintf("profile/%u", ssl_session_cache_instance++);
903}
904
905void ProfileIOData::Init(content::ProtocolHandlerMap* protocol_handlers) const {
906  // The basic logic is implemented here. The specific initialization
907  // is done in InitializeInternal(), implemented by subtypes. Static helper
908  // functions have been provided to assist in common operations.
909  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
910  DCHECK(!initialized_);
911
912  startup_metric_utils::ScopedSlowStartupUMA
913      scoped_timer("Startup.SlowStartupProfileIODataInit");
914
915  // TODO(jhawkins): Remove once crbug.com/102004 is fixed.
916  CHECK(initialized_on_UI_thread_);
917
918  // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed.
919  CHECK(profile_params_.get());
920
921  IOThread* const io_thread = profile_params_->io_thread;
922  IOThread::Globals* const io_thread_globals = io_thread->globals();
923  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
924  load_time_stats_ = GetLoadTimeStats(io_thread_globals);
925
926  // Create the common request contexts.
927  main_request_context_.reset(
928      new ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_MAIN,
929                                  load_time_stats_));
930  extensions_request_context_.reset(
931      new ChromeURLRequestContext(
932          ChromeURLRequestContext::CONTEXT_TYPE_EXTENSIONS,
933          load_time_stats_));
934
935  ChromeNetworkDelegate* network_delegate =
936      new ChromeNetworkDelegate(
937          io_thread_globals->extension_event_router_forwarder.get(),
938          &enable_referrers_);
939  if (command_line.HasSwitch(switches::kEnableClientHints))
940    network_delegate->SetEnableClientHints();
941  network_delegate->set_extension_info_map(
942      profile_params_->extension_info_map.get());
943  network_delegate->set_url_blacklist_manager(url_blacklist_manager_.get());
944  network_delegate->set_profile(profile_params_->profile);
945  network_delegate->set_profile_path(profile_params_->path);
946  network_delegate->set_cookie_settings(profile_params_->cookie_settings.get());
947  network_delegate->set_enable_do_not_track(&enable_do_not_track_);
948  network_delegate->set_force_google_safe_search(&force_safesearch_);
949  network_delegate->set_load_time_stats(load_time_stats_);
950  network_delegate_.reset(network_delegate);
951
952  fraudulent_certificate_reporter_.reset(
953      new chrome_browser_net::ChromeFraudulentCertificateReporter(
954          main_request_context_.get()));
955
956  // NOTE: Proxy service uses the default io thread network delegate, not the
957  // delegate just created.
958  proxy_service_.reset(
959      ProxyServiceFactory::CreateProxyService(
960          io_thread->net_log(),
961          io_thread_globals->proxy_script_fetcher_context.get(),
962          io_thread_globals->system_network_delegate.get(),
963          profile_params_->proxy_config_service.release(),
964          command_line));
965
966  transport_security_state_.reset(new net::TransportSecurityState());
967  transport_security_persister_.reset(
968      new net::TransportSecurityPersister(
969          transport_security_state_.get(),
970          profile_params_->path,
971          BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
972          is_incognito()));
973
974  // Take ownership over these parameters.
975  cookie_settings_ = profile_params_->cookie_settings;
976  host_content_settings_map_ = profile_params_->host_content_settings_map;
977  extension_info_map_ = profile_params_->extension_info_map;
978
979  resource_context_->host_resolver_ = io_thread_globals->host_resolver.get();
980  resource_context_->request_context_ = main_request_context_.get();
981
982  if (profile_params_->resource_prefetch_predictor_observer_) {
983    resource_prefetch_predictor_observer_.reset(
984        profile_params_->resource_prefetch_predictor_observer_.release());
985  }
986
987#if defined(ENABLE_MANAGED_USERS)
988  managed_mode_url_filter_ = profile_params_->managed_mode_url_filter;
989#endif
990
991#if defined(OS_CHROMEOS)
992  if (cert_verifier_) {
993    cert_verifier_->InitializeOnIOThread();
994    main_request_context_->set_cert_verifier(cert_verifier_.get());
995  } else {
996    main_request_context_->set_cert_verifier(
997        io_thread_globals->cert_verifier.get());
998  }
999  username_hash_ = profile_params_->username_hash;
1000#else
1001  main_request_context_->set_cert_verifier(
1002      io_thread_globals->cert_verifier.get());
1003#endif
1004
1005  InitializeInternal(profile_params_.get(), protocol_handlers);
1006
1007  profile_params_.reset();
1008  initialized_ = true;
1009}
1010
1011void ProfileIOData::ApplyProfileParamsToContext(
1012    ChromeURLRequestContext* context) const {
1013  context->set_http_user_agent_settings(
1014      chrome_http_user_agent_settings_.get());
1015  context->set_ssl_config_service(profile_params_->ssl_config_service.get());
1016}
1017
1018scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults(
1019    scoped_ptr<net::URLRequestJobFactoryImpl> job_factory,
1020    scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
1021        protocol_handler_interceptor,
1022    net::NetworkDelegate* network_delegate,
1023    net::FtpTransactionFactory* ftp_transaction_factory) const {
1024  // NOTE(willchan): Keep these protocol handlers in sync with
1025  // ProfileIOData::IsHandledProtocol().
1026  bool set_protocol = job_factory->SetProtocolHandler(
1027      chrome::kFileScheme,
1028      new net::FileProtocolHandler(
1029          content::BrowserThread::GetBlockingPool()->
1030              GetTaskRunnerWithShutdownBehavior(
1031                  base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
1032  DCHECK(set_protocol);
1033
1034  DCHECK(extension_info_map_.get());
1035  set_protocol = job_factory->SetProtocolHandler(
1036      extensions::kExtensionScheme,
1037      CreateExtensionProtocolHandler(is_incognito(),
1038                                     extension_info_map_.get()));
1039  DCHECK(set_protocol);
1040  set_protocol = job_factory->SetProtocolHandler(
1041      chrome::kExtensionResourceScheme,
1042      CreateExtensionResourceProtocolHandler());
1043  DCHECK(set_protocol);
1044  set_protocol = job_factory->SetProtocolHandler(
1045      chrome::kDataScheme, new net::DataProtocolHandler());
1046  DCHECK(set_protocol);
1047#if defined(OS_CHROMEOS)
1048  if (!is_incognito() && profile_params_) {
1049    set_protocol = job_factory->SetProtocolHandler(
1050        chrome::kDriveScheme,
1051        new drive::DriveProtocolHandler(profile_params_->profile));
1052    DCHECK(set_protocol);
1053  }
1054#endif  // defined(OS_CHROMEOS)
1055
1056  job_factory->SetProtocolHandler(
1057      chrome::kAboutScheme,
1058      new chrome_browser_net::AboutProtocolHandler());
1059#if !defined(DISABLE_FTP_SUPPORT)
1060  DCHECK(ftp_transaction_factory);
1061  job_factory->SetProtocolHandler(
1062      content::kFtpScheme,
1063      new net::FtpProtocolHandler(ftp_transaction_factory));
1064#endif  // !defined(DISABLE_FTP_SUPPORT)
1065
1066  scoped_ptr<net::URLRequestJobFactory> top_job_factory =
1067      job_factory.PassAs<net::URLRequestJobFactory>();
1068#if defined(DEBUG_DEVTOOLS)
1069  top_job_factory.reset(new net::ProtocolInterceptJobFactory(
1070      top_job_factory.Pass(),
1071      scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
1072          new DebugDevToolsInterceptor)));
1073#endif
1074
1075  if (protocol_handler_interceptor) {
1076    protocol_handler_interceptor->Chain(top_job_factory.Pass());
1077    return protocol_handler_interceptor.PassAs<net::URLRequestJobFactory>();
1078  } else {
1079    return top_job_factory.Pass();
1080  }
1081}
1082
1083void ProfileIOData::ShutdownOnUIThread() {
1084  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1085
1086  if (signin_names_)
1087    signin_names_->ReleaseResourcesOnUIThread();
1088
1089  google_services_user_account_id_.Destroy();
1090  google_services_username_.Destroy();
1091  google_services_username_pattern_.Destroy();
1092  reverse_autologin_enabled_.Destroy();
1093  one_click_signin_rejected_email_list_.Destroy();
1094  enable_referrers_.Destroy();
1095  enable_do_not_track_.Destroy();
1096  force_safesearch_.Destroy();
1097#if !defined(OS_CHROMEOS)
1098  enable_metrics_.Destroy();
1099#endif
1100  safe_browsing_enabled_.Destroy();
1101  printing_enabled_.Destroy();
1102  sync_disabled_.Destroy();
1103  signin_allowed_.Destroy();
1104  if (media_device_id_salt_)
1105    media_device_id_salt_->ShutdownOnUIThread();
1106  session_startup_pref_.Destroy();
1107#if defined(ENABLE_CONFIGURATION_POLICY)
1108  if (url_blacklist_manager_)
1109    url_blacklist_manager_->ShutdownOnUIThread();
1110#endif
1111  if (chrome_http_user_agent_settings_)
1112    chrome_http_user_agent_settings_->CleanupOnUIThread();
1113  bool posted = BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
1114  if (!posted)
1115    delete this;
1116}
1117
1118void ProfileIOData::set_server_bound_cert_service(
1119    net::ServerBoundCertService* server_bound_cert_service) const {
1120  server_bound_cert_service_.reset(server_bound_cert_service);
1121}
1122
1123void ProfileIOData::DestroyResourceContext() {
1124  resource_context_.reset();
1125}
1126
1127void ProfileIOData::PopulateNetworkSessionParams(
1128    const ProfileParams* profile_params,
1129    net::HttpNetworkSession::Params* params) const {
1130
1131  ChromeURLRequestContext* context = main_request_context();
1132
1133  IOThread* const io_thread = profile_params->io_thread;
1134
1135  io_thread->InitializeNetworkSessionParams(params);
1136
1137  params->host_resolver = context->host_resolver();
1138  params->cert_verifier = context->cert_verifier();
1139  params->server_bound_cert_service = context->server_bound_cert_service();
1140  params->transport_security_state = context->transport_security_state();
1141  params->cert_transparency_verifier = context->cert_transparency_verifier();
1142  params->proxy_service = context->proxy_service();
1143  params->ssl_session_cache_shard = GetSSLSessionCacheShard();
1144  params->ssl_config_service = context->ssl_config_service();
1145  params->http_auth_handler_factory = context->http_auth_handler_factory();
1146  params->network_delegate = network_delegate();
1147  params->http_server_properties = context->http_server_properties();
1148  params->net_log = context->net_log();
1149}
1150
1151void ProfileIOData::SetCookieSettingsForTesting(
1152    CookieSettings* cookie_settings) {
1153  DCHECK(!cookie_settings_.get());
1154  cookie_settings_ = cookie_settings;
1155}
1156
1157void ProfileIOData::set_signin_names_for_testing(
1158    SigninNamesOnIOThread* signin_names) {
1159  signin_names_.reset(signin_names);
1160}
1161