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