license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/browser/profile.h" |
| 6 | |
| 7 | #include "base/command_line.h" |
[email protected] | 04fba9a9 | 2008-10-28 17:25:25 | [diff] [blame] | 8 | #include "base/file_path.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | #include "base/file_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | #include "base/path_service.h" |
| 11 | #include "base/scoped_ptr.h" |
| 12 | #include "base/string_util.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 13 | #include "chrome/browser/bookmarks/bookmark_model.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | #include "chrome/browser/browser_list.h" |
| 15 | #include "chrome/browser/browser_process.h" |
[email protected] | 67a46b7f | 2009-06-16 21:41:02 | [diff] [blame] | 16 | #include "chrome/browser/browser_theme_provider.h" |
[email protected] | b7f0588 | 2009-02-22 01:21:56 | [diff] [blame] | 17 | #include "chrome/browser/download/download_manager.h" |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extensions_service.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 20 | #include "chrome/browser/extensions/user_script_master.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 21 | #include "chrome/browser/history/history.h" |
[email protected] | 6ab9b20 | 2008-12-23 22:34:50 | [diff] [blame] | 22 | #include "chrome/browser/net/chrome_url_request_context.h" |
[email protected] | e69d3395 | 2009-06-03 22:00:41 | [diff] [blame] | 23 | #include "chrome/browser/password_manager/password_store_default.h" |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 24 | #include "chrome/browser/privacy_blacklist/blacklist.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | #include "chrome/browser/profile_manager.h" |
[email protected] | 8c8657d6 | 2009-01-16 18:31:26 | [diff] [blame] | 26 | #include "chrome/browser/renderer_host/render_process_host.h" |
[email protected] | 1132436e | 2009-04-08 20:06:33 | [diff] [blame] | 27 | #include "chrome/browser/search_engines/template_url_fetcher.h" |
[email protected] | f63ae31 | 2009-02-04 17:58:46 | [diff] [blame] | 28 | #include "chrome/browser/search_engines/template_url_model.h" |
[email protected] | 85e921fb8 | 2009-02-11 23:19:44 | [diff] [blame] | 29 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | bd580a25 | 2009-02-12 01:16:30 | [diff] [blame] | 30 | #include "chrome/browser/sessions/tab_restore_service.h" |
[email protected] | f0a64429 | 2009-02-25 23:32:47 | [diff] [blame] | 31 | #include "chrome/browser/spellchecker.h" |
[email protected] | 1132436e | 2009-04-08 20:06:33 | [diff] [blame] | 32 | #include "chrome/browser/ssl/ssl_host_state.h" |
[email protected] | 44947830 | 2009-06-09 20:04:28 | [diff] [blame] | 33 | #include "chrome/browser/thumbnail_store.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | #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] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 39 | #include "chrome/common/extensions/extension_error_reporter.h" |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 40 | #include "chrome/common/net/cookie_monster_sqlite.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | #include "chrome/common/notification_service.h" |
| 42 | #include "chrome/common/pref_names.h" |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 43 | #include "chrome/common/render_messages.h" |
[email protected] | f90f5c51 | 2009-02-18 19:10:58 | [diff] [blame] | 44 | #include "grit/locale_settings.h" |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 45 | #include "net/base/force_tls_state.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 47 | using base::Time; |
| 48 | using base::TimeDelta; |
| 49 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | // Delay, in milliseconds, before we explicitly create the SessionService. |
| 51 | static const int kCreateSessionServiceDelayMS = 500; |
| 52 | |
| 53 | // A pointer to the request context for the default profile. See comments on |
| 54 | // Profile::GetDefaultRequestContext. |
| 55 | URLRequestContext* Profile::default_request_context_; |
| 56 | |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 57 | static 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] | 34cc84f | 2009-02-13 10:04:35 | [diff] [blame] | 67 | // static |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | void Profile::RegisterUserPrefs(PrefService* prefs) { |
[email protected] | 430d3f7 | 2008-10-27 17:56:55 | [diff] [blame] | 69 | prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 70 | prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); |
| 71 | prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); |
[email protected] | 74c8b42 | 2009-03-11 00:34:12 | [diff] [blame] | 72 | // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string. |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 73 | prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary, |
| 74 | IDS_SPELLCHECK_DICTIONARY); |
| 75 | prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true); |
[email protected] | 154a433 | 2009-06-03 20:20:58 | [diff] [blame] | 76 | prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true); |
[email protected] | f93fe78 | 2009-02-19 01:26:13 | [diff] [blame] | 77 | prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false); |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 78 | prefs->RegisterStringPref(prefs::kCurrentThemeID, L""); |
| 79 | prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages); |
| 80 | prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors); |
| 81 | prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints); |
[email protected] | 7895ea2 | 2009-06-02 20:53:50 | [diff] [blame] | 82 | prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties); |
[email protected] | f93fe78 | 2009-02-19 01:26:13 | [diff] [blame] | 83 | prefs->RegisterBooleanPref(prefs::kEnableExtensions, false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 84 | } |
| 85 | |
[email protected] | 34cc84f | 2009-02-13 10:04:35 | [diff] [blame] | 86 | // static |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 87 | Profile* Profile::CreateProfile(const FilePath& path) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 88 | return new ProfileImpl(path); |
| 89 | } |
| 90 | |
[email protected] | 34cc84f | 2009-02-13 10:04:35 | [diff] [blame] | 91 | // static |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 92 | URLRequestContext* Profile::GetDefaultRequestContext() { |
| 93 | return default_request_context_; |
| 94 | } |
| 95 | |
[email protected] | e69d3395 | 2009-06-03 22:00:41 | [diff] [blame] | 96 | #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] | 034eba5 | 2009-06-03 22:50:56 | [diff] [blame] | 103 | #elif defined(OS_MACOSX) |
| 104 | #include "chrome/browser/keychain_mac.h" |
| 105 | #include "chrome/browser/password_manager/password_store_mac.h" |
[email protected] | e69d3395 | 2009-06-03 22:00:41 | [diff] [blame] | 106 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 107 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 108 | //////////////////////////////////////////////////////////////////////////////// |
| 109 | // |
| 110 | // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 111 | // to make it suitable for the off the record mode. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | // |
| 113 | //////////////////////////////////////////////////////////////////////////////// |
| 114 | class OffTheRecordProfileImpl : public Profile, |
| 115 | public NotificationObserver { |
| 116 | public: |
| 117 | explicit OffTheRecordProfileImpl(Profile* real_profile) |
| 118 | : profile_(real_profile), |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 119 | extensions_request_context_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 120 | start_time_(Time::Now()) { |
[email protected] | 6ab9b20 | 2008-12-23 22:34:50 | [diff] [blame] | 121 | request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 122 | request_context_->AddRef(); |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 123 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 124 | // 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] | 88cf329 | 2009-05-22 01:48:43 | [diff] [blame] | 127 | registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
| 128 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | virtual ~OffTheRecordProfileImpl() { |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 132 | CleanupRequestContext(request_context_); |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 133 | CleanupRequestContext(extensions_request_context_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 134 | } |
| 135 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 136 | virtual FilePath GetPath() { return profile_->GetPath(); } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 137 | |
| 138 | virtual bool IsOffTheRecord() { |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | virtual Profile* GetOffTheRecordProfile() { |
| 143 | return this; |
| 144 | } |
| 145 | |
[email protected] | 860f5549 | 2009-03-27 19:50:59 | [diff] [blame] | 146 | virtual void DestroyOffTheRecordProfile() { |
| 147 | // Suicide is bad! |
| 148 | NOTREACHED(); |
| 149 | } |
| 150 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | virtual Profile* GetOriginalProfile() { |
| 152 | return profile_; |
| 153 | } |
| 154 | |
| 155 | virtual VisitedLinkMaster* GetVisitedLinkMaster() { |
[email protected] | 7fb6c86 | 2009-03-13 02:51:49 | [diff] [blame] | 156 | // 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 159 | } |
| 160 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 161 | virtual ExtensionsService* GetExtensionsService() { |
[email protected] | 1bd5413 | 2009-06-11 00:05:34 | [diff] [blame] | 162 | return NULL; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 163 | } |
| 164 | |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 165 | virtual UserScriptMaster* GetUserScriptMaster() { |
| 166 | return profile_->GetUserScriptMaster(); |
[email protected] | 04fba9a9 | 2008-10-28 17:25:25 | [diff] [blame] | 167 | } |
| 168 | |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 169 | virtual ExtensionProcessManager* GetExtensionProcessManager() { |
[email protected] | 1bd5413 | 2009-06-11 00:05:34 | [diff] [blame] | 170 | return NULL; |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 171 | } |
| 172 | |
[email protected] | 34cc84f | 2009-02-13 10:04:35 | [diff] [blame] | 173 | 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] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 181 | 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 188 | 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 197 | 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] | e69d3395 | 2009-06-03 22:00:41 | [diff] [blame] | 206 | 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 215 | 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] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 240 | 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 256 | virtual URLRequestContext* GetRequestContext() { |
| 257 | return request_context_; |
| 258 | } |
| 259 | |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 260 | virtual URLRequestContext* GetRequestContextForMedia() { |
[email protected] | d14c7ac | 2009-05-29 20:38:11 | [diff] [blame] | 261 | // In OTR mode, media request context is the same as the original one. |
| 262 | return request_context_; |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 263 | } |
| 264 | |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 265 | 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] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 277 | virtual Blacklist* GetBlacklist() { |
| 278 | return GetOriginalProfile()->GetBlacklist(); |
| 279 | } |
| 280 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 281 | 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 311 | virtual bool DidLastSessionExitCleanly() { |
| 312 | return profile_->DidLastSessionExitCleanly(); |
| 313 | } |
| 314 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 315 | virtual BookmarkModel* GetBookmarkModel() { |
| 316 | return profile_->GetBookmarkModel(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 317 | } |
| 318 | |
[email protected] | 3a453fa | 2008-08-15 18:46:34 | [diff] [blame] | 319 | #ifdef CHROME_PERSONALIZATION |
[email protected] | 57d3d0a | 2008-09-24 00:50:07 | [diff] [blame] | 320 | virtual ProfilePersonalization* GetProfilePersonalization() { |
[email protected] | 3a453fa | 2008-08-15 18:46:34 | [diff] [blame] | 321 | return profile_->GetProfilePersonalization(); |
| 322 | } |
| 323 | #endif |
| 324 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 325 | 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] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 339 | virtual void ResetTabRestoreService() { |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 340 | } |
| 341 | |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 342 | virtual void ReinitializeSpellChecker() { |
| 343 | profile_->ReinitializeSpellChecker(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | virtual SpellChecker* GetSpellChecker() { |
| 347 | return profile_->GetSpellChecker(); |
| 348 | } |
| 349 | |
[email protected] | 44947830 | 2009-06-09 20:04:28 | [diff] [blame] | 350 | virtual ThumbnailStore* GetThumbnailStore() { |
| 351 | return NULL; |
| 352 | } |
| 353 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 354 | virtual void MarkAsCleanShutdown() { |
| 355 | } |
| 356 | |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 357 | virtual void InitExtensions() { |
| 358 | NOTREACHED(); |
| 359 | } |
| 360 | |
[email protected] | ea0c98cf | 2009-06-18 23:02:54 | [diff] [blame] | 361 | virtual void InitWebResources() { |
| 362 | NOTREACHED(); |
| 363 | } |
| 364 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | 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] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 374 | DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 375 | // 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] | 88cf329 | 2009-05-22 01:48:43 | [diff] [blame] | 387 | NotificationRegistrar registrar_; |
| 388 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 389 | // The real underlying profile. |
| 390 | Profile* profile_; |
| 391 | |
[email protected] | 6ab9b20 | 2008-12-23 22:34:50 | [diff] [blame] | 392 | // The context to use for requests made from this OTR session. |
| 393 | ChromeURLRequestContext* request_context_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 394 | |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 395 | ChromeURLRequestContext* extensions_request_context_; |
| 396 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 397 | // The download manager that only stores downloaded items in memory. |
| 398 | scoped_refptr<DownloadManager> download_manager_; |
| 399 | |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 400 | // The download manager that only stores downloaded items in memory. |
| 401 | scoped_refptr<BrowserThemeProvider> theme_provider_; |
| 402 | |
[email protected] | 34cc84f | 2009-02-13 10:04:35 | [diff] [blame] | 403 | // 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] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 408 | // The ForceTLSState that only stores enabled sites in memory. |
| 409 | scoped_ptr<net::ForceTLSState> force_tls_state_; |
| 410 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 411 | // Time we were started. |
| 412 | Time start_time_; |
| 413 | |
| 414 | DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl); |
| 415 | }; |
| 416 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 417 | ProfileImpl::ProfileImpl(const FilePath& path) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 418 | : path_(path), |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 419 | request_context_(NULL), |
[email protected] | 363347b | 2009-03-13 20:06:57 | [diff] [blame] | 420 | media_request_context_(NULL), |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 421 | extensions_request_context_(NULL), |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 422 | blacklist_(NULL), |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 423 | history_service_created_(false), |
| 424 | created_web_data_service_(false), |
[email protected] | e69d3395 | 2009-06-03 22:00:41 | [diff] [blame] | 425 | created_password_store_(false), |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 426 | created_download_manager_(false), |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 427 | created_theme_provider_(false), |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 428 | start_time_(Time::Now()), |
| 429 | spellchecker_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 430 | 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] | 2d31666 | 2008-09-03 18:18:14 | [diff] [blame] | 433 | create_session_service_timer_.Start( |
| 434 | TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
| 435 | &ProfileImpl::EnsureSessionServiceCreated); |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 436 | |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 437 | PrefService* prefs = GetPrefs(); |
| 438 | prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this); |
| 439 | prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); |
[email protected] | 154a433 | 2009-06-03 20:20:58 | [diff] [blame] | 440 | prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this); |
[email protected] | 380ab46 | 2009-04-24 01:23:58 | [diff] [blame] | 441 | |
| 442 | #ifdef CHROME_PERSONALIZATION |
| 443 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableP13n)) |
| 444 | personalization_.reset(Personalization::CreateProfilePersonalization(this)); |
| 445 | #endif |
| 446 | |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 447 | if (CommandLine::ForCurrentProcess()-> |
| 448 | HasSwitch(switches::kPrivacyBlacklist)) { |
| 449 | std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue( |
| 450 | switches::kPrivacyBlacklist); |
| 451 | #if defined(OS_POSIX) |
| 452 | FilePath path(WideToUTF8(option)); |
| 453 | #else |
| 454 | FilePath path(option); |
| 455 | #endif |
| 456 | blacklist_ = new Blacklist(path); |
| 457 | } |
| 458 | |
[email protected] | 1351b6a | 2009-04-09 20:13:22 | [diff] [blame] | 459 | #if defined(OS_LINUX) |
| 460 | // TODO(port): Remove ifdef when the Linux splash page is not needed. |
| 461 | prefs->transient()->SetString(prefs::kHomePage, "about:linux-splash"); |
| 462 | prefs->transient()->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
| 463 | #endif |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 464 | |
| 465 | // Listen for theme installation. |
[email protected] | 88cf329 | 2009-05-22 01:48:43 | [diff] [blame] | 466 | registrar_.Add(this, NotificationType::THEME_INSTALLED, |
| 467 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 468 | } |
| 469 | |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 470 | void ProfileImpl::InitExtensions() { |
[email protected] | 8c756ac | 2009-01-30 23:36:41 | [diff] [blame] | 471 | if (user_script_master_ || extensions_service_) |
| 472 | return; // Already initialized. |
| 473 | |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 474 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | f93fe78 | 2009-02-19 01:26:13 | [diff] [blame] | 475 | PrefService* prefs = GetPrefs(); |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 476 | bool user_scripts_enabled = |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 477 | command_line->HasSwitch(switches::kEnableUserScripts) || |
[email protected] | f93fe78 | 2009-02-19 01:26:13 | [diff] [blame] | 478 | prefs->GetBoolean(prefs::kEnableUserScripts); |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 479 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 480 | FilePath script_dir; |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 481 | if (user_scripts_enabled) { |
[email protected] | 0cd957b | 2009-03-06 20:13:23 | [diff] [blame] | 482 | if (command_line->HasSwitch(switches::kUserScriptsDir)) { |
| 483 | std::wstring path_string = |
| 484 | command_line->GetSwitchValue(switches::kUserScriptsDir); |
| 485 | script_dir = FilePath::FromWStringHack(path_string); |
| 486 | } else { |
| 487 | script_dir = GetPath(); |
| 488 | script_dir = script_dir.Append(chrome::kUserScriptsDirname); |
| 489 | } |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 490 | } |
| 491 | |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 492 | ExtensionErrorReporter::Init(true); // allow noisy errors. |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 493 | user_script_master_ = new UserScriptMaster( |
[email protected] | 9197f3b | 2009-06-02 00:49:27 | [diff] [blame] | 494 | g_browser_process->file_thread()->message_loop(), |
| 495 | script_dir); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 496 | extensions_service_ = new ExtensionsService( |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame^] | 497 | this, |
| 498 | CommandLine::ForCurrentProcess(), |
| 499 | GetPrefs(), |
| 500 | GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName), |
| 501 | MessageLoop::current(), |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 502 | g_browser_process->file_thread()->message_loop()); |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 503 | |
[email protected] | 9197f3b | 2009-06-02 00:49:27 | [diff] [blame] | 504 | extensions_service_->Init(); |
[email protected] | bdbc87c | 2009-01-25 05:08:54 | [diff] [blame] | 505 | } |
| 506 | |
[email protected] | ea0c98cf | 2009-06-18 23:02:54 | [diff] [blame] | 507 | void ProfileImpl::InitWebResources() { |
| 508 | web_resource_service_ = new WebResourceService( |
| 509 | this, |
| 510 | g_browser_process->file_thread()->message_loop()); |
| 511 | |
| 512 | web_resource_service_->StartAfterDelay(); |
| 513 | } |
| 514 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 515 | ProfileImpl::~ProfileImpl() { |
[email protected] | 169627b | 2008-12-06 19:30:19 | [diff] [blame] | 516 | tab_restore_service_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 517 | |
| 518 | StopCreateSessionServiceTimer(); |
| 519 | // TemplateURLModel schedules a task on the WebDataService from its |
| 520 | // destructor. Delete it first to ensure the task gets scheduled before we |
| 521 | // shut down the database. |
| 522 | template_url_model_.reset(); |
| 523 | |
| 524 | // The download manager queries the history system and should be deleted |
| 525 | // before the history is shutdown so it can properly cancel all requests. |
| 526 | download_manager_ = NULL; |
| 527 | |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 528 | // The theme provider provides bitmaps to whoever wants them. |
| 529 | theme_provider_ = NULL; |
| 530 | |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 531 | // Remove pref observers. |
| 532 | PrefService* prefs = GetPrefs(); |
| 533 | prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this); |
| 534 | prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this); |
[email protected] | 154a433 | 2009-06-03 20:20:58 | [diff] [blame] | 535 | prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this); |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 536 | |
[email protected] | 3a453fa | 2008-08-15 18:46:34 | [diff] [blame] | 537 | #ifdef CHROME_PERSONALIZATION |
[email protected] | 57d3d0a | 2008-09-24 00:50:07 | [diff] [blame] | 538 | personalization_.reset(); |
[email protected] | 3a453fa | 2008-08-15 18:46:34 | [diff] [blame] | 539 | #endif |
| 540 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 541 | // Both HistoryService and WebDataService maintain threads for background |
| 542 | // processing. Its possible each thread still has tasks on it that have |
| 543 | // increased the ref count of the service. In such a situation, when we |
| 544 | // decrement the refcount, it won't be 0, and the threads/databases aren't |
| 545 | // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the |
| 546 | // databases are properly closed. |
| 547 | if (web_data_service_.get()) |
| 548 | web_data_service_->Shutdown(); |
| 549 | |
| 550 | if (history_service_.get()) |
| 551 | history_service_->Cleanup(); |
| 552 | |
| 553 | // The I/O thread may be NULL during testing. |
[email protected] | ab820df | 2008-08-26 05:55:10 | [diff] [blame] | 554 | base::Thread* io_thread = g_browser_process->io_thread(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 555 | |
| 556 | if (spellchecker_) { |
| 557 | // The spellchecker must be deleted on the I/O thread. During testing, we |
| 558 | // don't have an I/O thread. |
| 559 | if (io_thread) |
| 560 | io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_); |
| 561 | else |
| 562 | spellchecker_->Release(); |
| 563 | } |
| 564 | |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 565 | if (default_request_context_ == request_context_) |
| 566 | default_request_context_ = NULL; |
[email protected] | 6ab9b20 | 2008-12-23 22:34:50 | [diff] [blame] | 567 | |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 568 | CleanupRequestContext(request_context_); |
| 569 | CleanupRequestContext(media_request_context_); |
| 570 | CleanupRequestContext(extensions_request_context_); |
[email protected] | 1e744f2 | 2009-04-08 01:00:17 | [diff] [blame] | 571 | |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 572 | // When the request contexts are gone, the blacklist wont be needed anymore. |
| 573 | delete blacklist_; |
| 574 | blacklist_ = 0; |
| 575 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 576 | // HistoryService may call into the BookmarkModel, as such we need to |
| 577 | // delete HistoryService before the BookmarkModel. The destructor for |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 578 | // HistoryService will join with HistoryService's backend thread so that |
| 579 | // by the time the destructor has finished we're sure it will no longer call |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 580 | // into the BookmarkModel. |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 581 | history_service_ = NULL; |
| 582 | bookmark_bar_model_.reset(); |
| 583 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 584 | MarkAsCleanShutdown(); |
| 585 | } |
| 586 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 587 | FilePath ProfileImpl::GetPath() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 588 | return path_; |
| 589 | } |
| 590 | |
| 591 | bool ProfileImpl::IsOffTheRecord() { |
| 592 | return false; |
| 593 | } |
| 594 | |
| 595 | Profile* ProfileImpl::GetOffTheRecordProfile() { |
| 596 | if (!off_the_record_profile_.get()) { |
| 597 | scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this)); |
| 598 | off_the_record_profile_.swap(p); |
| 599 | } |
| 600 | return off_the_record_profile_.get(); |
| 601 | } |
| 602 | |
[email protected] | 860f5549 | 2009-03-27 19:50:59 | [diff] [blame] | 603 | void ProfileImpl::DestroyOffTheRecordProfile() { |
| 604 | off_the_record_profile_.reset(); |
| 605 | } |
| 606 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 607 | Profile* ProfileImpl::GetOriginalProfile() { |
| 608 | return this; |
| 609 | } |
| 610 | |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 611 | static void BroadcastNewHistoryTable(base::SharedMemory* table_memory) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 612 | if (!table_memory) |
| 613 | return; |
| 614 | |
| 615 | // send to all RenderProcessHosts |
| 616 | for (RenderProcessHost::iterator i = RenderProcessHost::begin(); |
| 617 | i != RenderProcessHost::end(); i++) { |
| 618 | if (!i->second->channel()) |
| 619 | continue; |
| 620 | |
[email protected] | 176aa48 | 2008-11-14 03:25:15 | [diff] [blame] | 621 | base::SharedMemoryHandle new_table; |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 622 | base::ProcessHandle process = i->second->process().handle(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 623 | if (!process) { |
| 624 | // process can be null if it's started with the --single-process flag. |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 625 | process = base::Process::Current().handle(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | table_memory->ShareToProcess(process, &new_table); |
| 629 | IPC::Message* msg = new ViewMsg_VisitedLink_NewTable(new_table); |
| 630 | i->second->channel()->Send(msg); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { |
| 635 | if (!visited_link_master_.get()) { |
| 636 | scoped_ptr<VisitedLinkMaster> visited_links( |
| 637 | new VisitedLinkMaster(g_browser_process->file_thread(), |
| 638 | BroadcastNewHistoryTable, this)); |
| 639 | if (!visited_links->Init()) |
| 640 | return NULL; |
| 641 | visited_link_master_.swap(visited_links); |
| 642 | } |
| 643 | |
| 644 | return visited_link_master_.get(); |
| 645 | } |
| 646 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 647 | ExtensionsService* ProfileImpl::GetExtensionsService() { |
| 648 | return extensions_service_.get(); |
| 649 | } |
| 650 | |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 651 | UserScriptMaster* ProfileImpl::GetUserScriptMaster() { |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 652 | return user_script_master_.get(); |
[email protected] | 04fba9a9 | 2008-10-28 17:25:25 | [diff] [blame] | 653 | } |
| 654 | |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 655 | ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() { |
[email protected] | c6e4a341 | 2009-06-24 15:45:29 | [diff] [blame] | 656 | return extensions_service_->extension_process_manager(); |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 657 | } |
| 658 | |
[email protected] | 34cc84f | 2009-02-13 10:04:35 | [diff] [blame] | 659 | SSLHostState* ProfileImpl::GetSSLHostState() { |
| 660 | if (!ssl_host_state_.get()) |
| 661 | ssl_host_state_.reset(new SSLHostState()); |
| 662 | |
| 663 | DCHECK(ssl_host_state_->CalledOnValidThread()); |
| 664 | return ssl_host_state_.get(); |
| 665 | } |
| 666 | |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 667 | net::ForceTLSState* ProfileImpl::GetForceTLSState() { |
| 668 | if (!force_tls_state_.get()) |
| 669 | force_tls_state_.reset(new net::ForceTLSState()); |
| 670 | |
| 671 | return force_tls_state_.get(); |
| 672 | } |
| 673 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 674 | PrefService* ProfileImpl::GetPrefs() { |
| 675 | if (!prefs_.get()) { |
[email protected] | 6faa0e0d | 2009-04-28 06:50:36 | [diff] [blame] | 676 | prefs_.reset(new PrefService(GetPrefFilePath(), |
| 677 | g_browser_process->file_thread())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 678 | |
| 679 | // The Profile class and ProfileManager class may read some prefs so |
| 680 | // register known prefs as soon as possible. |
| 681 | Profile::RegisterUserPrefs(prefs_.get()); |
| 682 | ProfileManager::RegisterUserPrefs(prefs_.get()); |
| 683 | |
| 684 | // The last session exited cleanly if there is no pref for |
| 685 | // kSessionExitedCleanly or the value for kSessionExitedCleanly is true. |
| 686 | last_session_exited_cleanly_ = |
| 687 | prefs_->GetBoolean(prefs::kSessionExitedCleanly); |
| 688 | // Mark the session as open. |
| 689 | prefs_->SetBoolean(prefs::kSessionExitedCleanly, false); |
| 690 | // Make sure we save to disk that the session has opened. |
[email protected] | 6faa0e0d | 2009-04-28 06:50:36 | [diff] [blame] | 691 | prefs_->ScheduleSavePersistentPrefs(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | return prefs_.get(); |
| 695 | } |
| 696 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 697 | FilePath ProfileImpl::GetPrefFilePath() { |
| 698 | FilePath pref_file_path = path_; |
| 699 | pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 700 | return pref_file_path; |
| 701 | } |
| 702 | |
| 703 | URLRequestContext* ProfileImpl::GetRequestContext() { |
| 704 | if (!request_context_) { |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 705 | FilePath cookie_path = GetPath(); |
| 706 | cookie_path = cookie_path.Append(chrome::kCookieFilename); |
| 707 | FilePath cache_path = GetPath(); |
[email protected] | 2b2830a | 2009-02-07 01:58:42 | [diff] [blame] | 708 | |
| 709 | // Override the cache location if specified by the user. |
| 710 | const std::wstring user_cache_dir( |
| 711 | CommandLine::ForCurrentProcess()->GetSwitchValue( |
| 712 | switches::kDiskCacheDir)); |
| 713 | if (!user_cache_dir.empty()) { |
| 714 | cache_path = FilePath::FromWStringHack(user_cache_dir); |
| 715 | } |
| 716 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 717 | cache_path = cache_path.Append(chrome::kCacheDirname); |
[email protected] | 6ab9b20 | 2008-12-23 22:34:50 | [diff] [blame] | 718 | request_context_ = ChromeURLRequestContext::CreateOriginal( |
| 719 | this, cookie_path, cache_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 720 | request_context_->AddRef(); |
| 721 | |
[email protected] | 6ab9b20 | 2008-12-23 22:34:50 | [diff] [blame] | 722 | // The first request context is always a normal (non-OTR) request context. |
| 723 | // Even when Chromium is started in OTR mode, a normal profile is always |
| 724 | // created first. |
| 725 | if (!default_request_context_) { |
| 726 | default_request_context_ = request_context_; |
| 727 | NotificationService::current()->Notify( |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 728 | NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
[email protected] | 6ab9b20 | 2008-12-23 22:34:50 | [diff] [blame] | 729 | NotificationService::AllSources(), NotificationService::NoDetails()); |
| 730 | } |
| 731 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 732 | DCHECK(request_context_->cookie_store()); |
| 733 | } |
| 734 | |
| 735 | return request_context_; |
| 736 | } |
| 737 | |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 738 | URLRequestContext* ProfileImpl::GetRequestContextForMedia() { |
| 739 | if (!media_request_context_) { |
| 740 | FilePath cache_path = GetPath(); |
[email protected] | e3edeba | 2009-03-23 18:57:14 | [diff] [blame] | 741 | |
| 742 | // Override the cache location if specified by the user. |
| 743 | const std::wstring user_cache_dir( |
| 744 | CommandLine::ForCurrentProcess()->GetSwitchValue( |
| 745 | switches::kDiskCacheDir)); |
| 746 | if (!user_cache_dir.empty()) { |
| 747 | cache_path = FilePath::FromWStringHack(user_cache_dir); |
| 748 | } |
| 749 | |
[email protected] | 4e7b5dbb | 2009-03-25 00:09:23 | [diff] [blame] | 750 | cache_path = cache_path.Append(chrome::kMediaCacheDirname); |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 751 | media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( |
| 752 | this, cache_path); |
| 753 | media_request_context_->AddRef(); |
| 754 | |
| 755 | DCHECK(media_request_context_->cookie_store()); |
| 756 | } |
| 757 | |
| 758 | return media_request_context_; |
| 759 | } |
| 760 | |
[email protected] | 47accfd6 | 2009-05-14 18:46:21 | [diff] [blame] | 761 | URLRequestContext* ProfileImpl::GetRequestContextForExtensions() { |
| 762 | if (!extensions_request_context_) { |
| 763 | FilePath cookie_path = GetPath(); |
| 764 | cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename); |
| 765 | |
| 766 | extensions_request_context_ = |
| 767 | ChromeURLRequestContext::CreateOriginalForExtensions(this, cookie_path); |
| 768 | extensions_request_context_->AddRef(); |
| 769 | |
| 770 | DCHECK(extensions_request_context_->cookie_store()); |
| 771 | } |
| 772 | |
| 773 | return extensions_request_context_; |
| 774 | } |
| 775 | |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 776 | Blacklist* ProfileImpl::GetBlacklist() { |
| 777 | return blacklist_; |
| 778 | } |
| 779 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 780 | HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { |
| 781 | if (!history_service_created_) { |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 782 | history_service_created_ = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 783 | scoped_refptr<HistoryService> history(new HistoryService(this)); |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 784 | if (!history->Init(GetPath(), GetBookmarkModel())) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 785 | return NULL; |
| 786 | history_service_.swap(history); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 787 | |
| 788 | // Send out the notification that the history service was created. |
| 789 | NotificationService::current()-> |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 790 | Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 791 | Details<HistoryService>(history_service_.get())); |
| 792 | } |
| 793 | return history_service_.get(); |
| 794 | } |
| 795 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 796 | TemplateURLModel* ProfileImpl::GetTemplateURLModel() { |
| 797 | if (!template_url_model_.get()) |
| 798 | template_url_model_.reset(new TemplateURLModel(this)); |
| 799 | return template_url_model_.get(); |
| 800 | } |
| 801 | |
| 802 | TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() { |
| 803 | if (!template_url_fetcher_.get()) |
| 804 | template_url_fetcher_.reset(new TemplateURLFetcher(this)); |
| 805 | return template_url_fetcher_.get(); |
| 806 | } |
| 807 | |
| 808 | WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) { |
| 809 | if (!created_web_data_service_) |
| 810 | CreateWebDataService(); |
| 811 | return web_data_service_.get(); |
| 812 | } |
| 813 | |
| 814 | void ProfileImpl::CreateWebDataService() { |
| 815 | DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL); |
| 816 | created_web_data_service_ = true; |
| 817 | scoped_refptr<WebDataService> wds(new WebDataService()); |
| 818 | if (!wds->Init(GetPath())) |
| 819 | return; |
| 820 | web_data_service_.swap(wds); |
| 821 | } |
| 822 | |
[email protected] | e69d3395 | 2009-06-03 22:00:41 | [diff] [blame] | 823 | PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) { |
| 824 | if (!created_password_store_) |
| 825 | CreatePasswordStore(); |
| 826 | return password_store_.get(); |
| 827 | } |
| 828 | |
| 829 | void ProfileImpl::CreatePasswordStore() { |
| 830 | DCHECK(!created_password_store_ && password_store_.get() == NULL); |
| 831 | created_password_store_ = true; |
| 832 | scoped_refptr<PasswordStore> ps; |
| 833 | #if defined(OS_LINUX) |
| 834 | // Temporarily disabled while we figure some stuff out. |
| 835 | // http://code.google.com/p/chromium/issues/detail?id=12351 |
| 836 | // if (getenv("KDE_FULL_SESSION")) { |
| 837 | // ps = new PasswordStoreKWallet(); |
| 838 | // } else { |
| 839 | // ps = new PasswordStoreGnome(); |
| 840 | // } |
| 841 | NOTIMPLEMENTED(); |
| 842 | #elif defined(OS_WIN) |
| 843 | ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS)); |
[email protected] | 034eba5 | 2009-06-03 22:50:56 | [diff] [blame] | 844 | #elif defined(OS_MACOSX) |
| 845 | ps = new PasswordStoreMac(new MacKeychain()); |
[email protected] | e69d3395 | 2009-06-03 22:00:41 | [diff] [blame] | 846 | #else |
| 847 | NOTIMPLEMENTED(); |
| 848 | #endif |
| 849 | if (!ps || !ps->Init()) { |
| 850 | // Try falling back to the default password manager |
| 851 | LOG(WARNING) << "Could not initialise native password manager - " |
| 852 | "falling back to default"; |
| 853 | ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS)); |
| 854 | if (!ps->Init()) |
| 855 | return; |
| 856 | } |
| 857 | password_store_.swap(ps); |
| 858 | } |
| 859 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 860 | DownloadManager* ProfileImpl::GetDownloadManager() { |
| 861 | if (!created_download_manager_) { |
| 862 | scoped_refptr<DownloadManager> dlm(new DownloadManager); |
| 863 | dlm->Init(this); |
| 864 | created_download_manager_ = true; |
| 865 | download_manager_.swap(dlm); |
| 866 | } |
| 867 | return download_manager_.get(); |
| 868 | } |
| 869 | |
| 870 | bool ProfileImpl::HasCreatedDownloadManager() const { |
| 871 | return created_download_manager_; |
| 872 | } |
| 873 | |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 874 | void ProfileImpl::InitThemes() { |
| 875 | if (!created_theme_provider_) { |
| 876 | scoped_refptr<BrowserThemeProvider> themes(new BrowserThemeProvider); |
| 877 | themes->Init(this); |
| 878 | created_theme_provider_ = true; |
| 879 | theme_provider_.swap(themes); |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | void ProfileImpl::SetTheme(Extension* extension) { |
| 884 | InitThemes(); |
| 885 | theme_provider_.get()->SetTheme(extension); |
| 886 | } |
| 887 | |
| 888 | void ProfileImpl::ClearTheme() { |
| 889 | InitThemes(); |
| 890 | theme_provider_.get()->UseDefaultTheme(); |
| 891 | } |
| 892 | |
| 893 | ThemeProvider* ProfileImpl::GetThemeProvider() { |
| 894 | InitThemes(); |
| 895 | return theme_provider_.get(); |
| 896 | } |
| 897 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 898 | SessionService* ProfileImpl::GetSessionService() { |
| 899 | if (!session_service_.get() && !shutdown_session_service_) { |
| 900 | session_service_ = new SessionService(this); |
| 901 | session_service_->ResetFromCurrentBrowsers(); |
| 902 | } |
| 903 | return session_service_.get(); |
| 904 | } |
| 905 | |
| 906 | void ProfileImpl::ShutdownSessionService() { |
| 907 | if (shutdown_session_service_) |
| 908 | return; |
| 909 | |
| 910 | // We're about to exit, force creation of the session service if it hasn't |
| 911 | // been created yet. We do this to ensure session state matches the point in |
| 912 | // time the user exited. |
| 913 | GetSessionService(); |
| 914 | shutdown_session_service_ = true; |
| 915 | session_service_ = NULL; |
| 916 | } |
| 917 | |
| 918 | bool ProfileImpl::HasSessionService() const { |
| 919 | return (session_service_.get() != NULL); |
| 920 | } |
| 921 | |
| 922 | std::wstring ProfileImpl::GetName() { |
| 923 | return GetPrefs()->GetString(prefs::kProfileName); |
| 924 | } |
| 925 | void ProfileImpl::SetName(const std::wstring& name) { |
| 926 | GetPrefs()->SetString(prefs::kProfileName, name); |
| 927 | } |
| 928 | |
| 929 | std::wstring ProfileImpl::GetID() { |
| 930 | return GetPrefs()->GetString(prefs::kProfileID); |
| 931 | } |
| 932 | void ProfileImpl::SetID(const std::wstring& id) { |
| 933 | GetPrefs()->SetString(prefs::kProfileID, id); |
| 934 | } |
| 935 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 936 | bool ProfileImpl::DidLastSessionExitCleanly() { |
| 937 | // last_session_exited_cleanly_ is set when the preferences are loaded. Force |
| 938 | // it to be set by asking for the prefs. |
| 939 | GetPrefs(); |
| 940 | return last_session_exited_cleanly_; |
| 941 | } |
| 942 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 943 | BookmarkModel* ProfileImpl::GetBookmarkModel() { |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 944 | if (!bookmark_bar_model_.get()) { |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 945 | bookmark_bar_model_.reset(new BookmarkModel(this)); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 946 | bookmark_bar_model_->Load(); |
| 947 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 948 | return bookmark_bar_model_.get(); |
| 949 | } |
| 950 | |
| 951 | bool ProfileImpl::IsSameProfile(Profile* profile) { |
| 952 | if (profile == static_cast<Profile*>(this)) |
| 953 | return true; |
| 954 | OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get(); |
| 955 | return otr_profile && profile == static_cast<Profile*>(otr_profile); |
| 956 | } |
| 957 | |
| 958 | Time ProfileImpl::GetStartTime() const { |
| 959 | return start_time_; |
| 960 | } |
| 961 | |
| 962 | TabRestoreService* ProfileImpl::GetTabRestoreService() { |
| 963 | if (!tab_restore_service_.get()) |
[email protected] | 169627b | 2008-12-06 19:30:19 | [diff] [blame] | 964 | tab_restore_service_ = new TabRestoreService(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 965 | return tab_restore_service_.get(); |
| 966 | } |
| 967 | |
[email protected] | 44947830 | 2009-06-09 20:04:28 | [diff] [blame] | 968 | ThumbnailStore* ProfileImpl::GetThumbnailStore() { |
| 969 | if (!thumbnail_store_.get()) { |
| 970 | thumbnail_store_ = new ThumbnailStore; |
[email protected] | f2458dc | 2009-06-24 22:38:58 | [diff] [blame] | 971 | thumbnail_store_->Init(GetPath().AppendASCII("thumbnailstore"), this); |
[email protected] | 44947830 | 2009-06-09 20:04:28 | [diff] [blame] | 972 | } |
| 973 | return thumbnail_store_.get(); |
| 974 | } |
| 975 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 976 | void ProfileImpl::ResetTabRestoreService() { |
[email protected] | 169627b | 2008-12-06 19:30:19 | [diff] [blame] | 977 | tab_restore_service_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 978 | } |
| 979 | |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 980 | // To be run in the IO thread to notify all resource message filters that the |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 981 | // spellchecker has changed. |
| 982 | class NotifySpellcheckerChangeTask : public Task { |
| 983 | public: |
| 984 | NotifySpellcheckerChangeTask( |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 985 | Profile* profile, |
| 986 | const SpellcheckerReinitializedDetails& spellchecker) |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 987 | : profile_(profile), |
| 988 | spellchecker_(spellchecker) { |
| 989 | } |
| 990 | |
| 991 | private: |
| 992 | void Run(void) { |
| 993 | NotificationService::current()->Notify( |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 994 | NotificationType::SPELLCHECKER_REINITIALIZED, |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 995 | Source<Profile>(profile_), |
| 996 | Details<SpellcheckerReinitializedDetails>(&spellchecker_)); |
| 997 | } |
| 998 | |
| 999 | Profile* profile_; |
| 1000 | SpellcheckerReinitializedDetails spellchecker_; |
| 1001 | }; |
| 1002 | |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1003 | void ProfileImpl::InitializeSpellChecker(bool need_to_broadcast) { |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1004 | // The I/O thread may be NULL during testing. |
| 1005 | base::Thread* io_thread = g_browser_process->io_thread(); |
| 1006 | if (spellchecker_) { |
| 1007 | // The spellchecker must be deleted on the I/O thread. |
| 1008 | // A dummy variable to aid in logical clarity. |
| 1009 | SpellChecker* last_spellchecker = spellchecker_; |
| 1010 | |
| 1011 | if (io_thread) |
| 1012 | io_thread->message_loop()->ReleaseSoon(FROM_HERE, last_spellchecker); |
| 1013 | else // during testing, we don't have an I/O thread |
| 1014 | last_spellchecker->Release(); |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1015 | } |
| 1016 | |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1017 | // Retrieve the (perhaps updated recently) dictionary name from preferences. |
| 1018 | PrefService* prefs = GetPrefs(); |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1019 | bool enable_spellcheck = prefs->GetBoolean(prefs::kEnableSpellCheck); |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1020 | |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1021 | if (enable_spellcheck) { |
[email protected] | bd17b70 | 2009-02-25 20:44:08 | [diff] [blame] | 1022 | FilePath dict_dir; |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1023 | PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir); |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 1024 | // Note that, as the object pointed to by previously by spellchecker_ |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1025 | // is being deleted in the io thread, the spellchecker_ can be made to point |
| 1026 | // to a new object (RE-initialized) in parallel in this UI thread. |
[email protected] | 4b4d1adc | 2008-12-10 22:28:58 | [diff] [blame] | 1027 | spellchecker_ = new SpellChecker(dict_dir, |
[email protected] | 74c8b42 | 2009-03-11 00:34:12 | [diff] [blame] | 1028 | WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)), |
| 1029 | GetRequestContext(), |
[email protected] | bd17b70 | 2009-02-25 20:44:08 | [diff] [blame] | 1030 | FilePath()); |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1031 | spellchecker_->AddRef(); // Manual refcounting. |
| 1032 | } else { |
| 1033 | spellchecker_ = NULL; |
| 1034 | } |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1035 | |
[email protected] | 154a433 | 2009-06-03 20:20:58 | [diff] [blame] | 1036 | // Set auto spell correct status for spellchecker. |
| 1037 | if (spellchecker_) { |
| 1038 | spellchecker_->EnableAutoSpellCorrect( |
| 1039 | prefs->GetBoolean(prefs::kEnableAutoSpellCorrect)); |
| 1040 | } |
| 1041 | |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1042 | if (need_to_broadcast && io_thread) { // Notify resource message filters. |
| 1043 | SpellcheckerReinitializedDetails scoped_spellchecker; |
| 1044 | scoped_spellchecker.spellchecker = spellchecker_; |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1045 | if (io_thread) { |
| 1046 | io_thread->message_loop()->PostTask( |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 1047 | FROM_HERE, |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1048 | new NotifySpellcheckerChangeTask(this, scoped_spellchecker)); |
| 1049 | } |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1053 | void ProfileImpl::ReinitializeSpellChecker() { |
| 1054 | InitializeSpellChecker(true); |
| 1055 | } |
| 1056 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1057 | SpellChecker* ProfileImpl::GetSpellChecker() { |
| 1058 | if (!spellchecker_) { |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1059 | // This is where spellchecker gets initialized. Note that this is being |
| 1060 | // initialized in the ui_thread. However, this is not a problem as long as |
| 1061 | // it is *used* in the io thread. |
[email protected] | 34cc84f | 2009-02-13 10:04:35 | [diff] [blame] | 1062 | // TODO(sidchat): One day, change everything so that spellchecker gets |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1063 | // initialized in the IO thread itself. |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1064 | InitializeSpellChecker(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1065 | } |
[email protected] | 2093085 | 2008-10-15 19:30:41 | [diff] [blame] | 1066 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1067 | return spellchecker_; |
| 1068 | } |
| 1069 | |
| 1070 | void ProfileImpl::MarkAsCleanShutdown() { |
| 1071 | if (prefs_.get()) { |
| 1072 | // The session cleanly exited, set kSessionExitedCleanly appropriately. |
| 1073 | prefs_->SetBoolean(prefs::kSessionExitedCleanly, true); |
| 1074 | |
| 1075 | // NOTE: If you change what thread this writes on, be sure and update |
| 1076 | // ChromeFrame::EndSession(). |
[email protected] | 6faa0e0d | 2009-04-28 06:50:36 | [diff] [blame] | 1077 | prefs_->SavePersistentPrefs(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1081 | void ProfileImpl::Observe(NotificationType type, |
| 1082 | const NotificationSource& source, |
| 1083 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 1084 | if (NotificationType::PREF_CHANGED == type) { |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1085 | std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); |
| 1086 | PrefService* prefs = Source<PrefService>(source).ptr(); |
| 1087 | DCHECK(pref_name_in && prefs); |
| 1088 | if (*pref_name_in == prefs::kSpellCheckDictionary || |
[email protected] | 154a433 | 2009-06-03 20:20:58 | [diff] [blame] | 1089 | *pref_name_in == prefs::kEnableSpellCheck || |
| 1090 | *pref_name_in == prefs::kEnableAutoSpellCorrect) { |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1091 | InitializeSpellChecker(true); |
| 1092 | } |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 1093 | } else if (NotificationType::THEME_INSTALLED == type) { |
| 1094 | Extension* extension = Details<Extension>(details).ptr(); |
| 1095 | SetTheme(extension); |
[email protected] | e7244d8 | 2008-10-29 18:13:26 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1099 | void ProfileImpl::StopCreateSessionServiceTimer() { |
[email protected] | 2d31666 | 2008-09-03 18:18:14 | [diff] [blame] | 1100 | create_session_service_timer_.Stop(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1101 | } |
[email protected] | 3a453fa | 2008-08-15 18:46:34 | [diff] [blame] | 1102 | |
| 1103 | #ifdef CHROME_PERSONALIZATION |
[email protected] | 57d3d0a | 2008-09-24 00:50:07 | [diff] [blame] | 1104 | ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { |
[email protected] | 57d3d0a | 2008-09-24 00:50:07 | [diff] [blame] | 1105 | return personalization_.get(); |
[email protected] | 3a453fa | 2008-08-15 18:46:34 | [diff] [blame] | 1106 | } |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1107 | #endif |