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