blob: 269bf95cff13e60a84d5e82a951125525949371c [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]67a46b7f2009-06-16 21:41:0217#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3718#include "chrome/browser/chrome_thread.h"
[email protected]b7f05882009-02-22 01:21:5619#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0720#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3721#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0522#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2523#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3524#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4825#include "chrome/browser/favicon_service.h"
[email protected]77f6fb432009-09-05 14:21:0926#include "chrome/browser/strict_transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4227#include "chrome/browser/history/history.h"
[email protected]3bf335a2009-06-26 20:46:0628#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5029#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4230#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2631#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4132#include "chrome/browser/password_manager/password_store_default.h"
[email protected]588074f2009-10-29 09:40:1033#include "chrome/browser/privacy_blacklist/blacklist_io.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2635#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]90085af02009-10-29 17:53:2136#include "chrome/browser/search_versus_navigate_classifier.h"
[email protected]1132436e2009-04-08 20:06:3337#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4638#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4439#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3040#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]f0a644292009-02-25 23:32:4741#include "chrome/browser/spellchecker.h"
[email protected]1132436e2009-04-08 20:06:3342#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1143#include "chrome/browser/sync/profile_sync_service.h"
[email protected]449478302009-06-09 20:04:2844#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3946#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2947#include "chrome/browser/webdata/web_data_service.h"
[email protected]23f1ef12009-09-01 22:30:3048#include "chrome/common/appcache/chrome_appcache_service.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/common/chrome_constants.h"
50#include "chrome/common/chrome_paths.h"
51#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5852#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2953#include "chrome/common/notification_service.h"
54#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3255#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5856#include "grit/locale_settings.h"
[email protected]77f6fb432009-09-05 14:21:0957#include "net/base/strict_transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3458#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2959
[email protected]a5166af62009-07-03 00:42:2960#if defined(OS_LINUX)
[email protected]a5166af62009-07-03 00:42:2961#include "chrome/browser/gtk/gtk_theme_provider.h"
62#endif
63
[email protected]2627431b2009-09-15 20:21:5364#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:2965#include "chrome/browser/chromeos/preferences.h"
[email protected]2627431b2009-09-15 20:21:5366#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]47accfd62009-05-14 18:46:21132 if (context) {
133 context->CleanupOnUIThread();
134
135 // Clean up request context on IO thread.
[email protected]6fad2632009-11-02 05:59:37136 ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, context);
[email protected]47accfd62009-05-14 18:46:21137 }
138}
139
[email protected]34cc84f2009-02-13 10:04:35140// static
[email protected]4bf6afd2009-10-08 14:00:11141const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
142
143// static
initial.commit09911bf2008-07-26 23:55:29144void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55145 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29146 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
147 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12148 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26149 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
150 IDS_SPELLCHECK_DICTIONARY);
151 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58152 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]f93fe782009-02-19 01:26:13153 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
[email protected]a5166af62009-07-03 00:42:29154#if defined(OS_LINUX)
155 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
156#endif
[email protected]51c490b2009-08-03 16:34:34157 prefs->RegisterStringPref(prefs::kCurrentThemeID,
158 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42159 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
160 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
161 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50162 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23163 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29164}
165
[email protected]34cc84f2009-02-13 10:04:35166// static
[email protected]f7011fcb2009-01-28 21:54:32167Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29168 return new ProfileImpl(path);
169}
170
[email protected]34cc84f2009-02-13 10:04:35171// static
[email protected]be180c802009-10-23 06:33:31172URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29173 return default_request_context_;
174}
175
[email protected]e69d33952009-06-03 22:00:41176#if defined(OS_LINUX)
177// Temporarily disabled while we figure some stuff out.
178// http://code.google.com/p/chromium/issues/detail?id=12351
179// #include "chrome/browser/password_manager/password_store_gnome.h"
180// #include "chrome/browser/password_manager/password_store_kwallet.h"
181#elif defined(OS_WIN)
182#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56183#elif defined(OS_MACOSX)
184#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17185#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56186#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41187#endif
initial.commit09911bf2008-07-26 23:55:29188
initial.commit09911bf2008-07-26 23:55:29189////////////////////////////////////////////////////////////////////////////////
190//
191// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42192// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29193//
194////////////////////////////////////////////////////////////////////////////////
195class OffTheRecordProfileImpl : public Profile,
196 public NotificationObserver {
197 public:
198 explicit OffTheRecordProfileImpl(Profile* real_profile)
199 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21200 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29201 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31202 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
initial.commit09911bf2008-07-26 23:55:29203 request_context_->AddRef();
[email protected]481e1a42009-05-06 20:56:05204
initial.commit09911bf2008-07-26 23:55:29205 // Register for browser close notifications so we can detect when the last
206 // off-the-record window is closed, in which case we can clean our states
207 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43208 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
209 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29210 }
211
212 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21213 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21214 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29215 }
216
[email protected]4bf6afd2009-10-08 14:00:11217 virtual ProfileId GetRuntimeId() {
218 return reinterpret_cast<ProfileId>(this);
219 }
220
[email protected]f7011fcb2009-01-28 21:54:32221 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29222
223 virtual bool IsOffTheRecord() {
224 return true;
225 }
226
227 virtual Profile* GetOffTheRecordProfile() {
228 return this;
229 }
230
[email protected]860f55492009-03-27 19:50:59231 virtual void DestroyOffTheRecordProfile() {
232 // Suicide is bad!
233 NOTREACHED();
234 }
235
initial.commit09911bf2008-07-26 23:55:29236 virtual Profile* GetOriginalProfile() {
237 return profile_;
238 }
239
[email protected]2f351cb2009-11-09 23:43:34240 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
241 if (!db_tracker_)
242 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
243 return db_tracker_;
244 }
245
initial.commit09911bf2008-07-26 23:55:29246 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49247 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
248 // because we don't want to leak the sites that the user has visited before.
249 return NULL;
initial.commit09911bf2008-07-26 23:55:29250 }
251
[email protected]6014d672008-12-05 00:38:25252 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34253 return NULL;
[email protected]6014d672008-12-05 00:38:25254 }
255
[email protected]0938d3c2009-01-09 20:37:35256 virtual UserScriptMaster* GetUserScriptMaster() {
257 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25258 }
259
[email protected]89ebc7e2009-08-24 22:11:07260 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
261 return NULL;
262 }
263
[email protected]481e1a42009-05-06 20:56:05264 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34265 return NULL;
[email protected]481e1a42009-05-06 20:56:05266 }
267
[email protected]7120f132009-07-20 21:05:37268 virtual ExtensionMessageService* GetExtensionMessageService() {
269 return NULL;
270 }
271
[email protected]34cc84f2009-02-13 10:04:35272 virtual SSLHostState* GetSSLHostState() {
273 if (!ssl_host_state_.get())
274 ssl_host_state_.reset(new SSLHostState());
275
276 DCHECK(ssl_host_state_->CalledOnValidThread());
277 return ssl_host_state_.get();
278 }
279
[email protected]77f6fb432009-09-05 14:21:09280 virtual net::StrictTransportSecurityState* GetStrictTransportSecurityState() {
281 if (!strict_transport_security_state_.get()) {
282 strict_transport_security_state_ =
283 new net::StrictTransportSecurityState();
284 }
[email protected]a9cea7542009-05-20 04:30:23285
[email protected]77f6fb432009-09-05 14:21:09286 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23287 }
288
initial.commit09911bf2008-07-26 23:55:29289 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
290 if (sat == EXPLICIT_ACCESS) {
291 return profile_->GetHistoryService(sat);
292 } else {
293 NOTREACHED() << "This profile is OffTheRecord";
294 return NULL;
295 }
296 }
297
[email protected]0850fa62009-10-08 22:34:29298 virtual HistoryService* GetHistoryServiceWithoutCreating() {
299 return profile_->GetHistoryServiceWithoutCreating();
300 }
301
[email protected]0189bc722009-08-28 21:56:48302 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
303 if (sat == EXPLICIT_ACCESS) {
304 return profile_->GetFaviconService(sat);
305 } else {
306 NOTREACHED() << "This profile is OffTheRecord";
307 return NULL;
308 }
309 }
310
[email protected]90085af02009-10-29 17:53:21311 virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
312 return profile_->GetSearchVersusNavigateClassifier();
313 }
314
initial.commit09911bf2008-07-26 23:55:29315 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
316 if (sat == EXPLICIT_ACCESS) {
317 return profile_->GetWebDataService(sat);
318 } else {
319 NOTREACHED() << "This profile is OffTheRecord";
320 return NULL;
321 }
322 }
323
[email protected]9cddbe372009-10-23 21:23:53324 virtual WebDataService* GetWebDataServiceWithoutCreating() {
325 return profile_->GetWebDataServiceWithoutCreating();
326 }
327
[email protected]e69d33952009-06-03 22:00:41328 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
329 if (sat == EXPLICIT_ACCESS) {
330 return profile_->GetPasswordStore(sat);
331 } else {
332 NOTREACHED() << "This profile is OffTheRecord";
333 return NULL;
334 }
335 }
336
initial.commit09911bf2008-07-26 23:55:29337 virtual PrefService* GetPrefs() {
338 return profile_->GetPrefs();
339 }
340
341 virtual TemplateURLModel* GetTemplateURLModel() {
342 return profile_->GetTemplateURLModel();
343 }
344
345 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
346 return profile_->GetTemplateURLFetcher();
347 }
348
349 virtual DownloadManager* GetDownloadManager() {
350 if (!download_manager_.get()) {
351 scoped_refptr<DownloadManager> dlm(new DownloadManager);
352 dlm->Init(this);
353 download_manager_.swap(dlm);
354 }
355 return download_manager_.get();
356 }
357
358 virtual bool HasCreatedDownloadManager() const {
359 return (download_manager_.get() != NULL);
360 }
361
[email protected]def11712009-11-06 00:42:15362 virtual PersonalDataManager* GetPersonalDataManager() {
363 return NULL;
364 }
365
[email protected]4a190632009-05-09 01:07:42366 virtual void InitThemes() {
367 GetOriginalProfile()->InitThemes();
368 }
369
370 virtual void SetTheme(Extension* extension) {
371 GetOriginalProfile()->SetTheme(extension);
372 }
373
[email protected]a5166af62009-07-03 00:42:29374 virtual void SetNativeTheme() {
375 GetOriginalProfile()->SetNativeTheme();
376 }
377
[email protected]4a190632009-05-09 01:07:42378 virtual void ClearTheme() {
379 GetOriginalProfile()->ClearTheme();
380 }
381
[email protected]51c490b2009-08-03 16:34:34382 virtual Extension* GetTheme() {
383 return GetOriginalProfile()->GetTheme();
384 }
385
[email protected]4a190632009-05-09 01:07:42386 virtual ThemeProvider* GetThemeProvider() {
387 return GetOriginalProfile()->GetThemeProvider();
388 }
389
[email protected]be180c802009-10-23 06:33:31390 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29391 return request_context_;
392 }
393
[email protected]be180c802009-10-23 06:33:31394 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11395 // In OTR mode, media request context is the same as the original one.
396 return request_context_;
[email protected]e7f29642009-03-02 22:53:18397 }
398
[email protected]be180c802009-10-23 06:33:31399 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21400 if (!extensions_request_context_) {
401 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31402 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this);
[email protected]47accfd62009-05-14 18:46:21403 extensions_request_context_->AddRef();
[email protected]47accfd62009-05-14 18:46:21404 }
405
406 return extensions_request_context_;
407 }
408
[email protected]db36938c2009-08-19 21:48:42409 virtual net::SSLConfigService* GetSSLConfigService() {
410 return GetOriginalProfile()->GetSSLConfigService();
411 }
412
[email protected]eaadd9052009-06-23 18:02:23413 virtual Blacklist* GetBlacklist() {
414 return GetOriginalProfile()->GetBlacklist();
415 }
416
initial.commit09911bf2008-07-26 23:55:29417 virtual SessionService* GetSessionService() {
418 // Don't save any sessions when off the record.
419 return NULL;
420 }
421
422 virtual void ShutdownSessionService() {
423 // We don't allow a session service, nothing to do.
424 }
425
426 virtual bool HasSessionService() const {
427 // We never have a session service.
428 return false;
429 }
430
431 virtual std::wstring GetName() {
432 return profile_->GetName();
433 }
434
435 virtual void SetName(const std::wstring& name) {
436 profile_->SetName(name);
437 }
438
439 virtual std::wstring GetID() {
440 return profile_->GetID();
441 }
442
443 virtual void SetID(const std::wstring& id) {
444 profile_->SetID(id);
445 }
446
initial.commit09911bf2008-07-26 23:55:29447 virtual bool DidLastSessionExitCleanly() {
448 return profile_->DidLastSessionExitCleanly();
449 }
450
[email protected]d8e41ed2008-09-11 15:22:32451 virtual BookmarkModel* GetBookmarkModel() {
452 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29453 }
454
[email protected]4bb336302009-10-12 05:44:26455 virtual DesktopNotificationService* GetDesktopNotificationService() {
456 return profile_->GetDesktopNotificationService();
457 }
458
[email protected]48352c12009-08-15 01:19:11459 virtual ProfileSyncService* GetProfileSyncService() {
460 return NULL;
[email protected]3a453fa2008-08-15 18:46:34461 }
[email protected]3a453fa2008-08-15 18:46:34462
initial.commit09911bf2008-07-26 23:55:29463 virtual bool IsSameProfile(Profile* profile) {
464 if (profile == static_cast<Profile*>(this))
465 return true;
466 return profile == profile_;
467 }
468
469 virtual Time GetStartTime() const {
470 return start_time_;
471 }
472
473 virtual TabRestoreService* GetTabRestoreService() {
474 return NULL;
475 }
476
[email protected]e7244d82008-10-29 18:13:26477 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41478 }
479
[email protected]e7244d82008-10-29 18:13:26480 virtual void ReinitializeSpellChecker() {
481 profile_->ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:29482 }
483
484 virtual SpellChecker* GetSpellChecker() {
485 return profile_->GetSpellChecker();
486 }
487
[email protected]e3448ea2009-10-02 01:29:29488 virtual void DeleteSpellChecker() {
489 profile_->DeleteSpellChecker();
490 }
491
[email protected]85c55dc2009-11-06 03:05:46492#if defined(SPELLCHECKER_IN_RENDERER)
493 virtual SpellCheckHost* GetSpellCheckHost() {
494 return profile_->GetSpellCheckHost();
495 }
496
497 virtual void ReinitializeSpellCheckHost(bool force) {
498 profile_->ReinitializeSpellCheckHost(force);
499 }
500#endif
501
[email protected]3bf335a2009-06-26 20:46:06502 virtual WebKitContext* GetWebKitContext() {
503 if (!webkit_context_.get())
504 webkit_context_ = new WebKitContext(GetPath(), true);
505 DCHECK(webkit_context_.get());
506 return webkit_context_.get();
507}
508
[email protected]449478302009-06-09 20:04:28509 virtual ThumbnailStore* GetThumbnailStore() {
510 return NULL;
511 }
512
initial.commit09911bf2008-07-26 23:55:29513 virtual void MarkAsCleanShutdown() {
514 }
515
[email protected]bdbc87c2009-01-25 05:08:54516 virtual void InitExtensions() {
517 NOTREACHED();
518 }
519
[email protected]ea0c98cf2009-06-18 23:02:54520 virtual void InitWebResources() {
521 NOTREACHED();
522 }
523
initial.commit09911bf2008-07-26 23:55:29524 virtual void ExitedOffTheRecordMode() {
525 // Drop our download manager so we forget about all the downloads made
526 // in off-the-record mode.
527 download_manager_ = NULL;
528 }
529
530 virtual void Observe(NotificationType type,
531 const NotificationSource& source,
532 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56533 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29534 // We are only interested in OTR browser closing.
535 if (Source<Browser>(source)->profile() != this)
536 return;
537
538 // Let's check if we still have an Off The Record window opened.
539 // Note that we check against 1 as this notification is sent before the
540 // browser window is actually removed from the list.
541 if (BrowserList::GetBrowserCount(this) <= 1)
542 ExitedOffTheRecordMode();
543 }
544
545 private:
[email protected]88cf3292009-05-22 01:48:43546 NotificationRegistrar registrar_;
547
initial.commit09911bf2008-07-26 23:55:29548 // The real underlying profile.
549 Profile* profile_;
550
[email protected]6ab9b202008-12-23 22:34:50551 // The context to use for requests made from this OTR session.
[email protected]be180c802009-10-23 06:33:31552 ChromeURLRequestContextGetter* request_context_;
initial.commit09911bf2008-07-26 23:55:29553
[email protected]be180c802009-10-23 06:33:31554 ChromeURLRequestContextGetter* extensions_request_context_;
[email protected]23f1ef12009-09-01 22:30:30555
initial.commit09911bf2008-07-26 23:55:29556 // The download manager that only stores downloaded items in memory.
557 scoped_refptr<DownloadManager> download_manager_;
558
[email protected]3bf335a2009-06-26 20:46:06559 // Use a special WebKit context for OTR browsing.
560 scoped_refptr<WebKitContext> webkit_context_;
561
[email protected]34cc84f2009-02-13 10:04:35562 // We don't want SSLHostState from the OTR profile to leak back to the main
563 // profile because then the main profile would learn some of the host names
564 // the user visited while OTR.
565 scoped_ptr<SSLHostState> ssl_host_state_;
566
[email protected]77f6fb432009-09-05 14:21:09567 // The StrictTransportSecurityState that only stores enabled sites in memory.
568 scoped_refptr<net::StrictTransportSecurityState>
569 strict_transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23570
initial.commit09911bf2008-07-26 23:55:29571 // Time we were started.
572 Time start_time_;
573
[email protected]2f351cb2009-11-09 23:43:34574 // The main database tracker for this profile.
575 // Should be used only on the file thread.
576 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
577
[email protected]90085af02009-10-29 17:53:21578 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29579};
580
[email protected]f7011fcb2009-01-28 21:54:32581ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29582 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39583 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07584 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32585 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57586 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21587 extensions_request_context_(NULL),
[email protected]eaadd9052009-06-23 18:02:23588 blacklist_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32589 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48590 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32591 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41592 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32593 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42594 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32595 start_time_(Time::Now()),
596 spellchecker_(NULL),
[email protected]85c55dc2009-11-06 03:05:46597#if defined(OS_LINUX)
598 spellcheck_host_(NULL),
599 spellcheck_host_ready_(false),
600#endif
initial.commit09911bf2008-07-26 23:55:29601 shutdown_session_service_(false) {
602 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
603 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14604 create_session_service_timer_.Start(
605 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
606 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54607
[email protected]89ebc7e2009-08-24 22:11:07608 if (CommandLine::ForCurrentProcess()->HasSwitch(
609 switches::kEnableExtensionTimelineApi)) {
610 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
611 }
612
[email protected]382a0702009-06-26 17:12:27613 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37614 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27615
[email protected]e7244d82008-10-29 18:13:26616 PrefService* prefs = GetPrefs();
617 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
618 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58619 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58620
[email protected]eaadd9052009-06-23 18:02:23621 if (CommandLine::ForCurrentProcess()->
622 HasSwitch(switches::kPrivacyBlacklist)) {
623 std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue(
624 switches::kPrivacyBlacklist);
625#if defined(OS_POSIX)
626 FilePath path(WideToUTF8(option));
627#else
628 FilePath path(option);
629#endif
[email protected]588074f2009-10-29 09:40:10630 blacklist_.reset(new Blacklist);
631 // TODO(phajdan.jr): Handle errors when reading blacklist.
632 BlacklistIO::ReadBinary(blacklist_.get(), path);
[email protected]eaadd9052009-06-23 18:02:23633 }
634
[email protected]405a64b2009-09-16 21:03:44635#if defined(OS_MACOSX)
636 // If the profile directory doesn't already have a cache directory and it
637 // is under ~/Library/Application Support, use a suitable cache directory
638 // under ~/Library/Caches. For example, a profile directory of
639 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
640 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
641 // ~/Library/Caches/Google/Chrome/MyProfileName.
642 //
643 // TODO(akalin): Come up with unit tests for this.
644 // TODO(akalin): Use for Linux, too?
645 if (!HasACacheSubdir(path_)) {
646 FilePath app_data_path, user_cache_path;
647 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
648 PathService::Get(base::DIR_CACHE, &user_cache_path) &&
649 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
650 base_cache_path_ = user_cache_path;
651 }
652 }
653#else
[email protected]bc96d562009-08-11 18:45:13654 if (!PathService::IsOverridden(chrome::DIR_USER_DATA))
655 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_);
[email protected]405a64b2009-09-16 21:03:44656#endif
[email protected]bc96d562009-08-11 18:45:13657 if (base_cache_path_.empty())
658 base_cache_path_ = path_;
659
[email protected]4a190632009-05-09 01:07:42660 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43661 registrar_.Add(this, NotificationType::THEME_INSTALLED,
662 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11663
664 // Listen for bookmark model load, to bootstrap the sync service.
665 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
666 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42667
668 ssl_config_service_manager_.reset(
669 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53670
671#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29672 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53673#endif
initial.commit09911bf2008-07-26 23:55:29674}
675
[email protected]bdbc87c2009-01-25 05:08:54676void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41677 if (user_script_master_ || extensions_service_)
678 return; // Already initialized.
679
[email protected]bdbc87c2009-01-25 05:08:54680 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]f93fe782009-02-19 01:26:13681 PrefService* prefs = GetPrefs();
[email protected]bdbc87c2009-01-25 05:08:54682 bool user_scripts_enabled =
[email protected]f0a51fb52009-03-05 12:46:38683 command_line->HasSwitch(switches::kEnableUserScripts) ||
[email protected]f93fe782009-02-19 01:26:13684 prefs->GetBoolean(prefs::kEnableUserScripts);
[email protected]bdbc87c2009-01-25 05:08:54685
[email protected]f7011fcb2009-01-28 21:54:32686 FilePath script_dir;
[email protected]bdbc87c2009-01-25 05:08:54687 if (user_scripts_enabled) {
[email protected]0cd957b2009-03-06 20:13:23688 if (command_line->HasSwitch(switches::kUserScriptsDir)) {
689 std::wstring path_string =
690 command_line->GetSwitchValue(switches::kUserScriptsDir);
691 script_dir = FilePath::FromWStringHack(path_string);
692 } else {
693 script_dir = GetPath();
694 script_dir = script_dir.Append(chrome::kUserScriptsDirname);
695 }
[email protected]bdbc87c2009-01-25 05:08:54696 }
697
[email protected]bb28e062009-02-27 17:19:18698 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]95d29192009-10-30 01:49:06699 user_script_master_ = new UserScriptMaster(script_dir);
[email protected]894bb502009-05-21 22:39:57700 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23701 this,
702 CommandLine::ForCurrentProcess(),
703 GetPrefs(),
704 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36705 true);
[email protected]bdbc87c2009-01-25 05:08:54706
[email protected]9197f3b2009-06-02 00:49:27707 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12708
709 // Load any extensions specified with --load-extension.
710 if (command_line->HasSwitch(switches::kLoadExtension)) {
711 std::wstring path_string =
712 command_line->GetSwitchValue(switches::kLoadExtension);
713 FilePath path = FilePath::FromWStringHack(path_string);
714 extensions_service_->LoadExtension(path);
715
716 // Tell UserScriptMaser to watch this extension's directory for changes so
717 // you can live edit content scripts during development.
718 user_script_master_->AddWatchedPath(path);
719 }
[email protected]bdbc87c2009-01-25 05:08:54720}
721
[email protected]ea0c98cf2009-06-18 23:02:54722void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07723 if (web_resource_service_)
724 return; // Already initialized.
725
[email protected]6fad2632009-11-02 05:59:37726 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54727 web_resource_service_->StartAfterDelay();
728}
729
initial.commit09911bf2008-07-26 23:55:29730ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19731 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29732
733 StopCreateSessionServiceTimer();
734 // TemplateURLModel schedules a task on the WebDataService from its
735 // destructor. Delete it first to ensure the task gets scheduled before we
736 // shut down the database.
737 template_url_model_.reset();
738
739 // The download manager queries the history system and should be deleted
740 // before the history is shutdown so it can properly cancel all requests.
741 download_manager_ = NULL;
742
[email protected]4a190632009-05-09 01:07:42743 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15744 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42745
[email protected]44961292009-07-20 20:03:09746 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
747 // save any new thumbnails to disk and release its reference to the
748 // HistoryService.
749 if (thumbnail_store_.get())
750 thumbnail_store_->Shutdown();
751
[email protected]e7244d82008-10-29 18:13:26752 // Remove pref observers.
753 PrefService* prefs = GetPrefs();
754 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
755 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58756 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26757
[email protected]48352c12009-08-15 01:19:11758 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34759
initial.commit09911bf2008-07-26 23:55:29760 // Both HistoryService and WebDataService maintain threads for background
761 // processing. Its possible each thread still has tasks on it that have
762 // increased the ref count of the service. In such a situation, when we
763 // decrement the refcount, it won't be 0, and the threads/databases aren't
764 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
765 // databases are properly closed.
766 if (web_data_service_.get())
767 web_data_service_->Shutdown();
768
769 if (history_service_.get())
770 history_service_->Cleanup();
771
[email protected]85c55dc2009-11-06 03:05:46772#if defined(SPELLCHECKER_IN_RENDERER)
773 if (spellcheck_host_.get())
774 spellcheck_host_->UnsetObserver();
775#endif
[email protected]e3448ea2009-10-02 01:29:29776 DeleteSpellCheckerImpl(false);
initial.commit09911bf2008-07-26 23:55:29777
[email protected]cfc06f122009-11-16 22:18:55778 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21779 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50780
[email protected]47accfd62009-05-14 18:46:21781 CleanupRequestContext(request_context_);
782 CleanupRequestContext(media_request_context_);
783 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17784
[email protected]eaadd9052009-06-23 18:02:23785 // When the request contexts are gone, the blacklist wont be needed anymore.
[email protected]588074f2009-10-29 09:40:10786 blacklist_.reset();
[email protected]eaadd9052009-06-23 18:02:23787
[email protected]d8e41ed2008-09-11 15:22:32788 // HistoryService may call into the BookmarkModel, as such we need to
789 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46790 // HistoryService will join with HistoryService's backend thread so that
791 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32792 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46793 history_service_ = NULL;
794 bookmark_bar_model_.reset();
795
[email protected]0189bc722009-08-28 21:56:48796 // FaviconService depends on HistoryServce so make sure we delete
797 // HistoryService first.
798 favicon_service_ = NULL;
799
[email protected]7120f132009-07-20 21:05:37800 extension_message_service_->ProfileDestroyed();
801
[email protected]6ef635e42009-07-26 06:16:12802 if (extensions_service_)
803 extensions_service_->ProfileDestroyed();
804
[email protected]66da08b2009-10-19 22:27:00805 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29806 MarkAsCleanShutdown();
807}
808
[email protected]4bf6afd2009-10-08 14:00:11809ProfileId ProfileImpl::GetRuntimeId() {
810 return reinterpret_cast<ProfileId>(this);
811}
812
[email protected]f7011fcb2009-01-28 21:54:32813FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29814 return path_;
815}
816
817bool ProfileImpl::IsOffTheRecord() {
818 return false;
819}
820
821Profile* ProfileImpl::GetOffTheRecordProfile() {
822 if (!off_the_record_profile_.get()) {
823 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
824 off_the_record_profile_.swap(p);
825 }
826 return off_the_record_profile_.get();
827}
828
[email protected]860f55492009-03-27 19:50:59829void ProfileImpl::DestroyOffTheRecordProfile() {
830 off_the_record_profile_.reset();
831}
832
initial.commit09911bf2008-07-26 23:55:29833Profile* ProfileImpl::GetOriginalProfile() {
834 return this;
835}
836
[email protected]2f351cb2009-11-09 23:43:34837webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
838 if (!db_tracker_)
839 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
840 return db_tracker_;
841}
842
initial.commit09911bf2008-07-26 23:55:29843VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
844 if (!visited_link_master_.get()) {
845 scoped_ptr<VisitedLinkMaster> visited_links(
[email protected]6fad2632009-11-02 05:59:37846 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29847 if (!visited_links->Init())
848 return NULL;
849 visited_link_master_.swap(visited_links);
850 }
851
852 return visited_link_master_.get();
853}
854
[email protected]6014d672008-12-05 00:38:25855ExtensionsService* ProfileImpl::GetExtensionsService() {
856 return extensions_service_.get();
857}
858
[email protected]0938d3c2009-01-09 20:37:35859UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35860 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25861}
862
[email protected]89ebc7e2009-08-24 22:11:07863ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
864 return extension_devtools_manager_.get();
865}
866
[email protected]481e1a42009-05-06 20:56:05867ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27868 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05869}
870
[email protected]7120f132009-07-20 21:05:37871ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
872 return extension_message_service_.get();
873}
874
[email protected]34cc84f2009-02-13 10:04:35875SSLHostState* ProfileImpl::GetSSLHostState() {
876 if (!ssl_host_state_.get())
877 ssl_host_state_.reset(new SSLHostState());
878
879 DCHECK(ssl_host_state_->CalledOnValidThread());
880 return ssl_host_state_.get();
881}
882
[email protected]77f6fb432009-09-05 14:21:09883net::StrictTransportSecurityState*
884 ProfileImpl::GetStrictTransportSecurityState() {
885 if (!strict_transport_security_state_.get()) {
886 strict_transport_security_state_ = new net::StrictTransportSecurityState();
887 strict_transport_security_persister_ = new StrictTransportSecurityPersister(
[email protected]6fad2632009-11-02 05:59:37888 strict_transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51889 }
[email protected]a9cea7542009-05-20 04:30:23890
[email protected]77f6fb432009-09-05 14:21:09891 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23892}
893
initial.commit09911bf2008-07-26 23:55:29894PrefService* ProfileImpl::GetPrefs() {
895 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37896 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29897
898 // The Profile class and ProfileManager class may read some prefs so
899 // register known prefs as soon as possible.
900 Profile::RegisterUserPrefs(prefs_.get());
901 ProfileManager::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53902#if defined(OS_CHROMEOS)
903 // Register Touchpad prefs here instead of in browser_prefs because these
904 // prefs are used in the constructor of ProfileImpl which happens before
905 // browser_prefs' RegisterAllPrefs is called.
[email protected]fecc1522009-10-15 21:08:29906 chromeos::Preferences::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53907#endif
initial.commit09911bf2008-07-26 23:55:29908
909 // The last session exited cleanly if there is no pref for
910 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
911 last_session_exited_cleanly_ =
912 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
913 // Mark the session as open.
914 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
915 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36916 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29917 }
918
919 return prefs_.get();
920}
921
[email protected]f7011fcb2009-01-28 21:54:32922FilePath ProfileImpl::GetPrefFilePath() {
923 FilePath pref_file_path = path_;
924 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29925 return pref_file_path;
926}
927
[email protected]be180c802009-10-23 06:33:31928URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29929 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32930 FilePath cookie_path = GetPath();
931 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13932 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31933 int max_size;
934 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42935
[email protected]405a64b2009-09-16 21:03:44936 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31937 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
938 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29939 request_context_->AddRef();
940
[email protected]6ab9b202008-12-23 22:34:50941 // The first request context is always a normal (non-OTR) request context.
942 // Even when Chromium is started in OTR mode, a normal profile is always
943 // created first.
944 if (!default_request_context_) {
945 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31946 // TODO(eroman): this isn't terribly useful anymore now that the
947 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50948 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56949 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50950 NotificationService::AllSources(), NotificationService::NoDetails());
951 }
initial.commit09911bf2008-07-26 23:55:29952 }
953
954 return request_context_;
955}
956
[email protected]be180c802009-10-23 06:33:31957URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18958 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13959 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31960 int max_size;
961 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14962
[email protected]405a64b2009-09-16 21:03:44963 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31964 media_request_context_ =
965 ChromeURLRequestContextGetter::CreateOriginalForMedia(
966 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18967 media_request_context_->AddRef();
[email protected]e7f29642009-03-02 22:53:18968 }
969
970 return media_request_context_;
971}
972
[email protected]0189bc722009-08-28 21:56:48973FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
974 if (!favicon_service_created_) {
975 favicon_service_created_ = true;
976 scoped_refptr<FaviconService> service(new FaviconService(this));
977 favicon_service_.swap(service);
978 }
979 return favicon_service_.get();
980}
981
[email protected]be180c802009-10-23 06:33:31982URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21983 if (!extensions_request_context_) {
984 FilePath cookie_path = GetPath();
985 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
986
987 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31988 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
989 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21990 extensions_request_context_->AddRef();
[email protected]47accfd62009-05-14 18:46:21991 }
992
993 return extensions_request_context_;
994}
995
[email protected]db36938c2009-08-19 21:48:42996net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
997 return ssl_config_service_manager_->Get();
998}
999
[email protected]eaadd9052009-06-23 18:02:231000Blacklist* ProfileImpl::GetBlacklist() {
[email protected]588074f2009-10-29 09:40:101001 return blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231002}
1003
initial.commit09911bf2008-07-26 23:55:291004HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1005 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461006 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291007 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321008 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291009 return NULL;
1010 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291011
1012 // Send out the notification that the history service was created.
1013 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561014 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291015 Details<HistoryService>(history_service_.get()));
1016 }
1017 return history_service_.get();
1018}
1019
[email protected]0850fa62009-10-08 22:34:291020HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1021 return history_service_.get();
1022}
1023
initial.commit09911bf2008-07-26 23:55:291024TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1025 if (!template_url_model_.get())
1026 template_url_model_.reset(new TemplateURLModel(this));
1027 return template_url_model_.get();
1028}
1029
1030TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1031 if (!template_url_fetcher_.get())
1032 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1033 return template_url_fetcher_.get();
1034}
1035
[email protected]11f4857282009-11-13 19:56:171036SearchVersusNavigateClassifier*
1037ProfileImpl::GetSearchVersusNavigateClassifier() {
[email protected]90085af02009-10-29 17:53:211038 if (!search_versus_navigate_classifier_.get()) {
1039 search_versus_navigate_classifier_.reset(
1040 new SearchVersusNavigateClassifier(this));
1041 }
1042 return search_versus_navigate_classifier_.get();
1043}
1044
initial.commit09911bf2008-07-26 23:55:291045WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1046 if (!created_web_data_service_)
1047 CreateWebDataService();
1048 return web_data_service_.get();
1049}
1050
[email protected]9cddbe372009-10-23 21:23:531051WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1052 return web_data_service_.get();
1053}
1054
initial.commit09911bf2008-07-26 23:55:291055void ProfileImpl::CreateWebDataService() {
1056 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1057 created_web_data_service_ = true;
1058 scoped_refptr<WebDataService> wds(new WebDataService());
1059 if (!wds->Init(GetPath()))
1060 return;
1061 web_data_service_.swap(wds);
1062}
1063
[email protected]e69d33952009-06-03 22:00:411064PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1065 if (!created_password_store_)
1066 CreatePasswordStore();
1067 return password_store_.get();
1068}
1069
1070void ProfileImpl::CreatePasswordStore() {
1071 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1072 created_password_store_ = true;
1073 scoped_refptr<PasswordStore> ps;
1074#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251075 // TODO(evanm): implement "native" password management.
1076 // This bug describes the issues.
1077 // http://code.google.com/p/chromium/issues/detail?id=12351
1078 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1079 if (!ps->Init())
1080 return;
[email protected]e69d33952009-06-03 22:00:411081#elif defined(OS_WIN)
1082 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561083#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171084 FilePath login_db_file_path = GetPath();
1085 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1086 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1087 if (!login_db->Init(login_db_file_path)) {
1088 LOG(ERROR) << "Could not initialize login database.";
1089 delete login_db;
1090 return;
1091 }
1092 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411093#else
1094 NOTIMPLEMENTED();
1095#endif
1096 if (!ps || !ps->Init()) {
1097 // Try falling back to the default password manager
1098 LOG(WARNING) << "Could not initialise native password manager - "
1099 "falling back to default";
1100 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1101 if (!ps->Init())
1102 return;
1103 }
1104 password_store_.swap(ps);
1105}
1106
initial.commit09911bf2008-07-26 23:55:291107DownloadManager* ProfileImpl::GetDownloadManager() {
1108 if (!created_download_manager_) {
1109 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1110 dlm->Init(this);
1111 created_download_manager_ = true;
1112 download_manager_.swap(dlm);
1113 }
1114 return download_manager_.get();
1115}
1116
1117bool ProfileImpl::HasCreatedDownloadManager() const {
1118 return created_download_manager_;
1119}
1120
[email protected]def11712009-11-06 00:42:151121PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1122 if (!personal_data_manager_.get()) {
1123 personal_data_manager_.reset(new PersonalDataManager);
1124 }
1125 return personal_data_manager_.get();
1126}
1127
[email protected]4a190632009-05-09 01:07:421128void ProfileImpl::InitThemes() {
1129 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571130#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151131 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291132#else
[email protected]761962c2009-09-25 00:18:151133 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291134#endif
[email protected]761962c2009-09-25 00:18:151135 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421136 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421137 }
1138}
1139
1140void ProfileImpl::SetTheme(Extension* extension) {
1141 InitThemes();
1142 theme_provider_.get()->SetTheme(extension);
1143}
1144
[email protected]a5166af62009-07-03 00:42:291145void ProfileImpl::SetNativeTheme() {
1146 InitThemes();
1147 theme_provider_.get()->SetNativeTheme();
1148}
1149
[email protected]4a190632009-05-09 01:07:421150void ProfileImpl::ClearTheme() {
1151 InitThemes();
1152 theme_provider_.get()->UseDefaultTheme();
1153}
1154
[email protected]51c490b2009-08-03 16:34:341155Extension* ProfileImpl::GetTheme() {
1156 InitThemes();
1157
1158 std::string id = theme_provider_.get()->GetThemeID();
1159 if (id == BrowserThemeProvider::kDefaultThemeID)
1160 return NULL;
1161
[email protected]61b411612009-11-10 23:17:411162 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341163}
1164
[email protected]4a190632009-05-09 01:07:421165ThemeProvider* ProfileImpl::GetThemeProvider() {
1166 InitThemes();
1167 return theme_provider_.get();
1168}
1169
initial.commit09911bf2008-07-26 23:55:291170SessionService* ProfileImpl::GetSessionService() {
1171 if (!session_service_.get() && !shutdown_session_service_) {
1172 session_service_ = new SessionService(this);
1173 session_service_->ResetFromCurrentBrowsers();
1174 }
1175 return session_service_.get();
1176}
1177
1178void ProfileImpl::ShutdownSessionService() {
1179 if (shutdown_session_service_)
1180 return;
1181
1182 // We're about to exit, force creation of the session service if it hasn't
1183 // been created yet. We do this to ensure session state matches the point in
1184 // time the user exited.
1185 GetSessionService();
1186 shutdown_session_service_ = true;
1187 session_service_ = NULL;
1188}
1189
1190bool ProfileImpl::HasSessionService() const {
1191 return (session_service_.get() != NULL);
1192}
1193
1194std::wstring ProfileImpl::GetName() {
1195 return GetPrefs()->GetString(prefs::kProfileName);
1196}
1197void ProfileImpl::SetName(const std::wstring& name) {
1198 GetPrefs()->SetString(prefs::kProfileName, name);
1199}
1200
1201std::wstring ProfileImpl::GetID() {
1202 return GetPrefs()->GetString(prefs::kProfileID);
1203}
1204void ProfileImpl::SetID(const std::wstring& id) {
1205 GetPrefs()->SetString(prefs::kProfileID, id);
1206}
1207
initial.commit09911bf2008-07-26 23:55:291208bool ProfileImpl::DidLastSessionExitCleanly() {
1209 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1210 // it to be set by asking for the prefs.
1211 GetPrefs();
1212 return last_session_exited_cleanly_;
1213}
1214
[email protected]d8e41ed2008-09-11 15:22:321215BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461216 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321217 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461218 bookmark_bar_model_->Load();
1219 }
initial.commit09911bf2008-07-26 23:55:291220 return bookmark_bar_model_.get();
1221}
1222
1223bool ProfileImpl::IsSameProfile(Profile* profile) {
1224 if (profile == static_cast<Profile*>(this))
1225 return true;
1226 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1227 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1228}
1229
1230Time ProfileImpl::GetStartTime() const {
1231 return start_time_;
1232}
1233
1234TabRestoreService* ProfileImpl::GetTabRestoreService() {
1235 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191236 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291237 return tab_restore_service_.get();
1238}
1239
[email protected]449478302009-06-09 20:04:281240ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1241 if (!thumbnail_store_.get()) {
1242 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251243 thumbnail_store_->Init(
1244 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281245 }
1246 return thumbnail_store_.get();
1247}
1248
initial.commit09911bf2008-07-26 23:55:291249void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191250 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291251}
1252
[email protected]a9afddb2009-02-12 17:49:421253// To be run in the IO thread to notify all resource message filters that the
[email protected]20930852008-10-15 19:30:411254// spellchecker has changed.
1255class NotifySpellcheckerChangeTask : public Task {
1256 public:
1257 NotifySpellcheckerChangeTask(
[email protected]e7244d82008-10-29 18:13:261258 Profile* profile,
1259 const SpellcheckerReinitializedDetails& spellchecker)
[email protected]20930852008-10-15 19:30:411260 : profile_(profile),
1261 spellchecker_(spellchecker) {
1262 }
1263
1264 private:
1265 void Run(void) {
1266 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561267 NotificationType::SPELLCHECKER_REINITIALIZED,
[email protected]20930852008-10-15 19:30:411268 Source<Profile>(profile_),
1269 Details<SpellcheckerReinitializedDetails>(&spellchecker_));
1270 }
1271
1272 Profile* profile_;
1273 SpellcheckerReinitializedDetails spellchecker_;
1274};
1275
[email protected]e3448ea2009-10-02 01:29:291276void ProfileImpl::ReinitializeSpellChecker() {
[email protected]20930852008-10-15 19:30:411277 PrefService* prefs = GetPrefs();
[email protected]e3448ea2009-10-02 01:29:291278 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1279 DeleteSpellCheckerImpl(false);
[email protected]20930852008-10-15 19:30:411280
[email protected]e3448ea2009-10-02 01:29:291281 // Retrieve the (perhaps updated recently) dictionary name from preferences.
[email protected]bd17b702009-02-25 20:44:081282 FilePath dict_dir;
[email protected]e7244d82008-10-29 18:13:261283 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
[email protected]a9afddb2009-02-12 17:49:421284 // Note that, as the object pointed to by previously by spellchecker_
[email protected]e7244d82008-10-29 18:13:261285 // is being deleted in the io thread, the spellchecker_ can be made to point
1286 // to a new object (RE-initialized) in parallel in this UI thread.
[email protected]4b4d1adc2008-12-10 22:28:581287 spellchecker_ = new SpellChecker(dict_dir,
[email protected]74c8b422009-03-11 00:34:121288 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1289 GetRequestContext(),
[email protected]bd17b702009-02-25 20:44:081290 FilePath());
[email protected]e7244d82008-10-29 18:13:261291 spellchecker_->AddRef(); // Manual refcounting.
[email protected]20930852008-10-15 19:30:411292
[email protected]e3448ea2009-10-02 01:29:291293 // Set auto spell correct status for spellchecker.
[email protected]154a4332009-06-03 20:20:581294 spellchecker_->EnableAutoSpellCorrect(
1295 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
[email protected]154a4332009-06-03 20:20:581296
[email protected]e3448ea2009-10-02 01:29:291297 NotifySpellCheckerChanged();
1298 } else {
1299 DeleteSpellCheckerImpl(true);
[email protected]20930852008-10-15 19:30:411300 }
1301}
1302
[email protected]85c55dc2009-11-06 03:05:461303#if defined(SPELLCHECKER_IN_RENDERER)
1304SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1305 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1306}
1307
1308void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1309 // If we are already loading the spellchecker, and this is just a hint to
1310 // load the spellchecker, do nothing.
1311 if (!force && spellcheck_host_.get())
1312 return;
1313
[email protected]f41301e2009-11-16 21:30:071314 spellcheck_host_ready_ = false;
1315
[email protected]85c55dc2009-11-06 03:05:461316 bool notify = false;
1317 if (spellcheck_host_.get()) {
1318 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051319 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461320 notify = true;
1321 }
1322
1323 PrefService* prefs = GetPrefs();
1324 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1325 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1326 spellcheck_host_ = new SpellCheckHost(this,
1327 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1328 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071329 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461330 } else if (notify) {
1331 // The spellchecker has been disabled.
1332 SpellCheckHostInitialized();
1333 }
1334}
1335
1336void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171337 spellcheck_host_ready_ = spellcheck_host_ &&
1338 spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue;
[email protected]85c55dc2009-11-06 03:05:461339 NotificationService::current()->Notify(
1340 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1341 Source<Profile>(this), NotificationService::NoDetails());
1342}
1343#endif
1344
[email protected]e3448ea2009-10-02 01:29:291345void ProfileImpl::NotifySpellCheckerChanged() {
[email protected]6fad2632009-11-02 05:59:371346 SpellcheckerReinitializedDetails scoped_spellchecker;
1347 scoped_spellchecker.spellchecker = spellchecker_;
1348 ChromeThread::PostTask(
1349 ChromeThread::IO, FROM_HERE,
1350 new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
[email protected]e3448ea2009-10-02 01:29:291351}
1352
1353void ProfileImpl::DeleteSpellCheckerImpl(bool notify) {
[email protected]6fad2632009-11-02 05:59:371354 if (!spellchecker_)
1355 return;
[email protected]e3448ea2009-10-02 01:29:291356
[email protected]6fad2632009-11-02 05:59:371357 // The spellchecker must be deleted on the I/O thread.
1358 ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, spellchecker_);
1359 spellchecker_ = NULL;
[email protected]e3448ea2009-10-02 01:29:291360
[email protected]6fad2632009-11-02 05:59:371361 if (notify)
1362 NotifySpellCheckerChanged();
[email protected]e7244d82008-10-29 18:13:261363}
1364
initial.commit09911bf2008-07-26 23:55:291365SpellChecker* ProfileImpl::GetSpellChecker() {
1366 if (!spellchecker_) {
[email protected]20930852008-10-15 19:30:411367 // This is where spellchecker gets initialized. Note that this is being
1368 // initialized in the ui_thread. However, this is not a problem as long as
1369 // it is *used* in the io thread.
[email protected]34cc84f2009-02-13 10:04:351370 // TODO(sidchat): One day, change everything so that spellchecker gets
[email protected]20930852008-10-15 19:30:411371 // initialized in the IO thread itself.
[email protected]e3448ea2009-10-02 01:29:291372 ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:291373 }
[email protected]20930852008-10-15 19:30:411374
initial.commit09911bf2008-07-26 23:55:291375 return spellchecker_;
1376}
1377
[email protected]3bf335a2009-06-26 20:46:061378WebKitContext* ProfileImpl::GetWebKitContext() {
1379 if (!webkit_context_.get())
1380 webkit_context_ = new WebKitContext(path_, false);
1381 DCHECK(webkit_context_.get());
1382 return webkit_context_.get();
1383}
1384
[email protected]4bb336302009-10-12 05:44:261385DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1386 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1387 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261388 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031389 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261390 }
[email protected]4bb336302009-10-12 05:44:261391 return desktop_notification_service_.get();
1392}
1393
initial.commit09911bf2008-07-26 23:55:291394void ProfileImpl::MarkAsCleanShutdown() {
1395 if (prefs_.get()) {
1396 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1397 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1398
1399 // NOTE: If you change what thread this writes on, be sure and update
1400 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361401 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291402 }
1403}
1404
[email protected]e7244d82008-10-29 18:13:261405void ProfileImpl::Observe(NotificationType type,
1406 const NotificationSource& source,
1407 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561408 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261409 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1410 PrefService* prefs = Source<PrefService>(source).ptr();
1411 DCHECK(pref_name_in && prefs);
1412 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461413#if !defined(SPELLCHECKER_IN_RENDERER)
1414 *pref_name_in == prefs::kEnableAutoSpellCorrect ||
1415#endif
1416 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]e3448ea2009-10-02 01:29:291417 ReinitializeSpellChecker();
[email protected]85c55dc2009-11-06 03:05:461418#if defined(SPELLCHECKER_IN_RENDERER)
1419 ReinitializeSpellCheckHost(true);
1420#endif
[email protected]e7244d82008-10-29 18:13:261421 }
[email protected]4a190632009-05-09 01:07:421422 } else if (NotificationType::THEME_INSTALLED == type) {
1423 Extension* extension = Details<Extension>(details).ptr();
1424 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111425 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1426 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1427 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1428 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261429 }
1430}
1431
initial.commit09911bf2008-07-26 23:55:291432void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141433 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291434}
[email protected]3a453fa2008-08-15 18:46:341435
[email protected]48352c12009-08-15 01:19:111436ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431437 if (!ProfileSyncService::IsSyncEnabled()) {
1438 return NULL;
[email protected]7367f1a2009-10-10 01:09:441439 }
[email protected]eec3bcfa2009-11-12 17:23:431440 if (!sync_service_.get())
1441 InitSyncService();
1442 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111443}
1444
1445void ProfileImpl::InitSyncService() {
[email protected]48352c12009-08-15 01:19:111446 sync_service_.reset(new ProfileSyncService(this));
1447 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111448}