Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: chrome/browser/profile.h

Issue 5606002: Move:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/process_singleton_win.cc ('k') | chrome/browser/profile.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 // This class gathers state related to a single user profile.
6
7 #ifndef CHROME_BROWSER_PROFILE_H_
8 #define CHROME_BROWSER_PROFILE_H_
9 #pragma once
10
11 #include "base/basictypes.h"
12 #include "base/logging.h"
13
14 namespace base {
15 class Time;
16 }
17
18 #if defined(OS_CHROMEOS)
19 namespace chromeos {
20 class EnterpriseExtensionObserver;
21 class ProxyConfigServiceImpl;
22 }
23 #endif
24
25 namespace history {
26 class TopSites;
27 }
28
29 namespace net {
30 class TransportSecurityState;
31 class SSLConfigService;
32 }
33
34 namespace policy {
35 class ProfilePolicyContext;
36 }
37
38 namespace webkit_database {
39 class DatabaseTracker;
40 }
41
42 class AutocompleteClassifier;
43 class BackgroundContentsService;
44 class BackgroundModeManager;
45 class BookmarkModel;
46 class BrowserSignin;
47 class BrowserThemeProvider;
48 class ChromeAppCacheService;
49 class ChromeBlobStorageContext;
50 class ChromeURLRequestContextGetter;
51 class CloudPrintProxyService;
52 class DesktopNotificationService;
53 class DownloadManager;
54 class Extension;
55 class ExtensionDevToolsManager;
56 class ExtensionEventRouter;
57 class ExtensionMessageService;
58 class ExtensionProcessManager;
59 class ExtensionsService;
60 class FaviconService;
61 class FilePath;
62 class BrowserFileSystemContext;
63 class FindBarState;
64 class GeolocationContentSettingsMap;
65 class GeolocationPermissionContext;
66 class HistoryService;
67 class HostContentSettingsMap;
68 class HostZoomMap;
69 class NavigationController;
70 class NTPResourceCache;
71 class PasswordStore;
72 class PersonalDataManager;
73 class PinnedTabService;
74 class PrefService;
75 class ExtensionInfoMap;
76 class PrefProxyConfigTracker;
77 class PromoCounter;
78 class ProfileSyncService;
79 class ProfileSyncFactory;
80 class SessionService;
81 class SpellCheckHost;
82 class SSLConfigServiceManager;
83 class SSLHostState;
84 class StatusTray;
85 class TransportSecurityPersister;
86 class SQLitePersistentCookieStore;
87 class TabRestoreService;
88 class TemplateURLFetcher;
89 class TemplateURLModel;
90 class ThemeProvider;
91 class TokenService;
92 class URLRequestContextGetter;
93 class UserScriptMaster;
94 class UserStyleSheetWatcher;
95 class VisitedLinkMaster;
96 class VisitedLinkEventListener;
97 class WebDataService;
98 class WebKitContext;
99 class WebResourceService;
100
101 typedef intptr_t ProfileId;
102
103 class Profile {
104 public:
105 // Profile services are accessed with the following parameter. This parameter
106 // defines what the caller plans to do with the service.
107 // The caller is responsible for not performing any operation that would
108 // result in persistent implicit records while using an OffTheRecord profile.
109 // This flag allows the profile to perform an additional check.
110 //
111 // It also gives us an opportunity to perform further checks in the future. We
112 // could, for example, return an history service that only allow some specific
113 // methods.
114 enum ServiceAccessType {
115 // The caller plans to perform a read or write that takes place as a result
116 // of the user input. Use this flag when the operation you are doing can be
117 // performed while off the record. (ex: creating a bookmark)
118 //
119 // Since EXPLICIT_ACCESS means "as a result of a user action", this request
120 // always succeeds.
121 EXPLICIT_ACCESS,
122
123 // The caller plans to call a method that will permanently change some data
124 // in the profile, as part of Chrome's implicit data logging. Use this flag
125 // when you are about to perform an operation which is incompatible with the
126 // off the record mode.
127 IMPLICIT_ACCESS
128 };
129
130 // Value that represents no profile Id.
131 static const ProfileId InvalidProfileId;
132
133 Profile() : restored_last_session_(false), accessibility_pause_level_(0) {}
134 virtual ~Profile() {}
135
136 // Profile prefs are registered as soon as the prefs are loaded for the first
137 // time.
138 static void RegisterUserPrefs(PrefService* prefs);
139
140 // Create a new profile given a path.
141 static Profile* CreateProfile(const FilePath& path);
142
143 // Returns the request context for the "default" profile. This may be called
144 // from any thread. This CAN return NULL if a first request context has not
145 // yet been created. If necessary, listen on the UI thread for
146 // NOTIFY_DEFAULT_REQUEST_CONTEXT_AVAILABLE.
147 static URLRequestContextGetter* GetDefaultRequestContext();
148
149 // Returns a unique Id that can be used to identify this profile at runtime.
150 // This Id is not persistent and will not survive a restart of the browser.
151 virtual ProfileId GetRuntimeId() = 0;
152
153 // Returns the path of the directory where this profile's data is stored.
154 virtual FilePath GetPath() = 0;
155
156 // Return whether this profile is off the record. Default is false.
157 virtual bool IsOffTheRecord() = 0;
158
159 // Return the off the record version of this profile. The returned pointer
160 // is owned by the receiving profile. If the receiving profile is off the
161 // record, the same profile is returned.
162 virtual Profile* GetOffTheRecordProfile() = 0;
163
164 // Destroys the off the record profile.
165 virtual void DestroyOffTheRecordProfile() = 0;
166
167 // True if an off the record profile exists.
168 virtual bool HasOffTheRecordProfile() = 0;
169
170 // Return the original "recording" profile. This method returns this if the
171 // profile is not off the record.
172 virtual Profile* GetOriginalProfile() = 0;
173
174 // Returns a pointer to the ChromeAppCacheService instance for this profile.
175 virtual ChromeAppCacheService* GetAppCacheService() = 0;
176
177 // Returns a pointer to the DatabaseTracker instance for this profile.
178 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0;
179
180 // Returns a pointer to the TopSites (thumbnail manager) instance
181 // for this profile.
182 virtual history::TopSites* GetTopSites() = 0;
183
184 // Variant of GetTopSites that doesn't force creation.
185 virtual history::TopSites* GetTopSitesWithoutCreating() = 0;
186
187 // Retrieves a pointer to the VisitedLinkMaster associated with this
188 // profile. The VisitedLinkMaster is lazily created the first time
189 // that this method is called.
190 virtual VisitedLinkMaster* GetVisitedLinkMaster() = 0;
191
192 // Retrieves a pointer to the ExtensionsService associated with this
193 // profile. The ExtensionsService is created at startup.
194 virtual ExtensionsService* GetExtensionsService() = 0;
195
196 // Retrieves a pointer to the UserScriptMaster associated with this
197 // profile. The UserScriptMaster is lazily created the first time
198 // that this method is called.
199 virtual UserScriptMaster* GetUserScriptMaster() = 0;
200
201 // Retrieves a pointer to the ExtensionDevToolsManager associated with this
202 // profile. The instance is created at startup.
203 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() = 0;
204
205 // Retrieves a pointer to the ExtensionProcessManager associated with this
206 // profile. The instance is created at startup.
207 virtual ExtensionProcessManager* GetExtensionProcessManager() = 0;
208
209 // Retrieves a pointer to the ExtensionMessageService associated with this
210 // profile. The instance is created at startup.
211 virtual ExtensionMessageService* GetExtensionMessageService() = 0;
212
213 // Accessor. The instance is created at startup.
214 virtual ExtensionEventRouter* GetExtensionEventRouter() = 0;
215
216 // Retrieves a pointer to the SSLHostState associated with this profile.
217 // The SSLHostState is lazily created the first time that this method is
218 // called.
219 virtual SSLHostState* GetSSLHostState() = 0;
220
221 // Retrieves a pointer to the TransportSecurityState associated with
222 // this profile. The TransportSecurityState is lazily created the
223 // first time that this method is called.
224 virtual net::TransportSecurityState*
225 GetTransportSecurityState() = 0;
226
227 // Retrieves a pointer to the FaviconService associated with this
228 // profile. The FaviconService is lazily created the first time
229 // that this method is called.
230 //
231 // Although FaviconService is refcounted, this will not addref, and callers
232 // do not need to do any reference counting as long as they keep the pointer
233 // only for the local scope (which they should do anyway since the browser
234 // process may decide to shut down).
235 //
236 // |access| defines what the caller plans to do with the service. See
237 // the ServiceAccessType definition above.
238 virtual FaviconService* GetFaviconService(ServiceAccessType access) = 0;
239
240 // Retrieves a pointer to the HistoryService associated with this
241 // profile. The HistoryService is lazily created the first time
242 // that this method is called.
243 //
244 // Although HistoryService is refcounted, this will not addref, and callers
245 // do not need to do any reference counting as long as they keep the pointer
246 // only for the local scope (which they should do anyway since the browser
247 // process may decide to shut down).
248 //
249 // |access| defines what the caller plans to do with the service. See
250 // the ServiceAccessType definition above.
251 virtual HistoryService* GetHistoryService(ServiceAccessType access) = 0;
252
253 // Similar to GetHistoryService(), but won't create the history service if it
254 // doesn't already exist.
255 virtual HistoryService* GetHistoryServiceWithoutCreating() = 0;
256
257 // Retrieves a pointer to the AutocompleteClassifier associated with this
258 // profile. The AutocompleteClassifier is lazily created the first time that
259 // this method is called.
260 virtual AutocompleteClassifier* GetAutocompleteClassifier() = 0;
261
262 // Returns the WebDataService for this profile. This is owned by
263 // the Profile. Callers that outlive the life of this profile need to be
264 // sure they refcount the returned value.
265 //
266 // |access| defines what the caller plans to do with the service. See
267 // the ServiceAccessType definition above.
268 virtual WebDataService* GetWebDataService(ServiceAccessType access) = 0;
269
270 // Similar to GetWebDataService(), but won't create the web data service if it
271 // doesn't already exist.
272 virtual WebDataService* GetWebDataServiceWithoutCreating() = 0;
273
274 // Returns the PasswordStore for this profile. This is owned by the Profile.
275 virtual PasswordStore* GetPasswordStore(ServiceAccessType access) = 0;
276
277 // Retrieves a pointer to the PrefService that manages the preferences
278 // for this user profile. The PrefService is lazily created the first
279 // time that this method is called.
280 virtual PrefService* GetPrefs() = 0;
281
282 // Returns the TemplateURLModel for this profile. This is owned by the
283 // the Profile.
284 virtual TemplateURLModel* GetTemplateURLModel() = 0;
285
286 // Returns the TemplateURLFetcher for this profile. This is owned by the
287 // profile.
288 virtual TemplateURLFetcher* GetTemplateURLFetcher() = 0;
289
290 // Returns the DownloadManager associated with this profile.
291 virtual DownloadManager* GetDownloadManager() = 0;
292 virtual bool HasCreatedDownloadManager() const = 0;
293
294 // Returns the PersonalDataManager associated with this profile.
295 virtual PersonalDataManager* GetPersonalDataManager() = 0;
296
297 // Returns the FileSystemContext associated to this profile. The context
298 // is lazily created the first time this method is called. This is owned
299 // by the profile.
300 virtual BrowserFileSystemContext* GetFileSystemContext() = 0;
301
302 // Returns the BrowserSignin object assigned to this profile.
303 virtual BrowserSignin* GetBrowserSignin() = 0;
304
305 // Init our themes system.
306 virtual void InitThemes() = 0;
307
308 // Set the theme to the specified extension.
309 virtual void SetTheme(const Extension* extension) = 0;
310
311 // Set the theme to the machine's native theme.
312 virtual void SetNativeTheme() = 0;
313
314 // Clear the theme and reset it to default.
315 virtual void ClearTheme() = 0;
316
317 // Gets the theme that was last set. Returns NULL if the theme is no longer
318 // installed, if there is no installed theme, or the theme was cleared.
319 virtual const Extension* GetTheme() = 0;
320
321 // Returns or creates the ThemeProvider associated with this profile
322 virtual BrowserThemeProvider* GetThemeProvider() = 0;
323
324 // Returns the request context information associated with this profile. Call
325 // this only on the UI thread, since it can send notifications that should
326 // happen on the UI thread.
327 virtual URLRequestContextGetter* GetRequestContext() = 0;
328
329 // Returns the request context for media resources asociated with this
330 // profile.
331 virtual URLRequestContextGetter* GetRequestContextForMedia() = 0;
332
333 // Returns the request context used for extension-related requests. This
334 // is only used for a separate cookie store currently.
335 virtual URLRequestContextGetter* GetRequestContextForExtensions() = 0;
336
337 // Called by the ExtensionsService that lives in this profile. Gives the
338 // profile a chance to react to the load event before the EXTENSION_LOADED
339 // notification has fired. The purpose for handling this event first is to
340 // avoid race conditions by making sure URLRequestContexts learn about new
341 // extensions before anything else needs them to know.
342 virtual void RegisterExtensionWithRequestContexts(
343 const Extension* extension) {}
344
345 // Called by the ExtensionsService that lives in this profile. Lets the
346 // profile clean up its RequestContexts once all the listeners to the
347 // EXTENSION_UNLOADED notification have finished running.
348 virtual void UnregisterExtensionWithRequestContexts(
349 const Extension* extension) {}
350
351 // Returns the SSLConfigService for this profile.
352 virtual net::SSLConfigService* GetSSLConfigService() = 0;
353
354 // Returns the Hostname <-> Content settings map for this profile.
355 virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0;
356
357 // Returns the Hostname <-> Zoom Level map for this profile.
358 virtual HostZoomMap* GetHostZoomMap() = 0;
359
360 // Returns the geolocation settings map for this profile.
361 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() = 0;
362
363 // Returns the geolocation permission context for this profile.
364 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0;
365
366 // Returns the user style sheet watcher.
367 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() = 0;
368
369 // Returns the find bar state for this profile. The find bar state is lazily
370 // created the first time that this method is called.
371 virtual FindBarState* GetFindBarState() = 0;
372
373 // Returns the session service for this profile. This may return NULL. If
374 // this profile supports a session service (it isn't off the record), and
375 // the session service hasn't yet been created, this forces creation of
376 // the session service.
377 //
378 // This returns NULL in two situations: the profile is off the record, or the
379 // session service has been explicitly shutdown (browser is exiting). Callers
380 // should always check the return value for NULL.
381 virtual SessionService* GetSessionService() = 0;
382
383 // If this profile has a session service, it is shut down. To properly record
384 // the current state this forces creation of the session service, then shuts
385 // it down.
386 virtual void ShutdownSessionService() = 0;
387
388 // Returns true if this profile has a session service.
389 virtual bool HasSessionService() const = 0;
390
391 // Returns true if this profile has a profile sync service.
392 virtual bool HasProfileSyncService() const = 0;
393
394 // Returns true if the last time this profile was open it was exited cleanly.
395 virtual bool DidLastSessionExitCleanly() = 0;
396
397 // Returns the BookmarkModel, creating if not yet created.
398 virtual BookmarkModel* GetBookmarkModel() = 0;
399
400 // Returns the Gaia Token Service, creating if not yet created.
401 virtual TokenService* GetTokenService() = 0;
402
403 // Returns the ProfileSyncService, creating if not yet created.
404 virtual ProfileSyncService* GetProfileSyncService() = 0;
405
406 // Returns the ProfileSyncService, creating if not yet created, with
407 // the specified CrOS username.
408 virtual ProfileSyncService* GetProfileSyncService(
409 const std::string& cros_user) = 0;
410
411 // Returns the CloudPrintProxyService, creating if not yet created.
412 virtual CloudPrintProxyService* GetCloudPrintProxyService() = 0;
413
414 // Return whether 2 profiles are the same. 2 profiles are the same if they
415 // represent the same profile. This can happen if there is pointer equality
416 // or if one profile is the off the record version of another profile (or vice
417 // versa).
418 virtual bool IsSameProfile(Profile* profile) = 0;
419
420 // Returns the time the profile was started. This is not the time the profile
421 // was created, rather it is the time the user started chrome and logged into
422 // this profile. For the single profile case, this corresponds to the time
423 // the user started chrome.
424 virtual base::Time GetStartTime() const = 0;
425
426 // Returns the TabRestoreService. This returns NULL when off the record.
427 virtual TabRestoreService* GetTabRestoreService() = 0;
428
429 virtual void ResetTabRestoreService() = 0;
430
431 // May return NULL.
432 virtual SpellCheckHost* GetSpellCheckHost() = 0;
433
434 // If |force| is false, and the spellchecker is already initialized (or is in
435 // the process of initializing), then do nothing. Otherwise clobber the
436 // current spellchecker and replace it with a new one.
437 virtual void ReinitializeSpellCheckHost(bool force) = 0;
438
439 // Returns the WebKitContext assigned to this profile.
440 virtual WebKitContext* GetWebKitContext() = 0;
441
442 // Returns the provider of desktop notifications for this profile.
443 virtual DesktopNotificationService* GetDesktopNotificationService() = 0;
444
445 // Returns the service that manages BackgroundContents for this profile.
446 virtual BackgroundContentsService* GetBackgroundContentsService() const = 0;
447
448 // Returns the StatusTray, which provides an API for displaying status icons
449 // in the system status tray. Returns NULL if status icons are not supported
450 // on this platform (or this is a unit test).
451 virtual StatusTray* GetStatusTray() = 0;
452
453 // Marks the profile as cleanly shutdown.
454 //
455 // NOTE: this is invoked internally on a normal shutdown, but is public so
456 // that it can be invoked when the user logs out/powers down (WM_ENDSESSION).
457 virtual void MarkAsCleanShutdown() = 0;
458
459 virtual void InitExtensions() = 0;
460
461 // Start up service that gathers data from a web resource feed.
462 virtual void InitWebResources() = 0;
463
464 // Returns the new tab page resource cache.
465 virtual NTPResourceCache* GetNTPResourceCache() = 0;
466
467 // Returns the last directory that was chosen for uploading or opening a file.
468 virtual FilePath last_selected_directory() = 0;
469 virtual void set_last_selected_directory(const FilePath& path) = 0;
470
471 // Returns a pointer to the ChromeBlobStorageContext instance for this
472 // profile.
473 virtual ChromeBlobStorageContext* GetBlobStorageContext() = 0;
474
475 // Returns the IO-thread-accessible profile data for this profile.
476 virtual ExtensionInfoMap* GetExtensionInfoMap() = 0;
477
478 // Returns the PromoCounter for Instant, or NULL if not applicable.
479 virtual PromoCounter* GetInstantPromoCounter() = 0;
480
481 // Gets the policy context associated with this profile.
482 virtual policy::ProfilePolicyContext* GetPolicyContext() = 0;
483
484 #if defined(OS_CHROMEOS)
485 // Returns ChromeOS's ProxyConfigServiceImpl, creating if not yet created.
486 virtual chromeos::ProxyConfigServiceImpl*
487 GetChromeOSProxyConfigServiceImpl() = 0;
488
489 // Creates ChromeOS's EnterpriseExtensionListener.
490 virtual void SetupChromeOSEnterpriseExtensionObserver() = 0;
491
492 #endif // defined(OS_CHROMEOS)
493
494 // Returns the helper object that provides the proxy configuration service
495 // access to the the proxy configuration possibly defined by preferences.
496 virtual PrefProxyConfigTracker* GetProxyConfigTracker() = 0;
497
498 #ifdef UNIT_TEST
499 // Use with caution. GetDefaultRequestContext may be called on any thread!
500 static void set_default_request_context(URLRequestContextGetter* c) {
501 default_request_context_ = c;
502 }
503 #endif
504
505 // Did the user restore the last session? This is set by SessionRestore.
506 void set_restored_last_session(bool restored_last_session) {
507 restored_last_session_ = restored_last_session;
508 }
509 bool restored_last_session() const {
510 return restored_last_session_;
511 }
512
513 // Stop sending accessibility events until ResumeAccessibilityEvents().
514 // Calls to Pause nest; no events will be sent until the number of
515 // Resume calls matches the number of Pause calls received.
516 void PauseAccessibilityEvents() {
517 accessibility_pause_level_++;
518 }
519
520 void ResumeAccessibilityEvents() {
521 DCHECK(accessibility_pause_level_ > 0);
522 accessibility_pause_level_--;
523 }
524
525 bool ShouldSendAccessibilityEvents() {
526 return 0 == accessibility_pause_level_;
527 }
528
529 // Checks whether sync is configurable by the user. Returns false if sync is
530 // disabled or controlled by configuration management.
531 bool IsSyncAccessible();
532
533 // Creates an OffTheRecordProfile which points to this Profile.
534 Profile* CreateOffTheRecordProfile();
535
536 protected:
537 static URLRequestContextGetter* default_request_context_;
538
539 private:
540 bool restored_last_session_;
541
542 // Accessibility events will only be propagated when the pause
543 // level is zero. PauseAccessibilityEvents and ResumeAccessibilityEvents
544 // increment and decrement the level, respectively, rather than set it to
545 // true or false, so that calls can be nested.
546 int accessibility_pause_level_;
547 };
548
549 #endif // CHROME_BROWSER_PROFILE_H_
OLDNEW
« no previous file with comments | « chrome/browser/process_singleton_win.cc ('k') | chrome/browser/profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698