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

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

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/profile.h ('k') | chrome/browser/profile_impl.h » ('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 #include "chrome/browser/profile.h"
6
7 #include "app/resource_bundle.h"
8 #include "base/command_line.h"
9 #include "base/file_path.h"
10 #include "base/file_util.h"
11 #include "base/path_service.h"
12 #include "base/scoped_ptr.h"
13 #include "base/string_util.h"
14 #include "chrome/browser/background_contents_service.h"
15 #include "chrome/browser/browser_list.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/browser_thread.h"
18 #include "chrome/browser/chrome_blob_storage_context.h"
19 #include "chrome/browser/download/download_manager.h"
20 #include "chrome/browser/extensions/extension_message_service.h"
21 #include "chrome/browser/extensions/extension_process_manager.h"
22 #include "chrome/browser/file_system/browser_file_system_context.h"
23 #include "chrome/browser/in_process_webkit/webkit_context.h"
24 #include "chrome/browser/net/chrome_url_request_context.h"
25 #include "chrome/browser/notifications/desktop_notification_service.h"
26 #include "chrome/browser/ssl/ssl_host_state.h"
27 #include "chrome/browser/sync/profile_sync_service.h"
28 #include "chrome/browser/themes/browser_theme_provider.h"
29 #include "chrome/browser/ui/find_bar/find_bar_state.h"
30 #include "chrome/common/chrome_constants.h"
31 #include "chrome/common/chrome_paths.h"
32 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/json_pref_store.h"
34 #include "chrome/common/notification_service.h"
35 #include "chrome/common/pref_names.h"
36 #include "chrome/common/render_messages.h"
37 #include "grit/browser_resources.h"
38 #include "grit/locale_settings.h"
39 #include "net/base/transport_security_state.h"
40 #include "webkit/database/database_tracker.h"
41 #if defined(TOOLKIT_USES_GTK)
42 #include "chrome/browser/gtk/gtk_theme_provider.h"
43 #endif
44
45 #if defined(OS_WIN)
46 #include "chrome/browser/password_manager/password_store_win.h"
47 #elif defined(OS_MACOSX)
48 #include "chrome/browser/keychain_mac.h"
49 #include "chrome/browser/password_manager/password_store_mac.h"
50 #elif defined(OS_POSIX) && !defined(OS_CHROMEOS)
51 #include "chrome/browser/password_manager/native_backend_gnome_x.h"
52 #include "chrome/browser/password_manager/native_backend_kwallet_x.h"
53 #include "chrome/browser/password_manager/password_store_x.h"
54 #endif
55
56 using base::Time;
57 using base::TimeDelta;
58
59 // A pointer to the request context for the default profile. See comments on
60 // Profile::GetDefaultRequestContext.
61 URLRequestContextGetter* Profile::default_request_context_;
62
63 namespace {
64
65 // TODO(pathorn): Duplicated in profile_impl.cc
66 void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
67 if (context)
68 context->CleanupOnUIThread();
69 }
70
71 } // namespace
72
73 // static
74 const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
75
76 // static
77 void Profile::RegisterUserPrefs(PrefService* prefs) {
78 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
79 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
80 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
81 prefs->RegisterBooleanPref(prefs::kSafeBrowsingReportingEnabled, false);
82 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
83 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
84 IDS_SPELLCHECK_DICTIONARY);
85 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
86 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
87 #if defined(TOOLKIT_USES_GTK)
88 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
89 GtkThemeProvider::DefaultUsesSystemTheme());
90 #endif
91 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
92 prefs->RegisterStringPref(prefs::kCurrentThemeID,
93 BrowserThemeProvider::kDefaultThemeID);
94 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
95 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
96 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
97 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
98 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
99 prefs->RegisterStringPref(prefs::kSelectFileLastDirectory, "");
100 #if defined(OS_CHROMEOS)
101 // TODO(dilmah): For OS_CHROMEOS we maintain kApplicationLocale in both
102 // local state and user's profile. For other platforms we maintain
103 // kApplicationLocale only in local state.
104 // In the future we may want to maintain kApplicationLocale
105 // in user's profile for other platforms as well.
106 prefs->RegisterStringPref(prefs::kApplicationLocale, "");
107 #endif
108 }
109
110 // static
111 URLRequestContextGetter* Profile::GetDefaultRequestContext() {
112 return default_request_context_;
113 }
114
115 bool Profile::IsSyncAccessible() {
116 ProfileSyncService* syncService = GetProfileSyncService();
117 return syncService && !syncService->IsManaged();
118 }
119
120 ////////////////////////////////////////////////////////////////////////////////
121 //
122 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
123 // to make it suitable for the off the record mode.
124 //
125 ////////////////////////////////////////////////////////////////////////////////
126 class OffTheRecordProfileImpl : public Profile,
127 public BrowserList::Observer {
128 public:
129 explicit OffTheRecordProfileImpl(Profile* real_profile)
130 : profile_(real_profile),
131 start_time_(Time::Now()) {
132 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
133 extension_process_manager_.reset(ExtensionProcessManager::Create(this));
134
135 BrowserList::AddObserver(this);
136
137 background_contents_service_.reset(
138 new BackgroundContentsService(this, CommandLine::ForCurrentProcess()));
139 }
140
141 virtual ~OffTheRecordProfileImpl() {
142 NotificationService::current()->Notify(NotificationType::PROFILE_DESTROYED,
143 Source<Profile>(this),
144 NotificationService::NoDetails());
145 CleanupRequestContext(request_context_);
146 CleanupRequestContext(extensions_request_context_);
147
148 // Clean up all DB files/directories
149 BrowserThread::PostTask(
150 BrowserThread::FILE, FROM_HERE,
151 NewRunnableMethod(
152 db_tracker_.get(),
153 &webkit_database::DatabaseTracker::DeleteIncognitoDBDirectory));
154
155 BrowserList::RemoveObserver(this);
156 }
157
158 virtual ProfileId GetRuntimeId() {
159 return reinterpret_cast<ProfileId>(this);
160 }
161
162 virtual FilePath GetPath() { return profile_->GetPath(); }
163
164 virtual bool IsOffTheRecord() {
165 return true;
166 }
167
168 virtual Profile* GetOffTheRecordProfile() {
169 return this;
170 }
171
172 virtual void DestroyOffTheRecordProfile() {
173 // Suicide is bad!
174 NOTREACHED();
175 }
176
177 virtual bool HasOffTheRecordProfile() {
178 return true;
179 }
180
181 virtual Profile* GetOriginalProfile() {
182 return profile_;
183 }
184
185 virtual ChromeAppCacheService* GetAppCacheService() {
186 if (!appcache_service_) {
187 appcache_service_ = new ChromeAppCacheService;
188 BrowserThread::PostTask(
189 BrowserThread::IO, FROM_HERE,
190 NewRunnableMethod(appcache_service_.get(),
191 &ChromeAppCacheService::InitializeOnIOThread,
192 GetPath(), IsOffTheRecord(),
193 make_scoped_refptr(GetHostContentSettingsMap())));
194 }
195 return appcache_service_;
196 }
197
198 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
199 if (!db_tracker_) {
200 db_tracker_ = new webkit_database::DatabaseTracker(
201 GetPath(), IsOffTheRecord());
202 }
203 return db_tracker_;
204 }
205
206 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
207 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
208 // because we don't want to leak the sites that the user has visited before.
209 return NULL;
210 }
211
212 virtual ExtensionsService* GetExtensionsService() {
213 return GetOriginalProfile()->GetExtensionsService();
214 }
215
216 virtual BackgroundContentsService* GetBackgroundContentsService() const {
217 return background_contents_service_.get();
218 }
219
220 virtual StatusTray* GetStatusTray() {
221 return GetOriginalProfile()->GetStatusTray();
222 }
223
224 virtual UserScriptMaster* GetUserScriptMaster() {
225 return GetOriginalProfile()->GetUserScriptMaster();
226 }
227
228 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
229 // TODO(mpcomplete): figure out whether we should return the original
230 // profile's version.
231 return NULL;
232 }
233
234 virtual ExtensionProcessManager* GetExtensionProcessManager() {
235 return extension_process_manager_.get();
236 }
237
238 virtual ExtensionMessageService* GetExtensionMessageService() {
239 return GetOriginalProfile()->GetExtensionMessageService();
240 }
241
242 virtual ExtensionEventRouter* GetExtensionEventRouter() {
243 return GetOriginalProfile()->GetExtensionEventRouter();
244 }
245
246 virtual SSLHostState* GetSSLHostState() {
247 if (!ssl_host_state_.get())
248 ssl_host_state_.reset(new SSLHostState());
249
250 DCHECK(ssl_host_state_->CalledOnValidThread());
251 return ssl_host_state_.get();
252 }
253
254 virtual net::TransportSecurityState* GetTransportSecurityState() {
255 if (!transport_security_state_.get())
256 transport_security_state_ = new net::TransportSecurityState();
257
258 return transport_security_state_.get();
259 }
260
261 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
262 if (sat == EXPLICIT_ACCESS)
263 return profile_->GetHistoryService(sat);
264
265 NOTREACHED() << "This profile is OffTheRecord";
266 return NULL;
267 }
268
269 virtual HistoryService* GetHistoryServiceWithoutCreating() {
270 return profile_->GetHistoryServiceWithoutCreating();
271 }
272
273 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
274 if (sat == EXPLICIT_ACCESS)
275 return profile_->GetFaviconService(sat);
276
277 NOTREACHED() << "This profile is OffTheRecord";
278 return NULL;
279 }
280
281 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
282 return profile_->GetAutocompleteClassifier();
283 }
284
285 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
286 if (sat == EXPLICIT_ACCESS)
287 return profile_->GetWebDataService(sat);
288
289 NOTREACHED() << "This profile is OffTheRecord";
290 return NULL;
291 }
292
293 virtual WebDataService* GetWebDataServiceWithoutCreating() {
294 return profile_->GetWebDataServiceWithoutCreating();
295 }
296
297 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
298 if (sat == EXPLICIT_ACCESS)
299 return profile_->GetPasswordStore(sat);
300
301 NOTREACHED() << "This profile is OffTheRecord";
302 return NULL;
303 }
304
305 virtual PrefService* GetPrefs() {
306 return profile_->GetPrefs();
307 }
308
309 virtual TemplateURLModel* GetTemplateURLModel() {
310 return profile_->GetTemplateURLModel();
311 }
312
313 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
314 return profile_->GetTemplateURLFetcher();
315 }
316
317 virtual DownloadManager* GetDownloadManager() {
318 if (!download_manager_.get()) {
319 scoped_refptr<DownloadManager> dlm(
320 new DownloadManager(g_browser_process->download_status_updater()));
321 dlm->Init(this);
322 download_manager_.swap(dlm);
323 }
324 return download_manager_.get();
325 }
326
327 virtual bool HasCreatedDownloadManager() const {
328 return (download_manager_.get() != NULL);
329 }
330
331 virtual PersonalDataManager* GetPersonalDataManager() {
332 return NULL;
333 }
334
335 virtual BrowserFileSystemContext* GetFileSystemContext() {
336 if (!browser_file_system_context_)
337 browser_file_system_context_ = new BrowserFileSystemContext(
338 GetPath(), IsOffTheRecord());
339 DCHECK(browser_file_system_context_.get());
340 return browser_file_system_context_.get();
341 }
342
343 virtual void InitThemes() {
344 profile_->InitThemes();
345 }
346
347 virtual void SetTheme(const Extension* extension) {
348 profile_->SetTheme(extension);
349 }
350
351 virtual void SetNativeTheme() {
352 profile_->SetNativeTheme();
353 }
354
355 virtual void ClearTheme() {
356 profile_->ClearTheme();
357 }
358
359 virtual const Extension* GetTheme() {
360 return profile_->GetTheme();
361 }
362
363 virtual BrowserThemeProvider* GetThemeProvider() {
364 return profile_->GetThemeProvider();
365 }
366
367 virtual URLRequestContextGetter* GetRequestContext() {
368 return request_context_;
369 }
370
371 virtual URLRequestContextGetter* GetRequestContextForMedia() {
372 // In OTR mode, media request context is the same as the original one.
373 return request_context_;
374 }
375
376 URLRequestContextGetter* GetRequestContextForExtensions() {
377 if (!extensions_request_context_) {
378 extensions_request_context_ =
379 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this);
380 }
381
382 return extensions_request_context_;
383 }
384
385 virtual net::SSLConfigService* GetSSLConfigService() {
386 return profile_->GetSSLConfigService();
387 }
388
389 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
390 // Retrieve the host content settings map of the parent profile in order to
391 // ensure the preferences have been migrated.
392 profile_->GetHostContentSettingsMap();
393 if (!host_content_settings_map_.get())
394 host_content_settings_map_ = new HostContentSettingsMap(this);
395 return host_content_settings_map_.get();
396 }
397
398 virtual HostZoomMap* GetHostZoomMap() {
399 if (!host_zoom_map_)
400 host_zoom_map_ = new HostZoomMap(this);
401 return host_zoom_map_.get();
402 }
403
404 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
405 return profile_->GetGeolocationContentSettingsMap();
406 }
407
408 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() {
409 return profile_->GetGeolocationPermissionContext();
410 }
411
412 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
413 return profile_->GetUserStyleSheetWatcher();
414 }
415
416 virtual FindBarState* GetFindBarState() {
417 if (!find_bar_state_.get())
418 find_bar_state_.reset(new FindBarState());
419 return find_bar_state_.get();
420 }
421
422 virtual SessionService* GetSessionService() {
423 // Don't save any sessions when off the record.
424 return NULL;
425 }
426
427 virtual void ShutdownSessionService() {
428 // We don't allow a session service, nothing to do.
429 }
430
431 virtual bool HasSessionService() const {
432 // We never have a session service.
433 return false;
434 }
435
436 virtual bool HasProfileSyncService() const {
437 // We never have a profile sync service.
438 return false;
439 }
440
441 virtual bool DidLastSessionExitCleanly() {
442 return profile_->DidLastSessionExitCleanly();
443 }
444
445 virtual BookmarkModel* GetBookmarkModel() {
446 return profile_->GetBookmarkModel();
447 }
448
449 virtual DesktopNotificationService* GetDesktopNotificationService() {
450 if (!desktop_notification_service_.get()) {
451 desktop_notification_service_.reset(new DesktopNotificationService(
452 this, g_browser_process->notification_ui_manager()));
453 }
454 return desktop_notification_service_.get();
455 }
456
457 virtual TokenService* GetTokenService() {
458 return NULL;
459 }
460
461 virtual ProfileSyncService* GetProfileSyncService() {
462 return NULL;
463 }
464
465 virtual ProfileSyncService* GetProfileSyncService(
466 const std::string& cros_user) {
467 return NULL;
468 }
469
470 virtual BrowserSignin* GetBrowserSignin() {
471 return profile_->GetBrowserSignin();
472 }
473
474 virtual CloudPrintProxyService* GetCloudPrintProxyService() {
475 return NULL;
476 }
477
478 virtual bool IsSameProfile(Profile* profile) {
479 return (profile == this) || (profile == profile_);
480 }
481
482 virtual Time GetStartTime() const {
483 return start_time_;
484 }
485
486 virtual TabRestoreService* GetTabRestoreService() {
487 return NULL;
488 }
489
490 virtual void ResetTabRestoreService() {
491 }
492
493 virtual SpellCheckHost* GetSpellCheckHost() {
494 return profile_->GetSpellCheckHost();
495 }
496
497 virtual void ReinitializeSpellCheckHost(bool force) {
498 profile_->ReinitializeSpellCheckHost(force);
499 }
500
501 virtual WebKitContext* GetWebKitContext() {
502 if (!webkit_context_.get())
503 webkit_context_ = new WebKitContext(this, false);
504 DCHECK(webkit_context_.get());
505 return webkit_context_.get();
506 }
507
508 virtual history::TopSites* GetTopSitesWithoutCreating() {
509 return NULL;
510 }
511
512 virtual history::TopSites* GetTopSites() {
513 return NULL;
514 }
515
516 virtual void MarkAsCleanShutdown() {
517 }
518
519 virtual void InitExtensions() {
520 NOTREACHED();
521 }
522
523 virtual void InitWebResources() {
524 NOTREACHED();
525 }
526
527 virtual NTPResourceCache* GetNTPResourceCache() {
528 // Just return the real profile resource cache.
529 return profile_->GetNTPResourceCache();
530 }
531
532 virtual FilePath last_selected_directory() {
533 const FilePath& directory = last_selected_directory_;
534 if (directory.empty()) {
535 return profile_->last_selected_directory();
536 }
537 return directory;
538 }
539
540 virtual void set_last_selected_directory(const FilePath& path) {
541 last_selected_directory_ = path;
542 }
543
544 #if defined(OS_CHROMEOS)
545 virtual chromeos::ProxyConfigServiceImpl*
546 GetChromeOSProxyConfigServiceImpl() {
547 return profile_->GetChromeOSProxyConfigServiceImpl();
548 }
549
550 virtual void SetupChromeOSEnterpriseExtensionObserver() {
551 profile_->SetupChromeOSEnterpriseExtensionObserver();
552 }
553 #endif // defined(OS_CHROMEOS)
554
555 virtual void ExitedOffTheRecordMode() {
556 // DownloadManager is lazily created, so check before accessing it.
557 if (download_manager_.get()) {
558 // Drop our download manager so we forget about all the downloads made
559 // in off-the-record mode.
560 download_manager_->Shutdown();
561 download_manager_ = NULL;
562 }
563 }
564
565 virtual void OnBrowserAdded(const Browser* browser) {
566 }
567
568 virtual void OnBrowserRemoved(const Browser* browser) {
569 if (BrowserList::GetBrowserCount(this) == 0)
570 ExitedOffTheRecordMode();
571 }
572
573 virtual ChromeBlobStorageContext* GetBlobStorageContext() {
574 if (!blob_storage_context_) {
575 blob_storage_context_ = new ChromeBlobStorageContext();
576 BrowserThread::PostTask(
577 BrowserThread::IO, FROM_HERE,
578 NewRunnableMethod(
579 blob_storage_context_.get(),
580 &ChromeBlobStorageContext::InitializeOnIOThread));
581 }
582 return blob_storage_context_;
583 }
584
585 virtual ExtensionInfoMap* GetExtensionInfoMap() {
586 return profile_->GetExtensionInfoMap();
587 }
588
589 virtual policy::ProfilePolicyContext* GetPolicyContext() {
590 return NULL;
591 }
592
593 virtual PromoCounter* GetInstantPromoCounter() {
594 return NULL;
595 }
596
597 virtual PrefProxyConfigTracker* GetProxyConfigTracker() {
598 return profile_->GetProxyConfigTracker();
599 }
600
601 private:
602 NotificationRegistrar registrar_;
603
604 // The real underlying profile.
605 Profile* profile_;
606
607 scoped_ptr<ExtensionProcessManager> extension_process_manager_;
608
609 // The context to use for requests made from this OTR session.
610 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
611
612 // The context to use for requests made by an extension while in OTR mode.
613 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_;
614
615 // The download manager that only stores downloaded items in memory.
616 scoped_refptr<DownloadManager> download_manager_;
617
618 // Use a separate desktop notification service for OTR.
619 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
620
621 // We use a non-writable content settings map for OTR.
622 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
623
624 // Use a separate zoom map for OTR.
625 scoped_refptr<HostZoomMap> host_zoom_map_;
626
627 // Use a special WebKit context for OTR browsing.
628 scoped_refptr<WebKitContext> webkit_context_;
629
630 // We don't want SSLHostState from the OTR profile to leak back to the main
631 // profile because then the main profile would learn some of the host names
632 // the user visited while OTR.
633 scoped_ptr<SSLHostState> ssl_host_state_;
634
635 // Use a separate FindBarState so search terms do not leak back to the main
636 // profile.
637 scoped_ptr<FindBarState> find_bar_state_;
638
639 // The TransportSecurityState that only stores enabled sites in memory.
640 scoped_refptr<net::TransportSecurityState>
641 transport_security_state_;
642
643 // Time we were started.
644 Time start_time_;
645
646 scoped_refptr<ChromeAppCacheService> appcache_service_;
647
648 // The main database tracker for this profile.
649 // Should be used only on the file thread.
650 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
651
652 FilePath last_selected_directory_;
653
654 // Tracks all BackgroundContents running under this profile.
655 scoped_ptr<BackgroundContentsService> background_contents_service_;
656
657 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
658
659 // The file_system context for this profile.
660 scoped_refptr<BrowserFileSystemContext> browser_file_system_context_;
661
662 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
663 };
664
665 Profile* Profile::CreateOffTheRecordProfile() {
666 return new OffTheRecordProfileImpl(this);
667 }
OLDNEW
« no previous file with comments | « chrome/browser/profile.h ('k') | chrome/browser/profile_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698