blob: 111029baf47f2fb5a0d2bf6cad94a8c9a5f2788a [file] [log] [blame]
[email protected]40bd6582009-12-04 23:49:511// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// 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]9c92d192009-12-02 08:03:1629#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4230#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4231#include "chrome/browser/history/history.h"
[email protected]40bd6582009-12-04 23:49:5132#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0633#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5034#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4235#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2636#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4137#include "chrome/browser/password_manager/password_store_default.h"
[email protected]a307e31e2009-11-30 16:11:2738#include "chrome/browser/privacy_blacklist/blacklist_manager.h"
initial.commit09911bf2008-07-26 23:55:2939#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2640#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]90085af02009-10-29 17:53:2141#include "chrome/browser/search_versus_navigate_classifier.h"
[email protected]1132436e2009-04-08 20:06:3342#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4643#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4444#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3045#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3346#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1147#include "chrome/browser/sync/profile_sync_service.h"
[email protected]449478302009-06-09 20:04:2848#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3950#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2951#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5652#include "chrome/browser/web_resource/web_resource_service.h"
[email protected]23f1ef12009-09-01 22:30:3053#include "chrome/common/appcache/chrome_appcache_service.h"
initial.commit09911bf2008-07-26 23:55:2954#include "chrome/common/chrome_constants.h"
55#include "chrome/common/chrome_paths.h"
56#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5857#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/common/notification_service.h"
59#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3260#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5861#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4262#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3463#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2964
[email protected]a5166af62009-07-03 00:42:2965#if defined(OS_LINUX)
66#include "chrome/browser/gtk/gtk_theme_provider.h"
67#endif
68
[email protected]e1acf6f2008-10-27 20:43:3369using base::Time;
70using base::TimeDelta;
71
[email protected]e5642992009-06-26 23:06:3172namespace {
73
initial.commit09911bf2008-07-26 23:55:2974// Delay, in milliseconds, before we explicitly create the SessionService.
75static const int kCreateSessionServiceDelayMS = 500;
76
[email protected]e5642992009-06-26 23:06:3177enum ContextType {
78 kNormalContext,
79 kMediaContext
80};
81
82// Gets the cache parameters from the command line. |type| is the type of
83// request context that we need, |cache_path| will be set to the user provided
84// path, or will not be touched if there is not an argument. |max_size| will
85// be the user provided value or zero by default.
86void GetCacheParameters(ContextType type, FilePath* cache_path,
87 int* max_size) {
88 DCHECK(cache_path);
89 DCHECK(max_size);
90
91 // Override the cache location if specified by the user.
92 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
93 switches::kDiskCacheDir));
94
95 if (!user_path.empty()) {
96 *cache_path = FilePath::FromWStringHack(user_path);
97 }
98
[email protected]b7e0a2a2009-10-13 02:07:2599 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
100 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31101 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25102 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31103
104 // By default we let the cache determine the right size.
105 *max_size = 0;
106 if (!StringToInt(value, max_size)) {
107 *max_size = 0;
108 } else if (max_size < 0) {
109 *max_size = 0;
110 }
111}
112
[email protected]405a64b2009-09-16 21:03:44113FilePath GetCachePath(const FilePath& base) {
114 return base.Append(chrome::kCacheDirname);
115}
116
117FilePath GetMediaCachePath(const FilePath& base) {
118 return base.Append(chrome::kMediaCacheDirname);
119}
120
121bool HasACacheSubdir(const FilePath &dir) {
122 return file_util::PathExists(GetCachePath(dir)) ||
123 file_util::PathExists(GetMediaCachePath(dir));
124}
125
[email protected]e5642992009-06-26 23:06:31126} // namespace
127
initial.commit09911bf2008-07-26 23:55:29128// A pointer to the request context for the default profile. See comments on
129// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31130URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29131
[email protected]be180c802009-10-23 06:33:31132static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19133 if (context)
[email protected]47accfd62009-05-14 18:46:21134 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21135}
136
[email protected]34cc84f2009-02-13 10:04:35137// static
[email protected]4bf6afd2009-10-08 14:00:11138const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
139
140// static
initial.commit09911bf2008-07-26 23:55:29141void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55142 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29143 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
144 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12145 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26146 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
147 IDS_SPELLCHECK_DICTIONARY);
148 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58149 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]a5166af62009-07-03 00:42:29150#if defined(OS_LINUX)
151 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
152#endif
[email protected]f017cc92009-12-14 20:48:07153 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[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]326e6792009-12-11 21:04:42276 virtual net::TransportSecurityState* GetTransportSecurityState() {
277 if (!transport_security_state_.get()) {
278 transport_security_state_ =
279 new net::TransportSecurityState();
[email protected]77f6fb432009-09-05 14:21:09280 }
[email protected]a9cea7542009-05-20 04:30:23281
[email protected]326e6792009-12-11 21:04:42282 return 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]40bd6582009-12-04 23:49:51408 virtual HostZoomMap* GetHostZoomMap() {
409 // Need to use a separate map from the normal one to avoid persisting zoom
410 // changes in OTR mode.
411 if (!host_zoom_map_)
412 host_zoom_map_ = new HostZoomMap(this);
413 return host_zoom_map_.get();
414 }
415
[email protected]a307e31e2009-11-30 16:11:27416 virtual BlacklistManager* GetBlacklistManager() {
417 return GetOriginalProfile()->GetBlacklistManager();
[email protected]eaadd9052009-06-23 18:02:23418 }
419
initial.commit09911bf2008-07-26 23:55:29420 virtual SessionService* GetSessionService() {
421 // Don't save any sessions when off the record.
422 return NULL;
423 }
424
425 virtual void ShutdownSessionService() {
426 // We don't allow a session service, nothing to do.
427 }
428
429 virtual bool HasSessionService() const {
430 // We never have a session service.
431 return false;
432 }
433
initial.commit09911bf2008-07-26 23:55:29434 virtual bool DidLastSessionExitCleanly() {
435 return profile_->DidLastSessionExitCleanly();
436 }
437
[email protected]d8e41ed2008-09-11 15:22:32438 virtual BookmarkModel* GetBookmarkModel() {
439 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29440 }
441
[email protected]4bb336302009-10-12 05:44:26442 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58443 if (!desktop_notification_service_.get()) {
444 desktop_notification_service_.reset(new DesktopNotificationService(
445 this, g_browser_process->notification_ui_manager()));
446 }
447 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26448 }
449
[email protected]48352c12009-08-15 01:19:11450 virtual ProfileSyncService* GetProfileSyncService() {
451 return NULL;
[email protected]3a453fa2008-08-15 18:46:34452 }
[email protected]3a453fa2008-08-15 18:46:34453
initial.commit09911bf2008-07-26 23:55:29454 virtual bool IsSameProfile(Profile* profile) {
455 if (profile == static_cast<Profile*>(this))
456 return true;
457 return profile == profile_;
458 }
459
460 virtual Time GetStartTime() const {
461 return start_time_;
462 }
463
464 virtual TabRestoreService* GetTabRestoreService() {
465 return NULL;
466 }
467
[email protected]e7244d82008-10-29 18:13:26468 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41469 }
470
[email protected]85c55dc2009-11-06 03:05:46471 virtual SpellCheckHost* GetSpellCheckHost() {
472 return profile_->GetSpellCheckHost();
473 }
474
475 virtual void ReinitializeSpellCheckHost(bool force) {
476 profile_->ReinitializeSpellCheckHost(force);
477 }
[email protected]85c55dc2009-11-06 03:05:46478
[email protected]3bf335a2009-06-26 20:46:06479 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29480 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21481 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29482 DCHECK(webkit_context_.get());
483 return webkit_context_.get();
484 }
[email protected]3bf335a2009-06-26 20:46:06485
[email protected]449478302009-06-09 20:04:28486 virtual ThumbnailStore* GetThumbnailStore() {
487 return NULL;
488 }
489
initial.commit09911bf2008-07-26 23:55:29490 virtual void MarkAsCleanShutdown() {
491 }
492
[email protected]bdbc87c2009-01-25 05:08:54493 virtual void InitExtensions() {
494 NOTREACHED();
495 }
496
[email protected]ea0c98cf2009-06-18 23:02:54497 virtual void InitWebResources() {
498 NOTREACHED();
499 }
500
[email protected]9c8dd902009-11-19 17:50:42501 virtual NTPResourceCache* GetNTPResourceCache() {
502 // Just return the real profile resource cache.
503 return profile_->GetNTPResourceCache();
504 }
505
initial.commit09911bf2008-07-26 23:55:29506 virtual void ExitedOffTheRecordMode() {
507 // Drop our download manager so we forget about all the downloads made
508 // in off-the-record mode.
509 download_manager_ = NULL;
510 }
511
512 virtual void Observe(NotificationType type,
513 const NotificationSource& source,
514 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56515 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29516 // We are only interested in OTR browser closing.
517 if (Source<Browser>(source)->profile() != this)
518 return;
519
520 // Let's check if we still have an Off The Record window opened.
521 // Note that we check against 1 as this notification is sent before the
522 // browser window is actually removed from the list.
523 if (BrowserList::GetBrowserCount(this) <= 1)
524 ExitedOffTheRecordMode();
525 }
526
527 private:
[email protected]88cf3292009-05-22 01:48:43528 NotificationRegistrar registrar_;
529
initial.commit09911bf2008-07-26 23:55:29530 // The real underlying profile.
531 Profile* profile_;
532
[email protected]6ab9b202008-12-23 22:34:50533 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19534 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29535
[email protected]13c30922009-11-19 03:43:19536 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_;
[email protected]23f1ef12009-09-01 22:30:30537
[email protected]40bd6582009-12-04 23:49:51538 scoped_refptr<HostZoomMap> host_zoom_map_;
539
initial.commit09911bf2008-07-26 23:55:29540 // The download manager that only stores downloaded items in memory.
541 scoped_refptr<DownloadManager> download_manager_;
542
[email protected]7d7696c52009-12-01 20:54:58543 // Use a separate desktop notification service for OTR.
544 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
545
[email protected]3bf335a2009-06-26 20:46:06546 // Use a special WebKit context for OTR browsing.
547 scoped_refptr<WebKitContext> webkit_context_;
548
[email protected]34cc84f2009-02-13 10:04:35549 // We don't want SSLHostState from the OTR profile to leak back to the main
550 // profile because then the main profile would learn some of the host names
551 // the user visited while OTR.
552 scoped_ptr<SSLHostState> ssl_host_state_;
553
[email protected]326e6792009-12-11 21:04:42554 // The TransportSecurityState that only stores enabled sites in memory.
555 scoped_refptr<net::TransportSecurityState>
556 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23557
initial.commit09911bf2008-07-26 23:55:29558 // Time we were started.
559 Time start_time_;
560
[email protected]2f351cb2009-11-09 23:43:34561 // The main database tracker for this profile.
562 // Should be used only on the file thread.
563 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
564
[email protected]90085af02009-10-29 17:53:21565 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29566};
567
[email protected]f7011fcb2009-01-28 21:54:32568ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29569 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39570 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07571 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32572 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57573 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21574 extensions_request_context_(NULL),
[email protected]40bd6582009-12-04 23:49:51575 host_zoom_map_(NULL),
[email protected]a307e31e2009-11-30 16:11:27576 blacklist_manager_(NULL),
577 blacklist_manager_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32578 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48579 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32580 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41581 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32582 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42583 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32584 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46585 spellcheck_host_(NULL),
586 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29587 shutdown_session_service_(false) {
588 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
589 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14590 create_session_service_timer_.Start(
591 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
592 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54593
[email protected]89ebc7e2009-08-24 22:11:07594 if (CommandLine::ForCurrentProcess()->HasSwitch(
595 switches::kEnableExtensionTimelineApi)) {
596 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
597 }
598
[email protected]382a0702009-06-26 17:12:27599 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37600 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27601
[email protected]e7244d82008-10-29 18:13:26602 PrefService* prefs = GetPrefs();
603 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
604 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58605 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58606
[email protected]405a64b2009-09-16 21:03:44607#if defined(OS_MACOSX)
608 // If the profile directory doesn't already have a cache directory and it
609 // is under ~/Library/Application Support, use a suitable cache directory
610 // under ~/Library/Caches. For example, a profile directory of
611 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
612 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
613 // ~/Library/Caches/Google/Chrome/MyProfileName.
614 //
615 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44616 if (!HasACacheSubdir(path_)) {
617 FilePath app_data_path, user_cache_path;
618 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12619 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44620 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
621 base_cache_path_ = user_cache_path;
622 }
623 }
[email protected]9e9b6e8e2009-12-02 08:45:01624#elif defined(OS_POSIX) // Posix minus Mac.
625 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
626 // for a spec on where cache files go. The net effect for most systems is we
627 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
628 // official builds.
629 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
630#if defined(GOOGLE_CHROME_BUILD)
631 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44632#else
[email protected]9e9b6e8e2009-12-02 08:45:01633 const char kCacheDir[] = "chromium";
634#endif
635 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
636 base_cache_path_ = base_cache_path_.Append(kCacheDir);
637 if (!file_util::PathExists(base_cache_path_))
638 file_util::CreateDirectory(base_cache_path_);
639 }
[email protected]405a64b2009-09-16 21:03:44640#endif
[email protected]bc96d562009-08-11 18:45:13641 if (base_cache_path_.empty())
642 base_cache_path_ = path_;
643
[email protected]4a190632009-05-09 01:07:42644 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43645 registrar_.Add(this, NotificationType::THEME_INSTALLED,
646 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11647
648 // Listen for bookmark model load, to bootstrap the sync service.
649 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
650 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42651
652 ssl_config_service_manager_.reset(
653 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53654
655#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29656 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53657#endif
initial.commit09911bf2008-07-26 23:55:29658}
659
[email protected]bdbc87c2009-01-25 05:08:54660void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41661 if (user_script_master_ || extensions_service_)
662 return; // Already initialized.
663
[email protected]bdbc87c2009-01-25 05:08:54664 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18665 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36666
667 FilePath script_dir; // Don't look for user scripts in any directory.
668 // TODO(aa): We should just remove this functionality,
669 // since it isn't used anymore.
[email protected]95d29192009-10-30 01:49:06670 user_script_master_ = new UserScriptMaster(script_dir);
[email protected]faed6e12009-11-24 22:38:36671
[email protected]894bb502009-05-21 22:39:57672 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23673 this,
674 CommandLine::ForCurrentProcess(),
675 GetPrefs(),
676 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36677 true);
[email protected]bdbc87c2009-01-25 05:08:54678
[email protected]9197f3b2009-06-02 00:49:27679 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12680
681 // Load any extensions specified with --load-extension.
682 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10683 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12684 extensions_service_->LoadExtension(path);
685
686 // Tell UserScriptMaser to watch this extension's directory for changes so
687 // you can live edit content scripts during development.
688 user_script_master_->AddWatchedPath(path);
689 }
[email protected]bdbc87c2009-01-25 05:08:54690}
691
[email protected]ea0c98cf2009-06-18 23:02:54692void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07693 if (web_resource_service_)
694 return; // Already initialized.
695
[email protected]6fad2632009-11-02 05:59:37696 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54697 web_resource_service_->StartAfterDelay();
698}
699
[email protected]9c8dd902009-11-19 17:50:42700NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
701 if (!ntp_resource_cache_.get())
702 ntp_resource_cache_.reset(new NTPResourceCache(this));
703 return ntp_resource_cache_.get();
704}
705
initial.commit09911bf2008-07-26 23:55:29706ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19707 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29708
709 StopCreateSessionServiceTimer();
710 // TemplateURLModel schedules a task on the WebDataService from its
711 // destructor. Delete it first to ensure the task gets scheduled before we
712 // shut down the database.
713 template_url_model_.reset();
714
715 // The download manager queries the history system and should be deleted
716 // before the history is shutdown so it can properly cancel all requests.
717 download_manager_ = NULL;
718
[email protected]4a190632009-05-09 01:07:42719 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15720 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42721
[email protected]44961292009-07-20 20:03:09722 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
723 // save any new thumbnails to disk and release its reference to the
724 // HistoryService.
725 if (thumbnail_store_.get())
726 thumbnail_store_->Shutdown();
727
[email protected]e7244d82008-10-29 18:13:26728 // Remove pref observers.
729 PrefService* prefs = GetPrefs();
730 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
731 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58732 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26733
[email protected]9c8dd902009-11-19 17:50:42734 // Delete the NTP resource cache so we can unregister pref observers.
735 ntp_resource_cache_.reset();
736
[email protected]48352c12009-08-15 01:19:11737 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34738
initial.commit09911bf2008-07-26 23:55:29739 // Both HistoryService and WebDataService maintain threads for background
740 // processing. Its possible each thread still has tasks on it that have
741 // increased the ref count of the service. In such a situation, when we
742 // decrement the refcount, it won't be 0, and the threads/databases aren't
743 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
744 // databases are properly closed.
745 if (web_data_service_.get())
746 web_data_service_->Shutdown();
747
748 if (history_service_.get())
749 history_service_->Cleanup();
750
[email protected]85c55dc2009-11-06 03:05:46751 if (spellcheck_host_.get())
752 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29753
[email protected]cfc06f122009-11-16 22:18:55754 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21755 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50756
[email protected]47accfd62009-05-14 18:46:21757 CleanupRequestContext(request_context_);
758 CleanupRequestContext(media_request_context_);
759 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17760
[email protected]d8e41ed2008-09-11 15:22:32761 // HistoryService may call into the BookmarkModel, as such we need to
762 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46763 // HistoryService will join with HistoryService's backend thread so that
764 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32765 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46766 history_service_ = NULL;
767 bookmark_bar_model_.reset();
768
[email protected]0189bc722009-08-28 21:56:48769 // FaviconService depends on HistoryServce so make sure we delete
770 // HistoryService first.
771 favicon_service_ = NULL;
772
[email protected]7120f132009-07-20 21:05:37773 extension_message_service_->ProfileDestroyed();
774
[email protected]6ef635e42009-07-26 06:16:12775 if (extensions_service_)
776 extensions_service_->ProfileDestroyed();
777
[email protected]66da08b2009-10-19 22:27:00778 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29779 MarkAsCleanShutdown();
780}
781
[email protected]4bf6afd2009-10-08 14:00:11782ProfileId ProfileImpl::GetRuntimeId() {
783 return reinterpret_cast<ProfileId>(this);
784}
785
[email protected]f7011fcb2009-01-28 21:54:32786FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29787 return path_;
788}
789
790bool ProfileImpl::IsOffTheRecord() {
791 return false;
792}
793
794Profile* ProfileImpl::GetOffTheRecordProfile() {
795 if (!off_the_record_profile_.get()) {
796 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
797 off_the_record_profile_.swap(p);
798 }
799 return off_the_record_profile_.get();
800}
801
[email protected]860f55492009-03-27 19:50:59802void ProfileImpl::DestroyOffTheRecordProfile() {
803 off_the_record_profile_.reset();
804}
805
initial.commit09911bf2008-07-26 23:55:29806Profile* ProfileImpl::GetOriginalProfile() {
807 return this;
808}
809
[email protected]2f351cb2009-11-09 23:43:34810webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
811 if (!db_tracker_)
812 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
813 return db_tracker_;
814}
815
initial.commit09911bf2008-07-26 23:55:29816VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
817 if (!visited_link_master_.get()) {
818 scoped_ptr<VisitedLinkMaster> visited_links(
[email protected]6fad2632009-11-02 05:59:37819 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29820 if (!visited_links->Init())
821 return NULL;
822 visited_link_master_.swap(visited_links);
823 }
824
825 return visited_link_master_.get();
826}
827
[email protected]6014d672008-12-05 00:38:25828ExtensionsService* ProfileImpl::GetExtensionsService() {
829 return extensions_service_.get();
830}
831
[email protected]0938d3c2009-01-09 20:37:35832UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35833 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25834}
835
[email protected]89ebc7e2009-08-24 22:11:07836ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
837 return extension_devtools_manager_.get();
838}
839
[email protected]481e1a42009-05-06 20:56:05840ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27841 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05842}
843
[email protected]7120f132009-07-20 21:05:37844ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
845 return extension_message_service_.get();
846}
847
[email protected]34cc84f2009-02-13 10:04:35848SSLHostState* ProfileImpl::GetSSLHostState() {
849 if (!ssl_host_state_.get())
850 ssl_host_state_.reset(new SSLHostState());
851
852 DCHECK(ssl_host_state_->CalledOnValidThread());
853 return ssl_host_state_.get();
854}
855
[email protected]326e6792009-12-11 21:04:42856net::TransportSecurityState*
857 ProfileImpl::GetTransportSecurityState() {
858 if (!transport_security_state_.get()) {
859 transport_security_state_ = new net::TransportSecurityState();
860 transport_security_persister_ =
861 new TransportSecurityPersister();
862 transport_security_persister_->Initialize(
863 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51864 }
[email protected]a9cea7542009-05-20 04:30:23865
[email protected]326e6792009-12-11 21:04:42866 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23867}
868
initial.commit09911bf2008-07-26 23:55:29869PrefService* ProfileImpl::GetPrefs() {
870 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37871 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29872
873 // The Profile class and ProfileManager class may read some prefs so
874 // register known prefs as soon as possible.
875 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51876 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29877
878 // The last session exited cleanly if there is no pref for
879 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
880 last_session_exited_cleanly_ =
881 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
882 // Mark the session as open.
883 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
884 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36885 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29886 }
887
888 return prefs_.get();
889}
890
[email protected]f7011fcb2009-01-28 21:54:32891FilePath ProfileImpl::GetPrefFilePath() {
892 FilePath pref_file_path = path_;
893 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29894 return pref_file_path;
895}
896
[email protected]be180c802009-10-23 06:33:31897URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29898 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32899 FilePath cookie_path = GetPath();
900 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13901 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31902 int max_size;
903 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42904
[email protected]405a64b2009-09-16 21:03:44905 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31906 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
907 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29908
[email protected]6ab9b202008-12-23 22:34:50909 // The first request context is always a normal (non-OTR) request context.
910 // Even when Chromium is started in OTR mode, a normal profile is always
911 // created first.
912 if (!default_request_context_) {
913 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31914 // TODO(eroman): this isn't terribly useful anymore now that the
915 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50916 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56917 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50918 NotificationService::AllSources(), NotificationService::NoDetails());
919 }
initial.commit09911bf2008-07-26 23:55:29920 }
921
922 return request_context_;
923}
924
[email protected]be180c802009-10-23 06:33:31925URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18926 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13927 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31928 int max_size;
929 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14930
[email protected]405a64b2009-09-16 21:03:44931 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31932 media_request_context_ =
933 ChromeURLRequestContextGetter::CreateOriginalForMedia(
934 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18935 }
936
937 return media_request_context_;
938}
939
[email protected]0189bc722009-08-28 21:56:48940FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
941 if (!favicon_service_created_) {
942 favicon_service_created_ = true;
943 scoped_refptr<FaviconService> service(new FaviconService(this));
944 favicon_service_.swap(service);
945 }
946 return favicon_service_.get();
947}
948
[email protected]be180c802009-10-23 06:33:31949URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21950 if (!extensions_request_context_) {
951 FilePath cookie_path = GetPath();
952 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
953
954 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31955 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
956 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21957 }
958
959 return extensions_request_context_;
960}
961
[email protected]db36938c2009-08-19 21:48:42962net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
963 return ssl_config_service_manager_->Get();
964}
965
[email protected]40bd6582009-12-04 23:49:51966HostZoomMap* ProfileImpl::GetHostZoomMap() {
967 if (!host_zoom_map_)
968 host_zoom_map_ = new HostZoomMap(this);
969 return host_zoom_map_.get();
970}
971
[email protected]a307e31e2009-11-30 16:11:27972BlacklistManager* ProfileImpl::GetBlacklistManager() {
973 if (!CommandLine::ForCurrentProcess()->HasSwitch(
974 switches::kEnablePrivacyBlacklists)) {
975 return NULL;
976 }
977 if (!blacklist_manager_created_) {
978 blacklist_manager_created_ = true;
979 blacklist_manager_ = new BlacklistManager(this, GetExtensionsService());
980 blacklist_manager_->Initialize();
981 }
982 return blacklist_manager_.get();
[email protected]eaadd9052009-06-23 18:02:23983}
984
initial.commit09911bf2008-07-26 23:55:29985HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
986 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:46987 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:29988 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:32989 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:29990 return NULL;
991 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:29992
993 // Send out the notification that the history service was created.
994 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56995 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:29996 Details<HistoryService>(history_service_.get()));
997 }
998 return history_service_.get();
999}
1000
[email protected]0850fa62009-10-08 22:34:291001HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1002 return history_service_.get();
1003}
1004
initial.commit09911bf2008-07-26 23:55:291005TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1006 if (!template_url_model_.get())
1007 template_url_model_.reset(new TemplateURLModel(this));
1008 return template_url_model_.get();
1009}
1010
1011TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1012 if (!template_url_fetcher_.get())
1013 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1014 return template_url_fetcher_.get();
1015}
1016
[email protected]11f4857282009-11-13 19:56:171017SearchVersusNavigateClassifier*
1018ProfileImpl::GetSearchVersusNavigateClassifier() {
[email protected]90085af02009-10-29 17:53:211019 if (!search_versus_navigate_classifier_.get()) {
1020 search_versus_navigate_classifier_.reset(
1021 new SearchVersusNavigateClassifier(this));
1022 }
1023 return search_versus_navigate_classifier_.get();
1024}
1025
initial.commit09911bf2008-07-26 23:55:291026WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1027 if (!created_web_data_service_)
1028 CreateWebDataService();
1029 return web_data_service_.get();
1030}
1031
[email protected]9cddbe372009-10-23 21:23:531032WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1033 return web_data_service_.get();
1034}
1035
initial.commit09911bf2008-07-26 23:55:291036void ProfileImpl::CreateWebDataService() {
1037 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1038 created_web_data_service_ = true;
1039 scoped_refptr<WebDataService> wds(new WebDataService());
1040 if (!wds->Init(GetPath()))
1041 return;
1042 web_data_service_.swap(wds);
1043}
1044
[email protected]e69d33952009-06-03 22:00:411045PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1046 if (!created_password_store_)
1047 CreatePasswordStore();
1048 return password_store_.get();
1049}
1050
1051void ProfileImpl::CreatePasswordStore() {
1052 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1053 created_password_store_ = true;
1054 scoped_refptr<PasswordStore> ps;
1055#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251056 // TODO(evanm): implement "native" password management.
1057 // This bug describes the issues.
1058 // http://code.google.com/p/chromium/issues/detail?id=12351
1059 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1060 if (!ps->Init())
1061 return;
[email protected]e69d33952009-06-03 22:00:411062#elif defined(OS_WIN)
1063 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561064#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171065 FilePath login_db_file_path = GetPath();
1066 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1067 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1068 if (!login_db->Init(login_db_file_path)) {
1069 LOG(ERROR) << "Could not initialize login database.";
1070 delete login_db;
1071 return;
1072 }
1073 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411074#else
1075 NOTIMPLEMENTED();
1076#endif
1077 if (!ps || !ps->Init()) {
1078 // Try falling back to the default password manager
1079 LOG(WARNING) << "Could not initialise native password manager - "
1080 "falling back to default";
1081 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1082 if (!ps->Init())
1083 return;
1084 }
1085 password_store_.swap(ps);
1086}
1087
initial.commit09911bf2008-07-26 23:55:291088DownloadManager* ProfileImpl::GetDownloadManager() {
1089 if (!created_download_manager_) {
1090 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1091 dlm->Init(this);
1092 created_download_manager_ = true;
1093 download_manager_.swap(dlm);
1094 }
1095 return download_manager_.get();
1096}
1097
1098bool ProfileImpl::HasCreatedDownloadManager() const {
1099 return created_download_manager_;
1100}
1101
[email protected]def11712009-11-06 00:42:151102PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1103 if (!personal_data_manager_.get()) {
1104 personal_data_manager_.reset(new PersonalDataManager);
1105 }
1106 return personal_data_manager_.get();
1107}
1108
[email protected]4a190632009-05-09 01:07:421109void ProfileImpl::InitThemes() {
1110 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571111#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151112 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291113#else
[email protected]761962c2009-09-25 00:18:151114 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291115#endif
[email protected]761962c2009-09-25 00:18:151116 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421117 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421118 }
1119}
1120
1121void ProfileImpl::SetTheme(Extension* extension) {
1122 InitThemes();
1123 theme_provider_.get()->SetTheme(extension);
1124}
1125
[email protected]a5166af62009-07-03 00:42:291126void ProfileImpl::SetNativeTheme() {
1127 InitThemes();
1128 theme_provider_.get()->SetNativeTheme();
1129}
1130
[email protected]4a190632009-05-09 01:07:421131void ProfileImpl::ClearTheme() {
1132 InitThemes();
1133 theme_provider_.get()->UseDefaultTheme();
1134}
1135
[email protected]51c490b2009-08-03 16:34:341136Extension* ProfileImpl::GetTheme() {
1137 InitThemes();
1138
1139 std::string id = theme_provider_.get()->GetThemeID();
1140 if (id == BrowserThemeProvider::kDefaultThemeID)
1141 return NULL;
1142
[email protected]61b411612009-11-10 23:17:411143 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341144}
1145
[email protected]4a190632009-05-09 01:07:421146ThemeProvider* ProfileImpl::GetThemeProvider() {
1147 InitThemes();
1148 return theme_provider_.get();
1149}
1150
initial.commit09911bf2008-07-26 23:55:291151SessionService* ProfileImpl::GetSessionService() {
1152 if (!session_service_.get() && !shutdown_session_service_) {
1153 session_service_ = new SessionService(this);
1154 session_service_->ResetFromCurrentBrowsers();
1155 }
1156 return session_service_.get();
1157}
1158
1159void ProfileImpl::ShutdownSessionService() {
1160 if (shutdown_session_service_)
1161 return;
1162
1163 // We're about to exit, force creation of the session service if it hasn't
1164 // been created yet. We do this to ensure session state matches the point in
1165 // time the user exited.
1166 GetSessionService();
1167 shutdown_session_service_ = true;
1168 session_service_ = NULL;
1169}
1170
1171bool ProfileImpl::HasSessionService() const {
1172 return (session_service_.get() != NULL);
1173}
1174
initial.commit09911bf2008-07-26 23:55:291175bool ProfileImpl::DidLastSessionExitCleanly() {
1176 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1177 // it to be set by asking for the prefs.
1178 GetPrefs();
1179 return last_session_exited_cleanly_;
1180}
1181
[email protected]d8e41ed2008-09-11 15:22:321182BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461183 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321184 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461185 bookmark_bar_model_->Load();
1186 }
initial.commit09911bf2008-07-26 23:55:291187 return bookmark_bar_model_.get();
1188}
1189
1190bool ProfileImpl::IsSameProfile(Profile* profile) {
1191 if (profile == static_cast<Profile*>(this))
1192 return true;
1193 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1194 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1195}
1196
1197Time ProfileImpl::GetStartTime() const {
1198 return start_time_;
1199}
1200
1201TabRestoreService* ProfileImpl::GetTabRestoreService() {
1202 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191203 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291204 return tab_restore_service_.get();
1205}
1206
[email protected]449478302009-06-09 20:04:281207ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1208 if (!thumbnail_store_.get()) {
1209 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251210 thumbnail_store_->Init(
1211 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281212 }
1213 return thumbnail_store_.get();
1214}
1215
initial.commit09911bf2008-07-26 23:55:291216void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191217 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291218}
1219
[email protected]85c55dc2009-11-06 03:05:461220SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1221 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1222}
1223
1224void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1225 // If we are already loading the spellchecker, and this is just a hint to
1226 // load the spellchecker, do nothing.
1227 if (!force && spellcheck_host_.get())
1228 return;
1229
[email protected]f41301e2009-11-16 21:30:071230 spellcheck_host_ready_ = false;
1231
[email protected]85c55dc2009-11-06 03:05:461232 bool notify = false;
1233 if (spellcheck_host_.get()) {
1234 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051235 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461236 notify = true;
1237 }
1238
1239 PrefService* prefs = GetPrefs();
1240 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1241 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1242 spellcheck_host_ = new SpellCheckHost(this,
1243 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1244 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071245 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461246 } else if (notify) {
1247 // The spellchecker has been disabled.
1248 SpellCheckHostInitialized();
1249 }
1250}
1251
1252void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171253 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291254 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1255 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461256 NotificationService::current()->Notify(
1257 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1258 Source<Profile>(this), NotificationService::NoDetails());
1259}
initial.commit09911bf2008-07-26 23:55:291260
[email protected]3bf335a2009-06-26 20:46:061261WebKitContext* ProfileImpl::GetWebKitContext() {
1262 if (!webkit_context_.get())
1263 webkit_context_ = new WebKitContext(path_, false);
1264 DCHECK(webkit_context_.get());
1265 return webkit_context_.get();
1266}
1267
[email protected]4bb336302009-10-12 05:44:261268DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1269 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1270 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261271 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031272 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261273 }
[email protected]4bb336302009-10-12 05:44:261274 return desktop_notification_service_.get();
1275}
1276
initial.commit09911bf2008-07-26 23:55:291277void ProfileImpl::MarkAsCleanShutdown() {
1278 if (prefs_.get()) {
1279 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1280 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1281
1282 // NOTE: If you change what thread this writes on, be sure and update
1283 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361284 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291285 }
1286}
1287
[email protected]e7244d82008-10-29 18:13:261288void ProfileImpl::Observe(NotificationType type,
1289 const NotificationSource& source,
1290 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561291 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261292 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1293 PrefService* prefs = Source<PrefService>(source).ptr();
1294 DCHECK(pref_name_in && prefs);
1295 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461296 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461297 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291298 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1299 NotificationService::current()->Notify(
1300 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1301 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261302 }
[email protected]4a190632009-05-09 01:07:421303 } else if (NotificationType::THEME_INSTALLED == type) {
1304 Extension* extension = Details<Extension>(details).ptr();
1305 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111306 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1307 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1308 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1309 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261310 }
1311}
1312
initial.commit09911bf2008-07-26 23:55:291313void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141314 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291315}
[email protected]3a453fa2008-08-15 18:46:341316
[email protected]48352c12009-08-15 01:19:111317ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431318 if (!ProfileSyncService::IsSyncEnabled()) {
1319 return NULL;
[email protected]7367f1a2009-10-10 01:09:441320 }
[email protected]eec3bcfa2009-11-12 17:23:431321 if (!sync_service_.get())
1322 InitSyncService();
1323 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111324}
1325
1326void ProfileImpl::InitSyncService() {
[email protected]48352c12009-08-15 01:19:111327 sync_service_.reset(new ProfileSyncService(this));
1328 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111329}