Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / profiles / profile.cc
blobaa10c07d0d0463a42f37e06a31648ebfa19ecd35
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.h"
7 #include <string>
9 #include "base/prefs/pref_service.h"
10 #include "build/build_config.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/first_run/first_run.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/sync/profile_sync_service.h"
15 #include "chrome/browser/sync/profile_sync_service_factory.h"
16 #include "chrome/common/pref_names.h"
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
18 #include "components/pref_registry/pref_registry_syncable.h"
19 #include "components/sync_driver/sync_prefs.h"
20 #include "content/public/browser/host_zoom_map.h"
21 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/notification_source.h"
23 #include "content/public/browser/storage_partition.h"
24 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_ui.h"
27 #if defined(OS_CHROMEOS)
28 #include "base/command_line.h"
29 #include "chrome/common/chrome_switches.h"
30 #include "chromeos/chromeos_switches.h"
31 #endif
33 #if defined(ENABLE_EXTENSIONS)
34 #include "extensions/browser/pref_names.h"
35 #endif
37 Profile::Profile()
38 : restored_last_session_(false),
39 sent_destroyed_notification_(false),
40 accessibility_pause_level_(0),
41 is_guest_profile_(false),
42 is_system_profile_(false) {
45 Profile::~Profile() {
48 // static
49 Profile* Profile::FromBrowserContext(content::BrowserContext* browser_context) {
50 // This is safe; this is the only implementation of the browser context.
51 return static_cast<Profile*>(browser_context);
54 // static
55 Profile* Profile::FromWebUI(content::WebUI* web_ui) {
56 return FromBrowserContext(web_ui->GetWebContents()->GetBrowserContext());
59 TestingProfile* Profile::AsTestingProfile() {
60 return NULL;
63 chrome::ChromeZoomLevelPrefs* Profile::GetZoomLevelPrefs() {
64 return NULL;
67 Profile::Delegate::~Delegate() {
70 // static
71 const char Profile::kProfileKey[] = "__PROFILE__";
72 // This must be a string which can never be a valid domain.
73 const char Profile::kNoHostedDomainFound[] = "NO_HOSTED_DOMAIN";
75 // static
76 void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
77 registry->RegisterBooleanPref(
78 prefs::kSearchSuggestEnabled,
79 true,
80 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
81 #if defined(OS_ANDROID)
82 registry->RegisterStringPref(
83 prefs::kContextualSearchEnabled,
84 std::string(),
85 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
86 #endif
87 registry->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
88 registry->RegisterStringPref(prefs::kSessionExitType, std::string());
89 registry->RegisterBooleanPref(
90 prefs::kSafeBrowsingEnabled,
91 true,
92 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
93 registry->RegisterBooleanPref(prefs::kSafeBrowsingExtendedReportingEnabled,
94 false);
95 registry->RegisterBooleanPref(prefs::kSafeBrowsingProceedAnywayDisabled,
96 false);
97 registry->RegisterBooleanPref(prefs::kSSLErrorOverrideAllowed, true);
98 registry->RegisterDictionaryPref(prefs::kSafeBrowsingIncidentsSent);
99 registry->RegisterBooleanPref(
100 prefs::kSafeBrowsingExtendedReportingOptInAllowed, true);
101 #if defined(ENABLE_GOOGLE_NOW)
102 registry->RegisterBooleanPref(prefs::kGoogleGeolocationAccessEnabled, false);
103 #endif
104 // This pref is intentionally outside the above #if. That flag corresponds
105 // to the Notifier extension and does not gate the launcher page.
106 // TODO(skare): Remove or rename ENABLE_GOOGLE_NOW: http://crbug.com/459827.
107 registry->RegisterBooleanPref(prefs::kGoogleNowLauncherEnabled, true);
108 registry->RegisterBooleanPref(prefs::kDisableExtensions, false);
109 #if defined(ENABLE_EXTENSIONS)
110 registry->RegisterBooleanPref(extensions::pref_names::kAlertsInitialized,
111 false);
112 #endif
113 registry->RegisterStringPref(prefs::kSelectFileLastDirectory, std::string());
114 // TODO(wjmaclean): remove the following two prefs once migration to per-
115 // partition zoom is complete.
116 registry->RegisterDoublePref(prefs::kDefaultZoomLevelDeprecated, 0.0);
117 registry->RegisterDictionaryPref(prefs::kPerHostZoomLevelsDeprecated);
119 registry->RegisterDictionaryPref(prefs::kPartitionDefaultZoomLevel);
120 registry->RegisterDictionaryPref(prefs::kPartitionPerHostZoomLevels);
121 registry->RegisterStringPref(prefs::kDefaultApps, "install");
122 registry->RegisterBooleanPref(prefs::kSpeechRecognitionFilterProfanities,
123 true);
124 registry->RegisterIntegerPref(prefs::kProfileIconVersion, 0);
125 #if defined(OS_CHROMEOS)
126 // TODO(dilmah): For OS_CHROMEOS we maintain kApplicationLocale in both
127 // local state and user's profile. For other platforms we maintain
128 // kApplicationLocale only in local state.
129 // In the future we may want to maintain kApplicationLocale
130 // in user's profile for other platforms as well.
131 registry->RegisterStringPref(
132 prefs::kApplicationLocale,
133 std::string(),
134 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
135 registry->RegisterStringPref(prefs::kApplicationLocaleBackup, std::string());
136 registry->RegisterStringPref(prefs::kApplicationLocaleAccepted,
137 std::string());
138 registry->RegisterStringPref(prefs::kCurrentWallpaperAppName, std::string());
139 #endif
141 #if defined(OS_ANDROID)
142 registry->RegisterBooleanPref(prefs::kDevToolsRemoteEnabled, false);
143 #endif
145 data_reduction_proxy::RegisterSyncableProfilePrefs(registry);
147 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS)
148 // Preferences related to the avatar bubble and user manager tutorials.
149 registry->RegisterIntegerPref(prefs::kProfileAvatarTutorialShown, 0);
150 #endif
153 std::string Profile::GetDebugName() {
154 std::string name = GetPath().BaseName().MaybeAsASCII();
155 if (name.empty()) {
156 name = "UnknownProfile";
158 return name;
161 bool Profile::IsGuestSession() const {
162 #if defined(OS_CHROMEOS)
163 static bool is_guest_session =
164 base::CommandLine::ForCurrentProcess()->HasSwitch(
165 chromeos::switches::kGuestSession);
166 return is_guest_session;
167 #else
168 return is_guest_profile_;
169 #endif
172 bool Profile::IsSystemProfile() const {
173 return is_system_profile_;
176 bool Profile::IsNewProfile() {
177 // The profile has been shut down if the prefs were loaded from disk, unless
178 // first-run autoimport wrote them and reloaded the pref service.
179 // TODO(dconnelly): revisit this when crbug.com/22142 (unifying the profile
180 // import code) is fixed.
181 return GetOriginalProfile()->GetPrefs()->GetInitializationStatus() ==
182 PrefService::INITIALIZATION_STATUS_CREATED_NEW_PREF_STORE;
185 bool Profile::IsSyncAllowed() {
186 if (ProfileSyncServiceFactory::HasProfileSyncService(this)) {
187 return ProfileSyncServiceFactory::GetForProfile(this)->IsSyncAllowed();
190 // No ProfileSyncService created yet - we don't want to create one, so just
191 // infer the accessible state by looking at prefs/command line flags.
192 sync_driver::SyncPrefs prefs(GetPrefs());
193 return ProfileSyncService::IsSyncAllowedByFlag() && !prefs.IsManaged();
196 void Profile::MaybeSendDestroyedNotification() {
197 if (!sent_destroyed_notification_) {
198 sent_destroyed_notification_ = true;
200 NotifyWillBeDestroyed(this);
201 content::NotificationService::current()->Notify(
202 chrome::NOTIFICATION_PROFILE_DESTROYED,
203 content::Source<Profile>(this),
204 content::NotificationService::NoDetails());
208 bool ProfileCompare::operator()(Profile* a, Profile* b) const {
209 DCHECK(a && b);
210 if (a->IsSameProfile(b))
211 return false;
212 return a->GetOriginalProfile() < b->GetOriginalProfile();
215 double Profile::GetDefaultZoomLevelForProfile() {
216 return GetDefaultStoragePartition(this)
217 ->GetHostZoomMap()
218 ->GetDefaultZoomLevel();