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