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_impl.h"
10 #include "base/callback.h"
11 #include "base/command_line.h"
12 #include "base/compiler_specific.h"
13 #include "base/environment.h"
14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/metrics/histogram_macros.h"
19 #include "base/path_service.h"
20 #include "base/prefs/json_pref_store.h"
21 #include "base/prefs/scoped_user_pref_update.h"
22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "base/synchronization/waitable_event.h"
27 #include "base/threading/sequenced_worker_pool.h"
28 #include "base/threading/thread_restrictions.h"
29 #include "base/trace_event/trace_event.h"
30 #include "base/version.h"
31 #include "chrome/browser/background/background_contents_service_factory.h"
32 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
33 #include "chrome/browser/browser_process.h"
34 #include "chrome/browser/chrome_notification_types.h"
35 #include "chrome/browser/content_settings/cookie_settings_factory.h"
36 #include "chrome/browser/dom_distiller/profile_utils.h"
37 #include "chrome/browser/domain_reliability/service_factory.h"
38 #include "chrome/browser/download/chrome_download_manager_delegate.h"
39 #include "chrome/browser/download/download_service.h"
40 #include "chrome/browser/download/download_service_factory.h"
41 #include "chrome/browser/net/net_pref_observer.h"
42 #include "chrome/browser/net/predictor.h"
43 #include "chrome/browser/net/pref_proxy_config_tracker.h"
44 #include "chrome/browser/net/proxy_service_factory.h"
45 #include "chrome/browser/net/ssl_config_service_manager.h"
46 #include "chrome/browser/permissions/permission_manager.h"
47 #include "chrome/browser/permissions/permission_manager_factory.h"
48 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
49 #include "chrome/browser/plugins/plugin_prefs.h"
50 #include "chrome/browser/policy/profile_policy_connector.h"
51 #include "chrome/browser/policy/profile_policy_connector_factory.h"
52 #include "chrome/browser/prefs/browser_prefs.h"
53 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
54 #include "chrome/browser/prefs/pref_service_syncable.h"
55 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h"
56 #include "chrome/browser/prerender/prerender_manager_factory.h"
57 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
58 #include "chrome/browser/profiles/chrome_version_service.h"
59 #include "chrome/browser/profiles/gaia_info_update_service_factory.h"
60 #include "chrome/browser/profiles/profile_destroyer.h"
61 #include "chrome/browser/profiles/profile_info_cache.h"
62 #include "chrome/browser/profiles/profile_manager.h"
63 #include "chrome/browser/profiles/profile_metrics.h"
64 #include "chrome/browser/push_messaging/push_messaging_service_factory.h"
65 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
66 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
67 #include "chrome/browser/services/gcm/gcm_profile_service.h"
68 #include "chrome/browser/sessions/session_service_factory.h"
69 #include "chrome/browser/signin/signin_manager_factory.h"
70 #include "chrome/browser/signin/signin_ui_util.h"
71 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
72 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
73 #include "chrome/browser/ui/startup/startup_browser_creator.h"
74 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
75 #include "chrome/common/chrome_constants.h"
76 #include "chrome/common/chrome_paths_internal.h"
77 #include "chrome/common/chrome_switches.h"
78 #include "chrome/common/pref_names.h"
79 #include "chrome/common/url_constants.h"
80 #include "chrome/grit/chromium_strings.h"
81 #include "components/bookmarks/browser/bookmark_model.h"
82 #include "components/content_settings/core/browser/cookie_settings.h"
83 #include "components/content_settings/core/browser/host_content_settings_map.h"
84 #include "components/domain_reliability/monitor.h"
85 #include "components/domain_reliability/service.h"
86 #include "components/keyed_service/content/browser_context_dependency_manager.h"
87 #include "components/metrics/metrics_service.h"
88 #include "components/omnibox/browser/autocomplete_classifier.h"
89 #include "components/omnibox/browser/shortcuts_backend.h"
90 #include "components/pref_registry/pref_registry_syncable.h"
91 #include "components/signin/core/browser/signin_manager.h"
92 #include "components/ui/zoom/zoom_event_manager.h"
93 #include "components/url_fixer/url_fixer.h"
94 #include "components/user_prefs/user_prefs.h"
95 #include "content/public/browser/browser_thread.h"
96 #include "content/public/browser/dom_storage_context.h"
97 #include "content/public/browser/notification_service.h"
98 #include "content/public/browser/render_process_host.h"
99 #include "content/public/browser/storage_partition.h"
100 #include "content/public/browser/url_data_source.h"
101 #include "content/public/browser/user_metrics.h"
102 #include "content/public/common/content_constants.h"
103 #include "content/public/common/page_zoom.h"
104 #include "ui/base/l10n/l10n_util.h"
106 #if defined(OS_ANDROID)
107 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
108 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
111 #if defined(OS_CHROMEOS)
112 #include "chrome/browser/chromeos/locale_change_guard.h"
113 #include "chrome/browser/chromeos/preferences.h"
114 #include "chrome/browser/chromeos/profiles/profile_helper.h"
115 #include "components/user_manager/user_manager.h"
118 #if defined(ENABLE_BACKGROUND)
119 #include "chrome/browser/background/background_mode_manager.h"
122 #if defined(ENABLE_CONFIGURATION_POLICY)
123 #include "chrome/browser/policy/schema_registry_service.h"
124 #include "chrome/browser/policy/schema_registry_service_factory.h"
125 #include "components/policy/core/browser/browser_policy_connector.h"
126 #if defined(OS_CHROMEOS)
127 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
128 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
129 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h"
131 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
132 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
136 #if defined(ENABLE_EXTENSIONS)
137 #include "chrome/browser/extensions/extension_service.h"
138 #include "chrome/browser/extensions/extension_special_storage_policy.h"
139 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
140 #include "components/guest_view/browser/guest_view_manager.h"
141 #include "extensions/browser/extension_pref_store.h"
142 #include "extensions/browser/extension_pref_value_map.h"
143 #include "extensions/browser/extension_pref_value_map_factory.h"
144 #include "extensions/browser/extension_system.h"
147 #if defined(ENABLE_SUPERVISED_USERS)
148 #include "chrome/browser/content_settings/content_settings_supervised_provider.h"
149 #include "chrome/browser/supervised_user/supervised_user_constants.h"
150 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
151 #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
155 using base::TimeDelta
;
156 using base::UserMetricsAction
;
157 using bookmarks::BookmarkModel
;
158 using content::BrowserThread
;
159 using content::DownloadManagerDelegate
;
163 #if defined(ENABLE_SESSION_SERVICE)
164 // Delay, in milliseconds, before we explicitly create the SessionService.
165 const int kCreateSessionServiceDelayMS
= 500;
168 // Text content of README file created in each profile directory. Both %s
169 // placeholders must contain the product name. This is not localizable and hence
171 const char kReadmeText
[] =
172 "%s settings and storage represent user-selected preferences and "
173 "information and MUST not be extracted, overwritten or modified except "
174 "through %s defined APIs.";
176 // Value written to prefs for EXIT_CRASHED and EXIT_SESSION_ENDED.
177 const char kPrefExitTypeCrashed
[] = "Crashed";
178 const char kPrefExitTypeSessionEnded
[] = "SessionEnded";
180 void CreateProfileReadme(const base::FilePath
& profile_path
) {
181 base::ThreadRestrictions::AssertIOAllowed();
182 base::FilePath readme_path
= profile_path
.Append(chrome::kReadmeFilename
);
183 std::string product_name
= l10n_util::GetStringUTF8(IDS_PRODUCT_NAME
);
184 std::string readme_text
= base::StringPrintf(
185 kReadmeText
, product_name
.c_str(), product_name
.c_str());
186 if (base::WriteFile(readme_path
, readme_text
.data(), readme_text
.size()) ==
188 LOG(ERROR
) << "Could not create README file.";
192 // Helper method needed because PostTask cannot currently take a Callback
193 // function with non-void return type.
194 void CreateDirectoryAndSignal(const base::FilePath
& path
,
195 base::WaitableEvent
* done_creating
,
196 bool create_readme
) {
197 // If the readme exists, the profile directory must also already exist.
198 base::FilePath readme_path
= path
.Append(chrome::kReadmeFilename
);
199 if (base::PathExists(readme_path
)) {
200 done_creating
->Signal();
204 DVLOG(1) << "Creating directory " << path
.value();
205 if (base::CreateDirectory(path
) && create_readme
)
206 CreateProfileReadme(path
);
207 done_creating
->Signal();
210 // Task that blocks the FILE thread until CreateDirectoryAndSignal() finishes on
211 // blocking I/O pool.
212 void BlockFileThreadOnDirectoryCreate(base::WaitableEvent
* done_creating
) {
213 done_creating
->Wait();
216 // Initiates creation of profile directory on |sequenced_task_runner| and
217 // ensures that FILE thread is blocked until that operation finishes. If
218 // |create_readme| is true, the profile README will be created in the profile
220 void CreateProfileDirectory(base::SequencedTaskRunner
* sequenced_task_runner
,
221 const base::FilePath
& path
,
222 bool create_readme
) {
223 base::WaitableEvent
* done_creating
= new base::WaitableEvent(false, false);
224 sequenced_task_runner
->PostTask(
225 FROM_HERE
, base::Bind(&CreateDirectoryAndSignal
, path
, done_creating
,
227 // Block the FILE thread until directory is created on I/O pool to make sure
228 // that we don't attempt any operation until that part completes.
229 BrowserThread::PostTask(
230 BrowserThread::FILE, FROM_HERE
,
231 base::Bind(&BlockFileThreadOnDirectoryCreate
,
232 base::Owned(done_creating
)));
235 base::FilePath
GetCachePath(const base::FilePath
& base
) {
236 return base
.Append(chrome::kCacheDirname
);
239 base::FilePath
GetMediaCachePath(const base::FilePath
& base
) {
240 return base
.Append(chrome::kMediaCacheDirname
);
243 // Converts the kSessionExitedCleanly pref to the corresponding EXIT_TYPE.
244 Profile::ExitType
SessionTypePrefValueToExitType(const std::string
& value
) {
245 if (value
== kPrefExitTypeSessionEnded
)
246 return Profile::EXIT_SESSION_ENDED
;
247 if (value
== kPrefExitTypeCrashed
)
248 return Profile::EXIT_CRASHED
;
249 return Profile::EXIT_NORMAL
;
252 // Converts an ExitType into a string that is written to prefs.
253 std::string
ExitTypeToSessionTypePrefValue(Profile::ExitType type
) {
255 case Profile::EXIT_NORMAL
:
256 return ProfileImpl::kPrefExitTypeNormal
;
257 case Profile::EXIT_SESSION_ENDED
:
258 return kPrefExitTypeSessionEnded
;
259 case Profile::EXIT_CRASHED
:
260 return kPrefExitTypeCrashed
;
263 return std::string();
266 PrefStore
* CreateExtensionPrefStore(Profile
* profile
,
267 bool incognito_pref_store
) {
268 #if defined(ENABLE_EXTENSIONS)
269 return new ExtensionPrefStore(
270 ExtensionPrefValueMapFactory::GetForBrowserContext(profile
),
271 incognito_pref_store
);
280 Profile
* Profile::CreateProfile(const base::FilePath
& path
,
282 CreateMode create_mode
) {
283 TRACE_EVENT1("browser,startup",
284 "Profile::CreateProfile",
286 path
.AsUTF8Unsafe());
288 // Get sequenced task runner for making sure that file operations of
289 // this profile (defined by |path|) are executed in expected order
290 // (what was previously assured by the FILE thread).
291 scoped_refptr
<base::SequencedTaskRunner
> sequenced_task_runner
=
292 JsonPrefStore::GetTaskRunnerForFile(path
,
293 BrowserThread::GetBlockingPool());
294 if (create_mode
== CREATE_MODE_ASYNCHRONOUS
) {
296 CreateProfileDirectory(sequenced_task_runner
.get(), path
, true);
297 } else if (create_mode
== CREATE_MODE_SYNCHRONOUS
) {
298 if (!base::PathExists(path
)) {
299 // TODO(rogerta): http://crbug/160553 - Bad things happen if we can't
300 // write to the profile directory. We should eventually be able to run in
302 if (!base::CreateDirectory(path
))
305 CreateProfileReadme(path
);
311 return new ProfileImpl(
312 path
, delegate
, create_mode
, sequenced_task_runner
.get());
316 const char* const ProfileImpl::kPrefExitTypeNormal
= "Normal";
319 void ProfileImpl::RegisterProfilePrefs(
320 user_prefs::PrefRegistrySyncable
* registry
) {
321 registry
->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled
, false);
322 registry
->RegisterBooleanPref(prefs::kAllowDeletingBrowserHistory
, true);
323 registry
->RegisterBooleanPref(prefs::kSigninAllowed
, true);
324 registry
->RegisterBooleanPref(prefs::kForceGoogleSafeSearch
, false);
325 registry
->RegisterBooleanPref(prefs::kForceYouTubeSafetyMode
, false);
326 registry
->RegisterBooleanPref(prefs::kRecordHistory
, false);
327 registry
->RegisterIntegerPref(
328 prefs::kProfileAvatarIndex
,
330 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
331 // Whether a profile is using an avatar without having explicitely chosen it
332 // (i.e. was assigned by default by legacy profile creation).
333 registry
->RegisterBooleanPref(
334 prefs::kProfileUsingDefaultAvatar
,
336 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
337 registry
->RegisterBooleanPref(
338 prefs::kProfileUsingGAIAAvatar
,
340 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
341 // Whether a profile is using a default avatar name (eg. Pickles or Person 1).
342 registry
->RegisterBooleanPref(
343 prefs::kProfileUsingDefaultName
,
345 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
346 registry
->RegisterStringPref(prefs::kSupervisedUserId
, std::string());
347 registry
->RegisterStringPref(prefs::kProfileName
,
349 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
350 registry
->RegisterStringPref(prefs::kHomePage
,
352 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
353 #if defined(ENABLE_PRINTING)
354 registry
->RegisterBooleanPref(prefs::kPrintingEnabled
, true);
356 registry
->RegisterBooleanPref(prefs::kPrintPreviewDisabled
, false);
357 registry
->RegisterBooleanPref(prefs::kForceEphemeralProfiles
, false);
359 // Initialize the cache prefs.
360 registry
->RegisterFilePathPref(prefs::kDiskCacheDir
, base::FilePath());
361 registry
->RegisterIntegerPref(prefs::kDiskCacheSize
, 0);
362 registry
->RegisterIntegerPref(prefs::kMediaCacheSize
, 0);
364 // Deprecated. Kept around for migration.
365 registry
->RegisterBooleanPref(
366 prefs::kClearSiteDataOnExit
,
368 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
371 ProfileImpl::ProfileImpl(
372 const base::FilePath
& path
,
374 CreateMode create_mode
,
375 base::SequencedTaskRunner
* sequenced_task_runner
)
377 pref_registry_(new user_prefs::PrefRegistrySyncable
),
379 host_content_settings_map_(NULL
),
380 last_session_exit_type_(EXIT_NORMAL
),
381 start_time_(Time::Now()),
384 TRACE_EVENT0("browser,startup", "ProfileImpl::ctor")
385 DCHECK(!path
.empty()) << "Using an empty path will attempt to write " <<
386 "profile files to the root directory!";
388 #if defined(ENABLE_SESSION_SERVICE)
389 create_session_service_timer_
.Start(FROM_HERE
,
390 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS
), this,
391 &ProfileImpl::EnsureSessionServiceCreated
);
394 set_is_guest_profile(path
== ProfileManager::GetGuestProfilePath());
395 set_is_system_profile(path
== ProfileManager::GetSystemProfilePath());
397 // Determine if prefetch is enabled for this profile.
398 // If not profile_manager is present, it means we are in a unittest.
399 const base::CommandLine
* command_line
=
400 base::CommandLine::ForCurrentProcess();
401 predictor_
= chrome_browser_net::Predictor::CreatePredictor(
402 !command_line
->HasSwitch(switches::kDisablePreconnect
),
403 !command_line
->HasSwitch(switches::kDnsPrefetchDisable
),
404 g_browser_process
->profile_manager() == NULL
);
406 // If we are creating the profile synchronously, then we should load the
407 // policy data immediately.
408 bool force_immediate_policy_load
= (create_mode
== CREATE_MODE_SYNCHRONOUS
);
409 #if defined(ENABLE_CONFIGURATION_POLICY)
410 policy::BrowserPolicyConnector
* connector
=
411 g_browser_process
->browser_policy_connector();
412 schema_registry_service_
=
413 policy::SchemaRegistryServiceFactory::CreateForContext(
414 this, connector
->GetChromeSchema(), connector
->GetSchemaRegistry());
415 #if defined(OS_CHROMEOS)
416 cloud_policy_manager_
=
417 policy::UserCloudPolicyManagerFactoryChromeOS::CreateForProfile(
418 this, force_immediate_policy_load
, sequenced_task_runner
);
420 cloud_policy_manager_
=
421 policy::UserCloudPolicyManagerFactory::CreateForOriginalBrowserContext(
423 force_immediate_policy_load
,
424 sequenced_task_runner
,
425 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
426 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
429 profile_policy_connector_
=
430 policy::ProfilePolicyConnectorFactory::CreateForBrowserContext(
431 this, force_immediate_policy_load
);
433 DCHECK(create_mode
== CREATE_MODE_ASYNCHRONOUS
||
434 create_mode
== CREATE_MODE_SYNCHRONOUS
);
435 bool async_prefs
= create_mode
== CREATE_MODE_ASYNCHRONOUS
;
437 #if defined(OS_CHROMEOS)
438 if (chromeos::ProfileHelper::IsSigninProfile(this))
439 chrome::RegisterLoginProfilePrefs(pref_registry_
.get());
442 chrome::RegisterUserProfilePrefs(pref_registry_
.get());
444 BrowserContextDependencyManager::GetInstance()->
445 RegisterProfilePrefsForServices(this, pref_registry_
.get());
447 SupervisedUserSettingsService
* supervised_user_settings
= nullptr;
448 #if defined(ENABLE_SUPERVISED_USERS)
449 supervised_user_settings
=
450 SupervisedUserSettingsServiceFactory::GetForProfile(this);
451 supervised_user_settings
->Init(
452 path_
, sequenced_task_runner
, create_mode
== CREATE_MODE_SYNCHRONOUS
);
455 scoped_refptr
<SafeBrowsingService
> safe_browsing_service(
456 g_browser_process
->safe_browsing_service());
457 if (safe_browsing_service
.get()) {
458 pref_validation_delegate_
=
459 safe_browsing_service
->CreatePreferenceValidationDelegate(this).Pass();
463 prefs_
= chrome_prefs::CreateProfilePrefs(
465 sequenced_task_runner
,
466 pref_validation_delegate_
.get(),
467 profile_policy_connector_
->policy_service(),
468 supervised_user_settings
,
469 CreateExtensionPrefStore(this, false),
472 // Register on BrowserContext.
473 user_prefs::UserPrefs::Set(this, prefs_
.get());
477 // Wait for the notification that prefs has been loaded
478 // (successfully or not). Note that we can use base::Unretained
479 // because the PrefService is owned by this class and lives on
481 prefs_
->AddPrefInitObserver(base::Bind(
482 &ProfileImpl::OnPrefsLoaded
, base::Unretained(this), create_mode
));
484 // Prefs were loaded synchronously so we can continue directly.
485 OnPrefsLoaded(create_mode
, true);
489 void ProfileImpl::DoFinalInit() {
490 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit")
491 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit");
493 PrefService
* prefs
= GetPrefs();
494 pref_change_registrar_
.Init(prefs
);
495 pref_change_registrar_
.Add(
496 prefs::kSupervisedUserId
,
497 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache
,
498 base::Unretained(this)));
500 // Changes in the profile avatar.
501 pref_change_registrar_
.Add(
502 prefs::kProfileAvatarIndex
,
503 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
504 base::Unretained(this)));
505 pref_change_registrar_
.Add(
506 prefs::kProfileUsingDefaultAvatar
,
507 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
508 base::Unretained(this)));
509 pref_change_registrar_
.Add(
510 prefs::kProfileUsingGAIAAvatar
,
511 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
512 base::Unretained(this)));
514 // Changes in the profile name.
515 pref_change_registrar_
.Add(
516 prefs::kProfileUsingDefaultName
,
517 base::Bind(&ProfileImpl::UpdateProfileNameCache
,
518 base::Unretained(this)));
519 pref_change_registrar_
.Add(
521 base::Bind(&ProfileImpl::UpdateProfileNameCache
,
522 base::Unretained(this)));
524 pref_change_registrar_
.Add(
525 prefs::kForceEphemeralProfiles
,
526 base::Bind(&ProfileImpl::UpdateProfileIsEphemeralCache
,
527 base::Unretained(this)));
529 // It would be nice to use PathService for fetching this directory, but
530 // the cache directory depends on the profile directory, which isn't available
532 chrome::GetUserCacheDirectory(path_
, &base_cache_path_
);
533 // Always create the cache directory asynchronously.
534 scoped_refptr
<base::SequencedTaskRunner
> sequenced_task_runner
=
535 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_
,
536 BrowserThread::GetBlockingPool());
537 CreateProfileDirectory(sequenced_task_runner
.get(), base_cache_path_
, false);
539 // Initialize components that depend on the current value.
540 UpdateProfileSupervisedUserIdCache();
541 UpdateProfileIsEphemeralCache();
542 GAIAInfoUpdateServiceFactory::GetForProfile(this);
544 PrefService
* local_state
= g_browser_process
->local_state();
545 ssl_config_service_manager_
.reset(
546 SSLConfigServiceManager::CreateDefaultManager(local_state
));
548 #if defined(ENABLE_BACKGROUND)
549 // Initialize the BackgroundModeManager - this has to be done here before
550 // InitExtensions() is called because it relies on receiving notifications
551 // when extensions are loaded. BackgroundModeManager is not needed under
552 // ChromeOS because Chrome is always running, no need for special keep-alive
553 // or launch-on-startup support unless kKeepAliveForTest is set.
554 bool init_background_mode_manager
= true;
555 #if defined(OS_CHROMEOS)
556 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
557 switches::kKeepAliveForTest
))
558 init_background_mode_manager
= false;
560 if (init_background_mode_manager
) {
561 if (g_browser_process
->background_mode_manager())
562 g_browser_process
->background_mode_manager()->RegisterProfile(this);
564 #endif // defined(ENABLE_BACKGROUND)
566 base::FilePath cookie_path
= GetPath();
567 cookie_path
= cookie_path
.Append(chrome::kCookieFilename
);
568 base::FilePath channel_id_path
= GetPath();
569 channel_id_path
= channel_id_path
.Append(chrome::kChannelIDFilename
);
570 base::FilePath cache_path
= base_cache_path_
;
572 GetCacheParameters(false, &cache_path
, &cache_max_size
);
573 cache_path
= GetCachePath(cache_path
);
575 base::FilePath media_cache_path
= base_cache_path_
;
576 int media_cache_max_size
;
577 GetCacheParameters(true, &media_cache_path
, &media_cache_max_size
);
578 media_cache_path
= GetMediaCachePath(media_cache_path
);
580 base::FilePath extensions_cookie_path
= GetPath();
581 extensions_cookie_path
=
582 extensions_cookie_path
.Append(chrome::kExtensionsCookieFilename
);
584 #if defined(OS_ANDROID)
585 SessionStartupPref::Type startup_pref_type
=
586 SessionStartupPref::GetDefaultStartupType();
588 SessionStartupPref::Type startup_pref_type
=
589 StartupBrowserCreator::GetSessionStartupPref(
590 *base::CommandLine::ForCurrentProcess(), this).type
;
592 content::CookieStoreConfig::SessionCookieMode session_cookie_mode
=
593 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES
;
594 if (GetLastSessionExitType() == Profile::EXIT_CRASHED
||
595 startup_pref_type
== SessionStartupPref::LAST
) {
596 session_cookie_mode
= content::CookieStoreConfig::RESTORED_SESSION_COOKIES
;
599 // Make sure we initialize the ProfileIOData after everything else has been
600 // initialized that we might be reading from the IO thread.
602 io_data_
.Init(cookie_path
, channel_id_path
, cache_path
,
603 cache_max_size
, media_cache_path
, media_cache_max_size
,
604 extensions_cookie_path
, GetPath(), predictor_
,
605 session_cookie_mode
, GetSpecialStoragePolicy(),
606 CreateDomainReliabilityMonitor(local_state
));
608 #if defined(ENABLE_PLUGINS)
609 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
610 PluginPrefs::GetForProfile(this).get(),
611 io_data_
.GetResourceContextNoInit());
614 TRACE_EVENT0("browser", "ProfileImpl::SetSaveSessionStorageOnDisk");
615 content::BrowserContext::GetDefaultStoragePartition(this)->
616 GetDOMStorageContext()->SetSaveSessionStorageOnDisk();
618 // TODO(wjmaclean): Remove this. crbug.com/420643
619 chrome::MigrateProfileZoomLevelPrefs(this);
621 // The DomDistillerViewerSource is not a normal WebUI so it must be registered
622 // as a URLDataSource early.
623 RegisterDomDistillerViewerSource(this);
625 #if defined(OS_CHROMEOS)
626 if (chromeos::UserSessionManager::GetInstance()
627 ->RestartToApplyPerSessionFlagsIfNeed(this, true)) {
633 TRACE_EVENT0("browser", "ProfileImpl::DoFileInit:DelegateOnProfileCreated")
634 delegate_
->OnProfileCreated(this, true, IsNewProfile());
638 SCOPED_UMA_HISTOGRAM_TIMER("Profile.NotifyProfileCreatedTime");
639 content::NotificationService::current()->Notify(
640 chrome::NOTIFICATION_PROFILE_CREATED
,
641 content::Source
<Profile
>(this),
642 content::NotificationService::NoDetails());
644 #if !defined(OS_CHROMEOS)
645 // Listen for bookmark model load, to bootstrap the sync service.
646 // On CrOS sync service will be initialized after sign in.
647 BookmarkModel
* model
= BookmarkModelFactory::GetForProfile(this);
648 model
->AddObserver(new BookmarkModelLoadedObserver(this));
651 PushMessagingServiceImpl::InitializeForProfile(this);
653 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS)
654 signin_ui_util::InitializePrefsForProfile(this);
658 base::FilePath
ProfileImpl::last_selected_directory() {
659 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory
);
662 void ProfileImpl::set_last_selected_directory(const base::FilePath
& path
) {
663 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory
, path
);
666 ProfileImpl::~ProfileImpl() {
667 MaybeSendDestroyedNotification();
669 bool prefs_loaded
= prefs_
->GetInitializationStatus() !=
670 PrefService::INITIALIZATION_STATUS_WAITING
;
672 #if defined(ENABLE_SESSION_SERVICE)
673 StopCreateSessionServiceTimer();
676 // Remove pref observers
677 pref_change_registrar_
.RemoveAll();
679 #if defined(ENABLE_PLUGINS)
680 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
681 io_data_
.GetResourceContextNoInit());
684 // Destroy OTR profile and its profile services first.
685 if (off_the_record_profile_
) {
686 ProfileDestroyer::DestroyOffTheRecordProfileNow(
687 off_the_record_profile_
.get());
689 #if defined(ENABLE_EXTENSIONS)
690 ExtensionPrefValueMapFactory::GetForBrowserContext(this)->
691 ClearAllIncognitoSessionOnlyPreferences();
695 BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
698 if (pref_proxy_config_tracker_
)
699 pref_proxy_config_tracker_
->DetachFromPrefService();
701 if (host_content_settings_map_
.get())
702 host_content_settings_map_
->ShutdownOnUIThread();
704 // This causes the Preferences file to be written to disk.
706 SetExitType(EXIT_NORMAL
);
709 std::string
ProfileImpl::GetProfileUserName() const {
710 const SigninManagerBase
* signin_manager
=
711 SigninManagerFactory::GetForProfileIfExists(this);
713 return signin_manager
->GetAuthenticatedUsername();
715 return std::string();
718 Profile::ProfileType
ProfileImpl::GetProfileType() const {
719 return REGULAR_PROFILE
;
722 scoped_ptr
<content::ZoomLevelDelegate
>
723 ProfileImpl::CreateZoomLevelDelegate(const base::FilePath
& partition_path
) {
724 return make_scoped_ptr(new chrome::ChromeZoomLevelPrefs(
725 GetPrefs(), GetPath(), partition_path
,
726 ui_zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
729 base::FilePath
ProfileImpl::GetPath() const {
733 scoped_refptr
<base::SequencedTaskRunner
> ProfileImpl::GetIOTaskRunner() {
734 return JsonPrefStore::GetTaskRunnerForFile(
735 GetPath(), BrowserThread::GetBlockingPool());
738 bool ProfileImpl::IsOffTheRecord() const {
742 Profile
* ProfileImpl::GetOffTheRecordProfile() {
743 if (!off_the_record_profile_
) {
744 scoped_ptr
<Profile
> p(CreateOffTheRecordProfile());
745 off_the_record_profile_
.swap(p
);
747 content::NotificationService::current()->Notify(
748 chrome::NOTIFICATION_PROFILE_CREATED
,
749 content::Source
<Profile
>(off_the_record_profile_
.get()),
750 content::NotificationService::NoDetails());
752 return off_the_record_profile_
.get();
755 void ProfileImpl::DestroyOffTheRecordProfile() {
756 off_the_record_profile_
.reset();
757 #if defined(ENABLE_EXTENSIONS)
758 ExtensionPrefValueMapFactory::GetForBrowserContext(this)->
759 ClearAllIncognitoSessionOnlyPreferences();
763 bool ProfileImpl::HasOffTheRecordProfile() {
764 return off_the_record_profile_
.get() != NULL
;
767 Profile
* ProfileImpl::GetOriginalProfile() {
771 bool ProfileImpl::IsSupervised() const {
772 return !GetPrefs()->GetString(prefs::kSupervisedUserId
).empty();
775 bool ProfileImpl::IsChild() const {
776 #if defined(ENABLE_SUPERVISED_USERS)
777 return GetPrefs()->GetString(prefs::kSupervisedUserId
) ==
778 supervised_users::kChildAccountSUID
;
784 bool ProfileImpl::IsLegacySupervised() const {
785 return IsSupervised() && !IsChild();
788 ExtensionSpecialStoragePolicy
*
789 ProfileImpl::GetExtensionSpecialStoragePolicy() {
790 #if defined(ENABLE_EXTENSIONS)
791 if (!extension_special_storage_policy_
.get()) {
792 TRACE_EVENT0("browser", "ProfileImpl::GetExtensionSpecialStoragePolicy")
793 extension_special_storage_policy_
= new ExtensionSpecialStoragePolicy(
794 CookieSettingsFactory::GetForProfile(this).get());
796 return extension_special_storage_policy_
.get();
802 void ProfileImpl::OnLocaleReady() {
803 TRACE_EVENT0("browser", "ProfileImpl::OnLocaleReady");
804 SCOPED_UMA_HISTOGRAM_TIMER("Profile.OnLocaleReadyTime");
805 // Migrate obsolete prefs.
806 if (g_browser_process
->local_state())
807 chrome::MigrateObsoleteBrowserPrefs(this, g_browser_process
->local_state());
808 chrome::MigrateObsoleteProfilePrefs(this);
810 // |kSessionExitType| was added after |kSessionExitedCleanly|. If the pref
811 // value is empty fallback to checking for |kSessionExitedCleanly|.
812 const std::string
exit_type_pref_value(
813 prefs_
->GetString(prefs::kSessionExitType
));
814 if (exit_type_pref_value
.empty()) {
815 last_session_exit_type_
=
816 prefs_
->GetBoolean(prefs::kSessionExitedCleanly
) ?
817 EXIT_NORMAL
: EXIT_CRASHED
;
819 last_session_exit_type_
=
820 SessionTypePrefValueToExitType(exit_type_pref_value
);
822 // Mark the session as open.
823 prefs_
->SetString(prefs::kSessionExitType
, kPrefExitTypeCrashed
);
824 // Force this to true in case we fallback and use it.
825 // TODO(sky): remove this in a couple of releases (m28ish).
826 prefs_
->SetBoolean(prefs::kSessionExitedCleanly
, true);
828 #if defined(SAFE_BROWSING_DB_REMOTE)
829 // Hardcode this pref on this build of Android until the UX is developed.
830 // http://crbug.com/481558
831 prefs_
->SetBoolean(prefs::kSafeBrowsingEnabled
, true);
834 g_browser_process
->profile_manager()->InitProfileUserPrefs(this);
837 SCOPED_UMA_HISTOGRAM_TIMER("Profile.CreateBrowserContextServicesTime");
838 BrowserContextDependencyManager::GetInstance()->
839 CreateBrowserContextServices(this);
842 DCHECK(!net_pref_observer_
);
844 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded:NetPrefObserver")
845 net_pref_observer_
.reset(new NetPrefObserver(prefs_
.get()));
848 chrome_prefs::SchedulePrefsFilePathVerification(path_
);
850 ChromeVersionService::OnProfileLoaded(prefs_
.get(), IsNewProfile());
854 void ProfileImpl::OnPrefsLoaded(CreateMode create_mode
, bool success
) {
855 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded");
858 delegate_
->OnProfileCreated(this, false, false);
862 #if defined(OS_CHROMEOS)
863 if (create_mode
== CREATE_MODE_SYNCHRONOUS
) {
864 // Synchronous create mode implies that either it is restart after crash,
865 // or we are in tests. In both cases the first loaded locale is correct.
868 chromeos::UserSessionManager::GetInstance()->RespectLocalePreferenceWrapper(
869 this, base::Bind(&ProfileImpl::OnLocaleReady
, base::Unretained(this)));
876 bool ProfileImpl::WasCreatedByVersionOrLater(const std::string
& version
) {
877 Version
profile_version(ChromeVersionService::GetVersion(prefs_
.get()));
878 Version
arg_version(version
);
879 return (profile_version
.CompareTo(arg_version
) >= 0);
882 void ProfileImpl::SetExitType(ExitType exit_type
) {
883 #if defined(OS_CHROMEOS)
884 if (chromeos::ProfileHelper::IsSigninProfile(this))
889 ExitType current_exit_type
= SessionTypePrefValueToExitType(
890 prefs_
->GetString(prefs::kSessionExitType
));
891 // This may be invoked multiple times during shutdown. Only persist the value
892 // first passed in (unless it's a reset to the crash state, which happens when
893 // foregrounding the app on mobile).
894 if (exit_type
== EXIT_CRASHED
|| current_exit_type
== EXIT_CRASHED
) {
895 prefs_
->SetString(prefs::kSessionExitType
,
896 ExitTypeToSessionTypePrefValue(exit_type
));
900 Profile::ExitType
ProfileImpl::GetLastSessionExitType() {
901 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
902 // it to be set by asking for the prefs.
904 return last_session_exit_type_
;
907 PrefService
* ProfileImpl::GetPrefs() {
908 return const_cast<PrefService
*>(
909 static_cast<const ProfileImpl
*>(this)->GetPrefs());
912 const PrefService
* ProfileImpl::GetPrefs() const {
913 DCHECK(prefs_
); // Should explicitly be initialized.
917 chrome::ChromeZoomLevelPrefs
* ProfileImpl::GetZoomLevelPrefs() {
918 return static_cast<chrome::ChromeZoomLevelPrefs
*>(
919 GetDefaultStoragePartition(this)->GetZoomLevelDelegate());
922 PrefService
* ProfileImpl::GetOffTheRecordPrefs() {
925 // The new ExtensionPrefStore is ref_counted and the new PrefService
926 // stores a reference so that we do not leak memory here.
927 otr_prefs_
.reset(prefs_
->CreateIncognitoPrefService(
928 CreateExtensionPrefStore(this, true)));
930 return otr_prefs_
.get();
933 net::URLRequestContextGetter
* ProfileImpl::CreateRequestContext(
934 content::ProtocolHandlerMap
* protocol_handlers
,
935 content::URLRequestInterceptorScopedVector request_interceptors
) {
936 return io_data_
.CreateMainRequestContextGetter(
938 request_interceptors
.Pass(),
939 g_browser_process
->local_state(),
940 g_browser_process
->io_thread()).get();
943 net::URLRequestContextGetter
* ProfileImpl::GetRequestContext() {
944 return GetDefaultStoragePartition(this)->GetURLRequestContext();
947 net::URLRequestContextGetter
* ProfileImpl::GetRequestContextForRenderProcess(
948 int renderer_child_id
) {
949 content::RenderProcessHost
* rph
= content::RenderProcessHost::FromID(
952 return rph
->GetStoragePartition()->GetURLRequestContext();
955 net::URLRequestContextGetter
* ProfileImpl::GetMediaRequestContext() {
956 // Return the default media context.
957 return io_data_
.GetMediaRequestContextGetter().get();
960 net::URLRequestContextGetter
*
961 ProfileImpl::GetMediaRequestContextForRenderProcess(
962 int renderer_child_id
) {
963 content::RenderProcessHost
* rph
= content::RenderProcessHost::FromID(
965 content::StoragePartition
* storage_partition
= rph
->GetStoragePartition();
967 return storage_partition
->GetMediaURLRequestContext();
970 net::URLRequestContextGetter
*
971 ProfileImpl::GetMediaRequestContextForStoragePartition(
972 const base::FilePath
& partition_path
,
975 .GetIsolatedMediaRequestContextGetter(partition_path
, in_memory
).get();
978 content::ResourceContext
* ProfileImpl::GetResourceContext() {
979 return io_data_
.GetResourceContext();
982 net::URLRequestContextGetter
* ProfileImpl::GetRequestContextForExtensions() {
983 return io_data_
.GetExtensionsRequestContextGetter().get();
986 net::URLRequestContextGetter
*
987 ProfileImpl::CreateRequestContextForStoragePartition(
988 const base::FilePath
& partition_path
,
990 content::ProtocolHandlerMap
* protocol_handlers
,
991 content::URLRequestInterceptorScopedVector request_interceptors
) {
992 return io_data_
.CreateIsolatedAppRequestContextGetter(
996 request_interceptors
.Pass()).get();
999 net::SSLConfigService
* ProfileImpl::GetSSLConfigService() {
1000 // If ssl_config_service_manager_ is null, this typically means that some
1001 // KeyedService is trying to create a RequestContext at startup,
1002 // but SSLConfigServiceManager is not initialized until DoFinalInit() which is
1003 // invoked after all KeyedServices have been initialized (see
1004 // http://crbug.com/171406).
1005 DCHECK(ssl_config_service_manager_
) <<
1006 "SSLConfigServiceManager is not initialized yet";
1007 return ssl_config_service_manager_
->Get();
1010 HostContentSettingsMap
* ProfileImpl::GetHostContentSettingsMap() {
1011 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1012 if (!host_content_settings_map_
.get()) {
1013 host_content_settings_map_
= new HostContentSettingsMap(GetPrefs(), false);
1014 #if defined(ENABLE_SUPERVISED_USERS)
1015 SupervisedUserSettingsService
* supervised_user_settings
=
1016 SupervisedUserSettingsServiceFactory::GetForProfile(this);
1017 scoped_ptr
<content_settings::SupervisedProvider
> supervised_provider(
1018 new content_settings::SupervisedProvider(supervised_user_settings
));
1019 host_content_settings_map_
->RegisterProvider(
1020 HostContentSettingsMap::SUPERVISED_PROVIDER
,
1021 supervised_provider
.Pass());
1024 return host_content_settings_map_
.get();
1027 content::BrowserPluginGuestManager
* ProfileImpl::GetGuestManager() {
1028 #if defined(ENABLE_EXTENSIONS)
1029 return guest_view::GuestViewManager::FromBrowserContext(this);
1035 DownloadManagerDelegate
* ProfileImpl::GetDownloadManagerDelegate() {
1036 return DownloadServiceFactory::GetForBrowserContext(this)->
1037 GetDownloadManagerDelegate();
1040 storage::SpecialStoragePolicy
* ProfileImpl::GetSpecialStoragePolicy() {
1041 #if defined(ENABLE_EXTENSIONS)
1042 return GetExtensionSpecialStoragePolicy();
1048 content::PushMessagingService
* ProfileImpl::GetPushMessagingService() {
1049 return PushMessagingServiceFactory::GetForProfile(this);
1052 content::SSLHostStateDelegate
* ProfileImpl::GetSSLHostStateDelegate() {
1053 return ChromeSSLHostStateDelegateFactory::GetForProfile(this);
1056 // TODO(mlamouri): we should all these BrowserContext implementation to Profile
1057 // instead of repeating them inside all Profile implementations.
1058 content::PermissionManager
* ProfileImpl::GetPermissionManager() {
1059 return PermissionManagerFactory::GetForProfile(this);
1062 bool ProfileImpl::IsSameProfile(Profile
* profile
) {
1063 if (profile
== static_cast<Profile
*>(this))
1065 Profile
* otr_profile
= off_the_record_profile_
.get();
1066 return otr_profile
&& profile
== otr_profile
;
1069 Time
ProfileImpl::GetStartTime() const {
1073 #if defined(ENABLE_SESSION_SERVICE)
1074 void ProfileImpl::StopCreateSessionServiceTimer() {
1075 create_session_service_timer_
.Stop();
1078 void ProfileImpl::EnsureSessionServiceCreated() {
1079 SessionServiceFactory::GetForProfile(this);
1083 #if defined(OS_CHROMEOS)
1084 void ProfileImpl::ChangeAppLocale(
1085 const std::string
& new_locale
, AppLocaleChangedVia via
) {
1086 if (new_locale
.empty()) {
1090 PrefService
* local_state
= g_browser_process
->local_state();
1091 DCHECK(local_state
);
1092 if (local_state
->IsManagedPreference(prefs::kApplicationLocale
))
1094 std::string pref_locale
= GetPrefs()->GetString(prefs::kApplicationLocale
);
1095 bool do_update_pref
= true;
1097 case APP_LOCALE_CHANGED_VIA_SETTINGS
:
1098 case APP_LOCALE_CHANGED_VIA_REVERT
: {
1099 // We keep kApplicationLocaleBackup value as a reference. In case value
1100 // of kApplicationLocale preference would change due to sync from other
1101 // device then kApplicationLocaleBackup value will trigger and allow us to
1102 // show notification about automatic locale change in LocaleChangeGuard.
1103 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, new_locale
);
1104 GetPrefs()->ClearPref(prefs::kApplicationLocaleAccepted
);
1105 // We maintain kApplicationLocale property in both a global storage
1106 // and user's profile. Global property determines locale of login screen,
1107 // while user's profile determines his personal locale preference.
1110 case APP_LOCALE_CHANGED_VIA_LOGIN
:
1111 case APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN
: {
1112 if (!pref_locale
.empty()) {
1113 DCHECK(pref_locale
== new_locale
);
1114 std::string accepted_locale
=
1115 GetPrefs()->GetString(prefs::kApplicationLocaleAccepted
);
1116 if (accepted_locale
== new_locale
) {
1117 // If locale is accepted then we do not want to show LocaleChange
1118 // notification. This notification is triggered by different values
1119 // of kApplicationLocaleBackup and kApplicationLocale preferences,
1120 // so make them identical.
1121 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, new_locale
);
1123 // Back up locale of login screen.
1124 std::string cur_locale
= g_browser_process
->GetApplicationLocale();
1125 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, cur_locale
);
1126 if (locale_change_guard_
== NULL
)
1127 locale_change_guard_
.reset(new chromeos::LocaleChangeGuard(this));
1128 locale_change_guard_
->PrepareChangingLocale(cur_locale
, new_locale
);
1131 std::string cur_locale
= g_browser_process
->GetApplicationLocale();
1132 std::string backup_locale
=
1133 GetPrefs()->GetString(prefs::kApplicationLocaleBackup
);
1134 // Profile synchronization takes time and is not completed at that
1135 // moment at first login. So we initialize locale preference in steps:
1136 // (1) first save it to temporary backup;
1137 // (2) on next login we assume that synchronization is already completed
1138 // and we may finalize initialization.
1139 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, cur_locale
);
1140 if (!new_locale
.empty())
1141 GetPrefs()->SetString(prefs::kApplicationLocale
, new_locale
);
1142 else if (!backup_locale
.empty())
1143 GetPrefs()->SetString(prefs::kApplicationLocale
, backup_locale
);
1144 do_update_pref
= false;
1148 case APP_LOCALE_CHANGED_VIA_UNKNOWN
:
1155 GetPrefs()->SetString(prefs::kApplicationLocale
, new_locale
);
1156 if (via
!= APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN
)
1157 local_state
->SetString(prefs::kApplicationLocale
, new_locale
);
1159 if (user_manager::UserManager::Get()->GetOwnerEmail() ==
1160 chromeos::ProfileHelper::Get()->GetUserByProfile(this)->email())
1161 local_state
->SetString(prefs::kOwnerLocale
, new_locale
);
1164 void ProfileImpl::OnLogin() {
1165 if (locale_change_guard_
== NULL
)
1166 locale_change_guard_
.reset(new chromeos::LocaleChangeGuard(this));
1167 locale_change_guard_
->OnLogin();
1170 void ProfileImpl::InitChromeOSPreferences() {
1171 chromeos_preferences_
.reset(new chromeos::Preferences());
1172 chromeos_preferences_
->Init(
1173 this, chromeos::ProfileHelper::Get()->GetUserByProfile(this));
1176 #endif // defined(OS_CHROMEOS)
1178 PrefProxyConfigTracker
* ProfileImpl::GetProxyConfigTracker() {
1179 if (!pref_proxy_config_tracker_
)
1180 pref_proxy_config_tracker_
.reset(CreateProxyConfigTracker());
1181 return pref_proxy_config_tracker_
.get();
1184 chrome_browser_net::Predictor
* ProfileImpl::GetNetworkPredictor() {
1188 DevToolsNetworkController
* ProfileImpl::GetDevToolsNetworkController() {
1189 return io_data_
.GetDevToolsNetworkController();
1192 void ProfileImpl::ClearNetworkingHistorySince(
1194 const base::Closure
& completion
) {
1195 io_data_
.ClearNetworkingHistorySince(time
, completion
);
1198 GURL
ProfileImpl::GetHomePage() {
1199 // --homepage overrides any preferences.
1200 const base::CommandLine
& command_line
=
1201 *base::CommandLine::ForCurrentProcess();
1202 if (command_line
.HasSwitch(switches::kHomePage
)) {
1203 // TODO(evanm): clean up usage of DIR_CURRENT.
1204 // http://code.google.com/p/chromium/issues/detail?id=60630
1205 // For now, allow this code to call getcwd().
1206 base::ThreadRestrictions::ScopedAllowIO allow_io
;
1208 base::FilePath browser_directory
;
1209 PathService::Get(base::DIR_CURRENT
, &browser_directory
);
1210 GURL
home_page(url_fixer::FixupRelativeFile(
1212 command_line
.GetSwitchValuePath(switches::kHomePage
)));
1213 if (home_page
.is_valid())
1217 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage
))
1218 return GURL(chrome::kChromeUINewTabURL
);
1219 GURL
home_page(url_fixer::FixupURL(GetPrefs()->GetString(prefs::kHomePage
),
1221 if (!home_page
.is_valid())
1222 return GURL(chrome::kChromeUINewTabURL
);
1226 void ProfileImpl::UpdateProfileSupervisedUserIdCache() {
1227 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1228 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1229 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1230 if (index
!= std::string::npos
) {
1231 std::string supervised_user_id
=
1232 GetPrefs()->GetString(prefs::kSupervisedUserId
);
1233 cache
.SetSupervisedUserIdOfProfileAtIndex(index
, supervised_user_id
);
1234 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager
);
1238 void ProfileImpl::UpdateProfileNameCache() {
1239 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1240 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1241 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1242 if (index
!= std::string::npos
) {
1243 std::string profile_name
=
1244 GetPrefs()->GetString(prefs::kProfileName
);
1245 cache
.SetNameOfProfileAtIndex(index
, base::UTF8ToUTF16(profile_name
));
1247 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName
);
1248 cache
.SetProfileIsUsingDefaultNameAtIndex(index
, default_name
);
1252 void ProfileImpl::UpdateProfileAvatarCache() {
1253 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1254 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1255 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1256 if (index
!= std::string::npos
) {
1257 size_t avatar_index
=
1258 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex
);
1259 cache
.SetAvatarIconOfProfileAtIndex(index
, avatar_index
);
1260 bool default_avatar
=
1261 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar
);
1262 cache
.SetProfileIsUsingDefaultAvatarAtIndex(index
, default_avatar
);
1264 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar
);
1265 cache
.SetIsUsingGAIAPictureOfProfileAtIndex(index
, gaia_avatar
);
1269 void ProfileImpl::UpdateProfileIsEphemeralCache() {
1270 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1271 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1272 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1273 if (index
!= std::string::npos
) {
1274 bool is_ephemeral
= GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles
);
1275 cache
.SetProfileIsEphemeralAtIndex(index
, is_ephemeral
);
1279 // Gets the cache parameters from the command line. If |is_media_context| is
1280 // set to true then settings for the media context type is what we need,
1281 // |cache_path| will be set to the user provided path, or will not be touched if
1282 // there is not an argument. |max_size| will be the user provided value or zero
1284 void ProfileImpl::GetCacheParameters(bool is_media_context
,
1285 base::FilePath
* cache_path
,
1289 base::FilePath
path(prefs_
->GetFilePath(prefs::kDiskCacheDir
));
1292 *max_size
= is_media_context
? prefs_
->GetInteger(prefs::kMediaCacheSize
) :
1293 prefs_
->GetInteger(prefs::kDiskCacheSize
);
1296 PrefProxyConfigTracker
* ProfileImpl::CreateProxyConfigTracker() {
1297 #if defined(OS_CHROMEOS)
1298 if (chromeos::ProfileHelper::IsSigninProfile(this)) {
1299 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
1300 g_browser_process
->local_state());
1302 #endif // defined(OS_CHROMEOS)
1303 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
1304 GetPrefs(), g_browser_process
->local_state());
1307 scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
1308 ProfileImpl::CreateDomainReliabilityMonitor(PrefService
* local_state
) {
1309 domain_reliability::DomainReliabilityService
* service
=
1310 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1311 GetForBrowserContext(this);
1313 return scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>();
1315 return service
->CreateMonitor(
1316 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));