blob: b6a8716de8823ac3330c26b50dd56e9c51b45348 [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]04fba9a92008-10-28 17:25:2510#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4411#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/path_service.h"
13#include "base/scoped_ptr.h"
14#include "base/string_util.h"
[email protected]0082d7e0d2010-02-27 14:34:1215#include "chrome/browser/appcache/chrome_appcache_service.h"
[email protected]def11712009-11-06 00:42:1516#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4217#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2918#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5119#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5720#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0221#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3722#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4223#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5624#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0725#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3726#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0527#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2528#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3529#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4830#include "chrome/browser/favicon_service.h"
[email protected]aee541e2010-03-19 01:52:4531#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]9c92d192009-12-02 08:03:1632#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4233#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4234#include "chrome/browser/history/history.h"
[email protected]e284e6d82010-01-29 19:49:4535#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5136#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0637#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5038#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4239#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2640#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4141#include "chrome/browser/password_manager/password_store_default.h"
[email protected]8c6335d32010-01-20 09:21:5042#include "chrome/browser/privacy_blacklist/blacklist.h"
initial.commit09911bf2008-07-26 23:55:2943#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2644#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]90085af02009-10-29 17:53:2145#include "chrome/browser/search_versus_navigate_classifier.h"
[email protected]1132436e2009-04-08 20:06:3346#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4647#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4448#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3049#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3350#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1151#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4352#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4053#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2854#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0655#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2956#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3957#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5659#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2960#include "chrome/common/chrome_constants.h"
61#include "chrome/common/chrome_paths.h"
62#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5863#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2964#include "chrome/common/notification_service.h"
65#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3266#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3467#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5868#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4269#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3470#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2971
[email protected]753efc42010-03-09 19:52:1672#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2973#include "chrome/browser/gtk/gtk_theme_provider.h"
74#endif
75
[email protected]e1acf6f2008-10-27 20:43:3376using base::Time;
77using base::TimeDelta;
78
[email protected]e5642992009-06-26 23:06:3179namespace {
80
initial.commit09911bf2008-07-26 23:55:2981// Delay, in milliseconds, before we explicitly create the SessionService.
82static const int kCreateSessionServiceDelayMS = 500;
83
[email protected]e5642992009-06-26 23:06:3184enum ContextType {
85 kNormalContext,
86 kMediaContext
87};
88
89// Gets the cache parameters from the command line. |type| is the type of
90// request context that we need, |cache_path| will be set to the user provided
91// path, or will not be touched if there is not an argument. |max_size| will
92// be the user provided value or zero by default.
93void GetCacheParameters(ContextType type, FilePath* cache_path,
94 int* max_size) {
95 DCHECK(cache_path);
96 DCHECK(max_size);
97
98 // Override the cache location if specified by the user.
99 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
100 switches::kDiskCacheDir));
101
102 if (!user_path.empty()) {
103 *cache_path = FilePath::FromWStringHack(user_path);
104 }
105
[email protected]b7e0a2a2009-10-13 02:07:25106 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
107 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31108 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25109 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31110
111 // By default we let the cache determine the right size.
112 *max_size = 0;
113 if (!StringToInt(value, max_size)) {
114 *max_size = 0;
115 } else if (max_size < 0) {
116 *max_size = 0;
117 }
118}
119
[email protected]405a64b2009-09-16 21:03:44120FilePath GetCachePath(const FilePath& base) {
121 return base.Append(chrome::kCacheDirname);
122}
123
124FilePath GetMediaCachePath(const FilePath& base) {
125 return base.Append(chrome::kMediaCacheDirname);
126}
127
128bool HasACacheSubdir(const FilePath &dir) {
129 return file_util::PathExists(GetCachePath(dir)) ||
130 file_util::PathExists(GetMediaCachePath(dir));
131}
132
[email protected]e5642992009-06-26 23:06:31133} // namespace
134
initial.commit09911bf2008-07-26 23:55:29135// A pointer to the request context for the default profile. See comments on
136// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31137URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29138
[email protected]be180c802009-10-23 06:33:31139static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19140 if (context)
[email protected]47accfd62009-05-14 18:46:21141 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21142}
143
[email protected]34cc84f2009-02-13 10:04:35144// static
[email protected]4bf6afd2009-10-08 14:00:11145const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
146
147// static
initial.commit09911bf2008-07-26 23:55:29148void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55149 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29150 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
151 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12152 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26153 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
154 IDS_SPELLCHECK_DICTIONARY);
155 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58156 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16157#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06158 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
159 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29160#endif
[email protected]f017cc92009-12-14 20:48:07161 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34162 prefs->RegisterStringPref(prefs::kCurrentThemeID,
163 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42164 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
165 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
166 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50167 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23168 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29169}
170
[email protected]34cc84f2009-02-13 10:04:35171// static
[email protected]f7011fcb2009-01-28 21:54:32172Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29173 return new ProfileImpl(path);
174}
175
[email protected]34cc84f2009-02-13 10:04:35176// static
[email protected]be180c802009-10-23 06:33:31177URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29178 return default_request_context_;
179}
180
[email protected]753efc42010-03-09 19:52:16181#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41182#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56183#elif defined(OS_MACOSX)
184#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17185#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56186#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16187#elif defined(OS_POSIX)
188// Temporarily disabled while we figure some stuff out.
189// http://code.google.com/p/chromium/issues/detail?id=12351
190// #include "chrome/browser/password_manager/password_store_gnome.h"
191// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41192#endif
initial.commit09911bf2008-07-26 23:55:29193
initial.commit09911bf2008-07-26 23:55:29194////////////////////////////////////////////////////////////////////////////////
195//
196// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42197// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29198//
199////////////////////////////////////////////////////////////////////////////////
200class OffTheRecordProfileImpl : public Profile,
201 public NotificationObserver {
202 public:
203 explicit OffTheRecordProfileImpl(Profile* real_profile)
204 : profile_(real_profile),
205 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31206 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05207
initial.commit09911bf2008-07-26 23:55:29208 // Register for browser close notifications so we can detect when the last
209 // off-the-record window is closed, in which case we can clean our states
210 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43211 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
212 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29213 }
214
215 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21216 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29217 }
218
[email protected]4bf6afd2009-10-08 14:00:11219 virtual ProfileId GetRuntimeId() {
220 return reinterpret_cast<ProfileId>(this);
221 }
222
[email protected]a6d0f182010-01-12 08:01:44223 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29224
225 virtual bool IsOffTheRecord() {
226 return true;
227 }
228
229 virtual Profile* GetOffTheRecordProfile() {
230 return this;
231 }
232
[email protected]860f55492009-03-27 19:50:59233 virtual void DestroyOffTheRecordProfile() {
234 // Suicide is bad!
235 NOTREACHED();
236 }
237
initial.commit09911bf2008-07-26 23:55:29238 virtual Profile* GetOriginalProfile() {
239 return profile_;
240 }
241
[email protected]2f351cb2009-11-09 23:43:34242 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
243 if (!db_tracker_)
244 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
245 return db_tracker_;
246 }
247
initial.commit09911bf2008-07-26 23:55:29248 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49249 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
250 // because we don't want to leak the sites that the user has visited before.
251 return NULL;
initial.commit09911bf2008-07-26 23:55:29252 }
253
[email protected]6014d672008-12-05 00:38:25254 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21255 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25256 }
257
[email protected]0938d3c2009-01-09 20:37:35258 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21259 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25260 }
261
[email protected]89ebc7e2009-08-24 22:11:07262 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21263 // TODO(mpcomplete): figure out whether we should return the original
264 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07265 return NULL;
266 }
267
[email protected]481e1a42009-05-06 20:56:05268 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21269 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05270 }
271
[email protected]7120f132009-07-20 21:05:37272 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21273 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37274 }
275
[email protected]34cc84f2009-02-13 10:04:35276 virtual SSLHostState* GetSSLHostState() {
277 if (!ssl_host_state_.get())
278 ssl_host_state_.reset(new SSLHostState());
279
280 DCHECK(ssl_host_state_->CalledOnValidThread());
281 return ssl_host_state_.get();
282 }
283
[email protected]326e6792009-12-11 21:04:42284 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54285 if (!transport_security_state_.get())
286 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23287
[email protected]326e6792009-12-11 21:04:42288 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23289 }
290
initial.commit09911bf2008-07-26 23:55:29291 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54292 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29293 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54294
295 NOTREACHED() << "This profile is OffTheRecord";
296 return NULL;
initial.commit09911bf2008-07-26 23:55:29297 }
298
[email protected]0850fa62009-10-08 22:34:29299 virtual HistoryService* GetHistoryServiceWithoutCreating() {
300 return profile_->GetHistoryServiceWithoutCreating();
301 }
302
[email protected]0189bc722009-08-28 21:56:48303 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54304 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48305 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54306
307 NOTREACHED() << "This profile is OffTheRecord";
308 return NULL;
[email protected]0189bc722009-08-28 21:56:48309 }
310
[email protected]90085af02009-10-29 17:53:21311 virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
312 return profile_->GetSearchVersusNavigateClassifier();
313 }
314
initial.commit09911bf2008-07-26 23:55:29315 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54316 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29317 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54318
319 NOTREACHED() << "This profile is OffTheRecord";
320 return NULL;
initial.commit09911bf2008-07-26 23:55:29321 }
322
[email protected]9cddbe372009-10-23 21:23:53323 virtual WebDataService* GetWebDataServiceWithoutCreating() {
324 return profile_->GetWebDataServiceWithoutCreating();
325 }
326
[email protected]e69d33952009-06-03 22:00:41327 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54328 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41329 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54330
331 NOTREACHED() << "This profile is OffTheRecord";
332 return NULL;
[email protected]e69d33952009-06-03 22:00:41333 }
334
initial.commit09911bf2008-07-26 23:55:29335 virtual PrefService* GetPrefs() {
336 return profile_->GetPrefs();
337 }
338
339 virtual TemplateURLModel* GetTemplateURLModel() {
340 return profile_->GetTemplateURLModel();
341 }
342
343 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
344 return profile_->GetTemplateURLFetcher();
345 }
346
347 virtual DownloadManager* GetDownloadManager() {
348 if (!download_manager_.get()) {
349 scoped_refptr<DownloadManager> dlm(new DownloadManager);
350 dlm->Init(this);
351 download_manager_.swap(dlm);
352 }
353 return download_manager_.get();
354 }
355
356 virtual bool HasCreatedDownloadManager() const {
357 return (download_manager_.get() != NULL);
358 }
359
[email protected]def11712009-11-06 00:42:15360 virtual PersonalDataManager* GetPersonalDataManager() {
361 return NULL;
362 }
363
[email protected]4a190632009-05-09 01:07:42364 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54365 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42366 }
367
368 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54369 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42370 }
371
[email protected]a5166af62009-07-03 00:42:29372 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54373 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29374 }
375
[email protected]4a190632009-05-09 01:07:42376 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54377 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42378 }
379
[email protected]51c490b2009-08-03 16:34:34380 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54381 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34382 }
383
[email protected]5786d3d2009-12-18 00:18:44384 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54385 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42386 }
387
[email protected]be180c802009-10-23 06:33:31388 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29389 return request_context_;
390 }
391
[email protected]be180c802009-10-23 06:33:31392 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11393 // In OTR mode, media request context is the same as the original one.
394 return request_context_;
[email protected]e7f29642009-03-02 22:53:18395 }
396
[email protected]be180c802009-10-23 06:33:31397 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21398 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21399 }
400
[email protected]db36938c2009-08-19 21:48:42401 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54402 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42403 }
404
[email protected]e284e6d82010-01-29 19:49:45405 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]08bc6302010-01-30 02:53:39406 return profile_->GetHostContentSettingsMap();
[email protected]e284e6d82010-01-29 19:49:45407 }
408
[email protected]40bd6582009-12-04 23:49:51409 virtual HostZoomMap* GetHostZoomMap() {
[email protected]779c3362010-01-30 01:09:33410 return profile_->GetHostZoomMap();
[email protected]40bd6582009-12-04 23:49:51411 }
412
[email protected]aee541e2010-03-19 01:52:45413 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
414 return profile_->GetGeolocationContentSettingsMap();
415 }
416
[email protected]8c6335d32010-01-20 09:21:50417 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54418 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23419 }
420
[email protected]6c32ce72010-03-08 05:18:06421 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
422 return profile_->GetUserStyleSheetWatcher();
423 }
424
initial.commit09911bf2008-07-26 23:55:29425 virtual SessionService* GetSessionService() {
426 // Don't save any sessions when off the record.
427 return NULL;
428 }
429
430 virtual void ShutdownSessionService() {
431 // We don't allow a session service, nothing to do.
432 }
433
434 virtual bool HasSessionService() const {
435 // We never have a session service.
436 return false;
437 }
438
initial.commit09911bf2008-07-26 23:55:29439 virtual bool DidLastSessionExitCleanly() {
440 return profile_->DidLastSessionExitCleanly();
441 }
442
[email protected]d8e41ed2008-09-11 15:22:32443 virtual BookmarkModel* GetBookmarkModel() {
444 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29445 }
446
[email protected]4bb336302009-10-12 05:44:26447 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58448 if (!desktop_notification_service_.get()) {
449 desktop_notification_service_.reset(new DesktopNotificationService(
450 this, g_browser_process->notification_ui_manager()));
451 }
452 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26453 }
454
[email protected]48352c12009-08-15 01:19:11455 virtual ProfileSyncService* GetProfileSyncService() {
456 return NULL;
[email protected]3a453fa2008-08-15 18:46:34457 }
[email protected]3a453fa2008-08-15 18:46:34458
initial.commit09911bf2008-07-26 23:55:29459 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54460 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29461 }
462
463 virtual Time GetStartTime() const {
464 return start_time_;
465 }
466
467 virtual TabRestoreService* GetTabRestoreService() {
468 return NULL;
469 }
470
[email protected]e7244d82008-10-29 18:13:26471 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41472 }
473
[email protected]85c55dc2009-11-06 03:05:46474 virtual SpellCheckHost* GetSpellCheckHost() {
475 return profile_->GetSpellCheckHost();
476 }
477
478 virtual void ReinitializeSpellCheckHost(bool force) {
479 profile_->ReinitializeSpellCheckHost(force);
480 }
[email protected]85c55dc2009-11-06 03:05:46481
[email protected]3bf335a2009-06-26 20:46:06482 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29483 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21484 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29485 DCHECK(webkit_context_.get());
486 return webkit_context_.get();
487 }
[email protected]3bf335a2009-06-26 20:46:06488
[email protected]449478302009-06-09 20:04:28489 virtual ThumbnailStore* GetThumbnailStore() {
490 return NULL;
491 }
492
initial.commit09911bf2008-07-26 23:55:29493 virtual void MarkAsCleanShutdown() {
494 }
495
[email protected]bdbc87c2009-01-25 05:08:54496 virtual void InitExtensions() {
497 NOTREACHED();
498 }
499
[email protected]ea0c98cf2009-06-18 23:02:54500 virtual void InitWebResources() {
501 NOTREACHED();
502 }
503
[email protected]9c8dd902009-11-19 17:50:42504 virtual NTPResourceCache* GetNTPResourceCache() {
505 // Just return the real profile resource cache.
506 return profile_->GetNTPResourceCache();
507 }
508
initial.commit09911bf2008-07-26 23:55:29509 virtual void ExitedOffTheRecordMode() {
510 // Drop our download manager so we forget about all the downloads made
511 // in off-the-record mode.
512 download_manager_ = NULL;
513 }
514
515 virtual void Observe(NotificationType type,
516 const NotificationSource& source,
517 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56518 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29519 // We are only interested in OTR browser closing.
520 if (Source<Browser>(source)->profile() != this)
521 return;
522
523 // Let's check if we still have an Off The Record window opened.
524 // Note that we check against 1 as this notification is sent before the
525 // browser window is actually removed from the list.
526 if (BrowserList::GetBrowserCount(this) <= 1)
527 ExitedOffTheRecordMode();
528 }
529
530 private:
[email protected]88cf3292009-05-22 01:48:43531 NotificationRegistrar registrar_;
532
initial.commit09911bf2008-07-26 23:55:29533 // The real underlying profile.
534 Profile* profile_;
535
[email protected]6ab9b202008-12-23 22:34:50536 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19537 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29538
539 // The download manager that only stores downloaded items in memory.
540 scoped_refptr<DownloadManager> download_manager_;
541
[email protected]7d7696c52009-12-01 20:54:58542 // Use a separate desktop notification service for OTR.
543 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
544
[email protected]3bf335a2009-06-26 20:46:06545 // Use a special WebKit context for OTR browsing.
546 scoped_refptr<WebKitContext> webkit_context_;
547
[email protected]34cc84f2009-02-13 10:04:35548 // We don't want SSLHostState from the OTR profile to leak back to the main
549 // profile because then the main profile would learn some of the host names
550 // the user visited while OTR.
551 scoped_ptr<SSLHostState> ssl_host_state_;
552
[email protected]326e6792009-12-11 21:04:42553 // The TransportSecurityState that only stores enabled sites in memory.
554 scoped_refptr<net::TransportSecurityState>
555 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23556
initial.commit09911bf2008-07-26 23:55:29557 // Time we were started.
558 Time start_time_;
559
[email protected]2f351cb2009-11-09 23:43:34560 // The main database tracker for this profile.
561 // Should be used only on the file thread.
562 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
563
[email protected]90085af02009-10-29 17:53:21564 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29565};
566
[email protected]f7011fcb2009-01-28 21:54:32567ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29568 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44569 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07570 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32571 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57572 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21573 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45574 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51575 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32576 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48577 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32578 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41579 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32580 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42581 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32582 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46583 spellcheck_host_(NULL),
584 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29585 shutdown_session_service_(false) {
586 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
587 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14588 create_session_service_timer_.Start(
589 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
590 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54591
[email protected]89ebc7e2009-08-24 22:11:07592 if (CommandLine::ForCurrentProcess()->HasSwitch(
593 switches::kEnableExtensionTimelineApi)) {
594 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
595 }
596
[email protected]382a0702009-06-26 17:12:27597 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37598 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27599
[email protected]e7244d82008-10-29 18:13:26600 PrefService* prefs = GetPrefs();
601 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
602 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58603 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58604
[email protected]405a64b2009-09-16 21:03:44605#if defined(OS_MACOSX)
606 // If the profile directory doesn't already have a cache directory and it
607 // is under ~/Library/Application Support, use a suitable cache directory
608 // under ~/Library/Caches. For example, a profile directory of
609 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
610 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
611 // ~/Library/Caches/Google/Chrome/MyProfileName.
612 //
613 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44614 if (!HasACacheSubdir(path_)) {
615 FilePath app_data_path, user_cache_path;
616 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12617 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44618 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
619 base_cache_path_ = user_cache_path;
620 }
621 }
[email protected]9e9b6e8e2009-12-02 08:45:01622#elif defined(OS_POSIX) // Posix minus Mac.
623 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
624 // for a spec on where cache files go. The net effect for most systems is we
625 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
626 // official builds.
627 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
628#if defined(GOOGLE_CHROME_BUILD)
629 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44630#else
[email protected]9e9b6e8e2009-12-02 08:45:01631 const char kCacheDir[] = "chromium";
632#endif
633 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
634 base_cache_path_ = base_cache_path_.Append(kCacheDir);
635 if (!file_util::PathExists(base_cache_path_))
636 file_util::CreateDirectory(base_cache_path_);
637 }
[email protected]405a64b2009-09-16 21:03:44638#endif
[email protected]bc96d562009-08-11 18:45:13639 if (base_cache_path_.empty())
640 base_cache_path_ = path_;
641
[email protected]4a190632009-05-09 01:07:42642 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43643 registrar_.Add(this, NotificationType::THEME_INSTALLED,
644 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11645
646 // Listen for bookmark model load, to bootstrap the sync service.
647 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
648 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42649
650 ssl_config_service_manager_.reset(
651 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53652
653#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29654 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53655#endif
[email protected]911f8152010-03-18 16:46:40656
657 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29658}
659
[email protected]bdbc87c2009-01-25 05:08:54660void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41661 if (user_script_master_ || extensions_service_)
662 return; // Already initialized.
663
[email protected]bdbc87c2009-01-25 05:08:54664 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18665 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36666
667 FilePath script_dir; // Don't look for user scripts in any directory.
668 // TODO(aa): We should just remove this functionality,
669 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51670 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36671
[email protected]894bb502009-05-21 22:39:57672 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23673 this,
674 CommandLine::ForCurrentProcess(),
675 GetPrefs(),
676 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36677 true);
[email protected]bdbc87c2009-01-25 05:08:54678
[email protected]1952c7d2010-03-04 23:48:34679 // Register the bookmark manager extension.
[email protected]4b776892010-03-19 22:57:33680 if (!CommandLine::ForCurrentProcess()->HasSwitch(
681 switches::kDisableTabbedBookmarkManager)) {
[email protected]1952c7d2010-03-04 23:48:34682 FilePath bookmark_manager_path;
683 if (PathService::Get(chrome::DIR_BOOKMARK_MANAGER,
684 &bookmark_manager_path)) {
685 std::string manifest =
686 ResourceBundle::GetSharedInstance().GetRawDataResource(
687 IDR_BOOKMARKS_MANIFEST).as_string();
688 extensions_service_->register_component_extension(
689 ExtensionsService::ComponentExtensionInfo(manifest,
690 bookmark_manager_path));
691 } else {
692 NOTREACHED();
693 }
694 }
695
[email protected]9197f3b2009-06-02 00:49:27696 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12697
698 // Load any extensions specified with --load-extension.
699 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10700 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12701 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12702 }
[email protected]bdbc87c2009-01-25 05:08:54703}
704
[email protected]ea0c98cf2009-06-18 23:02:54705void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07706 if (web_resource_service_)
707 return; // Already initialized.
708
[email protected]6fad2632009-11-02 05:59:37709 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54710 web_resource_service_->StartAfterDelay();
711}
712
[email protected]9c8dd902009-11-19 17:50:42713NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
714 if (!ntp_resource_cache_.get())
715 ntp_resource_cache_.reset(new NTPResourceCache(this));
716 return ntp_resource_cache_.get();
717}
718
initial.commit09911bf2008-07-26 23:55:29719ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56720 NotificationService::current()->Notify(
721 NotificationType::PROFILE_DESTROYED,
722 Source<Profile>(this),
723 NotificationService::NoDetails());
724
[email protected]169627b2008-12-06 19:30:19725 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29726
727 StopCreateSessionServiceTimer();
728 // TemplateURLModel schedules a task on the WebDataService from its
729 // destructor. Delete it first to ensure the task gets scheduled before we
730 // shut down the database.
731 template_url_model_.reset();
732
733 // The download manager queries the history system and should be deleted
734 // before the history is shutdown so it can properly cancel all requests.
735 download_manager_ = NULL;
736
[email protected]4a190632009-05-09 01:07:42737 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15738 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42739
[email protected]44961292009-07-20 20:03:09740 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
741 // save any new thumbnails to disk and release its reference to the
742 // HistoryService.
743 if (thumbnail_store_.get())
744 thumbnail_store_->Shutdown();
745
[email protected]e7244d82008-10-29 18:13:26746 // Remove pref observers.
747 PrefService* prefs = GetPrefs();
748 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
749 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58750 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26751
[email protected]9c8dd902009-11-19 17:50:42752 // Delete the NTP resource cache so we can unregister pref observers.
753 ntp_resource_cache_.reset();
754
[email protected]48352c12009-08-15 01:19:11755 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34756
initial.commit09911bf2008-07-26 23:55:29757 // Both HistoryService and WebDataService maintain threads for background
758 // processing. Its possible each thread still has tasks on it that have
759 // increased the ref count of the service. In such a situation, when we
760 // decrement the refcount, it won't be 0, and the threads/databases aren't
761 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
762 // databases are properly closed.
763 if (web_data_service_.get())
764 web_data_service_->Shutdown();
765
766 if (history_service_.get())
767 history_service_->Cleanup();
768
[email protected]85c55dc2009-11-06 03:05:46769 if (spellcheck_host_.get())
770 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29771
[email protected]cfc06f122009-11-16 22:18:55772 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21773 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50774
[email protected]47accfd62009-05-14 18:46:21775 CleanupRequestContext(request_context_);
776 CleanupRequestContext(media_request_context_);
777 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17778
[email protected]d8e41ed2008-09-11 15:22:32779 // HistoryService may call into the BookmarkModel, as such we need to
780 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46781 // HistoryService will join with HistoryService's backend thread so that
782 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32783 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46784 history_service_ = NULL;
785 bookmark_bar_model_.reset();
786
[email protected]0189bc722009-08-28 21:56:48787 // FaviconService depends on HistoryServce so make sure we delete
788 // HistoryService first.
789 favicon_service_ = NULL;
790
[email protected]7120f132009-07-20 21:05:37791 extension_message_service_->ProfileDestroyed();
792
[email protected]6ef635e42009-07-26 06:16:12793 if (extensions_service_)
794 extensions_service_->ProfileDestroyed();
795
[email protected]66da08b2009-10-19 22:27:00796 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29797 MarkAsCleanShutdown();
798}
799
[email protected]4bf6afd2009-10-08 14:00:11800ProfileId ProfileImpl::GetRuntimeId() {
801 return reinterpret_cast<ProfileId>(this);
802}
803
[email protected]f7011fcb2009-01-28 21:54:32804FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29805 return path_;
806}
807
808bool ProfileImpl::IsOffTheRecord() {
809 return false;
810}
811
812Profile* ProfileImpl::GetOffTheRecordProfile() {
813 if (!off_the_record_profile_.get()) {
814 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
815 off_the_record_profile_.swap(p);
816 }
817 return off_the_record_profile_.get();
818}
819
[email protected]860f55492009-03-27 19:50:59820void ProfileImpl::DestroyOffTheRecordProfile() {
821 off_the_record_profile_.reset();
822}
823
initial.commit09911bf2008-07-26 23:55:29824Profile* ProfileImpl::GetOriginalProfile() {
825 return this;
826}
827
[email protected]2f351cb2009-11-09 23:43:34828webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
829 if (!db_tracker_)
830 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
831 return db_tracker_;
832}
833
initial.commit09911bf2008-07-26 23:55:29834VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44835 if (!visited_link_master_.get()) {
836 scoped_ptr<VisitedLinkMaster> visited_links(
837 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
838 if (!visited_links->Init())
839 return NULL;
840 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53841 }
[email protected]a6d0f182010-01-12 08:01:44842
843 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29844}
845
[email protected]6014d672008-12-05 00:38:25846ExtensionsService* ProfileImpl::GetExtensionsService() {
847 return extensions_service_.get();
848}
849
[email protected]0938d3c2009-01-09 20:37:35850UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35851 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25852}
853
[email protected]89ebc7e2009-08-24 22:11:07854ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
855 return extension_devtools_manager_.get();
856}
857
[email protected]481e1a42009-05-06 20:56:05858ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27859 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05860}
861
[email protected]7120f132009-07-20 21:05:37862ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
863 return extension_message_service_.get();
864}
865
[email protected]34cc84f2009-02-13 10:04:35866SSLHostState* ProfileImpl::GetSSLHostState() {
867 if (!ssl_host_state_.get())
868 ssl_host_state_.reset(new SSLHostState());
869
870 DCHECK(ssl_host_state_->CalledOnValidThread());
871 return ssl_host_state_.get();
872}
873
[email protected]326e6792009-12-11 21:04:42874net::TransportSecurityState*
875 ProfileImpl::GetTransportSecurityState() {
876 if (!transport_security_state_.get()) {
877 transport_security_state_ = new net::TransportSecurityState();
878 transport_security_persister_ =
879 new TransportSecurityPersister();
880 transport_security_persister_->Initialize(
881 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51882 }
[email protected]a9cea7542009-05-20 04:30:23883
[email protected]326e6792009-12-11 21:04:42884 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23885}
886
initial.commit09911bf2008-07-26 23:55:29887PrefService* ProfileImpl::GetPrefs() {
888 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37889 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29890
891 // The Profile class and ProfileManager class may read some prefs so
892 // register known prefs as soon as possible.
893 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51894 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29895
896 // The last session exited cleanly if there is no pref for
897 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
898 last_session_exited_cleanly_ =
899 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
900 // Mark the session as open.
901 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
902 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36903 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29904 }
905
906 return prefs_.get();
907}
908
[email protected]f7011fcb2009-01-28 21:54:32909FilePath ProfileImpl::GetPrefFilePath() {
910 FilePath pref_file_path = path_;
911 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29912 return pref_file_path;
913}
914
[email protected]be180c802009-10-23 06:33:31915URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29916 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32917 FilePath cookie_path = GetPath();
918 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13919 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31920 int max_size;
921 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42922
[email protected]405a64b2009-09-16 21:03:44923 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31924 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
925 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29926
[email protected]6ab9b202008-12-23 22:34:50927 // The first request context is always a normal (non-OTR) request context.
928 // Even when Chromium is started in OTR mode, a normal profile is always
929 // created first.
930 if (!default_request_context_) {
931 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31932 // TODO(eroman): this isn't terribly useful anymore now that the
933 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50934 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56935 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50936 NotificationService::AllSources(), NotificationService::NoDetails());
937 }
initial.commit09911bf2008-07-26 23:55:29938 }
939
940 return request_context_;
941}
942
[email protected]be180c802009-10-23 06:33:31943URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18944 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13945 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31946 int max_size;
947 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14948
[email protected]405a64b2009-09-16 21:03:44949 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31950 media_request_context_ =
951 ChromeURLRequestContextGetter::CreateOriginalForMedia(
952 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18953 }
954
955 return media_request_context_;
956}
957
[email protected]0189bc722009-08-28 21:56:48958FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
959 if (!favicon_service_created_) {
960 favicon_service_created_ = true;
961 scoped_refptr<FaviconService> service(new FaviconService(this));
962 favicon_service_.swap(service);
963 }
964 return favicon_service_.get();
965}
966
[email protected]be180c802009-10-23 06:33:31967URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21968 if (!extensions_request_context_) {
969 FilePath cookie_path = GetPath();
970 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
971
972 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31973 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
974 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21975 }
976
977 return extensions_request_context_;
978}
979
[email protected]db36938c2009-08-19 21:48:42980net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
981 return ssl_config_service_manager_->Get();
982}
983
[email protected]e284e6d82010-01-29 19:49:45984HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
985 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:39986 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:45987 return host_content_settings_map_.get();
988}
989
[email protected]40bd6582009-12-04 23:49:51990HostZoomMap* ProfileImpl::GetHostZoomMap() {
991 if (!host_zoom_map_)
992 host_zoom_map_ = new HostZoomMap(this);
993 return host_zoom_map_.get();
994}
995
[email protected]aee541e2010-03-19 01:52:45996GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
997 if (!geolocation_content_settings_map_.get())
998 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
999 return geolocation_content_settings_map_.get();
1000}
1001
[email protected]8c6335d32010-01-20 09:21:501002Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271003 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141004 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271005 return NULL;
[email protected]c37f8b42010-01-23 16:22:141006 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541007 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501008 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231009}
1010
[email protected]6c32ce72010-03-08 05:18:061011UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1012 if (!user_style_sheet_watcher_.get()) {
1013 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1014 user_style_sheet_watcher_->Init();
1015 }
1016 return user_style_sheet_watcher_.get();
1017}
1018
initial.commit09911bf2008-07-26 23:55:291019HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1020 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461021 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291022 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321023 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291024 return NULL;
1025 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291026
1027 // Send out the notification that the history service was created.
1028 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561029 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291030 Details<HistoryService>(history_service_.get()));
1031 }
1032 return history_service_.get();
1033}
1034
[email protected]0850fa62009-10-08 22:34:291035HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1036 return history_service_.get();
1037}
1038
initial.commit09911bf2008-07-26 23:55:291039TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1040 if (!template_url_model_.get())
1041 template_url_model_.reset(new TemplateURLModel(this));
1042 return template_url_model_.get();
1043}
1044
1045TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1046 if (!template_url_fetcher_.get())
1047 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1048 return template_url_fetcher_.get();
1049}
1050
[email protected]11f4857282009-11-13 19:56:171051SearchVersusNavigateClassifier*
1052ProfileImpl::GetSearchVersusNavigateClassifier() {
[email protected]90085af02009-10-29 17:53:211053 if (!search_versus_navigate_classifier_.get()) {
1054 search_versus_navigate_classifier_.reset(
1055 new SearchVersusNavigateClassifier(this));
1056 }
1057 return search_versus_navigate_classifier_.get();
1058}
1059
initial.commit09911bf2008-07-26 23:55:291060WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1061 if (!created_web_data_service_)
1062 CreateWebDataService();
1063 return web_data_service_.get();
1064}
1065
[email protected]9cddbe372009-10-23 21:23:531066WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1067 return web_data_service_.get();
1068}
1069
initial.commit09911bf2008-07-26 23:55:291070void ProfileImpl::CreateWebDataService() {
1071 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1072 created_web_data_service_ = true;
1073 scoped_refptr<WebDataService> wds(new WebDataService());
1074 if (!wds->Init(GetPath()))
1075 return;
1076 web_data_service_.swap(wds);
1077}
1078
[email protected]e69d33952009-06-03 22:00:411079PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1080 if (!created_password_store_)
1081 CreatePasswordStore();
1082 return password_store_.get();
1083}
1084
1085void ProfileImpl::CreatePasswordStore() {
1086 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1087 created_password_store_ = true;
1088 scoped_refptr<PasswordStore> ps;
[email protected]753efc42010-03-09 19:52:161089#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:411090 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561091#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171092 FilePath login_db_file_path = GetPath();
1093 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1094 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1095 if (!login_db->Init(login_db_file_path)) {
1096 LOG(ERROR) << "Could not initialize login database.";
1097 delete login_db;
1098 return;
1099 }
1100 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161101#elif defined(OS_POSIX)
1102 // TODO(evanm): implement "native" password management.
1103 // This bug describes the issues.
1104 // http://code.google.com/p/chromium/issues/detail?id=12351
1105 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1106 if (!ps->Init())
1107 return;
[email protected]e69d33952009-06-03 22:00:411108#else
1109 NOTIMPLEMENTED();
1110#endif
1111 if (!ps || !ps->Init()) {
1112 // Try falling back to the default password manager
1113 LOG(WARNING) << "Could not initialise native password manager - "
1114 "falling back to default";
1115 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1116 if (!ps->Init())
1117 return;
1118 }
1119 password_store_.swap(ps);
1120}
1121
initial.commit09911bf2008-07-26 23:55:291122DownloadManager* ProfileImpl::GetDownloadManager() {
1123 if (!created_download_manager_) {
1124 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1125 dlm->Init(this);
1126 created_download_manager_ = true;
1127 download_manager_.swap(dlm);
1128 }
1129 return download_manager_.get();
1130}
1131
1132bool ProfileImpl::HasCreatedDownloadManager() const {
1133 return created_download_manager_;
1134}
1135
[email protected]def11712009-11-06 00:42:151136PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1137 if (!personal_data_manager_.get()) {
[email protected]2609bc12010-01-24 08:32:551138 personal_data_manager_.reset(new PersonalDataManager(this));
[email protected]def11712009-11-06 00:42:151139 }
1140 return personal_data_manager_.get();
1141}
1142
[email protected]4a190632009-05-09 01:07:421143void ProfileImpl::InitThemes() {
1144 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161145#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151146 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291147#else
[email protected]761962c2009-09-25 00:18:151148 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291149#endif
[email protected]761962c2009-09-25 00:18:151150 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421151 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421152 }
1153}
1154
1155void ProfileImpl::SetTheme(Extension* extension) {
1156 InitThemes();
1157 theme_provider_.get()->SetTheme(extension);
1158}
1159
[email protected]a5166af62009-07-03 00:42:291160void ProfileImpl::SetNativeTheme() {
1161 InitThemes();
1162 theme_provider_.get()->SetNativeTheme();
1163}
1164
[email protected]4a190632009-05-09 01:07:421165void ProfileImpl::ClearTheme() {
1166 InitThemes();
1167 theme_provider_.get()->UseDefaultTheme();
1168}
1169
[email protected]51c490b2009-08-03 16:34:341170Extension* ProfileImpl::GetTheme() {
1171 InitThemes();
1172
1173 std::string id = theme_provider_.get()->GetThemeID();
1174 if (id == BrowserThemeProvider::kDefaultThemeID)
1175 return NULL;
1176
[email protected]61b411612009-11-10 23:17:411177 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341178}
1179
[email protected]5786d3d2009-12-18 00:18:441180BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421181 InitThemes();
1182 return theme_provider_.get();
1183}
1184
initial.commit09911bf2008-07-26 23:55:291185SessionService* ProfileImpl::GetSessionService() {
1186 if (!session_service_.get() && !shutdown_session_service_) {
1187 session_service_ = new SessionService(this);
1188 session_service_->ResetFromCurrentBrowsers();
1189 }
1190 return session_service_.get();
1191}
1192
1193void ProfileImpl::ShutdownSessionService() {
1194 if (shutdown_session_service_)
1195 return;
1196
1197 // We're about to exit, force creation of the session service if it hasn't
1198 // been created yet. We do this to ensure session state matches the point in
1199 // time the user exited.
1200 GetSessionService();
1201 shutdown_session_service_ = true;
1202 session_service_ = NULL;
1203}
1204
1205bool ProfileImpl::HasSessionService() const {
1206 return (session_service_.get() != NULL);
1207}
1208
initial.commit09911bf2008-07-26 23:55:291209bool ProfileImpl::DidLastSessionExitCleanly() {
1210 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1211 // it to be set by asking for the prefs.
1212 GetPrefs();
1213 return last_session_exited_cleanly_;
1214}
1215
[email protected]d8e41ed2008-09-11 15:22:321216BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461217 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321218 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461219 bookmark_bar_model_->Load();
1220 }
initial.commit09911bf2008-07-26 23:55:291221 return bookmark_bar_model_.get();
1222}
1223
1224bool ProfileImpl::IsSameProfile(Profile* profile) {
1225 if (profile == static_cast<Profile*>(this))
1226 return true;
1227 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1228 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1229}
1230
1231Time ProfileImpl::GetStartTime() const {
1232 return start_time_;
1233}
1234
1235TabRestoreService* ProfileImpl::GetTabRestoreService() {
1236 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191237 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291238 return tab_restore_service_.get();
1239}
1240
[email protected]449478302009-06-09 20:04:281241ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1242 if (!thumbnail_store_.get()) {
1243 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251244 thumbnail_store_->Init(
1245 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281246 }
1247 return thumbnail_store_.get();
1248}
1249
initial.commit09911bf2008-07-26 23:55:291250void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191251 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291252}
1253
[email protected]85c55dc2009-11-06 03:05:461254SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1255 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1256}
1257
1258void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1259 // If we are already loading the spellchecker, and this is just a hint to
1260 // load the spellchecker, do nothing.
1261 if (!force && spellcheck_host_.get())
1262 return;
1263
[email protected]f41301e2009-11-16 21:30:071264 spellcheck_host_ready_ = false;
1265
[email protected]85c55dc2009-11-06 03:05:461266 bool notify = false;
1267 if (spellcheck_host_.get()) {
1268 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051269 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461270 notify = true;
1271 }
1272
1273 PrefService* prefs = GetPrefs();
1274 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1275 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1276 spellcheck_host_ = new SpellCheckHost(this,
1277 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1278 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071279 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461280 } else if (notify) {
1281 // The spellchecker has been disabled.
1282 SpellCheckHostInitialized();
1283 }
1284}
1285
1286void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171287 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291288 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1289 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461290 NotificationService::current()->Notify(
1291 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1292 Source<Profile>(this), NotificationService::NoDetails());
1293}
initial.commit09911bf2008-07-26 23:55:291294
[email protected]3bf335a2009-06-26 20:46:061295WebKitContext* ProfileImpl::GetWebKitContext() {
1296 if (!webkit_context_.get())
1297 webkit_context_ = new WebKitContext(path_, false);
1298 DCHECK(webkit_context_.get());
1299 return webkit_context_.get();
1300}
1301
[email protected]4bb336302009-10-12 05:44:261302DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1303 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1304 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261305 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031306 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261307 }
[email protected]4bb336302009-10-12 05:44:261308 return desktop_notification_service_.get();
1309}
1310
initial.commit09911bf2008-07-26 23:55:291311void ProfileImpl::MarkAsCleanShutdown() {
1312 if (prefs_.get()) {
1313 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1314 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1315
1316 // NOTE: If you change what thread this writes on, be sure and update
1317 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361318 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291319 }
1320}
1321
[email protected]e7244d82008-10-29 18:13:261322void ProfileImpl::Observe(NotificationType type,
1323 const NotificationSource& source,
1324 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561325 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261326 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1327 PrefService* prefs = Source<PrefService>(source).ptr();
1328 DCHECK(pref_name_in && prefs);
1329 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461330 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461331 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291332 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1333 NotificationService::current()->Notify(
1334 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1335 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261336 }
[email protected]4a190632009-05-09 01:07:421337 } else if (NotificationType::THEME_INSTALLED == type) {
1338 Extension* extension = Details<Extension>(details).ptr();
1339 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111340 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1341 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1342 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1343 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261344 }
1345}
1346
initial.commit09911bf2008-07-26 23:55:291347void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141348 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291349}
[email protected]3a453fa2008-08-15 18:46:341350
[email protected]48352c12009-08-15 01:19:111351ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431352 if (!ProfileSyncService::IsSyncEnabled()) {
1353 return NULL;
[email protected]7367f1a2009-10-10 01:09:441354 }
[email protected]eec3bcfa2009-11-12 17:23:431355 if (!sync_service_.get())
1356 InitSyncService();
1357 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111358}
1359
1360void ProfileImpl::InitSyncService() {
[email protected]4aea04a2010-02-10 20:13:431361 profile_sync_factory_.reset(
1362 new ProfileSyncFactoryImpl(this,
1363 CommandLine::ForCurrentProcess()));
1364 sync_service_.reset(
1365 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111366 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111367}