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