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