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/ui/zoom/zoom_event_manager.h"
92 #include "components/url_fixer/url_fixer.h"
93 #include "components/user_prefs/user_prefs.h"
94 #include "content/public/browser/browser_thread.h"
95 #include "content/public/browser/dom_storage_context.h"
96 #include "content/public/browser/notification_service.h"
97 #include "content/public/browser/render_process_host.h"
98 #include "content/public/browser/storage_partition.h"
99 #include "content/public/browser/url_data_source.h"
100 #include "content/public/browser/user_metrics.h"
101 #include "content/public/common/content_constants.h"
102 #include "content/public/common/page_zoom.h"
103 #include "ui/base/l10n/l10n_util.h"
105 #if defined(OS_ANDROID)
106 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
107 #include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
110 #if defined(OS_CHROMEOS)
111 #include "chrome/browser/chromeos/locale_change_guard.h"
112 #include "chrome/browser/chromeos/preferences.h"
113 #include "chrome/browser/chromeos/profiles/profile_helper.h"
114 #include "components/user_manager/user_manager.h"
117 #if defined(ENABLE_BACKGROUND)
118 #include "chrome/browser/background/background_mode_manager.h"
121 #if defined(ENABLE_CONFIGURATION_POLICY)
122 #include "chrome/browser/policy/schema_registry_service.h"
123 #include "chrome/browser/policy/schema_registry_service_factory.h"
124 #include "components/policy/core/browser/browser_policy_connector.h"
125 #if defined(OS_CHROMEOS)
126 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
127 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
128 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h"
130 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
131 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
135 #if defined(ENABLE_EXTENSIONS)
136 #include "chrome/browser/extensions/extension_service.h"
137 #include "chrome/browser/extensions/extension_special_storage_policy.h"
138 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
139 #include "components/guest_view/browser/guest_view_manager.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"
146 #if defined(ENABLE_SUPERVISED_USERS)
147 #include "chrome/browser/content_settings/content_settings_supervised_provider.h"
148 #include "chrome/browser/supervised_user/supervised_user_constants.h"
149 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
150 #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
154 using base::TimeDelta
;
155 using base::UserMetricsAction
;
156 using bookmarks::BookmarkModel
;
157 using content::BrowserThread
;
158 using content::DownloadManagerDelegate
;
162 #if defined(ENABLE_SESSION_SERVICE)
163 // Delay, in milliseconds, before we explicitly create the SessionService.
164 const int kCreateSessionServiceDelayMS
= 500;
167 // Text content of README file created in each profile directory. Both %s
168 // placeholders must contain the product name. This is not localizable and hence
170 const char kReadmeText
[] =
171 "%s settings and storage represent user-selected preferences and "
172 "information and MUST not be extracted, overwritten or modified except "
173 "through %s defined APIs.";
175 // Value written to prefs for EXIT_CRASHED and EXIT_SESSION_ENDED.
176 const char kPrefExitTypeCrashed
[] = "Crashed";
177 const char kPrefExitTypeSessionEnded
[] = "SessionEnded";
179 // Helper method needed because PostTask cannot currently take a Callback
180 // function with non-void return type.
181 void CreateDirectoryAndSignal(const base::FilePath
& path
,
182 base::WaitableEvent
* done_creating
) {
183 DVLOG(1) << "Creating directory " << path
.value();
184 base::CreateDirectory(path
);
185 done_creating
->Signal();
188 // Task that blocks the FILE thread until CreateDirectoryAndSignal() finishes on
189 // blocking I/O pool.
190 void BlockFileThreadOnDirectoryCreate(base::WaitableEvent
* done_creating
) {
191 done_creating
->Wait();
194 // Initiates creation of profile directory on |sequenced_task_runner| and
195 // ensures that FILE thread is blocked until that operation finishes.
196 void CreateProfileDirectory(base::SequencedTaskRunner
* sequenced_task_runner
,
197 const base::FilePath
& path
) {
198 base::WaitableEvent
* done_creating
= new base::WaitableEvent(false, false);
199 sequenced_task_runner
->PostTask(FROM_HERE
,
200 base::Bind(&CreateDirectoryAndSignal
,
203 // Block the FILE thread until directory is created on I/O pool to make sure
204 // that we don't attempt any operation until that part completes.
205 BrowserThread::PostTask(
206 BrowserThread::FILE, FROM_HERE
,
207 base::Bind(&BlockFileThreadOnDirectoryCreate
,
208 base::Owned(done_creating
)));
211 base::FilePath
GetCachePath(const base::FilePath
& base
) {
212 return base
.Append(chrome::kCacheDirname
);
215 base::FilePath
GetMediaCachePath(const base::FilePath
& base
) {
216 return base
.Append(chrome::kMediaCacheDirname
);
219 void EnsureReadmeFile(const base::FilePath
& base
) {
220 base::FilePath readme_path
= base
.Append(chrome::kReadmeFilename
);
221 if (base::PathExists(readme_path
))
223 std::string product_name
= l10n_util::GetStringUTF8(IDS_PRODUCT_NAME
);
224 std::string readme_text
= base::StringPrintf(
225 kReadmeText
, product_name
.c_str(), product_name
.c_str());
226 if (base::WriteFile(readme_path
, readme_text
.data(), readme_text
.size()) ==
228 LOG(ERROR
) << "Could not create README file.";
232 // Converts the kSessionExitedCleanly pref to the corresponding EXIT_TYPE.
233 Profile::ExitType
SessionTypePrefValueToExitType(const std::string
& value
) {
234 if (value
== kPrefExitTypeSessionEnded
)
235 return Profile::EXIT_SESSION_ENDED
;
236 if (value
== kPrefExitTypeCrashed
)
237 return Profile::EXIT_CRASHED
;
238 return Profile::EXIT_NORMAL
;
241 // Converts an ExitType into a string that is written to prefs.
242 std::string
ExitTypeToSessionTypePrefValue(Profile::ExitType type
) {
244 case Profile::EXIT_NORMAL
:
245 return ProfileImpl::kPrefExitTypeNormal
;
246 case Profile::EXIT_SESSION_ENDED
:
247 return kPrefExitTypeSessionEnded
;
248 case Profile::EXIT_CRASHED
:
249 return kPrefExitTypeCrashed
;
252 return std::string();
255 PrefStore
* CreateExtensionPrefStore(Profile
* profile
,
256 bool incognito_pref_store
) {
257 #if defined(ENABLE_EXTENSIONS)
258 return new ExtensionPrefStore(
259 ExtensionPrefValueMapFactory::GetForBrowserContext(profile
),
260 incognito_pref_store
);
269 Profile
* Profile::CreateProfile(const base::FilePath
& path
,
271 CreateMode create_mode
) {
272 TRACE_EVENT1("browser,startup",
273 "Profile::CreateProfile",
275 path
.AsUTF8Unsafe());
277 // Get sequenced task runner for making sure that file operations of
278 // this profile (defined by |path|) are executed in expected order
279 // (what was previously assured by the FILE thread).
280 scoped_refptr
<base::SequencedTaskRunner
> sequenced_task_runner
=
281 JsonPrefStore::GetTaskRunnerForFile(path
,
282 BrowserThread::GetBlockingPool());
283 if (create_mode
== CREATE_MODE_ASYNCHRONOUS
) {
285 CreateProfileDirectory(sequenced_task_runner
.get(), path
);
286 } else if (create_mode
== CREATE_MODE_SYNCHRONOUS
) {
287 if (!base::PathExists(path
)) {
288 // TODO(rogerta): http://crbug/160553 - Bad things happen if we can't
289 // write to the profile directory. We should eventually be able to run in
291 if (!base::CreateDirectory(path
))
298 return new ProfileImpl(
299 path
, delegate
, create_mode
, sequenced_task_runner
.get());
303 int ProfileImpl::create_readme_delay_ms
= 60000;
306 const char* const ProfileImpl::kPrefExitTypeNormal
= "Normal";
309 void ProfileImpl::RegisterProfilePrefs(
310 user_prefs::PrefRegistrySyncable
* registry
) {
311 registry
->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled
, false);
312 registry
->RegisterBooleanPref(prefs::kAllowDeletingBrowserHistory
, true);
313 registry
->RegisterBooleanPref(prefs::kSigninAllowed
, true);
314 registry
->RegisterBooleanPref(prefs::kForceGoogleSafeSearch
, false);
315 registry
->RegisterBooleanPref(prefs::kForceYouTubeSafetyMode
, false);
316 registry
->RegisterBooleanPref(prefs::kRecordHistory
, false);
317 registry
->RegisterIntegerPref(
318 prefs::kProfileAvatarIndex
,
320 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
321 // Whether a profile is using an avatar without having explicitely chosen it
322 // (i.e. was assigned by default by legacy profile creation).
323 registry
->RegisterBooleanPref(
324 prefs::kProfileUsingDefaultAvatar
,
326 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
327 registry
->RegisterBooleanPref(
328 prefs::kProfileUsingGAIAAvatar
,
330 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
331 // Whether a profile is using a default avatar name (eg. Pickles or Person 1).
332 registry
->RegisterBooleanPref(
333 prefs::kProfileUsingDefaultName
,
335 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
336 registry
->RegisterStringPref(prefs::kSupervisedUserId
, std::string());
337 registry
->RegisterStringPref(prefs::kProfileName
,
339 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
340 registry
->RegisterStringPref(prefs::kHomePage
,
342 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
343 #if defined(ENABLE_PRINTING)
344 registry
->RegisterBooleanPref(prefs::kPrintingEnabled
, true);
346 registry
->RegisterBooleanPref(prefs::kPrintPreviewDisabled
, false);
347 registry
->RegisterBooleanPref(prefs::kForceEphemeralProfiles
, false);
349 // Initialize the cache prefs.
350 registry
->RegisterFilePathPref(prefs::kDiskCacheDir
, base::FilePath());
351 registry
->RegisterIntegerPref(prefs::kDiskCacheSize
, 0);
352 registry
->RegisterIntegerPref(prefs::kMediaCacheSize
, 0);
354 // Deprecated. Kept around for migration.
355 registry
->RegisterBooleanPref(
356 prefs::kClearSiteDataOnExit
,
358 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
361 ProfileImpl::ProfileImpl(
362 const base::FilePath
& path
,
364 CreateMode create_mode
,
365 base::SequencedTaskRunner
* sequenced_task_runner
)
367 pref_registry_(new user_prefs::PrefRegistrySyncable
),
369 host_content_settings_map_(NULL
),
370 last_session_exit_type_(EXIT_NORMAL
),
371 start_time_(Time::Now()),
374 TRACE_EVENT0("browser,startup", "ProfileImpl::ctor")
375 DCHECK(!path
.empty()) << "Using an empty path will attempt to write " <<
376 "profile files to the root directory!";
378 #if defined(ENABLE_SESSION_SERVICE)
379 create_session_service_timer_
.Start(FROM_HERE
,
380 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS
), this,
381 &ProfileImpl::EnsureSessionServiceCreated
);
384 set_is_guest_profile(path
== ProfileManager::GetGuestProfilePath());
385 set_is_system_profile(path
== ProfileManager::GetSystemProfilePath());
387 // Determine if prefetch is enabled for this profile.
388 // If not profile_manager is present, it means we are in a unittest.
389 const base::CommandLine
* command_line
=
390 base::CommandLine::ForCurrentProcess();
391 predictor_
= chrome_browser_net::Predictor::CreatePredictor(
392 !command_line
->HasSwitch(switches::kDisablePreconnect
),
393 !command_line
->HasSwitch(switches::kDnsPrefetchDisable
),
394 g_browser_process
->profile_manager() == NULL
);
396 // If we are creating the profile synchronously, then we should load the
397 // policy data immediately.
398 bool force_immediate_policy_load
= (create_mode
== CREATE_MODE_SYNCHRONOUS
);
399 #if defined(ENABLE_CONFIGURATION_POLICY)
400 policy::BrowserPolicyConnector
* connector
=
401 g_browser_process
->browser_policy_connector();
402 schema_registry_service_
=
403 policy::SchemaRegistryServiceFactory::CreateForContext(
404 this, connector
->GetChromeSchema(), connector
->GetSchemaRegistry());
405 #if defined(OS_CHROMEOS)
406 cloud_policy_manager_
=
407 policy::UserCloudPolicyManagerFactoryChromeOS::CreateForProfile(
408 this, force_immediate_policy_load
, sequenced_task_runner
);
410 cloud_policy_manager_
=
411 policy::UserCloudPolicyManagerFactory::CreateForOriginalBrowserContext(
413 force_immediate_policy_load
,
414 sequenced_task_runner
,
415 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
416 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
419 profile_policy_connector_
=
420 policy::ProfilePolicyConnectorFactory::CreateForBrowserContext(
421 this, force_immediate_policy_load
);
423 DCHECK(create_mode
== CREATE_MODE_ASYNCHRONOUS
||
424 create_mode
== CREATE_MODE_SYNCHRONOUS
);
425 bool async_prefs
= create_mode
== CREATE_MODE_ASYNCHRONOUS
;
427 #if defined(OS_CHROMEOS)
428 if (chromeos::ProfileHelper::IsSigninProfile(this))
429 chrome::RegisterLoginProfilePrefs(pref_registry_
.get());
432 chrome::RegisterUserProfilePrefs(pref_registry_
.get());
434 BrowserContextDependencyManager::GetInstance()->
435 RegisterProfilePrefsForServices(this, pref_registry_
.get());
437 SupervisedUserSettingsService
* supervised_user_settings
= nullptr;
438 #if defined(ENABLE_SUPERVISED_USERS)
439 supervised_user_settings
=
440 SupervisedUserSettingsServiceFactory::GetForProfile(this);
441 supervised_user_settings
->Init(
442 path_
, sequenced_task_runner
, create_mode
== CREATE_MODE_SYNCHRONOUS
);
445 scoped_refptr
<SafeBrowsingService
> safe_browsing_service(
446 g_browser_process
->safe_browsing_service());
447 if (safe_browsing_service
.get()) {
448 pref_validation_delegate_
=
449 safe_browsing_service
->CreatePreferenceValidationDelegate(this).Pass();
453 prefs_
= chrome_prefs::CreateProfilePrefs(
455 sequenced_task_runner
,
456 pref_validation_delegate_
.get(),
457 profile_policy_connector_
->policy_service(),
458 supervised_user_settings
,
459 CreateExtensionPrefStore(this, false),
462 // Register on BrowserContext.
463 user_prefs::UserPrefs::Set(this, prefs_
.get());
467 // Wait for the notification that prefs has been loaded
468 // (successfully or not). Note that we can use base::Unretained
469 // because the PrefService is owned by this class and lives on
471 prefs_
->AddPrefInitObserver(base::Bind(
472 &ProfileImpl::OnPrefsLoaded
, base::Unretained(this), create_mode
));
474 // Prefs were loaded synchronously so we can continue directly.
475 OnPrefsLoaded(create_mode
, true);
479 void ProfileImpl::DoFinalInit() {
480 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit")
481 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit");
483 PrefService
* prefs
= GetPrefs();
484 pref_change_registrar_
.Init(prefs
);
485 pref_change_registrar_
.Add(
486 prefs::kSupervisedUserId
,
487 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache
,
488 base::Unretained(this)));
490 // Changes in the profile avatar.
491 pref_change_registrar_
.Add(
492 prefs::kProfileAvatarIndex
,
493 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
494 base::Unretained(this)));
495 pref_change_registrar_
.Add(
496 prefs::kProfileUsingDefaultAvatar
,
497 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
498 base::Unretained(this)));
499 pref_change_registrar_
.Add(
500 prefs::kProfileUsingGAIAAvatar
,
501 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
502 base::Unretained(this)));
504 // Changes in the profile name.
505 pref_change_registrar_
.Add(
506 prefs::kProfileUsingDefaultName
,
507 base::Bind(&ProfileImpl::UpdateProfileNameCache
,
508 base::Unretained(this)));
509 pref_change_registrar_
.Add(
511 base::Bind(&ProfileImpl::UpdateProfileNameCache
,
512 base::Unretained(this)));
514 pref_change_registrar_
.Add(
515 prefs::kForceEphemeralProfiles
,
516 base::Bind(&ProfileImpl::UpdateProfileIsEphemeralCache
,
517 base::Unretained(this)));
519 // It would be nice to use PathService for fetching this directory, but
520 // the cache directory depends on the profile directory, which isn't available
522 chrome::GetUserCacheDirectory(path_
, &base_cache_path_
);
523 // Always create the cache directory asynchronously.
524 scoped_refptr
<base::SequencedTaskRunner
> sequenced_task_runner
=
525 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_
,
526 BrowserThread::GetBlockingPool());
527 CreateProfileDirectory(sequenced_task_runner
.get(), base_cache_path_
);
529 // Initialize components that depend on the current value.
530 UpdateProfileSupervisedUserIdCache();
531 UpdateProfileIsEphemeralCache();
532 GAIAInfoUpdateServiceFactory::GetForProfile(this);
534 PrefService
* local_state
= g_browser_process
->local_state();
535 ssl_config_service_manager_
.reset(
536 SSLConfigServiceManager::CreateDefaultManager(local_state
));
538 #if defined(ENABLE_BACKGROUND)
539 // Initialize the BackgroundModeManager - this has to be done here before
540 // InitExtensions() is called because it relies on receiving notifications
541 // when extensions are loaded. BackgroundModeManager is not needed under
542 // ChromeOS because Chrome is always running, no need for special keep-alive
543 // or launch-on-startup support unless kKeepAliveForTest is set.
544 bool init_background_mode_manager
= true;
545 #if defined(OS_CHROMEOS)
546 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
547 switches::kKeepAliveForTest
))
548 init_background_mode_manager
= false;
550 if (init_background_mode_manager
) {
551 if (g_browser_process
->background_mode_manager())
552 g_browser_process
->background_mode_manager()->RegisterProfile(this);
554 #endif // defined(ENABLE_BACKGROUND)
556 base::FilePath cookie_path
= GetPath();
557 cookie_path
= cookie_path
.Append(chrome::kCookieFilename
);
558 base::FilePath channel_id_path
= GetPath();
559 channel_id_path
= channel_id_path
.Append(chrome::kChannelIDFilename
);
560 base::FilePath cache_path
= base_cache_path_
;
562 GetCacheParameters(false, &cache_path
, &cache_max_size
);
563 cache_path
= GetCachePath(cache_path
);
565 base::FilePath media_cache_path
= base_cache_path_
;
566 int media_cache_max_size
;
567 GetCacheParameters(true, &media_cache_path
, &media_cache_max_size
);
568 media_cache_path
= GetMediaCachePath(media_cache_path
);
570 base::FilePath extensions_cookie_path
= GetPath();
571 extensions_cookie_path
=
572 extensions_cookie_path
.Append(chrome::kExtensionsCookieFilename
);
574 #if defined(OS_ANDROID)
575 SessionStartupPref::Type startup_pref_type
=
576 SessionStartupPref::GetDefaultStartupType();
578 SessionStartupPref::Type startup_pref_type
=
579 StartupBrowserCreator::GetSessionStartupPref(
580 *base::CommandLine::ForCurrentProcess(), this).type
;
582 content::CookieStoreConfig::SessionCookieMode session_cookie_mode
=
583 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES
;
584 if (GetLastSessionExitType() == Profile::EXIT_CRASHED
||
585 startup_pref_type
== SessionStartupPref::LAST
) {
586 session_cookie_mode
= content::CookieStoreConfig::RESTORED_SESSION_COOKIES
;
589 // Make sure we initialize the ProfileIOData after everything else has been
590 // initialized that we might be reading from the IO thread.
592 io_data_
.Init(cookie_path
, channel_id_path
, cache_path
,
593 cache_max_size
, media_cache_path
, media_cache_max_size
,
594 extensions_cookie_path
, GetPath(), predictor_
,
595 session_cookie_mode
, GetSpecialStoragePolicy(),
596 CreateDomainReliabilityMonitor(local_state
));
598 #if defined(ENABLE_PLUGINS)
599 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
600 PluginPrefs::GetForProfile(this).get(),
601 io_data_
.GetResourceContextNoInit());
604 // Delay README creation to not impact startup performance.
605 BrowserThread::PostDelayedTask(
606 BrowserThread::FILE, FROM_HERE
,
607 base::Bind(&EnsureReadmeFile
, GetPath()),
608 base::TimeDelta::FromMilliseconds(create_readme_delay_ms
));
610 TRACE_EVENT0("browser", "ProfileImpl::SetSaveSessionStorageOnDisk");
611 content::BrowserContext::GetDefaultStoragePartition(this)->
612 GetDOMStorageContext()->SetSaveSessionStorageOnDisk();
614 // TODO(wjmaclean): Remove this. crbug.com/420643
615 chrome::MigrateProfileZoomLevelPrefs(this);
617 // The DomDistillerViewerSource is not a normal WebUI so it must be registered
618 // as a URLDataSource early.
619 RegisterDomDistillerViewerSource(this);
621 #if defined(OS_CHROMEOS)
622 if (chromeos::UserSessionManager::GetInstance()
623 ->RestartToApplyPerSessionFlagsIfNeed(this, true)) {
629 TRACE_EVENT0("browser", "ProfileImpl::DoFileInit:DelegateOnProfileCreated")
630 delegate_
->OnProfileCreated(this, true, IsNewProfile());
634 SCOPED_UMA_HISTOGRAM_TIMER("Profile.NotifyProfileCreatedTime");
635 content::NotificationService::current()->Notify(
636 chrome::NOTIFICATION_PROFILE_CREATED
,
637 content::Source
<Profile
>(this),
638 content::NotificationService::NoDetails());
640 #if !defined(OS_CHROMEOS)
641 // Listen for bookmark model load, to bootstrap the sync service.
642 // On CrOS sync service will be initialized after sign in.
643 BookmarkModel
* model
= BookmarkModelFactory::GetForProfile(this);
644 model
->AddObserver(new BookmarkModelLoadedObserver(this));
647 PushMessagingServiceImpl::InitializeForProfile(this);
649 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS)
650 signin_ui_util::InitializePrefsForProfile(this);
654 base::FilePath
ProfileImpl::last_selected_directory() {
655 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory
);
658 void ProfileImpl::set_last_selected_directory(const base::FilePath
& path
) {
659 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory
, path
);
662 ProfileImpl::~ProfileImpl() {
663 MaybeSendDestroyedNotification();
665 bool prefs_loaded
= prefs_
->GetInitializationStatus() !=
666 PrefService::INITIALIZATION_STATUS_WAITING
;
668 #if defined(ENABLE_SESSION_SERVICE)
669 StopCreateSessionServiceTimer();
672 // Remove pref observers
673 pref_change_registrar_
.RemoveAll();
675 #if defined(ENABLE_PLUGINS)
676 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
677 io_data_
.GetResourceContextNoInit());
680 // Destroy OTR profile and its profile services first.
681 if (off_the_record_profile_
) {
682 ProfileDestroyer::DestroyOffTheRecordProfileNow(
683 off_the_record_profile_
.get());
685 #if defined(ENABLE_EXTENSIONS)
686 ExtensionPrefValueMapFactory::GetForBrowserContext(this)->
687 ClearAllIncognitoSessionOnlyPreferences();
691 BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
694 if (pref_proxy_config_tracker_
)
695 pref_proxy_config_tracker_
->DetachFromPrefService();
697 if (host_content_settings_map_
.get())
698 host_content_settings_map_
->ShutdownOnUIThread();
700 // This causes the Preferences file to be written to disk.
702 SetExitType(EXIT_NORMAL
);
705 std::string
ProfileImpl::GetProfileUserName() const {
706 const SigninManagerBase
* signin_manager
=
707 SigninManagerFactory::GetForProfileIfExists(this);
709 return signin_manager
->GetAuthenticatedUsername();
711 return std::string();
714 Profile::ProfileType
ProfileImpl::GetProfileType() const {
715 return REGULAR_PROFILE
;
718 scoped_ptr
<content::ZoomLevelDelegate
>
719 ProfileImpl::CreateZoomLevelDelegate(const base::FilePath
& partition_path
) {
720 return make_scoped_ptr(new chrome::ChromeZoomLevelPrefs(
721 GetPrefs(), GetPath(), partition_path
,
722 ui_zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
725 base::FilePath
ProfileImpl::GetPath() const {
729 scoped_refptr
<base::SequencedTaskRunner
> ProfileImpl::GetIOTaskRunner() {
730 return JsonPrefStore::GetTaskRunnerForFile(
731 GetPath(), BrowserThread::GetBlockingPool());
734 bool ProfileImpl::IsOffTheRecord() const {
738 Profile
* ProfileImpl::GetOffTheRecordProfile() {
739 if (!off_the_record_profile_
) {
740 scoped_ptr
<Profile
> p(CreateOffTheRecordProfile());
741 off_the_record_profile_
.swap(p
);
743 content::NotificationService::current()->Notify(
744 chrome::NOTIFICATION_PROFILE_CREATED
,
745 content::Source
<Profile
>(off_the_record_profile_
.get()),
746 content::NotificationService::NoDetails());
748 return off_the_record_profile_
.get();
751 void ProfileImpl::DestroyOffTheRecordProfile() {
752 off_the_record_profile_
.reset();
753 #if defined(ENABLE_EXTENSIONS)
754 ExtensionPrefValueMapFactory::GetForBrowserContext(this)->
755 ClearAllIncognitoSessionOnlyPreferences();
759 bool ProfileImpl::HasOffTheRecordProfile() {
760 return off_the_record_profile_
.get() != NULL
;
763 Profile
* ProfileImpl::GetOriginalProfile() {
767 bool ProfileImpl::IsSupervised() {
768 return !GetPrefs()->GetString(prefs::kSupervisedUserId
).empty();
771 bool ProfileImpl::IsChild() {
772 #if defined(ENABLE_SUPERVISED_USERS)
773 return GetPrefs()->GetString(prefs::kSupervisedUserId
) ==
774 supervised_users::kChildAccountSUID
;
780 bool ProfileImpl::IsLegacySupervised() {
781 return IsSupervised() && !IsChild();
784 ExtensionSpecialStoragePolicy
*
785 ProfileImpl::GetExtensionSpecialStoragePolicy() {
786 #if defined(ENABLE_EXTENSIONS)
787 if (!extension_special_storage_policy_
.get()) {
788 TRACE_EVENT0("browser", "ProfileImpl::GetExtensionSpecialStoragePolicy")
789 extension_special_storage_policy_
= new ExtensionSpecialStoragePolicy(
790 CookieSettings::Factory::GetForProfile(this).get());
792 return extension_special_storage_policy_
.get();
798 void ProfileImpl::OnLocaleReady() {
799 TRACE_EVENT0("browser", "ProfileImpl::OnLocaleReady");
800 SCOPED_UMA_HISTOGRAM_TIMER("Profile.OnLocaleReadyTime");
801 // Migrate obsolete prefs.
802 if (g_browser_process
->local_state())
803 chrome::MigrateObsoleteBrowserPrefs(this, g_browser_process
->local_state());
804 chrome::MigrateObsoleteProfilePrefs(this);
806 // |kSessionExitType| was added after |kSessionExitedCleanly|. If the pref
807 // value is empty fallback to checking for |kSessionExitedCleanly|.
808 const std::string
exit_type_pref_value(
809 prefs_
->GetString(prefs::kSessionExitType
));
810 if (exit_type_pref_value
.empty()) {
811 last_session_exit_type_
=
812 prefs_
->GetBoolean(prefs::kSessionExitedCleanly
) ?
813 EXIT_NORMAL
: EXIT_CRASHED
;
815 last_session_exit_type_
=
816 SessionTypePrefValueToExitType(exit_type_pref_value
);
818 // Mark the session as open.
819 prefs_
->SetString(prefs::kSessionExitType
, kPrefExitTypeCrashed
);
820 // Force this to true in case we fallback and use it.
821 // TODO(sky): remove this in a couple of releases (m28ish).
822 prefs_
->SetBoolean(prefs::kSessionExitedCleanly
, true);
824 #if defined(SAFE_BROWSING_DB_REMOTE)
825 // Hardcode this pref on this build of Android until the UX is developed.
826 // http://crbug.com/481558
827 prefs_
->SetBoolean(prefs::kSafeBrowsingEnabled
, true);
830 g_browser_process
->profile_manager()->InitProfileUserPrefs(this);
833 SCOPED_UMA_HISTOGRAM_TIMER("Profile.CreateBrowserContextServicesTime");
834 BrowserContextDependencyManager::GetInstance()->
835 CreateBrowserContextServices(this);
838 DCHECK(!net_pref_observer_
);
840 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded:NetPrefObserver")
841 net_pref_observer_
.reset(new NetPrefObserver(prefs_
.get()));
844 chrome_prefs::SchedulePrefsFilePathVerification(path_
);
846 ChromeVersionService::OnProfileLoaded(prefs_
.get(), IsNewProfile());
850 void ProfileImpl::OnPrefsLoaded(CreateMode create_mode
, bool success
) {
851 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded");
854 delegate_
->OnProfileCreated(this, false, false);
858 #if defined(OS_CHROMEOS)
859 if (create_mode
== CREATE_MODE_SYNCHRONOUS
) {
860 // Synchronous create mode implies that either it is restart after crash,
861 // or we are in tests. In both cases the first loaded locale is correct.
864 chromeos::UserSessionManager::GetInstance()->RespectLocalePreferenceWrapper(
865 this, base::Bind(&ProfileImpl::OnLocaleReady
, base::Unretained(this)));
872 bool ProfileImpl::WasCreatedByVersionOrLater(const std::string
& version
) {
873 Version
profile_version(ChromeVersionService::GetVersion(prefs_
.get()));
874 Version
arg_version(version
);
875 return (profile_version
.CompareTo(arg_version
) >= 0);
878 void ProfileImpl::SetExitType(ExitType exit_type
) {
879 #if defined(OS_CHROMEOS)
880 if (chromeos::ProfileHelper::IsSigninProfile(this))
885 ExitType current_exit_type
= SessionTypePrefValueToExitType(
886 prefs_
->GetString(prefs::kSessionExitType
));
887 // This may be invoked multiple times during shutdown. Only persist the value
888 // first passed in (unless it's a reset to the crash state, which happens when
889 // foregrounding the app on mobile).
890 if (exit_type
== EXIT_CRASHED
|| current_exit_type
== EXIT_CRASHED
) {
891 prefs_
->SetString(prefs::kSessionExitType
,
892 ExitTypeToSessionTypePrefValue(exit_type
));
896 Profile::ExitType
ProfileImpl::GetLastSessionExitType() {
897 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
898 // it to be set by asking for the prefs.
900 return last_session_exit_type_
;
903 PrefService
* ProfileImpl::GetPrefs() {
904 return const_cast<PrefService
*>(
905 static_cast<const ProfileImpl
*>(this)->GetPrefs());
908 const PrefService
* ProfileImpl::GetPrefs() const {
909 DCHECK(prefs_
); // Should explicitly be initialized.
913 chrome::ChromeZoomLevelPrefs
* ProfileImpl::GetZoomLevelPrefs() {
914 return static_cast<chrome::ChromeZoomLevelPrefs
*>(
915 GetDefaultStoragePartition(this)->GetZoomLevelDelegate());
918 PrefService
* ProfileImpl::GetOffTheRecordPrefs() {
921 // The new ExtensionPrefStore is ref_counted and the new PrefService
922 // stores a reference so that we do not leak memory here.
923 otr_prefs_
.reset(prefs_
->CreateIncognitoPrefService(
924 CreateExtensionPrefStore(this, true)));
926 return otr_prefs_
.get();
929 net::URLRequestContextGetter
* ProfileImpl::CreateRequestContext(
930 content::ProtocolHandlerMap
* protocol_handlers
,
931 content::URLRequestInterceptorScopedVector request_interceptors
) {
932 return io_data_
.CreateMainRequestContextGetter(
934 request_interceptors
.Pass(),
935 g_browser_process
->local_state(),
936 g_browser_process
->io_thread()).get();
939 net::URLRequestContextGetter
* ProfileImpl::GetRequestContext() {
940 return GetDefaultStoragePartition(this)->GetURLRequestContext();
943 net::URLRequestContextGetter
* ProfileImpl::GetRequestContextForRenderProcess(
944 int renderer_child_id
) {
945 content::RenderProcessHost
* rph
= content::RenderProcessHost::FromID(
948 return rph
->GetStoragePartition()->GetURLRequestContext();
951 net::URLRequestContextGetter
* ProfileImpl::GetMediaRequestContext() {
952 // Return the default media context.
953 return io_data_
.GetMediaRequestContextGetter().get();
956 net::URLRequestContextGetter
*
957 ProfileImpl::GetMediaRequestContextForRenderProcess(
958 int renderer_child_id
) {
959 content::RenderProcessHost
* rph
= content::RenderProcessHost::FromID(
961 content::StoragePartition
* storage_partition
= rph
->GetStoragePartition();
963 return storage_partition
->GetMediaURLRequestContext();
966 net::URLRequestContextGetter
*
967 ProfileImpl::GetMediaRequestContextForStoragePartition(
968 const base::FilePath
& partition_path
,
971 .GetIsolatedMediaRequestContextGetter(partition_path
, in_memory
).get();
974 content::ResourceContext
* ProfileImpl::GetResourceContext() {
975 return io_data_
.GetResourceContext();
978 net::URLRequestContextGetter
* ProfileImpl::GetRequestContextForExtensions() {
979 return io_data_
.GetExtensionsRequestContextGetter().get();
982 net::URLRequestContextGetter
*
983 ProfileImpl::CreateRequestContextForStoragePartition(
984 const base::FilePath
& partition_path
,
986 content::ProtocolHandlerMap
* protocol_handlers
,
987 content::URLRequestInterceptorScopedVector request_interceptors
) {
988 return io_data_
.CreateIsolatedAppRequestContextGetter(
992 request_interceptors
.Pass()).get();
995 net::SSLConfigService
* ProfileImpl::GetSSLConfigService() {
996 // If ssl_config_service_manager_ is null, this typically means that some
997 // KeyedService is trying to create a RequestContext at startup,
998 // but SSLConfigServiceManager is not initialized until DoFinalInit() which is
999 // invoked after all KeyedServices have been initialized (see
1000 // http://crbug.com/171406).
1001 DCHECK(ssl_config_service_manager_
) <<
1002 "SSLConfigServiceManager is not initialized yet";
1003 return ssl_config_service_manager_
->Get();
1006 HostContentSettingsMap
* ProfileImpl::GetHostContentSettingsMap() {
1007 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1008 if (!host_content_settings_map_
.get()) {
1009 host_content_settings_map_
= new HostContentSettingsMap(GetPrefs(), false);
1010 #if defined(ENABLE_SUPERVISED_USERS)
1011 SupervisedUserSettingsService
* supervised_user_settings
=
1012 SupervisedUserSettingsServiceFactory::GetForProfile(this);
1013 scoped_ptr
<content_settings::SupervisedProvider
> supervised_provider(
1014 new content_settings::SupervisedProvider(supervised_user_settings
));
1015 host_content_settings_map_
->RegisterProvider(
1016 HostContentSettingsMap::SUPERVISED_PROVIDER
,
1017 supervised_provider
.Pass());
1020 return host_content_settings_map_
.get();
1023 content::BrowserPluginGuestManager
* ProfileImpl::GetGuestManager() {
1024 #if defined(ENABLE_EXTENSIONS)
1025 return guest_view::GuestViewManager::FromBrowserContext(this);
1031 DownloadManagerDelegate
* ProfileImpl::GetDownloadManagerDelegate() {
1032 return DownloadServiceFactory::GetForBrowserContext(this)->
1033 GetDownloadManagerDelegate();
1036 storage::SpecialStoragePolicy
* ProfileImpl::GetSpecialStoragePolicy() {
1037 #if defined(ENABLE_EXTENSIONS)
1038 return GetExtensionSpecialStoragePolicy();
1044 content::PushMessagingService
* ProfileImpl::GetPushMessagingService() {
1045 return PushMessagingServiceFactory::GetForProfile(this);
1048 content::SSLHostStateDelegate
* ProfileImpl::GetSSLHostStateDelegate() {
1049 return ChromeSSLHostStateDelegateFactory::GetForProfile(this);
1052 // TODO(mlamouri): we should all these BrowserContext implementation to Profile
1053 // instead of repeating them inside all Profile implementations.
1054 content::PermissionManager
* ProfileImpl::GetPermissionManager() {
1055 return PermissionManagerFactory::GetForProfile(this);
1058 bool ProfileImpl::IsSameProfile(Profile
* profile
) {
1059 if (profile
== static_cast<Profile
*>(this))
1061 Profile
* otr_profile
= off_the_record_profile_
.get();
1062 return otr_profile
&& profile
== otr_profile
;
1065 Time
ProfileImpl::GetStartTime() const {
1069 #if defined(ENABLE_SESSION_SERVICE)
1070 void ProfileImpl::StopCreateSessionServiceTimer() {
1071 create_session_service_timer_
.Stop();
1074 void ProfileImpl::EnsureSessionServiceCreated() {
1075 SessionServiceFactory::GetForProfile(this);
1079 #if defined(OS_CHROMEOS)
1080 void ProfileImpl::ChangeAppLocale(
1081 const std::string
& new_locale
, AppLocaleChangedVia via
) {
1082 if (new_locale
.empty()) {
1086 PrefService
* local_state
= g_browser_process
->local_state();
1087 DCHECK(local_state
);
1088 if (local_state
->IsManagedPreference(prefs::kApplicationLocale
))
1090 std::string pref_locale
= GetPrefs()->GetString(prefs::kApplicationLocale
);
1091 bool do_update_pref
= true;
1093 case APP_LOCALE_CHANGED_VIA_SETTINGS
:
1094 case APP_LOCALE_CHANGED_VIA_REVERT
: {
1095 // We keep kApplicationLocaleBackup value as a reference. In case value
1096 // of kApplicationLocale preference would change due to sync from other
1097 // device then kApplicationLocaleBackup value will trigger and allow us to
1098 // show notification about automatic locale change in LocaleChangeGuard.
1099 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, new_locale
);
1100 GetPrefs()->ClearPref(prefs::kApplicationLocaleAccepted
);
1101 // We maintain kApplicationLocale property in both a global storage
1102 // and user's profile. Global property determines locale of login screen,
1103 // while user's profile determines his personal locale preference.
1106 case APP_LOCALE_CHANGED_VIA_LOGIN
:
1107 case APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN
: {
1108 if (!pref_locale
.empty()) {
1109 DCHECK(pref_locale
== new_locale
);
1110 std::string accepted_locale
=
1111 GetPrefs()->GetString(prefs::kApplicationLocaleAccepted
);
1112 if (accepted_locale
== new_locale
) {
1113 // If locale is accepted then we do not want to show LocaleChange
1114 // notification. This notification is triggered by different values
1115 // of kApplicationLocaleBackup and kApplicationLocale preferences,
1116 // so make them identical.
1117 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, new_locale
);
1119 // Back up locale of login screen.
1120 std::string cur_locale
= g_browser_process
->GetApplicationLocale();
1121 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, cur_locale
);
1122 if (locale_change_guard_
== NULL
)
1123 locale_change_guard_
.reset(new chromeos::LocaleChangeGuard(this));
1124 locale_change_guard_
->PrepareChangingLocale(cur_locale
, new_locale
);
1127 std::string cur_locale
= g_browser_process
->GetApplicationLocale();
1128 std::string backup_locale
=
1129 GetPrefs()->GetString(prefs::kApplicationLocaleBackup
);
1130 // Profile synchronization takes time and is not completed at that
1131 // moment at first login. So we initialize locale preference in steps:
1132 // (1) first save it to temporary backup;
1133 // (2) on next login we assume that synchronization is already completed
1134 // and we may finalize initialization.
1135 GetPrefs()->SetString(prefs::kApplicationLocaleBackup
, cur_locale
);
1136 if (!new_locale
.empty())
1137 GetPrefs()->SetString(prefs::kApplicationLocale
, new_locale
);
1138 else if (!backup_locale
.empty())
1139 GetPrefs()->SetString(prefs::kApplicationLocale
, backup_locale
);
1140 do_update_pref
= false;
1144 case APP_LOCALE_CHANGED_VIA_UNKNOWN
:
1151 GetPrefs()->SetString(prefs::kApplicationLocale
, new_locale
);
1152 if (via
!= APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN
)
1153 local_state
->SetString(prefs::kApplicationLocale
, new_locale
);
1155 if (user_manager::UserManager::Get()->GetOwnerEmail() ==
1156 chromeos::ProfileHelper::Get()->GetUserByProfile(this)->email())
1157 local_state
->SetString(prefs::kOwnerLocale
, new_locale
);
1160 void ProfileImpl::OnLogin() {
1161 if (locale_change_guard_
== NULL
)
1162 locale_change_guard_
.reset(new chromeos::LocaleChangeGuard(this));
1163 locale_change_guard_
->OnLogin();
1166 void ProfileImpl::InitChromeOSPreferences() {
1167 chromeos_preferences_
.reset(new chromeos::Preferences());
1168 chromeos_preferences_
->Init(
1169 this, chromeos::ProfileHelper::Get()->GetUserByProfile(this));
1172 #endif // defined(OS_CHROMEOS)
1174 PrefProxyConfigTracker
* ProfileImpl::GetProxyConfigTracker() {
1175 if (!pref_proxy_config_tracker_
)
1176 pref_proxy_config_tracker_
.reset(CreateProxyConfigTracker());
1177 return pref_proxy_config_tracker_
.get();
1180 chrome_browser_net::Predictor
* ProfileImpl::GetNetworkPredictor() {
1184 DevToolsNetworkController
* ProfileImpl::GetDevToolsNetworkController() {
1185 return io_data_
.GetDevToolsNetworkController();
1188 void ProfileImpl::ClearNetworkingHistorySince(
1190 const base::Closure
& completion
) {
1191 io_data_
.ClearNetworkingHistorySince(time
, completion
);
1194 GURL
ProfileImpl::GetHomePage() {
1195 // --homepage overrides any preferences.
1196 const base::CommandLine
& command_line
=
1197 *base::CommandLine::ForCurrentProcess();
1198 if (command_line
.HasSwitch(switches::kHomePage
)) {
1199 // TODO(evanm): clean up usage of DIR_CURRENT.
1200 // http://code.google.com/p/chromium/issues/detail?id=60630
1201 // For now, allow this code to call getcwd().
1202 base::ThreadRestrictions::ScopedAllowIO allow_io
;
1204 base::FilePath browser_directory
;
1205 PathService::Get(base::DIR_CURRENT
, &browser_directory
);
1206 GURL
home_page(url_fixer::FixupRelativeFile(
1208 command_line
.GetSwitchValuePath(switches::kHomePage
)));
1209 if (home_page
.is_valid())
1213 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage
))
1214 return GURL(chrome::kChromeUINewTabURL
);
1215 GURL
home_page(url_fixer::FixupURL(GetPrefs()->GetString(prefs::kHomePage
),
1217 if (!home_page
.is_valid())
1218 return GURL(chrome::kChromeUINewTabURL
);
1222 void ProfileImpl::UpdateProfileSupervisedUserIdCache() {
1223 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1224 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1225 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1226 if (index
!= std::string::npos
) {
1227 std::string supervised_user_id
=
1228 GetPrefs()->GetString(prefs::kSupervisedUserId
);
1229 cache
.SetSupervisedUserIdOfProfileAtIndex(index
, supervised_user_id
);
1230 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager
);
1234 void ProfileImpl::UpdateProfileNameCache() {
1235 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1236 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1237 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1238 if (index
!= std::string::npos
) {
1239 std::string profile_name
=
1240 GetPrefs()->GetString(prefs::kProfileName
);
1241 cache
.SetNameOfProfileAtIndex(index
, base::UTF8ToUTF16(profile_name
));
1243 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName
);
1244 cache
.SetProfileIsUsingDefaultNameAtIndex(index
, default_name
);
1248 void ProfileImpl::UpdateProfileAvatarCache() {
1249 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1250 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1251 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1252 if (index
!= std::string::npos
) {
1253 size_t avatar_index
=
1254 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex
);
1255 cache
.SetAvatarIconOfProfileAtIndex(index
, avatar_index
);
1256 bool default_avatar
=
1257 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar
);
1258 cache
.SetProfileIsUsingDefaultAvatarAtIndex(index
, default_avatar
);
1260 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar
);
1261 cache
.SetIsUsingGAIAPictureOfProfileAtIndex(index
, gaia_avatar
);
1265 void ProfileImpl::UpdateProfileIsEphemeralCache() {
1266 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1267 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1268 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1269 if (index
!= std::string::npos
) {
1270 bool is_ephemeral
= GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles
);
1271 cache
.SetProfileIsEphemeralAtIndex(index
, is_ephemeral
);
1275 // Gets the cache parameters from the command line. If |is_media_context| is
1276 // set to true then settings for the media context type is what we need,
1277 // |cache_path| will be set to the user provided path, or will not be touched if
1278 // there is not an argument. |max_size| will be the user provided value or zero
1280 void ProfileImpl::GetCacheParameters(bool is_media_context
,
1281 base::FilePath
* cache_path
,
1285 base::FilePath
path(prefs_
->GetFilePath(prefs::kDiskCacheDir
));
1288 *max_size
= is_media_context
? prefs_
->GetInteger(prefs::kMediaCacheSize
) :
1289 prefs_
->GetInteger(prefs::kDiskCacheSize
);
1292 PrefProxyConfigTracker
* ProfileImpl::CreateProxyConfigTracker() {
1293 #if defined(OS_CHROMEOS)
1294 if (chromeos::ProfileHelper::IsSigninProfile(this)) {
1295 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
1296 g_browser_process
->local_state());
1298 #endif // defined(OS_CHROMEOS)
1299 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
1300 GetPrefs(), g_browser_process
->local_state());
1303 scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
1304 ProfileImpl::CreateDomainReliabilityMonitor(PrefService
* local_state
) {
1305 domain_reliability::DomainReliabilityService
* service
=
1306 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1307 GetForBrowserContext(this);
1309 return scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>();
1311 return service
->CreateMonitor(
1312 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));