Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / profiles / profile.h
blob412387e01c5c81dbccc58a823355570965349450
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_
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/hash_tables.h"
14 #include "base/logging.h"
15 #include "chrome/browser/net/pref_proxy_config_tracker.h"
16 #include "chrome/browser/ui/webui/chrome_url_data_manager_factory.h"
17 #include "content/public/browser/browser_context.h"
19 class ChromeAppCacheService;
20 class ChromeURLDataManager;
21 class ExtensionService;
22 class ExtensionSpecialStoragePolicy;
23 class FaviconService;
24 class GAIAInfoUpdateService;
25 class HostContentSettingsMap;
26 class PasswordStore;
27 class PrefService;
28 class PromoCounter;
29 class ProtocolHandlerRegistry;
30 class TestingProfile;
31 class WebDataService;
33 namespace android {
34 class TabContentsProvider;
37 namespace base {
38 class SequencedTaskRunner;
39 class Time;
42 namespace chrome_browser_net {
43 class Predictor;
46 namespace chromeos {
47 class LibCrosServiceLibraryImpl;
48 class ResetDefaultProxyConfigServiceTask;
51 namespace content {
52 class WebUI;
55 namespace fileapi {
56 class FileSystemContext;
59 namespace history {
60 class ShortcutsBackend;
61 class TopSites;
64 namespace net {
65 class SSLConfigService;
68 namespace policy {
69 class ManagedModePolicyProvider;
70 class PolicyService;
71 class UserCloudPolicyManager;
74 class Profile : public content::BrowserContext {
75 public:
76 // Profile services are accessed with the following parameter. This parameter
77 // defines what the caller plans to do with the service.
78 // The caller is responsible for not performing any operation that would
79 // result in persistent implicit records while using an OffTheRecord profile.
80 // This flag allows the profile to perform an additional check.
82 // It also gives us an opportunity to perform further checks in the future. We
83 // could, for example, return an history service that only allow some specific
84 // methods.
85 enum ServiceAccessType {
86 // The caller plans to perform a read or write that takes place as a result
87 // of the user input. Use this flag when the operation you are doing can be
88 // performed while incognito. (ex: creating a bookmark)
90 // Since EXPLICIT_ACCESS means "as a result of a user action", this request
91 // always succeeds.
92 EXPLICIT_ACCESS,
94 // The caller plans to call a method that will permanently change some data
95 // in the profile, as part of Chrome's implicit data logging. Use this flag
96 // when you are about to perform an operation which is incompatible with the
97 // incognito mode.
98 IMPLICIT_ACCESS
101 enum CreateStatus {
102 // Profile services were not created.
103 CREATE_STATUS_FAIL,
104 // Profile created but before initializing extensions and promo resources.
105 CREATE_STATUS_CREATED,
106 // Profile is created, extensions and promo resources are initialized.
107 CREATE_STATUS_INITIALIZED,
110 enum CreateMode {
111 CREATE_MODE_SYNCHRONOUS,
112 CREATE_MODE_ASYNCHRONOUS
115 enum ExitType {
116 // A normal shutdown. The user clicked exit/closed last window of the
117 // profile.
118 EXIT_NORMAL,
120 // The exit was the result of the system shutting down.
121 EXIT_SESSION_ENDED,
123 EXIT_CRASHED,
126 class Delegate {
127 public:
128 // Called when creation of the profile is finished.
129 virtual void OnProfileCreated(Profile* profile,
130 bool success,
131 bool is_new_profile) = 0;
134 // Key used to bind profile to the widget with which it is associated.
135 static const char* const kProfileKey;
137 Profile();
138 virtual ~Profile() {}
140 // Profile prefs are registered as soon as the prefs are loaded for the first
141 // time.
142 static void RegisterUserPrefs(PrefService* prefs);
144 // Gets task runner for I/O operations associated with |profile|.
145 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForProfile(
146 Profile* profile);
148 // Create a new profile given a path. If |create_mode| is
149 // CREATE_MODE_ASYNCHRONOUS then the profile is initialized asynchronously.
150 static Profile* CreateProfile(const FilePath& path,
151 Delegate* delegate,
152 CreateMode create_mode);
154 // Returns the profile corresponding to the given browser context.
155 static Profile* FromBrowserContext(content::BrowserContext* browser_context);
157 // Returns the profile corresponding to the given WebUI.
158 static Profile* FromWebUI(content::WebUI* web_ui);
160 // content::BrowserContext implementation ------------------------------------
162 // Typesafe upcast.
163 virtual TestingProfile* AsTestingProfile();
165 // Returns sequenced task runner where browser context dependent I/O
166 // operations should be performed.
167 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() = 0;
169 // Returns the name associated with this profile. This name is displayed in
170 // the browser frame.
171 virtual std::string GetProfileName() = 0;
173 // Return the incognito version of this profile. The returned pointer
174 // is owned by the receiving profile. If the receiving profile is off the
175 // record, the same profile is returned.
177 // WARNING: This will create the OffTheRecord profile if it doesn't already
178 // exist. If this isn't what you want, you need to check
179 // HasOffTheRecordProfile() first.
180 virtual Profile* GetOffTheRecordProfile() = 0;
182 // Destroys the incognito profile.
183 virtual void DestroyOffTheRecordProfile() = 0;
185 // True if an incognito profile exists.
186 virtual bool HasOffTheRecordProfile() = 0;
188 // Return the original "recording" profile. This method returns this if the
189 // profile is not incognito.
190 virtual Profile* GetOriginalProfile() = 0;
192 // Returns a pointer to the TopSites (thumbnail manager) instance
193 // for this profile.
194 virtual history::TopSites* GetTopSites() = 0;
196 // Variant of GetTopSites that doesn't force creation.
197 virtual history::TopSites* GetTopSitesWithoutCreating() = 0;
199 // DEPRECATED. Instead, use ExtensionSystem::extension_service().
200 // Retrieves a pointer to the ExtensionService associated with this
201 // profile. The ExtensionService is created at startup.
202 // TODO(yoz): remove this accessor (bug 104095).
203 virtual ExtensionService* GetExtensionService() = 0;
205 // Accessor. The instance is created upon first access.
206 virtual ExtensionSpecialStoragePolicy*
207 GetExtensionSpecialStoragePolicy() = 0;
209 // Accessor. The instance is created upon first access.
210 virtual GAIAInfoUpdateService* GetGAIAInfoUpdateService() = 0;
212 // Returns the UserCloudPolicyManager (if any) that handles this profile's
213 // connection to the cloud-based management service.
214 virtual policy::UserCloudPolicyManager* GetUserCloudPolicyManager() = 0;
216 // Returns the ManagedModePolicyProvider for this profile, if it exists.
217 virtual policy::ManagedModePolicyProvider* GetManagedModePolicyProvider() = 0;
219 // Returns the PolicyService that provides policies for this profile.
220 virtual policy::PolicyService* GetPolicyService() = 0;
222 // Retrieves a pointer to the PrefService that manages the preferences
223 // for this user profile.
224 virtual PrefService* GetPrefs() = 0;
226 // Retrieves a pointer to the PrefService that manages the preferences
227 // for OffTheRecord Profiles. This PrefService is lazily created the first
228 // time that this method is called.
229 virtual PrefService* GetOffTheRecordPrefs() = 0;
231 // Returns the main request context.
232 virtual net::URLRequestContextGetter* GetRequestContext() = 0;
234 // Returns the request context used for extension-related requests. This
235 // is only used for a separate cookie store currently.
236 virtual net::URLRequestContextGetter* GetRequestContextForExtensions() = 0;
238 // Returns the request context used within |partition_id|.
239 virtual net::URLRequestContextGetter* GetRequestContextForStoragePartition(
240 const FilePath& partition_path,
241 bool in_memory) = 0;
243 // Returns the SSLConfigService for this profile.
244 virtual net::SSLConfigService* GetSSLConfigService() = 0;
246 // Returns the Hostname <-> Content settings map for this profile.
247 virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0;
249 // Returns the ProtocolHandlerRegistry, creating if not yet created.
250 // TODO(smckay): replace this with access via ProtocolHandlerRegistryFactory.
251 virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() = 0;
253 // Return whether 2 profiles are the same. 2 profiles are the same if they
254 // represent the same profile. This can happen if there is pointer equality
255 // or if one profile is the incognito version of another profile (or vice
256 // versa).
257 virtual bool IsSameProfile(Profile* profile) = 0;
259 // Returns the time the profile was started. This is not the time the profile
260 // was created, rather it is the time the user started chrome and logged into
261 // this profile. For the single profile case, this corresponds to the time
262 // the user started chrome.
263 virtual base::Time GetStartTime() const = 0;
265 // Start up service that gathers data from a promo resource feed.
266 virtual void InitPromoResources() = 0;
268 // Returns the last directory that was chosen for uploading or opening a file.
269 virtual FilePath last_selected_directory() = 0;
270 virtual void set_last_selected_directory(const FilePath& path) = 0;
272 #if defined(OS_CHROMEOS)
273 enum AppLocaleChangedVia {
274 // Caused by chrome://settings change.
275 APP_LOCALE_CHANGED_VIA_SETTINGS,
276 // Locale has been reverted via LocaleChangeGuard.
277 APP_LOCALE_CHANGED_VIA_REVERT,
278 // From login screen.
279 APP_LOCALE_CHANGED_VIA_LOGIN,
280 // Source unknown.
281 APP_LOCALE_CHANGED_VIA_UNKNOWN
284 // Changes application locale for a profile.
285 virtual void ChangeAppLocale(
286 const std::string& locale, AppLocaleChangedVia via) = 0;
288 // Called after login.
289 virtual void OnLogin() = 0;
291 // Creates ChromeOS's EnterpriseExtensionListener.
292 virtual void SetupChromeOSEnterpriseExtensionObserver() = 0;
294 // Initializes Chrome OS's preferences.
295 virtual void InitChromeOSPreferences() = 0;
296 #endif // defined(OS_CHROMEOS)
298 // Returns the helper object that provides the proxy configuration service
299 // access to the the proxy configuration possibly defined by preferences.
300 virtual PrefProxyConfigTracker* GetProxyConfigTracker() = 0;
302 // Returns the Predictor object used for dns prefetch.
303 virtual chrome_browser_net::Predictor* GetNetworkPredictor() = 0;
305 // Deletes all network related data since |time|. It deletes transport
306 // security state since |time| and it also deletes HttpServerProperties data.
307 // Works asynchronously, however if the |completion| callback is non-null, it
308 // will be posted on the UI thread once the removal process completes.
309 // Be aware that theoretically it is possible that |completion| will be
310 // invoked after the Profile instance has been destroyed.
311 virtual void ClearNetworkingHistorySince(base::Time time,
312 const base::Closure& completion) = 0;
314 // Returns the home page for this profile.
315 virtual GURL GetHomePage() = 0;
317 // Returns whether or not the profile was created by a version of Chrome
318 // more recent (or equal to) the one specified.
319 virtual bool WasCreatedByVersionOrLater(const std::string& version) = 0;
321 std::string GetDebugName();
323 // Returns whether it is a guest session.
324 static bool IsGuestSession();
326 // Did the user restore the last session? This is set by SessionRestore.
327 void set_restored_last_session(bool restored_last_session) {
328 restored_last_session_ = restored_last_session;
330 bool restored_last_session() const {
331 return restored_last_session_;
334 // Sets the ExitType for the profile. This may be invoked multiple times
335 // during shutdown; only the first such change (the transition from
336 // EXIT_CRASHED to one of the other values) is written to prefs, any
337 // later calls are ignored.
339 // NOTE: this is invoked internally on a normal shutdown, but is public so
340 // that it can be invoked when the user logs out/powers down (WM_ENDSESSION),
341 // or to handle backgrounding/foregrounding on mobile.
342 virtual void SetExitType(ExitType exit_type) = 0;
344 // Returns how the last session was shutdown.
345 virtual ExitType GetLastSessionExitType() = 0;
347 // Stop sending accessibility events until ResumeAccessibilityEvents().
348 // Calls to Pause nest; no events will be sent until the number of
349 // Resume calls matches the number of Pause calls received.
350 void PauseAccessibilityEvents() {
351 accessibility_pause_level_++;
354 void ResumeAccessibilityEvents() {
355 DCHECK_GT(accessibility_pause_level_, 0);
356 accessibility_pause_level_--;
359 bool ShouldSendAccessibilityEvents() {
360 return 0 == accessibility_pause_level_;
363 // Checks whether sync is configurable by the user. Returns false if sync is
364 // disabled or controlled by configuration management.
365 bool IsSyncAccessible();
367 // Send NOTIFICATION_PROFILE_DESTROYED for this Profile, if it has not
368 // already been sent. It is necessary because most Profiles are destroyed by
369 // ProfileDestroyer, but in tests, some are not.
370 void MaybeSendDestroyedNotification();
372 // Creates an OffTheRecordProfile which points to this Profile.
373 Profile* CreateOffTheRecordProfile();
375 protected:
376 // TODO(erg, willchan): Remove friendship once |ProfileIOData| is made into
377 // a |ProfileKeyedService|.
378 friend class ChromeURLDataManagerFactory;
379 friend class OffTheRecordProfileImpl;
381 // Returns a callback to a method returning a |ChromeURLDataManagerBackend|.
382 // Used to create a |ChromeURLDataManager| for this |Profile|.
383 // TODO(erg, willchan): Remove this once |ProfileIOData| is made into a
384 // |ProfileKeyedService|.
385 virtual base::Callback<ChromeURLDataManagerBackend*(void)>
386 GetChromeURLDataManagerBackendGetter() const = 0;
388 private:
389 bool restored_last_session_;
391 // Used to prevent the notification that this Profile is destroyed from
392 // being sent twice.
393 bool sent_destroyed_notification_;
395 // Accessibility events will only be propagated when the pause
396 // level is zero. PauseAccessibilityEvents and ResumeAccessibilityEvents
397 // increment and decrement the level, respectively, rather than set it to
398 // true or false, so that calls can be nested.
399 int accessibility_pause_level_;
402 #if defined(COMPILER_GCC)
403 namespace BASE_HASH_NAMESPACE {
405 template<>
406 struct hash<Profile*> {
407 std::size_t operator()(Profile* const& p) const {
408 return reinterpret_cast<std::size_t>(p);
412 } // namespace BASE_HASH_NAMESPACE
413 #endif
415 #endif // CHROME_BROWSER_PROFILES_PROFILE_H_