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