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 DevToolsNetworkController
;
21 class ExtensionSpecialStoragePolicy
;
23 class HostContentSettingsMap
;
24 class PrefProxyConfigTracker
;
27 class ProtocolHandlerRegistry
;
31 class TabContentsProvider
;
35 class SequencedTaskRunner
;
40 class ChromeZoomLevelPrefs
;
43 namespace chrome_browser_net
{
48 class LibCrosServiceLibraryImpl
;
49 class ResetDefaultProxyConfigServiceTask
;
57 class FileSystemContext
;
65 class SSLConfigService
;
68 namespace user_prefs
{
69 class PrefRegistrySyncable
;
72 // Instead of adding more members to Profile, consider creating a
74 // http://dev.chromium.org/developers/design-documents/profile-architecture
75 class Profile
: public content::BrowserContext
{
77 // Profile services are accessed with the following parameter. This parameter
78 // defines what the caller plans to do with the service.
79 // The caller is responsible for not performing any operation that would
80 // result in persistent implicit records while using an OffTheRecord profile.
81 // This flag allows the profile to perform an additional check.
83 // It also gives us an opportunity to perform further checks in the future. We
84 // could, for example, return an history service that only allow some specific
86 enum ServiceAccessType
{
87 // The caller plans to perform a read or write that takes place as a result
88 // of the user input. Use this flag when the operation you are doing can be
89 // performed while incognito. (ex: creating a bookmark)
91 // Since EXPLICIT_ACCESS means "as a result of a user action", this request
95 // The caller plans to call a method that will permanently change some data
96 // in the profile, as part of Chrome's implicit data logging. Use this flag
97 // when you are about to perform an operation which is incompatible with the
103 // Profile services were not created due to a local error (e.g., disk full).
104 CREATE_STATUS_LOCAL_FAIL
,
105 // Profile services were not created due to a remote error (e.g., network
106 // down during limited-user registration).
107 CREATE_STATUS_REMOTE_FAIL
,
108 // Profile created but before initializing extensions and promo resources.
109 CREATE_STATUS_CREATED
,
110 // Profile is created, extensions and promo resources are initialized.
111 CREATE_STATUS_INITIALIZED
,
112 // Profile creation (supervised-user registration, generally) was canceled
114 CREATE_STATUS_CANCELED
,
115 MAX_CREATE_STATUS
// For histogram display.
119 CREATE_MODE_SYNCHRONOUS
,
120 CREATE_MODE_ASYNCHRONOUS
124 // A normal shutdown. The user clicked exit/closed last window of the
128 // The exit was the result of the system shutting down.
135 REGULAR_PROFILE
, // Login user's normal profile
136 INCOGNITO_PROFILE
, // Login user's off-the-record profile
137 GUEST_PROFILE
, // Guest session's profile
144 // Called when creation of the profile is finished.
145 virtual void OnProfileCreated(Profile
* profile
,
147 bool is_new_profile
) = 0;
150 // Key used to bind profile to the widget with which it is associated.
151 static const char kProfileKey
[];
152 // Value representing no hosted domain in the kProfileHostedDomain preference.
153 static const char kNoHostedDomainFound
[];
158 // Profile prefs are registered as soon as the prefs are loaded for the first
160 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
162 // Create a new profile given a path. If |create_mode| is
163 // CREATE_MODE_ASYNCHRONOUS then the profile is initialized asynchronously.
164 static Profile
* CreateProfile(const base::FilePath
& path
,
166 CreateMode create_mode
);
168 // Returns the profile corresponding to the given browser context.
169 static Profile
* FromBrowserContext(content::BrowserContext
* browser_context
);
171 // Returns the profile corresponding to the given WebUI.
172 static Profile
* FromWebUI(content::WebUI
* web_ui
);
174 // content::BrowserContext implementation ------------------------------------
177 virtual TestingProfile
* AsTestingProfile();
179 // Returns sequenced task runner where browser context dependent I/O
180 // operations should be performed.
181 virtual scoped_refptr
<base::SequencedTaskRunner
> GetIOTaskRunner() = 0;
183 // Returns the name associated with this profile. This name is displayed in
184 // the browser frame.
185 virtual std::string
GetProfileName() = 0;
187 // Returns the profile type.
188 virtual ProfileType
GetProfileType() const = 0;
190 // Return the incognito version of this profile. The returned pointer
191 // is owned by the receiving profile. If the receiving profile is off the
192 // record, the same profile is returned.
194 // WARNING: This will create the OffTheRecord profile if it doesn't already
195 // exist. If this isn't what you want, you need to check
196 // HasOffTheRecordProfile() first.
197 virtual Profile
* GetOffTheRecordProfile() = 0;
199 // Destroys the incognito profile.
200 virtual void DestroyOffTheRecordProfile() = 0;
202 // True if an incognito profile exists.
203 virtual bool HasOffTheRecordProfile() = 0;
205 // Return the original "recording" profile. This method returns this if the
206 // profile is not incognito.
207 virtual Profile
* GetOriginalProfile() = 0;
209 // Returns whether the profile is supervised (see SupervisedUserService).
210 virtual bool IsSupervised() = 0;
212 // Returns a pointer to the TopSites (thumbnail manager) instance
214 virtual history::TopSites
* GetTopSites() = 0;
216 // Variant of GetTopSites that doesn't force creation.
217 virtual history::TopSites
* GetTopSitesWithoutCreating() = 0;
219 // Accessor. The instance is created upon first access.
220 virtual ExtensionSpecialStoragePolicy
*
221 GetExtensionSpecialStoragePolicy() = 0;
223 // Retrieves a pointer to the PrefService that manages the
224 // preferences for this user profile.
225 virtual PrefService
* GetPrefs() = 0;
227 // Retrieves a pointer to the PrefService that manages the default zoom
228 // level and the per-host zoom levels for this user profile.
229 // TODO(wjmaclean): Remove this when HostZoomMap migrates to StoragePartition.
230 virtual chrome::ChromeZoomLevelPrefs
* GetZoomLevelPrefs();
232 // Retrieves a pointer to the PrefService that manages the preferences
233 // for OffTheRecord Profiles. This PrefService is lazily created the first
234 // time that this method is called.
235 virtual PrefService
* GetOffTheRecordPrefs() = 0;
237 // Returns the main request context.
238 virtual net::URLRequestContextGetter
* GetRequestContext() = 0;
240 // Returns the request context used for extension-related requests. This
241 // is only used for a separate cookie store currently.
242 virtual net::URLRequestContextGetter
* GetRequestContextForExtensions() = 0;
244 // Returns the SSLConfigService for this profile.
245 virtual net::SSLConfigService
* GetSSLConfigService() = 0;
247 // Returns the Hostname <-> Content settings map for this profile.
248 virtual HostContentSettingsMap
* GetHostContentSettingsMap() = 0;
250 // Return whether 2 profiles are the same. 2 profiles are the same if they
251 // represent the same profile. This can happen if there is pointer equality
252 // or if one profile is the incognito version of another profile (or vice
254 virtual bool IsSameProfile(Profile
* profile
) = 0;
256 // Returns the time the profile was started. This is not the time the profile
257 // was created, rather it is the time the user started chrome and logged into
258 // this profile. For the single profile case, this corresponds to the time
259 // the user started chrome.
260 virtual base::Time
GetStartTime() const = 0;
262 // Creates the main net::URLRequestContextGetter that will be returned by
263 // GetRequestContext(). Should only be called once per ContentBrowserClient
264 // object. This function is exposed because of the circular dependency where
265 // GetStoragePartition() is used to retrieve the request context, but creation
266 // still has to happen in the Profile so the StoragePartition calls
267 // ContextBrowserClient to call this function.
268 // TODO(ajwong): Remove once http://crbug.com/159193 is resolved.
269 virtual net::URLRequestContextGetter
* CreateRequestContext(
270 content::ProtocolHandlerMap
* protocol_handlers
,
271 content::URLRequestInterceptorScopedVector request_interceptors
) = 0;
273 // Creates the net::URLRequestContextGetter for a StoragePartition. Should
274 // only be called once per partition_path per ContentBrowserClient object.
275 // This function is exposed because the request context is retrieved from the
276 // StoragePartition, but creation still has to happen in the Profile so the
277 // StoragePartition calls ContextBrowserClient to call this function.
278 // TODO(ajwong): Remove once http://crbug.com/159193 is resolved.
279 virtual net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
280 const base::FilePath
& partition_path
,
282 content::ProtocolHandlerMap
* protocol_handlers
,
283 content::URLRequestInterceptorScopedVector request_interceptors
) = 0;
285 // Returns the last directory that was chosen for uploading or opening a file.
286 virtual base::FilePath
last_selected_directory() = 0;
287 virtual void set_last_selected_directory(const base::FilePath
& path
) = 0;
289 #if defined(OS_CHROMEOS)
290 enum AppLocaleChangedVia
{
291 // Caused by chrome://settings change.
292 APP_LOCALE_CHANGED_VIA_SETTINGS
,
293 // Locale has been reverted via LocaleChangeGuard.
294 APP_LOCALE_CHANGED_VIA_REVERT
,
295 // From login screen.
296 APP_LOCALE_CHANGED_VIA_LOGIN
,
297 // From login to a public session.
298 APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN
,
300 APP_LOCALE_CHANGED_VIA_UNKNOWN
303 // Changes application locale for a profile.
304 virtual void ChangeAppLocale(
305 const std::string
& locale
, AppLocaleChangedVia via
) = 0;
307 // Called after login.
308 virtual void OnLogin() = 0;
310 // Initializes Chrome OS's preferences.
311 virtual void InitChromeOSPreferences() = 0;
312 #endif // defined(OS_CHROMEOS)
314 // Returns the helper object that provides the proxy configuration service
315 // access to the the proxy configuration possibly defined by preferences.
316 virtual PrefProxyConfigTracker
* GetProxyConfigTracker() = 0;
318 // Returns the Predictor object used for dns prefetch.
319 virtual chrome_browser_net::Predictor
* GetNetworkPredictor() = 0;
321 // Returns the DevToolsNetworkController for this profile.
322 virtual DevToolsNetworkController
* GetDevToolsNetworkController() = 0;
324 // Deletes all network related data since |time|. It deletes transport
325 // security state since |time| and it also deletes HttpServerProperties data.
326 // Works asynchronously, however if the |completion| callback is non-null, it
327 // will be posted on the UI thread once the removal process completes.
328 // Be aware that theoretically it is possible that |completion| will be
329 // invoked after the Profile instance has been destroyed.
330 virtual void ClearNetworkingHistorySince(base::Time time
,
331 const base::Closure
& completion
) = 0;
333 // Returns the home page for this profile.
334 virtual GURL
GetHomePage() = 0;
336 // Returns whether or not the profile was created by a version of Chrome
337 // more recent (or equal to) the one specified.
338 virtual bool WasCreatedByVersionOrLater(const std::string
& version
) = 0;
340 std::string
GetDebugName();
342 // Returns whether it is a guest session.
343 virtual bool IsGuestSession() const;
345 // Did the user restore the last session? This is set by SessionRestore.
346 void set_restored_last_session(bool restored_last_session
) {
347 restored_last_session_
= restored_last_session
;
349 bool restored_last_session() const {
350 return restored_last_session_
;
353 // Sets the ExitType for the profile. This may be invoked multiple times
354 // during shutdown; only the first such change (the transition from
355 // EXIT_CRASHED to one of the other values) is written to prefs, any
356 // later calls are ignored.
358 // NOTE: this is invoked internally on a normal shutdown, but is public so
359 // that it can be invoked when the user logs out/powers down (WM_ENDSESSION),
360 // or to handle backgrounding/foregrounding on mobile.
361 virtual void SetExitType(ExitType exit_type
) = 0;
363 // Returns how the last session was shutdown.
364 virtual ExitType
GetLastSessionExitType() = 0;
366 // Stop sending accessibility events until ResumeAccessibilityEvents().
367 // Calls to Pause nest; no events will be sent until the number of
368 // Resume calls matches the number of Pause calls received.
369 void PauseAccessibilityEvents() {
370 accessibility_pause_level_
++;
373 void ResumeAccessibilityEvents() {
374 DCHECK_GT(accessibility_pause_level_
, 0);
375 accessibility_pause_level_
--;
378 bool ShouldSendAccessibilityEvents() {
379 return 0 == accessibility_pause_level_
;
382 // Returns whether the profile is new. A profile is new if the browser has
383 // not been shut down since the profile was created.
386 // Checks whether sync is configurable by the user. Returns false if sync is
387 // disabled or controlled by configuration management.
388 bool IsSyncAccessible();
390 // Send NOTIFICATION_PROFILE_DESTROYED for this Profile, if it has not
391 // already been sent. It is necessary because most Profiles are destroyed by
392 // ProfileDestroyer, but in tests, some are not.
393 void MaybeSendDestroyedNotification();
395 // Creates an OffTheRecordProfile which points to this Profile.
396 Profile
* CreateOffTheRecordProfile();
399 bool restored_last_session_
;
401 // Used to prevent the notification that this Profile is destroyed from
403 bool sent_destroyed_notification_
;
405 // Accessibility events will only be propagated when the pause
406 // level is zero. PauseAccessibilityEvents and ResumeAccessibilityEvents
407 // increment and decrement the level, respectively, rather than set it to
408 // true or false, so that calls can be nested.
409 int accessibility_pause_level_
;
411 DISALLOW_COPY_AND_ASSIGN(Profile
);
414 // The comparator for profile pointers as key in a map.
415 struct ProfileCompare
{
416 bool operator()(Profile
* a
, Profile
* b
) const;
419 #endif // CHROME_BROWSER_PROFILES_PROFILE_H_