blob: 3e8b1964f652615e1dc38448115f2785d2940d8b [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]67a46b7f2009-06-16 21:41:0216#include "chrome/browser/browser_theme_provider.h"
[email protected]b7f05882009-02-22 01:21:5617#include "chrome/browser/download/download_manager.h"
[email protected]481e1a42009-05-06 20:56:0518#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2519#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3520#include "chrome/browser/extensions/user_script_master.h"
[email protected]a9afddb2009-02-12 17:49:4221#include "chrome/browser/history/history.h"
[email protected]6ab9b202008-12-23 22:34:5022#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]e69d33952009-06-03 22:00:4123#include "chrome/browser/password_manager/password_store_default.h"
initial.commit09911bf2008-07-26 23:55:2924#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2625#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3326#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4627#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4428#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3029#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]f0a644292009-02-25 23:32:4730#include "chrome/browser/spellchecker.h"
[email protected]1132436e2009-04-08 20:06:3331#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]449478302009-06-09 20:04:2832#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/browser/visitedlink_master.h"
34#include "chrome/browser/webdata/web_data_service.h"
35#include "chrome/common/chrome_constants.h"
36#include "chrome/common/chrome_paths.h"
37#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5838#include "chrome/common/extensions/extension_error_reporter.h"
[email protected]47accfd62009-05-14 18:46:2139#include "chrome/common/net/cookie_monster_sqlite.h"
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/common/notification_service.h"
41#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3242#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5843#include "grit/locale_settings.h"
[email protected]a9cea7542009-05-20 04:30:2344#include "net/base/force_tls_state.h"
initial.commit09911bf2008-07-26 23:55:2945
[email protected]e1acf6f2008-10-27 20:43:3346using base::Time;
47using base::TimeDelta;
48
initial.commit09911bf2008-07-26 23:55:2949// Delay, in milliseconds, before we explicitly create the SessionService.
50static const int kCreateSessionServiceDelayMS = 500;
51
52// A pointer to the request context for the default profile. See comments on
53// Profile::GetDefaultRequestContext.
54URLRequestContext* Profile::default_request_context_;
55
[email protected]47accfd62009-05-14 18:46:2156static void CleanupRequestContext(ChromeURLRequestContext* context) {
57 if (context) {
58 context->CleanupOnUIThread();
59
60 // Clean up request context on IO thread.
61 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE,
62 context);
63 }
64}
65
[email protected]34cc84f2009-02-13 10:04:3566// static
initial.commit09911bf2008-07-26 23:55:2967void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:5568 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:2969 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
70 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:1271 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:2672 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
73 IDS_SPELLCHECK_DICTIONARY);
74 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:5875 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]f93fe782009-02-19 01:26:1376 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
[email protected]4a190632009-05-09 01:07:4277 prefs->RegisterStringPref(prefs::kCurrentThemeID, L"");
78 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
79 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
80 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:5081 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]f93fe782009-02-19 01:26:1382 prefs->RegisterBooleanPref(prefs::kEnableExtensions, false);
initial.commit09911bf2008-07-26 23:55:2983}
84
[email protected]34cc84f2009-02-13 10:04:3585// static
[email protected]f7011fcb2009-01-28 21:54:3286Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:2987 return new ProfileImpl(path);
88}
89
[email protected]34cc84f2009-02-13 10:04:3590// static
initial.commit09911bf2008-07-26 23:55:2991URLRequestContext* Profile::GetDefaultRequestContext() {
92 return default_request_context_;
93}
94
[email protected]e69d33952009-06-03 22:00:4195#if defined(OS_LINUX)
96// Temporarily disabled while we figure some stuff out.
97// http://code.google.com/p/chromium/issues/detail?id=12351
98// #include "chrome/browser/password_manager/password_store_gnome.h"
99// #include "chrome/browser/password_manager/password_store_kwallet.h"
100#elif defined(OS_WIN)
101#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56102#elif defined(OS_MACOSX)
103#include "chrome/browser/keychain_mac.h"
104#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41105#endif
initial.commit09911bf2008-07-26 23:55:29106
initial.commit09911bf2008-07-26 23:55:29107////////////////////////////////////////////////////////////////////////////////
108//
109// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42110// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29111//
112////////////////////////////////////////////////////////////////////////////////
113class OffTheRecordProfileImpl : public Profile,
114 public NotificationObserver {
115 public:
116 explicit OffTheRecordProfileImpl(Profile* real_profile)
117 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21118 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29119 start_time_(Time::Now()) {
[email protected]6ab9b202008-12-23 22:34:50120 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this);
initial.commit09911bf2008-07-26 23:55:29121 request_context_->AddRef();
[email protected]481e1a42009-05-06 20:56:05122
initial.commit09911bf2008-07-26 23:55:29123 // Register for browser close notifications so we can detect when the last
124 // off-the-record window is closed, in which case we can clean our states
125 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43126 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
127 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29128 }
129
130 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21131 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21132 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29133 }
134
[email protected]f7011fcb2009-01-28 21:54:32135 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29136
137 virtual bool IsOffTheRecord() {
138 return true;
139 }
140
141 virtual Profile* GetOffTheRecordProfile() {
142 return this;
143 }
144
[email protected]860f55492009-03-27 19:50:59145 virtual void DestroyOffTheRecordProfile() {
146 // Suicide is bad!
147 NOTREACHED();
148 }
149
initial.commit09911bf2008-07-26 23:55:29150 virtual Profile* GetOriginalProfile() {
151 return profile_;
152 }
153
154 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49155 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
156 // because we don't want to leak the sites that the user has visited before.
157 return NULL;
initial.commit09911bf2008-07-26 23:55:29158 }
159
[email protected]6014d672008-12-05 00:38:25160 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34161 return NULL;
[email protected]6014d672008-12-05 00:38:25162 }
163
[email protected]0938d3c2009-01-09 20:37:35164 virtual UserScriptMaster* GetUserScriptMaster() {
165 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25166 }
167
[email protected]481e1a42009-05-06 20:56:05168 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34169 return NULL;
[email protected]481e1a42009-05-06 20:56:05170 }
171
[email protected]34cc84f2009-02-13 10:04:35172 virtual SSLHostState* GetSSLHostState() {
173 if (!ssl_host_state_.get())
174 ssl_host_state_.reset(new SSLHostState());
175
176 DCHECK(ssl_host_state_->CalledOnValidThread());
177 return ssl_host_state_.get();
178 }
179
[email protected]a9cea7542009-05-20 04:30:23180 virtual net::ForceTLSState* GetForceTLSState() {
181 if (!force_tls_state_.get())
182 force_tls_state_.reset(new net::ForceTLSState());
183
184 return force_tls_state_.get();
185 }
186
initial.commit09911bf2008-07-26 23:55:29187 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
188 if (sat == EXPLICIT_ACCESS) {
189 return profile_->GetHistoryService(sat);
190 } else {
191 NOTREACHED() << "This profile is OffTheRecord";
192 return NULL;
193 }
194 }
195
initial.commit09911bf2008-07-26 23:55:29196 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
197 if (sat == EXPLICIT_ACCESS) {
198 return profile_->GetWebDataService(sat);
199 } else {
200 NOTREACHED() << "This profile is OffTheRecord";
201 return NULL;
202 }
203 }
204
[email protected]e69d33952009-06-03 22:00:41205 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
206 if (sat == EXPLICIT_ACCESS) {
207 return profile_->GetPasswordStore(sat);
208 } else {
209 NOTREACHED() << "This profile is OffTheRecord";
210 return NULL;
211 }
212 }
213
initial.commit09911bf2008-07-26 23:55:29214 virtual PrefService* GetPrefs() {
215 return profile_->GetPrefs();
216 }
217
218 virtual TemplateURLModel* GetTemplateURLModel() {
219 return profile_->GetTemplateURLModel();
220 }
221
222 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
223 return profile_->GetTemplateURLFetcher();
224 }
225
226 virtual DownloadManager* GetDownloadManager() {
227 if (!download_manager_.get()) {
228 scoped_refptr<DownloadManager> dlm(new DownloadManager);
229 dlm->Init(this);
230 download_manager_.swap(dlm);
231 }
232 return download_manager_.get();
233 }
234
235 virtual bool HasCreatedDownloadManager() const {
236 return (download_manager_.get() != NULL);
237 }
238
[email protected]4a190632009-05-09 01:07:42239 virtual void InitThemes() {
240 GetOriginalProfile()->InitThemes();
241 }
242
243 virtual void SetTheme(Extension* extension) {
244 GetOriginalProfile()->SetTheme(extension);
245 }
246
247 virtual void ClearTheme() {
248 GetOriginalProfile()->ClearTheme();
249 }
250
251 virtual ThemeProvider* GetThemeProvider() {
252 return GetOriginalProfile()->GetThemeProvider();
253 }
254
initial.commit09911bf2008-07-26 23:55:29255 virtual URLRequestContext* GetRequestContext() {
256 return request_context_;
257 }
258
[email protected]e7f29642009-03-02 22:53:18259 virtual URLRequestContext* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11260 // In OTR mode, media request context is the same as the original one.
261 return request_context_;
[email protected]e7f29642009-03-02 22:53:18262 }
263
[email protected]47accfd62009-05-14 18:46:21264 URLRequestContext* GetRequestContextForExtensions() {
265 if (!extensions_request_context_) {
266 extensions_request_context_ =
267 ChromeURLRequestContext::CreateOffTheRecordForExtensions(this);
268 extensions_request_context_->AddRef();
269
270 DCHECK(extensions_request_context_->cookie_store());
271 }
272
273 return extensions_request_context_;
274 }
275
initial.commit09911bf2008-07-26 23:55:29276 virtual SessionService* GetSessionService() {
277 // Don't save any sessions when off the record.
278 return NULL;
279 }
280
281 virtual void ShutdownSessionService() {
282 // We don't allow a session service, nothing to do.
283 }
284
285 virtual bool HasSessionService() const {
286 // We never have a session service.
287 return false;
288 }
289
290 virtual std::wstring GetName() {
291 return profile_->GetName();
292 }
293
294 virtual void SetName(const std::wstring& name) {
295 profile_->SetName(name);
296 }
297
298 virtual std::wstring GetID() {
299 return profile_->GetID();
300 }
301
302 virtual void SetID(const std::wstring& id) {
303 profile_->SetID(id);
304 }
305
initial.commit09911bf2008-07-26 23:55:29306 virtual bool DidLastSessionExitCleanly() {
307 return profile_->DidLastSessionExitCleanly();
308 }
309
[email protected]d8e41ed2008-09-11 15:22:32310 virtual BookmarkModel* GetBookmarkModel() {
311 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29312 }
313
[email protected]3a453fa2008-08-15 18:46:34314#ifdef CHROME_PERSONALIZATION
[email protected]57d3d0a2008-09-24 00:50:07315 virtual ProfilePersonalization* GetProfilePersonalization() {
[email protected]3a453fa2008-08-15 18:46:34316 return profile_->GetProfilePersonalization();
317 }
318#endif
319
initial.commit09911bf2008-07-26 23:55:29320 virtual bool IsSameProfile(Profile* profile) {
321 if (profile == static_cast<Profile*>(this))
322 return true;
323 return profile == profile_;
324 }
325
326 virtual Time GetStartTime() const {
327 return start_time_;
328 }
329
330 virtual TabRestoreService* GetTabRestoreService() {
331 return NULL;
332 }
333
[email protected]e7244d82008-10-29 18:13:26334 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41335 }
336
[email protected]e7244d82008-10-29 18:13:26337 virtual void ReinitializeSpellChecker() {
338 profile_->ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:29339 }
340
341 virtual SpellChecker* GetSpellChecker() {
342 return profile_->GetSpellChecker();
343 }
344
[email protected]449478302009-06-09 20:04:28345 virtual ThumbnailStore* GetThumbnailStore() {
346 return NULL;
347 }
348
initial.commit09911bf2008-07-26 23:55:29349 virtual void MarkAsCleanShutdown() {
350 }
351
[email protected]bdbc87c2009-01-25 05:08:54352 virtual void InitExtensions() {
353 NOTREACHED();
354 }
355
initial.commit09911bf2008-07-26 23:55:29356 virtual void ExitedOffTheRecordMode() {
357 // Drop our download manager so we forget about all the downloads made
358 // in off-the-record mode.
359 download_manager_ = NULL;
360 }
361
362 virtual void Observe(NotificationType type,
363 const NotificationSource& source,
364 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56365 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29366 // We are only interested in OTR browser closing.
367 if (Source<Browser>(source)->profile() != this)
368 return;
369
370 // Let's check if we still have an Off The Record window opened.
371 // Note that we check against 1 as this notification is sent before the
372 // browser window is actually removed from the list.
373 if (BrowserList::GetBrowserCount(this) <= 1)
374 ExitedOffTheRecordMode();
375 }
376
377 private:
[email protected]88cf3292009-05-22 01:48:43378 NotificationRegistrar registrar_;
379
initial.commit09911bf2008-07-26 23:55:29380 // The real underlying profile.
381 Profile* profile_;
382
[email protected]6ab9b202008-12-23 22:34:50383 // The context to use for requests made from this OTR session.
384 ChromeURLRequestContext* request_context_;
initial.commit09911bf2008-07-26 23:55:29385
[email protected]47accfd62009-05-14 18:46:21386 ChromeURLRequestContext* extensions_request_context_;
387
initial.commit09911bf2008-07-26 23:55:29388 // The download manager that only stores downloaded items in memory.
389 scoped_refptr<DownloadManager> download_manager_;
390
[email protected]4a190632009-05-09 01:07:42391 // The download manager that only stores downloaded items in memory.
392 scoped_refptr<BrowserThemeProvider> theme_provider_;
393
[email protected]34cc84f2009-02-13 10:04:35394 // We don't want SSLHostState from the OTR profile to leak back to the main
395 // profile because then the main profile would learn some of the host names
396 // the user visited while OTR.
397 scoped_ptr<SSLHostState> ssl_host_state_;
398
[email protected]a9cea7542009-05-20 04:30:23399 // The ForceTLSState that only stores enabled sites in memory.
400 scoped_ptr<net::ForceTLSState> force_tls_state_;
401
initial.commit09911bf2008-07-26 23:55:29402 // Time we were started.
403 Time start_time_;
404
405 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl);
406};
407
[email protected]f7011fcb2009-01-28 21:54:32408ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29409 : path_(path),
[email protected]f7011fcb2009-01-28 21:54:32410 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57411 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21412 extensions_request_context_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32413 history_service_created_(false),
414 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41415 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32416 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42417 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32418 start_time_(Time::Now()),
419 spellchecker_(NULL),
initial.commit09911bf2008-07-26 23:55:29420 shutdown_session_service_(false) {
421 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
422 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14423 create_session_service_timer_.Start(
424 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
425 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54426
[email protected]481e1a42009-05-06 20:56:05427 extension_process_manager_.reset(new ExtensionProcessManager(this));
428
[email protected]e7244d82008-10-29 18:13:26429 PrefService* prefs = GetPrefs();
430 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
431 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58432 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58433
434#ifdef CHROME_PERSONALIZATION
435 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableP13n))
436 personalization_.reset(Personalization::CreateProfilePersonalization(this));
437#endif
438
[email protected]1351b6a2009-04-09 20:13:22439#if defined(OS_LINUX)
440 // TODO(port): Remove ifdef when the Linux splash page is not needed.
441 prefs->transient()->SetString(prefs::kHomePage, "about:linux-splash");
442 prefs->transient()->SetBoolean(prefs::kHomePageIsNewTabPage, false);
443#endif
[email protected]4a190632009-05-09 01:07:42444
445 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43446 registrar_.Add(this, NotificationType::THEME_INSTALLED,
447 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29448}
449
[email protected]bdbc87c2009-01-25 05:08:54450void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41451 if (user_script_master_ || extensions_service_)
452 return; // Already initialized.
453
[email protected]bdbc87c2009-01-25 05:08:54454 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]f93fe782009-02-19 01:26:13455 PrefService* prefs = GetPrefs();
[email protected]bdbc87c2009-01-25 05:08:54456 bool user_scripts_enabled =
[email protected]f0a51fb52009-03-05 12:46:38457 command_line->HasSwitch(switches::kEnableUserScripts) ||
[email protected]f93fe782009-02-19 01:26:13458 prefs->GetBoolean(prefs::kEnableUserScripts);
[email protected]bdbc87c2009-01-25 05:08:54459
[email protected]f7011fcb2009-01-28 21:54:32460 FilePath script_dir;
[email protected]bdbc87c2009-01-25 05:08:54461 if (user_scripts_enabled) {
[email protected]0cd957b2009-03-06 20:13:23462 if (command_line->HasSwitch(switches::kUserScriptsDir)) {
463 std::wstring path_string =
464 command_line->GetSwitchValue(switches::kUserScriptsDir);
465 script_dir = FilePath::FromWStringHack(path_string);
466 } else {
467 script_dir = GetPath();
468 script_dir = script_dir.Append(chrome::kUserScriptsDirname);
469 }
[email protected]bdbc87c2009-01-25 05:08:54470 }
471
[email protected]bb28e062009-02-27 17:19:18472 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]bdbc87c2009-01-25 05:08:54473 user_script_master_ = new UserScriptMaster(
[email protected]9197f3b2009-06-02 00:49:27474 g_browser_process->file_thread()->message_loop(),
475 script_dir);
[email protected]894bb502009-05-21 22:39:57476 extensions_service_ = new ExtensionsService(
477 this, MessageLoop::current(),
[email protected]a1257b12009-06-12 02:51:34478 g_browser_process->file_thread()->message_loop());
[email protected]bdbc87c2009-01-25 05:08:54479
[email protected]9197f3b2009-06-02 00:49:27480 extensions_service_->Init();
[email protected]bdbc87c2009-01-25 05:08:54481}
482
initial.commit09911bf2008-07-26 23:55:29483ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19484 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29485
486 StopCreateSessionServiceTimer();
487 // TemplateURLModel schedules a task on the WebDataService from its
488 // destructor. Delete it first to ensure the task gets scheduled before we
489 // shut down the database.
490 template_url_model_.reset();
491
492 // The download manager queries the history system and should be deleted
493 // before the history is shutdown so it can properly cancel all requests.
494 download_manager_ = NULL;
495
[email protected]4a190632009-05-09 01:07:42496 // The theme provider provides bitmaps to whoever wants them.
497 theme_provider_ = NULL;
498
[email protected]e7244d82008-10-29 18:13:26499 // Remove pref observers.
500 PrefService* prefs = GetPrefs();
501 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
502 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58503 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26504
[email protected]3a453fa2008-08-15 18:46:34505#ifdef CHROME_PERSONALIZATION
[email protected]57d3d0a2008-09-24 00:50:07506 personalization_.reset();
[email protected]3a453fa2008-08-15 18:46:34507#endif
508
initial.commit09911bf2008-07-26 23:55:29509 // Both HistoryService and WebDataService maintain threads for background
510 // processing. Its possible each thread still has tasks on it that have
511 // increased the ref count of the service. In such a situation, when we
512 // decrement the refcount, it won't be 0, and the threads/databases aren't
513 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
514 // databases are properly closed.
515 if (web_data_service_.get())
516 web_data_service_->Shutdown();
517
518 if (history_service_.get())
519 history_service_->Cleanup();
520
521 // The I/O thread may be NULL during testing.
[email protected]ab820df2008-08-26 05:55:10522 base::Thread* io_thread = g_browser_process->io_thread();
initial.commit09911bf2008-07-26 23:55:29523
524 if (spellchecker_) {
525 // The spellchecker must be deleted on the I/O thread. During testing, we
526 // don't have an I/O thread.
527 if (io_thread)
528 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
529 else
530 spellchecker_->Release();
531 }
532
[email protected]47accfd62009-05-14 18:46:21533 if (default_request_context_ == request_context_)
534 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50535
[email protected]47accfd62009-05-14 18:46:21536 CleanupRequestContext(request_context_);
537 CleanupRequestContext(media_request_context_);
538 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17539
[email protected]d8e41ed2008-09-11 15:22:32540 // HistoryService may call into the BookmarkModel, as such we need to
541 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46542 // HistoryService will join with HistoryService's backend thread so that
543 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32544 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46545 history_service_ = NULL;
546 bookmark_bar_model_.reset();
547
initial.commit09911bf2008-07-26 23:55:29548 MarkAsCleanShutdown();
549}
550
[email protected]f7011fcb2009-01-28 21:54:32551FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29552 return path_;
553}
554
555bool ProfileImpl::IsOffTheRecord() {
556 return false;
557}
558
559Profile* ProfileImpl::GetOffTheRecordProfile() {
560 if (!off_the_record_profile_.get()) {
561 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
562 off_the_record_profile_.swap(p);
563 }
564 return off_the_record_profile_.get();
565}
566
[email protected]860f55492009-03-27 19:50:59567void ProfileImpl::DestroyOffTheRecordProfile() {
568 off_the_record_profile_.reset();
569}
570
initial.commit09911bf2008-07-26 23:55:29571Profile* ProfileImpl::GetOriginalProfile() {
572 return this;
573}
574
[email protected]176aa482008-11-14 03:25:15575static void BroadcastNewHistoryTable(base::SharedMemory* table_memory) {
initial.commit09911bf2008-07-26 23:55:29576 if (!table_memory)
577 return;
578
579 // send to all RenderProcessHosts
580 for (RenderProcessHost::iterator i = RenderProcessHost::begin();
581 i != RenderProcessHost::end(); i++) {
582 if (!i->second->channel())
583 continue;
584
[email protected]176aa482008-11-14 03:25:15585 base::SharedMemoryHandle new_table;
[email protected]f7011fcb2009-01-28 21:54:32586 base::ProcessHandle process = i->second->process().handle();
initial.commit09911bf2008-07-26 23:55:29587 if (!process) {
588 // process can be null if it's started with the --single-process flag.
[email protected]f7011fcb2009-01-28 21:54:32589 process = base::Process::Current().handle();
initial.commit09911bf2008-07-26 23:55:29590 }
591
592 table_memory->ShareToProcess(process, &new_table);
593 IPC::Message* msg = new ViewMsg_VisitedLink_NewTable(new_table);
594 i->second->channel()->Send(msg);
595 }
596}
597
598VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
599 if (!visited_link_master_.get()) {
600 scoped_ptr<VisitedLinkMaster> visited_links(
601 new VisitedLinkMaster(g_browser_process->file_thread(),
602 BroadcastNewHistoryTable, this));
603 if (!visited_links->Init())
604 return NULL;
605 visited_link_master_.swap(visited_links);
606 }
607
608 return visited_link_master_.get();
609}
610
[email protected]6014d672008-12-05 00:38:25611ExtensionsService* ProfileImpl::GetExtensionsService() {
612 return extensions_service_.get();
613}
614
[email protected]0938d3c2009-01-09 20:37:35615UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35616 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25617}
618
[email protected]481e1a42009-05-06 20:56:05619ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
620 return extension_process_manager_.get();
621}
622
[email protected]34cc84f2009-02-13 10:04:35623SSLHostState* ProfileImpl::GetSSLHostState() {
624 if (!ssl_host_state_.get())
625 ssl_host_state_.reset(new SSLHostState());
626
627 DCHECK(ssl_host_state_->CalledOnValidThread());
628 return ssl_host_state_.get();
629}
630
[email protected]a9cea7542009-05-20 04:30:23631net::ForceTLSState* ProfileImpl::GetForceTLSState() {
632 if (!force_tls_state_.get())
633 force_tls_state_.reset(new net::ForceTLSState());
634
635 return force_tls_state_.get();
636}
637
initial.commit09911bf2008-07-26 23:55:29638PrefService* ProfileImpl::GetPrefs() {
639 if (!prefs_.get()) {
[email protected]6faa0e0d2009-04-28 06:50:36640 prefs_.reset(new PrefService(GetPrefFilePath(),
641 g_browser_process->file_thread()));
initial.commit09911bf2008-07-26 23:55:29642
643 // The Profile class and ProfileManager class may read some prefs so
644 // register known prefs as soon as possible.
645 Profile::RegisterUserPrefs(prefs_.get());
646 ProfileManager::RegisterUserPrefs(prefs_.get());
647
648 // The last session exited cleanly if there is no pref for
649 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
650 last_session_exited_cleanly_ =
651 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
652 // Mark the session as open.
653 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
654 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36655 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29656 }
657
658 return prefs_.get();
659}
660
[email protected]f7011fcb2009-01-28 21:54:32661FilePath ProfileImpl::GetPrefFilePath() {
662 FilePath pref_file_path = path_;
663 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29664 return pref_file_path;
665}
666
667URLRequestContext* ProfileImpl::GetRequestContext() {
668 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32669 FilePath cookie_path = GetPath();
670 cookie_path = cookie_path.Append(chrome::kCookieFilename);
671 FilePath cache_path = GetPath();
[email protected]2b2830a2009-02-07 01:58:42672
673 // Override the cache location if specified by the user.
674 const std::wstring user_cache_dir(
675 CommandLine::ForCurrentProcess()->GetSwitchValue(
676 switches::kDiskCacheDir));
677 if (!user_cache_dir.empty()) {
678 cache_path = FilePath::FromWStringHack(user_cache_dir);
679 }
680
[email protected]f7011fcb2009-01-28 21:54:32681 cache_path = cache_path.Append(chrome::kCacheDirname);
[email protected]6ab9b202008-12-23 22:34:50682 request_context_ = ChromeURLRequestContext::CreateOriginal(
683 this, cookie_path, cache_path);
initial.commit09911bf2008-07-26 23:55:29684 request_context_->AddRef();
685
[email protected]6ab9b202008-12-23 22:34:50686 // The first request context is always a normal (non-OTR) request context.
687 // Even when Chromium is started in OTR mode, a normal profile is always
688 // created first.
689 if (!default_request_context_) {
690 default_request_context_ = request_context_;
691 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56692 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50693 NotificationService::AllSources(), NotificationService::NoDetails());
694 }
695
initial.commit09911bf2008-07-26 23:55:29696 DCHECK(request_context_->cookie_store());
697 }
698
699 return request_context_;
700}
701
[email protected]e7f29642009-03-02 22:53:18702URLRequestContext* ProfileImpl::GetRequestContextForMedia() {
703 if (!media_request_context_) {
704 FilePath cache_path = GetPath();
[email protected]e3edeba2009-03-23 18:57:14705
706 // Override the cache location if specified by the user.
707 const std::wstring user_cache_dir(
708 CommandLine::ForCurrentProcess()->GetSwitchValue(
709 switches::kDiskCacheDir));
710 if (!user_cache_dir.empty()) {
711 cache_path = FilePath::FromWStringHack(user_cache_dir);
712 }
713
[email protected]4e7b5dbb2009-03-25 00:09:23714 cache_path = cache_path.Append(chrome::kMediaCacheDirname);
[email protected]e7f29642009-03-02 22:53:18715 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia(
716 this, cache_path);
717 media_request_context_->AddRef();
718
719 DCHECK(media_request_context_->cookie_store());
720 }
721
722 return media_request_context_;
723}
724
[email protected]47accfd62009-05-14 18:46:21725URLRequestContext* ProfileImpl::GetRequestContextForExtensions() {
726 if (!extensions_request_context_) {
727 FilePath cookie_path = GetPath();
728 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
729
730 extensions_request_context_ =
731 ChromeURLRequestContext::CreateOriginalForExtensions(this, cookie_path);
732 extensions_request_context_->AddRef();
733
734 DCHECK(extensions_request_context_->cookie_store());
735 }
736
737 return extensions_request_context_;
738}
739
initial.commit09911bf2008-07-26 23:55:29740HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
741 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:46742 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:29743 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:32744 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:29745 return NULL;
746 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:29747
748 // Send out the notification that the history service was created.
749 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56750 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:29751 Details<HistoryService>(history_service_.get()));
752 }
753 return history_service_.get();
754}
755
initial.commit09911bf2008-07-26 23:55:29756TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
757 if (!template_url_model_.get())
758 template_url_model_.reset(new TemplateURLModel(this));
759 return template_url_model_.get();
760}
761
762TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
763 if (!template_url_fetcher_.get())
764 template_url_fetcher_.reset(new TemplateURLFetcher(this));
765 return template_url_fetcher_.get();
766}
767
768WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
769 if (!created_web_data_service_)
770 CreateWebDataService();
771 return web_data_service_.get();
772}
773
774void ProfileImpl::CreateWebDataService() {
775 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
776 created_web_data_service_ = true;
777 scoped_refptr<WebDataService> wds(new WebDataService());
778 if (!wds->Init(GetPath()))
779 return;
780 web_data_service_.swap(wds);
781}
782
[email protected]e69d33952009-06-03 22:00:41783PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
784 if (!created_password_store_)
785 CreatePasswordStore();
786 return password_store_.get();
787}
788
789void ProfileImpl::CreatePasswordStore() {
790 DCHECK(!created_password_store_ && password_store_.get() == NULL);
791 created_password_store_ = true;
792 scoped_refptr<PasswordStore> ps;
793#if defined(OS_LINUX)
794// Temporarily disabled while we figure some stuff out.
795// http://code.google.com/p/chromium/issues/detail?id=12351
796// if (getenv("KDE_FULL_SESSION")) {
797// ps = new PasswordStoreKWallet();
798// } else {
799// ps = new PasswordStoreGnome();
800// }
801 NOTIMPLEMENTED();
802#elif defined(OS_WIN)
803 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:56804#elif defined(OS_MACOSX)
805 ps = new PasswordStoreMac(new MacKeychain());
[email protected]e69d33952009-06-03 22:00:41806#else
807 NOTIMPLEMENTED();
808#endif
809 if (!ps || !ps->Init()) {
810 // Try falling back to the default password manager
811 LOG(WARNING) << "Could not initialise native password manager - "
812 "falling back to default";
813 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
814 if (!ps->Init())
815 return;
816 }
817 password_store_.swap(ps);
818}
819
initial.commit09911bf2008-07-26 23:55:29820DownloadManager* ProfileImpl::GetDownloadManager() {
821 if (!created_download_manager_) {
822 scoped_refptr<DownloadManager> dlm(new DownloadManager);
823 dlm->Init(this);
824 created_download_manager_ = true;
825 download_manager_.swap(dlm);
826 }
827 return download_manager_.get();
828}
829
830bool ProfileImpl::HasCreatedDownloadManager() const {
831 return created_download_manager_;
832}
833
[email protected]4a190632009-05-09 01:07:42834void ProfileImpl::InitThemes() {
835 if (!created_theme_provider_) {
836 scoped_refptr<BrowserThemeProvider> themes(new BrowserThemeProvider);
837 themes->Init(this);
838 created_theme_provider_ = true;
839 theme_provider_.swap(themes);
840 }
841}
842
843void ProfileImpl::SetTheme(Extension* extension) {
844 InitThemes();
845 theme_provider_.get()->SetTheme(extension);
846}
847
848void ProfileImpl::ClearTheme() {
849 InitThemes();
850 theme_provider_.get()->UseDefaultTheme();
851}
852
853ThemeProvider* ProfileImpl::GetThemeProvider() {
854 InitThemes();
855 return theme_provider_.get();
856}
857
initial.commit09911bf2008-07-26 23:55:29858SessionService* ProfileImpl::GetSessionService() {
859 if (!session_service_.get() && !shutdown_session_service_) {
860 session_service_ = new SessionService(this);
861 session_service_->ResetFromCurrentBrowsers();
862 }
863 return session_service_.get();
864}
865
866void ProfileImpl::ShutdownSessionService() {
867 if (shutdown_session_service_)
868 return;
869
870 // We're about to exit, force creation of the session service if it hasn't
871 // been created yet. We do this to ensure session state matches the point in
872 // time the user exited.
873 GetSessionService();
874 shutdown_session_service_ = true;
875 session_service_ = NULL;
876}
877
878bool ProfileImpl::HasSessionService() const {
879 return (session_service_.get() != NULL);
880}
881
882std::wstring ProfileImpl::GetName() {
883 return GetPrefs()->GetString(prefs::kProfileName);
884}
885void ProfileImpl::SetName(const std::wstring& name) {
886 GetPrefs()->SetString(prefs::kProfileName, name);
887}
888
889std::wstring ProfileImpl::GetID() {
890 return GetPrefs()->GetString(prefs::kProfileID);
891}
892void ProfileImpl::SetID(const std::wstring& id) {
893 GetPrefs()->SetString(prefs::kProfileID, id);
894}
895
initial.commit09911bf2008-07-26 23:55:29896bool ProfileImpl::DidLastSessionExitCleanly() {
897 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
898 // it to be set by asking for the prefs.
899 GetPrefs();
900 return last_session_exited_cleanly_;
901}
902
[email protected]d8e41ed2008-09-11 15:22:32903BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:46904 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:32905 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:46906 bookmark_bar_model_->Load();
907 }
initial.commit09911bf2008-07-26 23:55:29908 return bookmark_bar_model_.get();
909}
910
911bool ProfileImpl::IsSameProfile(Profile* profile) {
912 if (profile == static_cast<Profile*>(this))
913 return true;
914 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
915 return otr_profile && profile == static_cast<Profile*>(otr_profile);
916}
917
918Time ProfileImpl::GetStartTime() const {
919 return start_time_;
920}
921
922TabRestoreService* ProfileImpl::GetTabRestoreService() {
923 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:19924 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:29925 return tab_restore_service_.get();
926}
927
[email protected]449478302009-06-09 20:04:28928ThumbnailStore* ProfileImpl::GetThumbnailStore() {
929 if (!thumbnail_store_.get()) {
930 thumbnail_store_ = new ThumbnailStore;
931 thumbnail_store_->Init(GetPath().AppendASCII("thumbnailstore\\"));
932 }
933 return thumbnail_store_.get();
934}
935
initial.commit09911bf2008-07-26 23:55:29936void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:19937 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29938}
939
[email protected]a9afddb2009-02-12 17:49:42940// To be run in the IO thread to notify all resource message filters that the
[email protected]20930852008-10-15 19:30:41941// spellchecker has changed.
942class NotifySpellcheckerChangeTask : public Task {
943 public:
944 NotifySpellcheckerChangeTask(
[email protected]e7244d82008-10-29 18:13:26945 Profile* profile,
946 const SpellcheckerReinitializedDetails& spellchecker)
[email protected]20930852008-10-15 19:30:41947 : profile_(profile),
948 spellchecker_(spellchecker) {
949 }
950
951 private:
952 void Run(void) {
953 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56954 NotificationType::SPELLCHECKER_REINITIALIZED,
[email protected]20930852008-10-15 19:30:41955 Source<Profile>(profile_),
956 Details<SpellcheckerReinitializedDetails>(&spellchecker_));
957 }
958
959 Profile* profile_;
960 SpellcheckerReinitializedDetails spellchecker_;
961};
962
[email protected]e7244d82008-10-29 18:13:26963void ProfileImpl::InitializeSpellChecker(bool need_to_broadcast) {
[email protected]20930852008-10-15 19:30:41964 // The I/O thread may be NULL during testing.
965 base::Thread* io_thread = g_browser_process->io_thread();
966 if (spellchecker_) {
967 // The spellchecker must be deleted on the I/O thread.
968 // A dummy variable to aid in logical clarity.
969 SpellChecker* last_spellchecker = spellchecker_;
970
971 if (io_thread)
972 io_thread->message_loop()->ReleaseSoon(FROM_HERE, last_spellchecker);
973 else // during testing, we don't have an I/O thread
974 last_spellchecker->Release();
[email protected]20930852008-10-15 19:30:41975 }
976
[email protected]20930852008-10-15 19:30:41977 // Retrieve the (perhaps updated recently) dictionary name from preferences.
978 PrefService* prefs = GetPrefs();
[email protected]e7244d82008-10-29 18:13:26979 bool enable_spellcheck = prefs->GetBoolean(prefs::kEnableSpellCheck);
[email protected]20930852008-10-15 19:30:41980
[email protected]e7244d82008-10-29 18:13:26981 if (enable_spellcheck) {
[email protected]bd17b702009-02-25 20:44:08982 FilePath dict_dir;
[email protected]e7244d82008-10-29 18:13:26983 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
[email protected]a9afddb2009-02-12 17:49:42984 // Note that, as the object pointed to by previously by spellchecker_
[email protected]e7244d82008-10-29 18:13:26985 // is being deleted in the io thread, the spellchecker_ can be made to point
986 // to a new object (RE-initialized) in parallel in this UI thread.
[email protected]4b4d1adc2008-12-10 22:28:58987 spellchecker_ = new SpellChecker(dict_dir,
[email protected]74c8b422009-03-11 00:34:12988 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
989 GetRequestContext(),
[email protected]bd17b702009-02-25 20:44:08990 FilePath());
[email protected]e7244d82008-10-29 18:13:26991 spellchecker_->AddRef(); // Manual refcounting.
992 } else {
993 spellchecker_ = NULL;
994 }
[email protected]20930852008-10-15 19:30:41995
[email protected]154a4332009-06-03 20:20:58996 // Set auto spell correct status for spellchecker.
997 if (spellchecker_) {
998 spellchecker_->EnableAutoSpellCorrect(
999 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
1000 }
1001
[email protected]20930852008-10-15 19:30:411002 if (need_to_broadcast && io_thread) { // Notify resource message filters.
1003 SpellcheckerReinitializedDetails scoped_spellchecker;
1004 scoped_spellchecker.spellchecker = spellchecker_;
[email protected]e7244d82008-10-29 18:13:261005 if (io_thread) {
1006 io_thread->message_loop()->PostTask(
[email protected]a9afddb2009-02-12 17:49:421007 FROM_HERE,
[email protected]e7244d82008-10-29 18:13:261008 new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
1009 }
[email protected]20930852008-10-15 19:30:411010 }
1011}
1012
[email protected]e7244d82008-10-29 18:13:261013void ProfileImpl::ReinitializeSpellChecker() {
1014 InitializeSpellChecker(true);
1015}
1016
initial.commit09911bf2008-07-26 23:55:291017SpellChecker* ProfileImpl::GetSpellChecker() {
1018 if (!spellchecker_) {
[email protected]20930852008-10-15 19:30:411019 // This is where spellchecker gets initialized. Note that this is being
1020 // initialized in the ui_thread. However, this is not a problem as long as
1021 // it is *used* in the io thread.
[email protected]34cc84f2009-02-13 10:04:351022 // TODO(sidchat): One day, change everything so that spellchecker gets
[email protected]20930852008-10-15 19:30:411023 // initialized in the IO thread itself.
[email protected]e7244d82008-10-29 18:13:261024 InitializeSpellChecker(false);
initial.commit09911bf2008-07-26 23:55:291025 }
[email protected]20930852008-10-15 19:30:411026
initial.commit09911bf2008-07-26 23:55:291027 return spellchecker_;
1028}
1029
1030void ProfileImpl::MarkAsCleanShutdown() {
1031 if (prefs_.get()) {
1032 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1033 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1034
1035 // NOTE: If you change what thread this writes on, be sure and update
1036 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361037 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291038 }
1039}
1040
[email protected]e7244d82008-10-29 18:13:261041void ProfileImpl::Observe(NotificationType type,
1042 const NotificationSource& source,
1043 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561044 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261045 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1046 PrefService* prefs = Source<PrefService>(source).ptr();
1047 DCHECK(pref_name_in && prefs);
1048 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]154a4332009-06-03 20:20:581049 *pref_name_in == prefs::kEnableSpellCheck ||
1050 *pref_name_in == prefs::kEnableAutoSpellCorrect) {
[email protected]e7244d82008-10-29 18:13:261051 InitializeSpellChecker(true);
1052 }
[email protected]4a190632009-05-09 01:07:421053 } else if (NotificationType::THEME_INSTALLED == type) {
1054 Extension* extension = Details<Extension>(details).ptr();
1055 SetTheme(extension);
[email protected]e7244d82008-10-29 18:13:261056 }
1057}
1058
initial.commit09911bf2008-07-26 23:55:291059void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141060 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291061}
[email protected]3a453fa2008-08-15 18:46:341062
1063#ifdef CHROME_PERSONALIZATION
[email protected]57d3d0a2008-09-24 00:50:071064ProfilePersonalization* ProfileImpl::GetProfilePersonalization() {
[email protected]57d3d0a2008-09-24 00:50:071065 return personalization_.get();
[email protected]3a453fa2008-08-15 18:46:341066}
license.botbf09a502008-08-24 00:55:551067#endif