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