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