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