blob: dd2835eb2b0aeeded513f8de47023118c8fb0481 [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]2a0c0a52009-07-31 07:51:3261#include "net/ocsp/nss_ocsp.h"
[email protected]a5166af62009-07-03 00:42:2962#include "chrome/browser/gtk/gtk_theme_provider.h"
63#endif
64
[email protected]2627431b2009-09-15 20:21:5365#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:2966#include "chrome/browser/chromeos/preferences.h"
[email protected]2627431b2009-09-15 20:21:5367#endif
68
[email protected]e1acf6f2008-10-27 20:43:3369using base::Time;
70using base::TimeDelta;
71
[email protected]e5642992009-06-26 23:06:3172namespace {
73
initial.commit09911bf2008-07-26 23:55:2974// Delay, in milliseconds, before we explicitly create the SessionService.
75static const int kCreateSessionServiceDelayMS = 500;
76
[email protected]e5642992009-06-26 23:06:3177enum ContextType {
78 kNormalContext,
79 kMediaContext
80};
81
82// Gets the cache parameters from the command line. |type| is the type of
83// request context that we need, |cache_path| will be set to the user provided
84// path, or will not be touched if there is not an argument. |max_size| will
85// be the user provided value or zero by default.
86void GetCacheParameters(ContextType type, FilePath* cache_path,
87 int* max_size) {
88 DCHECK(cache_path);
89 DCHECK(max_size);
90
91 // Override the cache location if specified by the user.
92 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
93 switches::kDiskCacheDir));
94
95 if (!user_path.empty()) {
96 *cache_path = FilePath::FromWStringHack(user_path);
97 }
98
[email protected]b7e0a2a2009-10-13 02:07:2599 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
100 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31101 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25102 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31103
104 // By default we let the cache determine the right size.
105 *max_size = 0;
106 if (!StringToInt(value, max_size)) {
107 *max_size = 0;
108 } else if (max_size < 0) {
109 *max_size = 0;
110 }
111}
112
[email protected]405a64b2009-09-16 21:03:44113FilePath GetCachePath(const FilePath& base) {
114 return base.Append(chrome::kCacheDirname);
115}
116
117FilePath GetMediaCachePath(const FilePath& base) {
118 return base.Append(chrome::kMediaCacheDirname);
119}
120
121bool HasACacheSubdir(const FilePath &dir) {
122 return file_util::PathExists(GetCachePath(dir)) ||
123 file_util::PathExists(GetMediaCachePath(dir));
124}
125
[email protected]e5642992009-06-26 23:06:31126} // namespace
127
initial.commit09911bf2008-07-26 23:55:29128// A pointer to the request context for the default profile. See comments on
129// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31130URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29131
[email protected]be180c802009-10-23 06:33:31132static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]47accfd62009-05-14 18:46:21133 if (context) {
134 context->CleanupOnUIThread();
135
136 // Clean up request context on IO thread.
[email protected]6fad2632009-11-02 05:59:37137 ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, context);
[email protected]47accfd62009-05-14 18:46:21138 }
139}
140
[email protected]34cc84f2009-02-13 10:04:35141// static
[email protected]4bf6afd2009-10-08 14:00:11142const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
143
144// static
initial.commit09911bf2008-07-26 23:55:29145void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55146 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29147 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
148 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12149 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26150 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
151 IDS_SPELLCHECK_DICTIONARY);
152 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58153 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]f93fe782009-02-19 01:26:13154 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
[email protected]a5166af62009-07-03 00:42:29155#if defined(OS_LINUX)
156 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
157#endif
[email protected]51c490b2009-08-03 16:34:34158 prefs->RegisterStringPref(prefs::kCurrentThemeID,
159 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42160 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
161 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
162 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50163 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23164 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29165}
166
[email protected]34cc84f2009-02-13 10:04:35167// static
[email protected]f7011fcb2009-01-28 21:54:32168Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29169 return new ProfileImpl(path);
170}
171
[email protected]34cc84f2009-02-13 10:04:35172// static
[email protected]be180c802009-10-23 06:33:31173URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29174 return default_request_context_;
175}
176
[email protected]e69d33952009-06-03 22:00:41177#if defined(OS_LINUX)
178// Temporarily disabled while we figure some stuff out.
179// http://code.google.com/p/chromium/issues/detail?id=12351
180// #include "chrome/browser/password_manager/password_store_gnome.h"
181// #include "chrome/browser/password_manager/password_store_kwallet.h"
182#elif defined(OS_WIN)
183#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56184#elif defined(OS_MACOSX)
185#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17186#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56187#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41188#endif
initial.commit09911bf2008-07-26 23:55:29189
initial.commit09911bf2008-07-26 23:55:29190////////////////////////////////////////////////////////////////////////////////
191//
192// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42193// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29194//
195////////////////////////////////////////////////////////////////////////////////
196class OffTheRecordProfileImpl : public Profile,
197 public NotificationObserver {
198 public:
199 explicit OffTheRecordProfileImpl(Profile* real_profile)
200 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21201 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29202 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31203 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
initial.commit09911bf2008-07-26 23:55:29204 request_context_->AddRef();
[email protected]481e1a42009-05-06 20:56:05205
initial.commit09911bf2008-07-26 23:55:29206 // Register for browser close notifications so we can detect when the last
207 // off-the-record window is closed, in which case we can clean our states
208 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43209 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
210 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29211 }
212
213 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21214 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21215 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29216 }
217
[email protected]4bf6afd2009-10-08 14:00:11218 virtual ProfileId GetRuntimeId() {
219 return reinterpret_cast<ProfileId>(this);
220 }
221
[email protected]f7011fcb2009-01-28 21:54:32222 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29223
224 virtual bool IsOffTheRecord() {
225 return true;
226 }
227
228 virtual Profile* GetOffTheRecordProfile() {
229 return this;
230 }
231
[email protected]860f55492009-03-27 19:50:59232 virtual void DestroyOffTheRecordProfile() {
233 // Suicide is bad!
234 NOTREACHED();
235 }
236
initial.commit09911bf2008-07-26 23:55:29237 virtual Profile* GetOriginalProfile() {
238 return profile_;
239 }
240
[email protected]2f351cb2009-11-09 23:43:34241 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
242 if (!db_tracker_)
243 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
244 return db_tracker_;
245 }
246
initial.commit09911bf2008-07-26 23:55:29247 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49248 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
249 // because we don't want to leak the sites that the user has visited before.
250 return NULL;
initial.commit09911bf2008-07-26 23:55:29251 }
252
[email protected]6014d672008-12-05 00:38:25253 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34254 return NULL;
[email protected]6014d672008-12-05 00:38:25255 }
256
[email protected]0938d3c2009-01-09 20:37:35257 virtual UserScriptMaster* GetUserScriptMaster() {
258 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25259 }
260
[email protected]89ebc7e2009-08-24 22:11:07261 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
262 return NULL;
263 }
264
[email protected]481e1a42009-05-06 20:56:05265 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34266 return NULL;
[email protected]481e1a42009-05-06 20:56:05267 }
268
[email protected]7120f132009-07-20 21:05:37269 virtual ExtensionMessageService* GetExtensionMessageService() {
270 return NULL;
271 }
272
[email protected]34cc84f2009-02-13 10:04:35273 virtual SSLHostState* GetSSLHostState() {
274 if (!ssl_host_state_.get())
275 ssl_host_state_.reset(new SSLHostState());
276
277 DCHECK(ssl_host_state_->CalledOnValidThread());
278 return ssl_host_state_.get();
279 }
280
[email protected]77f6fb432009-09-05 14:21:09281 virtual net::StrictTransportSecurityState* GetStrictTransportSecurityState() {
282 if (!strict_transport_security_state_.get()) {
283 strict_transport_security_state_ =
284 new net::StrictTransportSecurityState();
285 }
[email protected]a9cea7542009-05-20 04:30:23286
[email protected]77f6fb432009-09-05 14:21:09287 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23288 }
289
initial.commit09911bf2008-07-26 23:55:29290 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
291 if (sat == EXPLICIT_ACCESS) {
292 return profile_->GetHistoryService(sat);
293 } else {
294 NOTREACHED() << "This profile is OffTheRecord";
295 return NULL;
296 }
297 }
298
[email protected]0850fa62009-10-08 22:34:29299 virtual HistoryService* GetHistoryServiceWithoutCreating() {
300 return profile_->GetHistoryServiceWithoutCreating();
301 }
302
[email protected]0189bc722009-08-28 21:56:48303 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
304 if (sat == EXPLICIT_ACCESS) {
305 return profile_->GetFaviconService(sat);
306 } else {
307 NOTREACHED() << "This profile is OffTheRecord";
308 return NULL;
309 }
310 }
311
[email protected]90085af02009-10-29 17:53:21312 virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
313 return profile_->GetSearchVersusNavigateClassifier();
314 }
315
initial.commit09911bf2008-07-26 23:55:29316 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
317 if (sat == EXPLICIT_ACCESS) {
318 return profile_->GetWebDataService(sat);
319 } else {
320 NOTREACHED() << "This profile is OffTheRecord";
321 return NULL;
322 }
323 }
324
[email protected]9cddbe372009-10-23 21:23:53325 virtual WebDataService* GetWebDataServiceWithoutCreating() {
326 return profile_->GetWebDataServiceWithoutCreating();
327 }
328
[email protected]e69d33952009-06-03 22:00:41329 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
330 if (sat == EXPLICIT_ACCESS) {
331 return profile_->GetPasswordStore(sat);
332 } else {
333 NOTREACHED() << "This profile is OffTheRecord";
334 return NULL;
335 }
336 }
337
initial.commit09911bf2008-07-26 23:55:29338 virtual PrefService* GetPrefs() {
339 return profile_->GetPrefs();
340 }
341
342 virtual TemplateURLModel* GetTemplateURLModel() {
343 return profile_->GetTemplateURLModel();
344 }
345
346 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
347 return profile_->GetTemplateURLFetcher();
348 }
349
350 virtual DownloadManager* GetDownloadManager() {
351 if (!download_manager_.get()) {
352 scoped_refptr<DownloadManager> dlm(new DownloadManager);
353 dlm->Init(this);
354 download_manager_.swap(dlm);
355 }
356 return download_manager_.get();
357 }
358
359 virtual bool HasCreatedDownloadManager() const {
360 return (download_manager_.get() != NULL);
361 }
362
[email protected]def11712009-11-06 00:42:15363 virtual PersonalDataManager* GetPersonalDataManager() {
364 return NULL;
365 }
366
[email protected]4a190632009-05-09 01:07:42367 virtual void InitThemes() {
368 GetOriginalProfile()->InitThemes();
369 }
370
371 virtual void SetTheme(Extension* extension) {
372 GetOriginalProfile()->SetTheme(extension);
373 }
374
[email protected]a5166af62009-07-03 00:42:29375 virtual void SetNativeTheme() {
376 GetOriginalProfile()->SetNativeTheme();
377 }
378
[email protected]4a190632009-05-09 01:07:42379 virtual void ClearTheme() {
380 GetOriginalProfile()->ClearTheme();
381 }
382
[email protected]51c490b2009-08-03 16:34:34383 virtual Extension* GetTheme() {
384 return GetOriginalProfile()->GetTheme();
385 }
386
[email protected]4a190632009-05-09 01:07:42387 virtual ThemeProvider* GetThemeProvider() {
388 return GetOriginalProfile()->GetThemeProvider();
389 }
390
[email protected]be180c802009-10-23 06:33:31391 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29392 return request_context_;
393 }
394
[email protected]be180c802009-10-23 06:33:31395 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11396 // In OTR mode, media request context is the same as the original one.
397 return request_context_;
[email protected]e7f29642009-03-02 22:53:18398 }
399
[email protected]be180c802009-10-23 06:33:31400 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21401 if (!extensions_request_context_) {
402 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31403 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this);
[email protected]47accfd62009-05-14 18:46:21404 extensions_request_context_->AddRef();
[email protected]47accfd62009-05-14 18:46:21405 }
406
407 return extensions_request_context_;
408 }
409
[email protected]db36938c2009-08-19 21:48:42410 virtual net::SSLConfigService* GetSSLConfigService() {
411 return GetOriginalProfile()->GetSSLConfigService();
412 }
413
[email protected]eaadd9052009-06-23 18:02:23414 virtual Blacklist* GetBlacklist() {
415 return GetOriginalProfile()->GetBlacklist();
416 }
417
initial.commit09911bf2008-07-26 23:55:29418 virtual SessionService* GetSessionService() {
419 // Don't save any sessions when off the record.
420 return NULL;
421 }
422
423 virtual void ShutdownSessionService() {
424 // We don't allow a session service, nothing to do.
425 }
426
427 virtual bool HasSessionService() const {
428 // We never have a session service.
429 return false;
430 }
431
432 virtual std::wstring GetName() {
433 return profile_->GetName();
434 }
435
436 virtual void SetName(const std::wstring& name) {
437 profile_->SetName(name);
438 }
439
440 virtual std::wstring GetID() {
441 return profile_->GetID();
442 }
443
444 virtual void SetID(const std::wstring& id) {
445 profile_->SetID(id);
446 }
447
initial.commit09911bf2008-07-26 23:55:29448 virtual bool DidLastSessionExitCleanly() {
449 return profile_->DidLastSessionExitCleanly();
450 }
451
[email protected]d8e41ed2008-09-11 15:22:32452 virtual BookmarkModel* GetBookmarkModel() {
453 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29454 }
455
[email protected]4bb336302009-10-12 05:44:26456 virtual DesktopNotificationService* GetDesktopNotificationService() {
457 return profile_->GetDesktopNotificationService();
458 }
459
[email protected]48352c12009-08-15 01:19:11460 virtual ProfileSyncService* GetProfileSyncService() {
461 return NULL;
[email protected]3a453fa2008-08-15 18:46:34462 }
[email protected]3a453fa2008-08-15 18:46:34463
initial.commit09911bf2008-07-26 23:55:29464 virtual bool IsSameProfile(Profile* profile) {
465 if (profile == static_cast<Profile*>(this))
466 return true;
467 return profile == profile_;
468 }
469
470 virtual Time GetStartTime() const {
471 return start_time_;
472 }
473
474 virtual TabRestoreService* GetTabRestoreService() {
475 return NULL;
476 }
477
[email protected]e7244d82008-10-29 18:13:26478 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41479 }
480
[email protected]e7244d82008-10-29 18:13:26481 virtual void ReinitializeSpellChecker() {
482 profile_->ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:29483 }
484
485 virtual SpellChecker* GetSpellChecker() {
486 return profile_->GetSpellChecker();
487 }
488
[email protected]e3448ea2009-10-02 01:29:29489 virtual void DeleteSpellChecker() {
490 profile_->DeleteSpellChecker();
491 }
492
[email protected]85c55dc2009-11-06 03:05:46493#if defined(SPELLCHECKER_IN_RENDERER)
494 virtual SpellCheckHost* GetSpellCheckHost() {
495 return profile_->GetSpellCheckHost();
496 }
497
498 virtual void ReinitializeSpellCheckHost(bool force) {
499 profile_->ReinitializeSpellCheckHost(force);
500 }
501#endif
502
[email protected]3bf335a2009-06-26 20:46:06503 virtual WebKitContext* GetWebKitContext() {
504 if (!webkit_context_.get())
505 webkit_context_ = new WebKitContext(GetPath(), true);
506 DCHECK(webkit_context_.get());
507 return webkit_context_.get();
508}
509
[email protected]449478302009-06-09 20:04:28510 virtual ThumbnailStore* GetThumbnailStore() {
511 return NULL;
512 }
513
initial.commit09911bf2008-07-26 23:55:29514 virtual void MarkAsCleanShutdown() {
515 }
516
[email protected]bdbc87c2009-01-25 05:08:54517 virtual void InitExtensions() {
518 NOTREACHED();
519 }
520
[email protected]ea0c98cf2009-06-18 23:02:54521 virtual void InitWebResources() {
522 NOTREACHED();
523 }
524
initial.commit09911bf2008-07-26 23:55:29525 virtual void ExitedOffTheRecordMode() {
526 // Drop our download manager so we forget about all the downloads made
527 // in off-the-record mode.
528 download_manager_ = NULL;
529 }
530
531 virtual void Observe(NotificationType type,
532 const NotificationSource& source,
533 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56534 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29535 // We are only interested in OTR browser closing.
536 if (Source<Browser>(source)->profile() != this)
537 return;
538
539 // Let's check if we still have an Off The Record window opened.
540 // Note that we check against 1 as this notification is sent before the
541 // browser window is actually removed from the list.
542 if (BrowserList::GetBrowserCount(this) <= 1)
543 ExitedOffTheRecordMode();
544 }
545
546 private:
[email protected]88cf3292009-05-22 01:48:43547 NotificationRegistrar registrar_;
548
initial.commit09911bf2008-07-26 23:55:29549 // The real underlying profile.
550 Profile* profile_;
551
[email protected]6ab9b202008-12-23 22:34:50552 // The context to use for requests made from this OTR session.
[email protected]be180c802009-10-23 06:33:31553 ChromeURLRequestContextGetter* request_context_;
initial.commit09911bf2008-07-26 23:55:29554
[email protected]be180c802009-10-23 06:33:31555 ChromeURLRequestContextGetter* extensions_request_context_;
[email protected]23f1ef12009-09-01 22:30:30556
initial.commit09911bf2008-07-26 23:55:29557 // The download manager that only stores downloaded items in memory.
558 scoped_refptr<DownloadManager> download_manager_;
559
[email protected]3bf335a2009-06-26 20:46:06560 // Use a special WebKit context for OTR browsing.
561 scoped_refptr<WebKitContext> webkit_context_;
562
[email protected]34cc84f2009-02-13 10:04:35563 // We don't want SSLHostState from the OTR profile to leak back to the main
564 // profile because then the main profile would learn some of the host names
565 // the user visited while OTR.
566 scoped_ptr<SSLHostState> ssl_host_state_;
567
[email protected]77f6fb432009-09-05 14:21:09568 // The StrictTransportSecurityState that only stores enabled sites in memory.
569 scoped_refptr<net::StrictTransportSecurityState>
570 strict_transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23571
initial.commit09911bf2008-07-26 23:55:29572 // Time we were started.
573 Time start_time_;
574
[email protected]2f351cb2009-11-09 23:43:34575 // The main database tracker for this profile.
576 // Should be used only on the file thread.
577 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
578
[email protected]90085af02009-10-29 17:53:21579 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29580};
581
[email protected]f7011fcb2009-01-28 21:54:32582ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29583 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39584 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07585 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32586 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57587 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21588 extensions_request_context_(NULL),
[email protected]eaadd9052009-06-23 18:02:23589 blacklist_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32590 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48591 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32592 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41593 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32594 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42595 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32596 start_time_(Time::Now()),
597 spellchecker_(NULL),
[email protected]85c55dc2009-11-06 03:05:46598#if defined(OS_LINUX)
599 spellcheck_host_(NULL),
600 spellcheck_host_ready_(false),
601#endif
initial.commit09911bf2008-07-26 23:55:29602 shutdown_session_service_(false) {
603 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
604 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14605 create_session_service_timer_.Start(
606 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
607 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54608
[email protected]89ebc7e2009-08-24 22:11:07609 if (CommandLine::ForCurrentProcess()->HasSwitch(
610 switches::kEnableExtensionTimelineApi)) {
611 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
612 }
613
[email protected]382a0702009-06-26 17:12:27614 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37615 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27616
[email protected]e7244d82008-10-29 18:13:26617 PrefService* prefs = GetPrefs();
618 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
619 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58620 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58621
[email protected]eaadd9052009-06-23 18:02:23622 if (CommandLine::ForCurrentProcess()->
623 HasSwitch(switches::kPrivacyBlacklist)) {
624 std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue(
625 switches::kPrivacyBlacklist);
626#if defined(OS_POSIX)
627 FilePath path(WideToUTF8(option));
628#else
629 FilePath path(option);
630#endif
[email protected]588074f2009-10-29 09:40:10631 blacklist_.reset(new Blacklist);
632 // TODO(phajdan.jr): Handle errors when reading blacklist.
633 BlacklistIO::ReadBinary(blacklist_.get(), path);
[email protected]eaadd9052009-06-23 18:02:23634 }
635
[email protected]405a64b2009-09-16 21:03:44636#if defined(OS_MACOSX)
637 // If the profile directory doesn't already have a cache directory and it
638 // is under ~/Library/Application Support, use a suitable cache directory
639 // under ~/Library/Caches. For example, a profile directory of
640 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
641 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
642 // ~/Library/Caches/Google/Chrome/MyProfileName.
643 //
644 // TODO(akalin): Come up with unit tests for this.
645 // TODO(akalin): Use for Linux, too?
646 if (!HasACacheSubdir(path_)) {
647 FilePath app_data_path, user_cache_path;
648 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
649 PathService::Get(base::DIR_CACHE, &user_cache_path) &&
650 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
651 base_cache_path_ = user_cache_path;
652 }
653 }
654#else
[email protected]bc96d562009-08-11 18:45:13655 if (!PathService::IsOverridden(chrome::DIR_USER_DATA))
656 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_);
[email protected]405a64b2009-09-16 21:03:44657#endif
[email protected]bc96d562009-08-11 18:45:13658 if (base_cache_path_.empty())
659 base_cache_path_ = path_;
660
[email protected]4a190632009-05-09 01:07:42661 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43662 registrar_.Add(this, NotificationType::THEME_INSTALLED,
663 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11664
665 // Listen for bookmark model load, to bootstrap the sync service.
666 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
667 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42668
669 ssl_config_service_manager_.reset(
670 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53671
672#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29673 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53674#endif
initial.commit09911bf2008-07-26 23:55:29675}
676
[email protected]bdbc87c2009-01-25 05:08:54677void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41678 if (user_script_master_ || extensions_service_)
679 return; // Already initialized.
680
[email protected]bdbc87c2009-01-25 05:08:54681 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]f93fe782009-02-19 01:26:13682 PrefService* prefs = GetPrefs();
[email protected]bdbc87c2009-01-25 05:08:54683 bool user_scripts_enabled =
[email protected]f0a51fb52009-03-05 12:46:38684 command_line->HasSwitch(switches::kEnableUserScripts) ||
[email protected]f93fe782009-02-19 01:26:13685 prefs->GetBoolean(prefs::kEnableUserScripts);
[email protected]bdbc87c2009-01-25 05:08:54686
[email protected]f7011fcb2009-01-28 21:54:32687 FilePath script_dir;
[email protected]bdbc87c2009-01-25 05:08:54688 if (user_scripts_enabled) {
[email protected]0cd957b2009-03-06 20:13:23689 if (command_line->HasSwitch(switches::kUserScriptsDir)) {
690 std::wstring path_string =
691 command_line->GetSwitchValue(switches::kUserScriptsDir);
692 script_dir = FilePath::FromWStringHack(path_string);
693 } else {
694 script_dir = GetPath();
695 script_dir = script_dir.Append(chrome::kUserScriptsDirname);
696 }
[email protected]bdbc87c2009-01-25 05:08:54697 }
698
[email protected]bb28e062009-02-27 17:19:18699 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]95d29192009-10-30 01:49:06700 user_script_master_ = new UserScriptMaster(script_dir);
[email protected]894bb502009-05-21 22:39:57701 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23702 this,
703 CommandLine::ForCurrentProcess(),
704 GetPrefs(),
705 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36706 true);
[email protected]bdbc87c2009-01-25 05:08:54707
[email protected]9197f3b2009-06-02 00:49:27708 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12709
710 // Load any extensions specified with --load-extension.
711 if (command_line->HasSwitch(switches::kLoadExtension)) {
712 std::wstring path_string =
713 command_line->GetSwitchValue(switches::kLoadExtension);
714 FilePath path = FilePath::FromWStringHack(path_string);
715 extensions_service_->LoadExtension(path);
716
717 // Tell UserScriptMaser to watch this extension's directory for changes so
718 // you can live edit content scripts during development.
719 user_script_master_->AddWatchedPath(path);
720 }
[email protected]bdbc87c2009-01-25 05:08:54721}
722
[email protected]ea0c98cf2009-06-18 23:02:54723void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07724 if (web_resource_service_)
725 return; // Already initialized.
726
[email protected]6fad2632009-11-02 05:59:37727 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54728 web_resource_service_->StartAfterDelay();
729}
730
initial.commit09911bf2008-07-26 23:55:29731ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19732 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29733
734 StopCreateSessionServiceTimer();
735 // TemplateURLModel schedules a task on the WebDataService from its
736 // destructor. Delete it first to ensure the task gets scheduled before we
737 // shut down the database.
738 template_url_model_.reset();
739
740 // The download manager queries the history system and should be deleted
741 // before the history is shutdown so it can properly cancel all requests.
742 download_manager_ = NULL;
743
[email protected]4a190632009-05-09 01:07:42744 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15745 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42746
[email protected]44961292009-07-20 20:03:09747 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
748 // save any new thumbnails to disk and release its reference to the
749 // HistoryService.
750 if (thumbnail_store_.get())
751 thumbnail_store_->Shutdown();
752
[email protected]e7244d82008-10-29 18:13:26753 // Remove pref observers.
754 PrefService* prefs = GetPrefs();
755 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
756 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58757 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26758
[email protected]48352c12009-08-15 01:19:11759 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34760
initial.commit09911bf2008-07-26 23:55:29761 // Both HistoryService and WebDataService maintain threads for background
762 // processing. Its possible each thread still has tasks on it that have
763 // increased the ref count of the service. In such a situation, when we
764 // decrement the refcount, it won't be 0, and the threads/databases aren't
765 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
766 // databases are properly closed.
767 if (web_data_service_.get())
768 web_data_service_->Shutdown();
769
770 if (history_service_.get())
771 history_service_->Cleanup();
772
[email protected]85c55dc2009-11-06 03:05:46773#if defined(SPELLCHECKER_IN_RENDERER)
774 if (spellcheck_host_.get())
775 spellcheck_host_->UnsetObserver();
776#endif
[email protected]e3448ea2009-10-02 01:29:29777 DeleteSpellCheckerImpl(false);
initial.commit09911bf2008-07-26 23:55:29778
[email protected]2a0c0a52009-07-31 07:51:32779 if (default_request_context_ == request_context_) {
780#if defined(OS_LINUX)
781 // We use default_request_context_ for OCSP.
782 // Release URLRequestContext used in OCSP handlers.
783 net::SetURLRequestContextForOCSP(NULL);
784#endif
[email protected]47accfd62009-05-14 18:46:21785 default_request_context_ = NULL;
[email protected]2a0c0a52009-07-31 07:51:32786 }
[email protected]6ab9b202008-12-23 22:34:50787
[email protected]47accfd62009-05-14 18:46:21788 CleanupRequestContext(request_context_);
789 CleanupRequestContext(media_request_context_);
790 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17791
[email protected]eaadd9052009-06-23 18:02:23792 // When the request contexts are gone, the blacklist wont be needed anymore.
[email protected]588074f2009-10-29 09:40:10793 blacklist_.reset();
[email protected]eaadd9052009-06-23 18:02:23794
[email protected]d8e41ed2008-09-11 15:22:32795 // HistoryService may call into the BookmarkModel, as such we need to
796 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46797 // HistoryService will join with HistoryService's backend thread so that
798 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32799 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46800 history_service_ = NULL;
801 bookmark_bar_model_.reset();
802
[email protected]0189bc722009-08-28 21:56:48803 // FaviconService depends on HistoryServce so make sure we delete
804 // HistoryService first.
805 favicon_service_ = NULL;
806
[email protected]7120f132009-07-20 21:05:37807 extension_message_service_->ProfileDestroyed();
808
[email protected]6ef635e42009-07-26 06:16:12809 if (extensions_service_)
810 extensions_service_->ProfileDestroyed();
811
[email protected]66da08b2009-10-19 22:27:00812 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29813 MarkAsCleanShutdown();
814}
815
[email protected]4bf6afd2009-10-08 14:00:11816ProfileId ProfileImpl::GetRuntimeId() {
817 return reinterpret_cast<ProfileId>(this);
818}
819
[email protected]f7011fcb2009-01-28 21:54:32820FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29821 return path_;
822}
823
824bool ProfileImpl::IsOffTheRecord() {
825 return false;
826}
827
828Profile* ProfileImpl::GetOffTheRecordProfile() {
829 if (!off_the_record_profile_.get()) {
830 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
831 off_the_record_profile_.swap(p);
832 }
833 return off_the_record_profile_.get();
834}
835
[email protected]860f55492009-03-27 19:50:59836void ProfileImpl::DestroyOffTheRecordProfile() {
837 off_the_record_profile_.reset();
838}
839
initial.commit09911bf2008-07-26 23:55:29840Profile* ProfileImpl::GetOriginalProfile() {
841 return this;
842}
843
[email protected]2f351cb2009-11-09 23:43:34844webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
845 if (!db_tracker_)
846 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
847 return db_tracker_;
848}
849
initial.commit09911bf2008-07-26 23:55:29850VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
851 if (!visited_link_master_.get()) {
852 scoped_ptr<VisitedLinkMaster> visited_links(
[email protected]6fad2632009-11-02 05:59:37853 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29854 if (!visited_links->Init())
855 return NULL;
856 visited_link_master_.swap(visited_links);
857 }
858
859 return visited_link_master_.get();
860}
861
[email protected]6014d672008-12-05 00:38:25862ExtensionsService* ProfileImpl::GetExtensionsService() {
863 return extensions_service_.get();
864}
865
[email protected]0938d3c2009-01-09 20:37:35866UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35867 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25868}
869
[email protected]89ebc7e2009-08-24 22:11:07870ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
871 return extension_devtools_manager_.get();
872}
873
[email protected]481e1a42009-05-06 20:56:05874ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27875 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05876}
877
[email protected]7120f132009-07-20 21:05:37878ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
879 return extension_message_service_.get();
880}
881
[email protected]34cc84f2009-02-13 10:04:35882SSLHostState* ProfileImpl::GetSSLHostState() {
883 if (!ssl_host_state_.get())
884 ssl_host_state_.reset(new SSLHostState());
885
886 DCHECK(ssl_host_state_->CalledOnValidThread());
887 return ssl_host_state_.get();
888}
889
[email protected]77f6fb432009-09-05 14:21:09890net::StrictTransportSecurityState*
891 ProfileImpl::GetStrictTransportSecurityState() {
892 if (!strict_transport_security_state_.get()) {
893 strict_transport_security_state_ = new net::StrictTransportSecurityState();
894 strict_transport_security_persister_ = new StrictTransportSecurityPersister(
[email protected]6fad2632009-11-02 05:59:37895 strict_transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51896 }
[email protected]a9cea7542009-05-20 04:30:23897
[email protected]77f6fb432009-09-05 14:21:09898 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23899}
900
initial.commit09911bf2008-07-26 23:55:29901PrefService* ProfileImpl::GetPrefs() {
902 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37903 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29904
905 // The Profile class and ProfileManager class may read some prefs so
906 // register known prefs as soon as possible.
907 Profile::RegisterUserPrefs(prefs_.get());
908 ProfileManager::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53909#if defined(OS_CHROMEOS)
910 // Register Touchpad prefs here instead of in browser_prefs because these
911 // prefs are used in the constructor of ProfileImpl which happens before
912 // browser_prefs' RegisterAllPrefs is called.
[email protected]fecc1522009-10-15 21:08:29913 chromeos::Preferences::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53914#endif
initial.commit09911bf2008-07-26 23:55:29915
916 // The last session exited cleanly if there is no pref for
917 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
918 last_session_exited_cleanly_ =
919 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
920 // Mark the session as open.
921 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
922 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36923 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29924 }
925
926 return prefs_.get();
927}
928
[email protected]f7011fcb2009-01-28 21:54:32929FilePath ProfileImpl::GetPrefFilePath() {
930 FilePath pref_file_path = path_;
931 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29932 return pref_file_path;
933}
934
[email protected]be180c802009-10-23 06:33:31935URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29936 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32937 FilePath cookie_path = GetPath();
938 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13939 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31940 int max_size;
941 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42942
[email protected]405a64b2009-09-16 21:03:44943 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31944 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
945 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29946 request_context_->AddRef();
947
[email protected]6ab9b202008-12-23 22:34:50948 // The first request context is always a normal (non-OTR) request context.
949 // Even when Chromium is started in OTR mode, a normal profile is always
950 // created first.
951 if (!default_request_context_) {
952 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31953 // TODO(eroman): this isn't terribly useful anymore now that the
954 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50955 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56956 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50957 NotificationService::AllSources(), NotificationService::NoDetails());
958 }
initial.commit09911bf2008-07-26 23:55:29959 }
960
961 return request_context_;
962}
963
[email protected]be180c802009-10-23 06:33:31964URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18965 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13966 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31967 int max_size;
968 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14969
[email protected]405a64b2009-09-16 21:03:44970 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31971 media_request_context_ =
972 ChromeURLRequestContextGetter::CreateOriginalForMedia(
973 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18974 media_request_context_->AddRef();
[email protected]e7f29642009-03-02 22:53:18975 }
976
977 return media_request_context_;
978}
979
[email protected]0189bc722009-08-28 21:56:48980FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
981 if (!favicon_service_created_) {
982 favicon_service_created_ = true;
983 scoped_refptr<FaviconService> service(new FaviconService(this));
984 favicon_service_.swap(service);
985 }
986 return favicon_service_.get();
987}
988
[email protected]be180c802009-10-23 06:33:31989URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21990 if (!extensions_request_context_) {
991 FilePath cookie_path = GetPath();
992 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
993
994 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31995 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
996 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21997 extensions_request_context_->AddRef();
[email protected]47accfd62009-05-14 18:46:21998 }
999
1000 return extensions_request_context_;
1001}
1002
[email protected]db36938c2009-08-19 21:48:421003net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1004 return ssl_config_service_manager_->Get();
1005}
1006
[email protected]eaadd9052009-06-23 18:02:231007Blacklist* ProfileImpl::GetBlacklist() {
[email protected]588074f2009-10-29 09:40:101008 return blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231009}
1010
initial.commit09911bf2008-07-26 23:55:291011HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1012 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461013 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291014 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321015 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291016 return NULL;
1017 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291018
1019 // Send out the notification that the history service was created.
1020 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561021 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291022 Details<HistoryService>(history_service_.get()));
1023 }
1024 return history_service_.get();
1025}
1026
[email protected]0850fa62009-10-08 22:34:291027HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1028 return history_service_.get();
1029}
1030
initial.commit09911bf2008-07-26 23:55:291031TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1032 if (!template_url_model_.get())
1033 template_url_model_.reset(new TemplateURLModel(this));
1034 return template_url_model_.get();
1035}
1036
1037TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1038 if (!template_url_fetcher_.get())
1039 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1040 return template_url_fetcher_.get();
1041}
1042
[email protected]90085af02009-10-29 17:53:211043SearchVersusNavigateClassifier* ProfileImpl::GetSearchVersusNavigateClassifier()
1044{
1045 if (!search_versus_navigate_classifier_.get()) {
1046 search_versus_navigate_classifier_.reset(
1047 new SearchVersusNavigateClassifier(this));
1048 }
1049 return search_versus_navigate_classifier_.get();
1050}
1051
initial.commit09911bf2008-07-26 23:55:291052WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1053 if (!created_web_data_service_)
1054 CreateWebDataService();
1055 return web_data_service_.get();
1056}
1057
[email protected]9cddbe372009-10-23 21:23:531058WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1059 return web_data_service_.get();
1060}
1061
initial.commit09911bf2008-07-26 23:55:291062void ProfileImpl::CreateWebDataService() {
1063 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1064 created_web_data_service_ = true;
1065 scoped_refptr<WebDataService> wds(new WebDataService());
1066 if (!wds->Init(GetPath()))
1067 return;
1068 web_data_service_.swap(wds);
1069}
1070
[email protected]e69d33952009-06-03 22:00:411071PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1072 if (!created_password_store_)
1073 CreatePasswordStore();
1074 return password_store_.get();
1075}
1076
1077void ProfileImpl::CreatePasswordStore() {
1078 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1079 created_password_store_ = true;
1080 scoped_refptr<PasswordStore> ps;
1081#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251082 // TODO(evanm): implement "native" password management.
1083 // This bug describes the issues.
1084 // http://code.google.com/p/chromium/issues/detail?id=12351
1085 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1086 if (!ps->Init())
1087 return;
[email protected]e69d33952009-06-03 22:00:411088#elif defined(OS_WIN)
1089 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561090#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171091 FilePath login_db_file_path = GetPath();
1092 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1093 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1094 if (!login_db->Init(login_db_file_path)) {
1095 LOG(ERROR) << "Could not initialize login database.";
1096 delete login_db;
1097 return;
1098 }
1099 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411100#else
1101 NOTIMPLEMENTED();
1102#endif
1103 if (!ps || !ps->Init()) {
1104 // Try falling back to the default password manager
1105 LOG(WARNING) << "Could not initialise native password manager - "
1106 "falling back to default";
1107 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1108 if (!ps->Init())
1109 return;
1110 }
1111 password_store_.swap(ps);
1112}
1113
initial.commit09911bf2008-07-26 23:55:291114DownloadManager* ProfileImpl::GetDownloadManager() {
1115 if (!created_download_manager_) {
1116 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1117 dlm->Init(this);
1118 created_download_manager_ = true;
1119 download_manager_.swap(dlm);
1120 }
1121 return download_manager_.get();
1122}
1123
1124bool ProfileImpl::HasCreatedDownloadManager() const {
1125 return created_download_manager_;
1126}
1127
[email protected]def11712009-11-06 00:42:151128PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1129 if (!personal_data_manager_.get()) {
1130 personal_data_manager_.reset(new PersonalDataManager);
1131 }
1132 return personal_data_manager_.get();
1133}
1134
[email protected]4a190632009-05-09 01:07:421135void ProfileImpl::InitThemes() {
1136 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571137#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151138 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291139#else
[email protected]761962c2009-09-25 00:18:151140 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291141#endif
[email protected]761962c2009-09-25 00:18:151142 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421143 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421144 }
1145}
1146
1147void ProfileImpl::SetTheme(Extension* extension) {
1148 InitThemes();
1149 theme_provider_.get()->SetTheme(extension);
1150}
1151
[email protected]a5166af62009-07-03 00:42:291152void ProfileImpl::SetNativeTheme() {
1153 InitThemes();
1154 theme_provider_.get()->SetNativeTheme();
1155}
1156
[email protected]4a190632009-05-09 01:07:421157void ProfileImpl::ClearTheme() {
1158 InitThemes();
1159 theme_provider_.get()->UseDefaultTheme();
1160}
1161
[email protected]51c490b2009-08-03 16:34:341162Extension* ProfileImpl::GetTheme() {
1163 InitThemes();
1164
1165 std::string id = theme_provider_.get()->GetThemeID();
1166 if (id == BrowserThemeProvider::kDefaultThemeID)
1167 return NULL;
1168
[email protected]61b411612009-11-10 23:17:411169 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341170}
1171
[email protected]4a190632009-05-09 01:07:421172ThemeProvider* ProfileImpl::GetThemeProvider() {
1173 InitThemes();
1174 return theme_provider_.get();
1175}
1176
initial.commit09911bf2008-07-26 23:55:291177SessionService* ProfileImpl::GetSessionService() {
1178 if (!session_service_.get() && !shutdown_session_service_) {
1179 session_service_ = new SessionService(this);
1180 session_service_->ResetFromCurrentBrowsers();
1181 }
1182 return session_service_.get();
1183}
1184
1185void ProfileImpl::ShutdownSessionService() {
1186 if (shutdown_session_service_)
1187 return;
1188
1189 // We're about to exit, force creation of the session service if it hasn't
1190 // been created yet. We do this to ensure session state matches the point in
1191 // time the user exited.
1192 GetSessionService();
1193 shutdown_session_service_ = true;
1194 session_service_ = NULL;
1195}
1196
1197bool ProfileImpl::HasSessionService() const {
1198 return (session_service_.get() != NULL);
1199}
1200
1201std::wstring ProfileImpl::GetName() {
1202 return GetPrefs()->GetString(prefs::kProfileName);
1203}
1204void ProfileImpl::SetName(const std::wstring& name) {
1205 GetPrefs()->SetString(prefs::kProfileName, name);
1206}
1207
1208std::wstring ProfileImpl::GetID() {
1209 return GetPrefs()->GetString(prefs::kProfileID);
1210}
1211void ProfileImpl::SetID(const std::wstring& id) {
1212 GetPrefs()->SetString(prefs::kProfileID, id);
1213}
1214
initial.commit09911bf2008-07-26 23:55:291215bool ProfileImpl::DidLastSessionExitCleanly() {
1216 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1217 // it to be set by asking for the prefs.
1218 GetPrefs();
1219 return last_session_exited_cleanly_;
1220}
1221
[email protected]d8e41ed2008-09-11 15:22:321222BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461223 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321224 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461225 bookmark_bar_model_->Load();
1226 }
initial.commit09911bf2008-07-26 23:55:291227 return bookmark_bar_model_.get();
1228}
1229
1230bool ProfileImpl::IsSameProfile(Profile* profile) {
1231 if (profile == static_cast<Profile*>(this))
1232 return true;
1233 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1234 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1235}
1236
1237Time ProfileImpl::GetStartTime() const {
1238 return start_time_;
1239}
1240
1241TabRestoreService* ProfileImpl::GetTabRestoreService() {
1242 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191243 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291244 return tab_restore_service_.get();
1245}
1246
[email protected]449478302009-06-09 20:04:281247ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1248 if (!thumbnail_store_.get()) {
1249 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251250 thumbnail_store_->Init(
1251 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281252 }
1253 return thumbnail_store_.get();
1254}
1255
initial.commit09911bf2008-07-26 23:55:291256void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191257 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291258}
1259
[email protected]a9afddb2009-02-12 17:49:421260// To be run in the IO thread to notify all resource message filters that the
[email protected]20930852008-10-15 19:30:411261// spellchecker has changed.
1262class NotifySpellcheckerChangeTask : public Task {
1263 public:
1264 NotifySpellcheckerChangeTask(
[email protected]e7244d82008-10-29 18:13:261265 Profile* profile,
1266 const SpellcheckerReinitializedDetails& spellchecker)
[email protected]20930852008-10-15 19:30:411267 : profile_(profile),
1268 spellchecker_(spellchecker) {
1269 }
1270
1271 private:
1272 void Run(void) {
1273 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561274 NotificationType::SPELLCHECKER_REINITIALIZED,
[email protected]20930852008-10-15 19:30:411275 Source<Profile>(profile_),
1276 Details<SpellcheckerReinitializedDetails>(&spellchecker_));
1277 }
1278
1279 Profile* profile_;
1280 SpellcheckerReinitializedDetails spellchecker_;
1281};
1282
[email protected]e3448ea2009-10-02 01:29:291283void ProfileImpl::ReinitializeSpellChecker() {
[email protected]20930852008-10-15 19:30:411284 PrefService* prefs = GetPrefs();
[email protected]e3448ea2009-10-02 01:29:291285 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1286 DeleteSpellCheckerImpl(false);
[email protected]20930852008-10-15 19:30:411287
[email protected]e3448ea2009-10-02 01:29:291288 // Retrieve the (perhaps updated recently) dictionary name from preferences.
[email protected]bd17b702009-02-25 20:44:081289 FilePath dict_dir;
[email protected]e7244d82008-10-29 18:13:261290 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
[email protected]a9afddb2009-02-12 17:49:421291 // Note that, as the object pointed to by previously by spellchecker_
[email protected]e7244d82008-10-29 18:13:261292 // is being deleted in the io thread, the spellchecker_ can be made to point
1293 // to a new object (RE-initialized) in parallel in this UI thread.
[email protected]4b4d1adc2008-12-10 22:28:581294 spellchecker_ = new SpellChecker(dict_dir,
[email protected]74c8b422009-03-11 00:34:121295 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1296 GetRequestContext(),
[email protected]bd17b702009-02-25 20:44:081297 FilePath());
[email protected]e7244d82008-10-29 18:13:261298 spellchecker_->AddRef(); // Manual refcounting.
[email protected]20930852008-10-15 19:30:411299
[email protected]e3448ea2009-10-02 01:29:291300 // Set auto spell correct status for spellchecker.
[email protected]154a4332009-06-03 20:20:581301 spellchecker_->EnableAutoSpellCorrect(
1302 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
[email protected]154a4332009-06-03 20:20:581303
[email protected]e3448ea2009-10-02 01:29:291304 NotifySpellCheckerChanged();
1305 } else {
1306 DeleteSpellCheckerImpl(true);
[email protected]20930852008-10-15 19:30:411307 }
1308}
1309
[email protected]85c55dc2009-11-06 03:05:461310#if defined(SPELLCHECKER_IN_RENDERER)
1311SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1312 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1313}
1314
1315void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1316 // If we are already loading the spellchecker, and this is just a hint to
1317 // load the spellchecker, do nothing.
1318 if (!force && spellcheck_host_.get())
1319 return;
1320
1321 bool notify = false;
1322 if (spellcheck_host_.get()) {
1323 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051324 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461325 spellcheck_host_ready_ = false;
1326 notify = true;
1327 }
1328
1329 PrefService* prefs = GetPrefs();
1330 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1331 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1332 spellcheck_host_ = new SpellCheckHost(this,
1333 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1334 GetRequestContext());
[email protected]85c55dc2009-11-06 03:05:461335 } else if (notify) {
1336 // The spellchecker has been disabled.
1337 SpellCheckHostInitialized();
1338 }
1339}
1340
1341void ProfileImpl::SpellCheckHostInitialized() {
1342 spellcheck_host_ready_ =
1343 spellcheck_host_ && spellcheck_host_->bdict_fd().fd != -1;
1344 NotificationService::current()->Notify(
1345 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1346 Source<Profile>(this), NotificationService::NoDetails());
1347}
1348#endif
1349
[email protected]e3448ea2009-10-02 01:29:291350void ProfileImpl::NotifySpellCheckerChanged() {
[email protected]6fad2632009-11-02 05:59:371351 SpellcheckerReinitializedDetails scoped_spellchecker;
1352 scoped_spellchecker.spellchecker = spellchecker_;
1353 ChromeThread::PostTask(
1354 ChromeThread::IO, FROM_HERE,
1355 new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
[email protected]e3448ea2009-10-02 01:29:291356}
1357
1358void ProfileImpl::DeleteSpellCheckerImpl(bool notify) {
[email protected]6fad2632009-11-02 05:59:371359 if (!spellchecker_)
1360 return;
[email protected]e3448ea2009-10-02 01:29:291361
[email protected]6fad2632009-11-02 05:59:371362 // The spellchecker must be deleted on the I/O thread.
1363 ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, spellchecker_);
1364 spellchecker_ = NULL;
[email protected]e3448ea2009-10-02 01:29:291365
[email protected]6fad2632009-11-02 05:59:371366 if (notify)
1367 NotifySpellCheckerChanged();
[email protected]e7244d82008-10-29 18:13:261368}
1369
initial.commit09911bf2008-07-26 23:55:291370SpellChecker* ProfileImpl::GetSpellChecker() {
1371 if (!spellchecker_) {
[email protected]20930852008-10-15 19:30:411372 // This is where spellchecker gets initialized. Note that this is being
1373 // initialized in the ui_thread. However, this is not a problem as long as
1374 // it is *used* in the io thread.
[email protected]34cc84f2009-02-13 10:04:351375 // TODO(sidchat): One day, change everything so that spellchecker gets
[email protected]20930852008-10-15 19:30:411376 // initialized in the IO thread itself.
[email protected]e3448ea2009-10-02 01:29:291377 ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:291378 }
[email protected]20930852008-10-15 19:30:411379
initial.commit09911bf2008-07-26 23:55:291380 return spellchecker_;
1381}
1382
[email protected]3bf335a2009-06-26 20:46:061383WebKitContext* ProfileImpl::GetWebKitContext() {
1384 if (!webkit_context_.get())
1385 webkit_context_ = new WebKitContext(path_, false);
1386 DCHECK(webkit_context_.get());
1387 return webkit_context_.get();
1388}
1389
[email protected]4bb336302009-10-12 05:44:261390DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1391 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1392 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261393 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031394 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261395 }
[email protected]4bb336302009-10-12 05:44:261396 return desktop_notification_service_.get();
1397}
1398
initial.commit09911bf2008-07-26 23:55:291399void ProfileImpl::MarkAsCleanShutdown() {
1400 if (prefs_.get()) {
1401 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1402 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1403
1404 // NOTE: If you change what thread this writes on, be sure and update
1405 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361406 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291407 }
1408}
1409
[email protected]e7244d82008-10-29 18:13:261410void ProfileImpl::Observe(NotificationType type,
1411 const NotificationSource& source,
1412 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561413 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261414 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1415 PrefService* prefs = Source<PrefService>(source).ptr();
1416 DCHECK(pref_name_in && prefs);
1417 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461418#if !defined(SPELLCHECKER_IN_RENDERER)
1419 *pref_name_in == prefs::kEnableAutoSpellCorrect ||
1420#endif
1421 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]e3448ea2009-10-02 01:29:291422 ReinitializeSpellChecker();
[email protected]85c55dc2009-11-06 03:05:461423#if defined(SPELLCHECKER_IN_RENDERER)
1424 ReinitializeSpellCheckHost(true);
1425#endif
[email protected]e7244d82008-10-29 18:13:261426 }
[email protected]4a190632009-05-09 01:07:421427 } else if (NotificationType::THEME_INSTALLED == type) {
1428 Extension* extension = Details<Extension>(details).ptr();
1429 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111430 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1431 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1432 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1433 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261434 }
1435}
1436
initial.commit09911bf2008-07-26 23:55:291437void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141438 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291439}
[email protected]3a453fa2008-08-15 18:46:341440
[email protected]48352c12009-08-15 01:19:111441ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431442 if (!ProfileSyncService::IsSyncEnabled()) {
1443 return NULL;
[email protected]7367f1a2009-10-10 01:09:441444 }
[email protected]eec3bcfa2009-11-12 17:23:431445 if (!sync_service_.get())
1446 InitSyncService();
1447 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111448}
1449
1450void ProfileImpl::InitSyncService() {
[email protected]48352c12009-08-15 01:19:111451 sync_service_.reset(new ProfileSyncService(this));
1452 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111453}