blob: 278a297eadd35bda824f91f41e4384a8e8d710c6 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/profile.h"
6
[email protected]2735e3692009-09-25 18:19:397#include "app/theme_provider.h"
initial.commit09911bf2008-07-26 23:55:298#include "base/command_line.h"
[email protected]04fba9a92008-10-28 17:25:259#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4410#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/path_service.h"
12#include "base/scoped_ptr.h"
13#include "base/string_util.h"
[email protected]def11712009-11-06 00:42:1514#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4215#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2916#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5117#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5718#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0219#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3720#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4221#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5622#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0723#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3724#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0525#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2526#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3527#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4828#include "chrome/browser/favicon_service.h"
[email protected]9c92d192009-12-02 08:03:1629#include "chrome/browser/spellcheck_host.h"
[email protected]77f6fb432009-09-05 14:21:0930#include "chrome/browser/strict_transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4231#include "chrome/browser/history/history.h"
[email protected]3bf335a2009-06-26 20:46:0632#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5033#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4234#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2635#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4136#include "chrome/browser/password_manager/password_store_default.h"
[email protected]a307e31e2009-11-30 16:11:2737#include "chrome/browser/privacy_blacklist/blacklist_manager.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2639#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]90085af02009-10-29 17:53:2140#include "chrome/browser/search_versus_navigate_classifier.h"
[email protected]1132436e2009-04-08 20:06:3341#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4642#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4443#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3044#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3345#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1146#include "chrome/browser/sync/profile_sync_service.h"
[email protected]449478302009-06-09 20:04:2847#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2948#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3949#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2950#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5651#include "chrome/browser/web_resource/web_resource_service.h"
[email protected]23f1ef12009-09-01 22:30:3052#include "chrome/common/appcache/chrome_appcache_service.h"
initial.commit09911bf2008-07-26 23:55:2953#include "chrome/common/chrome_constants.h"
54#include "chrome/common/chrome_paths.h"
55#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5856#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2957#include "chrome/common/notification_service.h"
58#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3259#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5860#include "grit/locale_settings.h"
[email protected]77f6fb432009-09-05 14:21:0961#include "net/base/strict_transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3462#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2963
[email protected]a5166af62009-07-03 00:42:2964#if defined(OS_LINUX)
65#include "chrome/browser/gtk/gtk_theme_provider.h"
66#endif
67
[email protected]e1acf6f2008-10-27 20:43:3368using base::Time;
69using base::TimeDelta;
70
[email protected]e5642992009-06-26 23:06:3171namespace {
72
initial.commit09911bf2008-07-26 23:55:2973// Delay, in milliseconds, before we explicitly create the SessionService.
74static const int kCreateSessionServiceDelayMS = 500;
75
[email protected]e5642992009-06-26 23:06:3176enum ContextType {
77 kNormalContext,
78 kMediaContext
79};
80
81// Gets the cache parameters from the command line. |type| is the type of
82// request context that we need, |cache_path| will be set to the user provided
83// path, or will not be touched if there is not an argument. |max_size| will
84// be the user provided value or zero by default.
85void GetCacheParameters(ContextType type, FilePath* cache_path,
86 int* max_size) {
87 DCHECK(cache_path);
88 DCHECK(max_size);
89
90 // Override the cache location if specified by the user.
91 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
92 switches::kDiskCacheDir));
93
94 if (!user_path.empty()) {
95 *cache_path = FilePath::FromWStringHack(user_path);
96 }
97
[email protected]b7e0a2a2009-10-13 02:07:2598 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
99 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31100 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25101 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31102
103 // By default we let the cache determine the right size.
104 *max_size = 0;
105 if (!StringToInt(value, max_size)) {
106 *max_size = 0;
107 } else if (max_size < 0) {
108 *max_size = 0;
109 }
110}
111
[email protected]405a64b2009-09-16 21:03:44112FilePath GetCachePath(const FilePath& base) {
113 return base.Append(chrome::kCacheDirname);
114}
115
116FilePath GetMediaCachePath(const FilePath& base) {
117 return base.Append(chrome::kMediaCacheDirname);
118}
119
120bool HasACacheSubdir(const FilePath &dir) {
121 return file_util::PathExists(GetCachePath(dir)) ||
122 file_util::PathExists(GetMediaCachePath(dir));
123}
124
[email protected]e5642992009-06-26 23:06:31125} // namespace
126
initial.commit09911bf2008-07-26 23:55:29127// A pointer to the request context for the default profile. See comments on
128// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31129URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29130
[email protected]be180c802009-10-23 06:33:31131static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19132 if (context)
[email protected]47accfd62009-05-14 18:46:21133 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21134}
135
[email protected]34cc84f2009-02-13 10:04:35136// static
[email protected]4bf6afd2009-10-08 14:00:11137const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
138
139// static
initial.commit09911bf2008-07-26 23:55:29140void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55141 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29142 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
143 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12144 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26145 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
146 IDS_SPELLCHECK_DICTIONARY);
147 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58148 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]a5166af62009-07-03 00:42:29149#if defined(OS_LINUX)
150 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
151#endif
[email protected]51c490b2009-08-03 16:34:34152 prefs->RegisterStringPref(prefs::kCurrentThemeID,
153 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42154 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
155 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
156 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50157 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23158 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29159}
160
[email protected]34cc84f2009-02-13 10:04:35161// static
[email protected]f7011fcb2009-01-28 21:54:32162Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29163 return new ProfileImpl(path);
164}
165
[email protected]34cc84f2009-02-13 10:04:35166// static
[email protected]be180c802009-10-23 06:33:31167URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29168 return default_request_context_;
169}
170
[email protected]e69d33952009-06-03 22:00:41171#if defined(OS_LINUX)
172// Temporarily disabled while we figure some stuff out.
173// http://code.google.com/p/chromium/issues/detail?id=12351
174// #include "chrome/browser/password_manager/password_store_gnome.h"
175// #include "chrome/browser/password_manager/password_store_kwallet.h"
176#elif defined(OS_WIN)
177#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56178#elif defined(OS_MACOSX)
179#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17180#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56181#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41182#endif
initial.commit09911bf2008-07-26 23:55:29183
initial.commit09911bf2008-07-26 23:55:29184////////////////////////////////////////////////////////////////////////////////
185//
186// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42187// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29188//
189////////////////////////////////////////////////////////////////////////////////
190class OffTheRecordProfileImpl : public Profile,
191 public NotificationObserver {
192 public:
193 explicit OffTheRecordProfileImpl(Profile* real_profile)
194 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21195 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29196 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31197 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05198
initial.commit09911bf2008-07-26 23:55:29199 // Register for browser close notifications so we can detect when the last
200 // off-the-record window is closed, in which case we can clean our states
201 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43202 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
203 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29204 }
205
206 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21207 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21208 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29209 }
210
[email protected]4bf6afd2009-10-08 14:00:11211 virtual ProfileId GetRuntimeId() {
212 return reinterpret_cast<ProfileId>(this);
213 }
214
[email protected]f7011fcb2009-01-28 21:54:32215 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29216
217 virtual bool IsOffTheRecord() {
218 return true;
219 }
220
221 virtual Profile* GetOffTheRecordProfile() {
222 return this;
223 }
224
[email protected]860f55492009-03-27 19:50:59225 virtual void DestroyOffTheRecordProfile() {
226 // Suicide is bad!
227 NOTREACHED();
228 }
229
initial.commit09911bf2008-07-26 23:55:29230 virtual Profile* GetOriginalProfile() {
231 return profile_;
232 }
233
[email protected]2f351cb2009-11-09 23:43:34234 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
235 if (!db_tracker_)
236 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
237 return db_tracker_;
238 }
239
initial.commit09911bf2008-07-26 23:55:29240 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49241 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
242 // because we don't want to leak the sites that the user has visited before.
243 return NULL;
initial.commit09911bf2008-07-26 23:55:29244 }
245
[email protected]6014d672008-12-05 00:38:25246 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34247 return NULL;
[email protected]6014d672008-12-05 00:38:25248 }
249
[email protected]0938d3c2009-01-09 20:37:35250 virtual UserScriptMaster* GetUserScriptMaster() {
251 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25252 }
253
[email protected]89ebc7e2009-08-24 22:11:07254 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
255 return NULL;
256 }
257
[email protected]481e1a42009-05-06 20:56:05258 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34259 return NULL;
[email protected]481e1a42009-05-06 20:56:05260 }
261
[email protected]7120f132009-07-20 21:05:37262 virtual ExtensionMessageService* GetExtensionMessageService() {
263 return NULL;
264 }
265
[email protected]34cc84f2009-02-13 10:04:35266 virtual SSLHostState* GetSSLHostState() {
267 if (!ssl_host_state_.get())
268 ssl_host_state_.reset(new SSLHostState());
269
270 DCHECK(ssl_host_state_->CalledOnValidThread());
271 return ssl_host_state_.get();
272 }
273
[email protected]77f6fb432009-09-05 14:21:09274 virtual net::StrictTransportSecurityState* GetStrictTransportSecurityState() {
275 if (!strict_transport_security_state_.get()) {
276 strict_transport_security_state_ =
277 new net::StrictTransportSecurityState();
278 }
[email protected]a9cea7542009-05-20 04:30:23279
[email protected]77f6fb432009-09-05 14:21:09280 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23281 }
282
initial.commit09911bf2008-07-26 23:55:29283 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
284 if (sat == EXPLICIT_ACCESS) {
285 return profile_->GetHistoryService(sat);
286 } else {
287 NOTREACHED() << "This profile is OffTheRecord";
288 return NULL;
289 }
290 }
291
[email protected]0850fa62009-10-08 22:34:29292 virtual HistoryService* GetHistoryServiceWithoutCreating() {
293 return profile_->GetHistoryServiceWithoutCreating();
294 }
295
[email protected]0189bc722009-08-28 21:56:48296 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
297 if (sat == EXPLICIT_ACCESS) {
298 return profile_->GetFaviconService(sat);
299 } else {
300 NOTREACHED() << "This profile is OffTheRecord";
301 return NULL;
302 }
303 }
304
[email protected]90085af02009-10-29 17:53:21305 virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
306 return profile_->GetSearchVersusNavigateClassifier();
307 }
308
initial.commit09911bf2008-07-26 23:55:29309 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
310 if (sat == EXPLICIT_ACCESS) {
311 return profile_->GetWebDataService(sat);
312 } else {
313 NOTREACHED() << "This profile is OffTheRecord";
314 return NULL;
315 }
316 }
317
[email protected]9cddbe372009-10-23 21:23:53318 virtual WebDataService* GetWebDataServiceWithoutCreating() {
319 return profile_->GetWebDataServiceWithoutCreating();
320 }
321
[email protected]e69d33952009-06-03 22:00:41322 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
323 if (sat == EXPLICIT_ACCESS) {
324 return profile_->GetPasswordStore(sat);
325 } else {
326 NOTREACHED() << "This profile is OffTheRecord";
327 return NULL;
328 }
329 }
330
initial.commit09911bf2008-07-26 23:55:29331 virtual PrefService* GetPrefs() {
332 return profile_->GetPrefs();
333 }
334
335 virtual TemplateURLModel* GetTemplateURLModel() {
336 return profile_->GetTemplateURLModel();
337 }
338
339 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
340 return profile_->GetTemplateURLFetcher();
341 }
342
343 virtual DownloadManager* GetDownloadManager() {
344 if (!download_manager_.get()) {
345 scoped_refptr<DownloadManager> dlm(new DownloadManager);
346 dlm->Init(this);
347 download_manager_.swap(dlm);
348 }
349 return download_manager_.get();
350 }
351
352 virtual bool HasCreatedDownloadManager() const {
353 return (download_manager_.get() != NULL);
354 }
355
[email protected]def11712009-11-06 00:42:15356 virtual PersonalDataManager* GetPersonalDataManager() {
357 return NULL;
358 }
359
[email protected]4a190632009-05-09 01:07:42360 virtual void InitThemes() {
361 GetOriginalProfile()->InitThemes();
362 }
363
364 virtual void SetTheme(Extension* extension) {
365 GetOriginalProfile()->SetTheme(extension);
366 }
367
[email protected]a5166af62009-07-03 00:42:29368 virtual void SetNativeTheme() {
369 GetOriginalProfile()->SetNativeTheme();
370 }
371
[email protected]4a190632009-05-09 01:07:42372 virtual void ClearTheme() {
373 GetOriginalProfile()->ClearTheme();
374 }
375
[email protected]51c490b2009-08-03 16:34:34376 virtual Extension* GetTheme() {
377 return GetOriginalProfile()->GetTheme();
378 }
379
[email protected]4a190632009-05-09 01:07:42380 virtual ThemeProvider* GetThemeProvider() {
381 return GetOriginalProfile()->GetThemeProvider();
382 }
383
[email protected]be180c802009-10-23 06:33:31384 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29385 return request_context_;
386 }
387
[email protected]be180c802009-10-23 06:33:31388 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11389 // In OTR mode, media request context is the same as the original one.
390 return request_context_;
[email protected]e7f29642009-03-02 22:53:18391 }
392
[email protected]be180c802009-10-23 06:33:31393 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21394 if (!extensions_request_context_) {
395 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31396 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this);
[email protected]47accfd62009-05-14 18:46:21397 }
398
399 return extensions_request_context_;
400 }
401
[email protected]db36938c2009-08-19 21:48:42402 virtual net::SSLConfigService* GetSSLConfigService() {
403 return GetOriginalProfile()->GetSSLConfigService();
404 }
405
[email protected]a307e31e2009-11-30 16:11:27406 virtual BlacklistManager* GetBlacklistManager() {
407 return GetOriginalProfile()->GetBlacklistManager();
[email protected]eaadd9052009-06-23 18:02:23408 }
409
initial.commit09911bf2008-07-26 23:55:29410 virtual SessionService* GetSessionService() {
411 // Don't save any sessions when off the record.
412 return NULL;
413 }
414
415 virtual void ShutdownSessionService() {
416 // We don't allow a session service, nothing to do.
417 }
418
419 virtual bool HasSessionService() const {
420 // We never have a session service.
421 return false;
422 }
423
initial.commit09911bf2008-07-26 23:55:29424 virtual bool DidLastSessionExitCleanly() {
425 return profile_->DidLastSessionExitCleanly();
426 }
427
[email protected]d8e41ed2008-09-11 15:22:32428 virtual BookmarkModel* GetBookmarkModel() {
429 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29430 }
431
[email protected]4bb336302009-10-12 05:44:26432 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58433 if (!desktop_notification_service_.get()) {
434 desktop_notification_service_.reset(new DesktopNotificationService(
435 this, g_browser_process->notification_ui_manager()));
436 }
437 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26438 }
439
[email protected]48352c12009-08-15 01:19:11440 virtual ProfileSyncService* GetProfileSyncService() {
441 return NULL;
[email protected]3a453fa2008-08-15 18:46:34442 }
[email protected]3a453fa2008-08-15 18:46:34443
initial.commit09911bf2008-07-26 23:55:29444 virtual bool IsSameProfile(Profile* profile) {
445 if (profile == static_cast<Profile*>(this))
446 return true;
447 return profile == profile_;
448 }
449
450 virtual Time GetStartTime() const {
451 return start_time_;
452 }
453
454 virtual TabRestoreService* GetTabRestoreService() {
455 return NULL;
456 }
457
[email protected]e7244d82008-10-29 18:13:26458 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41459 }
460
[email protected]85c55dc2009-11-06 03:05:46461 virtual SpellCheckHost* GetSpellCheckHost() {
462 return profile_->GetSpellCheckHost();
463 }
464
465 virtual void ReinitializeSpellCheckHost(bool force) {
466 profile_->ReinitializeSpellCheckHost(force);
467 }
[email protected]85c55dc2009-11-06 03:05:46468
[email protected]3bf335a2009-06-26 20:46:06469 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29470 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21471 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29472 DCHECK(webkit_context_.get());
473 return webkit_context_.get();
474 }
[email protected]3bf335a2009-06-26 20:46:06475
[email protected]449478302009-06-09 20:04:28476 virtual ThumbnailStore* GetThumbnailStore() {
477 return NULL;
478 }
479
initial.commit09911bf2008-07-26 23:55:29480 virtual void MarkAsCleanShutdown() {
481 }
482
[email protected]bdbc87c2009-01-25 05:08:54483 virtual void InitExtensions() {
484 NOTREACHED();
485 }
486
[email protected]ea0c98cf2009-06-18 23:02:54487 virtual void InitWebResources() {
488 NOTREACHED();
489 }
490
[email protected]9c8dd902009-11-19 17:50:42491 virtual NTPResourceCache* GetNTPResourceCache() {
492 // Just return the real profile resource cache.
493 return profile_->GetNTPResourceCache();
494 }
495
initial.commit09911bf2008-07-26 23:55:29496 virtual void ExitedOffTheRecordMode() {
497 // Drop our download manager so we forget about all the downloads made
498 // in off-the-record mode.
499 download_manager_ = NULL;
500 }
501
502 virtual void Observe(NotificationType type,
503 const NotificationSource& source,
504 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56505 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29506 // We are only interested in OTR browser closing.
507 if (Source<Browser>(source)->profile() != this)
508 return;
509
510 // Let's check if we still have an Off The Record window opened.
511 // Note that we check against 1 as this notification is sent before the
512 // browser window is actually removed from the list.
513 if (BrowserList::GetBrowserCount(this) <= 1)
514 ExitedOffTheRecordMode();
515 }
516
517 private:
[email protected]88cf3292009-05-22 01:48:43518 NotificationRegistrar registrar_;
519
initial.commit09911bf2008-07-26 23:55:29520 // The real underlying profile.
521 Profile* profile_;
522
[email protected]6ab9b202008-12-23 22:34:50523 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19524 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29525
[email protected]13c30922009-11-19 03:43:19526 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_;
[email protected]23f1ef12009-09-01 22:30:30527
initial.commit09911bf2008-07-26 23:55:29528 // The download manager that only stores downloaded items in memory.
529 scoped_refptr<DownloadManager> download_manager_;
530
[email protected]7d7696c52009-12-01 20:54:58531 // Use a separate desktop notification service for OTR.
532 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
533
[email protected]3bf335a2009-06-26 20:46:06534 // Use a special WebKit context for OTR browsing.
535 scoped_refptr<WebKitContext> webkit_context_;
536
[email protected]34cc84f2009-02-13 10:04:35537 // We don't want SSLHostState from the OTR profile to leak back to the main
538 // profile because then the main profile would learn some of the host names
539 // the user visited while OTR.
540 scoped_ptr<SSLHostState> ssl_host_state_;
541
[email protected]77f6fb432009-09-05 14:21:09542 // The StrictTransportSecurityState that only stores enabled sites in memory.
543 scoped_refptr<net::StrictTransportSecurityState>
544 strict_transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23545
initial.commit09911bf2008-07-26 23:55:29546 // Time we were started.
547 Time start_time_;
548
[email protected]2f351cb2009-11-09 23:43:34549 // The main database tracker for this profile.
550 // Should be used only on the file thread.
551 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
552
[email protected]90085af02009-10-29 17:53:21553 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29554};
555
[email protected]f7011fcb2009-01-28 21:54:32556ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29557 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39558 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07559 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32560 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57561 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21562 extensions_request_context_(NULL),
[email protected]a307e31e2009-11-30 16:11:27563 blacklist_manager_(NULL),
564 blacklist_manager_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32565 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48566 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32567 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41568 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32569 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42570 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32571 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46572 spellcheck_host_(NULL),
573 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29574 shutdown_session_service_(false) {
575 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
576 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14577 create_session_service_timer_.Start(
578 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
579 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54580
[email protected]89ebc7e2009-08-24 22:11:07581 if (CommandLine::ForCurrentProcess()->HasSwitch(
582 switches::kEnableExtensionTimelineApi)) {
583 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
584 }
585
[email protected]382a0702009-06-26 17:12:27586 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37587 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27588
[email protected]e7244d82008-10-29 18:13:26589 PrefService* prefs = GetPrefs();
590 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
591 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58592 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58593
[email protected]405a64b2009-09-16 21:03:44594#if defined(OS_MACOSX)
595 // If the profile directory doesn't already have a cache directory and it
596 // is under ~/Library/Application Support, use a suitable cache directory
597 // under ~/Library/Caches. For example, a profile directory of
598 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
599 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
600 // ~/Library/Caches/Google/Chrome/MyProfileName.
601 //
602 // TODO(akalin): Come up with unit tests for this.
603 // TODO(akalin): Use for Linux, too?
604 if (!HasACacheSubdir(path_)) {
605 FilePath app_data_path, user_cache_path;
606 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
607 PathService::Get(base::DIR_CACHE, &user_cache_path) &&
608 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
609 base_cache_path_ = user_cache_path;
610 }
611 }
[email protected]9e9b6e8e2009-12-02 08:45:01612#elif defined(OS_POSIX) // Posix minus Mac.
613 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
614 // for a spec on where cache files go. The net effect for most systems is we
615 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
616 // official builds.
617 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
618#if defined(GOOGLE_CHROME_BUILD)
619 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44620#else
[email protected]9e9b6e8e2009-12-02 08:45:01621 const char kCacheDir[] = "chromium";
622#endif
623 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
624 base_cache_path_ = base_cache_path_.Append(kCacheDir);
625 if (!file_util::PathExists(base_cache_path_))
626 file_util::CreateDirectory(base_cache_path_);
627 }
[email protected]405a64b2009-09-16 21:03:44628#endif
[email protected]bc96d562009-08-11 18:45:13629 if (base_cache_path_.empty())
630 base_cache_path_ = path_;
631
[email protected]4a190632009-05-09 01:07:42632 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43633 registrar_.Add(this, NotificationType::THEME_INSTALLED,
634 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11635
636 // Listen for bookmark model load, to bootstrap the sync service.
637 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
638 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42639
640 ssl_config_service_manager_.reset(
641 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53642
643#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29644 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53645#endif
initial.commit09911bf2008-07-26 23:55:29646}
647
[email protected]bdbc87c2009-01-25 05:08:54648void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41649 if (user_script_master_ || extensions_service_)
650 return; // Already initialized.
651
[email protected]bdbc87c2009-01-25 05:08:54652 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18653 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36654
655 FilePath script_dir; // Don't look for user scripts in any directory.
656 // TODO(aa): We should just remove this functionality,
657 // since it isn't used anymore.
[email protected]95d29192009-10-30 01:49:06658 user_script_master_ = new UserScriptMaster(script_dir);
[email protected]faed6e12009-11-24 22:38:36659
[email protected]894bb502009-05-21 22:39:57660 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23661 this,
662 CommandLine::ForCurrentProcess(),
663 GetPrefs(),
664 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36665 true);
[email protected]bdbc87c2009-01-25 05:08:54666
[email protected]9197f3b2009-06-02 00:49:27667 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12668
669 // Load any extensions specified with --load-extension.
670 if (command_line->HasSwitch(switches::kLoadExtension)) {
671 std::wstring path_string =
672 command_line->GetSwitchValue(switches::kLoadExtension);
673 FilePath path = FilePath::FromWStringHack(path_string);
674 extensions_service_->LoadExtension(path);
675
676 // Tell UserScriptMaser to watch this extension's directory for changes so
677 // you can live edit content scripts during development.
678 user_script_master_->AddWatchedPath(path);
679 }
[email protected]bdbc87c2009-01-25 05:08:54680}
681
[email protected]ea0c98cf2009-06-18 23:02:54682void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07683 if (web_resource_service_)
684 return; // Already initialized.
685
[email protected]6fad2632009-11-02 05:59:37686 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54687 web_resource_service_->StartAfterDelay();
688}
689
[email protected]9c8dd902009-11-19 17:50:42690NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
691 if (!ntp_resource_cache_.get())
692 ntp_resource_cache_.reset(new NTPResourceCache(this));
693 return ntp_resource_cache_.get();
694}
695
initial.commit09911bf2008-07-26 23:55:29696ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19697 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29698
699 StopCreateSessionServiceTimer();
700 // TemplateURLModel schedules a task on the WebDataService from its
701 // destructor. Delete it first to ensure the task gets scheduled before we
702 // shut down the database.
703 template_url_model_.reset();
704
705 // The download manager queries the history system and should be deleted
706 // before the history is shutdown so it can properly cancel all requests.
707 download_manager_ = NULL;
708
[email protected]4a190632009-05-09 01:07:42709 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15710 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42711
[email protected]44961292009-07-20 20:03:09712 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
713 // save any new thumbnails to disk and release its reference to the
714 // HistoryService.
715 if (thumbnail_store_.get())
716 thumbnail_store_->Shutdown();
717
[email protected]e7244d82008-10-29 18:13:26718 // Remove pref observers.
719 PrefService* prefs = GetPrefs();
720 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
721 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58722 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26723
[email protected]9c8dd902009-11-19 17:50:42724 // Delete the NTP resource cache so we can unregister pref observers.
725 ntp_resource_cache_.reset();
726
[email protected]48352c12009-08-15 01:19:11727 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34728
initial.commit09911bf2008-07-26 23:55:29729 // Both HistoryService and WebDataService maintain threads for background
730 // processing. Its possible each thread still has tasks on it that have
731 // increased the ref count of the service. In such a situation, when we
732 // decrement the refcount, it won't be 0, and the threads/databases aren't
733 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
734 // databases are properly closed.
735 if (web_data_service_.get())
736 web_data_service_->Shutdown();
737
738 if (history_service_.get())
739 history_service_->Cleanup();
740
[email protected]85c55dc2009-11-06 03:05:46741 if (spellcheck_host_.get())
742 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29743
[email protected]cfc06f122009-11-16 22:18:55744 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21745 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50746
[email protected]47accfd62009-05-14 18:46:21747 CleanupRequestContext(request_context_);
748 CleanupRequestContext(media_request_context_);
749 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17750
[email protected]d8e41ed2008-09-11 15:22:32751 // HistoryService may call into the BookmarkModel, as such we need to
752 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46753 // HistoryService will join with HistoryService's backend thread so that
754 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32755 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46756 history_service_ = NULL;
757 bookmark_bar_model_.reset();
758
[email protected]0189bc722009-08-28 21:56:48759 // FaviconService depends on HistoryServce so make sure we delete
760 // HistoryService first.
761 favicon_service_ = NULL;
762
[email protected]7120f132009-07-20 21:05:37763 extension_message_service_->ProfileDestroyed();
764
[email protected]6ef635e42009-07-26 06:16:12765 if (extensions_service_)
766 extensions_service_->ProfileDestroyed();
767
[email protected]66da08b2009-10-19 22:27:00768 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29769 MarkAsCleanShutdown();
770}
771
[email protected]4bf6afd2009-10-08 14:00:11772ProfileId ProfileImpl::GetRuntimeId() {
773 return reinterpret_cast<ProfileId>(this);
774}
775
[email protected]f7011fcb2009-01-28 21:54:32776FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29777 return path_;
778}
779
780bool ProfileImpl::IsOffTheRecord() {
781 return false;
782}
783
784Profile* ProfileImpl::GetOffTheRecordProfile() {
785 if (!off_the_record_profile_.get()) {
786 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
787 off_the_record_profile_.swap(p);
788 }
789 return off_the_record_profile_.get();
790}
791
[email protected]860f55492009-03-27 19:50:59792void ProfileImpl::DestroyOffTheRecordProfile() {
793 off_the_record_profile_.reset();
794}
795
initial.commit09911bf2008-07-26 23:55:29796Profile* ProfileImpl::GetOriginalProfile() {
797 return this;
798}
799
[email protected]2f351cb2009-11-09 23:43:34800webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
801 if (!db_tracker_)
802 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
803 return db_tracker_;
804}
805
initial.commit09911bf2008-07-26 23:55:29806VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
807 if (!visited_link_master_.get()) {
808 scoped_ptr<VisitedLinkMaster> visited_links(
[email protected]6fad2632009-11-02 05:59:37809 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29810 if (!visited_links->Init())
811 return NULL;
812 visited_link_master_.swap(visited_links);
813 }
814
815 return visited_link_master_.get();
816}
817
[email protected]6014d672008-12-05 00:38:25818ExtensionsService* ProfileImpl::GetExtensionsService() {
819 return extensions_service_.get();
820}
821
[email protected]0938d3c2009-01-09 20:37:35822UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35823 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25824}
825
[email protected]89ebc7e2009-08-24 22:11:07826ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
827 return extension_devtools_manager_.get();
828}
829
[email protected]481e1a42009-05-06 20:56:05830ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27831 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05832}
833
[email protected]7120f132009-07-20 21:05:37834ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
835 return extension_message_service_.get();
836}
837
[email protected]34cc84f2009-02-13 10:04:35838SSLHostState* ProfileImpl::GetSSLHostState() {
839 if (!ssl_host_state_.get())
840 ssl_host_state_.reset(new SSLHostState());
841
842 DCHECK(ssl_host_state_->CalledOnValidThread());
843 return ssl_host_state_.get();
844}
845
[email protected]77f6fb432009-09-05 14:21:09846net::StrictTransportSecurityState*
847 ProfileImpl::GetStrictTransportSecurityState() {
848 if (!strict_transport_security_state_.get()) {
849 strict_transport_security_state_ = new net::StrictTransportSecurityState();
[email protected]0c03b432009-11-17 21:41:08850 strict_transport_security_persister_ =
851 new StrictTransportSecurityPersister();
852 strict_transport_security_persister_->Initialize(
[email protected]6fad2632009-11-02 05:59:37853 strict_transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51854 }
[email protected]a9cea7542009-05-20 04:30:23855
[email protected]77f6fb432009-09-05 14:21:09856 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23857}
858
initial.commit09911bf2008-07-26 23:55:29859PrefService* ProfileImpl::GetPrefs() {
860 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37861 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29862
863 // The Profile class and ProfileManager class may read some prefs so
864 // register known prefs as soon as possible.
865 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51866 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29867
868 // The last session exited cleanly if there is no pref for
869 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
870 last_session_exited_cleanly_ =
871 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
872 // Mark the session as open.
873 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
874 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36875 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29876 }
877
878 return prefs_.get();
879}
880
[email protected]f7011fcb2009-01-28 21:54:32881FilePath ProfileImpl::GetPrefFilePath() {
882 FilePath pref_file_path = path_;
883 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29884 return pref_file_path;
885}
886
[email protected]be180c802009-10-23 06:33:31887URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29888 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32889 FilePath cookie_path = GetPath();
890 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13891 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31892 int max_size;
893 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42894
[email protected]405a64b2009-09-16 21:03:44895 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31896 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
897 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29898
[email protected]6ab9b202008-12-23 22:34:50899 // The first request context is always a normal (non-OTR) request context.
900 // Even when Chromium is started in OTR mode, a normal profile is always
901 // created first.
902 if (!default_request_context_) {
903 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31904 // TODO(eroman): this isn't terribly useful anymore now that the
905 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50906 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56907 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50908 NotificationService::AllSources(), NotificationService::NoDetails());
909 }
initial.commit09911bf2008-07-26 23:55:29910 }
911
912 return request_context_;
913}
914
[email protected]be180c802009-10-23 06:33:31915URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18916 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13917 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31918 int max_size;
919 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14920
[email protected]405a64b2009-09-16 21:03:44921 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31922 media_request_context_ =
923 ChromeURLRequestContextGetter::CreateOriginalForMedia(
924 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18925 }
926
927 return media_request_context_;
928}
929
[email protected]0189bc722009-08-28 21:56:48930FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
931 if (!favicon_service_created_) {
932 favicon_service_created_ = true;
933 scoped_refptr<FaviconService> service(new FaviconService(this));
934 favicon_service_.swap(service);
935 }
936 return favicon_service_.get();
937}
938
[email protected]be180c802009-10-23 06:33:31939URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21940 if (!extensions_request_context_) {
941 FilePath cookie_path = GetPath();
942 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
943
944 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31945 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
946 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21947 }
948
949 return extensions_request_context_;
950}
951
[email protected]db36938c2009-08-19 21:48:42952net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
953 return ssl_config_service_manager_->Get();
954}
955
[email protected]a307e31e2009-11-30 16:11:27956BlacklistManager* ProfileImpl::GetBlacklistManager() {
957 if (!CommandLine::ForCurrentProcess()->HasSwitch(
958 switches::kEnablePrivacyBlacklists)) {
959 return NULL;
960 }
961 if (!blacklist_manager_created_) {
962 blacklist_manager_created_ = true;
963 blacklist_manager_ = new BlacklistManager(this, GetExtensionsService());
964 blacklist_manager_->Initialize();
965 }
966 return blacklist_manager_.get();
[email protected]eaadd9052009-06-23 18:02:23967}
968
initial.commit09911bf2008-07-26 23:55:29969HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
970 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:46971 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:29972 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:32973 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:29974 return NULL;
975 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:29976
977 // Send out the notification that the history service was created.
978 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56979 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:29980 Details<HistoryService>(history_service_.get()));
981 }
982 return history_service_.get();
983}
984
[email protected]0850fa62009-10-08 22:34:29985HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
986 return history_service_.get();
987}
988
initial.commit09911bf2008-07-26 23:55:29989TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
990 if (!template_url_model_.get())
991 template_url_model_.reset(new TemplateURLModel(this));
992 return template_url_model_.get();
993}
994
995TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
996 if (!template_url_fetcher_.get())
997 template_url_fetcher_.reset(new TemplateURLFetcher(this));
998 return template_url_fetcher_.get();
999}
1000
[email protected]11f4857282009-11-13 19:56:171001SearchVersusNavigateClassifier*
1002ProfileImpl::GetSearchVersusNavigateClassifier() {
[email protected]90085af02009-10-29 17:53:211003 if (!search_versus_navigate_classifier_.get()) {
1004 search_versus_navigate_classifier_.reset(
1005 new SearchVersusNavigateClassifier(this));
1006 }
1007 return search_versus_navigate_classifier_.get();
1008}
1009
initial.commit09911bf2008-07-26 23:55:291010WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1011 if (!created_web_data_service_)
1012 CreateWebDataService();
1013 return web_data_service_.get();
1014}
1015
[email protected]9cddbe372009-10-23 21:23:531016WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1017 return web_data_service_.get();
1018}
1019
initial.commit09911bf2008-07-26 23:55:291020void ProfileImpl::CreateWebDataService() {
1021 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1022 created_web_data_service_ = true;
1023 scoped_refptr<WebDataService> wds(new WebDataService());
1024 if (!wds->Init(GetPath()))
1025 return;
1026 web_data_service_.swap(wds);
1027}
1028
[email protected]e69d33952009-06-03 22:00:411029PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1030 if (!created_password_store_)
1031 CreatePasswordStore();
1032 return password_store_.get();
1033}
1034
1035void ProfileImpl::CreatePasswordStore() {
1036 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1037 created_password_store_ = true;
1038 scoped_refptr<PasswordStore> ps;
1039#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251040 // TODO(evanm): implement "native" password management.
1041 // This bug describes the issues.
1042 // http://code.google.com/p/chromium/issues/detail?id=12351
1043 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1044 if (!ps->Init())
1045 return;
[email protected]e69d33952009-06-03 22:00:411046#elif defined(OS_WIN)
1047 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561048#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171049 FilePath login_db_file_path = GetPath();
1050 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1051 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1052 if (!login_db->Init(login_db_file_path)) {
1053 LOG(ERROR) << "Could not initialize login database.";
1054 delete login_db;
1055 return;
1056 }
1057 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411058#else
1059 NOTIMPLEMENTED();
1060#endif
1061 if (!ps || !ps->Init()) {
1062 // Try falling back to the default password manager
1063 LOG(WARNING) << "Could not initialise native password manager - "
1064 "falling back to default";
1065 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1066 if (!ps->Init())
1067 return;
1068 }
1069 password_store_.swap(ps);
1070}
1071
initial.commit09911bf2008-07-26 23:55:291072DownloadManager* ProfileImpl::GetDownloadManager() {
1073 if (!created_download_manager_) {
1074 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1075 dlm->Init(this);
1076 created_download_manager_ = true;
1077 download_manager_.swap(dlm);
1078 }
1079 return download_manager_.get();
1080}
1081
1082bool ProfileImpl::HasCreatedDownloadManager() const {
1083 return created_download_manager_;
1084}
1085
[email protected]def11712009-11-06 00:42:151086PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1087 if (!personal_data_manager_.get()) {
1088 personal_data_manager_.reset(new PersonalDataManager);
1089 }
1090 return personal_data_manager_.get();
1091}
1092
[email protected]4a190632009-05-09 01:07:421093void ProfileImpl::InitThemes() {
1094 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571095#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151096 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291097#else
[email protected]761962c2009-09-25 00:18:151098 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291099#endif
[email protected]761962c2009-09-25 00:18:151100 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421101 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421102 }
1103}
1104
1105void ProfileImpl::SetTheme(Extension* extension) {
1106 InitThemes();
1107 theme_provider_.get()->SetTheme(extension);
1108}
1109
[email protected]a5166af62009-07-03 00:42:291110void ProfileImpl::SetNativeTheme() {
1111 InitThemes();
1112 theme_provider_.get()->SetNativeTheme();
1113}
1114
[email protected]4a190632009-05-09 01:07:421115void ProfileImpl::ClearTheme() {
1116 InitThemes();
1117 theme_provider_.get()->UseDefaultTheme();
1118}
1119
[email protected]51c490b2009-08-03 16:34:341120Extension* ProfileImpl::GetTheme() {
1121 InitThemes();
1122
1123 std::string id = theme_provider_.get()->GetThemeID();
1124 if (id == BrowserThemeProvider::kDefaultThemeID)
1125 return NULL;
1126
[email protected]61b411612009-11-10 23:17:411127 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341128}
1129
[email protected]4a190632009-05-09 01:07:421130ThemeProvider* ProfileImpl::GetThemeProvider() {
1131 InitThemes();
1132 return theme_provider_.get();
1133}
1134
initial.commit09911bf2008-07-26 23:55:291135SessionService* ProfileImpl::GetSessionService() {
1136 if (!session_service_.get() && !shutdown_session_service_) {
1137 session_service_ = new SessionService(this);
1138 session_service_->ResetFromCurrentBrowsers();
1139 }
1140 return session_service_.get();
1141}
1142
1143void ProfileImpl::ShutdownSessionService() {
1144 if (shutdown_session_service_)
1145 return;
1146
1147 // We're about to exit, force creation of the session service if it hasn't
1148 // been created yet. We do this to ensure session state matches the point in
1149 // time the user exited.
1150 GetSessionService();
1151 shutdown_session_service_ = true;
1152 session_service_ = NULL;
1153}
1154
1155bool ProfileImpl::HasSessionService() const {
1156 return (session_service_.get() != NULL);
1157}
1158
initial.commit09911bf2008-07-26 23:55:291159bool ProfileImpl::DidLastSessionExitCleanly() {
1160 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1161 // it to be set by asking for the prefs.
1162 GetPrefs();
1163 return last_session_exited_cleanly_;
1164}
1165
[email protected]d8e41ed2008-09-11 15:22:321166BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461167 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321168 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461169 bookmark_bar_model_->Load();
1170 }
initial.commit09911bf2008-07-26 23:55:291171 return bookmark_bar_model_.get();
1172}
1173
1174bool ProfileImpl::IsSameProfile(Profile* profile) {
1175 if (profile == static_cast<Profile*>(this))
1176 return true;
1177 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1178 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1179}
1180
1181Time ProfileImpl::GetStartTime() const {
1182 return start_time_;
1183}
1184
1185TabRestoreService* ProfileImpl::GetTabRestoreService() {
1186 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191187 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291188 return tab_restore_service_.get();
1189}
1190
[email protected]449478302009-06-09 20:04:281191ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1192 if (!thumbnail_store_.get()) {
1193 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251194 thumbnail_store_->Init(
1195 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281196 }
1197 return thumbnail_store_.get();
1198}
1199
initial.commit09911bf2008-07-26 23:55:291200void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191201 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291202}
1203
[email protected]85c55dc2009-11-06 03:05:461204SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1205 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1206}
1207
1208void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1209 // If we are already loading the spellchecker, and this is just a hint to
1210 // load the spellchecker, do nothing.
1211 if (!force && spellcheck_host_.get())
1212 return;
1213
[email protected]f41301e2009-11-16 21:30:071214 spellcheck_host_ready_ = false;
1215
[email protected]85c55dc2009-11-06 03:05:461216 bool notify = false;
1217 if (spellcheck_host_.get()) {
1218 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051219 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461220 notify = true;
1221 }
1222
1223 PrefService* prefs = GetPrefs();
1224 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1225 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1226 spellcheck_host_ = new SpellCheckHost(this,
1227 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1228 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071229 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461230 } else if (notify) {
1231 // The spellchecker has been disabled.
1232 SpellCheckHostInitialized();
1233 }
1234}
1235
1236void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171237 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291238 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1239 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461240 NotificationService::current()->Notify(
1241 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1242 Source<Profile>(this), NotificationService::NoDetails());
1243}
initial.commit09911bf2008-07-26 23:55:291244
[email protected]3bf335a2009-06-26 20:46:061245WebKitContext* ProfileImpl::GetWebKitContext() {
1246 if (!webkit_context_.get())
1247 webkit_context_ = new WebKitContext(path_, false);
1248 DCHECK(webkit_context_.get());
1249 return webkit_context_.get();
1250}
1251
[email protected]4bb336302009-10-12 05:44:261252DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1253 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1254 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261255 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031256 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261257 }
[email protected]4bb336302009-10-12 05:44:261258 return desktop_notification_service_.get();
1259}
1260
initial.commit09911bf2008-07-26 23:55:291261void ProfileImpl::MarkAsCleanShutdown() {
1262 if (prefs_.get()) {
1263 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1264 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1265
1266 // NOTE: If you change what thread this writes on, be sure and update
1267 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361268 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291269 }
1270}
1271
[email protected]e7244d82008-10-29 18:13:261272void ProfileImpl::Observe(NotificationType type,
1273 const NotificationSource& source,
1274 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561275 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261276 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1277 PrefService* prefs = Source<PrefService>(source).ptr();
1278 DCHECK(pref_name_in && prefs);
1279 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461280 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461281 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291282 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1283 NotificationService::current()->Notify(
1284 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1285 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261286 }
[email protected]4a190632009-05-09 01:07:421287 } else if (NotificationType::THEME_INSTALLED == type) {
1288 Extension* extension = Details<Extension>(details).ptr();
1289 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111290 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1291 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1292 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1293 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261294 }
1295}
1296
initial.commit09911bf2008-07-26 23:55:291297void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141298 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291299}
[email protected]3a453fa2008-08-15 18:46:341300
[email protected]48352c12009-08-15 01:19:111301ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431302 if (!ProfileSyncService::IsSyncEnabled()) {
1303 return NULL;
[email protected]7367f1a2009-10-10 01:09:441304 }
[email protected]eec3bcfa2009-11-12 17:23:431305 if (!sync_service_.get())
1306 InitSyncService();
1307 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111308}
1309
1310void ProfileImpl::InitSyncService() {
[email protected]48352c12009-08-15 01:19:111311 sync_service_.reset(new ProfileSyncService(this));
1312 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111313}