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 // Return whether 2 profiles are the same. 2 profiles are the same if they
214 // represent the same profile. This can happen if there is pointer equality
215 // or if one profile is the incognito version of another profile (or vice
217 virtual bool IsSameProfile(Profile
* profile
) = 0;
219 // Returns the time the profile was started. This is not the time the profile
220 // was created, rather it is the time the user started chrome and logged into
221 // this profile. For the single profile case, this corresponds to the time
222 // the user started chrome.
223 virtual base::Time
GetStartTime() const = 0;
225 // Creates the main net::URLRequestContextGetter that will be returned by
226 // GetRequestContext(). Should only be called once per ContentBrowserClient
227 // object. This function is exposed because of the circular dependency where
228 // GetStoragePartition() is used to retrieve the request context, but creation
229 // still has to happen in the Profile so the StoragePartition calls
230 // ContextBrowserClient to call this function.
231 // TODO(ajwong): Remove once http://crbug.com/159193 is resolved.
232 virtual net::URLRequestContextGetter
* CreateRequestContext(
233 content::ProtocolHandlerMap
* protocol_handlers
,
234 content::URLRequestInterceptorScopedVector request_interceptors
) = 0;
236 // Creates the net::URLRequestContextGetter for a StoragePartition. Should
237 // only be called once per partition_path per ContentBrowserClient object.
238 // This function is exposed because the request context is retrieved from the
239 // StoragePartition, but creation still has to happen in the Profile so the
240 // StoragePartition calls ContextBrowserClient to call this function.
241 // TODO(ajwong): Remove once http://crbug.com/159193 is resolved.
242 virtual net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
243 const base::FilePath
& partition_path
,
245 content::ProtocolHandlerMap
* protocol_handlers
,
246 content::URLRequestInterceptorScopedVector request_interceptors
) = 0;
248 // Returns the last directory that was chosen for uploading or opening a file.
249 virtual base::FilePath
last_selected_directory() = 0;
250 virtual void set_last_selected_directory(const base::FilePath
& path
) = 0;
252 #if defined(OS_CHROMEOS)
253 enum AppLocaleChangedVia
{
254 // Caused by chrome://settings change.
255 APP_LOCALE_CHANGED_VIA_SETTINGS
,
256 // Locale has been reverted via LocaleChangeGuard.
257 APP_LOCALE_CHANGED_VIA_REVERT
,
258 // From login screen.
259 APP_LOCALE_CHANGED_VIA_LOGIN
,
260 // From login to a public session.
261 APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN
,
263 APP_LOCALE_CHANGED_VIA_UNKNOWN
266 // Changes application locale for a profile.
267 virtual void ChangeAppLocale(
268 const std::string
& locale
, AppLocaleChangedVia via
) = 0;
270 // Called after login.
271 virtual void OnLogin() = 0;
273 // Initializes Chrome OS's preferences.
274 virtual void InitChromeOSPreferences() = 0;
275 #endif // defined(OS_CHROMEOS)
277 // Returns the helper object that provides the proxy configuration service
278 // access to the the proxy configuration possibly defined by preferences.
279 virtual PrefProxyConfigTracker
* GetProxyConfigTracker() = 0;
281 // Returns the Predictor object used for dns prefetch.
282 virtual chrome_browser_net::Predictor
* GetNetworkPredictor() = 0;
284 // Returns the DevToolsNetworkControllerHandle for this profile.
285 virtual DevToolsNetworkControllerHandle
*
286 GetDevToolsNetworkControllerHandle() = 0;
288 // Deletes all network related data since |time|. It deletes transport
289 // security state since |time| and it also deletes HttpServerProperties data.
290 // Works asynchronously, however if the |completion| callback is non-null, it
291 // will be posted on the UI thread once the removal process completes.
292 // Be aware that theoretically it is possible that |completion| will be
293 // invoked after the Profile instance has been destroyed.
294 virtual void ClearNetworkingHistorySince(base::Time time
,
295 const base::Closure
& completion
) = 0;
297 // Returns the home page for this profile.
298 virtual GURL
GetHomePage() = 0;
300 // Returns whether or not the profile was created by a version of Chrome
301 // more recent (or equal to) the one specified.
302 virtual bool WasCreatedByVersionOrLater(const std::string
& version
) = 0;
304 std::string
GetDebugName();
306 // Returns whether it is a guest session.
307 virtual bool IsGuestSession() const;
309 // Returns whether it is a system profile.
310 virtual bool IsSystemProfile() const;
312 // Did the user restore the last session? This is set by SessionRestore.
313 void set_restored_last_session(bool restored_last_session
) {
314 restored_last_session_
= restored_last_session
;
316 bool restored_last_session() const {
317 return restored_last_session_
;
320 // Sets the ExitType for the profile. This may be invoked multiple times
321 // during shutdown; only the first such change (the transition from
322 // EXIT_CRASHED to one of the other values) is written to prefs, any
323 // later calls are ignored.
325 // NOTE: this is invoked internally on a normal shutdown, but is public so
326 // that it can be invoked when the user logs out/powers down (WM_ENDSESSION),
327 // or to handle backgrounding/foregrounding on mobile.
328 virtual void SetExitType(ExitType exit_type
) = 0;
330 // Returns how the last session was shutdown.
331 virtual ExitType
GetLastSessionExitType() = 0;
333 // Stop sending accessibility events until ResumeAccessibilityEvents().
334 // Calls to Pause nest; no events will be sent until the number of
335 // Resume calls matches the number of Pause calls received.
336 void PauseAccessibilityEvents() {
337 accessibility_pause_level_
++;
340 void ResumeAccessibilityEvents() {
341 DCHECK_GT(accessibility_pause_level_
, 0);
342 accessibility_pause_level_
--;
345 bool ShouldSendAccessibilityEvents() {
346 return 0 == accessibility_pause_level_
;
349 // Returns whether the profile is new. A profile is new if the browser has
350 // not been shut down since the profile was created.
353 // Checks whether sync is configurable by the user. Returns false if sync is
354 // disallowed by the command line or controlled by configuration management.
355 bool IsSyncAllowed();
357 // Send NOTIFICATION_PROFILE_DESTROYED for this Profile, if it has not
358 // already been sent. It is necessary because most Profiles are destroyed by
359 // ProfileDestroyer, but in tests, some are not.
360 void MaybeSendDestroyedNotification();
362 // Creates an OffTheRecordProfile which points to this Profile.
363 Profile
* CreateOffTheRecordProfile();
365 // Convenience method to retrieve the default zoom level for the default
366 // storage partition.
367 double GetDefaultZoomLevelForProfile();
370 void set_is_guest_profile(bool is_guest_profile
) {
371 is_guest_profile_
= is_guest_profile
;
374 void set_is_system_profile(bool is_system_profile
) {
375 is_system_profile_
= is_system_profile
;
379 bool restored_last_session_
;
381 // Used to prevent the notification that this Profile is destroyed from
383 bool sent_destroyed_notification_
;
385 // Accessibility events will only be propagated when the pause
386 // level is zero. PauseAccessibilityEvents and ResumeAccessibilityEvents
387 // increment and decrement the level, respectively, rather than set it to
388 // true or false, so that calls can be nested.
389 int accessibility_pause_level_
;
391 bool is_guest_profile_
;
393 // A non-browsing profile not associated to a user. Sample use: User-Manager.
394 bool is_system_profile_
;
396 DISALLOW_COPY_AND_ASSIGN(Profile
);
399 // The comparator for profile pointers as key in a map.
400 struct ProfileCompare
{
401 bool operator()(Profile
* a
, Profile
* b
) const;
404 #endif // CHROME_BROWSER_PROFILES_PROFILE_H_