blob: 2db89ac3333a78133c0eee493ed9c0563b94672d [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/profile.h"
6
[email protected]2735e3692009-09-25 18:19:397#include "app/theme_provider.h"
initial.commit09911bf2008-07-26 23:55:298#include "base/command_line.h"
[email protected]04fba9a92008-10-28 17:25:259#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4410#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/path_service.h"
12#include "base/scoped_ptr.h"
13#include "base/string_util.h"
[email protected]def11712009-11-06 00:42:1514#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4215#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2916#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5117#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5718#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0219#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3720#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4221#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5622#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0723#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3724#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0525#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2526#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3527#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4828#include "chrome/browser/favicon_service.h"
[email protected]77f6fb432009-09-05 14:21:0929#include "chrome/browser/strict_transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4230#include "chrome/browser/history/history.h"
[email protected]3bf335a2009-06-26 20:46:0631#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5032#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4233#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2634#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4135#include "chrome/browser/password_manager/password_store_default.h"
[email protected]a307e31e2009-11-30 16:11:2736#include "chrome/browser/privacy_blacklist/blacklist_manager.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2638#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]90085af02009-10-29 17:53:2139#include "chrome/browser/search_versus_navigate_classifier.h"
[email protected]1132436e2009-04-08 20:06:3340#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4641#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4442#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3043#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3344#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1145#include "chrome/browser/sync/profile_sync_service.h"
[email protected]449478302009-06-09 20:04:2846#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2947#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3948#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5650#include "chrome/browser/web_resource/web_resource_service.h"
[email protected]23f1ef12009-09-01 22:30:3051#include "chrome/common/appcache/chrome_appcache_service.h"
initial.commit09911bf2008-07-26 23:55:2952#include "chrome/common/chrome_constants.h"
53#include "chrome/common/chrome_paths.h"
54#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5855#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2956#include "chrome/common/notification_service.h"
57#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3258#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5859#include "grit/locale_settings.h"
[email protected]77f6fb432009-09-05 14:21:0960#include "net/base/strict_transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3461#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2962
[email protected]a5166af62009-07-03 00:42:2963#if defined(OS_LINUX)
64#include "chrome/browser/gtk/gtk_theme_provider.h"
65#endif
66
[email protected]e1acf6f2008-10-27 20:43:3367using base::Time;
68using base::TimeDelta;
69
[email protected]e5642992009-06-26 23:06:3170namespace {
71
initial.commit09911bf2008-07-26 23:55:2972// Delay, in milliseconds, before we explicitly create the SessionService.
73static const int kCreateSessionServiceDelayMS = 500;
74
[email protected]e5642992009-06-26 23:06:3175enum ContextType {
76 kNormalContext,
77 kMediaContext
78};
79
80// Gets the cache parameters from the command line. |type| is the type of
81// request context that we need, |cache_path| will be set to the user provided
82// path, or will not be touched if there is not an argument. |max_size| will
83// be the user provided value or zero by default.
84void GetCacheParameters(ContextType type, FilePath* cache_path,
85 int* max_size) {
86 DCHECK(cache_path);
87 DCHECK(max_size);
88
89 // Override the cache location if specified by the user.
90 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
91 switches::kDiskCacheDir));
92
93 if (!user_path.empty()) {
94 *cache_path = FilePath::FromWStringHack(user_path);
95 }
96
[email protected]b7e0a2a2009-10-13 02:07:2597 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
98 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:3199 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25100 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31101
102 // By default we let the cache determine the right size.
103 *max_size = 0;
104 if (!StringToInt(value, max_size)) {
105 *max_size = 0;
106 } else if (max_size < 0) {
107 *max_size = 0;
108 }
109}
110
[email protected]405a64b2009-09-16 21:03:44111FilePath GetCachePath(const FilePath& base) {
112 return base.Append(chrome::kCacheDirname);
113}
114
115FilePath GetMediaCachePath(const FilePath& base) {
116 return base.Append(chrome::kMediaCacheDirname);
117}
118
119bool HasACacheSubdir(const FilePath &dir) {
120 return file_util::PathExists(GetCachePath(dir)) ||
121 file_util::PathExists(GetMediaCachePath(dir));
122}
123
[email protected]e5642992009-06-26 23:06:31124} // namespace
125
initial.commit09911bf2008-07-26 23:55:29126// A pointer to the request context for the default profile. See comments on
127// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31128URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29129
[email protected]be180c802009-10-23 06:33:31130static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19131 if (context)
[email protected]47accfd62009-05-14 18:46:21132 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21133}
134
[email protected]34cc84f2009-02-13 10:04:35135// static
[email protected]4bf6afd2009-10-08 14:00:11136const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
137
138// static
initial.commit09911bf2008-07-26 23:55:29139void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55140 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29141 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
142 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12143 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26144 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
145 IDS_SPELLCHECK_DICTIONARY);
146 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58147 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]a5166af62009-07-03 00:42:29148#if defined(OS_LINUX)
149 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
150#endif
[email protected]51c490b2009-08-03 16:34:34151 prefs->RegisterStringPref(prefs::kCurrentThemeID,
152 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42153 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
154 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
155 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50156 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23157 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29158}
159
[email protected]34cc84f2009-02-13 10:04:35160// static
[email protected]f7011fcb2009-01-28 21:54:32161Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29162 return new ProfileImpl(path);
163}
164
[email protected]34cc84f2009-02-13 10:04:35165// static
[email protected]be180c802009-10-23 06:33:31166URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29167 return default_request_context_;
168}
169
[email protected]e69d33952009-06-03 22:00:41170#if defined(OS_LINUX)
171// Temporarily disabled while we figure some stuff out.
172// http://code.google.com/p/chromium/issues/detail?id=12351
173// #include "chrome/browser/password_manager/password_store_gnome.h"
174// #include "chrome/browser/password_manager/password_store_kwallet.h"
175#elif defined(OS_WIN)
176#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56177#elif defined(OS_MACOSX)
178#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17179#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56180#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41181#endif
initial.commit09911bf2008-07-26 23:55:29182
initial.commit09911bf2008-07-26 23:55:29183////////////////////////////////////////////////////////////////////////////////
184//
185// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42186// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29187//
188////////////////////////////////////////////////////////////////////////////////
189class OffTheRecordProfileImpl : public Profile,
190 public NotificationObserver {
191 public:
192 explicit OffTheRecordProfileImpl(Profile* real_profile)
193 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21194 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29195 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31196 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05197
initial.commit09911bf2008-07-26 23:55:29198 // Register for browser close notifications so we can detect when the last
199 // off-the-record window is closed, in which case we can clean our states
200 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43201 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
202 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29203 }
204
205 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21206 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21207 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29208 }
209
[email protected]4bf6afd2009-10-08 14:00:11210 virtual ProfileId GetRuntimeId() {
211 return reinterpret_cast<ProfileId>(this);
212 }
213
[email protected]f7011fcb2009-01-28 21:54:32214 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29215
216 virtual bool IsOffTheRecord() {
217 return true;
218 }
219
220 virtual Profile* GetOffTheRecordProfile() {
221 return this;
222 }
223
[email protected]860f55492009-03-27 19:50:59224 virtual void DestroyOffTheRecordProfile() {
225 // Suicide is bad!
226 NOTREACHED();
227 }
228
initial.commit09911bf2008-07-26 23:55:29229 virtual Profile* GetOriginalProfile() {
230 return profile_;
231 }
232
[email protected]2f351cb2009-11-09 23:43:34233 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
234 if (!db_tracker_)
235 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
236 return db_tracker_;
237 }
238
initial.commit09911bf2008-07-26 23:55:29239 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49240 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
241 // because we don't want to leak the sites that the user has visited before.
242 return NULL;
initial.commit09911bf2008-07-26 23:55:29243 }
244
[email protected]6014d672008-12-05 00:38:25245 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34246 return NULL;
[email protected]6014d672008-12-05 00:38:25247 }
248
[email protected]0938d3c2009-01-09 20:37:35249 virtual UserScriptMaster* GetUserScriptMaster() {
250 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25251 }
252
[email protected]89ebc7e2009-08-24 22:11:07253 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
254 return NULL;
255 }
256
[email protected]481e1a42009-05-06 20:56:05257 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34258 return NULL;
[email protected]481e1a42009-05-06 20:56:05259 }
260
[email protected]7120f132009-07-20 21:05:37261 virtual ExtensionMessageService* GetExtensionMessageService() {
262 return NULL;
263 }
264
[email protected]34cc84f2009-02-13 10:04:35265 virtual SSLHostState* GetSSLHostState() {
266 if (!ssl_host_state_.get())
267 ssl_host_state_.reset(new SSLHostState());
268
269 DCHECK(ssl_host_state_->CalledOnValidThread());
270 return ssl_host_state_.get();
271 }
272
[email protected]77f6fb432009-09-05 14:21:09273 virtual net::StrictTransportSecurityState* GetStrictTransportSecurityState() {
274 if (!strict_transport_security_state_.get()) {
275 strict_transport_security_state_ =
276 new net::StrictTransportSecurityState();
277 }
[email protected]a9cea7542009-05-20 04:30:23278
[email protected]77f6fb432009-09-05 14:21:09279 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23280 }
281
initial.commit09911bf2008-07-26 23:55:29282 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
283 if (sat == EXPLICIT_ACCESS) {
284 return profile_->GetHistoryService(sat);
285 } else {
286 NOTREACHED() << "This profile is OffTheRecord";
287 return NULL;
288 }
289 }
290
[email protected]0850fa62009-10-08 22:34:29291 virtual HistoryService* GetHistoryServiceWithoutCreating() {
292 return profile_->GetHistoryServiceWithoutCreating();
293 }
294
[email protected]0189bc722009-08-28 21:56:48295 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
296 if (sat == EXPLICIT_ACCESS) {
297 return profile_->GetFaviconService(sat);
298 } else {
299 NOTREACHED() << "This profile is OffTheRecord";
300 return NULL;
301 }
302 }
303
[email protected]90085af02009-10-29 17:53:21304 virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
305 return profile_->GetSearchVersusNavigateClassifier();
306 }
307
initial.commit09911bf2008-07-26 23:55:29308 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
309 if (sat == EXPLICIT_ACCESS) {
310 return profile_->GetWebDataService(sat);
311 } else {
312 NOTREACHED() << "This profile is OffTheRecord";
313 return NULL;
314 }
315 }
316
[email protected]9cddbe372009-10-23 21:23:53317 virtual WebDataService* GetWebDataServiceWithoutCreating() {
318 return profile_->GetWebDataServiceWithoutCreating();
319 }
320
[email protected]e69d33952009-06-03 22:00:41321 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
322 if (sat == EXPLICIT_ACCESS) {
323 return profile_->GetPasswordStore(sat);
324 } else {
325 NOTREACHED() << "This profile is OffTheRecord";
326 return NULL;
327 }
328 }
329
initial.commit09911bf2008-07-26 23:55:29330 virtual PrefService* GetPrefs() {
331 return profile_->GetPrefs();
332 }
333
334 virtual TemplateURLModel* GetTemplateURLModel() {
335 return profile_->GetTemplateURLModel();
336 }
337
338 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
339 return profile_->GetTemplateURLFetcher();
340 }
341
342 virtual DownloadManager* GetDownloadManager() {
343 if (!download_manager_.get()) {
344 scoped_refptr<DownloadManager> dlm(new DownloadManager);
345 dlm->Init(this);
346 download_manager_.swap(dlm);
347 }
348 return download_manager_.get();
349 }
350
351 virtual bool HasCreatedDownloadManager() const {
352 return (download_manager_.get() != NULL);
353 }
354
[email protected]def11712009-11-06 00:42:15355 virtual PersonalDataManager* GetPersonalDataManager() {
356 return NULL;
357 }
358
[email protected]4a190632009-05-09 01:07:42359 virtual void InitThemes() {
360 GetOriginalProfile()->InitThemes();
361 }
362
363 virtual void SetTheme(Extension* extension) {
364 GetOriginalProfile()->SetTheme(extension);
365 }
366
[email protected]a5166af62009-07-03 00:42:29367 virtual void SetNativeTheme() {
368 GetOriginalProfile()->SetNativeTheme();
369 }
370
[email protected]4a190632009-05-09 01:07:42371 virtual void ClearTheme() {
372 GetOriginalProfile()->ClearTheme();
373 }
374
[email protected]51c490b2009-08-03 16:34:34375 virtual Extension* GetTheme() {
376 return GetOriginalProfile()->GetTheme();
377 }
378
[email protected]4a190632009-05-09 01:07:42379 virtual ThemeProvider* GetThemeProvider() {
380 return GetOriginalProfile()->GetThemeProvider();
381 }
382
[email protected]be180c802009-10-23 06:33:31383 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29384 return request_context_;
385 }
386
[email protected]be180c802009-10-23 06:33:31387 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11388 // In OTR mode, media request context is the same as the original one.
389 return request_context_;
[email protected]e7f29642009-03-02 22:53:18390 }
391
[email protected]be180c802009-10-23 06:33:31392 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21393 if (!extensions_request_context_) {
394 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31395 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this);
[email protected]47accfd62009-05-14 18:46:21396 }
397
398 return extensions_request_context_;
399 }
400
[email protected]db36938c2009-08-19 21:48:42401 virtual net::SSLConfigService* GetSSLConfigService() {
402 return GetOriginalProfile()->GetSSLConfigService();
403 }
404
[email protected]a307e31e2009-11-30 16:11:27405 virtual BlacklistManager* GetBlacklistManager() {
406 return GetOriginalProfile()->GetBlacklistManager();
[email protected]eaadd9052009-06-23 18:02:23407 }
408
initial.commit09911bf2008-07-26 23:55:29409 virtual SessionService* GetSessionService() {
410 // Don't save any sessions when off the record.
411 return NULL;
412 }
413
414 virtual void ShutdownSessionService() {
415 // We don't allow a session service, nothing to do.
416 }
417
418 virtual bool HasSessionService() const {
419 // We never have a session service.
420 return false;
421 }
422
initial.commit09911bf2008-07-26 23:55:29423 virtual bool DidLastSessionExitCleanly() {
424 return profile_->DidLastSessionExitCleanly();
425 }
426
[email protected]d8e41ed2008-09-11 15:22:32427 virtual BookmarkModel* GetBookmarkModel() {
428 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29429 }
430
[email protected]4bb336302009-10-12 05:44:26431 virtual DesktopNotificationService* GetDesktopNotificationService() {
432 return profile_->GetDesktopNotificationService();
433 }
434
[email protected]48352c12009-08-15 01:19:11435 virtual ProfileSyncService* GetProfileSyncService() {
436 return NULL;
[email protected]3a453fa2008-08-15 18:46:34437 }
[email protected]3a453fa2008-08-15 18:46:34438
initial.commit09911bf2008-07-26 23:55:29439 virtual bool IsSameProfile(Profile* profile) {
440 if (profile == static_cast<Profile*>(this))
441 return true;
442 return profile == profile_;
443 }
444
445 virtual Time GetStartTime() const {
446 return start_time_;
447 }
448
449 virtual TabRestoreService* GetTabRestoreService() {
450 return NULL;
451 }
452
[email protected]e7244d82008-10-29 18:13:26453 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41454 }
455
[email protected]85c55dc2009-11-06 03:05:46456 virtual SpellCheckHost* GetSpellCheckHost() {
457 return profile_->GetSpellCheckHost();
458 }
459
460 virtual void ReinitializeSpellCheckHost(bool force) {
461 profile_->ReinitializeSpellCheckHost(force);
462 }
[email protected]85c55dc2009-11-06 03:05:46463
[email protected]3bf335a2009-06-26 20:46:06464 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29465 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21466 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29467 DCHECK(webkit_context_.get());
468 return webkit_context_.get();
469 }
[email protected]3bf335a2009-06-26 20:46:06470
[email protected]449478302009-06-09 20:04:28471 virtual ThumbnailStore* GetThumbnailStore() {
472 return NULL;
473 }
474
initial.commit09911bf2008-07-26 23:55:29475 virtual void MarkAsCleanShutdown() {
476 }
477
[email protected]bdbc87c2009-01-25 05:08:54478 virtual void InitExtensions() {
479 NOTREACHED();
480 }
481
[email protected]ea0c98cf2009-06-18 23:02:54482 virtual void InitWebResources() {
483 NOTREACHED();
484 }
485
[email protected]9c8dd902009-11-19 17:50:42486 virtual NTPResourceCache* GetNTPResourceCache() {
487 // Just return the real profile resource cache.
488 return profile_->GetNTPResourceCache();
489 }
490
initial.commit09911bf2008-07-26 23:55:29491 virtual void ExitedOffTheRecordMode() {
492 // Drop our download manager so we forget about all the downloads made
493 // in off-the-record mode.
494 download_manager_ = NULL;
495 }
496
497 virtual void Observe(NotificationType type,
498 const NotificationSource& source,
499 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56500 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29501 // We are only interested in OTR browser closing.
502 if (Source<Browser>(source)->profile() != this)
503 return;
504
505 // Let's check if we still have an Off The Record window opened.
506 // Note that we check against 1 as this notification is sent before the
507 // browser window is actually removed from the list.
508 if (BrowserList::GetBrowserCount(this) <= 1)
509 ExitedOffTheRecordMode();
510 }
511
512 private:
[email protected]88cf3292009-05-22 01:48:43513 NotificationRegistrar registrar_;
514
initial.commit09911bf2008-07-26 23:55:29515 // The real underlying profile.
516 Profile* profile_;
517
[email protected]6ab9b202008-12-23 22:34:50518 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19519 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29520
[email protected]13c30922009-11-19 03:43:19521 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_;
[email protected]23f1ef12009-09-01 22:30:30522
initial.commit09911bf2008-07-26 23:55:29523 // The download manager that only stores downloaded items in memory.
524 scoped_refptr<DownloadManager> download_manager_;
525
[email protected]3bf335a2009-06-26 20:46:06526 // Use a special WebKit context for OTR browsing.
527 scoped_refptr<WebKitContext> webkit_context_;
528
[email protected]34cc84f2009-02-13 10:04:35529 // We don't want SSLHostState from the OTR profile to leak back to the main
530 // profile because then the main profile would learn some of the host names
531 // the user visited while OTR.
532 scoped_ptr<SSLHostState> ssl_host_state_;
533
[email protected]77f6fb432009-09-05 14:21:09534 // The StrictTransportSecurityState that only stores enabled sites in memory.
535 scoped_refptr<net::StrictTransportSecurityState>
536 strict_transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23537
initial.commit09911bf2008-07-26 23:55:29538 // Time we were started.
539 Time start_time_;
540
[email protected]2f351cb2009-11-09 23:43:34541 // The main database tracker for this profile.
542 // Should be used only on the file thread.
543 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
544
[email protected]90085af02009-10-29 17:53:21545 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29546};
547
[email protected]f7011fcb2009-01-28 21:54:32548ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29549 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39550 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07551 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32552 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57553 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21554 extensions_request_context_(NULL),
[email protected]a307e31e2009-11-30 16:11:27555 blacklist_manager_(NULL),
556 blacklist_manager_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32557 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48558 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32559 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41560 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32561 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42562 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32563 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46564 spellcheck_host_(NULL),
565 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29566 shutdown_session_service_(false) {
567 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
568 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14569 create_session_service_timer_.Start(
570 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
571 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54572
[email protected]89ebc7e2009-08-24 22:11:07573 if (CommandLine::ForCurrentProcess()->HasSwitch(
574 switches::kEnableExtensionTimelineApi)) {
575 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
576 }
577
[email protected]382a0702009-06-26 17:12:27578 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37579 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27580
[email protected]e7244d82008-10-29 18:13:26581 PrefService* prefs = GetPrefs();
582 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
583 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58584 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58585
[email protected]405a64b2009-09-16 21:03:44586#if defined(OS_MACOSX)
587 // If the profile directory doesn't already have a cache directory and it
588 // is under ~/Library/Application Support, use a suitable cache directory
589 // under ~/Library/Caches. For example, a profile directory of
590 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
591 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
592 // ~/Library/Caches/Google/Chrome/MyProfileName.
593 //
594 // TODO(akalin): Come up with unit tests for this.
595 // TODO(akalin): Use for Linux, too?
596 if (!HasACacheSubdir(path_)) {
597 FilePath app_data_path, user_cache_path;
598 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
599 PathService::Get(base::DIR_CACHE, &user_cache_path) &&
600 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
601 base_cache_path_ = user_cache_path;
602 }
603 }
604#else
[email protected]bc96d562009-08-11 18:45:13605 if (!PathService::IsOverridden(chrome::DIR_USER_DATA))
606 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_);
[email protected]405a64b2009-09-16 21:03:44607#endif
[email protected]bc96d562009-08-11 18:45:13608 if (base_cache_path_.empty())
609 base_cache_path_ = path_;
610
[email protected]4a190632009-05-09 01:07:42611 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43612 registrar_.Add(this, NotificationType::THEME_INSTALLED,
613 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11614
615 // Listen for bookmark model load, to bootstrap the sync service.
616 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
617 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42618
619 ssl_config_service_manager_.reset(
620 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53621
622#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29623 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53624#endif
initial.commit09911bf2008-07-26 23:55:29625}
626
[email protected]bdbc87c2009-01-25 05:08:54627void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41628 if (user_script_master_ || extensions_service_)
629 return; // Already initialized.
630
[email protected]bdbc87c2009-01-25 05:08:54631 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18632 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36633
634 FilePath script_dir; // Don't look for user scripts in any directory.
635 // TODO(aa): We should just remove this functionality,
636 // since it isn't used anymore.
[email protected]95d29192009-10-30 01:49:06637 user_script_master_ = new UserScriptMaster(script_dir);
[email protected]faed6e12009-11-24 22:38:36638
[email protected]894bb502009-05-21 22:39:57639 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23640 this,
641 CommandLine::ForCurrentProcess(),
642 GetPrefs(),
643 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36644 true);
[email protected]bdbc87c2009-01-25 05:08:54645
[email protected]9197f3b2009-06-02 00:49:27646 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12647
648 // Load any extensions specified with --load-extension.
649 if (command_line->HasSwitch(switches::kLoadExtension)) {
650 std::wstring path_string =
651 command_line->GetSwitchValue(switches::kLoadExtension);
652 FilePath path = FilePath::FromWStringHack(path_string);
653 extensions_service_->LoadExtension(path);
654
655 // Tell UserScriptMaser to watch this extension's directory for changes so
656 // you can live edit content scripts during development.
657 user_script_master_->AddWatchedPath(path);
658 }
[email protected]bdbc87c2009-01-25 05:08:54659}
660
[email protected]ea0c98cf2009-06-18 23:02:54661void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07662 if (web_resource_service_)
663 return; // Already initialized.
664
[email protected]6fad2632009-11-02 05:59:37665 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54666 web_resource_service_->StartAfterDelay();
667}
668
[email protected]9c8dd902009-11-19 17:50:42669NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
670 if (!ntp_resource_cache_.get())
671 ntp_resource_cache_.reset(new NTPResourceCache(this));
672 return ntp_resource_cache_.get();
673}
674
initial.commit09911bf2008-07-26 23:55:29675ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19676 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29677
678 StopCreateSessionServiceTimer();
679 // TemplateURLModel schedules a task on the WebDataService from its
680 // destructor. Delete it first to ensure the task gets scheduled before we
681 // shut down the database.
682 template_url_model_.reset();
683
684 // The download manager queries the history system and should be deleted
685 // before the history is shutdown so it can properly cancel all requests.
686 download_manager_ = NULL;
687
[email protected]4a190632009-05-09 01:07:42688 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15689 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42690
[email protected]44961292009-07-20 20:03:09691 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
692 // save any new thumbnails to disk and release its reference to the
693 // HistoryService.
694 if (thumbnail_store_.get())
695 thumbnail_store_->Shutdown();
696
[email protected]e7244d82008-10-29 18:13:26697 // Remove pref observers.
698 PrefService* prefs = GetPrefs();
699 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
700 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58701 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26702
[email protected]9c8dd902009-11-19 17:50:42703 // Delete the NTP resource cache so we can unregister pref observers.
704 ntp_resource_cache_.reset();
705
[email protected]48352c12009-08-15 01:19:11706 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34707
initial.commit09911bf2008-07-26 23:55:29708 // Both HistoryService and WebDataService maintain threads for background
709 // processing. Its possible each thread still has tasks on it that have
710 // increased the ref count of the service. In such a situation, when we
711 // decrement the refcount, it won't be 0, and the threads/databases aren't
712 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
713 // databases are properly closed.
714 if (web_data_service_.get())
715 web_data_service_->Shutdown();
716
717 if (history_service_.get())
718 history_service_->Cleanup();
719
[email protected]85c55dc2009-11-06 03:05:46720 if (spellcheck_host_.get())
721 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29722
[email protected]cfc06f122009-11-16 22:18:55723 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21724 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50725
[email protected]47accfd62009-05-14 18:46:21726 CleanupRequestContext(request_context_);
727 CleanupRequestContext(media_request_context_);
728 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17729
[email protected]d8e41ed2008-09-11 15:22:32730 // HistoryService may call into the BookmarkModel, as such we need to
731 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46732 // HistoryService will join with HistoryService's backend thread so that
733 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32734 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46735 history_service_ = NULL;
736 bookmark_bar_model_.reset();
737
[email protected]0189bc722009-08-28 21:56:48738 // FaviconService depends on HistoryServce so make sure we delete
739 // HistoryService first.
740 favicon_service_ = NULL;
741
[email protected]7120f132009-07-20 21:05:37742 extension_message_service_->ProfileDestroyed();
743
[email protected]6ef635e42009-07-26 06:16:12744 if (extensions_service_)
745 extensions_service_->ProfileDestroyed();
746
[email protected]66da08b2009-10-19 22:27:00747 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29748 MarkAsCleanShutdown();
749}
750
[email protected]4bf6afd2009-10-08 14:00:11751ProfileId ProfileImpl::GetRuntimeId() {
752 return reinterpret_cast<ProfileId>(this);
753}
754
[email protected]f7011fcb2009-01-28 21:54:32755FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29756 return path_;
757}
758
759bool ProfileImpl::IsOffTheRecord() {
760 return false;
761}
762
763Profile* ProfileImpl::GetOffTheRecordProfile() {
764 if (!off_the_record_profile_.get()) {
765 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
766 off_the_record_profile_.swap(p);
767 }
768 return off_the_record_profile_.get();
769}
770
[email protected]860f55492009-03-27 19:50:59771void ProfileImpl::DestroyOffTheRecordProfile() {
772 off_the_record_profile_.reset();
773}
774
initial.commit09911bf2008-07-26 23:55:29775Profile* ProfileImpl::GetOriginalProfile() {
776 return this;
777}
778
[email protected]2f351cb2009-11-09 23:43:34779webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
780 if (!db_tracker_)
781 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
782 return db_tracker_;
783}
784
initial.commit09911bf2008-07-26 23:55:29785VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
786 if (!visited_link_master_.get()) {
787 scoped_ptr<VisitedLinkMaster> visited_links(
[email protected]6fad2632009-11-02 05:59:37788 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29789 if (!visited_links->Init())
790 return NULL;
791 visited_link_master_.swap(visited_links);
792 }
793
794 return visited_link_master_.get();
795}
796
[email protected]6014d672008-12-05 00:38:25797ExtensionsService* ProfileImpl::GetExtensionsService() {
798 return extensions_service_.get();
799}
800
[email protected]0938d3c2009-01-09 20:37:35801UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35802 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25803}
804
[email protected]89ebc7e2009-08-24 22:11:07805ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
806 return extension_devtools_manager_.get();
807}
808
[email protected]481e1a42009-05-06 20:56:05809ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27810 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05811}
812
[email protected]7120f132009-07-20 21:05:37813ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
814 return extension_message_service_.get();
815}
816
[email protected]34cc84f2009-02-13 10:04:35817SSLHostState* ProfileImpl::GetSSLHostState() {
818 if (!ssl_host_state_.get())
819 ssl_host_state_.reset(new SSLHostState());
820
821 DCHECK(ssl_host_state_->CalledOnValidThread());
822 return ssl_host_state_.get();
823}
824
[email protected]77f6fb432009-09-05 14:21:09825net::StrictTransportSecurityState*
826 ProfileImpl::GetStrictTransportSecurityState() {
827 if (!strict_transport_security_state_.get()) {
828 strict_transport_security_state_ = new net::StrictTransportSecurityState();
[email protected]0c03b432009-11-17 21:41:08829 strict_transport_security_persister_ =
830 new StrictTransportSecurityPersister();
831 strict_transport_security_persister_->Initialize(
[email protected]6fad2632009-11-02 05:59:37832 strict_transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51833 }
[email protected]a9cea7542009-05-20 04:30:23834
[email protected]77f6fb432009-09-05 14:21:09835 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23836}
837
initial.commit09911bf2008-07-26 23:55:29838PrefService* ProfileImpl::GetPrefs() {
839 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37840 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29841
842 // The Profile class and ProfileManager class may read some prefs so
843 // register known prefs as soon as possible.
844 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51845 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29846
847 // The last session exited cleanly if there is no pref for
848 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
849 last_session_exited_cleanly_ =
850 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
851 // Mark the session as open.
852 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
853 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36854 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29855 }
856
857 return prefs_.get();
858}
859
[email protected]f7011fcb2009-01-28 21:54:32860FilePath ProfileImpl::GetPrefFilePath() {
861 FilePath pref_file_path = path_;
862 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29863 return pref_file_path;
864}
865
[email protected]be180c802009-10-23 06:33:31866URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29867 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32868 FilePath cookie_path = GetPath();
869 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13870 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31871 int max_size;
872 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42873
[email protected]405a64b2009-09-16 21:03:44874 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31875 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
876 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29877
[email protected]6ab9b202008-12-23 22:34:50878 // The first request context is always a normal (non-OTR) request context.
879 // Even when Chromium is started in OTR mode, a normal profile is always
880 // created first.
881 if (!default_request_context_) {
882 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31883 // TODO(eroman): this isn't terribly useful anymore now that the
884 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50885 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56886 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50887 NotificationService::AllSources(), NotificationService::NoDetails());
888 }
initial.commit09911bf2008-07-26 23:55:29889 }
890
891 return request_context_;
892}
893
[email protected]be180c802009-10-23 06:33:31894URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18895 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13896 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31897 int max_size;
898 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14899
[email protected]405a64b2009-09-16 21:03:44900 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31901 media_request_context_ =
902 ChromeURLRequestContextGetter::CreateOriginalForMedia(
903 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18904 }
905
906 return media_request_context_;
907}
908
[email protected]0189bc722009-08-28 21:56:48909FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
910 if (!favicon_service_created_) {
911 favicon_service_created_ = true;
912 scoped_refptr<FaviconService> service(new FaviconService(this));
913 favicon_service_.swap(service);
914 }
915 return favicon_service_.get();
916}
917
[email protected]be180c802009-10-23 06:33:31918URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21919 if (!extensions_request_context_) {
920 FilePath cookie_path = GetPath();
921 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
922
923 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31924 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
925 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21926 }
927
928 return extensions_request_context_;
929}
930
[email protected]db36938c2009-08-19 21:48:42931net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
932 return ssl_config_service_manager_->Get();
933}
934
[email protected]a307e31e2009-11-30 16:11:27935BlacklistManager* ProfileImpl::GetBlacklistManager() {
936 if (!CommandLine::ForCurrentProcess()->HasSwitch(
937 switches::kEnablePrivacyBlacklists)) {
938 return NULL;
939 }
940 if (!blacklist_manager_created_) {
941 blacklist_manager_created_ = true;
942 blacklist_manager_ = new BlacklistManager(this, GetExtensionsService());
943 blacklist_manager_->Initialize();
944 }
945 return blacklist_manager_.get();
[email protected]eaadd9052009-06-23 18:02:23946}
947
initial.commit09911bf2008-07-26 23:55:29948HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
949 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:46950 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:29951 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:32952 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:29953 return NULL;
954 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:29955
956 // Send out the notification that the history service was created.
957 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56958 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:29959 Details<HistoryService>(history_service_.get()));
960 }
961 return history_service_.get();
962}
963
[email protected]0850fa62009-10-08 22:34:29964HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
965 return history_service_.get();
966}
967
initial.commit09911bf2008-07-26 23:55:29968TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
969 if (!template_url_model_.get())
970 template_url_model_.reset(new TemplateURLModel(this));
971 return template_url_model_.get();
972}
973
974TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
975 if (!template_url_fetcher_.get())
976 template_url_fetcher_.reset(new TemplateURLFetcher(this));
977 return template_url_fetcher_.get();
978}
979
[email protected]11f4857282009-11-13 19:56:17980SearchVersusNavigateClassifier*
981ProfileImpl::GetSearchVersusNavigateClassifier() {
[email protected]90085af02009-10-29 17:53:21982 if (!search_versus_navigate_classifier_.get()) {
983 search_versus_navigate_classifier_.reset(
984 new SearchVersusNavigateClassifier(this));
985 }
986 return search_versus_navigate_classifier_.get();
987}
988
initial.commit09911bf2008-07-26 23:55:29989WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
990 if (!created_web_data_service_)
991 CreateWebDataService();
992 return web_data_service_.get();
993}
994
[email protected]9cddbe372009-10-23 21:23:53995WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
996 return web_data_service_.get();
997}
998
initial.commit09911bf2008-07-26 23:55:29999void ProfileImpl::CreateWebDataService() {
1000 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1001 created_web_data_service_ = true;
1002 scoped_refptr<WebDataService> wds(new WebDataService());
1003 if (!wds->Init(GetPath()))
1004 return;
1005 web_data_service_.swap(wds);
1006}
1007
[email protected]e69d33952009-06-03 22:00:411008PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1009 if (!created_password_store_)
1010 CreatePasswordStore();
1011 return password_store_.get();
1012}
1013
1014void ProfileImpl::CreatePasswordStore() {
1015 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1016 created_password_store_ = true;
1017 scoped_refptr<PasswordStore> ps;
1018#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251019 // TODO(evanm): implement "native" password management.
1020 // This bug describes the issues.
1021 // http://code.google.com/p/chromium/issues/detail?id=12351
1022 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1023 if (!ps->Init())
1024 return;
[email protected]e69d33952009-06-03 22:00:411025#elif defined(OS_WIN)
1026 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561027#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171028 FilePath login_db_file_path = GetPath();
1029 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1030 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1031 if (!login_db->Init(login_db_file_path)) {
1032 LOG(ERROR) << "Could not initialize login database.";
1033 delete login_db;
1034 return;
1035 }
1036 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411037#else
1038 NOTIMPLEMENTED();
1039#endif
1040 if (!ps || !ps->Init()) {
1041 // Try falling back to the default password manager
1042 LOG(WARNING) << "Could not initialise native password manager - "
1043 "falling back to default";
1044 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1045 if (!ps->Init())
1046 return;
1047 }
1048 password_store_.swap(ps);
1049}
1050
initial.commit09911bf2008-07-26 23:55:291051DownloadManager* ProfileImpl::GetDownloadManager() {
1052 if (!created_download_manager_) {
1053 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1054 dlm->Init(this);
1055 created_download_manager_ = true;
1056 download_manager_.swap(dlm);
1057 }
1058 return download_manager_.get();
1059}
1060
1061bool ProfileImpl::HasCreatedDownloadManager() const {
1062 return created_download_manager_;
1063}
1064
[email protected]def11712009-11-06 00:42:151065PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1066 if (!personal_data_manager_.get()) {
1067 personal_data_manager_.reset(new PersonalDataManager);
1068 }
1069 return personal_data_manager_.get();
1070}
1071
[email protected]4a190632009-05-09 01:07:421072void ProfileImpl::InitThemes() {
1073 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571074#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151075 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291076#else
[email protected]761962c2009-09-25 00:18:151077 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291078#endif
[email protected]761962c2009-09-25 00:18:151079 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421080 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421081 }
1082}
1083
1084void ProfileImpl::SetTheme(Extension* extension) {
1085 InitThemes();
1086 theme_provider_.get()->SetTheme(extension);
1087}
1088
[email protected]a5166af62009-07-03 00:42:291089void ProfileImpl::SetNativeTheme() {
1090 InitThemes();
1091 theme_provider_.get()->SetNativeTheme();
1092}
1093
[email protected]4a190632009-05-09 01:07:421094void ProfileImpl::ClearTheme() {
1095 InitThemes();
1096 theme_provider_.get()->UseDefaultTheme();
1097}
1098
[email protected]51c490b2009-08-03 16:34:341099Extension* ProfileImpl::GetTheme() {
1100 InitThemes();
1101
1102 std::string id = theme_provider_.get()->GetThemeID();
1103 if (id == BrowserThemeProvider::kDefaultThemeID)
1104 return NULL;
1105
[email protected]61b411612009-11-10 23:17:411106 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341107}
1108
[email protected]4a190632009-05-09 01:07:421109ThemeProvider* ProfileImpl::GetThemeProvider() {
1110 InitThemes();
1111 return theme_provider_.get();
1112}
1113
initial.commit09911bf2008-07-26 23:55:291114SessionService* ProfileImpl::GetSessionService() {
1115 if (!session_service_.get() && !shutdown_session_service_) {
1116 session_service_ = new SessionService(this);
1117 session_service_->ResetFromCurrentBrowsers();
1118 }
1119 return session_service_.get();
1120}
1121
1122void ProfileImpl::ShutdownSessionService() {
1123 if (shutdown_session_service_)
1124 return;
1125
1126 // We're about to exit, force creation of the session service if it hasn't
1127 // been created yet. We do this to ensure session state matches the point in
1128 // time the user exited.
1129 GetSessionService();
1130 shutdown_session_service_ = true;
1131 session_service_ = NULL;
1132}
1133
1134bool ProfileImpl::HasSessionService() const {
1135 return (session_service_.get() != NULL);
1136}
1137
initial.commit09911bf2008-07-26 23:55:291138bool ProfileImpl::DidLastSessionExitCleanly() {
1139 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1140 // it to be set by asking for the prefs.
1141 GetPrefs();
1142 return last_session_exited_cleanly_;
1143}
1144
[email protected]d8e41ed2008-09-11 15:22:321145BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461146 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321147 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461148 bookmark_bar_model_->Load();
1149 }
initial.commit09911bf2008-07-26 23:55:291150 return bookmark_bar_model_.get();
1151}
1152
1153bool ProfileImpl::IsSameProfile(Profile* profile) {
1154 if (profile == static_cast<Profile*>(this))
1155 return true;
1156 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1157 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1158}
1159
1160Time ProfileImpl::GetStartTime() const {
1161 return start_time_;
1162}
1163
1164TabRestoreService* ProfileImpl::GetTabRestoreService() {
1165 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191166 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291167 return tab_restore_service_.get();
1168}
1169
[email protected]449478302009-06-09 20:04:281170ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1171 if (!thumbnail_store_.get()) {
1172 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251173 thumbnail_store_->Init(
1174 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281175 }
1176 return thumbnail_store_.get();
1177}
1178
initial.commit09911bf2008-07-26 23:55:291179void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191180 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291181}
1182
[email protected]85c55dc2009-11-06 03:05:461183SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1184 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1185}
1186
1187void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1188 // If we are already loading the spellchecker, and this is just a hint to
1189 // load the spellchecker, do nothing.
1190 if (!force && spellcheck_host_.get())
1191 return;
1192
[email protected]f41301e2009-11-16 21:30:071193 spellcheck_host_ready_ = false;
1194
[email protected]85c55dc2009-11-06 03:05:461195 bool notify = false;
1196 if (spellcheck_host_.get()) {
1197 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051198 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461199 notify = true;
1200 }
1201
1202 PrefService* prefs = GetPrefs();
1203 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1204 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1205 spellcheck_host_ = new SpellCheckHost(this,
1206 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1207 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071208 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461209 } else if (notify) {
1210 // The spellchecker has been disabled.
1211 SpellCheckHostInitialized();
1212 }
1213}
1214
1215void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171216 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291217 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1218 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461219 NotificationService::current()->Notify(
1220 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1221 Source<Profile>(this), NotificationService::NoDetails());
1222}
initial.commit09911bf2008-07-26 23:55:291223
[email protected]3bf335a2009-06-26 20:46:061224WebKitContext* ProfileImpl::GetWebKitContext() {
1225 if (!webkit_context_.get())
1226 webkit_context_ = new WebKitContext(path_, false);
1227 DCHECK(webkit_context_.get());
1228 return webkit_context_.get();
1229}
1230
[email protected]4bb336302009-10-12 05:44:261231DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1232 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1233 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261234 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031235 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261236 }
[email protected]4bb336302009-10-12 05:44:261237 return desktop_notification_service_.get();
1238}
1239
initial.commit09911bf2008-07-26 23:55:291240void ProfileImpl::MarkAsCleanShutdown() {
1241 if (prefs_.get()) {
1242 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1243 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1244
1245 // NOTE: If you change what thread this writes on, be sure and update
1246 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361247 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291248 }
1249}
1250
[email protected]e7244d82008-10-29 18:13:261251void ProfileImpl::Observe(NotificationType type,
1252 const NotificationSource& source,
1253 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561254 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261255 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1256 PrefService* prefs = Source<PrefService>(source).ptr();
1257 DCHECK(pref_name_in && prefs);
1258 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461259 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461260 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291261 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1262 NotificationService::current()->Notify(
1263 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1264 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261265 }
[email protected]4a190632009-05-09 01:07:421266 } else if (NotificationType::THEME_INSTALLED == type) {
1267 Extension* extension = Details<Extension>(details).ptr();
1268 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111269 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1270 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1271 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1272 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261273 }
1274}
1275
initial.commit09911bf2008-07-26 23:55:291276void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141277 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291278}
[email protected]3a453fa2008-08-15 18:46:341279
[email protected]48352c12009-08-15 01:19:111280ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431281 if (!ProfileSyncService::IsSyncEnabled()) {
1282 return NULL;
[email protected]7367f1a2009-10-10 01:09:441283 }
[email protected]eec3bcfa2009-11-12 17:23:431284 if (!sync_service_.get())
1285 InitSyncService();
1286 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111287}
1288
1289void ProfileImpl::InitSyncService() {
[email protected]48352c12009-08-15 01:19:111290 sync_service_.reset(new ProfileSyncService(this));
1291 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111292}