1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/profiles/profile_impl.h"
10 #include "base/callback.h"
11 #include "base/command_line.h"
12 #include "base/compiler_specific.h"
13 #include "base/environment.h"
14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/metrics/histogram_macros.h"
19 #include "base/path_service.h"
20 #include "base/prefs/json_pref_store.h"
21 #include "base/prefs/scoped_user_pref_update.h"
22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "base/synchronization/waitable_event.h"
27 #include "base/threading/sequenced_worker_pool.h"
28 #include "base/threading/thread_restrictions.h"
29 #include "base/trace_event/trace_event.h"
30 #include "base/version.h"
31 #include "chrome/browser/background/background_contents_service_factory.h"
32 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
33 #include "chrome/browser/browser_process.h"
34 #include "chrome/browser/chrome_notification_types.h"
35 #include "chrome/browser/content_settings/cookie_settings_factory.h"
36 #include "chrome/browser/dom_distiller/profile_utils.h"
37 #include "chrome/browser/domain_reliability/service_factory.h"
38 #include "chrome/browser/download/chrome_download_manager_delegate.h"
39 #include "chrome/browser/download/download_service.h"
40 #include "chrome/browser/download/download_service_factory.h"
41 #include "chrome/browser/net/net_pref_observer.h"
42 #include "chrome/browser/net/predictor.h"
43 #include "chrome/browser/net/pref_proxy_config_tracker.h"
44 #include "chrome/browser/net/proxy_service_factory.h"
45 #include "chrome/browser/net/ssl_config_service_manager.h"
46 #include "chrome/browser/permissions/permission_manager.h"
47 #include "chrome/browser/permissions/permission_manager_factory.h"
48 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
49 #include "chrome/browser/plugins/plugin_prefs.h"
50 #include "chrome/browser/policy/profile_policy_connector.h"
51 #include "chrome/browser/policy/profile_policy_connector_factory.h"
52 #include "chrome/browser/prefs/browser_prefs.h"
53 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
54 #include "chrome/browser/prefs/pref_service_syncable.h"
55 #include "chrome/browser/prerender/prerender_manager_factory.h"
56 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
57 #include "chrome/browser/profiles/chrome_version_service.h"
58 #include "chrome/browser/profiles/gaia_info_update_service_factory.h"
59 #include "chrome/browser/profiles/profile_destroyer.h"
60 #include "chrome/browser/profiles/profile_info_cache.h"
61 #include "chrome/browser/profiles/profile_manager.h"
62 #include "chrome/browser/profiles/profile_metrics.h"
63 #include "chrome/browser/push_messaging/push_messaging_service_factory.h"
64 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
65 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
66 #include "chrome/browser/services/gcm/gcm_profile_service.h"
67 #include "chrome/browser/sessions/session_service_factory.h"
68 #include "chrome/browser/signin/signin_manager_factory.h"
69 #include "chrome/browser/signin/signin_ui_util.h"
70 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
71 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
72 #include "chrome/browser/ui/startup/startup_browser_creator.h"
73 #include "chrome/common/chrome_constants.h"
74 #include "chrome/common/chrome_paths_internal.h"
75 #include "chrome/common/chrome_switches.h"
76 #include "chrome/common/pref_names.h"
77 #include "chrome/common/url_constants.h"
78 #include "chrome/grit/chromium_strings.h"
79 #include "components/bookmarks/browser/bookmark_model.h"
80 #include "components/content_settings/core/browser/cookie_settings.h"
81 #include "components/content_settings/core/browser/host_content_settings_map.h"
82 #include "components/domain_reliability/monitor.h"
83 #include "components/domain_reliability/service.h"
84 #include "components/keyed_service/content/browser_context_dependency_manager.h"
85 #include "components/metrics/metrics_service.h"
86 #include "components/omnibox/browser/autocomplete_classifier.h"
87 #include "components/omnibox/browser/shortcuts_backend.h"
88 #include "components/pref_registry/pref_registry_syncable.h"
89 #include "components/signin/core/browser/signin_manager.h"
90 #include "components/ui/zoom/zoom_event_manager.h"
91 #include "components/url_formatter/url_fixer.h"
92 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.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 void CreateProfileReadme(const base::FilePath
& profile_path
) {
180 base::ThreadRestrictions::AssertIOAllowed();
181 base::FilePath readme_path
= profile_path
.Append(chrome::kReadmeFilename
);
182 std::string product_name
= l10n_util::GetStringUTF8(IDS_PRODUCT_NAME
);
183 std::string readme_text
= base::StringPrintf(
184 kReadmeText
, product_name
.c_str(), product_name
.c_str());
185 if (base::WriteFile(readme_path
, readme_text
.data(), readme_text
.size()) ==
187 LOG(ERROR
) << "Could not create README file.";
191 // Helper method needed because PostTask cannot currently take a Callback
192 // function with non-void return type.
193 void CreateDirectoryAndSignal(const base::FilePath
& path
,
194 base::WaitableEvent
* done_creating
,
195 bool create_readme
) {
196 // If the readme exists, the profile directory must also already exist.
197 base::FilePath readme_path
= path
.Append(chrome::kReadmeFilename
);
198 if (base::PathExists(readme_path
)) {
199 done_creating
->Signal();
203 DVLOG(1) << "Creating directory " << path
.value();
204 if (base::CreateDirectory(path
) && create_readme
)
205 CreateProfileReadme(path
);
206 done_creating
->Signal();
209 // Task that blocks the FILE thread until CreateDirectoryAndSignal() finishes on
210 // blocking I/O pool.
211 void BlockFileThreadOnDirectoryCreate(base::WaitableEvent
* done_creating
) {
212 done_creating
->Wait();
215 // Initiates creation of profile directory on |sequenced_task_runner| and
216 // ensures that FILE thread is blocked until that operation finishes. If
217 // |create_readme| is true, the profile README will be created in the profile
219 void CreateProfileDirectory(base::SequencedTaskRunner
* sequenced_task_runner
,
220 const base::FilePath
& path
,
221 bool create_readme
) {
222 base::WaitableEvent
* done_creating
= new base::WaitableEvent(false, false);
223 sequenced_task_runner
->PostTask(
224 FROM_HERE
, base::Bind(&CreateDirectoryAndSignal
, path
, done_creating
,
226 // Block the FILE thread until directory is created on I/O pool to make sure
227 // that we don't attempt any operation until that part completes.
228 BrowserThread::PostTask(
229 BrowserThread::FILE, FROM_HERE
,
230 base::Bind(&BlockFileThreadOnDirectoryCreate
,
231 base::Owned(done_creating
)));
234 base::FilePath
GetCachePath(const base::FilePath
& base
) {
235 return base
.Append(chrome::kCacheDirname
);
238 base::FilePath
GetMediaCachePath(const base::FilePath
& base
) {
239 return base
.Append(chrome::kMediaCacheDirname
);
242 // Converts the kSessionExitedCleanly pref to the corresponding EXIT_TYPE.
243 Profile::ExitType
SessionTypePrefValueToExitType(const std::string
& value
) {
244 if (value
== kPrefExitTypeSessionEnded
)
245 return Profile::EXIT_SESSION_ENDED
;
246 if (value
== kPrefExitTypeCrashed
)
247 return Profile::EXIT_CRASHED
;
248 return Profile::EXIT_NORMAL
;
251 // Converts an ExitType into a string that is written to prefs.
252 std::string
ExitTypeToSessionTypePrefValue(Profile::ExitType type
) {
254 case Profile::EXIT_NORMAL
:
255 return ProfileImpl::kPrefExitTypeNormal
;
256 case Profile::EXIT_SESSION_ENDED
:
257 return kPrefExitTypeSessionEnded
;
258 case Profile::EXIT_CRASHED
:
259 return kPrefExitTypeCrashed
;
262 return std::string();
265 PrefStore
* CreateExtensionPrefStore(Profile
* profile
,
266 bool incognito_pref_store
) {
267 #if defined(ENABLE_EXTENSIONS)
268 return new ExtensionPrefStore(
269 ExtensionPrefValueMapFactory::GetForBrowserContext(profile
),
270 incognito_pref_store
);
279 Profile
* Profile::CreateProfile(const base::FilePath
& path
,
281 CreateMode create_mode
) {
282 TRACE_EVENT1("browser,startup",
283 "Profile::CreateProfile",
285 path
.AsUTF8Unsafe());
287 // Get sequenced task runner for making sure that file operations of
288 // this profile (defined by |path|) are executed in expected order
289 // (what was previously assured by the FILE thread).
290 scoped_refptr
<base::SequencedTaskRunner
> sequenced_task_runner
=
291 JsonPrefStore::GetTaskRunnerForFile(path
,
292 BrowserThread::GetBlockingPool());
293 if (create_mode
== CREATE_MODE_ASYNCHRONOUS
) {
295 CreateProfileDirectory(sequenced_task_runner
.get(), path
, true);
296 } else if (create_mode
== CREATE_MODE_SYNCHRONOUS
) {
297 if (!base::PathExists(path
)) {
298 // TODO(rogerta): http://crbug/160553 - Bad things happen if we can't
299 // write to the profile directory. We should eventually be able to run in
301 if (!base::CreateDirectory(path
))
304 CreateProfileReadme(path
);
310 return new ProfileImpl(
311 path
, delegate
, create_mode
, sequenced_task_runner
.get());
315 const char* const ProfileImpl::kPrefExitTypeNormal
= "Normal";
318 void ProfileImpl::RegisterProfilePrefs(
319 user_prefs::PrefRegistrySyncable
* registry
) {
320 registry
->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled
, false);
321 registry
->RegisterBooleanPref(prefs::kAllowDeletingBrowserHistory
, true);
322 registry
->RegisterBooleanPref(prefs::kSigninAllowed
, true);
323 registry
->RegisterBooleanPref(prefs::kForceGoogleSafeSearch
, false);
324 registry
->RegisterBooleanPref(prefs::kForceYouTubeSafetyMode
, false);
325 registry
->RegisterBooleanPref(prefs::kRecordHistory
, false);
326 registry
->RegisterIntegerPref(
327 prefs::kProfileAvatarIndex
,
329 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
330 // Whether a profile is using an avatar without having explicitely chosen it
331 // (i.e. was assigned by default by legacy profile creation).
332 registry
->RegisterBooleanPref(
333 prefs::kProfileUsingDefaultAvatar
,
335 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
336 registry
->RegisterBooleanPref(
337 prefs::kProfileUsingGAIAAvatar
,
339 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
340 // Whether a profile is using a default avatar name (eg. Pickles or Person 1).
341 registry
->RegisterBooleanPref(
342 prefs::kProfileUsingDefaultName
,
344 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
345 registry
->RegisterStringPref(prefs::kSupervisedUserId
, std::string());
346 registry
->RegisterStringPref(prefs::kProfileName
,
348 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
349 registry
->RegisterStringPref(prefs::kHomePage
,
351 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
352 #if defined(ENABLE_PRINTING)
353 registry
->RegisterBooleanPref(prefs::kPrintingEnabled
, true);
355 registry
->RegisterBooleanPref(prefs::kPrintPreviewDisabled
, false);
356 registry
->RegisterBooleanPref(prefs::kForceEphemeralProfiles
, false);
358 // Initialize the cache prefs.
359 registry
->RegisterFilePathPref(prefs::kDiskCacheDir
, base::FilePath());
360 registry
->RegisterIntegerPref(prefs::kDiskCacheSize
, 0);
361 registry
->RegisterIntegerPref(prefs::kMediaCacheSize
, 0);
363 // Deprecated. Kept around for migration.
364 registry
->RegisterBooleanPref(
365 prefs::kClearSiteDataOnExit
,
367 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
370 ProfileImpl::ProfileImpl(
371 const base::FilePath
& path
,
373 CreateMode create_mode
,
374 base::SequencedTaskRunner
* sequenced_task_runner
)
376 pref_registry_(new user_prefs::PrefRegistrySyncable
),
378 host_content_settings_map_(NULL
),
379 last_session_exit_type_(EXIT_NORMAL
),
380 start_time_(Time::Now()),
383 TRACE_EVENT0("browser,startup", "ProfileImpl::ctor")
384 DCHECK(!path
.empty()) << "Using an empty path will attempt to write " <<
385 "profile files to the root directory!";
387 #if defined(ENABLE_SESSION_SERVICE)
388 create_session_service_timer_
.Start(FROM_HERE
,
389 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS
), this,
390 &ProfileImpl::EnsureSessionServiceCreated
);
393 set_is_guest_profile(path
== ProfileManager::GetGuestProfilePath());
394 set_is_system_profile(path
== ProfileManager::GetSystemProfilePath());
396 // Determine if prefetch is enabled for this profile.
397 // If not profile_manager is present, it means we are in a unittest.
398 const base::CommandLine
* command_line
=
399 base::CommandLine::ForCurrentProcess();
400 predictor_
= chrome_browser_net::Predictor::CreatePredictor(
401 !command_line
->HasSwitch(switches::kDisablePreconnect
),
402 !command_line
->HasSwitch(switches::kDnsPrefetchDisable
),
403 g_browser_process
->profile_manager() == NULL
);
405 // If we are creating the profile synchronously, then we should load the
406 // policy data immediately.
407 bool force_immediate_policy_load
= (create_mode
== CREATE_MODE_SYNCHRONOUS
);
408 #if defined(ENABLE_CONFIGURATION_POLICY)
409 policy::BrowserPolicyConnector
* connector
=
410 g_browser_process
->browser_policy_connector();
411 schema_registry_service_
=
412 policy::SchemaRegistryServiceFactory::CreateForContext(
413 this, connector
->GetChromeSchema(), connector
->GetSchemaRegistry());
414 #if defined(OS_CHROMEOS)
415 cloud_policy_manager_
=
416 policy::UserCloudPolicyManagerFactoryChromeOS::CreateForProfile(
417 this, force_immediate_policy_load
, sequenced_task_runner
);
419 cloud_policy_manager_
=
420 policy::UserCloudPolicyManagerFactory::CreateForOriginalBrowserContext(
422 force_immediate_policy_load
,
423 sequenced_task_runner
,
424 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
425 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));
428 profile_policy_connector_
=
429 policy::ProfilePolicyConnectorFactory::CreateForBrowserContext(
430 this, force_immediate_policy_load
);
432 DCHECK(create_mode
== CREATE_MODE_ASYNCHRONOUS
||
433 create_mode
== CREATE_MODE_SYNCHRONOUS
);
434 bool async_prefs
= create_mode
== CREATE_MODE_ASYNCHRONOUS
;
436 #if defined(OS_CHROMEOS)
437 if (chromeos::ProfileHelper::IsSigninProfile(this))
438 chrome::RegisterLoginProfilePrefs(pref_registry_
.get());
441 chrome::RegisterUserProfilePrefs(pref_registry_
.get());
443 BrowserContextDependencyManager::GetInstance()->
444 RegisterProfilePrefsForServices(this, pref_registry_
.get());
446 SupervisedUserSettingsService
* supervised_user_settings
= nullptr;
447 #if defined(ENABLE_SUPERVISED_USERS)
448 supervised_user_settings
=
449 SupervisedUserSettingsServiceFactory::GetForProfile(this);
450 supervised_user_settings
->Init(
451 path_
, sequenced_task_runner
, create_mode
== CREATE_MODE_SYNCHRONOUS
);
454 scoped_refptr
<SafeBrowsingService
> safe_browsing_service(
455 g_browser_process
->safe_browsing_service());
456 if (safe_browsing_service
.get()) {
457 pref_validation_delegate_
=
458 safe_browsing_service
->CreatePreferenceValidationDelegate(this).Pass();
462 prefs_
= chrome_prefs::CreateProfilePrefs(
464 sequenced_task_runner
,
465 pref_validation_delegate_
.get(),
466 profile_policy_connector_
->policy_service(),
467 supervised_user_settings
,
468 CreateExtensionPrefStore(this, false),
471 // Register on BrowserContext.
472 user_prefs::UserPrefs::Set(this, prefs_
.get());
476 // Wait for the notification that prefs has been loaded
477 // (successfully or not). Note that we can use base::Unretained
478 // because the PrefService is owned by this class and lives on
480 prefs_
->AddPrefInitObserver(base::Bind(
481 &ProfileImpl::OnPrefsLoaded
, base::Unretained(this), create_mode
));
483 // Prefs were loaded synchronously so we can continue directly.
484 OnPrefsLoaded(create_mode
, true);
488 void ProfileImpl::DoFinalInit() {
489 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit")
490 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit");
492 PrefService
* prefs
= GetPrefs();
493 pref_change_registrar_
.Init(prefs
);
494 pref_change_registrar_
.Add(
495 prefs::kSupervisedUserId
,
496 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache
,
497 base::Unretained(this)));
499 // Changes in the profile avatar.
500 pref_change_registrar_
.Add(
501 prefs::kProfileAvatarIndex
,
502 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
503 base::Unretained(this)));
504 pref_change_registrar_
.Add(
505 prefs::kProfileUsingDefaultAvatar
,
506 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
507 base::Unretained(this)));
508 pref_change_registrar_
.Add(
509 prefs::kProfileUsingGAIAAvatar
,
510 base::Bind(&ProfileImpl::UpdateProfileAvatarCache
,
511 base::Unretained(this)));
513 // Changes in the profile name.
514 pref_change_registrar_
.Add(
515 prefs::kProfileUsingDefaultName
,
516 base::Bind(&ProfileImpl::UpdateProfileNameCache
,
517 base::Unretained(this)));
518 pref_change_registrar_
.Add(
520 base::Bind(&ProfileImpl::UpdateProfileNameCache
,
521 base::Unretained(this)));
523 pref_change_registrar_
.Add(
524 prefs::kForceEphemeralProfiles
,
525 base::Bind(&ProfileImpl::UpdateProfileIsEphemeralCache
,
526 base::Unretained(this)));
528 // It would be nice to use PathService for fetching this directory, but
529 // the cache directory depends on the profile directory, which isn't available
531 chrome::GetUserCacheDirectory(path_
, &base_cache_path_
);
532 // Always create the cache directory asynchronously.
533 scoped_refptr
<base::SequencedTaskRunner
> sequenced_task_runner
=
534 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_
,
535 BrowserThread::GetBlockingPool());
536 CreateProfileDirectory(sequenced_task_runner
.get(), base_cache_path_
, false);
538 // Initialize components that depend on the current value.
539 UpdateProfileSupervisedUserIdCache();
540 UpdateProfileIsEphemeralCache();
541 GAIAInfoUpdateServiceFactory::GetForProfile(this);
543 PrefService
* local_state
= g_browser_process
->local_state();
544 ssl_config_service_manager_
.reset(
545 SSLConfigServiceManager::CreateDefaultManager(local_state
));
547 #if defined(ENABLE_BACKGROUND)
548 // Initialize the BackgroundModeManager - this has to be done here before
549 // InitExtensions() is called because it relies on receiving notifications
550 // when extensions are loaded. BackgroundModeManager is not needed under
551 // ChromeOS because Chrome is always running, no need for special keep-alive
552 // or launch-on-startup support unless kKeepAliveForTest is set.
553 bool init_background_mode_manager
= true;
554 #if defined(OS_CHROMEOS)
555 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
556 switches::kKeepAliveForTest
))
557 init_background_mode_manager
= false;
559 if (init_background_mode_manager
) {
560 if (g_browser_process
->background_mode_manager())
561 g_browser_process
->background_mode_manager()->RegisterProfile(this);
563 #endif // defined(ENABLE_BACKGROUND)
565 base::FilePath cookie_path
= GetPath();
566 cookie_path
= cookie_path
.Append(chrome::kCookieFilename
);
567 base::FilePath channel_id_path
= GetPath();
568 channel_id_path
= channel_id_path
.Append(chrome::kChannelIDFilename
);
569 base::FilePath cache_path
= base_cache_path_
;
571 GetCacheParameters(false, &cache_path
, &cache_max_size
);
572 cache_path
= GetCachePath(cache_path
);
574 base::FilePath media_cache_path
= base_cache_path_
;
575 int media_cache_max_size
;
576 GetCacheParameters(true, &media_cache_path
, &media_cache_max_size
);
577 media_cache_path
= GetMediaCachePath(media_cache_path
);
579 base::FilePath extensions_cookie_path
= GetPath();
580 extensions_cookie_path
=
581 extensions_cookie_path
.Append(chrome::kExtensionsCookieFilename
);
583 #if defined(OS_ANDROID)
584 SessionStartupPref::Type startup_pref_type
=
585 SessionStartupPref::GetDefaultStartupType();
587 SessionStartupPref::Type startup_pref_type
=
588 StartupBrowserCreator::GetSessionStartupPref(
589 *base::CommandLine::ForCurrentProcess(), this).type
;
591 content::CookieStoreConfig::SessionCookieMode session_cookie_mode
=
592 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES
;
593 if (GetLastSessionExitType() == Profile::EXIT_CRASHED
||
594 startup_pref_type
== SessionStartupPref::LAST
) {
595 session_cookie_mode
= content::CookieStoreConfig::RESTORED_SESSION_COOKIES
;
598 // Make sure we initialize the ProfileIOData after everything else has been
599 // initialized that we might be reading from the IO thread.
601 io_data_
.Init(cookie_path
, channel_id_path
, cache_path
,
602 cache_max_size
, media_cache_path
, media_cache_max_size
,
603 extensions_cookie_path
, GetPath(), predictor_
,
604 session_cookie_mode
, GetSpecialStoragePolicy(),
605 CreateDomainReliabilityMonitor(local_state
));
607 #if defined(ENABLE_PLUGINS)
608 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
609 PluginPrefs::GetForProfile(this).get(),
610 io_data_
.GetResourceContextNoInit());
613 TRACE_EVENT0("browser", "ProfileImpl::SetSaveSessionStorageOnDisk");
614 content::BrowserContext::GetDefaultStoragePartition(this)->
615 GetDOMStorageContext()->SetSaveSessionStorageOnDisk();
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() const {
768 return !GetPrefs()->GetString(prefs::kSupervisedUserId
).empty();
771 bool ProfileImpl::IsChild() const {
772 #if defined(ENABLE_SUPERVISED_USERS)
773 return GetPrefs()->GetString(prefs::kSupervisedUserId
) ==
774 supervised_users::kChildAccountSUID
;
780 bool ProfileImpl::IsLegacySupervised() const {
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 CookieSettingsFactory::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 DevToolsNetworkControllerHandle
*
1185 ProfileImpl::GetDevToolsNetworkControllerHandle() {
1186 return io_data_
.GetDevToolsNetworkControllerHandle();
1189 void ProfileImpl::ClearNetworkingHistorySince(
1191 const base::Closure
& completion
) {
1192 io_data_
.ClearNetworkingHistorySince(time
, completion
);
1195 GURL
ProfileImpl::GetHomePage() {
1196 // --homepage overrides any preferences.
1197 const base::CommandLine
& command_line
=
1198 *base::CommandLine::ForCurrentProcess();
1199 if (command_line
.HasSwitch(switches::kHomePage
)) {
1200 // TODO(evanm): clean up usage of DIR_CURRENT.
1201 // http://code.google.com/p/chromium/issues/detail?id=60630
1202 // For now, allow this code to call getcwd().
1203 base::ThreadRestrictions::ScopedAllowIO allow_io
;
1205 base::FilePath browser_directory
;
1206 PathService::Get(base::DIR_CURRENT
, &browser_directory
);
1207 GURL
home_page(url_formatter::FixupRelativeFile(
1209 command_line
.GetSwitchValuePath(switches::kHomePage
)));
1210 if (home_page
.is_valid())
1214 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage
))
1215 return GURL(chrome::kChromeUINewTabURL
);
1216 GURL
home_page(url_formatter::FixupURL(
1217 GetPrefs()->GetString(prefs::kHomePage
), std::string()));
1218 if (!home_page
.is_valid())
1219 return GURL(chrome::kChromeUINewTabURL
);
1223 void ProfileImpl::UpdateProfileSupervisedUserIdCache() {
1224 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1225 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1226 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1227 if (index
!= std::string::npos
) {
1228 std::string supervised_user_id
=
1229 GetPrefs()->GetString(prefs::kSupervisedUserId
);
1230 cache
.SetSupervisedUserIdOfProfileAtIndex(index
, supervised_user_id
);
1231 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager
);
1235 void ProfileImpl::UpdateProfileNameCache() {
1236 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1237 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1238 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1239 if (index
!= std::string::npos
) {
1240 std::string profile_name
=
1241 GetPrefs()->GetString(prefs::kProfileName
);
1242 cache
.SetNameOfProfileAtIndex(index
, base::UTF8ToUTF16(profile_name
));
1244 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName
);
1245 cache
.SetProfileIsUsingDefaultNameAtIndex(index
, default_name
);
1249 void ProfileImpl::UpdateProfileAvatarCache() {
1250 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1251 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1252 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1253 if (index
!= std::string::npos
) {
1254 size_t avatar_index
=
1255 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex
);
1256 cache
.SetAvatarIconOfProfileAtIndex(index
, avatar_index
);
1257 bool default_avatar
=
1258 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar
);
1259 cache
.SetProfileIsUsingDefaultAvatarAtIndex(index
, default_avatar
);
1261 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar
);
1262 cache
.SetIsUsingGAIAPictureOfProfileAtIndex(index
, gaia_avatar
);
1266 void ProfileImpl::UpdateProfileIsEphemeralCache() {
1267 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
1268 ProfileInfoCache
& cache
= profile_manager
->GetProfileInfoCache();
1269 size_t index
= cache
.GetIndexOfProfileWithPath(GetPath());
1270 if (index
!= std::string::npos
) {
1271 bool is_ephemeral
= GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles
);
1272 cache
.SetProfileIsEphemeralAtIndex(index
, is_ephemeral
);
1276 // Gets the cache parameters from the command line. If |is_media_context| is
1277 // set to true then settings for the media context type is what we need,
1278 // |cache_path| will be set to the user provided path, or will not be touched if
1279 // there is not an argument. |max_size| will be the user provided value or zero
1281 void ProfileImpl::GetCacheParameters(bool is_media_context
,
1282 base::FilePath
* cache_path
,
1286 base::FilePath
path(prefs_
->GetFilePath(prefs::kDiskCacheDir
));
1289 *max_size
= is_media_context
? prefs_
->GetInteger(prefs::kMediaCacheSize
) :
1290 prefs_
->GetInteger(prefs::kDiskCacheSize
);
1293 PrefProxyConfigTracker
* ProfileImpl::CreateProxyConfigTracker() {
1294 #if defined(OS_CHROMEOS)
1295 if (chromeos::ProfileHelper::IsSigninProfile(this)) {
1296 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
1297 g_browser_process
->local_state());
1299 #endif // defined(OS_CHROMEOS)
1300 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
1301 GetPrefs(), g_browser_process
->local_state());
1304 scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
1305 ProfileImpl::CreateDomainReliabilityMonitor(PrefService
* local_state
) {
1306 domain_reliability::DomainReliabilityService
* service
=
1307 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1308 GetForBrowserContext(this);
1310 return scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>();
1312 return service
->CreateMonitor(
1313 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
));