blob: 5c502591449e24cf847e1a34158d1b29840160a4 [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
7#include "base/command_line.h"
[email protected]04fba9a92008-10-28 17:25:258#include "base/file_path.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/path_service.h"
11#include "base/scoped_ptr.h"
12#include "base/string_util.h"
[email protected]a9afddb2009-02-12 17:49:4213#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2914#include "chrome/browser/browser_list.h"
15#include "chrome/browser/browser_process.h"
[email protected]b7f05882009-02-22 01:21:5616#include "chrome/browser/download/download_manager.h"
[email protected]481e1a42009-05-06 20:56:0517#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2518#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3519#include "chrome/browser/extensions/user_script_master.h"
[email protected]a9afddb2009-02-12 17:49:4220#include "chrome/browser/history/history.h"
[email protected]6ab9b202008-12-23 22:34:5021#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]e69d33952009-06-03 22:00:4122#include "chrome/browser/password_manager/password_store_default.h"
initial.commit09911bf2008-07-26 23:55:2923#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2624#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3325#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4626#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4427#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3028#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]f0a644292009-02-25 23:32:4729#include "chrome/browser/spellchecker.h"
[email protected]1132436e2009-04-08 20:06:3330#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]4a190632009-05-09 01:07:4231#include "chrome/browser/browser_theme_provider.h"
initial.commit09911bf2008-07-26 23:55:2932#include "chrome/browser/visitedlink_master.h"
33#include "chrome/browser/webdata/web_data_service.h"
34#include "chrome/common/chrome_constants.h"
35#include "chrome/common/chrome_paths.h"
36#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5837#include "chrome/common/extensions/extension_error_reporter.h"
[email protected]47accfd62009-05-14 18:46:2138#include "chrome/common/net/cookie_monster_sqlite.h"
initial.commit09911bf2008-07-26 23:55:2939#include "chrome/common/notification_service.h"
40#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3241#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5842#include "grit/locale_settings.h"
[email protected]a9cea7542009-05-20 04:30:2343#include "net/base/force_tls_state.h"
initial.commit09911bf2008-07-26 23:55:2944
[email protected]e1acf6f2008-10-27 20:43:3345using base::Time;
46using base::TimeDelta;
47
initial.commit09911bf2008-07-26 23:55:2948// Delay, in milliseconds, before we explicitly create the SessionService.
49static const int kCreateSessionServiceDelayMS = 500;
50
51// A pointer to the request context for the default profile. See comments on
52// Profile::GetDefaultRequestContext.
53URLRequestContext* Profile::default_request_context_;
54
[email protected]47accfd62009-05-14 18:46:2155static void CleanupRequestContext(ChromeURLRequestContext* context) {
56 if (context) {
57 context->CleanupOnUIThread();
58
59 // Clean up request context on IO thread.
60 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE,
61 context);
62 }
63}
64
[email protected]34cc84f2009-02-13 10:04:3565// static
initial.commit09911bf2008-07-26 23:55:2966void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:5567 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:2968 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
69 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:1270 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:2671 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
72 IDS_SPELLCHECK_DICTIONARY);
73 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:5874 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]f93fe782009-02-19 01:26:1375 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
[email protected]4a190632009-05-09 01:07:4276 prefs->RegisterStringPref(prefs::kCurrentThemeID, L"");
77 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
78 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
79 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:5080 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]f93fe782009-02-19 01:26:1381 prefs->RegisterBooleanPref(prefs::kEnableExtensions, false);
initial.commit09911bf2008-07-26 23:55:2982}
83
[email protected]34cc84f2009-02-13 10:04:3584// static
[email protected]f7011fcb2009-01-28 21:54:3285Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:2986 return new ProfileImpl(path);
87}
88
[email protected]34cc84f2009-02-13 10:04:3589// static
initial.commit09911bf2008-07-26 23:55:2990URLRequestContext* Profile::GetDefaultRequestContext() {
91 return default_request_context_;
92}
93
[email protected]e69d33952009-06-03 22:00:4194#if defined(OS_LINUX)
95// Temporarily disabled while we figure some stuff out.
96// http://code.google.com/p/chromium/issues/detail?id=12351
97// #include "chrome/browser/password_manager/password_store_gnome.h"
98// #include "chrome/browser/password_manager/password_store_kwallet.h"
99#elif defined(OS_WIN)
100#include "chrome/browser/password_manager/password_store_win.h"
101#endif
initial.commit09911bf2008-07-26 23:55:29102
initial.commit09911bf2008-07-26 23:55:29103////////////////////////////////////////////////////////////////////////////////
104//
105// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42106// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29107//
108////////////////////////////////////////////////////////////////////////////////
109class OffTheRecordProfileImpl : public Profile,
110 public NotificationObserver {
111 public:
112 explicit OffTheRecordProfileImpl(Profile* real_profile)
113 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21114 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29115 start_time_(Time::Now()) {
[email protected]6ab9b202008-12-23 22:34:50116 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this);
initial.commit09911bf2008-07-26 23:55:29117 request_context_->AddRef();
[email protected]481e1a42009-05-06 20:56:05118
119 extension_process_manager_.reset(new ExtensionProcessManager(this));
120
initial.commit09911bf2008-07-26 23:55:29121 // Register for browser close notifications so we can detect when the last
122 // off-the-record window is closed, in which case we can clean our states
123 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43124 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
125 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29126 }
127
128 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21129 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21130 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29131 }
132
[email protected]f7011fcb2009-01-28 21:54:32133 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29134
135 virtual bool IsOffTheRecord() {
136 return true;
137 }
138
139 virtual Profile* GetOffTheRecordProfile() {
140 return this;
141 }
142
[email protected]860f55492009-03-27 19:50:59143 virtual void DestroyOffTheRecordProfile() {
144 // Suicide is bad!
145 NOTREACHED();
146 }
147
initial.commit09911bf2008-07-26 23:55:29148 virtual Profile* GetOriginalProfile() {
149 return profile_;
150 }
151
152 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49153 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
154 // because we don't want to leak the sites that the user has visited before.
155 return NULL;
initial.commit09911bf2008-07-26 23:55:29156 }
157
[email protected]6014d672008-12-05 00:38:25158 virtual ExtensionsService* GetExtensionsService() {
159 return profile_->GetExtensionsService();
160 }
161
[email protected]0938d3c2009-01-09 20:37:35162 virtual UserScriptMaster* GetUserScriptMaster() {
163 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25164 }
165
[email protected]481e1a42009-05-06 20:56:05166 virtual ExtensionProcessManager* GetExtensionProcessManager() {
167 return extension_process_manager_.get();
168 }
169
[email protected]34cc84f2009-02-13 10:04:35170 virtual SSLHostState* GetSSLHostState() {
171 if (!ssl_host_state_.get())
172 ssl_host_state_.reset(new SSLHostState());
173
174 DCHECK(ssl_host_state_->CalledOnValidThread());
175 return ssl_host_state_.get();
176 }
177
[email protected]a9cea7542009-05-20 04:30:23178 virtual net::ForceTLSState* GetForceTLSState() {
179 if (!force_tls_state_.get())
180 force_tls_state_.reset(new net::ForceTLSState());
181
182 return force_tls_state_.get();
183 }
184
initial.commit09911bf2008-07-26 23:55:29185 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
186 if (sat == EXPLICIT_ACCESS) {
187 return profile_->GetHistoryService(sat);
188 } else {
189 NOTREACHED() << "This profile is OffTheRecord";
190 return NULL;
191 }
192 }
193
initial.commit09911bf2008-07-26 23:55:29194 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
195 if (sat == EXPLICIT_ACCESS) {
196 return profile_->GetWebDataService(sat);
197 } else {
198 NOTREACHED() << "This profile is OffTheRecord";
199 return NULL;
200 }
201 }
202
[email protected]e69d33952009-06-03 22:00:41203 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
204 if (sat == EXPLICIT_ACCESS) {
205 return profile_->GetPasswordStore(sat);
206 } else {
207 NOTREACHED() << "This profile is OffTheRecord";
208 return NULL;
209 }
210 }
211
initial.commit09911bf2008-07-26 23:55:29212 virtual PrefService* GetPrefs() {
213 return profile_->GetPrefs();
214 }
215
216 virtual TemplateURLModel* GetTemplateURLModel() {
217 return profile_->GetTemplateURLModel();
218 }
219
220 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
221 return profile_->GetTemplateURLFetcher();
222 }
223
224 virtual DownloadManager* GetDownloadManager() {
225 if (!download_manager_.get()) {
226 scoped_refptr<DownloadManager> dlm(new DownloadManager);
227 dlm->Init(this);
228 download_manager_.swap(dlm);
229 }
230 return download_manager_.get();
231 }
232
233 virtual bool HasCreatedDownloadManager() const {
234 return (download_manager_.get() != NULL);
235 }
236
[email protected]4a190632009-05-09 01:07:42237 virtual void InitThemes() {
238 GetOriginalProfile()->InitThemes();
239 }
240
241 virtual void SetTheme(Extension* extension) {
242 GetOriginalProfile()->SetTheme(extension);
243 }
244
245 virtual void ClearTheme() {
246 GetOriginalProfile()->ClearTheme();
247 }
248
249 virtual ThemeProvider* GetThemeProvider() {
250 return GetOriginalProfile()->GetThemeProvider();
251 }
252
initial.commit09911bf2008-07-26 23:55:29253 virtual URLRequestContext* GetRequestContext() {
254 return request_context_;
255 }
256
[email protected]e7f29642009-03-02 22:53:18257 virtual URLRequestContext* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11258 // In OTR mode, media request context is the same as the original one.
259 return request_context_;
[email protected]e7f29642009-03-02 22:53:18260 }
261
[email protected]47accfd62009-05-14 18:46:21262 URLRequestContext* GetRequestContextForExtensions() {
263 if (!extensions_request_context_) {
264 extensions_request_context_ =
265 ChromeURLRequestContext::CreateOffTheRecordForExtensions(this);
266 extensions_request_context_->AddRef();
267
268 DCHECK(extensions_request_context_->cookie_store());
269 }
270
271 return extensions_request_context_;
272 }
273
initial.commit09911bf2008-07-26 23:55:29274 virtual SessionService* GetSessionService() {
275 // Don't save any sessions when off the record.
276 return NULL;
277 }
278
279 virtual void ShutdownSessionService() {
280 // We don't allow a session service, nothing to do.
281 }
282
283 virtual bool HasSessionService() const {
284 // We never have a session service.
285 return false;
286 }
287
288 virtual std::wstring GetName() {
289 return profile_->GetName();
290 }
291
292 virtual void SetName(const std::wstring& name) {
293 profile_->SetName(name);
294 }
295
296 virtual std::wstring GetID() {
297 return profile_->GetID();
298 }
299
300 virtual void SetID(const std::wstring& id) {
301 profile_->SetID(id);
302 }
303
initial.commit09911bf2008-07-26 23:55:29304 virtual bool DidLastSessionExitCleanly() {
305 return profile_->DidLastSessionExitCleanly();
306 }
307
[email protected]d8e41ed2008-09-11 15:22:32308 virtual BookmarkModel* GetBookmarkModel() {
309 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29310 }
311
[email protected]3a453fa2008-08-15 18:46:34312#ifdef CHROME_PERSONALIZATION
[email protected]57d3d0a2008-09-24 00:50:07313 virtual ProfilePersonalization* GetProfilePersonalization() {
[email protected]3a453fa2008-08-15 18:46:34314 return profile_->GetProfilePersonalization();
315 }
316#endif
317
initial.commit09911bf2008-07-26 23:55:29318 virtual bool IsSameProfile(Profile* profile) {
319 if (profile == static_cast<Profile*>(this))
320 return true;
321 return profile == profile_;
322 }
323
324 virtual Time GetStartTime() const {
325 return start_time_;
326 }
327
328 virtual TabRestoreService* GetTabRestoreService() {
329 return NULL;
330 }
331
[email protected]e7244d82008-10-29 18:13:26332 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41333 }
334
[email protected]e7244d82008-10-29 18:13:26335 virtual void ReinitializeSpellChecker() {
336 profile_->ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:29337 }
338
339 virtual SpellChecker* GetSpellChecker() {
340 return profile_->GetSpellChecker();
341 }
342
343 virtual void MarkAsCleanShutdown() {
344 }
345
[email protected]bdbc87c2009-01-25 05:08:54346 virtual void InitExtensions() {
347 NOTREACHED();
348 }
349
initial.commit09911bf2008-07-26 23:55:29350 virtual void ExitedOffTheRecordMode() {
351 // Drop our download manager so we forget about all the downloads made
352 // in off-the-record mode.
353 download_manager_ = NULL;
354 }
355
356 virtual void Observe(NotificationType type,
357 const NotificationSource& source,
358 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56359 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29360 // We are only interested in OTR browser closing.
361 if (Source<Browser>(source)->profile() != this)
362 return;
363
364 // Let's check if we still have an Off The Record window opened.
365 // Note that we check against 1 as this notification is sent before the
366 // browser window is actually removed from the list.
367 if (BrowserList::GetBrowserCount(this) <= 1)
368 ExitedOffTheRecordMode();
369 }
370
371 private:
[email protected]88cf3292009-05-22 01:48:43372 NotificationRegistrar registrar_;
373
initial.commit09911bf2008-07-26 23:55:29374 // The real underlying profile.
375 Profile* profile_;
376
[email protected]6ab9b202008-12-23 22:34:50377 // The context to use for requests made from this OTR session.
378 ChromeURLRequestContext* request_context_;
initial.commit09911bf2008-07-26 23:55:29379
[email protected]47accfd62009-05-14 18:46:21380 ChromeURLRequestContext* extensions_request_context_;
381
initial.commit09911bf2008-07-26 23:55:29382 // The download manager that only stores downloaded items in memory.
383 scoped_refptr<DownloadManager> download_manager_;
384
[email protected]4a190632009-05-09 01:07:42385 // The download manager that only stores downloaded items in memory.
386 scoped_refptr<BrowserThemeProvider> theme_provider_;
387
[email protected]34cc84f2009-02-13 10:04:35388 // We don't want SSLHostState from the OTR profile to leak back to the main
389 // profile because then the main profile would learn some of the host names
390 // the user visited while OTR.
391 scoped_ptr<SSLHostState> ssl_host_state_;
392
[email protected]a9cea7542009-05-20 04:30:23393 // The ForceTLSState that only stores enabled sites in memory.
394 scoped_ptr<net::ForceTLSState> force_tls_state_;
395
[email protected]481e1a42009-05-06 20:56:05396 // Extensions run in a different context in incognito mode.
397 scoped_ptr<ExtensionProcessManager> extension_process_manager_;
398
initial.commit09911bf2008-07-26 23:55:29399 // Time we were started.
400 Time start_time_;
401
402 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl);
403};
404
[email protected]f7011fcb2009-01-28 21:54:32405ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29406 : path_(path),
[email protected]f7011fcb2009-01-28 21:54:32407 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57408 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21409 extensions_request_context_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32410 history_service_created_(false),
411 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41412 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32413 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42414 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32415 start_time_(Time::Now()),
416 spellchecker_(NULL),
initial.commit09911bf2008-07-26 23:55:29417 shutdown_session_service_(false) {
418 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
419 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14420 create_session_service_timer_.Start(
421 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
422 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54423
[email protected]481e1a42009-05-06 20:56:05424 extension_process_manager_.reset(new ExtensionProcessManager(this));
425
[email protected]e7244d82008-10-29 18:13:26426 PrefService* prefs = GetPrefs();
427 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
428 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58429 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58430
431#ifdef CHROME_PERSONALIZATION
432 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableP13n))
433 personalization_.reset(Personalization::CreateProfilePersonalization(this));
434#endif
435
[email protected]1351b6a2009-04-09 20:13:22436#if defined(OS_LINUX)
437 // TODO(port): Remove ifdef when the Linux splash page is not needed.
438 prefs->transient()->SetString(prefs::kHomePage, "about:linux-splash");
439 prefs->transient()->SetBoolean(prefs::kHomePageIsNewTabPage, false);
440#endif
[email protected]4a190632009-05-09 01:07:42441
442 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43443 registrar_.Add(this, NotificationType::THEME_INSTALLED,
444 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29445}
446
[email protected]bdbc87c2009-01-25 05:08:54447void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41448 if (user_script_master_ || extensions_service_)
449 return; // Already initialized.
450
[email protected]bdbc87c2009-01-25 05:08:54451 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]f93fe782009-02-19 01:26:13452 PrefService* prefs = GetPrefs();
[email protected]bdbc87c2009-01-25 05:08:54453 bool user_scripts_enabled =
[email protected]f0a51fb52009-03-05 12:46:38454 command_line->HasSwitch(switches::kEnableUserScripts) ||
[email protected]f93fe782009-02-19 01:26:13455 prefs->GetBoolean(prefs::kEnableUserScripts);
[email protected]bdbc87c2009-01-25 05:08:54456
[email protected]f7011fcb2009-01-28 21:54:32457 FilePath script_dir;
[email protected]bdbc87c2009-01-25 05:08:54458 if (user_scripts_enabled) {
[email protected]0cd957b2009-03-06 20:13:23459 if (command_line->HasSwitch(switches::kUserScriptsDir)) {
460 std::wstring path_string =
461 command_line->GetSwitchValue(switches::kUserScriptsDir);
462 script_dir = FilePath::FromWStringHack(path_string);
463 } else {
464 script_dir = GetPath();
465 script_dir = script_dir.Append(chrome::kUserScriptsDirname);
466 }
[email protected]bdbc87c2009-01-25 05:08:54467 }
468
[email protected]bb28e062009-02-27 17:19:18469 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]bdbc87c2009-01-25 05:08:54470 user_script_master_ = new UserScriptMaster(
[email protected]9197f3b2009-06-02 00:49:27471 g_browser_process->file_thread()->message_loop(),
472 script_dir);
[email protected]894bb502009-05-21 22:39:57473 extensions_service_ = new ExtensionsService(
474 this, MessageLoop::current(),
475 g_browser_process->file_thread()->message_loop(),
476 std::string()); // Use default registry path
[email protected]bdbc87c2009-01-25 05:08:54477
[email protected]9197f3b2009-06-02 00:49:27478 extensions_service_->Init();
[email protected]bdbc87c2009-01-25 05:08:54479}
480
initial.commit09911bf2008-07-26 23:55:29481ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19482 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29483
484 StopCreateSessionServiceTimer();
485 // TemplateURLModel schedules a task on the WebDataService from its
486 // destructor. Delete it first to ensure the task gets scheduled before we
487 // shut down the database.
488 template_url_model_.reset();
489
490 // The download manager queries the history system and should be deleted
491 // before the history is shutdown so it can properly cancel all requests.
492 download_manager_ = NULL;
493
[email protected]4a190632009-05-09 01:07:42494 // The theme provider provides bitmaps to whoever wants them.
495 theme_provider_ = NULL;
496
[email protected]e7244d82008-10-29 18:13:26497 // Remove pref observers.
498 PrefService* prefs = GetPrefs();
499 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
500 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58501 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26502
[email protected]3a453fa2008-08-15 18:46:34503#ifdef CHROME_PERSONALIZATION
[email protected]57d3d0a2008-09-24 00:50:07504 personalization_.reset();
[email protected]3a453fa2008-08-15 18:46:34505#endif
506
initial.commit09911bf2008-07-26 23:55:29507 // Both HistoryService and WebDataService maintain threads for background
508 // processing. Its possible each thread still has tasks on it that have
509 // increased the ref count of the service. In such a situation, when we
510 // decrement the refcount, it won't be 0, and the threads/databases aren't
511 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
512 // databases are properly closed.
513 if (web_data_service_.get())
514 web_data_service_->Shutdown();
515
516 if (history_service_.get())
517 history_service_->Cleanup();
518
519 // The I/O thread may be NULL during testing.
[email protected]ab820df2008-08-26 05:55:10520 base::Thread* io_thread = g_browser_process->io_thread();
initial.commit09911bf2008-07-26 23:55:29521
522 if (spellchecker_) {
523 // The spellchecker must be deleted on the I/O thread. During testing, we
524 // don't have an I/O thread.
525 if (io_thread)
526 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
527 else
528 spellchecker_->Release();
529 }
530
[email protected]47accfd62009-05-14 18:46:21531 if (default_request_context_ == request_context_)
532 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50533
[email protected]47accfd62009-05-14 18:46:21534 CleanupRequestContext(request_context_);
535 CleanupRequestContext(media_request_context_);
536 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17537
[email protected]d8e41ed2008-09-11 15:22:32538 // HistoryService may call into the BookmarkModel, as such we need to
539 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46540 // HistoryService will join with HistoryService's backend thread so that
541 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32542 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46543 history_service_ = NULL;
544 bookmark_bar_model_.reset();
545
initial.commit09911bf2008-07-26 23:55:29546 MarkAsCleanShutdown();
547}
548
[email protected]f7011fcb2009-01-28 21:54:32549FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29550 return path_;
551}
552
553bool ProfileImpl::IsOffTheRecord() {
554 return false;
555}
556
557Profile* ProfileImpl::GetOffTheRecordProfile() {
558 if (!off_the_record_profile_.get()) {
559 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
560 off_the_record_profile_.swap(p);
561 }
562 return off_the_record_profile_.get();
563}
564
[email protected]860f55492009-03-27 19:50:59565void ProfileImpl::DestroyOffTheRecordProfile() {
566 off_the_record_profile_.reset();
567}
568
initial.commit09911bf2008-07-26 23:55:29569Profile* ProfileImpl::GetOriginalProfile() {
570 return this;
571}
572
[email protected]176aa482008-11-14 03:25:15573static void BroadcastNewHistoryTable(base::SharedMemory* table_memory) {
initial.commit09911bf2008-07-26 23:55:29574 if (!table_memory)
575 return;
576
577 // send to all RenderProcessHosts
578 for (RenderProcessHost::iterator i = RenderProcessHost::begin();
579 i != RenderProcessHost::end(); i++) {
580 if (!i->second->channel())
581 continue;
582
[email protected]176aa482008-11-14 03:25:15583 base::SharedMemoryHandle new_table;
[email protected]f7011fcb2009-01-28 21:54:32584 base::ProcessHandle process = i->second->process().handle();
initial.commit09911bf2008-07-26 23:55:29585 if (!process) {
586 // process can be null if it's started with the --single-process flag.
[email protected]f7011fcb2009-01-28 21:54:32587 process = base::Process::Current().handle();
initial.commit09911bf2008-07-26 23:55:29588 }
589
590 table_memory->ShareToProcess(process, &new_table);
591 IPC::Message* msg = new ViewMsg_VisitedLink_NewTable(new_table);
592 i->second->channel()->Send(msg);
593 }
594}
595
596VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
597 if (!visited_link_master_.get()) {
598 scoped_ptr<VisitedLinkMaster> visited_links(
599 new VisitedLinkMaster(g_browser_process->file_thread(),
600 BroadcastNewHistoryTable, this));
601 if (!visited_links->Init())
602 return NULL;
603 visited_link_master_.swap(visited_links);
604 }
605
606 return visited_link_master_.get();
607}
608
[email protected]6014d672008-12-05 00:38:25609ExtensionsService* ProfileImpl::GetExtensionsService() {
610 return extensions_service_.get();
611}
612
[email protected]0938d3c2009-01-09 20:37:35613UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35614 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25615}
616
[email protected]481e1a42009-05-06 20:56:05617ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
618 return extension_process_manager_.get();
619}
620
[email protected]34cc84f2009-02-13 10:04:35621SSLHostState* ProfileImpl::GetSSLHostState() {
622 if (!ssl_host_state_.get())
623 ssl_host_state_.reset(new SSLHostState());
624
625 DCHECK(ssl_host_state_->CalledOnValidThread());
626 return ssl_host_state_.get();
627}
628
[email protected]a9cea7542009-05-20 04:30:23629net::ForceTLSState* ProfileImpl::GetForceTLSState() {
630 if (!force_tls_state_.get())
631 force_tls_state_.reset(new net::ForceTLSState());
632
633 return force_tls_state_.get();
634}
635
initial.commit09911bf2008-07-26 23:55:29636PrefService* ProfileImpl::GetPrefs() {
637 if (!prefs_.get()) {
[email protected]6faa0e0d2009-04-28 06:50:36638 prefs_.reset(new PrefService(GetPrefFilePath(),
639 g_browser_process->file_thread()));
initial.commit09911bf2008-07-26 23:55:29640
641 // The Profile class and ProfileManager class may read some prefs so
642 // register known prefs as soon as possible.
643 Profile::RegisterUserPrefs(prefs_.get());
644 ProfileManager::RegisterUserPrefs(prefs_.get());
645
646 // The last session exited cleanly if there is no pref for
647 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
648 last_session_exited_cleanly_ =
649 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
650 // Mark the session as open.
651 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
652 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36653 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29654 }
655
656 return prefs_.get();
657}
658
[email protected]f7011fcb2009-01-28 21:54:32659FilePath ProfileImpl::GetPrefFilePath() {
660 FilePath pref_file_path = path_;
661 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29662 return pref_file_path;
663}
664
665URLRequestContext* ProfileImpl::GetRequestContext() {
666 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32667 FilePath cookie_path = GetPath();
668 cookie_path = cookie_path.Append(chrome::kCookieFilename);
669 FilePath cache_path = GetPath();
[email protected]2b2830a2009-02-07 01:58:42670
671 // Override the cache location if specified by the user.
672 const std::wstring user_cache_dir(
673 CommandLine::ForCurrentProcess()->GetSwitchValue(
674 switches::kDiskCacheDir));
675 if (!user_cache_dir.empty()) {
676 cache_path = FilePath::FromWStringHack(user_cache_dir);
677 }
678
[email protected]f7011fcb2009-01-28 21:54:32679 cache_path = cache_path.Append(chrome::kCacheDirname);
[email protected]6ab9b202008-12-23 22:34:50680 request_context_ = ChromeURLRequestContext::CreateOriginal(
681 this, cookie_path, cache_path);
initial.commit09911bf2008-07-26 23:55:29682 request_context_->AddRef();
683
[email protected]6ab9b202008-12-23 22:34:50684 // The first request context is always a normal (non-OTR) request context.
685 // Even when Chromium is started in OTR mode, a normal profile is always
686 // created first.
687 if (!default_request_context_) {
688 default_request_context_ = request_context_;
689 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56690 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50691 NotificationService::AllSources(), NotificationService::NoDetails());
692 }
693
initial.commit09911bf2008-07-26 23:55:29694 DCHECK(request_context_->cookie_store());
695 }
696
697 return request_context_;
698}
699
[email protected]e7f29642009-03-02 22:53:18700URLRequestContext* ProfileImpl::GetRequestContextForMedia() {
701 if (!media_request_context_) {
702 FilePath cache_path = GetPath();
[email protected]e3edeba2009-03-23 18:57:14703
704 // Override the cache location if specified by the user.
705 const std::wstring user_cache_dir(
706 CommandLine::ForCurrentProcess()->GetSwitchValue(
707 switches::kDiskCacheDir));
708 if (!user_cache_dir.empty()) {
709 cache_path = FilePath::FromWStringHack(user_cache_dir);
710 }
711
[email protected]4e7b5dbb2009-03-25 00:09:23712 cache_path = cache_path.Append(chrome::kMediaCacheDirname);
[email protected]e7f29642009-03-02 22:53:18713 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia(
714 this, cache_path);
715 media_request_context_->AddRef();
716
717 DCHECK(media_request_context_->cookie_store());
718 }
719
720 return media_request_context_;
721}
722
[email protected]47accfd62009-05-14 18:46:21723URLRequestContext* ProfileImpl::GetRequestContextForExtensions() {
724 if (!extensions_request_context_) {
725 FilePath cookie_path = GetPath();
726 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
727
728 extensions_request_context_ =
729 ChromeURLRequestContext::CreateOriginalForExtensions(this, cookie_path);
730 extensions_request_context_->AddRef();
731
732 DCHECK(extensions_request_context_->cookie_store());
733 }
734
735 return extensions_request_context_;
736}
737
initial.commit09911bf2008-07-26 23:55:29738HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
739 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:46740 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:29741 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:32742 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:29743 return NULL;
744 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:29745
746 // Send out the notification that the history service was created.
747 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56748 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:29749 Details<HistoryService>(history_service_.get()));
750 }
751 return history_service_.get();
752}
753
initial.commit09911bf2008-07-26 23:55:29754TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
755 if (!template_url_model_.get())
756 template_url_model_.reset(new TemplateURLModel(this));
757 return template_url_model_.get();
758}
759
760TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
761 if (!template_url_fetcher_.get())
762 template_url_fetcher_.reset(new TemplateURLFetcher(this));
763 return template_url_fetcher_.get();
764}
765
766WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
767 if (!created_web_data_service_)
768 CreateWebDataService();
769 return web_data_service_.get();
770}
771
772void ProfileImpl::CreateWebDataService() {
773 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
774 created_web_data_service_ = true;
775 scoped_refptr<WebDataService> wds(new WebDataService());
776 if (!wds->Init(GetPath()))
777 return;
778 web_data_service_.swap(wds);
779}
780
[email protected]e69d33952009-06-03 22:00:41781PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
782 if (!created_password_store_)
783 CreatePasswordStore();
784 return password_store_.get();
785}
786
787void ProfileImpl::CreatePasswordStore() {
788 DCHECK(!created_password_store_ && password_store_.get() == NULL);
789 created_password_store_ = true;
790 scoped_refptr<PasswordStore> ps;
791#if defined(OS_LINUX)
792// Temporarily disabled while we figure some stuff out.
793// http://code.google.com/p/chromium/issues/detail?id=12351
794// if (getenv("KDE_FULL_SESSION")) {
795// ps = new PasswordStoreKWallet();
796// } else {
797// ps = new PasswordStoreGnome();
798// }
799 NOTIMPLEMENTED();
800#elif defined(OS_WIN)
801 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
802#else
803 NOTIMPLEMENTED();
804#endif
805 if (!ps || !ps->Init()) {
806 // Try falling back to the default password manager
807 LOG(WARNING) << "Could not initialise native password manager - "
808 "falling back to default";
809 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
810 if (!ps->Init())
811 return;
812 }
813 password_store_.swap(ps);
814}
815
initial.commit09911bf2008-07-26 23:55:29816DownloadManager* ProfileImpl::GetDownloadManager() {
817 if (!created_download_manager_) {
818 scoped_refptr<DownloadManager> dlm(new DownloadManager);
819 dlm->Init(this);
820 created_download_manager_ = true;
821 download_manager_.swap(dlm);
822 }
823 return download_manager_.get();
824}
825
826bool ProfileImpl::HasCreatedDownloadManager() const {
827 return created_download_manager_;
828}
829
[email protected]4a190632009-05-09 01:07:42830void ProfileImpl::InitThemes() {
831 if (!created_theme_provider_) {
832 scoped_refptr<BrowserThemeProvider> themes(new BrowserThemeProvider);
833 themes->Init(this);
834 created_theme_provider_ = true;
835 theme_provider_.swap(themes);
836 }
837}
838
839void ProfileImpl::SetTheme(Extension* extension) {
840 InitThemes();
841 theme_provider_.get()->SetTheme(extension);
842}
843
844void ProfileImpl::ClearTheme() {
845 InitThemes();
846 theme_provider_.get()->UseDefaultTheme();
847}
848
849ThemeProvider* ProfileImpl::GetThemeProvider() {
850 InitThemes();
851 return theme_provider_.get();
852}
853
initial.commit09911bf2008-07-26 23:55:29854SessionService* ProfileImpl::GetSessionService() {
855 if (!session_service_.get() && !shutdown_session_service_) {
856 session_service_ = new SessionService(this);
857 session_service_->ResetFromCurrentBrowsers();
858 }
859 return session_service_.get();
860}
861
862void ProfileImpl::ShutdownSessionService() {
863 if (shutdown_session_service_)
864 return;
865
866 // We're about to exit, force creation of the session service if it hasn't
867 // been created yet. We do this to ensure session state matches the point in
868 // time the user exited.
869 GetSessionService();
870 shutdown_session_service_ = true;
871 session_service_ = NULL;
872}
873
874bool ProfileImpl::HasSessionService() const {
875 return (session_service_.get() != NULL);
876}
877
878std::wstring ProfileImpl::GetName() {
879 return GetPrefs()->GetString(prefs::kProfileName);
880}
881void ProfileImpl::SetName(const std::wstring& name) {
882 GetPrefs()->SetString(prefs::kProfileName, name);
883}
884
885std::wstring ProfileImpl::GetID() {
886 return GetPrefs()->GetString(prefs::kProfileID);
887}
888void ProfileImpl::SetID(const std::wstring& id) {
889 GetPrefs()->SetString(prefs::kProfileID, id);
890}
891
initial.commit09911bf2008-07-26 23:55:29892bool ProfileImpl::DidLastSessionExitCleanly() {
893 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
894 // it to be set by asking for the prefs.
895 GetPrefs();
896 return last_session_exited_cleanly_;
897}
898
[email protected]d8e41ed2008-09-11 15:22:32899BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:46900 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:32901 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:46902 bookmark_bar_model_->Load();
903 }
initial.commit09911bf2008-07-26 23:55:29904 return bookmark_bar_model_.get();
905}
906
907bool ProfileImpl::IsSameProfile(Profile* profile) {
908 if (profile == static_cast<Profile*>(this))
909 return true;
910 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
911 return otr_profile && profile == static_cast<Profile*>(otr_profile);
912}
913
914Time ProfileImpl::GetStartTime() const {
915 return start_time_;
916}
917
918TabRestoreService* ProfileImpl::GetTabRestoreService() {
919 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:19920 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:29921 return tab_restore_service_.get();
922}
923
924void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:19925 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29926}
927
[email protected]a9afddb2009-02-12 17:49:42928// To be run in the IO thread to notify all resource message filters that the
[email protected]20930852008-10-15 19:30:41929// spellchecker has changed.
930class NotifySpellcheckerChangeTask : public Task {
931 public:
932 NotifySpellcheckerChangeTask(
[email protected]e7244d82008-10-29 18:13:26933 Profile* profile,
934 const SpellcheckerReinitializedDetails& spellchecker)
[email protected]20930852008-10-15 19:30:41935 : profile_(profile),
936 spellchecker_(spellchecker) {
937 }
938
939 private:
940 void Run(void) {
941 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56942 NotificationType::SPELLCHECKER_REINITIALIZED,
[email protected]20930852008-10-15 19:30:41943 Source<Profile>(profile_),
944 Details<SpellcheckerReinitializedDetails>(&spellchecker_));
945 }
946
947 Profile* profile_;
948 SpellcheckerReinitializedDetails spellchecker_;
949};
950
[email protected]e7244d82008-10-29 18:13:26951void ProfileImpl::InitializeSpellChecker(bool need_to_broadcast) {
[email protected]20930852008-10-15 19:30:41952 // The I/O thread may be NULL during testing.
953 base::Thread* io_thread = g_browser_process->io_thread();
954 if (spellchecker_) {
955 // The spellchecker must be deleted on the I/O thread.
956 // A dummy variable to aid in logical clarity.
957 SpellChecker* last_spellchecker = spellchecker_;
958
959 if (io_thread)
960 io_thread->message_loop()->ReleaseSoon(FROM_HERE, last_spellchecker);
961 else // during testing, we don't have an I/O thread
962 last_spellchecker->Release();
[email protected]20930852008-10-15 19:30:41963 }
964
[email protected]20930852008-10-15 19:30:41965 // Retrieve the (perhaps updated recently) dictionary name from preferences.
966 PrefService* prefs = GetPrefs();
[email protected]e7244d82008-10-29 18:13:26967 bool enable_spellcheck = prefs->GetBoolean(prefs::kEnableSpellCheck);
[email protected]20930852008-10-15 19:30:41968
[email protected]e7244d82008-10-29 18:13:26969 if (enable_spellcheck) {
[email protected]bd17b702009-02-25 20:44:08970 FilePath dict_dir;
[email protected]e7244d82008-10-29 18:13:26971 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
[email protected]a9afddb2009-02-12 17:49:42972 // Note that, as the object pointed to by previously by spellchecker_
[email protected]e7244d82008-10-29 18:13:26973 // is being deleted in the io thread, the spellchecker_ can be made to point
974 // to a new object (RE-initialized) in parallel in this UI thread.
[email protected]4b4d1adc2008-12-10 22:28:58975 spellchecker_ = new SpellChecker(dict_dir,
[email protected]74c8b422009-03-11 00:34:12976 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
977 GetRequestContext(),
[email protected]bd17b702009-02-25 20:44:08978 FilePath());
[email protected]e7244d82008-10-29 18:13:26979 spellchecker_->AddRef(); // Manual refcounting.
980 } else {
981 spellchecker_ = NULL;
982 }
[email protected]20930852008-10-15 19:30:41983
[email protected]154a4332009-06-03 20:20:58984 // Set auto spell correct status for spellchecker.
985 if (spellchecker_) {
986 spellchecker_->EnableAutoSpellCorrect(
987 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
988 }
989
[email protected]20930852008-10-15 19:30:41990 if (need_to_broadcast && io_thread) { // Notify resource message filters.
991 SpellcheckerReinitializedDetails scoped_spellchecker;
992 scoped_spellchecker.spellchecker = spellchecker_;
[email protected]e7244d82008-10-29 18:13:26993 if (io_thread) {
994 io_thread->message_loop()->PostTask(
[email protected]a9afddb2009-02-12 17:49:42995 FROM_HERE,
[email protected]e7244d82008-10-29 18:13:26996 new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
997 }
[email protected]20930852008-10-15 19:30:41998 }
999}
1000
[email protected]e7244d82008-10-29 18:13:261001void ProfileImpl::ReinitializeSpellChecker() {
1002 InitializeSpellChecker(true);
1003}
1004
initial.commit09911bf2008-07-26 23:55:291005SpellChecker* ProfileImpl::GetSpellChecker() {
1006 if (!spellchecker_) {
[email protected]20930852008-10-15 19:30:411007 // This is where spellchecker gets initialized. Note that this is being
1008 // initialized in the ui_thread. However, this is not a problem as long as
1009 // it is *used* in the io thread.
[email protected]34cc84f2009-02-13 10:04:351010 // TODO(sidchat): One day, change everything so that spellchecker gets
[email protected]20930852008-10-15 19:30:411011 // initialized in the IO thread itself.
[email protected]e7244d82008-10-29 18:13:261012 InitializeSpellChecker(false);
initial.commit09911bf2008-07-26 23:55:291013 }
[email protected]20930852008-10-15 19:30:411014
initial.commit09911bf2008-07-26 23:55:291015 return spellchecker_;
1016}
1017
1018void ProfileImpl::MarkAsCleanShutdown() {
1019 if (prefs_.get()) {
1020 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1021 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1022
1023 // NOTE: If you change what thread this writes on, be sure and update
1024 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361025 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291026 }
1027}
1028
[email protected]e7244d82008-10-29 18:13:261029void ProfileImpl::Observe(NotificationType type,
1030 const NotificationSource& source,
1031 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561032 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261033 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1034 PrefService* prefs = Source<PrefService>(source).ptr();
1035 DCHECK(pref_name_in && prefs);
1036 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]154a4332009-06-03 20:20:581037 *pref_name_in == prefs::kEnableSpellCheck ||
1038 *pref_name_in == prefs::kEnableAutoSpellCorrect) {
[email protected]e7244d82008-10-29 18:13:261039 InitializeSpellChecker(true);
1040 }
[email protected]4a190632009-05-09 01:07:421041 } else if (NotificationType::THEME_INSTALLED == type) {
1042 Extension* extension = Details<Extension>(details).ptr();
1043 SetTheme(extension);
[email protected]e7244d82008-10-29 18:13:261044 }
1045}
1046
initial.commit09911bf2008-07-26 23:55:291047void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141048 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291049}
[email protected]3a453fa2008-08-15 18:46:341050
1051#ifdef CHROME_PERSONALIZATION
[email protected]57d3d0a2008-09-24 00:50:071052ProfilePersonalization* ProfileImpl::GetProfilePersonalization() {
[email protected]57d3d0a2008-09-24 00:50:071053 return personalization_.get();
[email protected]3a453fa2008-08-15 18:46:341054}
license.botbf09a502008-08-24 00:55:551055#endif