blob: 35bf8c2771329437f9abe51e77fb1551b84d5dc8 [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"
[email protected]eaadd9052009-06-23 18:02:2324#include "chrome/browser/privacy_blacklist/blacklist.h"
initial.commit09911bf2008-07-26 23:55:2925#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2626#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3327#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4628#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4429#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3030#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]f0a644292009-02-25 23:32:4731#include "chrome/browser/spellchecker.h"
[email protected]1132436e2009-04-08 20:06:3332#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]449478302009-06-09 20:04:2833#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/browser/visitedlink_master.h"
35#include "chrome/browser/webdata/web_data_service.h"
36#include "chrome/common/chrome_constants.h"
37#include "chrome/common/chrome_paths.h"
38#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5839#include "chrome/common/extensions/extension_error_reporter.h"
[email protected]47accfd62009-05-14 18:46:2140#include "chrome/common/net/cookie_monster_sqlite.h"
initial.commit09911bf2008-07-26 23:55:2941#include "chrome/common/notification_service.h"
42#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3243#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5844#include "grit/locale_settings.h"
[email protected]a9cea7542009-05-20 04:30:2345#include "net/base/force_tls_state.h"
initial.commit09911bf2008-07-26 23:55:2946
[email protected]e1acf6f2008-10-27 20:43:3347using base::Time;
48using base::TimeDelta;
49
initial.commit09911bf2008-07-26 23:55:2950// Delay, in milliseconds, before we explicitly create the SessionService.
51static const int kCreateSessionServiceDelayMS = 500;
52
53// A pointer to the request context for the default profile. See comments on
54// Profile::GetDefaultRequestContext.
55URLRequestContext* Profile::default_request_context_;
56
[email protected]47accfd62009-05-14 18:46:2157static void CleanupRequestContext(ChromeURLRequestContext* context) {
58 if (context) {
59 context->CleanupOnUIThread();
60
61 // Clean up request context on IO thread.
62 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE,
63 context);
64 }
65}
66
[email protected]34cc84f2009-02-13 10:04:3567// static
initial.commit09911bf2008-07-26 23:55:2968void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:5569 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:2970 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
71 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:1272 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:2673 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
74 IDS_SPELLCHECK_DICTIONARY);
75 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:5876 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]f93fe782009-02-19 01:26:1377 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
[email protected]4a190632009-05-09 01:07:4278 prefs->RegisterStringPref(prefs::kCurrentThemeID, L"");
79 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
80 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
81 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:5082 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]f93fe782009-02-19 01:26:1383 prefs->RegisterBooleanPref(prefs::kEnableExtensions, false);
initial.commit09911bf2008-07-26 23:55:2984}
85
[email protected]34cc84f2009-02-13 10:04:3586// static
[email protected]f7011fcb2009-01-28 21:54:3287Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:2988 return new ProfileImpl(path);
89}
90
[email protected]34cc84f2009-02-13 10:04:3591// static
initial.commit09911bf2008-07-26 23:55:2992URLRequestContext* Profile::GetDefaultRequestContext() {
93 return default_request_context_;
94}
95
[email protected]e69d33952009-06-03 22:00:4196#if defined(OS_LINUX)
97// Temporarily disabled while we figure some stuff out.
98// http://code.google.com/p/chromium/issues/detail?id=12351
99// #include "chrome/browser/password_manager/password_store_gnome.h"
100// #include "chrome/browser/password_manager/password_store_kwallet.h"
101#elif defined(OS_WIN)
102#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56103#elif defined(OS_MACOSX)
104#include "chrome/browser/keychain_mac.h"
105#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41106#endif
initial.commit09911bf2008-07-26 23:55:29107
initial.commit09911bf2008-07-26 23:55:29108////////////////////////////////////////////////////////////////////////////////
109//
110// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42111// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29112//
113////////////////////////////////////////////////////////////////////////////////
114class OffTheRecordProfileImpl : public Profile,
115 public NotificationObserver {
116 public:
117 explicit OffTheRecordProfileImpl(Profile* real_profile)
118 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21119 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29120 start_time_(Time::Now()) {
[email protected]6ab9b202008-12-23 22:34:50121 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this);
initial.commit09911bf2008-07-26 23:55:29122 request_context_->AddRef();
[email protected]481e1a42009-05-06 20:56:05123
initial.commit09911bf2008-07-26 23:55:29124 // Register for browser close notifications so we can detect when the last
125 // off-the-record window is closed, in which case we can clean our states
126 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43127 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
128 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29129 }
130
131 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21132 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21133 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29134 }
135
[email protected]f7011fcb2009-01-28 21:54:32136 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29137
138 virtual bool IsOffTheRecord() {
139 return true;
140 }
141
142 virtual Profile* GetOffTheRecordProfile() {
143 return this;
144 }
145
[email protected]860f55492009-03-27 19:50:59146 virtual void DestroyOffTheRecordProfile() {
147 // Suicide is bad!
148 NOTREACHED();
149 }
150
initial.commit09911bf2008-07-26 23:55:29151 virtual Profile* GetOriginalProfile() {
152 return profile_;
153 }
154
155 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49156 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
157 // because we don't want to leak the sites that the user has visited before.
158 return NULL;
initial.commit09911bf2008-07-26 23:55:29159 }
160
[email protected]6014d672008-12-05 00:38:25161 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34162 return NULL;
[email protected]6014d672008-12-05 00:38:25163 }
164
[email protected]0938d3c2009-01-09 20:37:35165 virtual UserScriptMaster* GetUserScriptMaster() {
166 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25167 }
168
[email protected]481e1a42009-05-06 20:56:05169 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34170 return NULL;
[email protected]481e1a42009-05-06 20:56:05171 }
172
[email protected]34cc84f2009-02-13 10:04:35173 virtual SSLHostState* GetSSLHostState() {
174 if (!ssl_host_state_.get())
175 ssl_host_state_.reset(new SSLHostState());
176
177 DCHECK(ssl_host_state_->CalledOnValidThread());
178 return ssl_host_state_.get();
179 }
180
[email protected]a9cea7542009-05-20 04:30:23181 virtual net::ForceTLSState* GetForceTLSState() {
182 if (!force_tls_state_.get())
183 force_tls_state_.reset(new net::ForceTLSState());
184
185 return force_tls_state_.get();
186 }
187
initial.commit09911bf2008-07-26 23:55:29188 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
189 if (sat == EXPLICIT_ACCESS) {
190 return profile_->GetHistoryService(sat);
191 } else {
192 NOTREACHED() << "This profile is OffTheRecord";
193 return NULL;
194 }
195 }
196
initial.commit09911bf2008-07-26 23:55:29197 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
198 if (sat == EXPLICIT_ACCESS) {
199 return profile_->GetWebDataService(sat);
200 } else {
201 NOTREACHED() << "This profile is OffTheRecord";
202 return NULL;
203 }
204 }
205
[email protected]e69d33952009-06-03 22:00:41206 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
207 if (sat == EXPLICIT_ACCESS) {
208 return profile_->GetPasswordStore(sat);
209 } else {
210 NOTREACHED() << "This profile is OffTheRecord";
211 return NULL;
212 }
213 }
214
initial.commit09911bf2008-07-26 23:55:29215 virtual PrefService* GetPrefs() {
216 return profile_->GetPrefs();
217 }
218
219 virtual TemplateURLModel* GetTemplateURLModel() {
220 return profile_->GetTemplateURLModel();
221 }
222
223 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
224 return profile_->GetTemplateURLFetcher();
225 }
226
227 virtual DownloadManager* GetDownloadManager() {
228 if (!download_manager_.get()) {
229 scoped_refptr<DownloadManager> dlm(new DownloadManager);
230 dlm->Init(this);
231 download_manager_.swap(dlm);
232 }
233 return download_manager_.get();
234 }
235
236 virtual bool HasCreatedDownloadManager() const {
237 return (download_manager_.get() != NULL);
238 }
239
[email protected]4a190632009-05-09 01:07:42240 virtual void InitThemes() {
241 GetOriginalProfile()->InitThemes();
242 }
243
244 virtual void SetTheme(Extension* extension) {
245 GetOriginalProfile()->SetTheme(extension);
246 }
247
248 virtual void ClearTheme() {
249 GetOriginalProfile()->ClearTheme();
250 }
251
252 virtual ThemeProvider* GetThemeProvider() {
253 return GetOriginalProfile()->GetThemeProvider();
254 }
255
initial.commit09911bf2008-07-26 23:55:29256 virtual URLRequestContext* GetRequestContext() {
257 return request_context_;
258 }
259
[email protected]e7f29642009-03-02 22:53:18260 virtual URLRequestContext* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11261 // In OTR mode, media request context is the same as the original one.
262 return request_context_;
[email protected]e7f29642009-03-02 22:53:18263 }
264
[email protected]47accfd62009-05-14 18:46:21265 URLRequestContext* GetRequestContextForExtensions() {
266 if (!extensions_request_context_) {
267 extensions_request_context_ =
268 ChromeURLRequestContext::CreateOffTheRecordForExtensions(this);
269 extensions_request_context_->AddRef();
270
271 DCHECK(extensions_request_context_->cookie_store());
272 }
273
274 return extensions_request_context_;
275 }
276
[email protected]eaadd9052009-06-23 18:02:23277 virtual Blacklist* GetBlacklist() {
278 return GetOriginalProfile()->GetBlacklist();
279 }
280
initial.commit09911bf2008-07-26 23:55:29281 virtual SessionService* GetSessionService() {
282 // Don't save any sessions when off the record.
283 return NULL;
284 }
285
286 virtual void ShutdownSessionService() {
287 // We don't allow a session service, nothing to do.
288 }
289
290 virtual bool HasSessionService() const {
291 // We never have a session service.
292 return false;
293 }
294
295 virtual std::wstring GetName() {
296 return profile_->GetName();
297 }
298
299 virtual void SetName(const std::wstring& name) {
300 profile_->SetName(name);
301 }
302
303 virtual std::wstring GetID() {
304 return profile_->GetID();
305 }
306
307 virtual void SetID(const std::wstring& id) {
308 profile_->SetID(id);
309 }
310
initial.commit09911bf2008-07-26 23:55:29311 virtual bool DidLastSessionExitCleanly() {
312 return profile_->DidLastSessionExitCleanly();
313 }
314
[email protected]d8e41ed2008-09-11 15:22:32315 virtual BookmarkModel* GetBookmarkModel() {
316 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29317 }
318
[email protected]3a453fa2008-08-15 18:46:34319#ifdef CHROME_PERSONALIZATION
[email protected]57d3d0a2008-09-24 00:50:07320 virtual ProfilePersonalization* GetProfilePersonalization() {
[email protected]3a453fa2008-08-15 18:46:34321 return profile_->GetProfilePersonalization();
322 }
323#endif
324
initial.commit09911bf2008-07-26 23:55:29325 virtual bool IsSameProfile(Profile* profile) {
326 if (profile == static_cast<Profile*>(this))
327 return true;
328 return profile == profile_;
329 }
330
331 virtual Time GetStartTime() const {
332 return start_time_;
333 }
334
335 virtual TabRestoreService* GetTabRestoreService() {
336 return NULL;
337 }
338
[email protected]e7244d82008-10-29 18:13:26339 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41340 }
341
[email protected]e7244d82008-10-29 18:13:26342 virtual void ReinitializeSpellChecker() {
343 profile_->ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:29344 }
345
346 virtual SpellChecker* GetSpellChecker() {
347 return profile_->GetSpellChecker();
348 }
349
[email protected]449478302009-06-09 20:04:28350 virtual ThumbnailStore* GetThumbnailStore() {
351 return NULL;
352 }
353
initial.commit09911bf2008-07-26 23:55:29354 virtual void MarkAsCleanShutdown() {
355 }
356
[email protected]bdbc87c2009-01-25 05:08:54357 virtual void InitExtensions() {
358 NOTREACHED();
359 }
360
[email protected]ea0c98cf2009-06-18 23:02:54361 virtual void InitWebResources() {
362 NOTREACHED();
363 }
364
initial.commit09911bf2008-07-26 23:55:29365 virtual void ExitedOffTheRecordMode() {
366 // Drop our download manager so we forget about all the downloads made
367 // in off-the-record mode.
368 download_manager_ = NULL;
369 }
370
371 virtual void Observe(NotificationType type,
372 const NotificationSource& source,
373 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56374 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29375 // We are only interested in OTR browser closing.
376 if (Source<Browser>(source)->profile() != this)
377 return;
378
379 // Let's check if we still have an Off The Record window opened.
380 // Note that we check against 1 as this notification is sent before the
381 // browser window is actually removed from the list.
382 if (BrowserList::GetBrowserCount(this) <= 1)
383 ExitedOffTheRecordMode();
384 }
385
386 private:
[email protected]88cf3292009-05-22 01:48:43387 NotificationRegistrar registrar_;
388
initial.commit09911bf2008-07-26 23:55:29389 // The real underlying profile.
390 Profile* profile_;
391
[email protected]6ab9b202008-12-23 22:34:50392 // The context to use for requests made from this OTR session.
393 ChromeURLRequestContext* request_context_;
initial.commit09911bf2008-07-26 23:55:29394
[email protected]47accfd62009-05-14 18:46:21395 ChromeURLRequestContext* extensions_request_context_;
396
initial.commit09911bf2008-07-26 23:55:29397 // The download manager that only stores downloaded items in memory.
398 scoped_refptr<DownloadManager> download_manager_;
399
[email protected]4a190632009-05-09 01:07:42400 // The download manager that only stores downloaded items in memory.
401 scoped_refptr<BrowserThemeProvider> theme_provider_;
402
[email protected]34cc84f2009-02-13 10:04:35403 // We don't want SSLHostState from the OTR profile to leak back to the main
404 // profile because then the main profile would learn some of the host names
405 // the user visited while OTR.
406 scoped_ptr<SSLHostState> ssl_host_state_;
407
[email protected]a9cea7542009-05-20 04:30:23408 // The ForceTLSState that only stores enabled sites in memory.
409 scoped_ptr<net::ForceTLSState> force_tls_state_;
410
initial.commit09911bf2008-07-26 23:55:29411 // Time we were started.
412 Time start_time_;
413
414 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl);
415};
416
[email protected]f7011fcb2009-01-28 21:54:32417ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29418 : path_(path),
[email protected]f7011fcb2009-01-28 21:54:32419 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57420 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21421 extensions_request_context_(NULL),
[email protected]eaadd9052009-06-23 18:02:23422 blacklist_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32423 history_service_created_(false),
424 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41425 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32426 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42427 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32428 start_time_(Time::Now()),
429 spellchecker_(NULL),
initial.commit09911bf2008-07-26 23:55:29430 shutdown_session_service_(false) {
431 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
432 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14433 create_session_service_timer_.Start(
434 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
435 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54436
[email protected]382a0702009-06-26 17:12:27437 extension_process_manager_.reset(new ExtensionProcessManager(this));
438
[email protected]e7244d82008-10-29 18:13:26439 PrefService* prefs = GetPrefs();
440 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
441 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58442 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58443
444#ifdef CHROME_PERSONALIZATION
445 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableP13n))
446 personalization_.reset(Personalization::CreateProfilePersonalization(this));
447#endif
448
[email protected]eaadd9052009-06-23 18:02:23449 if (CommandLine::ForCurrentProcess()->
450 HasSwitch(switches::kPrivacyBlacklist)) {
451 std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue(
452 switches::kPrivacyBlacklist);
453#if defined(OS_POSIX)
454 FilePath path(WideToUTF8(option));
455#else
456 FilePath path(option);
457#endif
458 blacklist_ = new Blacklist(path);
459 }
460
[email protected]1351b6a2009-04-09 20:13:22461#if defined(OS_LINUX)
462 // TODO(port): Remove ifdef when the Linux splash page is not needed.
463 prefs->transient()->SetString(prefs::kHomePage, "about:linux-splash");
464 prefs->transient()->SetBoolean(prefs::kHomePageIsNewTabPage, false);
465#endif
[email protected]4a190632009-05-09 01:07:42466
467 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43468 registrar_.Add(this, NotificationType::THEME_INSTALLED,
469 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29470}
471
[email protected]bdbc87c2009-01-25 05:08:54472void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41473 if (user_script_master_ || extensions_service_)
474 return; // Already initialized.
475
[email protected]bdbc87c2009-01-25 05:08:54476 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]f93fe782009-02-19 01:26:13477 PrefService* prefs = GetPrefs();
[email protected]bdbc87c2009-01-25 05:08:54478 bool user_scripts_enabled =
[email protected]f0a51fb52009-03-05 12:46:38479 command_line->HasSwitch(switches::kEnableUserScripts) ||
[email protected]f93fe782009-02-19 01:26:13480 prefs->GetBoolean(prefs::kEnableUserScripts);
[email protected]bdbc87c2009-01-25 05:08:54481
[email protected]f7011fcb2009-01-28 21:54:32482 FilePath script_dir;
[email protected]bdbc87c2009-01-25 05:08:54483 if (user_scripts_enabled) {
[email protected]0cd957b2009-03-06 20:13:23484 if (command_line->HasSwitch(switches::kUserScriptsDir)) {
485 std::wstring path_string =
486 command_line->GetSwitchValue(switches::kUserScriptsDir);
487 script_dir = FilePath::FromWStringHack(path_string);
488 } else {
489 script_dir = GetPath();
490 script_dir = script_dir.Append(chrome::kUserScriptsDirname);
491 }
[email protected]bdbc87c2009-01-25 05:08:54492 }
493
[email protected]bb28e062009-02-27 17:19:18494 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]bdbc87c2009-01-25 05:08:54495 user_script_master_ = new UserScriptMaster(
[email protected]9197f3b2009-06-02 00:49:27496 g_browser_process->file_thread()->message_loop(),
497 script_dir);
[email protected]894bb502009-05-21 22:39:57498 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23499 this,
500 CommandLine::ForCurrentProcess(),
501 GetPrefs(),
502 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
503 MessageLoop::current(),
[email protected]a1257b12009-06-12 02:51:34504 g_browser_process->file_thread()->message_loop());
[email protected]bdbc87c2009-01-25 05:08:54505
[email protected]9197f3b2009-06-02 00:49:27506 extensions_service_->Init();
[email protected]bdbc87c2009-01-25 05:08:54507}
508
[email protected]ea0c98cf2009-06-18 23:02:54509void ProfileImpl::InitWebResources() {
510 web_resource_service_ = new WebResourceService(
511 this,
512 g_browser_process->file_thread()->message_loop());
513
514 web_resource_service_->StartAfterDelay();
515}
516
initial.commit09911bf2008-07-26 23:55:29517ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19518 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29519
520 StopCreateSessionServiceTimer();
521 // TemplateURLModel schedules a task on the WebDataService from its
522 // destructor. Delete it first to ensure the task gets scheduled before we
523 // shut down the database.
524 template_url_model_.reset();
525
526 // The download manager queries the history system and should be deleted
527 // before the history is shutdown so it can properly cancel all requests.
528 download_manager_ = NULL;
529
[email protected]4a190632009-05-09 01:07:42530 // The theme provider provides bitmaps to whoever wants them.
531 theme_provider_ = NULL;
532
[email protected]e7244d82008-10-29 18:13:26533 // Remove pref observers.
534 PrefService* prefs = GetPrefs();
535 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
536 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58537 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26538
[email protected]3a453fa2008-08-15 18:46:34539#ifdef CHROME_PERSONALIZATION
[email protected]57d3d0a2008-09-24 00:50:07540 personalization_.reset();
[email protected]3a453fa2008-08-15 18:46:34541#endif
542
initial.commit09911bf2008-07-26 23:55:29543 // Both HistoryService and WebDataService maintain threads for background
544 // processing. Its possible each thread still has tasks on it that have
545 // increased the ref count of the service. In such a situation, when we
546 // decrement the refcount, it won't be 0, and the threads/databases aren't
547 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
548 // databases are properly closed.
549 if (web_data_service_.get())
550 web_data_service_->Shutdown();
551
552 if (history_service_.get())
553 history_service_->Cleanup();
554
555 // The I/O thread may be NULL during testing.
[email protected]ab820df2008-08-26 05:55:10556 base::Thread* io_thread = g_browser_process->io_thread();
initial.commit09911bf2008-07-26 23:55:29557
558 if (spellchecker_) {
559 // The spellchecker must be deleted on the I/O thread. During testing, we
560 // don't have an I/O thread.
561 if (io_thread)
562 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
563 else
564 spellchecker_->Release();
565 }
566
[email protected]47accfd62009-05-14 18:46:21567 if (default_request_context_ == request_context_)
568 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50569
[email protected]47accfd62009-05-14 18:46:21570 CleanupRequestContext(request_context_);
571 CleanupRequestContext(media_request_context_);
572 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17573
[email protected]eaadd9052009-06-23 18:02:23574 // When the request contexts are gone, the blacklist wont be needed anymore.
575 delete blacklist_;
576 blacklist_ = 0;
577
[email protected]d8e41ed2008-09-11 15:22:32578 // HistoryService may call into the BookmarkModel, as such we need to
579 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46580 // HistoryService will join with HistoryService's backend thread so that
581 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32582 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46583 history_service_ = NULL;
584 bookmark_bar_model_.reset();
585
initial.commit09911bf2008-07-26 23:55:29586 MarkAsCleanShutdown();
587}
588
[email protected]f7011fcb2009-01-28 21:54:32589FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29590 return path_;
591}
592
593bool ProfileImpl::IsOffTheRecord() {
594 return false;
595}
596
597Profile* ProfileImpl::GetOffTheRecordProfile() {
598 if (!off_the_record_profile_.get()) {
599 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
600 off_the_record_profile_.swap(p);
601 }
602 return off_the_record_profile_.get();
603}
604
[email protected]860f55492009-03-27 19:50:59605void ProfileImpl::DestroyOffTheRecordProfile() {
606 off_the_record_profile_.reset();
607}
608
initial.commit09911bf2008-07-26 23:55:29609Profile* ProfileImpl::GetOriginalProfile() {
610 return this;
611}
612
[email protected]176aa482008-11-14 03:25:15613static void BroadcastNewHistoryTable(base::SharedMemory* table_memory) {
initial.commit09911bf2008-07-26 23:55:29614 if (!table_memory)
615 return;
616
617 // send to all RenderProcessHosts
618 for (RenderProcessHost::iterator i = RenderProcessHost::begin();
619 i != RenderProcessHost::end(); i++) {
620 if (!i->second->channel())
621 continue;
622
[email protected]176aa482008-11-14 03:25:15623 base::SharedMemoryHandle new_table;
[email protected]f7011fcb2009-01-28 21:54:32624 base::ProcessHandle process = i->second->process().handle();
initial.commit09911bf2008-07-26 23:55:29625 if (!process) {
626 // process can be null if it's started with the --single-process flag.
[email protected]f7011fcb2009-01-28 21:54:32627 process = base::Process::Current().handle();
initial.commit09911bf2008-07-26 23:55:29628 }
629
630 table_memory->ShareToProcess(process, &new_table);
631 IPC::Message* msg = new ViewMsg_VisitedLink_NewTable(new_table);
632 i->second->channel()->Send(msg);
633 }
634}
635
636VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
637 if (!visited_link_master_.get()) {
638 scoped_ptr<VisitedLinkMaster> visited_links(
639 new VisitedLinkMaster(g_browser_process->file_thread(),
640 BroadcastNewHistoryTable, this));
641 if (!visited_links->Init())
642 return NULL;
643 visited_link_master_.swap(visited_links);
644 }
645
646 return visited_link_master_.get();
647}
648
[email protected]6014d672008-12-05 00:38:25649ExtensionsService* ProfileImpl::GetExtensionsService() {
650 return extensions_service_.get();
651}
652
[email protected]0938d3c2009-01-09 20:37:35653UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35654 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25655}
656
[email protected]481e1a42009-05-06 20:56:05657ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27658 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05659}
660
[email protected]34cc84f2009-02-13 10:04:35661SSLHostState* ProfileImpl::GetSSLHostState() {
662 if (!ssl_host_state_.get())
663 ssl_host_state_.reset(new SSLHostState());
664
665 DCHECK(ssl_host_state_->CalledOnValidThread());
666 return ssl_host_state_.get();
667}
668
[email protected]a9cea7542009-05-20 04:30:23669net::ForceTLSState* ProfileImpl::GetForceTLSState() {
670 if (!force_tls_state_.get())
671 force_tls_state_.reset(new net::ForceTLSState());
672
673 return force_tls_state_.get();
674}
675
initial.commit09911bf2008-07-26 23:55:29676PrefService* ProfileImpl::GetPrefs() {
677 if (!prefs_.get()) {
[email protected]6faa0e0d2009-04-28 06:50:36678 prefs_.reset(new PrefService(GetPrefFilePath(),
679 g_browser_process->file_thread()));
initial.commit09911bf2008-07-26 23:55:29680
681 // The Profile class and ProfileManager class may read some prefs so
682 // register known prefs as soon as possible.
683 Profile::RegisterUserPrefs(prefs_.get());
684 ProfileManager::RegisterUserPrefs(prefs_.get());
685
686 // The last session exited cleanly if there is no pref for
687 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
688 last_session_exited_cleanly_ =
689 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
690 // Mark the session as open.
691 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
692 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36693 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29694 }
695
696 return prefs_.get();
697}
698
[email protected]f7011fcb2009-01-28 21:54:32699FilePath ProfileImpl::GetPrefFilePath() {
700 FilePath pref_file_path = path_;
701 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29702 return pref_file_path;
703}
704
705URLRequestContext* ProfileImpl::GetRequestContext() {
706 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32707 FilePath cookie_path = GetPath();
708 cookie_path = cookie_path.Append(chrome::kCookieFilename);
709 FilePath cache_path = GetPath();
[email protected]2b2830a2009-02-07 01:58:42710
711 // Override the cache location if specified by the user.
712 const std::wstring user_cache_dir(
713 CommandLine::ForCurrentProcess()->GetSwitchValue(
714 switches::kDiskCacheDir));
715 if (!user_cache_dir.empty()) {
716 cache_path = FilePath::FromWStringHack(user_cache_dir);
717 }
718
[email protected]f7011fcb2009-01-28 21:54:32719 cache_path = cache_path.Append(chrome::kCacheDirname);
[email protected]6ab9b202008-12-23 22:34:50720 request_context_ = ChromeURLRequestContext::CreateOriginal(
721 this, cookie_path, cache_path);
initial.commit09911bf2008-07-26 23:55:29722 request_context_->AddRef();
723
[email protected]6ab9b202008-12-23 22:34:50724 // The first request context is always a normal (non-OTR) request context.
725 // Even when Chromium is started in OTR mode, a normal profile is always
726 // created first.
727 if (!default_request_context_) {
728 default_request_context_ = request_context_;
729 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56730 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50731 NotificationService::AllSources(), NotificationService::NoDetails());
732 }
733
initial.commit09911bf2008-07-26 23:55:29734 DCHECK(request_context_->cookie_store());
735 }
736
737 return request_context_;
738}
739
[email protected]e7f29642009-03-02 22:53:18740URLRequestContext* ProfileImpl::GetRequestContextForMedia() {
741 if (!media_request_context_) {
742 FilePath cache_path = GetPath();
[email protected]e3edeba2009-03-23 18:57:14743
744 // Override the cache location if specified by the user.
745 const std::wstring user_cache_dir(
746 CommandLine::ForCurrentProcess()->GetSwitchValue(
747 switches::kDiskCacheDir));
748 if (!user_cache_dir.empty()) {
749 cache_path = FilePath::FromWStringHack(user_cache_dir);
750 }
751
[email protected]4e7b5dbb2009-03-25 00:09:23752 cache_path = cache_path.Append(chrome::kMediaCacheDirname);
[email protected]e7f29642009-03-02 22:53:18753 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia(
754 this, cache_path);
755 media_request_context_->AddRef();
756
757 DCHECK(media_request_context_->cookie_store());
758 }
759
760 return media_request_context_;
761}
762
[email protected]47accfd62009-05-14 18:46:21763URLRequestContext* ProfileImpl::GetRequestContextForExtensions() {
764 if (!extensions_request_context_) {
765 FilePath cookie_path = GetPath();
766 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
767
768 extensions_request_context_ =
769 ChromeURLRequestContext::CreateOriginalForExtensions(this, cookie_path);
770 extensions_request_context_->AddRef();
771
772 DCHECK(extensions_request_context_->cookie_store());
773 }
774
775 return extensions_request_context_;
776}
777
[email protected]eaadd9052009-06-23 18:02:23778Blacklist* ProfileImpl::GetBlacklist() {
779 return blacklist_;
780}
781
initial.commit09911bf2008-07-26 23:55:29782HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
783 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:46784 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:29785 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:32786 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:29787 return NULL;
788 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:29789
790 // Send out the notification that the history service was created.
791 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56792 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:29793 Details<HistoryService>(history_service_.get()));
794 }
795 return history_service_.get();
796}
797
initial.commit09911bf2008-07-26 23:55:29798TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
799 if (!template_url_model_.get())
800 template_url_model_.reset(new TemplateURLModel(this));
801 return template_url_model_.get();
802}
803
804TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
805 if (!template_url_fetcher_.get())
806 template_url_fetcher_.reset(new TemplateURLFetcher(this));
807 return template_url_fetcher_.get();
808}
809
810WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
811 if (!created_web_data_service_)
812 CreateWebDataService();
813 return web_data_service_.get();
814}
815
816void ProfileImpl::CreateWebDataService() {
817 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
818 created_web_data_service_ = true;
819 scoped_refptr<WebDataService> wds(new WebDataService());
820 if (!wds->Init(GetPath()))
821 return;
822 web_data_service_.swap(wds);
823}
824
[email protected]e69d33952009-06-03 22:00:41825PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
826 if (!created_password_store_)
827 CreatePasswordStore();
828 return password_store_.get();
829}
830
831void ProfileImpl::CreatePasswordStore() {
832 DCHECK(!created_password_store_ && password_store_.get() == NULL);
833 created_password_store_ = true;
834 scoped_refptr<PasswordStore> ps;
835#if defined(OS_LINUX)
836// Temporarily disabled while we figure some stuff out.
837// http://code.google.com/p/chromium/issues/detail?id=12351
838// if (getenv("KDE_FULL_SESSION")) {
839// ps = new PasswordStoreKWallet();
840// } else {
841// ps = new PasswordStoreGnome();
842// }
843 NOTIMPLEMENTED();
844#elif defined(OS_WIN)
845 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:56846#elif defined(OS_MACOSX)
847 ps = new PasswordStoreMac(new MacKeychain());
[email protected]e69d33952009-06-03 22:00:41848#else
849 NOTIMPLEMENTED();
850#endif
851 if (!ps || !ps->Init()) {
852 // Try falling back to the default password manager
853 LOG(WARNING) << "Could not initialise native password manager - "
854 "falling back to default";
855 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
856 if (!ps->Init())
857 return;
858 }
859 password_store_.swap(ps);
860}
861
initial.commit09911bf2008-07-26 23:55:29862DownloadManager* ProfileImpl::GetDownloadManager() {
863 if (!created_download_manager_) {
864 scoped_refptr<DownloadManager> dlm(new DownloadManager);
865 dlm->Init(this);
866 created_download_manager_ = true;
867 download_manager_.swap(dlm);
868 }
869 return download_manager_.get();
870}
871
872bool ProfileImpl::HasCreatedDownloadManager() const {
873 return created_download_manager_;
874}
875
[email protected]4a190632009-05-09 01:07:42876void ProfileImpl::InitThemes() {
877 if (!created_theme_provider_) {
878 scoped_refptr<BrowserThemeProvider> themes(new BrowserThemeProvider);
879 themes->Init(this);
880 created_theme_provider_ = true;
881 theme_provider_.swap(themes);
882 }
883}
884
885void ProfileImpl::SetTheme(Extension* extension) {
886 InitThemes();
887 theme_provider_.get()->SetTheme(extension);
888}
889
890void ProfileImpl::ClearTheme() {
891 InitThemes();
892 theme_provider_.get()->UseDefaultTheme();
893}
894
895ThemeProvider* ProfileImpl::GetThemeProvider() {
896 InitThemes();
897 return theme_provider_.get();
898}
899
initial.commit09911bf2008-07-26 23:55:29900SessionService* ProfileImpl::GetSessionService() {
901 if (!session_service_.get() && !shutdown_session_service_) {
902 session_service_ = new SessionService(this);
903 session_service_->ResetFromCurrentBrowsers();
904 }
905 return session_service_.get();
906}
907
908void ProfileImpl::ShutdownSessionService() {
909 if (shutdown_session_service_)
910 return;
911
912 // We're about to exit, force creation of the session service if it hasn't
913 // been created yet. We do this to ensure session state matches the point in
914 // time the user exited.
915 GetSessionService();
916 shutdown_session_service_ = true;
917 session_service_ = NULL;
918}
919
920bool ProfileImpl::HasSessionService() const {
921 return (session_service_.get() != NULL);
922}
923
924std::wstring ProfileImpl::GetName() {
925 return GetPrefs()->GetString(prefs::kProfileName);
926}
927void ProfileImpl::SetName(const std::wstring& name) {
928 GetPrefs()->SetString(prefs::kProfileName, name);
929}
930
931std::wstring ProfileImpl::GetID() {
932 return GetPrefs()->GetString(prefs::kProfileID);
933}
934void ProfileImpl::SetID(const std::wstring& id) {
935 GetPrefs()->SetString(prefs::kProfileID, id);
936}
937
initial.commit09911bf2008-07-26 23:55:29938bool ProfileImpl::DidLastSessionExitCleanly() {
939 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
940 // it to be set by asking for the prefs.
941 GetPrefs();
942 return last_session_exited_cleanly_;
943}
944
[email protected]d8e41ed2008-09-11 15:22:32945BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:46946 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:32947 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:46948 bookmark_bar_model_->Load();
949 }
initial.commit09911bf2008-07-26 23:55:29950 return bookmark_bar_model_.get();
951}
952
953bool ProfileImpl::IsSameProfile(Profile* profile) {
954 if (profile == static_cast<Profile*>(this))
955 return true;
956 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
957 return otr_profile && profile == static_cast<Profile*>(otr_profile);
958}
959
960Time ProfileImpl::GetStartTime() const {
961 return start_time_;
962}
963
964TabRestoreService* ProfileImpl::GetTabRestoreService() {
965 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:19966 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:29967 return tab_restore_service_.get();
968}
969
[email protected]449478302009-06-09 20:04:28970ThumbnailStore* ProfileImpl::GetThumbnailStore() {
971 if (!thumbnail_store_.get()) {
972 thumbnail_store_ = new ThumbnailStore;
[email protected]f2458dc2009-06-24 22:38:58973 thumbnail_store_->Init(GetPath().AppendASCII("thumbnailstore"), this);
[email protected]449478302009-06-09 20:04:28974 }
975 return thumbnail_store_.get();
976}
977
initial.commit09911bf2008-07-26 23:55:29978void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:19979 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29980}
981
[email protected]a9afddb2009-02-12 17:49:42982// To be run in the IO thread to notify all resource message filters that the
[email protected]20930852008-10-15 19:30:41983// spellchecker has changed.
984class NotifySpellcheckerChangeTask : public Task {
985 public:
986 NotifySpellcheckerChangeTask(
[email protected]e7244d82008-10-29 18:13:26987 Profile* profile,
988 const SpellcheckerReinitializedDetails& spellchecker)
[email protected]20930852008-10-15 19:30:41989 : profile_(profile),
990 spellchecker_(spellchecker) {
991 }
992
993 private:
994 void Run(void) {
995 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56996 NotificationType::SPELLCHECKER_REINITIALIZED,
[email protected]20930852008-10-15 19:30:41997 Source<Profile>(profile_),
998 Details<SpellcheckerReinitializedDetails>(&spellchecker_));
999 }
1000
1001 Profile* profile_;
1002 SpellcheckerReinitializedDetails spellchecker_;
1003};
1004
[email protected]e7244d82008-10-29 18:13:261005void ProfileImpl::InitializeSpellChecker(bool need_to_broadcast) {
[email protected]20930852008-10-15 19:30:411006 // The I/O thread may be NULL during testing.
1007 base::Thread* io_thread = g_browser_process->io_thread();
1008 if (spellchecker_) {
1009 // The spellchecker must be deleted on the I/O thread.
1010 // A dummy variable to aid in logical clarity.
1011 SpellChecker* last_spellchecker = spellchecker_;
1012
1013 if (io_thread)
1014 io_thread->message_loop()->ReleaseSoon(FROM_HERE, last_spellchecker);
1015 else // during testing, we don't have an I/O thread
1016 last_spellchecker->Release();
[email protected]20930852008-10-15 19:30:411017 }
1018
[email protected]20930852008-10-15 19:30:411019 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1020 PrefService* prefs = GetPrefs();
[email protected]e7244d82008-10-29 18:13:261021 bool enable_spellcheck = prefs->GetBoolean(prefs::kEnableSpellCheck);
[email protected]20930852008-10-15 19:30:411022
[email protected]e7244d82008-10-29 18:13:261023 if (enable_spellcheck) {
[email protected]bd17b702009-02-25 20:44:081024 FilePath dict_dir;
[email protected]e7244d82008-10-29 18:13:261025 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
[email protected]a9afddb2009-02-12 17:49:421026 // Note that, as the object pointed to by previously by spellchecker_
[email protected]e7244d82008-10-29 18:13:261027 // is being deleted in the io thread, the spellchecker_ can be made to point
1028 // to a new object (RE-initialized) in parallel in this UI thread.
[email protected]4b4d1adc2008-12-10 22:28:581029 spellchecker_ = new SpellChecker(dict_dir,
[email protected]74c8b422009-03-11 00:34:121030 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1031 GetRequestContext(),
[email protected]bd17b702009-02-25 20:44:081032 FilePath());
[email protected]e7244d82008-10-29 18:13:261033 spellchecker_->AddRef(); // Manual refcounting.
1034 } else {
1035 spellchecker_ = NULL;
1036 }
[email protected]20930852008-10-15 19:30:411037
[email protected]154a4332009-06-03 20:20:581038 // Set auto spell correct status for spellchecker.
1039 if (spellchecker_) {
1040 spellchecker_->EnableAutoSpellCorrect(
1041 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
1042 }
1043
[email protected]20930852008-10-15 19:30:411044 if (need_to_broadcast && io_thread) { // Notify resource message filters.
1045 SpellcheckerReinitializedDetails scoped_spellchecker;
1046 scoped_spellchecker.spellchecker = spellchecker_;
[email protected]e7244d82008-10-29 18:13:261047 if (io_thread) {
1048 io_thread->message_loop()->PostTask(
[email protected]a9afddb2009-02-12 17:49:421049 FROM_HERE,
[email protected]e7244d82008-10-29 18:13:261050 new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
1051 }
[email protected]20930852008-10-15 19:30:411052 }
1053}
1054
[email protected]e7244d82008-10-29 18:13:261055void ProfileImpl::ReinitializeSpellChecker() {
1056 InitializeSpellChecker(true);
1057}
1058
initial.commit09911bf2008-07-26 23:55:291059SpellChecker* ProfileImpl::GetSpellChecker() {
1060 if (!spellchecker_) {
[email protected]20930852008-10-15 19:30:411061 // This is where spellchecker gets initialized. Note that this is being
1062 // initialized in the ui_thread. However, this is not a problem as long as
1063 // it is *used* in the io thread.
[email protected]34cc84f2009-02-13 10:04:351064 // TODO(sidchat): One day, change everything so that spellchecker gets
[email protected]20930852008-10-15 19:30:411065 // initialized in the IO thread itself.
[email protected]e7244d82008-10-29 18:13:261066 InitializeSpellChecker(false);
initial.commit09911bf2008-07-26 23:55:291067 }
[email protected]20930852008-10-15 19:30:411068
initial.commit09911bf2008-07-26 23:55:291069 return spellchecker_;
1070}
1071
1072void ProfileImpl::MarkAsCleanShutdown() {
1073 if (prefs_.get()) {
1074 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1075 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1076
1077 // NOTE: If you change what thread this writes on, be sure and update
1078 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361079 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291080 }
1081}
1082
[email protected]e7244d82008-10-29 18:13:261083void ProfileImpl::Observe(NotificationType type,
1084 const NotificationSource& source,
1085 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561086 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261087 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1088 PrefService* prefs = Source<PrefService>(source).ptr();
1089 DCHECK(pref_name_in && prefs);
1090 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]154a4332009-06-03 20:20:581091 *pref_name_in == prefs::kEnableSpellCheck ||
1092 *pref_name_in == prefs::kEnableAutoSpellCorrect) {
[email protected]e7244d82008-10-29 18:13:261093 InitializeSpellChecker(true);
1094 }
[email protected]4a190632009-05-09 01:07:421095 } else if (NotificationType::THEME_INSTALLED == type) {
1096 Extension* extension = Details<Extension>(details).ptr();
1097 SetTheme(extension);
[email protected]e7244d82008-10-29 18:13:261098 }
1099}
1100
initial.commit09911bf2008-07-26 23:55:291101void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141102 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291103}
[email protected]3a453fa2008-08-15 18:46:341104
1105#ifdef CHROME_PERSONALIZATION
[email protected]57d3d0a2008-09-24 00:50:071106ProfilePersonalization* ProfileImpl::GetProfilePersonalization() {
[email protected]57d3d0a2008-09-24 00:50:071107 return personalization_.get();
[email protected]3a453fa2008-08-15 18:46:341108}
license.botbf09a502008-08-24 00:55:551109#endif