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 // This class gathers state related to a single user profile.
7 #ifndef CHROME_BROWSER_PROFILES_PROFILE_H_
8 #define CHROME_BROWSER_PROFILES_PROFILE_H_
12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/logging.h"
15 #include "components/domain_reliability/clear_mode.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/content_browser_client.h"
19 class ChromeAppCacheService
;
20 class DevToolsNetworkControllerHandle
;
21 class ExtensionSpecialStoragePolicy
;
22 class HostContentSettingsMap
;
23 class PrefProxyConfigTracker
;
26 class ProtocolHandlerRegistry
;
30 class TabContentsProvider
;
34 class SequencedTaskRunner
;
39 class ChromeZoomLevelPrefs
;
42 namespace chrome_browser_net
{
47 class LibCrosServiceLibraryImpl
;
48 class ResetDefaultProxyConfigServiceTask
;
56 class FileSystemContext
;
60 class SSLConfigService
;
63 namespace user_prefs
{
64 class PrefRegistrySyncable
;
67 // Instead of adding more members to Profile, consider creating a
69 // http://dev.chromium.org/developers/design-documents/profile-architecture
70 class Profile
: public content::BrowserContext
{
73 // Profile services were not created due to a local error (e.g., disk full).
74 CREATE_STATUS_LOCAL_FAIL
,
75 // Profile services were not created due to a remote error (e.g., network
76 // down during limited-user registration).
77 CREATE_STATUS_REMOTE_FAIL
,
78 // Profile created but before initializing extensions and promo resources.
79 CREATE_STATUS_CREATED
,
80 // Profile is created, extensions and promo resources are initialized.
81 CREATE_STATUS_INITIALIZED
,
82 // Profile creation (supervised-user registration, generally) was canceled
84 CREATE_STATUS_CANCELED
,
85 MAX_CREATE_STATUS
// For histogram display.
89 CREATE_MODE_SYNCHRONOUS
,
90 CREATE_MODE_ASYNCHRONOUS
94 // A normal shutdown. The user clicked exit/closed last window of the
98 // The exit was the result of the system shutting down.
105 REGULAR_PROFILE
, // Login user's normal profile
106 INCOGNITO_PROFILE
, // Login user's off-the-record profile
107 GUEST_PROFILE
, // Guest session's profile
114 // Called when creation of the profile is finished.
115 virtual void OnProfileCreated(Profile
* profile
,
117 bool is_new_profile
) = 0;
120 // Key used to bind profile to the widget with which it is associated.
121 static const char kProfileKey
[];
122 // Value representing no hosted domain in the kProfileHostedDomain preference.
123 static const char kNoHostedDomainFound
[];
128 // Profile prefs are registered as soon as the prefs are loaded for the first
130 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
132 // Create a new profile given a path. If |create_mode| is
133 // CREATE_MODE_ASYNCHRONOUS then the profile is initialized asynchronously.
134 static Profile
* CreateProfile(const base::FilePath
& path
,
136 CreateMode create_mode
);
138 // Returns the profile corresponding to the given browser context.
139 static Profile
* FromBrowserContext(content::BrowserContext
* browser_context
);
141 // Returns the profile corresponding to the given WebUI.
142 static Profile
* FromWebUI(content::WebUI
* web_ui
);
144 // content::BrowserContext implementation ------------------------------------
147 virtual TestingProfile
* AsTestingProfile();
149 // Returns sequenced task runner where browser context dependent I/O
150 // operations should be performed.
151 virtual scoped_refptr
<base::SequencedTaskRunner
> GetIOTaskRunner() = 0;
153 // Returns the username associated with this profile, if any. In non-test
154 // implementations, this is usually the Google-services email address.
155 virtual std::string
GetProfileUserName() const = 0;
157 // Returns the profile type.
158 virtual ProfileType
GetProfileType() const = 0;
160 // Return the incognito version of this profile. The returned pointer
161 // is owned by the receiving profile. If the receiving profile is off the
162 // record, the same profile is returned.
164 // WARNING: This will create the OffTheRecord profile if it doesn't already
165 // exist. If this isn't what you want, you need to check
166 // HasOffTheRecordProfile() first.
167 virtual Profile
* GetOffTheRecordProfile() = 0;
169 // Destroys the incognito profile.
170 virtual void DestroyOffTheRecordProfile() = 0;
172 // True if an incognito profile exists.
173 virtual bool HasOffTheRecordProfile() = 0;
175 // Return the original "recording" profile. This method returns this if the
176 // profile is not incognito.
177 virtual Profile
* GetOriginalProfile() = 0;
179 // Returns whether the profile is supervised (either a legacy supervised
180 // user or a child account; see SupervisedUserService).
181 virtual bool IsSupervised() const = 0;
182 // Returns whether the profile is associated with a child account.
183 virtual bool IsChild() const = 0;
184 // Returns whether the profile is a legacy supervised user profile.
185 virtual bool IsLegacySupervised() const = 0;
187 // Accessor. The instance is created upon first access.
188 virtual ExtensionSpecialStoragePolicy
*
189 GetExtensionSpecialStoragePolicy() = 0;
191 // Retrieves a pointer to the PrefService that manages the
192 // preferences for this user profile.
193 virtual PrefService
* GetPrefs() = 0;
194 virtual const PrefService
* GetPrefs() const = 0;
196 // Retrieves a pointer to the PrefService that manages the default zoom
197 // level and the per-host zoom levels for this user profile.
198 // TODO(wjmaclean): Remove this when HostZoomMap migrates to StoragePartition.
199 virtual chrome::ChromeZoomLevelPrefs
* GetZoomLevelPrefs();
201 // Retrieves a pointer to the PrefService that manages the preferences
202 // for OffTheRecord Profiles. This PrefService is lazily created the first
203 // time that this method is called.
204 virtual PrefService
* GetOffTheRecordPrefs() = 0;
206 // Returns the main request context.
207 net::URLRequestContextGetter
* GetRequestContext() override
= 0;
209 // Returns the request context used for extension-related requests. This
210 // is only used for a separate cookie store currently.
211 virtual net::URLRequestContextGetter
* GetRequestContextForExtensions() = 0;
213 // Returns the SSLConfigService for this profile.
214 virtual net::SSLConfigService
* GetSSLConfigService() = 0;
216 // Returns the Hostname <-> Content settings map for this profile.
217 virtual HostContentSettingsMap
* GetHostContentSettingsMap() = 0;
219 // Return whether 2 profiles are the same. 2 profiles are the same if they
220 // represent the same profile. This can happen if there is pointer equality
221 // or if one profile is the incognito version of another profile (or vice
223 virtual bool IsSameProfile(Profile
* profile
) = 0;
225 // Returns the time the profile was started. This is not the time the profile
226 // was created, rather it is the time the user started chrome and logged into
227 // this profile. For the single profile case, this corresponds to the time
228 // the user started chrome.
229 virtual base::Time
GetStartTime() const = 0;
231 // Creates the main net::URLRequestContextGetter that will be returned by
232 // GetRequestContext(). Should only be called once per ContentBrowserClient
233 // object. This function is exposed because of the circular dependency where
234 // GetStoragePartition() is used to retrieve the request context, but creation
235 // still has to happen in the Profile so the StoragePartition calls
236 // ContextBrowserClient to call this function.
237 // TODO(ajwong): Remove once http://crbug.com/159193 is resolved.
238 virtual net::URLRequestContextGetter
* CreateRequestContext(
239 content::ProtocolHandlerMap
* protocol_handlers
,
240 content::URLRequestInterceptorScopedVector request_interceptors
) = 0;
242 // Creates the net::URLRequestContextGetter for a StoragePartition. Should
243 // only be called once per partition_path per ContentBrowserClient object.
244 // This function is exposed because the request context is retrieved from the
245 // StoragePartition, but creation still has to happen in the Profile so the
246 // StoragePartition calls ContextBrowserClient to call this function.
247 // TODO(ajwong): Remove once http://crbug.com/159193 is resolved.
248 virtual net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
249 const base::FilePath
& partition_path
,
251 content::ProtocolHandlerMap
* protocol_handlers
,
252 content::URLRequestInterceptorScopedVector request_interceptors
) = 0;
254 // Returns the last directory that was chosen for uploading or opening a file.
255 virtual base::FilePath
last_selected_directory() = 0;
256 virtual void set_last_selected_directory(const base::FilePath
& path
) = 0;
258 #if defined(OS_CHROMEOS)
259 enum AppLocaleChangedVia
{
260 // Caused by chrome://settings change.
261 APP_LOCALE_CHANGED_VIA_SETTINGS
,
262 // Locale has been reverted via LocaleChangeGuard.
263 APP_LOCALE_CHANGED_VIA_REVERT
,
264 // From login screen.
265 APP_LOCALE_CHANGED_VIA_LOGIN
,
266 // From login to a public session.
267 APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN
,
269 APP_LOCALE_CHANGED_VIA_UNKNOWN
272 // Changes application locale for a profile.
273 virtual void ChangeAppLocale(
274 const std::string
& locale
, AppLocaleChangedVia via
) = 0;
276 // Called after login.
277 virtual void OnLogin() = 0;
279 // Initializes Chrome OS's preferences.
280 virtual void InitChromeOSPreferences() = 0;
281 #endif // defined(OS_CHROMEOS)
283 // Returns the helper object that provides the proxy configuration service
284 // access to the the proxy configuration possibly defined by preferences.
285 virtual PrefProxyConfigTracker
* GetProxyConfigTracker() = 0;
287 // Returns the Predictor object used for dns prefetch.
288 virtual chrome_browser_net::Predictor
* GetNetworkPredictor() = 0;
290 // Returns the DevToolsNetworkControllerHandle for this profile.
291 virtual DevToolsNetworkControllerHandle
*
292 GetDevToolsNetworkControllerHandle() = 0;
294 // Deletes all network related data since |time|. It deletes transport
295 // security state since |time| and it also deletes HttpServerProperties data.
296 // Works asynchronously, however if the |completion| callback is non-null, it
297 // will be posted on the UI thread once the removal process completes.
298 // Be aware that theoretically it is possible that |completion| will be
299 // invoked after the Profile instance has been destroyed.
300 virtual void ClearNetworkingHistorySince(base::Time time
,
301 const base::Closure
& completion
) = 0;
303 // Returns the home page for this profile.
304 virtual GURL
GetHomePage() = 0;
306 // Returns whether or not the profile was created by a version of Chrome
307 // more recent (or equal to) the one specified.
308 virtual bool WasCreatedByVersionOrLater(const std::string
& version
) = 0;
310 std::string
GetDebugName();
312 // Returns whether it is a guest session.
313 virtual bool IsGuestSession() const;
315 // Returns whether it is a system profile.
316 virtual bool IsSystemProfile() const;
318 // Did the user restore the last session? This is set by SessionRestore.
319 void set_restored_last_session(bool restored_last_session
) {
320 restored_last_session_
= restored_last_session
;
322 bool restored_last_session() const {
323 return restored_last_session_
;
326 // Sets the ExitType for the profile. This may be invoked multiple times
327 // during shutdown; only the first such change (the transition from
328 // EXIT_CRASHED to one of the other values) is written to prefs, any
329 // later calls are ignored.
331 // NOTE: this is invoked internally on a normal shutdown, but is public so
332 // that it can be invoked when the user logs out/powers down (WM_ENDSESSION),
333 // or to handle backgrounding/foregrounding on mobile.
334 virtual void SetExitType(ExitType exit_type
) = 0;
336 // Returns how the last session was shutdown.
337 virtual ExitType
GetLastSessionExitType() = 0;
339 // Stop sending accessibility events until ResumeAccessibilityEvents().
340 // Calls to Pause nest; no events will be sent until the number of
341 // Resume calls matches the number of Pause calls received.
342 void PauseAccessibilityEvents() {
343 accessibility_pause_level_
++;
346 void ResumeAccessibilityEvents() {
347 DCHECK_GT(accessibility_pause_level_
, 0);
348 accessibility_pause_level_
--;
351 bool ShouldSendAccessibilityEvents() {
352 return 0 == accessibility_pause_level_
;
355 // Returns whether the profile is new. A profile is new if the browser has
356 // not been shut down since the profile was created.
359 // Checks whether sync is configurable by the user. Returns false if sync is
360 // disallowed by the command line or controlled by configuration management.
361 bool IsSyncAllowed();
363 // Send NOTIFICATION_PROFILE_DESTROYED for this Profile, if it has not
364 // already been sent. It is necessary because most Profiles are destroyed by
365 // ProfileDestroyer, but in tests, some are not.
366 void MaybeSendDestroyedNotification();
368 // Creates an OffTheRecordProfile which points to this Profile.
369 Profile
* CreateOffTheRecordProfile();
371 // Convenience method to retrieve the default zoom level for the default
372 // storage partition.
373 double GetDefaultZoomLevelForProfile();
376 void set_is_guest_profile(bool is_guest_profile
) {
377 is_guest_profile_
= is_guest_profile
;
380 void set_is_system_profile(bool is_system_profile
) {
381 is_system_profile_
= is_system_profile
;
385 bool restored_last_session_
;
387 // Used to prevent the notification that this Profile is destroyed from
389 bool sent_destroyed_notification_
;
391 // Accessibility events will only be propagated when the pause
392 // level is zero. PauseAccessibilityEvents and ResumeAccessibilityEvents
393 // increment and decrement the level, respectively, rather than set it to
394 // true or false, so that calls can be nested.
395 int accessibility_pause_level_
;
397 bool is_guest_profile_
;
399 // A non-browsing profile not associated to a user. Sample use: User-Manager.
400 bool is_system_profile_
;
402 DISALLOW_COPY_AND_ASSIGN(Profile
);
405 // The comparator for profile pointers as key in a map.
406 struct ProfileCompare
{
407 bool operator()(Profile
* a
, Profile
* b
) const;
410 #endif // CHROME_BROWSER_PROFILES_PROFILE_H_