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