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/trace_event/trace_event.h"
29 #include "base/version.h"
30 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
31 #include "chrome/browser/autocomplete/shortcuts_backend.h"
32 #include "chrome/browser/background/background_contents_service_factory.h"
33 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
34 #include "chrome/browser/browser_process.h"
35 #include "chrome/browser/chrome_notification_types.h"
36 #include "chrome/browser/content_settings/cookie_settings.h"
37 #include "chrome/browser/dom_distiller/profile_utils.h"
38 #include "chrome/browser/domain_reliability/service_factory.h"
39 #include "chrome/browser/download/chrome_download_manager_delegate.h"
40 #include "chrome/browser/download/download_service.h"
41 #include "chrome/browser/download/download_service_factory.h"
42 #include "chrome/browser/net/net_pref_observer.h"
43 #include "chrome/browser/net/predictor.h"
44 #include "chrome/browser/net/pref_proxy_config_tracker.h"
45 #include "chrome/browser/net/proxy_service_factory.h"
46 #include "chrome/browser/net/ssl_config_service_manager.h"
47 #include "chrome/browser/permissions/permission_manager.h"
48 #include "chrome/browser/permissions/permission_manager_factory.h"
49 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
50 #include "chrome/browser/plugins/plugin_prefs.h"
51 #include "chrome/browser/policy/profile_policy_connector.h"
52 #include "chrome/browser/policy/profile_policy_connector_factory.h"
53 #include "chrome/browser/prefs/browser_prefs.h"
54 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
55 #include "chrome/browser/prefs/pref_service_syncable.h"
56 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h"
57 #include "chrome/browser/prerender/prerender_manager_factory.h"
58 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
59 #include "chrome/browser/profiles/chrome_version_service.h"
60 #include "chrome/browser/profiles/gaia_info_update_service_factory.h"
61 #include "chrome/browser/profiles/profile_destroyer.h"
62 #include "chrome/browser/profiles/profile_info_cache.h"
63 #include "chrome/browser/profiles/profile_manager.h"
64 #include "chrome/browser/profiles/profile_metrics.h"
65 #include "chrome/browser/push_messaging/push_messaging_service_factory.h"
66 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
67 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
68 #include "chrome/browser/services/gcm/gcm_profile_service.h"
69 #include "chrome/browser/sessions/session_service_factory.h"
70 #include "chrome/browser/signin/signin_manager_factory.h"
71 #include "chrome/browser/signin/signin_ui_util.h"
72 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
73 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
74 #include "chrome/browser/ui/startup/startup_browser_creator.h"
75 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
76 #include "chrome/common/chrome_constants.h"
77 #include "chrome/common/chrome_paths_internal.h"
78 #include "chrome/common/chrome_switches.h"
79 #include "chrome/common/chrome_version_info.h"
80 #include "chrome/common/pref_names.h"
81 #include "chrome/common/url_constants.h"
82 #include "chrome/grit/chromium_strings.h"
83 #include "components/bookmarks/browser/bookmark_model.h"
84 #include "components/content_settings/core/browser/host_content_settings_map.h"
85 #include "components/domain_reliability/monitor.h"
86 #include "components/domain_reliability/service.h"
87 #include "components/keyed_service/content/browser_context_dependency_manager.h"
88 #include "components/metrics/metrics_service.h"
89 #include "components/pref_registry/pref_registry_syncable.h"
90 #include "components/signin/core/browser/signin_manager.h"
91 #include "components/startup_metric_utils/startup_metric_utils.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 "extensions/browser/extension_pref_store.h"
141 #include "extensions/browser/extension_pref_value_map.h"
142 #include "extensions/browser/extension_pref_value_map_factory.h"
143 #include "extensions/browser/extension_system.h"
144 #include "extensions/browser/guest_view/guest_view_manager.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 // Helper method needed because PostTask cannot currently take a Callback
181 // function with non-void return type.
182 void CreateDirectoryAndSignal(const base::FilePath
& path
,
183 base::WaitableEvent
* done_creating
) {
184 DVLOG(1) << "Creating directory " << path
.value();
185 base::CreateDirectory(path
);
186 done_creating
->Signal();
189 // Task that blocks the FILE thread until CreateDirectoryAndSignal() finishes on
190 // blocking I/O pool.
191 void BlockFileThreadOnDirectoryCreate(base::WaitableEvent
* done_creating
) {
192 done_creating
->Wait();
195 // Initiates creation of profile directory on |sequenced_task_runner| and
196 // ensures that FILE thread is blocked until that operation finishes.
197 void CreateProfileDirectory(base::SequencedTaskRunner
* sequenced_task_runner
,
198 const base::FilePath
& path
) {
199 base::WaitableEvent
* done_creating
= new base::WaitableEvent(false, false);
200 sequenced_task_runner
->PostTask(FROM_HERE
,
201 base::Bind(&CreateDirectoryAndSignal
,
204 // Block the FILE thread until directory is created on I/O pool to make sure
205 // that we don't attempt any operation until that part completes.
206 BrowserThread::PostTask(
207 BrowserThread::FILE, FROM_HERE
,
208 base::Bind(&BlockFileThreadOnDirectoryCreate
,
209 base::Owned(done_creating
)));
212 base::FilePath
GetCachePath(const base::FilePath
& base
) {
213 return base
.Append(chrome::kCacheDirname
);
216 base::FilePath
GetMediaCachePath(const base::FilePath
& base
) {
217 return base
.Append(chrome::kMediaCacheDirname
);
220 void EnsureReadmeFile(const base::FilePath
& base
) {
221 base::FilePath readme_path
= base
.Append(chrome::kReadmeFilename
);
222 if (base::PathExists(readme_path
))
224 std::string product_name
= l10n_util::GetStringUTF8(IDS_PRODUCT_NAME
);
225 std::string readme_text
= base::StringPrintf(
226 kReadmeText
, product_name
.c_str(), product_name
.c_str());
227 if (base::WriteFile(readme_path
, readme_text
.data(), readme_text
.size()) ==
229 LOG(ERROR
) << "Could not create README file.";
233 // Converts the kSessionExitedCleanly pref to the corresponding EXIT_TYPE.
234 Profile::ExitType
SessionTypePrefValueToExitType(const std::string
& value
) {
235 if (value
== kPrefExitTypeSessionEnded
)
236 return Profile::EXIT_SESSION_ENDED
;
237 if (value
== kPrefExitTypeCrashed
)
238 return Profile::EXIT_CRASHED
;
239 return Profile::EXIT_NORMAL
;
242 // Converts an ExitType into a string that is written to prefs.
243 std::string
ExitTypeToSessionTypePrefValue(Profile::ExitType type
) {
245 case Profile::EXIT_NORMAL
:
246 return ProfileImpl::kPrefExitTypeNormal
;
247 case Profile::EXIT_SESSION_ENDED
:
248 return kPrefExitTypeSessionEnded
;
249 case Profile::EXIT_CRASHED
:
250 return kPrefExitTypeCrashed
;
253 return std::string();
256 PrefStore
* CreateExtensionPrefStore(Profile
* profile
,
257 bool incognito_pref_store
) {
258 #if defined(ENABLE_EXTENSIONS)
259 return new ExtensionPrefStore(
260 ExtensionPrefValueMapFactory::GetForBrowserContext(profile
),
261 incognito_pref_store
);
270 Profile
* Profile::CreateProfile(const base::FilePath
& path
,
272 CreateMode create_mode
) {
273 TRACE_EVENT1("browser,startup",
274 "Profile::CreateProfile",
276 path
.AsUTF8Unsafe());
278 // Get sequenced task runner for making sure that file operations of
279 // this profile (defined by |path|) are executed in expected order
280 // (what was previously assured by the FILE thread).
281 scoped_refptr
<base::SequencedTaskRunner
> sequenced_task_runner
=
282 JsonPrefStore::GetTaskRunnerForFile(path
,
283 BrowserThread::GetBlockingPool());
284 if (create_mode
== CREATE_MODE_ASYNCHRONOUS
) {
286 CreateProfileDirectory(sequenced_task_runner
.get(), path
);
287 } else if (create_mode
== CREATE_MODE_SYNCHRONOUS
) {
288 if (!base::PathExists(path
)) {
289 // TODO(rogerta): http://crbug/160553 - Bad things happen if we can't
290 // write to the profile directory. We should eventually be able to run in
292 if (!base::CreateDirectory(path
))
299 return new ProfileImpl(
300 path
, delegate
, create_mode
, sequenced_task_runner
.get());
304 int ProfileImpl::create_readme_delay_ms
= 60000;
307 const char* const ProfileImpl::kPrefExitTypeNormal
= "Normal";
310 void ProfileImpl::RegisterProfilePrefs(
311 user_prefs::PrefRegistrySyncable
* registry
) {
312 registry
->RegisterBooleanPref(
313 prefs::kSavingBrowserHistoryDisabled
,
315 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
316 registry
->RegisterBooleanPref(
317 prefs::kAllowDeletingBrowserHistory
,
319 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
320 registry
->RegisterBooleanPref(
321 prefs::kSigninAllowed
,
323 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
324 registry
->RegisterBooleanPref(
325 prefs::kForceSafeSearch
,
327 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
328 registry
->RegisterBooleanPref(
329 prefs::kForceGoogleSafeSearch
,
331 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
332 registry
->RegisterBooleanPref(
333 prefs::kForceYouTubeSafetyMode
,
335 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
336 registry
->RegisterBooleanPref(
337 prefs::kRecordHistory
,
339 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
340 registry
->RegisterIntegerPref(
341 prefs::kProfileAvatarIndex
,
343 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
344 // Whether a profile is using an avatar without having explicitely chosen it
345 // (i.e. was assigned by default by legacy profile creation).
346 registry
->RegisterBooleanPref(
347 prefs::kProfileUsingDefaultAvatar
,
349 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
350 registry
->RegisterBooleanPref(
351 prefs::kProfileUsingGAIAAvatar
,
353 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
354 // Whether a profile is using a default avatar name (eg. Pickles or Person 1).
355 registry
->RegisterBooleanPref(
356 prefs::kProfileUsingDefaultName
,
358 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
359 registry
->RegisterStringPref(
360 prefs::kSupervisedUserId
,
362 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
363 registry
->RegisterStringPref(prefs::kProfileName
,
365 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
366 registry
->RegisterStringPref(prefs::kHomePage
,
368 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
369 #if defined(ENABLE_PRINTING)
370 registry
->RegisterBooleanPref(
371 prefs::kPrintingEnabled
,
373 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
375 registry
->RegisterBooleanPref(
376 prefs::kPrintPreviewDisabled
,
378 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
379 registry
->RegisterBooleanPref(
380 prefs::kForceEphemeralProfiles
,
382 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
384 // Initialize the cache prefs.
385 registry
->RegisterFilePathPref(
386 prefs::kDiskCacheDir
,
388 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
389 registry
->RegisterIntegerPref(
390 prefs::kDiskCacheSize
,
392 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
393 registry
->RegisterIntegerPref(
394 prefs::kMediaCacheSize
,
396 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
398 // Deprecated. Kept around for migration.
399 registry
->RegisterBooleanPref(
400 prefs::kClearSiteDataOnExit
,
402 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
405 ProfileImpl::ProfileImpl(
406 const base::FilePath
& path
,
408 CreateMode create_mode
,
409 base::SequencedTaskRunner
* sequenced_task_runner
)
411 pref_registry_(new user_prefs::PrefRegistrySyncable
),
413 host_content_settings_map_(NULL
),
414 last_session_exit_type_(EXIT_NORMAL
),
415 start_time_(Time::Now()),
418 TRACE_EVENT0("browser,startup", "ProfileImpl::ctor")
419 DCHECK(!path
.empty()) << "Using an empty path will attempt to write " <<
420 "profile files to the root directory!";
422 #if defined(ENABLE_SESSION_SERVICE)
423 create_session_service_timer_
.Start(FROM_HERE
,
424 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS
), this,
425 &ProfileImpl::EnsureSessionServiceCreated
);
428 set_is_guest_profile(path
== ProfileManager::GetGuestProfilePath());
429 set_is_system_profile(path
== ProfileManager::GetSystemProfilePath());
431 // Determine if prefetch is enabled for this profile.
432 // If not profile_manager is present, it means we are in a unittest.
433 const base::CommandLine
* command_line
=
434 base::CommandLine::ForCurrentProcess();
435 predictor_
= chrome_browser_net::Predictor::CreatePredictor(
436 !command_line
->HasSwitch(switches::kDisablePreconnect
),
437 !command_line
->HasSwitch(switches::kDnsPrefetchDisable
),
438 g_browser_process
->profile_manager() == NULL
);
440 // If we are creating the profile synchronously, then we should load the
441 // policy data immediately.
442 bool force_immediate_policy_load
= (create_mode
== CREATE_MODE_SYNCHRONOUS
);
443 #if defined(ENABLE_CONFIGURATION_POLICY)
444 policy::BrowserPolicyConnector
* connector
=
445 g_browser_process
->browser_policy_connector();
446 schema_registry_service_
=
447 policy::SchemaRegistryServiceFactory::CreateForContext(
448 this, connector
->GetChromeSchema(), connector
->GetSchemaRegistry());
449 #if defined(OS_CHROMEOS)
450 cloud_policy_manager_
=
451 policy::UserCloudPolicyManagerFactoryChromeOS::CreateForProfile(
452 this, force_immediate_policy_load
, sequenced_task_runner
);
454 cloud_policy_manager_
=
455 policy::UserCloudPolicyManagerFactory::CreateForOriginalBrowserContext(
457 force_immediate_policy_load
,
458 sequenced_task_runner
,
459 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
460 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
463 profile_policy_connector_
=
464 policy::ProfilePolicyConnectorFactory::CreateForBrowserContext(
465 this, force_immediate_policy_load
);
467 DCHECK(create_mode
== CREATE_MODE_ASYNCHRONOUS
||
468 create_mode
== CREATE_MODE_SYNCHRONOUS
);
469 bool async_prefs
= create_mode
== CREATE_MODE_ASYNCHRONOUS
;
471 #if defined(OS_CHROMEOS)
472 if (chromeos::ProfileHelper::IsSigninProfile(this))
473 chrome::RegisterLoginProfilePrefs(pref_registry_
.get());
476 chrome::RegisterUserProfilePrefs(pref_registry_
.get());
478 BrowserContextDependencyManager::GetInstance()->
479 RegisterProfilePrefsForServices(this, pref_registry_
.get());
481 SupervisedUserSettingsService
* supervised_user_settings
= nullptr;
482 #if defined(ENABLE_SUPERVISED_USERS)
483 supervised_user_settings
=
484 SupervisedUserSettingsServiceFactory::GetForProfile(this);
485 supervised_user_settings
->Init(
486 path_
, sequenced_task_runner
, create_mode
== CREATE_MODE_SYNCHRONOUS
);
489 scoped_refptr
<SafeBrowsingService
> safe_browsing_service(
490 g_browser_process
->safe_browsing_service());
491 if (safe_browsing_service
.get()) {
492 pref_validation_delegate_
=
493 safe_browsing_service
->CreatePreferenceValidationDelegate(this).Pass();
497 // On startup, preference loading is always synchronous so a scoped timer
499 startup_metric_utils::ScopedSlowStartupUMA
500 scoped_timer("Startup.SlowStartupPreferenceLoading");
501 prefs_
= chrome_prefs::CreateProfilePrefs(
503 sequenced_task_runner
,
504 pref_validation_delegate_
.get(),
505 profile_policy_connector_
->policy_service(),
506 supervised_user_settings
,
507 CreateExtensionPrefStore(this, false),
510 // Register on BrowserContext.
511 user_prefs::UserPrefs::Set(this, prefs_
.get());
514 startup_metric_utils::ScopedSlowStartupUMA
515 scoped_timer("Startup.SlowStartupFinalProfileInit");
517 // Wait for the notification that prefs has been loaded
518 // (successfully or not). Note that we can use base::Unretained
519 // because the PrefService is owned by this class and lives on
521 prefs_
->AddPrefInitObserver(base::Bind(&ProfileImpl::OnPrefsLoaded
,
522 base::Unretained(this)));
524 // Prefs were loaded synchronously so we can continue directly.
529 void ProfileImpl::DoFinalInit() {
530 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit")
531 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit");
533 PrefService
* prefs
= GetPrefs();
534 pref_change_registrar_
.Init(prefs
);
535 pref_change_registrar_
.Add(
536 prefs::kSupervisedUserId
,
537 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache
,
538 base::Unretained(this)));
540 // Changes in the profile avatar.
541 pref_change_registrar_
.Add(
542 prefs::kProfileAvatarIndex
,
543 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
544 base::Unretained(this)));
545 pref_change_registrar_
.Add(
546 prefs::kProfileUsingDefaultAvatar
,
547 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
548 base::Unretained(this)));
549 pref_change_registrar_
.Add(
550 prefs::kProfileUsingGAIAAvatar
,
551 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
552 base::Unretained(this)));
554 // Changes in the profile name.
555 pref_change_registrar_
.Add(
556 prefs::kProfileUsingDefaultName
,
557 base::Bind(&ProfileImpl::UpdateProfileNameCache
,
558 base::Unretained(this)));
559 pref_change_registrar_
.Add(
561 base::Bind(&ProfileImpl::UpdateProfileNameCache
,
562 base::Unretained(this)));
564 pref_change_registrar_
.Add(
565 prefs::kForceEphemeralProfiles
,
566 base::Bind(&ProfileImpl::UpdateProfileIsEphemeralCache
,
567 base::Unretained(this)));
569 // It would be nice to use PathService for fetching this directory, but
570 // the cache directory depends on the profile directory, which isn't available
572 chrome::GetUserCacheDirectory(path_
, &base_cache_path_
);
573 // Always create the cache directory asynchronously.
574 scoped_refptr
<base::SequencedTaskRunner
> sequenced_task_runner
=
575 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_
,
576 BrowserThread::GetBlockingPool());
577 CreateProfileDirectory(sequenced_task_runner
.get(), base_cache_path_
);
579 // Initialize components that depend on the current value.
580 UpdateProfileSupervisedUserIdCache();
581 UpdateProfileIsEphemeralCache();
582 GAIAInfoUpdateServiceFactory::GetForProfile(this);
584 PrefService
* local_state
= g_browser_process
->local_state();
585 ssl_config_service_manager_
.reset(
586 SSLConfigServiceManager::CreateDefaultManager(local_state
));
588 #if defined(ENABLE_BACKGROUND)
589 // Initialize the BackgroundModeManager - this has to be done here before
590 // InitExtensions() is called because it relies on receiving notifications
591 // when extensions are loaded. BackgroundModeManager is not needed under
592 // ChromeOS because Chrome is always running, no need for special keep-alive
593 // or launch-on-startup support unless kKeepAliveForTest is set.
594 bool init_background_mode_manager
= true;
595 #if defined(OS_CHROMEOS)
596 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
597 switches::kKeepAliveForTest
))
598 init_background_mode_manager
= false;
600 if (init_background_mode_manager
) {
601 if (g_browser_process
->background_mode_manager())
602 g_browser_process
->background_mode_manager()->RegisterProfile(this);
604 #endif // defined(ENABLE_BACKGROUND)
606 base::FilePath cookie_path
= GetPath();
607 cookie_path
= cookie_path
.Append(chrome::kCookieFilename
);
608 base::FilePath channel_id_path
= GetPath();
609 channel_id_path
= channel_id_path
.Append(chrome::kChannelIDFilename
);
610 base::FilePath cache_path
= base_cache_path_
;
612 GetCacheParameters(false, &cache_path
, &cache_max_size
);
613 cache_path
= GetCachePath(cache_path
);
615 base::FilePath media_cache_path
= base_cache_path_
;
616 int media_cache_max_size
;
617 GetCacheParameters(true, &media_cache_path
, &media_cache_max_size
);
618 media_cache_path
= GetMediaCachePath(media_cache_path
);
620 base::FilePath extensions_cookie_path
= GetPath();
621 extensions_cookie_path
=
622 extensions_cookie_path
.Append(chrome::kExtensionsCookieFilename
);
624 #if defined(OS_ANDROID)
625 SessionStartupPref::Type startup_pref_type
=
626 SessionStartupPref::GetDefaultStartupType();
628 SessionStartupPref::Type startup_pref_type
=
629 StartupBrowserCreator::GetSessionStartupPref(
630 *base::CommandLine::ForCurrentProcess(), this).type
;
632 content::CookieStoreConfig::SessionCookieMode session_cookie_mode
=
633 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES
;
634 if (GetLastSessionExitType() == Profile::EXIT_CRASHED
||
635 startup_pref_type
== SessionStartupPref::LAST
) {
636 session_cookie_mode
= content::CookieStoreConfig::RESTORED_SESSION_COOKIES
;
639 // Make sure we initialize the ProfileIOData after everything else has been
640 // initialized that we might be reading from the IO thread.
642 io_data_
.Init(cookie_path
, channel_id_path
, cache_path
,
643 cache_max_size
, media_cache_path
, media_cache_max_size
,
644 extensions_cookie_path
, GetPath(), predictor_
,
645 session_cookie_mode
, GetSpecialStoragePolicy(),
646 CreateDomainReliabilityMonitor(local_state
));
648 #if defined(ENABLE_PLUGINS)
649 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
650 PluginPrefs::GetForProfile(this).get(),
651 io_data_
.GetResourceContextNoInit());
654 // Delay README creation to not impact startup performance.
655 BrowserThread::PostDelayedTask(
656 BrowserThread::FILE, FROM_HERE
,
657 base::Bind(&EnsureReadmeFile
, GetPath()),
658 base::TimeDelta::FromMilliseconds(create_readme_delay_ms
));
660 TRACE_EVENT0("browser", "ProfileImpl::SetSaveSessionStorageOnDisk");
661 content::BrowserContext::GetDefaultStoragePartition(this)->
662 GetDOMStorageContext()->SetSaveSessionStorageOnDisk();
664 // TODO(wjmaclean): Remove this. crbug.com/420643
665 chrome::MigrateProfileZoomLevelPrefs(this);
667 // The DomDistillerViewerSource is not a normal WebUI so it must be registered
668 // as a URLDataSource early.
669 RegisterDomDistillerViewerSource(this);
671 #if defined(OS_CHROMEOS)
672 if (chromeos::UserSessionManager::GetInstance()
673 ->RestartToApplyPerSessionFlagsIfNeed(this, true)) {
679 TRACE_EVENT0("browser", "ProfileImpl::DoFileInit:DelegateOnProfileCreated")
680 delegate_
->OnProfileCreated(this, true, IsNewProfile());
684 SCOPED_UMA_HISTOGRAM_TIMER("Profile.NotifyProfileCreatedTime");
685 content::NotificationService::current()->Notify(
686 chrome::NOTIFICATION_PROFILE_CREATED
,
687 content::Source
<Profile
>(this),
688 content::NotificationService::NoDetails());
690 #if !defined(OS_CHROMEOS)
691 // Listen for bookmark model load, to bootstrap the sync service.
692 // On CrOS sync service will be initialized after sign in.
693 BookmarkModel
* model
= BookmarkModelFactory::GetForProfile(this);
694 model
->AddObserver(new BookmarkModelLoadedObserver(this));
697 PushMessagingServiceImpl::InitializeForProfile(this);
699 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS)
700 signin_ui_util::InitializePrefsForProfile(this);
704 base::FilePath
ProfileImpl::last_selected_directory() {
705 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory
);
708 void ProfileImpl::set_last_selected_directory(const base::FilePath
& path
) {
709 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory
, path
);
712 ProfileImpl::~ProfileImpl() {
713 MaybeSendDestroyedNotification();
715 bool prefs_loaded
= prefs_
->GetInitializationStatus() !=
716 PrefService::INITIALIZATION_STATUS_WAITING
;
718 #if defined(ENABLE_SESSION_SERVICE)
719 StopCreateSessionServiceTimer();
722 // Remove pref observers
723 pref_change_registrar_
.RemoveAll();
725 #if defined(ENABLE_PLUGINS)
726 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
727 io_data_
.GetResourceContextNoInit());
730 // Destroy OTR profile and its profile services first.
731 if (off_the_record_profile_
) {
732 ProfileDestroyer::DestroyOffTheRecordProfileNow(
733 off_the_record_profile_
.get());
735 #if defined(ENABLE_EXTENSIONS)
736 ExtensionPrefValueMapFactory::GetForBrowserContext(this)->
737 ClearAllIncognitoSessionOnlyPreferences();
741 BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
744 if (pref_proxy_config_tracker_
)
745 pref_proxy_config_tracker_
->DetachFromPrefService();
747 if (host_content_settings_map_
.get())
748 host_content_settings_map_
->ShutdownOnUIThread();
750 // This causes the Preferences file to be written to disk.
752 SetExitType(EXIT_NORMAL
);
755 std::string
ProfileImpl::GetProfileUserName() const {
756 const SigninManagerBase
* signin_manager
=
757 SigninManagerFactory::GetForProfileIfExists(this);
759 return signin_manager
->GetAuthenticatedUsername();
761 return std::string();
764 Profile::ProfileType
ProfileImpl::GetProfileType() const {
765 return REGULAR_PROFILE
;
768 scoped_ptr
<content::ZoomLevelDelegate
>
769 ProfileImpl::CreateZoomLevelDelegate(const base::FilePath
& partition_path
) {
770 return make_scoped_ptr(new chrome::ChromeZoomLevelPrefs(
771 GetPrefs(), GetPath(), partition_path
,
772 ui_zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
775 base::FilePath
ProfileImpl::GetPath() const {
779 scoped_refptr
<base::SequencedTaskRunner
> ProfileImpl::GetIOTaskRunner() {
780 return JsonPrefStore::GetTaskRunnerForFile(
781 GetPath(), BrowserThread::GetBlockingPool());
784 bool ProfileImpl::IsOffTheRecord() const {
788 Profile
* ProfileImpl::GetOffTheRecordProfile() {
789 if (!off_the_record_profile_
) {
790 scoped_ptr
<Profile
> p(CreateOffTheRecordProfile());
791 off_the_record_profile_
.swap(p
);
793 content::NotificationService::current()->Notify(
794 chrome::NOTIFICATION_PROFILE_CREATED
,
795 content::Source
<Profile
>(off_the_record_profile_
.get()),
796 content::NotificationService::NoDetails());
798 return off_the_record_profile_
.get();
801 void ProfileImpl::DestroyOffTheRecordProfile() {
802 off_the_record_profile_
.reset();
803 #if defined(ENABLE_EXTENSIONS)
804 ExtensionPrefValueMapFactory::GetForBrowserContext(this)->
805 ClearAllIncognitoSessionOnlyPreferences();
809 bool ProfileImpl::HasOffTheRecordProfile() {
810 return off_the_record_profile_
.get() != NULL
;
813 Profile
* ProfileImpl::GetOriginalProfile() {
817 bool ProfileImpl::IsSupervised() {
818 return !GetPrefs()->GetString(prefs::kSupervisedUserId
).empty();
821 bool ProfileImpl::IsChild() {
822 #if defined(ENABLE_SUPERVISED_USERS)
823 return GetPrefs()->GetString(prefs::kSupervisedUserId
) ==
824 supervised_users::kChildAccountSUID
;
830 bool ProfileImpl::IsLegacySupervised() {
831 return IsSupervised() && !IsChild();
834 ExtensionSpecialStoragePolicy
*
835 ProfileImpl::GetExtensionSpecialStoragePolicy() {
836 #if defined(ENABLE_EXTENSIONS)
837 if (!extension_special_storage_policy_
.get()) {
838 TRACE_EVENT0("browser", "ProfileImpl::GetExtensionSpecialStoragePolicy")
839 extension_special_storage_policy_
= new ExtensionSpecialStoragePolicy(
840 CookieSettings::Factory::GetForProfile(this).get());
842 return extension_special_storage_policy_
.get();
848 void ProfileImpl::OnPrefsLoaded(bool success
) {
849 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded");
850 SCOPED_UMA_HISTOGRAM_TIMER("Profile.OnPrefsLoadedTime");
853 delegate_
->OnProfileCreated(this, false, false);
857 // Migrate obsolete prefs.
858 if (g_browser_process
->local_state())
859 chrome::MigrateObsoleteBrowserPrefs(this, g_browser_process
->local_state());
860 chrome::MigrateObsoleteProfilePrefs(this);
862 // |kSessionExitType| was added after |kSessionExitedCleanly|. If the pref
863 // value is empty fallback to checking for |kSessionExitedCleanly|.
864 const std::string
exit_type_pref_value(
865 prefs_
->GetString(prefs::kSessionExitType
));
866 if (exit_type_pref_value
.empty()) {
867 last_session_exit_type_
=
868 prefs_
->GetBoolean(prefs::kSessionExitedCleanly
) ?
869 EXIT_NORMAL
: EXIT_CRASHED
;
871 last_session_exit_type_
=
872 SessionTypePrefValueToExitType(exit_type_pref_value
);
874 // Mark the session as open.
875 prefs_
->SetString(prefs::kSessionExitType
, kPrefExitTypeCrashed
);
876 // Force this to true in case we fallback and use it.
877 // TODO(sky): remove this in a couple of releases (m28ish).
878 prefs_
->SetBoolean(prefs::kSessionExitedCleanly
, true);
880 #if defined(OS_ANDROID) && defined(FULL_SAFE_BROWSING)
881 // Clear safe browsing setting in the case we need to roll back
882 // for users enrolled in Finch trial before.
883 if (!SafeBrowsingService::IsEnabledByFieldTrial())
884 prefs_
->ClearPref(prefs::kSafeBrowsingEnabled
);
887 g_browser_process
->profile_manager()->InitProfileUserPrefs(this);
890 SCOPED_UMA_HISTOGRAM_TIMER("Profile.CreateBrowserContextServicesTime");
891 BrowserContextDependencyManager::GetInstance()->
892 CreateBrowserContextServices(this);
895 DCHECK(!net_pref_observer_
);
897 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded:NetPrefObserver")
898 net_pref_observer_
.reset(new NetPrefObserver(prefs_
.get()));
901 chrome_prefs::SchedulePrefsFilePathVerification(path_
);
903 ChromeVersionService::OnProfileLoaded(prefs_
.get(), IsNewProfile());
907 bool ProfileImpl::WasCreatedByVersionOrLater(const std::string
& version
) {
908 Version
profile_version(ChromeVersionService::GetVersion(prefs_
.get()));
909 Version
arg_version(version
);
910 return (profile_version
.CompareTo(arg_version
) >= 0);
913 void ProfileImpl::SetExitType(ExitType exit_type
) {
914 #if defined(OS_CHROMEOS)
915 if (chromeos::ProfileHelper::IsSigninProfile(this))
920 ExitType current_exit_type
= SessionTypePrefValueToExitType(
921 prefs_
->GetString(prefs::kSessionExitType
));
922 // This may be invoked multiple times during shutdown. Only persist the value
923 // first passed in (unless it's a reset to the crash state, which happens when
924 // foregrounding the app on mobile).
925 if (exit_type
== EXIT_CRASHED
|| current_exit_type
== EXIT_CRASHED
) {
926 prefs_
->SetString(prefs::kSessionExitType
,
927 ExitTypeToSessionTypePrefValue(exit_type
));
931 Profile::ExitType
ProfileImpl::GetLastSessionExitType() {
932 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
933 // it to be set by asking for the prefs.
935 return last_session_exit_type_
;
938 PrefService
* ProfileImpl::GetPrefs() {
939 return const_cast<PrefService
*>(
940 static_cast<const ProfileImpl
*>(this)->GetPrefs());
943 const PrefService
* ProfileImpl::GetPrefs() const {
944 DCHECK(prefs_
); // Should explicitly be initialized.
948 chrome::ChromeZoomLevelPrefs
* ProfileImpl::GetZoomLevelPrefs() {
949 return static_cast<chrome::ChromeZoomLevelPrefs
*>(
950 GetDefaultStoragePartition(this)->GetZoomLevelDelegate());
953 PrefService
* ProfileImpl::GetOffTheRecordPrefs() {
956 // The new ExtensionPrefStore is ref_counted and the new PrefService
957 // stores a reference so that we do not leak memory here.
958 otr_prefs_
.reset(prefs_
->CreateIncognitoPrefService(
959 CreateExtensionPrefStore(this, true)));
961 return otr_prefs_
.get();
964 net::URLRequestContextGetter
* ProfileImpl::CreateRequestContext(
965 content::ProtocolHandlerMap
* protocol_handlers
,
966 content::URLRequestInterceptorScopedVector request_interceptors
) {
967 return io_data_
.CreateMainRequestContextGetter(
969 request_interceptors
.Pass(),
970 g_browser_process
->local_state(),
971 g_browser_process
->io_thread()).get();
974 net::URLRequestContextGetter
* ProfileImpl::GetRequestContext() {
975 return GetDefaultStoragePartition(this)->GetURLRequestContext();
978 net::URLRequestContextGetter
* ProfileImpl::GetRequestContextForRenderProcess(
979 int renderer_child_id
) {
980 content::RenderProcessHost
* rph
= content::RenderProcessHost::FromID(
983 return rph
->GetStoragePartition()->GetURLRequestContext();
986 net::URLRequestContextGetter
* ProfileImpl::GetMediaRequestContext() {
987 // Return the default media context.
988 return io_data_
.GetMediaRequestContextGetter().get();
991 net::URLRequestContextGetter
*
992 ProfileImpl::GetMediaRequestContextForRenderProcess(
993 int renderer_child_id
) {
994 content::RenderProcessHost
* rph
= content::RenderProcessHost::FromID(
996 content::StoragePartition
* storage_partition
= rph
->GetStoragePartition();
998 return storage_partition
->GetMediaURLRequestContext();
1001 net::URLRequestContextGetter
*
1002 ProfileImpl::GetMediaRequestContextForStoragePartition(
1003 const base::FilePath
& partition_path
,
1006 .GetIsolatedMediaRequestContextGetter(partition_path
, in_memory
).get();
1009 content::ResourceContext
* ProfileImpl::GetResourceContext() {
1010 return io_data_
.GetResourceContext();
1013 net::URLRequestContextGetter
* ProfileImpl::GetRequestContextForExtensions() {
1014 return io_data_
.GetExtensionsRequestContextGetter().get();
1017 net::URLRequestContextGetter
*
1018 ProfileImpl::CreateRequestContextForStoragePartition(
1019 const base::FilePath
& partition_path
,
1021 content::ProtocolHandlerMap
* protocol_handlers
,
1022 content::URLRequestInterceptorScopedVector request_interceptors
) {
1023 return io_data_
.CreateIsolatedAppRequestContextGetter(
1027 request_interceptors
.Pass()).get();
1030 net::SSLConfigService
* ProfileImpl::GetSSLConfigService() {
1031 // If ssl_config_service_manager_ is null, this typically means that some
1032 // KeyedService is trying to create a RequestContext at startup,
1033 // but SSLConfigServiceManager is not initialized until DoFinalInit() which is
1034 // invoked after all KeyedServices have been initialized (see
1035 // http://crbug.com/171406).
1036 DCHECK(ssl_config_service_manager_
) <<
1037 "SSLConfigServiceManager is not initialized yet";
1038 return ssl_config_service_manager_
->Get();
1041 HostContentSettingsMap
* ProfileImpl::GetHostContentSettingsMap() {
1042 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1043 if (!host_content_settings_map_
.get()) {
1044 host_content_settings_map_
= new HostContentSettingsMap(GetPrefs(), false);
1045 #if defined(ENABLE_SUPERVISED_USERS)
1046 SupervisedUserSettingsService
* supervised_user_settings
=
1047 SupervisedUserSettingsServiceFactory::GetForProfile(this);
1048 scoped_ptr
<content_settings::SupervisedProvider
> supervised_provider(
1049 new content_settings::SupervisedProvider(supervised_user_settings
));
1050 host_content_settings_map_
->RegisterProvider(
1051 HostContentSettingsMap::SUPERVISED_PROVIDER
,
1052 supervised_provider
.Pass());
1055 return host_content_settings_map_
.get();
1058 content::BrowserPluginGuestManager
* ProfileImpl::GetGuestManager() {
1059 #if defined(ENABLE_EXTENSIONS)
1060 return extensions::GuestViewManager::FromBrowserContext(this);
1066 DownloadManagerDelegate
* ProfileImpl::GetDownloadManagerDelegate() {
1067 return DownloadServiceFactory::GetForBrowserContext(this)->
1068 GetDownloadManagerDelegate();
1071 storage::SpecialStoragePolicy
* ProfileImpl::GetSpecialStoragePolicy() {
1072 #if defined(ENABLE_EXTENSIONS)
1073 return GetExtensionSpecialStoragePolicy();
1079 content::PushMessagingService
* ProfileImpl::GetPushMessagingService() {
1080 return PushMessagingServiceFactory::GetForProfile(this);
1083 content::SSLHostStateDelegate
* ProfileImpl::GetSSLHostStateDelegate() {
1084 return ChromeSSLHostStateDelegateFactory::GetForProfile(this);
1087 // TODO(mlamouri): we should all these BrowserContext implementation to Profile
1088 // instead of repeating them inside all Profile implementations.
1089 content::PermissionManager
* ProfileImpl::GetPermissionManager() {
1090 return PermissionManagerFactory::GetForProfile(this);
1093 bool ProfileImpl::IsSameProfile(Profile
* profile
) {
1094 if (profile
== static_cast<Profile
*>(this))
1096 Profile
* otr_profile
= off_the_record_profile_
.get();
1097 return otr_profile
&& profile
== otr_profile
;
1100 Time
ProfileImpl::GetStartTime() const {
1104 #if defined(ENABLE_SESSION_SERVICE)
1105 void ProfileImpl::StopCreateSessionServiceTimer() {
1106 create_session_service_timer_
.Stop();
1109 void ProfileImpl::EnsureSessionServiceCreated() {
1110 SessionServiceFactory::GetForProfile(this);
1114 #if defined(OS_CHROMEOS)
1115 void ProfileImpl::ChangeAppLocale(
1116 const std::string
& new_locale
, AppLocaleChangedVia via
) {
1117 if (new_locale
.empty()) {
1121 PrefService
* local_state
= g_browser_process
->local_state();
1122 DCHECK(local_state
);
1123 if (local_state
->IsManagedPreference(prefs::kApplicationLocale
))
1125 std::string pref_locale
= GetPrefs()->GetString(prefs::kApplicationLocale
);
1126 bool do_update_pref
= true;
1128 case APP_LOCALE_CHANGED_VIA_SETTINGS
:
1129 case APP_LOCALE_CHANGED_VIA_REVERT
: {
1130 // We keep kApplicationLocaleBackup value as a reference. In case value
1131 // of kApplicationLocale preference would change due to sync from other
1132 // device then kApplicationLocaleBackup value will trigger and allow us to
1133 // show notification about automatic locale change in LocaleChangeGuard.
1134 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, new_locale
);
1135 GetPrefs()->ClearPref(prefs::kApplicationLocaleAccepted
);
1136 // We maintain kApplicationLocale property in both a global storage
1137 // and user's profile. Global property determines locale of login screen,
1138 // while user's profile determines his personal locale preference.
1141 case APP_LOCALE_CHANGED_VIA_LOGIN
:
1142 case APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN
: {
1143 if (!pref_locale
.empty()) {
1144 DCHECK(pref_locale
== new_locale
);
1145 std::string accepted_locale
=
1146 GetPrefs()->GetString(prefs::kApplicationLocaleAccepted
);
1147 if (accepted_locale
== new_locale
) {
1148 // If locale is accepted then we do not want to show LocaleChange
1149 // notification. This notification is triggered by different values
1150 // of kApplicationLocaleBackup and kApplicationLocale preferences,
1151 // so make them identical.
1152 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, new_locale
);
1154 // Back up locale of login screen.
1155 std::string cur_locale
= g_browser_process
->GetApplicationLocale();
1156 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, cur_locale
);
1157 if (locale_change_guard_
== NULL
)
1158 locale_change_guard_
.reset(new chromeos::LocaleChangeGuard(this));
1159 locale_change_guard_
->PrepareChangingLocale(cur_locale
, new_locale
);
1162 std::string cur_locale
= g_browser_process
->GetApplicationLocale();
1163 std::string backup_locale
=
1164 GetPrefs()->GetString(prefs::kApplicationLocaleBackup
);
1165 // Profile synchronization takes time and is not completed at that
1166 // moment at first login. So we initialize locale preference in steps:
1167 // (1) first save it to temporary backup;
1168 // (2) on next login we assume that synchronization is already completed
1169 // and we may finalize initialization.
1170 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, cur_locale
);
1171 if (!new_locale
.empty())
1172 GetPrefs()->SetString(prefs::kApplicationLocale
, new_locale
);
1173 else if (!backup_locale
.empty())
1174 GetPrefs()->SetString(prefs::kApplicationLocale
, backup_locale
);
1175 do_update_pref
= false;
1179 case APP_LOCALE_CHANGED_VIA_UNKNOWN
:
1186 GetPrefs()->SetString(prefs::kApplicationLocale
, new_locale
);
1187 if (via
!= APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN
)
1188 local_state
->SetString(prefs::kApplicationLocale
, new_locale
);
1190 if (user_manager::UserManager::Get()->GetOwnerEmail() ==
1191 chromeos::ProfileHelper::Get()->GetUserByProfile(this)->email())
1192 local_state
->SetString(prefs::kOwnerLocale
, new_locale
);
1195 void ProfileImpl::OnLogin() {
1196 if (locale_change_guard_
== NULL
)
1197 locale_change_guard_
.reset(new chromeos::LocaleChangeGuard(this));
1198 locale_change_guard_
->OnLogin();
1201 void ProfileImpl::InitChromeOSPreferences() {
1202 chromeos_preferences_
.reset(new chromeos::Preferences());
1203 chromeos_preferences_
->Init(
1204 this, chromeos::ProfileHelper::Get()->GetUserByProfile(this));
1207 #endif // defined(OS_CHROMEOS)
1209 PrefProxyConfigTracker
* ProfileImpl::GetProxyConfigTracker() {
1210 if (!pref_proxy_config_tracker_
)
1211 pref_proxy_config_tracker_
.reset(CreateProxyConfigTracker());
1212 return pref_proxy_config_tracker_
.get();
1215 chrome_browser_net::Predictor
* ProfileImpl::GetNetworkPredictor() {
1219 DevToolsNetworkController
* ProfileImpl::GetDevToolsNetworkController() {
1220 return io_data_
.GetDevToolsNetworkController();
1223 void ProfileImpl::ClearNetworkingHistorySince(
1225 const base::Closure
& completion
) {
1226 io_data_
.ClearNetworkingHistorySince(time
, completion
);
1229 GURL
ProfileImpl::GetHomePage() {
1230 // --homepage overrides any preferences.
1231 const base::CommandLine
& command_line
=
1232 *base::CommandLine::ForCurrentProcess();
1233 if (command_line
.HasSwitch(switches::kHomePage
)) {
1234 // TODO(evanm): clean up usage of DIR_CURRENT.
1235 // http://code.google.com/p/chromium/issues/detail?id=60630
1236 // For now, allow this code to call getcwd().
1237 base::ThreadRestrictions::ScopedAllowIO allow_io
;
1239 base::FilePath browser_directory
;
1240 PathService::Get(base::DIR_CURRENT
, &browser_directory
);
1241 GURL
home_page(url_fixer::FixupRelativeFile(
1243 command_line
.GetSwitchValuePath(switches::kHomePage
)));
1244 if (home_page
.is_valid())
1248 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage
))
1249 return GURL(chrome::kChromeUINewTabURL
);
1250 GURL
home_page(url_fixer::FixupURL(GetPrefs()->GetString(prefs::kHomePage
),
1252 if (!home_page
.is_valid())
1253 return GURL(chrome::kChromeUINewTabURL
);
1257 void ProfileImpl::UpdateProfileSupervisedUserIdCache() {
1258 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1259 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1260 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1261 if (index
!= std::string::npos
) {
1262 std::string supervised_user_id
=
1263 GetPrefs()->GetString(prefs::kSupervisedUserId
);
1264 cache
.SetSupervisedUserIdOfProfileAtIndex(index
, supervised_user_id
);
1265 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager
);
1269 void ProfileImpl::UpdateProfileNameCache() {
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 std::string profile_name
=
1275 GetPrefs()->GetString(prefs::kProfileName
);
1276 cache
.SetNameOfProfileAtIndex(index
, base::UTF8ToUTF16(profile_name
));
1278 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName
);
1279 cache
.SetProfileIsUsingDefaultNameAtIndex(index
, default_name
);
1283 void ProfileImpl::UpdateProfileAvatarCache() {
1284 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1285 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1286 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1287 if (index
!= std::string::npos
) {
1288 size_t avatar_index
=
1289 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex
);
1290 cache
.SetAvatarIconOfProfileAtIndex(index
, avatar_index
);
1291 bool default_avatar
=
1292 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar
);
1293 cache
.SetProfileIsUsingDefaultAvatarAtIndex(index
, default_avatar
);
1295 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar
);
1296 cache
.SetIsUsingGAIAPictureOfProfileAtIndex(index
, gaia_avatar
);
1300 void ProfileImpl::UpdateProfileIsEphemeralCache() {
1301 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1302 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1303 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1304 if (index
!= std::string::npos
) {
1305 bool is_ephemeral
= GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles
);
1306 cache
.SetProfileIsEphemeralAtIndex(index
, is_ephemeral
);
1310 // Gets the cache parameters from the command line. If |is_media_context| is
1311 // set to true then settings for the media context type is what we need,
1312 // |cache_path| will be set to the user provided path, or will not be touched if
1313 // there is not an argument. |max_size| will be the user provided value or zero
1315 void ProfileImpl::GetCacheParameters(bool is_media_context
,
1316 base::FilePath
* cache_path
,
1320 base::FilePath
path(prefs_
->GetFilePath(prefs::kDiskCacheDir
));
1323 *max_size
= is_media_context
? prefs_
->GetInteger(prefs::kMediaCacheSize
) :
1324 prefs_
->GetInteger(prefs::kDiskCacheSize
);
1327 PrefProxyConfigTracker
* ProfileImpl::CreateProxyConfigTracker() {
1328 #if defined(OS_CHROMEOS)
1329 if (chromeos::ProfileHelper::IsSigninProfile(this)) {
1330 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
1331 g_browser_process
->local_state());
1333 #endif // defined(OS_CHROMEOS)
1334 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
1335 GetPrefs(), g_browser_process
->local_state());
1338 scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
1339 ProfileImpl::CreateDomainReliabilityMonitor(PrefService
* local_state
) {
1340 domain_reliability::DomainReliabilityService
* service
=
1341 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1342 GetForBrowserContext(this);
1344 return scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>();
1346 return service
->CreateMonitor(
1347 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));