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