blob: 7f6c3f0aa84f82ea48f2f1c67386e35101cd15df [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]8a4892d8d2009-11-23 20:40:5717#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0218#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3719#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4220#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5621#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0722#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3723#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0524#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2525#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3526#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4827#include "chrome/browser/favicon_service.h"
[email protected]77f6fb432009-09-05 14:21:0928#include "chrome/browser/strict_transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4229#include "chrome/browser/history/history.h"
[email protected]3bf335a2009-06-26 20:46:0630#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5031#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4232#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2633#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4134#include "chrome/browser/password_manager/password_store_default.h"
[email protected]a307e31e2009-11-30 16:11:2735#include "chrome/browser/privacy_blacklist/blacklist_manager.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2637#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]90085af02009-10-29 17:53:2138#include "chrome/browser/search_versus_navigate_classifier.h"
[email protected]1132436e2009-04-08 20:06:3339#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4640#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4441#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3042#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3343#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1144#include "chrome/browser/sync/profile_sync_service.h"
[email protected]449478302009-06-09 20:04:2845#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2946#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3947#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2948#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5649#include "chrome/browser/web_resource/web_resource_service.h"
[email protected]23f1ef12009-09-01 22:30:3050#include "chrome/common/appcache/chrome_appcache_service.h"
initial.commit09911bf2008-07-26 23:55:2951#include "chrome/common/chrome_constants.h"
52#include "chrome/common/chrome_paths.h"
53#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5854#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2955#include "chrome/common/notification_service.h"
56#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3257#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5858#include "grit/locale_settings.h"
[email protected]77f6fb432009-09-05 14:21:0959#include "net/base/strict_transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3460#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2961
[email protected]a5166af62009-07-03 00:42:2962#if defined(OS_LINUX)
63#include "chrome/browser/gtk/gtk_theme_provider.h"
64#endif
65
[email protected]2627431b2009-09-15 20:21:5366#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:2967#include "chrome/browser/chromeos/preferences.h"
[email protected]2627431b2009-09-15 20:21:5368#endif
69
[email protected]e1acf6f2008-10-27 20:43:3370using base::Time;
71using base::TimeDelta;
72
[email protected]e5642992009-06-26 23:06:3173namespace {
74
initial.commit09911bf2008-07-26 23:55:2975// Delay, in milliseconds, before we explicitly create the SessionService.
76static const int kCreateSessionServiceDelayMS = 500;
77
[email protected]e5642992009-06-26 23:06:3178enum ContextType {
79 kNormalContext,
80 kMediaContext
81};
82
83// Gets the cache parameters from the command line. |type| is the type of
84// request context that we need, |cache_path| will be set to the user provided
85// path, or will not be touched if there is not an argument. |max_size| will
86// be the user provided value or zero by default.
87void GetCacheParameters(ContextType type, FilePath* cache_path,
88 int* max_size) {
89 DCHECK(cache_path);
90 DCHECK(max_size);
91
92 // Override the cache location if specified by the user.
93 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
94 switches::kDiskCacheDir));
95
96 if (!user_path.empty()) {
97 *cache_path = FilePath::FromWStringHack(user_path);
98 }
99
[email protected]b7e0a2a2009-10-13 02:07:25100 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
101 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31102 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25103 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31104
105 // By default we let the cache determine the right size.
106 *max_size = 0;
107 if (!StringToInt(value, max_size)) {
108 *max_size = 0;
109 } else if (max_size < 0) {
110 *max_size = 0;
111 }
112}
113
[email protected]405a64b2009-09-16 21:03:44114FilePath GetCachePath(const FilePath& base) {
115 return base.Append(chrome::kCacheDirname);
116}
117
118FilePath GetMediaCachePath(const FilePath& base) {
119 return base.Append(chrome::kMediaCacheDirname);
120}
121
122bool HasACacheSubdir(const FilePath &dir) {
123 return file_util::PathExists(GetCachePath(dir)) ||
124 file_util::PathExists(GetMediaCachePath(dir));
125}
126
[email protected]e5642992009-06-26 23:06:31127} // namespace
128
initial.commit09911bf2008-07-26 23:55:29129// A pointer to the request context for the default profile. See comments on
130// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31131URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29132
[email protected]be180c802009-10-23 06:33:31133static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19134 if (context)
[email protected]47accfd62009-05-14 18:46:21135 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21136}
137
[email protected]34cc84f2009-02-13 10:04:35138// static
[email protected]4bf6afd2009-10-08 14:00:11139const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
140
141// static
initial.commit09911bf2008-07-26 23:55:29142void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55143 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29144 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
145 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12146 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26147 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
148 IDS_SPELLCHECK_DICTIONARY);
149 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58150 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]a5166af62009-07-03 00:42:29151#if defined(OS_LINUX)
152 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
153#endif
[email protected]51c490b2009-08-03 16:34:34154 prefs->RegisterStringPref(prefs::kCurrentThemeID,
155 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42156 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
157 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
158 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50159 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23160 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29161}
162
[email protected]34cc84f2009-02-13 10:04:35163// static
[email protected]f7011fcb2009-01-28 21:54:32164Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29165 return new ProfileImpl(path);
166}
167
[email protected]34cc84f2009-02-13 10:04:35168// static
[email protected]be180c802009-10-23 06:33:31169URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29170 return default_request_context_;
171}
172
[email protected]e69d33952009-06-03 22:00:41173#if defined(OS_LINUX)
174// Temporarily disabled while we figure some stuff out.
175// http://code.google.com/p/chromium/issues/detail?id=12351
176// #include "chrome/browser/password_manager/password_store_gnome.h"
177// #include "chrome/browser/password_manager/password_store_kwallet.h"
178#elif defined(OS_WIN)
179#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56180#elif defined(OS_MACOSX)
181#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17182#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56183#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41184#endif
initial.commit09911bf2008-07-26 23:55:29185
initial.commit09911bf2008-07-26 23:55:29186////////////////////////////////////////////////////////////////////////////////
187//
188// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42189// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29190//
191////////////////////////////////////////////////////////////////////////////////
192class OffTheRecordProfileImpl : public Profile,
193 public NotificationObserver {
194 public:
195 explicit OffTheRecordProfileImpl(Profile* real_profile)
196 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21197 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29198 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31199 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05200
initial.commit09911bf2008-07-26 23:55:29201 // Register for browser close notifications so we can detect when the last
202 // off-the-record window is closed, in which case we can clean our states
203 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43204 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
205 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29206 }
207
208 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21209 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21210 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29211 }
212
[email protected]4bf6afd2009-10-08 14:00:11213 virtual ProfileId GetRuntimeId() {
214 return reinterpret_cast<ProfileId>(this);
215 }
216
[email protected]f7011fcb2009-01-28 21:54:32217 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29218
219 virtual bool IsOffTheRecord() {
220 return true;
221 }
222
223 virtual Profile* GetOffTheRecordProfile() {
224 return this;
225 }
226
[email protected]860f55492009-03-27 19:50:59227 virtual void DestroyOffTheRecordProfile() {
228 // Suicide is bad!
229 NOTREACHED();
230 }
231
initial.commit09911bf2008-07-26 23:55:29232 virtual Profile* GetOriginalProfile() {
233 return profile_;
234 }
235
[email protected]2f351cb2009-11-09 23:43:34236 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
237 if (!db_tracker_)
238 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
239 return db_tracker_;
240 }
241
initial.commit09911bf2008-07-26 23:55:29242 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49243 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
244 // because we don't want to leak the sites that the user has visited before.
245 return NULL;
initial.commit09911bf2008-07-26 23:55:29246 }
247
[email protected]6014d672008-12-05 00:38:25248 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34249 return NULL;
[email protected]6014d672008-12-05 00:38:25250 }
251
[email protected]0938d3c2009-01-09 20:37:35252 virtual UserScriptMaster* GetUserScriptMaster() {
253 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25254 }
255
[email protected]89ebc7e2009-08-24 22:11:07256 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
257 return NULL;
258 }
259
[email protected]481e1a42009-05-06 20:56:05260 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34261 return NULL;
[email protected]481e1a42009-05-06 20:56:05262 }
263
[email protected]7120f132009-07-20 21:05:37264 virtual ExtensionMessageService* GetExtensionMessageService() {
265 return NULL;
266 }
267
[email protected]34cc84f2009-02-13 10:04:35268 virtual SSLHostState* GetSSLHostState() {
269 if (!ssl_host_state_.get())
270 ssl_host_state_.reset(new SSLHostState());
271
272 DCHECK(ssl_host_state_->CalledOnValidThread());
273 return ssl_host_state_.get();
274 }
275
[email protected]77f6fb432009-09-05 14:21:09276 virtual net::StrictTransportSecurityState* GetStrictTransportSecurityState() {
277 if (!strict_transport_security_state_.get()) {
278 strict_transport_security_state_ =
279 new net::StrictTransportSecurityState();
280 }
[email protected]a9cea7542009-05-20 04:30:23281
[email protected]77f6fb432009-09-05 14:21:09282 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23283 }
284
initial.commit09911bf2008-07-26 23:55:29285 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
286 if (sat == EXPLICIT_ACCESS) {
287 return profile_->GetHistoryService(sat);
288 } else {
289 NOTREACHED() << "This profile is OffTheRecord";
290 return NULL;
291 }
292 }
293
[email protected]0850fa62009-10-08 22:34:29294 virtual HistoryService* GetHistoryServiceWithoutCreating() {
295 return profile_->GetHistoryServiceWithoutCreating();
296 }
297
[email protected]0189bc722009-08-28 21:56:48298 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
299 if (sat == EXPLICIT_ACCESS) {
300 return profile_->GetFaviconService(sat);
301 } else {
302 NOTREACHED() << "This profile is OffTheRecord";
303 return NULL;
304 }
305 }
306
[email protected]90085af02009-10-29 17:53:21307 virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
308 return profile_->GetSearchVersusNavigateClassifier();
309 }
310
initial.commit09911bf2008-07-26 23:55:29311 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
312 if (sat == EXPLICIT_ACCESS) {
313 return profile_->GetWebDataService(sat);
314 } else {
315 NOTREACHED() << "This profile is OffTheRecord";
316 return NULL;
317 }
318 }
319
[email protected]9cddbe372009-10-23 21:23:53320 virtual WebDataService* GetWebDataServiceWithoutCreating() {
321 return profile_->GetWebDataServiceWithoutCreating();
322 }
323
[email protected]e69d33952009-06-03 22:00:41324 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
325 if (sat == EXPLICIT_ACCESS) {
326 return profile_->GetPasswordStore(sat);
327 } else {
328 NOTREACHED() << "This profile is OffTheRecord";
329 return NULL;
330 }
331 }
332
initial.commit09911bf2008-07-26 23:55:29333 virtual PrefService* GetPrefs() {
334 return profile_->GetPrefs();
335 }
336
337 virtual TemplateURLModel* GetTemplateURLModel() {
338 return profile_->GetTemplateURLModel();
339 }
340
341 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
342 return profile_->GetTemplateURLFetcher();
343 }
344
345 virtual DownloadManager* GetDownloadManager() {
346 if (!download_manager_.get()) {
347 scoped_refptr<DownloadManager> dlm(new DownloadManager);
348 dlm->Init(this);
349 download_manager_.swap(dlm);
350 }
351 return download_manager_.get();
352 }
353
354 virtual bool HasCreatedDownloadManager() const {
355 return (download_manager_.get() != NULL);
356 }
357
[email protected]def11712009-11-06 00:42:15358 virtual PersonalDataManager* GetPersonalDataManager() {
359 return NULL;
360 }
361
[email protected]4a190632009-05-09 01:07:42362 virtual void InitThemes() {
363 GetOriginalProfile()->InitThemes();
364 }
365
366 virtual void SetTheme(Extension* extension) {
367 GetOriginalProfile()->SetTheme(extension);
368 }
369
[email protected]a5166af62009-07-03 00:42:29370 virtual void SetNativeTheme() {
371 GetOriginalProfile()->SetNativeTheme();
372 }
373
[email protected]4a190632009-05-09 01:07:42374 virtual void ClearTheme() {
375 GetOriginalProfile()->ClearTheme();
376 }
377
[email protected]51c490b2009-08-03 16:34:34378 virtual Extension* GetTheme() {
379 return GetOriginalProfile()->GetTheme();
380 }
381
[email protected]4a190632009-05-09 01:07:42382 virtual ThemeProvider* GetThemeProvider() {
383 return GetOriginalProfile()->GetThemeProvider();
384 }
385
[email protected]be180c802009-10-23 06:33:31386 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29387 return request_context_;
388 }
389
[email protected]be180c802009-10-23 06:33:31390 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11391 // In OTR mode, media request context is the same as the original one.
392 return request_context_;
[email protected]e7f29642009-03-02 22:53:18393 }
394
[email protected]be180c802009-10-23 06:33:31395 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21396 if (!extensions_request_context_) {
397 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31398 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this);
[email protected]47accfd62009-05-14 18:46:21399 }
400
401 return extensions_request_context_;
402 }
403
[email protected]db36938c2009-08-19 21:48:42404 virtual net::SSLConfigService* GetSSLConfigService() {
405 return GetOriginalProfile()->GetSSLConfigService();
406 }
407
[email protected]a307e31e2009-11-30 16:11:27408 virtual BlacklistManager* GetBlacklistManager() {
409 return GetOriginalProfile()->GetBlacklistManager();
[email protected]eaadd9052009-06-23 18:02:23410 }
411
initial.commit09911bf2008-07-26 23:55:29412 virtual SessionService* GetSessionService() {
413 // Don't save any sessions when off the record.
414 return NULL;
415 }
416
417 virtual void ShutdownSessionService() {
418 // We don't allow a session service, nothing to do.
419 }
420
421 virtual bool HasSessionService() const {
422 // We never have a session service.
423 return false;
424 }
425
426 virtual std::wstring GetName() {
427 return profile_->GetName();
428 }
429
430 virtual void SetName(const std::wstring& name) {
431 profile_->SetName(name);
432 }
433
434 virtual std::wstring GetID() {
435 return profile_->GetID();
436 }
437
438 virtual void SetID(const std::wstring& id) {
439 profile_->SetID(id);
440 }
441
initial.commit09911bf2008-07-26 23:55:29442 virtual bool DidLastSessionExitCleanly() {
443 return profile_->DidLastSessionExitCleanly();
444 }
445
[email protected]d8e41ed2008-09-11 15:22:32446 virtual BookmarkModel* GetBookmarkModel() {
447 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29448 }
449
[email protected]4bb336302009-10-12 05:44:26450 virtual DesktopNotificationService* GetDesktopNotificationService() {
451 return profile_->GetDesktopNotificationService();
452 }
453
[email protected]48352c12009-08-15 01:19:11454 virtual ProfileSyncService* GetProfileSyncService() {
455 return NULL;
[email protected]3a453fa2008-08-15 18:46:34456 }
[email protected]3a453fa2008-08-15 18:46:34457
initial.commit09911bf2008-07-26 23:55:29458 virtual bool IsSameProfile(Profile* profile) {
459 if (profile == static_cast<Profile*>(this))
460 return true;
461 return profile == profile_;
462 }
463
464 virtual Time GetStartTime() const {
465 return start_time_;
466 }
467
468 virtual TabRestoreService* GetTabRestoreService() {
469 return NULL;
470 }
471
[email protected]e7244d82008-10-29 18:13:26472 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41473 }
474
[email protected]85c55dc2009-11-06 03:05:46475 virtual SpellCheckHost* GetSpellCheckHost() {
476 return profile_->GetSpellCheckHost();
477 }
478
479 virtual void ReinitializeSpellCheckHost(bool force) {
480 profile_->ReinitializeSpellCheckHost(force);
481 }
[email protected]85c55dc2009-11-06 03:05:46482
[email protected]3bf335a2009-06-26 20:46:06483 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29484 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21485 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29486 DCHECK(webkit_context_.get());
487 return webkit_context_.get();
488 }
[email protected]3bf335a2009-06-26 20:46:06489
[email protected]449478302009-06-09 20:04:28490 virtual ThumbnailStore* GetThumbnailStore() {
491 return NULL;
492 }
493
initial.commit09911bf2008-07-26 23:55:29494 virtual void MarkAsCleanShutdown() {
495 }
496
[email protected]bdbc87c2009-01-25 05:08:54497 virtual void InitExtensions() {
498 NOTREACHED();
499 }
500
[email protected]ea0c98cf2009-06-18 23:02:54501 virtual void InitWebResources() {
502 NOTREACHED();
503 }
504
[email protected]9c8dd902009-11-19 17:50:42505 virtual NTPResourceCache* GetNTPResourceCache() {
506 // Just return the real profile resource cache.
507 return profile_->GetNTPResourceCache();
508 }
509
initial.commit09911bf2008-07-26 23:55:29510 virtual void ExitedOffTheRecordMode() {
511 // Drop our download manager so we forget about all the downloads made
512 // in off-the-record mode.
513 download_manager_ = NULL;
514 }
515
516 virtual void Observe(NotificationType type,
517 const NotificationSource& source,
518 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56519 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29520 // We are only interested in OTR browser closing.
521 if (Source<Browser>(source)->profile() != this)
522 return;
523
524 // Let's check if we still have an Off The Record window opened.
525 // Note that we check against 1 as this notification is sent before the
526 // browser window is actually removed from the list.
527 if (BrowserList::GetBrowserCount(this) <= 1)
528 ExitedOffTheRecordMode();
529 }
530
531 private:
[email protected]88cf3292009-05-22 01:48:43532 NotificationRegistrar registrar_;
533
initial.commit09911bf2008-07-26 23:55:29534 // The real underlying profile.
535 Profile* profile_;
536
[email protected]6ab9b202008-12-23 22:34:50537 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19538 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29539
[email protected]13c30922009-11-19 03:43:19540 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_;
[email protected]23f1ef12009-09-01 22:30:30541
initial.commit09911bf2008-07-26 23:55:29542 // The download manager that only stores downloaded items in memory.
543 scoped_refptr<DownloadManager> download_manager_;
544
[email protected]3bf335a2009-06-26 20:46:06545 // Use a special WebKit context for OTR browsing.
546 scoped_refptr<WebKitContext> webkit_context_;
547
[email protected]34cc84f2009-02-13 10:04:35548 // We don't want SSLHostState from the OTR profile to leak back to the main
549 // profile because then the main profile would learn some of the host names
550 // the user visited while OTR.
551 scoped_ptr<SSLHostState> ssl_host_state_;
552
[email protected]77f6fb432009-09-05 14:21:09553 // The StrictTransportSecurityState that only stores enabled sites in memory.
554 scoped_refptr<net::StrictTransportSecurityState>
555 strict_transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23556
initial.commit09911bf2008-07-26 23:55:29557 // Time we were started.
558 Time start_time_;
559
[email protected]2f351cb2009-11-09 23:43:34560 // The main database tracker for this profile.
561 // Should be used only on the file thread.
562 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
563
[email protected]90085af02009-10-29 17:53:21564 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29565};
566
[email protected]f7011fcb2009-01-28 21:54:32567ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29568 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39569 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07570 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32571 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57572 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21573 extensions_request_context_(NULL),
[email protected]a307e31e2009-11-30 16:11:27574 blacklist_manager_(NULL),
575 blacklist_manager_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32576 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48577 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32578 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41579 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32580 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42581 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32582 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46583 spellcheck_host_(NULL),
584 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29585 shutdown_session_service_(false) {
586 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
587 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14588 create_session_service_timer_.Start(
589 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
590 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54591
[email protected]89ebc7e2009-08-24 22:11:07592 if (CommandLine::ForCurrentProcess()->HasSwitch(
593 switches::kEnableExtensionTimelineApi)) {
594 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
595 }
596
[email protected]382a0702009-06-26 17:12:27597 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37598 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27599
[email protected]e7244d82008-10-29 18:13:26600 PrefService* prefs = GetPrefs();
601 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
602 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58603 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58604
[email protected]405a64b2009-09-16 21:03:44605#if defined(OS_MACOSX)
606 // If the profile directory doesn't already have a cache directory and it
607 // is under ~/Library/Application Support, use a suitable cache directory
608 // under ~/Library/Caches. For example, a profile directory of
609 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
610 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
611 // ~/Library/Caches/Google/Chrome/MyProfileName.
612 //
613 // TODO(akalin): Come up with unit tests for this.
614 // TODO(akalin): Use for Linux, too?
615 if (!HasACacheSubdir(path_)) {
616 FilePath app_data_path, user_cache_path;
617 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
618 PathService::Get(base::DIR_CACHE, &user_cache_path) &&
619 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
620 base_cache_path_ = user_cache_path;
621 }
622 }
623#else
[email protected]bc96d562009-08-11 18:45:13624 if (!PathService::IsOverridden(chrome::DIR_USER_DATA))
625 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_);
[email protected]405a64b2009-09-16 21:03:44626#endif
[email protected]bc96d562009-08-11 18:45:13627 if (base_cache_path_.empty())
628 base_cache_path_ = path_;
629
[email protected]4a190632009-05-09 01:07:42630 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43631 registrar_.Add(this, NotificationType::THEME_INSTALLED,
632 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11633
634 // Listen for bookmark model load, to bootstrap the sync service.
635 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
636 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42637
638 ssl_config_service_manager_.reset(
639 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53640
641#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29642 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53643#endif
initial.commit09911bf2008-07-26 23:55:29644}
645
[email protected]bdbc87c2009-01-25 05:08:54646void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41647 if (user_script_master_ || extensions_service_)
648 return; // Already initialized.
649
[email protected]bdbc87c2009-01-25 05:08:54650 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18651 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36652
653 FilePath script_dir; // Don't look for user scripts in any directory.
654 // TODO(aa): We should just remove this functionality,
655 // since it isn't used anymore.
[email protected]95d29192009-10-30 01:49:06656 user_script_master_ = new UserScriptMaster(script_dir);
[email protected]faed6e12009-11-24 22:38:36657
[email protected]894bb502009-05-21 22:39:57658 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23659 this,
660 CommandLine::ForCurrentProcess(),
661 GetPrefs(),
662 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36663 true);
[email protected]bdbc87c2009-01-25 05:08:54664
[email protected]9197f3b2009-06-02 00:49:27665 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12666
667 // Load any extensions specified with --load-extension.
668 if (command_line->HasSwitch(switches::kLoadExtension)) {
669 std::wstring path_string =
670 command_line->GetSwitchValue(switches::kLoadExtension);
671 FilePath path = FilePath::FromWStringHack(path_string);
672 extensions_service_->LoadExtension(path);
673
674 // Tell UserScriptMaser to watch this extension's directory for changes so
675 // you can live edit content scripts during development.
676 user_script_master_->AddWatchedPath(path);
677 }
[email protected]bdbc87c2009-01-25 05:08:54678}
679
[email protected]ea0c98cf2009-06-18 23:02:54680void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07681 if (web_resource_service_)
682 return; // Already initialized.
683
[email protected]6fad2632009-11-02 05:59:37684 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54685 web_resource_service_->StartAfterDelay();
686}
687
[email protected]9c8dd902009-11-19 17:50:42688NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
689 if (!ntp_resource_cache_.get())
690 ntp_resource_cache_.reset(new NTPResourceCache(this));
691 return ntp_resource_cache_.get();
692}
693
initial.commit09911bf2008-07-26 23:55:29694ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19695 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29696
697 StopCreateSessionServiceTimer();
698 // TemplateURLModel schedules a task on the WebDataService from its
699 // destructor. Delete it first to ensure the task gets scheduled before we
700 // shut down the database.
701 template_url_model_.reset();
702
703 // The download manager queries the history system and should be deleted
704 // before the history is shutdown so it can properly cancel all requests.
705 download_manager_ = NULL;
706
[email protected]4a190632009-05-09 01:07:42707 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15708 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42709
[email protected]44961292009-07-20 20:03:09710 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
711 // save any new thumbnails to disk and release its reference to the
712 // HistoryService.
713 if (thumbnail_store_.get())
714 thumbnail_store_->Shutdown();
715
[email protected]e7244d82008-10-29 18:13:26716 // Remove pref observers.
717 PrefService* prefs = GetPrefs();
718 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
719 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58720 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26721
[email protected]9c8dd902009-11-19 17:50:42722 // Delete the NTP resource cache so we can unregister pref observers.
723 ntp_resource_cache_.reset();
724
[email protected]48352c12009-08-15 01:19:11725 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34726
initial.commit09911bf2008-07-26 23:55:29727 // Both HistoryService and WebDataService maintain threads for background
728 // processing. Its possible each thread still has tasks on it that have
729 // increased the ref count of the service. In such a situation, when we
730 // decrement the refcount, it won't be 0, and the threads/databases aren't
731 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
732 // databases are properly closed.
733 if (web_data_service_.get())
734 web_data_service_->Shutdown();
735
736 if (history_service_.get())
737 history_service_->Cleanup();
738
[email protected]85c55dc2009-11-06 03:05:46739 if (spellcheck_host_.get())
740 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29741
[email protected]cfc06f122009-11-16 22:18:55742 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21743 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50744
[email protected]47accfd62009-05-14 18:46:21745 CleanupRequestContext(request_context_);
746 CleanupRequestContext(media_request_context_);
747 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17748
[email protected]d8e41ed2008-09-11 15:22:32749 // HistoryService may call into the BookmarkModel, as such we need to
750 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46751 // HistoryService will join with HistoryService's backend thread so that
752 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32753 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46754 history_service_ = NULL;
755 bookmark_bar_model_.reset();
756
[email protected]0189bc722009-08-28 21:56:48757 // FaviconService depends on HistoryServce so make sure we delete
758 // HistoryService first.
759 favicon_service_ = NULL;
760
[email protected]7120f132009-07-20 21:05:37761 extension_message_service_->ProfileDestroyed();
762
[email protected]6ef635e42009-07-26 06:16:12763 if (extensions_service_)
764 extensions_service_->ProfileDestroyed();
765
[email protected]66da08b2009-10-19 22:27:00766 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29767 MarkAsCleanShutdown();
768}
769
[email protected]4bf6afd2009-10-08 14:00:11770ProfileId ProfileImpl::GetRuntimeId() {
771 return reinterpret_cast<ProfileId>(this);
772}
773
[email protected]f7011fcb2009-01-28 21:54:32774FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29775 return path_;
776}
777
778bool ProfileImpl::IsOffTheRecord() {
779 return false;
780}
781
782Profile* ProfileImpl::GetOffTheRecordProfile() {
783 if (!off_the_record_profile_.get()) {
784 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
785 off_the_record_profile_.swap(p);
786 }
787 return off_the_record_profile_.get();
788}
789
[email protected]860f55492009-03-27 19:50:59790void ProfileImpl::DestroyOffTheRecordProfile() {
791 off_the_record_profile_.reset();
792}
793
initial.commit09911bf2008-07-26 23:55:29794Profile* ProfileImpl::GetOriginalProfile() {
795 return this;
796}
797
[email protected]2f351cb2009-11-09 23:43:34798webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
799 if (!db_tracker_)
800 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
801 return db_tracker_;
802}
803
initial.commit09911bf2008-07-26 23:55:29804VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
805 if (!visited_link_master_.get()) {
806 scoped_ptr<VisitedLinkMaster> visited_links(
[email protected]6fad2632009-11-02 05:59:37807 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29808 if (!visited_links->Init())
809 return NULL;
810 visited_link_master_.swap(visited_links);
811 }
812
813 return visited_link_master_.get();
814}
815
[email protected]6014d672008-12-05 00:38:25816ExtensionsService* ProfileImpl::GetExtensionsService() {
817 return extensions_service_.get();
818}
819
[email protected]0938d3c2009-01-09 20:37:35820UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35821 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25822}
823
[email protected]89ebc7e2009-08-24 22:11:07824ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
825 return extension_devtools_manager_.get();
826}
827
[email protected]481e1a42009-05-06 20:56:05828ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27829 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05830}
831
[email protected]7120f132009-07-20 21:05:37832ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
833 return extension_message_service_.get();
834}
835
[email protected]34cc84f2009-02-13 10:04:35836SSLHostState* ProfileImpl::GetSSLHostState() {
837 if (!ssl_host_state_.get())
838 ssl_host_state_.reset(new SSLHostState());
839
840 DCHECK(ssl_host_state_->CalledOnValidThread());
841 return ssl_host_state_.get();
842}
843
[email protected]77f6fb432009-09-05 14:21:09844net::StrictTransportSecurityState*
845 ProfileImpl::GetStrictTransportSecurityState() {
846 if (!strict_transport_security_state_.get()) {
847 strict_transport_security_state_ = new net::StrictTransportSecurityState();
[email protected]0c03b432009-11-17 21:41:08848 strict_transport_security_persister_ =
849 new StrictTransportSecurityPersister();
850 strict_transport_security_persister_->Initialize(
[email protected]6fad2632009-11-02 05:59:37851 strict_transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51852 }
[email protected]a9cea7542009-05-20 04:30:23853
[email protected]77f6fb432009-09-05 14:21:09854 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23855}
856
initial.commit09911bf2008-07-26 23:55:29857PrefService* ProfileImpl::GetPrefs() {
858 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37859 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29860
861 // The Profile class and ProfileManager class may read some prefs so
862 // register known prefs as soon as possible.
863 Profile::RegisterUserPrefs(prefs_.get());
864 ProfileManager::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53865#if defined(OS_CHROMEOS)
866 // Register Touchpad prefs here instead of in browser_prefs because these
867 // prefs are used in the constructor of ProfileImpl which happens before
868 // browser_prefs' RegisterAllPrefs is called.
[email protected]fecc1522009-10-15 21:08:29869 chromeos::Preferences::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53870#endif
initial.commit09911bf2008-07-26 23:55:29871
872 // The last session exited cleanly if there is no pref for
873 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
874 last_session_exited_cleanly_ =
875 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
876 // Mark the session as open.
877 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
878 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36879 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29880 }
881
882 return prefs_.get();
883}
884
[email protected]f7011fcb2009-01-28 21:54:32885FilePath ProfileImpl::GetPrefFilePath() {
886 FilePath pref_file_path = path_;
887 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29888 return pref_file_path;
889}
890
[email protected]be180c802009-10-23 06:33:31891URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29892 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32893 FilePath cookie_path = GetPath();
894 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13895 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31896 int max_size;
897 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42898
[email protected]405a64b2009-09-16 21:03:44899 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31900 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
901 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29902
[email protected]6ab9b202008-12-23 22:34:50903 // The first request context is always a normal (non-OTR) request context.
904 // Even when Chromium is started in OTR mode, a normal profile is always
905 // created first.
906 if (!default_request_context_) {
907 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31908 // TODO(eroman): this isn't terribly useful anymore now that the
909 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50910 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56911 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50912 NotificationService::AllSources(), NotificationService::NoDetails());
913 }
initial.commit09911bf2008-07-26 23:55:29914 }
915
916 return request_context_;
917}
918
[email protected]be180c802009-10-23 06:33:31919URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18920 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13921 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31922 int max_size;
923 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14924
[email protected]405a64b2009-09-16 21:03:44925 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31926 media_request_context_ =
927 ChromeURLRequestContextGetter::CreateOriginalForMedia(
928 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18929 }
930
931 return media_request_context_;
932}
933
[email protected]0189bc722009-08-28 21:56:48934FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
935 if (!favicon_service_created_) {
936 favicon_service_created_ = true;
937 scoped_refptr<FaviconService> service(new FaviconService(this));
938 favicon_service_.swap(service);
939 }
940 return favicon_service_.get();
941}
942
[email protected]be180c802009-10-23 06:33:31943URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21944 if (!extensions_request_context_) {
945 FilePath cookie_path = GetPath();
946 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
947
948 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31949 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
950 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21951 }
952
953 return extensions_request_context_;
954}
955
[email protected]db36938c2009-08-19 21:48:42956net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
957 return ssl_config_service_manager_->Get();
958}
959
[email protected]a307e31e2009-11-30 16:11:27960BlacklistManager* ProfileImpl::GetBlacklistManager() {
961 if (!CommandLine::ForCurrentProcess()->HasSwitch(
962 switches::kEnablePrivacyBlacklists)) {
963 return NULL;
964 }
965 if (!blacklist_manager_created_) {
966 blacklist_manager_created_ = true;
967 blacklist_manager_ = new BlacklistManager(this, GetExtensionsService());
968 blacklist_manager_->Initialize();
969 }
970 return blacklist_manager_.get();
[email protected]eaadd9052009-06-23 18:02:23971}
972
initial.commit09911bf2008-07-26 23:55:29973HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
974 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:46975 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:29976 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:32977 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:29978 return NULL;
979 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:29980
981 // Send out the notification that the history service was created.
982 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56983 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:29984 Details<HistoryService>(history_service_.get()));
985 }
986 return history_service_.get();
987}
988
[email protected]0850fa62009-10-08 22:34:29989HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
990 return history_service_.get();
991}
992
initial.commit09911bf2008-07-26 23:55:29993TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
994 if (!template_url_model_.get())
995 template_url_model_.reset(new TemplateURLModel(this));
996 return template_url_model_.get();
997}
998
999TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1000 if (!template_url_fetcher_.get())
1001 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1002 return template_url_fetcher_.get();
1003}
1004
[email protected]11f4857282009-11-13 19:56:171005SearchVersusNavigateClassifier*
1006ProfileImpl::GetSearchVersusNavigateClassifier() {
[email protected]90085af02009-10-29 17:53:211007 if (!search_versus_navigate_classifier_.get()) {
1008 search_versus_navigate_classifier_.reset(
1009 new SearchVersusNavigateClassifier(this));
1010 }
1011 return search_versus_navigate_classifier_.get();
1012}
1013
initial.commit09911bf2008-07-26 23:55:291014WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1015 if (!created_web_data_service_)
1016 CreateWebDataService();
1017 return web_data_service_.get();
1018}
1019
[email protected]9cddbe372009-10-23 21:23:531020WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1021 return web_data_service_.get();
1022}
1023
initial.commit09911bf2008-07-26 23:55:291024void ProfileImpl::CreateWebDataService() {
1025 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1026 created_web_data_service_ = true;
1027 scoped_refptr<WebDataService> wds(new WebDataService());
1028 if (!wds->Init(GetPath()))
1029 return;
1030 web_data_service_.swap(wds);
1031}
1032
[email protected]e69d33952009-06-03 22:00:411033PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1034 if (!created_password_store_)
1035 CreatePasswordStore();
1036 return password_store_.get();
1037}
1038
1039void ProfileImpl::CreatePasswordStore() {
1040 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1041 created_password_store_ = true;
1042 scoped_refptr<PasswordStore> ps;
1043#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251044 // TODO(evanm): implement "native" password management.
1045 // This bug describes the issues.
1046 // http://code.google.com/p/chromium/issues/detail?id=12351
1047 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1048 if (!ps->Init())
1049 return;
[email protected]e69d33952009-06-03 22:00:411050#elif defined(OS_WIN)
1051 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561052#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171053 FilePath login_db_file_path = GetPath();
1054 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1055 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1056 if (!login_db->Init(login_db_file_path)) {
1057 LOG(ERROR) << "Could not initialize login database.";
1058 delete login_db;
1059 return;
1060 }
1061 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411062#else
1063 NOTIMPLEMENTED();
1064#endif
1065 if (!ps || !ps->Init()) {
1066 // Try falling back to the default password manager
1067 LOG(WARNING) << "Could not initialise native password manager - "
1068 "falling back to default";
1069 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1070 if (!ps->Init())
1071 return;
1072 }
1073 password_store_.swap(ps);
1074}
1075
initial.commit09911bf2008-07-26 23:55:291076DownloadManager* ProfileImpl::GetDownloadManager() {
1077 if (!created_download_manager_) {
1078 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1079 dlm->Init(this);
1080 created_download_manager_ = true;
1081 download_manager_.swap(dlm);
1082 }
1083 return download_manager_.get();
1084}
1085
1086bool ProfileImpl::HasCreatedDownloadManager() const {
1087 return created_download_manager_;
1088}
1089
[email protected]def11712009-11-06 00:42:151090PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1091 if (!personal_data_manager_.get()) {
1092 personal_data_manager_.reset(new PersonalDataManager);
1093 }
1094 return personal_data_manager_.get();
1095}
1096
[email protected]4a190632009-05-09 01:07:421097void ProfileImpl::InitThemes() {
1098 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571099#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151100 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291101#else
[email protected]761962c2009-09-25 00:18:151102 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291103#endif
[email protected]761962c2009-09-25 00:18:151104 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421105 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421106 }
1107}
1108
1109void ProfileImpl::SetTheme(Extension* extension) {
1110 InitThemes();
1111 theme_provider_.get()->SetTheme(extension);
1112}
1113
[email protected]a5166af62009-07-03 00:42:291114void ProfileImpl::SetNativeTheme() {
1115 InitThemes();
1116 theme_provider_.get()->SetNativeTheme();
1117}
1118
[email protected]4a190632009-05-09 01:07:421119void ProfileImpl::ClearTheme() {
1120 InitThemes();
1121 theme_provider_.get()->UseDefaultTheme();
1122}
1123
[email protected]51c490b2009-08-03 16:34:341124Extension* ProfileImpl::GetTheme() {
1125 InitThemes();
1126
1127 std::string id = theme_provider_.get()->GetThemeID();
1128 if (id == BrowserThemeProvider::kDefaultThemeID)
1129 return NULL;
1130
[email protected]61b411612009-11-10 23:17:411131 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341132}
1133
[email protected]4a190632009-05-09 01:07:421134ThemeProvider* ProfileImpl::GetThemeProvider() {
1135 InitThemes();
1136 return theme_provider_.get();
1137}
1138
initial.commit09911bf2008-07-26 23:55:291139SessionService* ProfileImpl::GetSessionService() {
1140 if (!session_service_.get() && !shutdown_session_service_) {
1141 session_service_ = new SessionService(this);
1142 session_service_->ResetFromCurrentBrowsers();
1143 }
1144 return session_service_.get();
1145}
1146
1147void ProfileImpl::ShutdownSessionService() {
1148 if (shutdown_session_service_)
1149 return;
1150
1151 // We're about to exit, force creation of the session service if it hasn't
1152 // been created yet. We do this to ensure session state matches the point in
1153 // time the user exited.
1154 GetSessionService();
1155 shutdown_session_service_ = true;
1156 session_service_ = NULL;
1157}
1158
1159bool ProfileImpl::HasSessionService() const {
1160 return (session_service_.get() != NULL);
1161}
1162
1163std::wstring ProfileImpl::GetName() {
1164 return GetPrefs()->GetString(prefs::kProfileName);
1165}
1166void ProfileImpl::SetName(const std::wstring& name) {
1167 GetPrefs()->SetString(prefs::kProfileName, name);
1168}
1169
1170std::wstring ProfileImpl::GetID() {
1171 return GetPrefs()->GetString(prefs::kProfileID);
1172}
1173void ProfileImpl::SetID(const std::wstring& id) {
1174 GetPrefs()->SetString(prefs::kProfileID, id);
1175}
1176
initial.commit09911bf2008-07-26 23:55:291177bool ProfileImpl::DidLastSessionExitCleanly() {
1178 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1179 // it to be set by asking for the prefs.
1180 GetPrefs();
1181 return last_session_exited_cleanly_;
1182}
1183
[email protected]d8e41ed2008-09-11 15:22:321184BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461185 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321186 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461187 bookmark_bar_model_->Load();
1188 }
initial.commit09911bf2008-07-26 23:55:291189 return bookmark_bar_model_.get();
1190}
1191
1192bool ProfileImpl::IsSameProfile(Profile* profile) {
1193 if (profile == static_cast<Profile*>(this))
1194 return true;
1195 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1196 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1197}
1198
1199Time ProfileImpl::GetStartTime() const {
1200 return start_time_;
1201}
1202
1203TabRestoreService* ProfileImpl::GetTabRestoreService() {
1204 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191205 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291206 return tab_restore_service_.get();
1207}
1208
[email protected]449478302009-06-09 20:04:281209ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1210 if (!thumbnail_store_.get()) {
1211 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251212 thumbnail_store_->Init(
1213 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281214 }
1215 return thumbnail_store_.get();
1216}
1217
initial.commit09911bf2008-07-26 23:55:291218void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191219 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291220}
1221
[email protected]85c55dc2009-11-06 03:05:461222SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1223 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1224}
1225
1226void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1227 // If we are already loading the spellchecker, and this is just a hint to
1228 // load the spellchecker, do nothing.
1229 if (!force && spellcheck_host_.get())
1230 return;
1231
[email protected]f41301e2009-11-16 21:30:071232 spellcheck_host_ready_ = false;
1233
[email protected]85c55dc2009-11-06 03:05:461234 bool notify = false;
1235 if (spellcheck_host_.get()) {
1236 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051237 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461238 notify = true;
1239 }
1240
1241 PrefService* prefs = GetPrefs();
1242 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1243 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1244 spellcheck_host_ = new SpellCheckHost(this,
1245 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1246 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071247 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461248 } else if (notify) {
1249 // The spellchecker has been disabled.
1250 SpellCheckHostInitialized();
1251 }
1252}
1253
1254void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171255 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291256 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1257 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461258 NotificationService::current()->Notify(
1259 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1260 Source<Profile>(this), NotificationService::NoDetails());
1261}
initial.commit09911bf2008-07-26 23:55:291262
[email protected]3bf335a2009-06-26 20:46:061263WebKitContext* ProfileImpl::GetWebKitContext() {
1264 if (!webkit_context_.get())
1265 webkit_context_ = new WebKitContext(path_, false);
1266 DCHECK(webkit_context_.get());
1267 return webkit_context_.get();
1268}
1269
[email protected]4bb336302009-10-12 05:44:261270DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1271 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1272 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261273 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031274 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261275 }
[email protected]4bb336302009-10-12 05:44:261276 return desktop_notification_service_.get();
1277}
1278
initial.commit09911bf2008-07-26 23:55:291279void ProfileImpl::MarkAsCleanShutdown() {
1280 if (prefs_.get()) {
1281 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1282 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1283
1284 // NOTE: If you change what thread this writes on, be sure and update
1285 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361286 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291287 }
1288}
1289
[email protected]e7244d82008-10-29 18:13:261290void ProfileImpl::Observe(NotificationType type,
1291 const NotificationSource& source,
1292 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561293 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261294 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1295 PrefService* prefs = Source<PrefService>(source).ptr();
1296 DCHECK(pref_name_in && prefs);
1297 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461298 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461299 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291300 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1301 NotificationService::current()->Notify(
1302 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1303 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261304 }
[email protected]4a190632009-05-09 01:07:421305 } else if (NotificationType::THEME_INSTALLED == type) {
1306 Extension* extension = Details<Extension>(details).ptr();
1307 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111308 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1309 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1310 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1311 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261312 }
1313}
1314
initial.commit09911bf2008-07-26 23:55:291315void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141316 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291317}
[email protected]3a453fa2008-08-15 18:46:341318
[email protected]48352c12009-08-15 01:19:111319ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431320 if (!ProfileSyncService::IsSyncEnabled()) {
1321 return NULL;
[email protected]7367f1a2009-10-10 01:09:441322 }
[email protected]eec3bcfa2009-11-12 17:23:431323 if (!sync_service_.get())
1324 InitSyncService();
1325 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111326}
1327
1328void ProfileImpl::InitSyncService() {
[email protected]48352c12009-08-15 01:19:111329 sync_service_.reset(new ProfileSyncService(this));
1330 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111331}