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