blob: a5ade1e49c6ff29f7dff041d7243d0b6a0c1e46a [file] [log] [blame]
[email protected]e284e6d82010-01-29 19:49:451// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/profile.h"
6
[email protected]1952c7d2010-03-04 23:48:347#include "app/resource_bundle.h"
[email protected]2735e3692009-09-25 18:19:398#include "app/theme_provider.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/command_line.h"
[email protected]fee67982010-04-23 17:24:2210#include "base/env_var.h"
[email protected]04fba9a92008-10-28 17:25:2511#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4412#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/path_service.h"
14#include "base/scoped_ptr.h"
15#include "base/string_util.h"
[email protected]0082d7e0d2010-02-27 14:34:1216#include "chrome/browser/appcache/chrome_appcache_service.h"
[email protected]69c579e2010-04-23 20:01:0017#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]def11712009-11-06 00:42:1518#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4219#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5121#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5722#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0223#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3724#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4225#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5626#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0727#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]14a000d2010-04-29 21:44:2428#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]7120f132009-07-20 21:05:3729#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0530#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2531#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3532#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4833#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5334#include "chrome/browser/find_bar_state.h"
[email protected]aee541e2010-03-19 01:52:4535#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]9c92d192009-12-02 08:03:1636#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4237#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4238#include "chrome/browser/history/history.h"
[email protected]e284e6d82010-01-29 19:49:4539#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5140#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0641#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]277404c22010-04-22 13:09:4542#include "chrome/browser/json_pref_store.h"
[email protected]6ab9b202008-12-23 22:34:5043#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4244#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2645#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4146#include "chrome/browser/password_manager/password_store_default.h"
[email protected]8c6335d32010-01-20 09:21:5047#include "chrome/browser/privacy_blacklist/blacklist.h"
[email protected]1bd056e2010-04-20 02:03:4848#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2650#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3351#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4652#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4453#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3054#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3355#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1156#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4357#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4058#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2859#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0660#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2961#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3962#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2963#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5664#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2965#include "chrome/common/chrome_constants.h"
66#include "chrome/common/chrome_paths.h"
67#include "chrome/common/chrome_switches.h"
initial.commit09911bf2008-07-26 23:55:2968#include "chrome/common/notification_service.h"
69#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3270#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3471#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5872#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4273#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3474#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2975
[email protected]753efc42010-03-09 19:52:1676#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2977#include "chrome/browser/gtk/gtk_theme_provider.h"
78#endif
79
[email protected]e1acf6f2008-10-27 20:43:3380using base::Time;
81using base::TimeDelta;
82
[email protected]e5642992009-06-26 23:06:3183namespace {
84
initial.commit09911bf2008-07-26 23:55:2985// Delay, in milliseconds, before we explicitly create the SessionService.
86static const int kCreateSessionServiceDelayMS = 500;
87
[email protected]e5642992009-06-26 23:06:3188enum ContextType {
89 kNormalContext,
90 kMediaContext
91};
92
93// Gets the cache parameters from the command line. |type| is the type of
94// request context that we need, |cache_path| will be set to the user provided
95// path, or will not be touched if there is not an argument. |max_size| will
96// be the user provided value or zero by default.
97void GetCacheParameters(ContextType type, FilePath* cache_path,
98 int* max_size) {
99 DCHECK(cache_path);
100 DCHECK(max_size);
101
102 // Override the cache location if specified by the user.
103 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
104 switches::kDiskCacheDir));
105
106 if (!user_path.empty()) {
107 *cache_path = FilePath::FromWStringHack(user_path);
108 }
109
[email protected]b7e0a2a2009-10-13 02:07:25110 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
111 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31112 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25113 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31114
115 // By default we let the cache determine the right size.
116 *max_size = 0;
117 if (!StringToInt(value, max_size)) {
118 *max_size = 0;
119 } else if (max_size < 0) {
120 *max_size = 0;
121 }
122}
123
[email protected]405a64b2009-09-16 21:03:44124FilePath GetCachePath(const FilePath& base) {
125 return base.Append(chrome::kCacheDirname);
126}
127
128FilePath GetMediaCachePath(const FilePath& base) {
129 return base.Append(chrome::kMediaCacheDirname);
130}
131
132bool HasACacheSubdir(const FilePath &dir) {
133 return file_util::PathExists(GetCachePath(dir)) ||
134 file_util::PathExists(GetMediaCachePath(dir));
135}
136
[email protected]57a777f72010-03-31 01:09:42137void PostExtensionLoadedToContextGetter(ChromeURLRequestContextGetter* getter,
138 Extension* extension) {
139 if (!getter)
140 return;
141 // Callee takes ownership of new ExtensionInfo struct.
142 ChromeThread::PostTask(
143 ChromeThread::IO, FROM_HERE,
144 NewRunnableMethod(getter,
145 &ChromeURLRequestContextGetter::OnNewExtensions,
146 extension->id(),
147 new ChromeURLRequestContext::ExtensionInfo(
148 extension->path(),
149 extension->default_locale(),
150 extension->web_extent(),
151 extension->api_permissions())));
152}
153
154void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
155 Extension* extension) {
156 if (!getter)
157 return;
158 ChromeThread::PostTask(
159 ChromeThread::IO, FROM_HERE,
160 NewRunnableMethod(getter,
161 &ChromeURLRequestContextGetter::OnUnloadedExtension,
162 extension->id()));
163}
164
[email protected]e5642992009-06-26 23:06:31165} // namespace
166
initial.commit09911bf2008-07-26 23:55:29167// A pointer to the request context for the default profile. See comments on
168// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31169URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29170
[email protected]be180c802009-10-23 06:33:31171static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19172 if (context)
[email protected]47accfd62009-05-14 18:46:21173 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21174}
175
[email protected]34cc84f2009-02-13 10:04:35176// static
[email protected]4bf6afd2009-10-08 14:00:11177const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
178
179// static
initial.commit09911bf2008-07-26 23:55:29180void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55181 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29182 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
183 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12184 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26185 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
186 IDS_SPELLCHECK_DICTIONARY);
187 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58188 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16189#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06190 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
191 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29192#endif
[email protected]f017cc92009-12-14 20:48:07193 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34194 prefs->RegisterStringPref(prefs::kCurrentThemeID,
195 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42196 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
197 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
198 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50199 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23200 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29201}
202
[email protected]34cc84f2009-02-13 10:04:35203// static
[email protected]f7011fcb2009-01-28 21:54:32204Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29205 return new ProfileImpl(path);
206}
207
[email protected]34cc84f2009-02-13 10:04:35208// static
[email protected]be180c802009-10-23 06:33:31209URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29210 return default_request_context_;
211}
212
[email protected]753efc42010-03-09 19:52:16213#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41214#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56215#elif defined(OS_MACOSX)
216#include "chrome/browser/keychain_mac.h"
217#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16218#elif defined(OS_POSIX)
219// Temporarily disabled while we figure some stuff out.
220// http://code.google.com/p/chromium/issues/detail?id=12351
221// #include "chrome/browser/password_manager/password_store_gnome.h"
222// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41223#endif
initial.commit09911bf2008-07-26 23:55:29224
initial.commit09911bf2008-07-26 23:55:29225////////////////////////////////////////////////////////////////////////////////
226//
227// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42228// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29229//
230////////////////////////////////////////////////////////////////////////////////
231class OffTheRecordProfileImpl : public Profile,
232 public NotificationObserver {
233 public:
234 explicit OffTheRecordProfileImpl(Profile* real_profile)
235 : profile_(real_profile),
236 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31237 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05238
initial.commit09911bf2008-07-26 23:55:29239 // Register for browser close notifications so we can detect when the last
240 // off-the-record window is closed, in which case we can clean our states
241 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43242 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
243 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29244 }
245
246 virtual ~OffTheRecordProfileImpl() {
[email protected]098c743d2010-05-04 07:58:59247 NotificationService::current()->Notify(
248 NotificationType::PROFILE_DESTROYED,
249 Source<Profile>(this),
250 NotificationService::NoDetails());
251 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29252 }
253
[email protected]4bf6afd2009-10-08 14:00:11254 virtual ProfileId GetRuntimeId() {
255 return reinterpret_cast<ProfileId>(this);
256 }
257
[email protected]a6d0f182010-01-12 08:01:44258 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29259
260 virtual bool IsOffTheRecord() {
261 return true;
262 }
263
264 virtual Profile* GetOffTheRecordProfile() {
265 return this;
266 }
267
[email protected]860f55492009-03-27 19:50:59268 virtual void DestroyOffTheRecordProfile() {
269 // Suicide is bad!
270 NOTREACHED();
271 }
272
initial.commit09911bf2008-07-26 23:55:29273 virtual Profile* GetOriginalProfile() {
274 return profile_;
275 }
276
[email protected]2f351cb2009-11-09 23:43:34277 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
278 if (!db_tracker_)
279 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
280 return db_tracker_;
281 }
282
initial.commit09911bf2008-07-26 23:55:29283 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49284 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
285 // because we don't want to leak the sites that the user has visited before.
286 return NULL;
initial.commit09911bf2008-07-26 23:55:29287 }
288
[email protected]6014d672008-12-05 00:38:25289 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21290 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25291 }
292
[email protected]0938d3c2009-01-09 20:37:35293 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21294 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25295 }
296
[email protected]89ebc7e2009-08-24 22:11:07297 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21298 // TODO(mpcomplete): figure out whether we should return the original
299 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07300 return NULL;
301 }
302
[email protected]481e1a42009-05-06 20:56:05303 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21304 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05305 }
306
[email protected]7120f132009-07-20 21:05:37307 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21308 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37309 }
310
[email protected]34cc84f2009-02-13 10:04:35311 virtual SSLHostState* GetSSLHostState() {
312 if (!ssl_host_state_.get())
313 ssl_host_state_.reset(new SSLHostState());
314
315 DCHECK(ssl_host_state_->CalledOnValidThread());
316 return ssl_host_state_.get();
317 }
318
[email protected]326e6792009-12-11 21:04:42319 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54320 if (!transport_security_state_.get())
321 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23322
[email protected]326e6792009-12-11 21:04:42323 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23324 }
325
initial.commit09911bf2008-07-26 23:55:29326 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54327 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29328 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54329
330 NOTREACHED() << "This profile is OffTheRecord";
331 return NULL;
initial.commit09911bf2008-07-26 23:55:29332 }
333
[email protected]0850fa62009-10-08 22:34:29334 virtual HistoryService* GetHistoryServiceWithoutCreating() {
335 return profile_->GetHistoryServiceWithoutCreating();
336 }
337
[email protected]0189bc722009-08-28 21:56:48338 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54339 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48340 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54341
342 NOTREACHED() << "This profile is OffTheRecord";
343 return NULL;
[email protected]0189bc722009-08-28 21:56:48344 }
345
[email protected]69c579e2010-04-23 20:01:00346 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
347 return profile_->GetAutocompleteClassifier();
[email protected]90085af02009-10-29 17:53:21348 }
349
initial.commit09911bf2008-07-26 23:55:29350 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54351 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29352 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54353
354 NOTREACHED() << "This profile is OffTheRecord";
355 return NULL;
initial.commit09911bf2008-07-26 23:55:29356 }
357
[email protected]9cddbe372009-10-23 21:23:53358 virtual WebDataService* GetWebDataServiceWithoutCreating() {
359 return profile_->GetWebDataServiceWithoutCreating();
360 }
361
[email protected]e69d33952009-06-03 22:00:41362 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54363 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41364 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54365
366 NOTREACHED() << "This profile is OffTheRecord";
367 return NULL;
[email protected]e69d33952009-06-03 22:00:41368 }
369
initial.commit09911bf2008-07-26 23:55:29370 virtual PrefService* GetPrefs() {
371 return profile_->GetPrefs();
372 }
373
374 virtual TemplateURLModel* GetTemplateURLModel() {
375 return profile_->GetTemplateURLModel();
376 }
377
378 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
379 return profile_->GetTemplateURLFetcher();
380 }
381
382 virtual DownloadManager* GetDownloadManager() {
383 if (!download_manager_.get()) {
384 scoped_refptr<DownloadManager> dlm(new DownloadManager);
385 dlm->Init(this);
386 download_manager_.swap(dlm);
387 }
388 return download_manager_.get();
389 }
390
391 virtual bool HasCreatedDownloadManager() const {
392 return (download_manager_.get() != NULL);
393 }
394
[email protected]def11712009-11-06 00:42:15395 virtual PersonalDataManager* GetPersonalDataManager() {
396 return NULL;
397 }
398
[email protected]4a190632009-05-09 01:07:42399 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54400 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42401 }
402
403 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54404 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42405 }
406
[email protected]a5166af62009-07-03 00:42:29407 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54408 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29409 }
410
[email protected]4a190632009-05-09 01:07:42411 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54412 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42413 }
414
[email protected]51c490b2009-08-03 16:34:34415 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54416 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34417 }
418
[email protected]5786d3d2009-12-18 00:18:44419 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54420 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42421 }
422
[email protected]be180c802009-10-23 06:33:31423 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29424 return request_context_;
425 }
426
[email protected]be180c802009-10-23 06:33:31427 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11428 // In OTR mode, media request context is the same as the original one.
429 return request_context_;
[email protected]e7f29642009-03-02 22:53:18430 }
431
[email protected]be180c802009-10-23 06:33:31432 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21433 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21434 }
435
[email protected]db36938c2009-08-19 21:48:42436 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54437 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42438 }
439
[email protected]e284e6d82010-01-29 19:49:45440 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]bd147842010-04-09 15:29:17441 // Retrieve the host content settings map of the parent profile in order to
442 // ensure the preferences have been migrated.
443 profile_->GetHostContentSettingsMap();
444 if (!host_content_settings_map_.get())
445 host_content_settings_map_ = new HostContentSettingsMap(this);
446 return host_content_settings_map_.get();
[email protected]e284e6d82010-01-29 19:49:45447 }
448
[email protected]40bd6582009-12-04 23:49:51449 virtual HostZoomMap* GetHostZoomMap() {
[email protected]779c3362010-01-30 01:09:33450 return profile_->GetHostZoomMap();
[email protected]40bd6582009-12-04 23:49:51451 }
452
[email protected]aee541e2010-03-19 01:52:45453 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
454 return profile_->GetGeolocationContentSettingsMap();
455 }
456
[email protected]8c6335d32010-01-20 09:21:50457 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54458 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23459 }
460
[email protected]6c32ce72010-03-08 05:18:06461 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
462 return profile_->GetUserStyleSheetWatcher();
463 }
464
[email protected]e5d2f7132010-04-09 18:13:53465 virtual FindBarState* GetFindBarState() {
466 if (!find_bar_state_.get())
467 find_bar_state_.reset(new FindBarState());
468 return find_bar_state_.get();
469 }
470
initial.commit09911bf2008-07-26 23:55:29471 virtual SessionService* GetSessionService() {
472 // Don't save any sessions when off the record.
473 return NULL;
474 }
475
476 virtual void ShutdownSessionService() {
477 // We don't allow a session service, nothing to do.
478 }
479
480 virtual bool HasSessionService() const {
481 // We never have a session service.
482 return false;
483 }
484
initial.commit09911bf2008-07-26 23:55:29485 virtual bool DidLastSessionExitCleanly() {
486 return profile_->DidLastSessionExitCleanly();
487 }
488
[email protected]d8e41ed2008-09-11 15:22:32489 virtual BookmarkModel* GetBookmarkModel() {
490 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29491 }
492
[email protected]4bb336302009-10-12 05:44:26493 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58494 if (!desktop_notification_service_.get()) {
495 desktop_notification_service_.reset(new DesktopNotificationService(
496 this, g_browser_process->notification_ui_manager()));
497 }
498 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26499 }
500
[email protected]48352c12009-08-15 01:19:11501 virtual ProfileSyncService* GetProfileSyncService() {
502 return NULL;
[email protected]3a453fa2008-08-15 18:46:34503 }
[email protected]3a453fa2008-08-15 18:46:34504
[email protected]1bd056e2010-04-20 02:03:48505 virtual CloudPrintProxyService* GetCloudPrintProxyService() {
506 return NULL;
507 }
508
initial.commit09911bf2008-07-26 23:55:29509 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54510 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29511 }
512
513 virtual Time GetStartTime() const {
514 return start_time_;
515 }
516
517 virtual TabRestoreService* GetTabRestoreService() {
518 return NULL;
519 }
520
[email protected]e7244d82008-10-29 18:13:26521 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41522 }
523
[email protected]85c55dc2009-11-06 03:05:46524 virtual SpellCheckHost* GetSpellCheckHost() {
525 return profile_->GetSpellCheckHost();
526 }
527
528 virtual void ReinitializeSpellCheckHost(bool force) {
529 profile_->ReinitializeSpellCheckHost(force);
530 }
[email protected]85c55dc2009-11-06 03:05:46531
[email protected]3bf335a2009-06-26 20:46:06532 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29533 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21534 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29535 DCHECK(webkit_context_.get());
536 return webkit_context_.get();
537 }
[email protected]3bf335a2009-06-26 20:46:06538
[email protected]449478302009-06-09 20:04:28539 virtual ThumbnailStore* GetThumbnailStore() {
540 return NULL;
541 }
542
initial.commit09911bf2008-07-26 23:55:29543 virtual void MarkAsCleanShutdown() {
544 }
545
[email protected]bdbc87c2009-01-25 05:08:54546 virtual void InitExtensions() {
547 NOTREACHED();
548 }
549
[email protected]ea0c98cf2009-06-18 23:02:54550 virtual void InitWebResources() {
551 NOTREACHED();
552 }
553
[email protected]9c8dd902009-11-19 17:50:42554 virtual NTPResourceCache* GetNTPResourceCache() {
555 // Just return the real profile resource cache.
556 return profile_->GetNTPResourceCache();
557 }
558
initial.commit09911bf2008-07-26 23:55:29559 virtual void ExitedOffTheRecordMode() {
560 // Drop our download manager so we forget about all the downloads made
561 // in off-the-record mode.
562 download_manager_ = NULL;
563 }
564
565 virtual void Observe(NotificationType type,
566 const NotificationSource& source,
567 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56568 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29569 // We are only interested in OTR browser closing.
570 if (Source<Browser>(source)->profile() != this)
571 return;
572
573 // Let's check if we still have an Off The Record window opened.
574 // Note that we check against 1 as this notification is sent before the
575 // browser window is actually removed from the list.
576 if (BrowserList::GetBrowserCount(this) <= 1)
577 ExitedOffTheRecordMode();
578 }
579
580 private:
[email protected]88cf3292009-05-22 01:48:43581 NotificationRegistrar registrar_;
582
initial.commit09911bf2008-07-26 23:55:29583 // The real underlying profile.
584 Profile* profile_;
585
[email protected]6ab9b202008-12-23 22:34:50586 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19587 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29588
589 // The download manager that only stores downloaded items in memory.
590 scoped_refptr<DownloadManager> download_manager_;
591
[email protected]7d7696c52009-12-01 20:54:58592 // Use a separate desktop notification service for OTR.
593 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
594
[email protected]bd147842010-04-09 15:29:17595 // We use a non-writable content settings map for OTR.
596 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
597
[email protected]3bf335a2009-06-26 20:46:06598 // Use a special WebKit context for OTR browsing.
599 scoped_refptr<WebKitContext> webkit_context_;
600
[email protected]34cc84f2009-02-13 10:04:35601 // We don't want SSLHostState from the OTR profile to leak back to the main
602 // profile because then the main profile would learn some of the host names
603 // the user visited while OTR.
604 scoped_ptr<SSLHostState> ssl_host_state_;
605
[email protected]e5d2f7132010-04-09 18:13:53606 // Use a separate FindBarState so search terms do not leak back to the main
607 // profile.
608 scoped_ptr<FindBarState> find_bar_state_;
609
[email protected]326e6792009-12-11 21:04:42610 // The TransportSecurityState that only stores enabled sites in memory.
611 scoped_refptr<net::TransportSecurityState>
612 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23613
initial.commit09911bf2008-07-26 23:55:29614 // Time we were started.
615 Time start_time_;
616
[email protected]2f351cb2009-11-09 23:43:34617 // The main database tracker for this profile.
618 // Should be used only on the file thread.
619 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
620
[email protected]90085af02009-10-29 17:53:21621 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29622};
623
[email protected]f7011fcb2009-01-28 21:54:32624ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29625 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44626 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07627 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32628 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57629 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21630 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45631 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51632 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32633 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48634 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32635 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41636 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32637 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42638 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32639 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46640 spellcheck_host_(NULL),
641 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29642 shutdown_session_service_(false) {
643 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
644 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14645 create_session_service_timer_.Start(
646 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
647 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54648
[email protected]89ebc7e2009-08-24 22:11:07649 if (CommandLine::ForCurrentProcess()->HasSwitch(
650 switches::kEnableExtensionTimelineApi)) {
651 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
652 }
653
[email protected]382a0702009-06-26 17:12:27654 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37655 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27656
[email protected]e7244d82008-10-29 18:13:26657 PrefService* prefs = GetPrefs();
658 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
659 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58660 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58661
[email protected]405a64b2009-09-16 21:03:44662#if defined(OS_MACOSX)
663 // If the profile directory doesn't already have a cache directory and it
664 // is under ~/Library/Application Support, use a suitable cache directory
665 // under ~/Library/Caches. For example, a profile directory of
666 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
667 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
668 // ~/Library/Caches/Google/Chrome/MyProfileName.
669 //
670 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44671 if (!HasACacheSubdir(path_)) {
672 FilePath app_data_path, user_cache_path;
673 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12674 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44675 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
676 base_cache_path_ = user_cache_path;
677 }
678 }
[email protected]9e9b6e8e2009-12-02 08:45:01679#elif defined(OS_POSIX) // Posix minus Mac.
680 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
681 // for a spec on where cache files go. The net effect for most systems is we
682 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
683 // official builds.
684 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
685#if defined(GOOGLE_CHROME_BUILD)
686 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44687#else
[email protected]9e9b6e8e2009-12-02 08:45:01688 const char kCacheDir[] = "chromium";
689#endif
690 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
691 base_cache_path_ = base_cache_path_.Append(kCacheDir);
692 if (!file_util::PathExists(base_cache_path_))
693 file_util::CreateDirectory(base_cache_path_);
694 }
[email protected]405a64b2009-09-16 21:03:44695#endif
[email protected]bc96d562009-08-11 18:45:13696 if (base_cache_path_.empty())
697 base_cache_path_ = path_;
698
[email protected]4a190632009-05-09 01:07:42699 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43700 registrar_.Add(this, NotificationType::THEME_INSTALLED,
701 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11702
703 // Listen for bookmark model load, to bootstrap the sync service.
704 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
705 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42706
707 ssl_config_service_manager_.reset(
708 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53709
710#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29711 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53712#endif
[email protected]911f8152010-03-18 16:46:40713
714 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29715}
716
[email protected]bdbc87c2009-01-25 05:08:54717void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41718 if (user_script_master_ || extensions_service_)
719 return; // Already initialized.
720
[email protected]bdbc87c2009-01-25 05:08:54721 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18722 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36723
724 FilePath script_dir; // Don't look for user scripts in any directory.
725 // TODO(aa): We should just remove this functionality,
726 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51727 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36728
[email protected]894bb502009-05-21 22:39:57729 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23730 this,
731 CommandLine::ForCurrentProcess(),
732 GetPrefs(),
733 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36734 true);
[email protected]bdbc87c2009-01-25 05:08:54735
[email protected]fee67982010-04-23 17:24:22736 // Register the component extensions.
737 std::map<std::string, int> component_extensions;
738
739 // Bookmark manager.
[email protected]47e532b2010-04-23 17:46:40740 component_extensions["bookmark_manager"] = IDR_BOOKMARKS_MANIFEST;
[email protected]fee67982010-04-23 17:24:22741
[email protected]abdc9fb52010-05-06 01:44:48742#if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
[email protected]ae90f252010-05-04 18:28:03743 // Chat manager.
744 if (CommandLine::ForCurrentProcess()->HasSwitch(
745 switches::kEnableChatManager)) {
746 component_extensions["chat_manager"] = IDR_CHAT_MANAGER_MANIFEST;
747 }
748#endif
749
[email protected]fee67982010-04-23 17:24:22750 // Some sample apps to make our lives easier while we are developing extension
751 // apps. This way we don't have to constantly install these over and over.
752 if (CommandLine::ForCurrentProcess()->HasSwitch(
753 switches::kEnableExtensionApps)) {
754#if defined(OS_WIN)
755 std::string user_domain;
756 if (base::EnvVarGetter::Create()->GetEnv("USERDOMAIN", &user_domain) &&
757 user_domain == "GOOGLE") {
758 component_extensions["gmail_app"] = IDR_GMAIL_APP_MANIFEST;
759 component_extensions["calendar_app"] = IDR_CALENDAR_APP_MANIFEST;
760 component_extensions["docs_app"] = IDR_DOCS_APP_MANIFEST;
761 }
762#endif
763 }
764
765 for (std::map<std::string, int>::iterator iter = component_extensions.begin();
766 iter != component_extensions.end(); ++iter) {
767 FilePath path;
768 if (PathService::Get(chrome::DIR_RESOURCES, &path)) {
769 path = path.AppendASCII(iter->first);
[email protected]1952c7d2010-03-04 23:48:34770 } else {
771 NOTREACHED();
772 }
[email protected]fee67982010-04-23 17:24:22773
774 std::string manifest =
775 ResourceBundle::GetSharedInstance().GetRawDataResource(
776 iter->second).as_string();
777 extensions_service_->register_component_extension(
778 ExtensionsService::ComponentExtensionInfo(manifest, path));
[email protected]1952c7d2010-03-04 23:48:34779 }
780
[email protected]9197f3b2009-06-02 00:49:27781 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12782
783 // Load any extensions specified with --load-extension.
784 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10785 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12786 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12787 }
[email protected]bdbc87c2009-01-25 05:08:54788}
789
[email protected]ea0c98cf2009-06-18 23:02:54790void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07791 if (web_resource_service_)
792 return; // Already initialized.
793
[email protected]6fad2632009-11-02 05:59:37794 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54795 web_resource_service_->StartAfterDelay();
796}
797
[email protected]9c8dd902009-11-19 17:50:42798NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
799 if (!ntp_resource_cache_.get())
800 ntp_resource_cache_.reset(new NTPResourceCache(this));
801 return ntp_resource_cache_.get();
802}
803
initial.commit09911bf2008-07-26 23:55:29804ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56805 NotificationService::current()->Notify(
806 NotificationType::PROFILE_DESTROYED,
807 Source<Profile>(this),
808 NotificationService::NoDetails());
809
[email protected]169627b2008-12-06 19:30:19810 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29811
812 StopCreateSessionServiceTimer();
813 // TemplateURLModel schedules a task on the WebDataService from its
814 // destructor. Delete it first to ensure the task gets scheduled before we
815 // shut down the database.
816 template_url_model_.reset();
817
818 // The download manager queries the history system and should be deleted
819 // before the history is shutdown so it can properly cancel all requests.
820 download_manager_ = NULL;
821
[email protected]4a190632009-05-09 01:07:42822 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15823 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42824
[email protected]44961292009-07-20 20:03:09825 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
826 // save any new thumbnails to disk and release its reference to the
827 // HistoryService.
828 if (thumbnail_store_.get())
829 thumbnail_store_->Shutdown();
830
[email protected]e7244d82008-10-29 18:13:26831 // Remove pref observers.
832 PrefService* prefs = GetPrefs();
833 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
834 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58835 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26836
[email protected]9c8dd902009-11-19 17:50:42837 // Delete the NTP resource cache so we can unregister pref observers.
838 ntp_resource_cache_.reset();
839
[email protected]48352c12009-08-15 01:19:11840 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34841
initial.commit09911bf2008-07-26 23:55:29842 // Both HistoryService and WebDataService maintain threads for background
843 // processing. Its possible each thread still has tasks on it that have
844 // increased the ref count of the service. In such a situation, when we
845 // decrement the refcount, it won't be 0, and the threads/databases aren't
846 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
847 // databases are properly closed.
848 if (web_data_service_.get())
849 web_data_service_->Shutdown();
850
851 if (history_service_.get())
852 history_service_->Cleanup();
853
[email protected]85c55dc2009-11-06 03:05:46854 if (spellcheck_host_.get())
855 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29856
[email protected]cfc06f122009-11-16 22:18:55857 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21858 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50859
[email protected]47accfd62009-05-14 18:46:21860 CleanupRequestContext(request_context_);
861 CleanupRequestContext(media_request_context_);
862 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17863
[email protected]d8e41ed2008-09-11 15:22:32864 // HistoryService may call into the BookmarkModel, as such we need to
865 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46866 // HistoryService will join with HistoryService's backend thread so that
867 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32868 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46869 history_service_ = NULL;
870 bookmark_bar_model_.reset();
871
[email protected]0189bc722009-08-28 21:56:48872 // FaviconService depends on HistoryServce so make sure we delete
873 // HistoryService first.
874 favicon_service_ = NULL;
875
[email protected]7120f132009-07-20 21:05:37876 extension_message_service_->ProfileDestroyed();
877
[email protected]6ef635e42009-07-26 06:16:12878 if (extensions_service_)
879 extensions_service_->ProfileDestroyed();
880
[email protected]66da08b2009-10-19 22:27:00881 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29882 MarkAsCleanShutdown();
883}
884
[email protected]4bf6afd2009-10-08 14:00:11885ProfileId ProfileImpl::GetRuntimeId() {
886 return reinterpret_cast<ProfileId>(this);
887}
888
[email protected]f7011fcb2009-01-28 21:54:32889FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29890 return path_;
891}
892
893bool ProfileImpl::IsOffTheRecord() {
894 return false;
895}
896
897Profile* ProfileImpl::GetOffTheRecordProfile() {
898 if (!off_the_record_profile_.get()) {
899 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
900 off_the_record_profile_.swap(p);
901 }
902 return off_the_record_profile_.get();
903}
904
[email protected]860f55492009-03-27 19:50:59905void ProfileImpl::DestroyOffTheRecordProfile() {
906 off_the_record_profile_.reset();
907}
908
initial.commit09911bf2008-07-26 23:55:29909Profile* ProfileImpl::GetOriginalProfile() {
910 return this;
911}
912
[email protected]2f351cb2009-11-09 23:43:34913webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
914 if (!db_tracker_)
915 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
916 return db_tracker_;
917}
918
initial.commit09911bf2008-07-26 23:55:29919VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44920 if (!visited_link_master_.get()) {
921 scoped_ptr<VisitedLinkMaster> visited_links(
922 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
923 if (!visited_links->Init())
924 return NULL;
925 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53926 }
[email protected]a6d0f182010-01-12 08:01:44927
928 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29929}
930
[email protected]6014d672008-12-05 00:38:25931ExtensionsService* ProfileImpl::GetExtensionsService() {
932 return extensions_service_.get();
933}
934
[email protected]0938d3c2009-01-09 20:37:35935UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35936 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25937}
938
[email protected]89ebc7e2009-08-24 22:11:07939ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
940 return extension_devtools_manager_.get();
941}
942
[email protected]481e1a42009-05-06 20:56:05943ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27944 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05945}
946
[email protected]7120f132009-07-20 21:05:37947ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
948 return extension_message_service_.get();
949}
950
[email protected]34cc84f2009-02-13 10:04:35951SSLHostState* ProfileImpl::GetSSLHostState() {
952 if (!ssl_host_state_.get())
953 ssl_host_state_.reset(new SSLHostState());
954
955 DCHECK(ssl_host_state_->CalledOnValidThread());
956 return ssl_host_state_.get();
957}
958
[email protected]326e6792009-12-11 21:04:42959net::TransportSecurityState*
960 ProfileImpl::GetTransportSecurityState() {
961 if (!transport_security_state_.get()) {
962 transport_security_state_ = new net::TransportSecurityState();
963 transport_security_persister_ =
964 new TransportSecurityPersister();
965 transport_security_persister_->Initialize(
966 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51967 }
[email protected]a9cea7542009-05-20 04:30:23968
[email protected]326e6792009-12-11 21:04:42969 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23970}
971
initial.commit09911bf2008-07-26 23:55:29972PrefService* ProfileImpl::GetPrefs() {
973 if (!prefs_.get()) {
[email protected]277404c22010-04-22 13:09:45974 prefs_.reset(new PrefService(new JsonPrefStore(GetPrefFilePath())));
initial.commit09911bf2008-07-26 23:55:29975
976 // The Profile class and ProfileManager class may read some prefs so
977 // register known prefs as soon as possible.
978 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51979 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29980
981 // The last session exited cleanly if there is no pref for
982 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
983 last_session_exited_cleanly_ =
984 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
985 // Mark the session as open.
986 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
987 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36988 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29989 }
990
991 return prefs_.get();
992}
993
[email protected]f7011fcb2009-01-28 21:54:32994FilePath ProfileImpl::GetPrefFilePath() {
995 FilePath pref_file_path = path_;
996 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29997 return pref_file_path;
998}
999
[email protected]be180c802009-10-23 06:33:311000URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:291001 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:321002 FilePath cookie_path = GetPath();
1003 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:131004 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311005 int max_size;
1006 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:421007
[email protected]405a64b2009-09-16 21:03:441008 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311009 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
1010 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:291011
[email protected]6ab9b202008-12-23 22:34:501012 // The first request context is always a normal (non-OTR) request context.
1013 // Even when Chromium is started in OTR mode, a normal profile is always
1014 // created first.
1015 if (!default_request_context_) {
1016 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:311017 // TODO(eroman): this isn't terribly useful anymore now that the
1018 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:501019 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561020 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:501021 NotificationService::AllSources(), NotificationService::NoDetails());
1022 }
initial.commit09911bf2008-07-26 23:55:291023 }
1024
1025 return request_context_;
1026}
1027
[email protected]be180c802009-10-23 06:33:311028URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:181029 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:131030 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311031 int max_size;
1032 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:141033
[email protected]405a64b2009-09-16 21:03:441034 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311035 media_request_context_ =
1036 ChromeURLRequestContextGetter::CreateOriginalForMedia(
1037 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:181038 }
1039
1040 return media_request_context_;
1041}
1042
[email protected]0189bc722009-08-28 21:56:481043FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
1044 if (!favicon_service_created_) {
1045 favicon_service_created_ = true;
1046 scoped_refptr<FaviconService> service(new FaviconService(this));
1047 favicon_service_.swap(service);
1048 }
1049 return favicon_service_.get();
1050}
1051
[email protected]be180c802009-10-23 06:33:311052URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:211053 if (!extensions_request_context_) {
1054 FilePath cookie_path = GetPath();
1055 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1056
1057 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:311058 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
1059 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:211060 }
1061
1062 return extensions_request_context_;
1063}
1064
[email protected]57a777f72010-03-31 01:09:421065void ProfileImpl::RegisterExtensionWithRequestContexts(
1066 Extension* extension) {
1067 // Notify the default, extension and media contexts on the IO thread.
1068 PostExtensionLoadedToContextGetter(
1069 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1070 extension);
1071 PostExtensionLoadedToContextGetter(
1072 static_cast<ChromeURLRequestContextGetter*>(
1073 GetRequestContextForExtensions()),
1074 extension);
1075 PostExtensionLoadedToContextGetter(
1076 static_cast<ChromeURLRequestContextGetter*>(
1077 GetRequestContextForMedia()),
1078 extension);
1079}
1080
1081void ProfileImpl::UnregisterExtensionWithRequestContexts(
1082 Extension* extension) {
1083 // Notify the default, extension and media contexts on the IO thread.
1084 PostExtensionUnloadedToContextGetter(
1085 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1086 extension);
1087 PostExtensionUnloadedToContextGetter(
1088 static_cast<ChromeURLRequestContextGetter*>(
1089 GetRequestContextForExtensions()),
1090 extension);
1091 PostExtensionUnloadedToContextGetter(
1092 static_cast<ChromeURLRequestContextGetter*>(
1093 GetRequestContextForMedia()),
1094 extension);
1095}
1096
[email protected]db36938c2009-08-19 21:48:421097net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1098 return ssl_config_service_manager_->Get();
1099}
1100
[email protected]e284e6d82010-01-29 19:49:451101HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
1102 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:391103 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:451104 return host_content_settings_map_.get();
1105}
1106
[email protected]40bd6582009-12-04 23:49:511107HostZoomMap* ProfileImpl::GetHostZoomMap() {
1108 if (!host_zoom_map_)
1109 host_zoom_map_ = new HostZoomMap(this);
1110 return host_zoom_map_.get();
1111}
1112
[email protected]aee541e2010-03-19 01:52:451113GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
1114 if (!geolocation_content_settings_map_.get())
1115 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
1116 return geolocation_content_settings_map_.get();
1117}
1118
[email protected]8c6335d32010-01-20 09:21:501119Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271120 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141121 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271122 return NULL;
[email protected]c37f8b42010-01-23 16:22:141123 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541124 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501125 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231126}
1127
[email protected]6c32ce72010-03-08 05:18:061128UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1129 if (!user_style_sheet_watcher_.get()) {
1130 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1131 user_style_sheet_watcher_->Init();
1132 }
1133 return user_style_sheet_watcher_.get();
1134}
1135
[email protected]e5d2f7132010-04-09 18:13:531136FindBarState* ProfileImpl::GetFindBarState() {
1137 if (!find_bar_state_.get()) {
1138 find_bar_state_.reset(new FindBarState());
1139 }
1140 return find_bar_state_.get();
1141}
1142
initial.commit09911bf2008-07-26 23:55:291143HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1144 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461145 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291146 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321147 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291148 return NULL;
1149 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291150
1151 // Send out the notification that the history service was created.
1152 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561153 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291154 Details<HistoryService>(history_service_.get()));
1155 }
1156 return history_service_.get();
1157}
1158
[email protected]0850fa62009-10-08 22:34:291159HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1160 return history_service_.get();
1161}
1162
initial.commit09911bf2008-07-26 23:55:291163TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1164 if (!template_url_model_.get())
1165 template_url_model_.reset(new TemplateURLModel(this));
1166 return template_url_model_.get();
1167}
1168
1169TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1170 if (!template_url_fetcher_.get())
1171 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1172 return template_url_fetcher_.get();
1173}
1174
[email protected]69c579e2010-04-23 20:01:001175AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
1176 if (!autocomplete_classifier_.get())
1177 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
1178 return autocomplete_classifier_.get();
[email protected]90085af02009-10-29 17:53:211179}
1180
initial.commit09911bf2008-07-26 23:55:291181WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1182 if (!created_web_data_service_)
1183 CreateWebDataService();
1184 return web_data_service_.get();
1185}
1186
[email protected]9cddbe372009-10-23 21:23:531187WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1188 return web_data_service_.get();
1189}
1190
initial.commit09911bf2008-07-26 23:55:291191void ProfileImpl::CreateWebDataService() {
1192 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1193 created_web_data_service_ = true;
1194 scoped_refptr<WebDataService> wds(new WebDataService());
1195 if (!wds->Init(GetPath()))
1196 return;
1197 web_data_service_.swap(wds);
1198}
1199
[email protected]e69d33952009-06-03 22:00:411200PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1201 if (!created_password_store_)
1202 CreatePasswordStore();
1203 return password_store_.get();
1204}
1205
1206void ProfileImpl::CreatePasswordStore() {
1207 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1208 created_password_store_ = true;
1209 scoped_refptr<PasswordStore> ps;
[email protected]e0411ae52009-06-30 23:59:171210 FilePath login_db_file_path = GetPath();
1211 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
[email protected]ec44cd52010-04-05 22:30:471212 LoginDatabase* login_db = new LoginDatabase();
[email protected]e0411ae52009-06-30 23:59:171213 if (!login_db->Init(login_db_file_path)) {
1214 LOG(ERROR) << "Could not initialize login database.";
1215 delete login_db;
1216 return;
1217 }
[email protected]e8380f52010-04-30 16:39:421218#if defined(OS_WIN)
1219 ps = new PasswordStoreWin(login_db, this,
1220 GetWebDataService(Profile::IMPLICIT_ACCESS));
1221#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171222 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161223#elif defined(OS_POSIX)
1224 // TODO(evanm): implement "native" password management.
1225 // This bug describes the issues.
1226 // http://code.google.com/p/chromium/issues/detail?id=12351
[email protected]e8380f52010-04-30 16:39:421227 ps = new PasswordStoreDefault(login_db, this,
1228 GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]e69d33952009-06-03 22:00:411229#else
1230 NOTIMPLEMENTED();
1231#endif
[email protected]e8380f52010-04-30 16:39:421232 if (!ps)
1233 delete login_db;
1234
[email protected]e69d33952009-06-03 22:00:411235 if (!ps || !ps->Init()) {
[email protected]e8380f52010-04-30 16:39:421236 NOTREACHED() << "Could not initialise password manager";
1237 return;
[email protected]e69d33952009-06-03 22:00:411238 }
1239 password_store_.swap(ps);
1240}
1241
initial.commit09911bf2008-07-26 23:55:291242DownloadManager* ProfileImpl::GetDownloadManager() {
1243 if (!created_download_manager_) {
1244 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1245 dlm->Init(this);
1246 created_download_manager_ = true;
1247 download_manager_.swap(dlm);
1248 }
1249 return download_manager_.get();
1250}
1251
1252bool ProfileImpl::HasCreatedDownloadManager() const {
1253 return created_download_manager_;
1254}
1255
[email protected]def11712009-11-06 00:42:151256PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1257 if (!personal_data_manager_.get()) {
[email protected]e0976a72010-04-02 01:25:241258 personal_data_manager_.reset(new PersonalDataManager());
1259 personal_data_manager_->Init(this);
[email protected]def11712009-11-06 00:42:151260 }
1261 return personal_data_manager_.get();
1262}
1263
[email protected]4a190632009-05-09 01:07:421264void ProfileImpl::InitThemes() {
1265 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161266#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151267 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291268#else
[email protected]761962c2009-09-25 00:18:151269 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291270#endif
[email protected]761962c2009-09-25 00:18:151271 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421272 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421273 }
1274}
1275
1276void ProfileImpl::SetTheme(Extension* extension) {
1277 InitThemes();
1278 theme_provider_.get()->SetTheme(extension);
1279}
1280
[email protected]a5166af62009-07-03 00:42:291281void ProfileImpl::SetNativeTheme() {
1282 InitThemes();
1283 theme_provider_.get()->SetNativeTheme();
1284}
1285
[email protected]4a190632009-05-09 01:07:421286void ProfileImpl::ClearTheme() {
1287 InitThemes();
1288 theme_provider_.get()->UseDefaultTheme();
1289}
1290
[email protected]51c490b2009-08-03 16:34:341291Extension* ProfileImpl::GetTheme() {
1292 InitThemes();
1293
1294 std::string id = theme_provider_.get()->GetThemeID();
1295 if (id == BrowserThemeProvider::kDefaultThemeID)
1296 return NULL;
1297
[email protected]61b411612009-11-10 23:17:411298 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341299}
1300
[email protected]5786d3d2009-12-18 00:18:441301BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421302 InitThemes();
1303 return theme_provider_.get();
1304}
1305
initial.commit09911bf2008-07-26 23:55:291306SessionService* ProfileImpl::GetSessionService() {
1307 if (!session_service_.get() && !shutdown_session_service_) {
1308 session_service_ = new SessionService(this);
1309 session_service_->ResetFromCurrentBrowsers();
1310 }
1311 return session_service_.get();
1312}
1313
1314void ProfileImpl::ShutdownSessionService() {
1315 if (shutdown_session_service_)
1316 return;
1317
1318 // We're about to exit, force creation of the session service if it hasn't
1319 // been created yet. We do this to ensure session state matches the point in
1320 // time the user exited.
1321 GetSessionService();
1322 shutdown_session_service_ = true;
1323 session_service_ = NULL;
1324}
1325
1326bool ProfileImpl::HasSessionService() const {
1327 return (session_service_.get() != NULL);
1328}
1329
initial.commit09911bf2008-07-26 23:55:291330bool ProfileImpl::DidLastSessionExitCleanly() {
1331 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1332 // it to be set by asking for the prefs.
1333 GetPrefs();
1334 return last_session_exited_cleanly_;
1335}
1336
[email protected]d8e41ed2008-09-11 15:22:321337BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461338 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321339 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461340 bookmark_bar_model_->Load();
1341 }
initial.commit09911bf2008-07-26 23:55:291342 return bookmark_bar_model_.get();
1343}
1344
1345bool ProfileImpl::IsSameProfile(Profile* profile) {
1346 if (profile == static_cast<Profile*>(this))
1347 return true;
1348 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1349 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1350}
1351
1352Time ProfileImpl::GetStartTime() const {
1353 return start_time_;
1354}
1355
1356TabRestoreService* ProfileImpl::GetTabRestoreService() {
1357 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191358 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291359 return tab_restore_service_.get();
1360}
1361
[email protected]449478302009-06-09 20:04:281362ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1363 if (!thumbnail_store_.get()) {
1364 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251365 thumbnail_store_->Init(
1366 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281367 }
1368 return thumbnail_store_.get();
1369}
1370
initial.commit09911bf2008-07-26 23:55:291371void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191372 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291373}
1374
[email protected]85c55dc2009-11-06 03:05:461375SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1376 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1377}
1378
1379void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1380 // If we are already loading the spellchecker, and this is just a hint to
1381 // load the spellchecker, do nothing.
1382 if (!force && spellcheck_host_.get())
1383 return;
1384
[email protected]f41301e2009-11-16 21:30:071385 spellcheck_host_ready_ = false;
1386
[email protected]85c55dc2009-11-06 03:05:461387 bool notify = false;
1388 if (spellcheck_host_.get()) {
1389 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051390 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461391 notify = true;
1392 }
1393
1394 PrefService* prefs = GetPrefs();
1395 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1396 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1397 spellcheck_host_ = new SpellCheckHost(this,
1398 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1399 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071400 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461401 } else if (notify) {
1402 // The spellchecker has been disabled.
1403 SpellCheckHostInitialized();
1404 }
1405}
1406
1407void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171408 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291409 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1410 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461411 NotificationService::current()->Notify(
1412 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1413 Source<Profile>(this), NotificationService::NoDetails());
1414}
initial.commit09911bf2008-07-26 23:55:291415
[email protected]3bf335a2009-06-26 20:46:061416WebKitContext* ProfileImpl::GetWebKitContext() {
1417 if (!webkit_context_.get())
1418 webkit_context_ = new WebKitContext(path_, false);
1419 DCHECK(webkit_context_.get());
1420 return webkit_context_.get();
1421}
1422
[email protected]4bb336302009-10-12 05:44:261423DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1424 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1425 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261426 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031427 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261428 }
[email protected]4bb336302009-10-12 05:44:261429 return desktop_notification_service_.get();
1430}
1431
initial.commit09911bf2008-07-26 23:55:291432void ProfileImpl::MarkAsCleanShutdown() {
1433 if (prefs_.get()) {
1434 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1435 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1436
1437 // NOTE: If you change what thread this writes on, be sure and update
1438 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361439 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291440 }
1441}
1442
[email protected]e7244d82008-10-29 18:13:261443void ProfileImpl::Observe(NotificationType type,
1444 const NotificationSource& source,
1445 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561446 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261447 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1448 PrefService* prefs = Source<PrefService>(source).ptr();
1449 DCHECK(pref_name_in && prefs);
1450 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461451 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461452 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291453 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1454 NotificationService::current()->Notify(
1455 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1456 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261457 }
[email protected]4a190632009-05-09 01:07:421458 } else if (NotificationType::THEME_INSTALLED == type) {
1459 Extension* extension = Details<Extension>(details).ptr();
1460 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111461 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1462 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1463 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1464 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261465 }
1466}
1467
initial.commit09911bf2008-07-26 23:55:291468void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141469 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291470}
[email protected]3a453fa2008-08-15 18:46:341471
[email protected]48352c12009-08-15 01:19:111472ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431473 if (!ProfileSyncService::IsSyncEnabled()) {
1474 return NULL;
[email protected]7367f1a2009-10-10 01:09:441475 }
[email protected]eec3bcfa2009-11-12 17:23:431476 if (!sync_service_.get())
1477 InitSyncService();
1478 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111479}
1480
[email protected]1bd056e2010-04-20 02:03:481481CloudPrintProxyService* ProfileImpl::GetCloudPrintProxyService() {
1482 if (!cloud_print_proxy_service_.get())
1483 InitCloudPrintProxyService();
1484 return cloud_print_proxy_service_.get();
1485}
1486
[email protected]48352c12009-08-15 01:19:111487void ProfileImpl::InitSyncService() {
[email protected]4aea04a2010-02-10 20:13:431488 profile_sync_factory_.reset(
1489 new ProfileSyncFactoryImpl(this,
1490 CommandLine::ForCurrentProcess()));
1491 sync_service_.reset(
1492 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111493 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111494}
[email protected]1bd056e2010-04-20 02:03:481495
1496void ProfileImpl::InitCloudPrintProxyService() {
1497 cloud_print_proxy_service_.reset(new CloudPrintProxyService(this));
1498 cloud_print_proxy_service_->Initialize();
1499}