Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / profiles / profile.cc
blobabdb17f77735260cb7227cfc4009df244fb8a41a
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/browser/sync/sync_prefs.h"
17 #include "chrome/common/pref_names.h"
18 #include "components/user_prefs/pref_registry_syncable.h"
19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_ui.h"
23 #include "extensions/browser/pref_names.h"
25 #if defined(OS_CHROMEOS)
26 #include "base/command_line.h"
27 #include "chrome/common/chrome_switches.h"
28 #include "chromeos/chromeos_switches.h"
29 #endif
31 Profile::Profile()
32 : restored_last_session_(false),
33 sent_destroyed_notification_(false),
34 accessibility_pause_level_(0) {
37 Profile::~Profile() {
40 // static
41 Profile* Profile::FromBrowserContext(content::BrowserContext* browser_context) {
42 // This is safe; this is the only implementation of the browser context.
43 return static_cast<Profile*>(browser_context);
46 // static
47 Profile* Profile::FromWebUI(content::WebUI* web_ui) {
48 return FromBrowserContext(web_ui->GetWebContents()->GetBrowserContext());
51 TestingProfile* Profile::AsTestingProfile() {
52 return NULL;
55 Profile::Delegate::~Delegate() {
58 // static
59 const char Profile::kProfileKey[] = "__PROFILE__";
61 // static
62 void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
63 registry->RegisterBooleanPref(
64 prefs::kSearchSuggestEnabled,
65 true,
66 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
67 registry->RegisterBooleanPref(
68 prefs::kSessionExitedCleanly,
69 true,
70 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
71 registry->RegisterStringPref(
72 prefs::kSessionExitType,
73 std::string(),
74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
75 registry->RegisterBooleanPref(
76 prefs::kSafeBrowsingEnabled,
77 true,
78 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
79 registry->RegisterBooleanPref(
80 prefs::kSafeBrowsingReportingEnabled,
81 false,
82 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
83 registry->RegisterBooleanPref(
84 prefs::kSafeBrowsingProceedAnywayDisabled,
85 false,
86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
87 #if defined(ENABLE_GOOGLE_NOW)
88 registry->RegisterBooleanPref(
89 prefs::kGoogleGeolocationAccessEnabled,
90 false,
91 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
92 #endif
93 registry->RegisterBooleanPref(
94 prefs::kDisableExtensions,
95 false,
96 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
97 registry->RegisterBooleanPref(
98 extensions::pref_names::kAlertsInitialized,
99 false,
100 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
101 registry->RegisterStringPref(
102 prefs::kSelectFileLastDirectory,
103 std::string(),
104 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
105 registry->RegisterDoublePref(
106 prefs::kDefaultZoomLevel,
107 0.0,
108 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
109 registry->RegisterDictionaryPref(
110 prefs::kPerHostZoomLevels,
111 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
112 registry->RegisterStringPref(
113 prefs::kDefaultApps,
114 "install",
115 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
116 registry->RegisterBooleanPref(
117 prefs::kSpeechRecognitionFilterProfanities,
118 true,
119 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
120 registry->RegisterIntegerPref(
121 prefs::kProfileIconVersion,
123 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
124 #if defined(OS_CHROMEOS)
125 // TODO(dilmah): For OS_CHROMEOS we maintain kApplicationLocale in both
126 // local state and user's profile. For other platforms we maintain
127 // kApplicationLocale only in local state.
128 // In the future we may want to maintain kApplicationLocale
129 // in user's profile for other platforms as well.
130 registry->RegisterStringPref(
131 prefs::kApplicationLocale,
132 std::string(),
133 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
134 registry->RegisterStringPref(
135 prefs::kApplicationLocaleBackup,
136 std::string(),
137 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
138 registry->RegisterStringPref(
139 prefs::kApplicationLocaleAccepted,
140 std::string(),
141 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
142 #endif
144 #if defined(OS_ANDROID)
145 registry->RegisterBooleanPref(
146 prefs::kDevToolsRemoteEnabled,
147 false,
148 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
149 #endif
150 #if defined(OS_ANDROID) || defined(OS_IOS)
151 registry->RegisterBooleanPref(
152 prefs::kSpdyProxyAuthEnabled,
153 false,
154 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
155 registry->RegisterBooleanPref(
156 prefs::kSpdyProxyAuthWasEnabledBefore,
157 false,
158 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
160 #endif // defined(OS_ANDROID) || defined(OS_IOS)
164 std::string Profile::GetDebugName() {
165 std::string name = GetPath().BaseName().MaybeAsASCII();
166 if (name.empty()) {
167 name = "UnknownProfile";
169 return name;
172 bool Profile::IsGuestSession() const {
173 #if defined(OS_CHROMEOS)
174 static bool is_guest_session = CommandLine::ForCurrentProcess()->HasSwitch(
175 chromeos::switches::kGuestSession);
176 return is_guest_session;
177 #else
178 return GetPath() == ProfileManager::GetGuestProfilePath();
179 #endif
182 bool Profile::IsNewProfile() {
183 // The profile has been shut down if the prefs were loaded from disk, unless
184 // first-run autoimport wrote them and reloaded the pref service.
185 // TODO(dconnelly): revisit this when crbug.com/22142 (unifying the profile
186 // import code) is fixed.
187 return GetOriginalProfile()->GetPrefs()->GetInitializationStatus() ==
188 PrefService::INITIALIZATION_STATUS_CREATED_NEW_PREF_STORE;
191 bool Profile::IsSyncAccessible() {
192 if (ProfileSyncServiceFactory::HasProfileSyncService(this))
193 return !ProfileSyncServiceFactory::GetForProfile(this)->IsManaged();
195 // No ProfileSyncService created yet - we don't want to create one, so just
196 // infer the accessible state by looking at prefs/command line flags.
197 browser_sync::SyncPrefs prefs(GetPrefs());
198 return ProfileSyncService::IsSyncEnabled() && !prefs.IsManaged();
201 void Profile::MaybeSendDestroyedNotification() {
202 if (!sent_destroyed_notification_) {
203 sent_destroyed_notification_ = true;
204 content::NotificationService::current()->Notify(
205 chrome::NOTIFICATION_PROFILE_DESTROYED,
206 content::Source<Profile>(this),
207 content::NotificationService::NoDetails());