blob: 01d4824f148885ffbd9535b19c61cfb2ddd8309f [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]9c92d192009-12-02 08:03:1631#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4232#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4233#include "chrome/browser/history/history.h"
[email protected]e284e6d82010-01-29 19:49:4534#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5135#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0636#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5037#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4238#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2639#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4140#include "chrome/browser/password_manager/password_store_default.h"
[email protected]8c6335d32010-01-20 09:21:5041#include "chrome/browser/privacy_blacklist/blacklist.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2643#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]90085af02009-10-29 17:53:2144#include "chrome/browser/search_versus_navigate_classifier.h"
[email protected]1132436e2009-04-08 20:06:3345#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4646#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4447#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3048#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3349#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1150#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4351#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4052#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2853#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0654#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2955#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3956#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2957#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5658#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/common/chrome_constants.h"
60#include "chrome/common/chrome_paths.h"
61#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5862#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2963#include "chrome/common/notification_service.h"
64#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3265#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3466#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5867#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4268#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3469#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2970
[email protected]753efc42010-03-09 19:52:1671#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2972#include "chrome/browser/gtk/gtk_theme_provider.h"
73#endif
74
[email protected]e1acf6f2008-10-27 20:43:3375using base::Time;
76using base::TimeDelta;
77
[email protected]e5642992009-06-26 23:06:3178namespace {
79
initial.commit09911bf2008-07-26 23:55:2980// Delay, in milliseconds, before we explicitly create the SessionService.
81static const int kCreateSessionServiceDelayMS = 500;
82
[email protected]e5642992009-06-26 23:06:3183enum ContextType {
84 kNormalContext,
85 kMediaContext
86};
87
88// Gets the cache parameters from the command line. |type| is the type of
89// request context that we need, |cache_path| will be set to the user provided
90// path, or will not be touched if there is not an argument. |max_size| will
91// be the user provided value or zero by default.
92void GetCacheParameters(ContextType type, FilePath* cache_path,
93 int* max_size) {
94 DCHECK(cache_path);
95 DCHECK(max_size);
96
97 // Override the cache location if specified by the user.
98 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
99 switches::kDiskCacheDir));
100
101 if (!user_path.empty()) {
102 *cache_path = FilePath::FromWStringHack(user_path);
103 }
104
[email protected]b7e0a2a2009-10-13 02:07:25105 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
106 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31107 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25108 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31109
110 // By default we let the cache determine the right size.
111 *max_size = 0;
112 if (!StringToInt(value, max_size)) {
113 *max_size = 0;
114 } else if (max_size < 0) {
115 *max_size = 0;
116 }
117}
118
[email protected]405a64b2009-09-16 21:03:44119FilePath GetCachePath(const FilePath& base) {
120 return base.Append(chrome::kCacheDirname);
121}
122
123FilePath GetMediaCachePath(const FilePath& base) {
124 return base.Append(chrome::kMediaCacheDirname);
125}
126
127bool HasACacheSubdir(const FilePath &dir) {
128 return file_util::PathExists(GetCachePath(dir)) ||
129 file_util::PathExists(GetMediaCachePath(dir));
130}
131
[email protected]e5642992009-06-26 23:06:31132} // namespace
133
initial.commit09911bf2008-07-26 23:55:29134// A pointer to the request context for the default profile. See comments on
135// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31136URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29137
[email protected]be180c802009-10-23 06:33:31138static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19139 if (context)
[email protected]47accfd62009-05-14 18:46:21140 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21141}
142
[email protected]34cc84f2009-02-13 10:04:35143// static
[email protected]4bf6afd2009-10-08 14:00:11144const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
145
146// static
initial.commit09911bf2008-07-26 23:55:29147void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55148 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29149 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
150 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12151 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26152 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
153 IDS_SPELLCHECK_DICTIONARY);
154 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58155 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16156#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:29157 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
158#endif
[email protected]f017cc92009-12-14 20:48:07159 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34160 prefs->RegisterStringPref(prefs::kCurrentThemeID,
161 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42162 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
163 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
164 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50165 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23166 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29167}
168
[email protected]34cc84f2009-02-13 10:04:35169// static
[email protected]f7011fcb2009-01-28 21:54:32170Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29171 return new ProfileImpl(path);
172}
173
[email protected]34cc84f2009-02-13 10:04:35174// static
[email protected]be180c802009-10-23 06:33:31175URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29176 return default_request_context_;
177}
178
[email protected]753efc42010-03-09 19:52:16179#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41180#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56181#elif defined(OS_MACOSX)
182#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17183#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56184#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16185#elif defined(OS_POSIX)
186// Temporarily disabled while we figure some stuff out.
187// http://code.google.com/p/chromium/issues/detail?id=12351
188// #include "chrome/browser/password_manager/password_store_gnome.h"
189// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41190#endif
initial.commit09911bf2008-07-26 23:55:29191
initial.commit09911bf2008-07-26 23:55:29192////////////////////////////////////////////////////////////////////////////////
193//
194// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42195// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29196//
197////////////////////////////////////////////////////////////////////////////////
198class OffTheRecordProfileImpl : public Profile,
199 public NotificationObserver {
200 public:
201 explicit OffTheRecordProfileImpl(Profile* real_profile)
202 : profile_(real_profile),
203 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31204 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05205
initial.commit09911bf2008-07-26 23:55:29206 // Register for browser close notifications so we can detect when the last
207 // off-the-record window is closed, in which case we can clean our states
208 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43209 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
210 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29211 }
212
213 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21214 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29215 }
216
[email protected]4bf6afd2009-10-08 14:00:11217 virtual ProfileId GetRuntimeId() {
218 return reinterpret_cast<ProfileId>(this);
219 }
220
[email protected]a6d0f182010-01-12 08:01:44221 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29222
223 virtual bool IsOffTheRecord() {
224 return true;
225 }
226
227 virtual Profile* GetOffTheRecordProfile() {
228 return this;
229 }
230
[email protected]860f55492009-03-27 19:50:59231 virtual void DestroyOffTheRecordProfile() {
232 // Suicide is bad!
233 NOTREACHED();
234 }
235
initial.commit09911bf2008-07-26 23:55:29236 virtual Profile* GetOriginalProfile() {
237 return profile_;
238 }
239
[email protected]2f351cb2009-11-09 23:43:34240 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
241 if (!db_tracker_)
242 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
243 return db_tracker_;
244 }
245
initial.commit09911bf2008-07-26 23:55:29246 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49247 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
248 // because we don't want to leak the sites that the user has visited before.
249 return NULL;
initial.commit09911bf2008-07-26 23:55:29250 }
251
[email protected]6014d672008-12-05 00:38:25252 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21253 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25254 }
255
[email protected]0938d3c2009-01-09 20:37:35256 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21257 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25258 }
259
[email protected]89ebc7e2009-08-24 22:11:07260 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21261 // TODO(mpcomplete): figure out whether we should return the original
262 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07263 return NULL;
264 }
265
[email protected]481e1a42009-05-06 20:56:05266 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21267 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05268 }
269
[email protected]7120f132009-07-20 21:05:37270 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21271 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37272 }
273
[email protected]34cc84f2009-02-13 10:04:35274 virtual SSLHostState* GetSSLHostState() {
275 if (!ssl_host_state_.get())
276 ssl_host_state_.reset(new SSLHostState());
277
278 DCHECK(ssl_host_state_->CalledOnValidThread());
279 return ssl_host_state_.get();
280 }
281
[email protected]326e6792009-12-11 21:04:42282 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54283 if (!transport_security_state_.get())
284 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23285
[email protected]326e6792009-12-11 21:04:42286 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23287 }
288
initial.commit09911bf2008-07-26 23:55:29289 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54290 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29291 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54292
293 NOTREACHED() << "This profile is OffTheRecord";
294 return NULL;
initial.commit09911bf2008-07-26 23:55:29295 }
296
[email protected]0850fa62009-10-08 22:34:29297 virtual HistoryService* GetHistoryServiceWithoutCreating() {
298 return profile_->GetHistoryServiceWithoutCreating();
299 }
300
[email protected]0189bc722009-08-28 21:56:48301 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54302 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48303 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54304
305 NOTREACHED() << "This profile is OffTheRecord";
306 return NULL;
[email protected]0189bc722009-08-28 21:56:48307 }
308
[email protected]90085af02009-10-29 17:53:21309 virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
310 return profile_->GetSearchVersusNavigateClassifier();
311 }
312
initial.commit09911bf2008-07-26 23:55:29313 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54314 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29315 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54316
317 NOTREACHED() << "This profile is OffTheRecord";
318 return NULL;
initial.commit09911bf2008-07-26 23:55:29319 }
320
[email protected]9cddbe372009-10-23 21:23:53321 virtual WebDataService* GetWebDataServiceWithoutCreating() {
322 return profile_->GetWebDataServiceWithoutCreating();
323 }
324
[email protected]e69d33952009-06-03 22:00:41325 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54326 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41327 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54328
329 NOTREACHED() << "This profile is OffTheRecord";
330 return NULL;
[email protected]e69d33952009-06-03 22:00:41331 }
332
initial.commit09911bf2008-07-26 23:55:29333 virtual PrefService* GetPrefs() {
334 return profile_->GetPrefs();
335 }
336
337 virtual TemplateURLModel* GetTemplateURLModel() {
338 return profile_->GetTemplateURLModel();
339 }
340
341 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
342 return profile_->GetTemplateURLFetcher();
343 }
344
345 virtual DownloadManager* GetDownloadManager() {
346 if (!download_manager_.get()) {
347 scoped_refptr<DownloadManager> dlm(new DownloadManager);
348 dlm->Init(this);
349 download_manager_.swap(dlm);
350 }
351 return download_manager_.get();
352 }
353
354 virtual bool HasCreatedDownloadManager() const {
355 return (download_manager_.get() != NULL);
356 }
357
[email protected]def11712009-11-06 00:42:15358 virtual PersonalDataManager* GetPersonalDataManager() {
359 return NULL;
360 }
361
[email protected]4a190632009-05-09 01:07:42362 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54363 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42364 }
365
366 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54367 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42368 }
369
[email protected]a5166af62009-07-03 00:42:29370 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54371 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29372 }
373
[email protected]4a190632009-05-09 01:07:42374 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54375 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42376 }
377
[email protected]51c490b2009-08-03 16:34:34378 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54379 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34380 }
381
[email protected]5786d3d2009-12-18 00:18:44382 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54383 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42384 }
385
[email protected]be180c802009-10-23 06:33:31386 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29387 return request_context_;
388 }
389
[email protected]be180c802009-10-23 06:33:31390 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11391 // In OTR mode, media request context is the same as the original one.
392 return request_context_;
[email protected]e7f29642009-03-02 22:53:18393 }
394
[email protected]be180c802009-10-23 06:33:31395 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21396 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21397 }
398
[email protected]db36938c2009-08-19 21:48:42399 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54400 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42401 }
402
[email protected]e284e6d82010-01-29 19:49:45403 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]08bc6302010-01-30 02:53:39404 return profile_->GetHostContentSettingsMap();
[email protected]e284e6d82010-01-29 19:49:45405 }
406
[email protected]40bd6582009-12-04 23:49:51407 virtual HostZoomMap* GetHostZoomMap() {
[email protected]779c3362010-01-30 01:09:33408 return profile_->GetHostZoomMap();
[email protected]40bd6582009-12-04 23:49:51409 }
410
[email protected]8c6335d32010-01-20 09:21:50411 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54412 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23413 }
414
[email protected]6c32ce72010-03-08 05:18:06415 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
416 return profile_->GetUserStyleSheetWatcher();
417 }
418
initial.commit09911bf2008-07-26 23:55:29419 virtual SessionService* GetSessionService() {
420 // Don't save any sessions when off the record.
421 return NULL;
422 }
423
424 virtual void ShutdownSessionService() {
425 // We don't allow a session service, nothing to do.
426 }
427
428 virtual bool HasSessionService() const {
429 // We never have a session service.
430 return false;
431 }
432
initial.commit09911bf2008-07-26 23:55:29433 virtual bool DidLastSessionExitCleanly() {
434 return profile_->DidLastSessionExitCleanly();
435 }
436
[email protected]d8e41ed2008-09-11 15:22:32437 virtual BookmarkModel* GetBookmarkModel() {
438 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29439 }
440
[email protected]4bb336302009-10-12 05:44:26441 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58442 if (!desktop_notification_service_.get()) {
443 desktop_notification_service_.reset(new DesktopNotificationService(
444 this, g_browser_process->notification_ui_manager()));
445 }
446 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26447 }
448
[email protected]48352c12009-08-15 01:19:11449 virtual ProfileSyncService* GetProfileSyncService() {
450 return NULL;
[email protected]3a453fa2008-08-15 18:46:34451 }
[email protected]3a453fa2008-08-15 18:46:34452
initial.commit09911bf2008-07-26 23:55:29453 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54454 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29455 }
456
457 virtual Time GetStartTime() const {
458 return start_time_;
459 }
460
461 virtual TabRestoreService* GetTabRestoreService() {
462 return NULL;
463 }
464
[email protected]e7244d82008-10-29 18:13:26465 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41466 }
467
[email protected]85c55dc2009-11-06 03:05:46468 virtual SpellCheckHost* GetSpellCheckHost() {
469 return profile_->GetSpellCheckHost();
470 }
471
472 virtual void ReinitializeSpellCheckHost(bool force) {
473 profile_->ReinitializeSpellCheckHost(force);
474 }
[email protected]85c55dc2009-11-06 03:05:46475
[email protected]3bf335a2009-06-26 20:46:06476 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29477 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21478 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29479 DCHECK(webkit_context_.get());
480 return webkit_context_.get();
481 }
[email protected]3bf335a2009-06-26 20:46:06482
[email protected]449478302009-06-09 20:04:28483 virtual ThumbnailStore* GetThumbnailStore() {
484 return NULL;
485 }
486
initial.commit09911bf2008-07-26 23:55:29487 virtual void MarkAsCleanShutdown() {
488 }
489
[email protected]bdbc87c2009-01-25 05:08:54490 virtual void InitExtensions() {
491 NOTREACHED();
492 }
493
[email protected]ea0c98cf2009-06-18 23:02:54494 virtual void InitWebResources() {
495 NOTREACHED();
496 }
497
[email protected]9c8dd902009-11-19 17:50:42498 virtual NTPResourceCache* GetNTPResourceCache() {
499 // Just return the real profile resource cache.
500 return profile_->GetNTPResourceCache();
501 }
502
initial.commit09911bf2008-07-26 23:55:29503 virtual void ExitedOffTheRecordMode() {
504 // Drop our download manager so we forget about all the downloads made
505 // in off-the-record mode.
506 download_manager_ = NULL;
507 }
508
509 virtual void Observe(NotificationType type,
510 const NotificationSource& source,
511 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56512 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29513 // We are only interested in OTR browser closing.
514 if (Source<Browser>(source)->profile() != this)
515 return;
516
517 // Let's check if we still have an Off The Record window opened.
518 // Note that we check against 1 as this notification is sent before the
519 // browser window is actually removed from the list.
520 if (BrowserList::GetBrowserCount(this) <= 1)
521 ExitedOffTheRecordMode();
522 }
523
524 private:
[email protected]88cf3292009-05-22 01:48:43525 NotificationRegistrar registrar_;
526
initial.commit09911bf2008-07-26 23:55:29527 // The real underlying profile.
528 Profile* profile_;
529
[email protected]6ab9b202008-12-23 22:34:50530 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19531 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29532
533 // The download manager that only stores downloaded items in memory.
534 scoped_refptr<DownloadManager> download_manager_;
535
[email protected]7d7696c52009-12-01 20:54:58536 // Use a separate desktop notification service for OTR.
537 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
538
[email protected]3bf335a2009-06-26 20:46:06539 // Use a special WebKit context for OTR browsing.
540 scoped_refptr<WebKitContext> webkit_context_;
541
[email protected]34cc84f2009-02-13 10:04:35542 // We don't want SSLHostState from the OTR profile to leak back to the main
543 // profile because then the main profile would learn some of the host names
544 // the user visited while OTR.
545 scoped_ptr<SSLHostState> ssl_host_state_;
546
[email protected]326e6792009-12-11 21:04:42547 // The TransportSecurityState that only stores enabled sites in memory.
548 scoped_refptr<net::TransportSecurityState>
549 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23550
initial.commit09911bf2008-07-26 23:55:29551 // Time we were started.
552 Time start_time_;
553
[email protected]2f351cb2009-11-09 23:43:34554 // The main database tracker for this profile.
555 // Should be used only on the file thread.
556 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
557
[email protected]90085af02009-10-29 17:53:21558 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29559};
560
[email protected]f7011fcb2009-01-28 21:54:32561ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29562 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44563 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07564 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32565 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57566 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21567 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45568 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51569 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32570 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48571 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32572 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41573 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32574 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42575 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32576 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46577 spellcheck_host_(NULL),
578 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29579 shutdown_session_service_(false) {
580 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
581 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14582 create_session_service_timer_.Start(
583 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
584 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54585
[email protected]89ebc7e2009-08-24 22:11:07586 if (CommandLine::ForCurrentProcess()->HasSwitch(
587 switches::kEnableExtensionTimelineApi)) {
588 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
589 }
590
[email protected]382a0702009-06-26 17:12:27591 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37592 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27593
[email protected]e7244d82008-10-29 18:13:26594 PrefService* prefs = GetPrefs();
595 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
596 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58597 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58598
[email protected]405a64b2009-09-16 21:03:44599#if defined(OS_MACOSX)
600 // If the profile directory doesn't already have a cache directory and it
601 // is under ~/Library/Application Support, use a suitable cache directory
602 // under ~/Library/Caches. For example, a profile directory of
603 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
604 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
605 // ~/Library/Caches/Google/Chrome/MyProfileName.
606 //
607 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44608 if (!HasACacheSubdir(path_)) {
609 FilePath app_data_path, user_cache_path;
610 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12611 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44612 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
613 base_cache_path_ = user_cache_path;
614 }
615 }
[email protected]9e9b6e8e2009-12-02 08:45:01616#elif defined(OS_POSIX) // Posix minus Mac.
617 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
618 // for a spec on where cache files go. The net effect for most systems is we
619 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
620 // official builds.
621 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
622#if defined(GOOGLE_CHROME_BUILD)
623 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44624#else
[email protected]9e9b6e8e2009-12-02 08:45:01625 const char kCacheDir[] = "chromium";
626#endif
627 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
628 base_cache_path_ = base_cache_path_.Append(kCacheDir);
629 if (!file_util::PathExists(base_cache_path_))
630 file_util::CreateDirectory(base_cache_path_);
631 }
[email protected]405a64b2009-09-16 21:03:44632#endif
[email protected]bc96d562009-08-11 18:45:13633 if (base_cache_path_.empty())
634 base_cache_path_ = path_;
635
[email protected]4a190632009-05-09 01:07:42636 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43637 registrar_.Add(this, NotificationType::THEME_INSTALLED,
638 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11639
640 // Listen for bookmark model load, to bootstrap the sync service.
641 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
642 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42643
644 ssl_config_service_manager_.reset(
645 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53646
647#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29648 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53649#endif
[email protected]911f8152010-03-18 16:46:40650
651 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29652}
653
[email protected]bdbc87c2009-01-25 05:08:54654void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41655 if (user_script_master_ || extensions_service_)
656 return; // Already initialized.
657
[email protected]bdbc87c2009-01-25 05:08:54658 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18659 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36660
661 FilePath script_dir; // Don't look for user scripts in any directory.
662 // TODO(aa): We should just remove this functionality,
663 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51664 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36665
[email protected]894bb502009-05-21 22:39:57666 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23667 this,
668 CommandLine::ForCurrentProcess(),
669 GetPrefs(),
670 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36671 true);
[email protected]bdbc87c2009-01-25 05:08:54672
[email protected]1952c7d2010-03-04 23:48:34673 // Register the bookmark manager extension.
674 if (CommandLine::ForCurrentProcess()->HasSwitch(
675 switches::kEnableTabbedBookmarkManager)) {
676 FilePath bookmark_manager_path;
677 if (PathService::Get(chrome::DIR_BOOKMARK_MANAGER,
678 &bookmark_manager_path)) {
679 std::string manifest =
680 ResourceBundle::GetSharedInstance().GetRawDataResource(
681 IDR_BOOKMARKS_MANIFEST).as_string();
682 extensions_service_->register_component_extension(
683 ExtensionsService::ComponentExtensionInfo(manifest,
684 bookmark_manager_path));
685 } else {
686 NOTREACHED();
687 }
688 }
689
[email protected]9197f3b2009-06-02 00:49:27690 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12691
692 // Load any extensions specified with --load-extension.
693 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10694 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12695 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12696 }
[email protected]bdbc87c2009-01-25 05:08:54697}
698
[email protected]ea0c98cf2009-06-18 23:02:54699void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07700 if (web_resource_service_)
701 return; // Already initialized.
702
[email protected]6fad2632009-11-02 05:59:37703 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54704 web_resource_service_->StartAfterDelay();
705}
706
[email protected]9c8dd902009-11-19 17:50:42707NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
708 if (!ntp_resource_cache_.get())
709 ntp_resource_cache_.reset(new NTPResourceCache(this));
710 return ntp_resource_cache_.get();
711}
712
initial.commit09911bf2008-07-26 23:55:29713ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56714 NotificationService::current()->Notify(
715 NotificationType::PROFILE_DESTROYED,
716 Source<Profile>(this),
717 NotificationService::NoDetails());
718
[email protected]169627b2008-12-06 19:30:19719 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29720
721 StopCreateSessionServiceTimer();
722 // TemplateURLModel schedules a task on the WebDataService from its
723 // destructor. Delete it first to ensure the task gets scheduled before we
724 // shut down the database.
725 template_url_model_.reset();
726
727 // The download manager queries the history system and should be deleted
728 // before the history is shutdown so it can properly cancel all requests.
729 download_manager_ = NULL;
730
[email protected]4a190632009-05-09 01:07:42731 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15732 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42733
[email protected]44961292009-07-20 20:03:09734 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
735 // save any new thumbnails to disk and release its reference to the
736 // HistoryService.
737 if (thumbnail_store_.get())
738 thumbnail_store_->Shutdown();
739
[email protected]e7244d82008-10-29 18:13:26740 // Remove pref observers.
741 PrefService* prefs = GetPrefs();
742 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
743 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58744 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26745
[email protected]9c8dd902009-11-19 17:50:42746 // Delete the NTP resource cache so we can unregister pref observers.
747 ntp_resource_cache_.reset();
748
[email protected]48352c12009-08-15 01:19:11749 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34750
initial.commit09911bf2008-07-26 23:55:29751 // Both HistoryService and WebDataService maintain threads for background
752 // processing. Its possible each thread still has tasks on it that have
753 // increased the ref count of the service. In such a situation, when we
754 // decrement the refcount, it won't be 0, and the threads/databases aren't
755 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
756 // databases are properly closed.
757 if (web_data_service_.get())
758 web_data_service_->Shutdown();
759
760 if (history_service_.get())
761 history_service_->Cleanup();
762
[email protected]85c55dc2009-11-06 03:05:46763 if (spellcheck_host_.get())
764 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29765
[email protected]cfc06f122009-11-16 22:18:55766 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21767 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50768
[email protected]47accfd62009-05-14 18:46:21769 CleanupRequestContext(request_context_);
770 CleanupRequestContext(media_request_context_);
771 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17772
[email protected]d8e41ed2008-09-11 15:22:32773 // HistoryService may call into the BookmarkModel, as such we need to
774 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46775 // HistoryService will join with HistoryService's backend thread so that
776 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32777 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46778 history_service_ = NULL;
779 bookmark_bar_model_.reset();
780
[email protected]0189bc722009-08-28 21:56:48781 // FaviconService depends on HistoryServce so make sure we delete
782 // HistoryService first.
783 favicon_service_ = NULL;
784
[email protected]7120f132009-07-20 21:05:37785 extension_message_service_->ProfileDestroyed();
786
[email protected]6ef635e42009-07-26 06:16:12787 if (extensions_service_)
788 extensions_service_->ProfileDestroyed();
789
[email protected]66da08b2009-10-19 22:27:00790 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29791 MarkAsCleanShutdown();
792}
793
[email protected]4bf6afd2009-10-08 14:00:11794ProfileId ProfileImpl::GetRuntimeId() {
795 return reinterpret_cast<ProfileId>(this);
796}
797
[email protected]f7011fcb2009-01-28 21:54:32798FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29799 return path_;
800}
801
802bool ProfileImpl::IsOffTheRecord() {
803 return false;
804}
805
806Profile* ProfileImpl::GetOffTheRecordProfile() {
807 if (!off_the_record_profile_.get()) {
808 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
809 off_the_record_profile_.swap(p);
810 }
811 return off_the_record_profile_.get();
812}
813
[email protected]860f55492009-03-27 19:50:59814void ProfileImpl::DestroyOffTheRecordProfile() {
815 off_the_record_profile_.reset();
816}
817
initial.commit09911bf2008-07-26 23:55:29818Profile* ProfileImpl::GetOriginalProfile() {
819 return this;
820}
821
[email protected]2f351cb2009-11-09 23:43:34822webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
823 if (!db_tracker_)
824 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
825 return db_tracker_;
826}
827
initial.commit09911bf2008-07-26 23:55:29828VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44829 if (!visited_link_master_.get()) {
830 scoped_ptr<VisitedLinkMaster> visited_links(
831 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
832 if (!visited_links->Init())
833 return NULL;
834 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53835 }
[email protected]a6d0f182010-01-12 08:01:44836
837 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29838}
839
[email protected]6014d672008-12-05 00:38:25840ExtensionsService* ProfileImpl::GetExtensionsService() {
841 return extensions_service_.get();
842}
843
[email protected]0938d3c2009-01-09 20:37:35844UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35845 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25846}
847
[email protected]89ebc7e2009-08-24 22:11:07848ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
849 return extension_devtools_manager_.get();
850}
851
[email protected]481e1a42009-05-06 20:56:05852ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27853 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05854}
855
[email protected]7120f132009-07-20 21:05:37856ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
857 return extension_message_service_.get();
858}
859
[email protected]34cc84f2009-02-13 10:04:35860SSLHostState* ProfileImpl::GetSSLHostState() {
861 if (!ssl_host_state_.get())
862 ssl_host_state_.reset(new SSLHostState());
863
864 DCHECK(ssl_host_state_->CalledOnValidThread());
865 return ssl_host_state_.get();
866}
867
[email protected]326e6792009-12-11 21:04:42868net::TransportSecurityState*
869 ProfileImpl::GetTransportSecurityState() {
870 if (!transport_security_state_.get()) {
871 transport_security_state_ = new net::TransportSecurityState();
872 transport_security_persister_ =
873 new TransportSecurityPersister();
874 transport_security_persister_->Initialize(
875 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51876 }
[email protected]a9cea7542009-05-20 04:30:23877
[email protected]326e6792009-12-11 21:04:42878 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23879}
880
initial.commit09911bf2008-07-26 23:55:29881PrefService* ProfileImpl::GetPrefs() {
882 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37883 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29884
885 // The Profile class and ProfileManager class may read some prefs so
886 // register known prefs as soon as possible.
887 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51888 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29889
890 // The last session exited cleanly if there is no pref for
891 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
892 last_session_exited_cleanly_ =
893 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
894 // Mark the session as open.
895 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
896 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36897 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29898 }
899
900 return prefs_.get();
901}
902
[email protected]f7011fcb2009-01-28 21:54:32903FilePath ProfileImpl::GetPrefFilePath() {
904 FilePath pref_file_path = path_;
905 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29906 return pref_file_path;
907}
908
[email protected]be180c802009-10-23 06:33:31909URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29910 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32911 FilePath cookie_path = GetPath();
912 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13913 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31914 int max_size;
915 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42916
[email protected]405a64b2009-09-16 21:03:44917 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31918 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
919 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29920
[email protected]6ab9b202008-12-23 22:34:50921 // The first request context is always a normal (non-OTR) request context.
922 // Even when Chromium is started in OTR mode, a normal profile is always
923 // created first.
924 if (!default_request_context_) {
925 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31926 // TODO(eroman): this isn't terribly useful anymore now that the
927 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50928 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56929 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50930 NotificationService::AllSources(), NotificationService::NoDetails());
931 }
initial.commit09911bf2008-07-26 23:55:29932 }
933
934 return request_context_;
935}
936
[email protected]be180c802009-10-23 06:33:31937URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18938 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13939 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31940 int max_size;
941 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14942
[email protected]405a64b2009-09-16 21:03:44943 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31944 media_request_context_ =
945 ChromeURLRequestContextGetter::CreateOriginalForMedia(
946 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18947 }
948
949 return media_request_context_;
950}
951
[email protected]0189bc722009-08-28 21:56:48952FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
953 if (!favicon_service_created_) {
954 favicon_service_created_ = true;
955 scoped_refptr<FaviconService> service(new FaviconService(this));
956 favicon_service_.swap(service);
957 }
958 return favicon_service_.get();
959}
960
[email protected]be180c802009-10-23 06:33:31961URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21962 if (!extensions_request_context_) {
963 FilePath cookie_path = GetPath();
964 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
965
966 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31967 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
968 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21969 }
970
971 return extensions_request_context_;
972}
973
[email protected]db36938c2009-08-19 21:48:42974net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
975 return ssl_config_service_manager_->Get();
976}
977
[email protected]e284e6d82010-01-29 19:49:45978HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
979 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:39980 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:45981 return host_content_settings_map_.get();
982}
983
[email protected]40bd6582009-12-04 23:49:51984HostZoomMap* ProfileImpl::GetHostZoomMap() {
985 if (!host_zoom_map_)
986 host_zoom_map_ = new HostZoomMap(this);
987 return host_zoom_map_.get();
988}
989
[email protected]8c6335d32010-01-20 09:21:50990Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:27991 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:14992 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:27993 return NULL;
[email protected]c37f8b42010-01-23 16:22:14994 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:54995 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:50996 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:23997}
998
[email protected]6c32ce72010-03-08 05:18:06999UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1000 if (!user_style_sheet_watcher_.get()) {
1001 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1002 user_style_sheet_watcher_->Init();
1003 }
1004 return user_style_sheet_watcher_.get();
1005}
1006
initial.commit09911bf2008-07-26 23:55:291007HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1008 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461009 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291010 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321011 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291012 return NULL;
1013 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291014
1015 // Send out the notification that the history service was created.
1016 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561017 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291018 Details<HistoryService>(history_service_.get()));
1019 }
1020 return history_service_.get();
1021}
1022
[email protected]0850fa62009-10-08 22:34:291023HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1024 return history_service_.get();
1025}
1026
initial.commit09911bf2008-07-26 23:55:291027TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1028 if (!template_url_model_.get())
1029 template_url_model_.reset(new TemplateURLModel(this));
1030 return template_url_model_.get();
1031}
1032
1033TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1034 if (!template_url_fetcher_.get())
1035 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1036 return template_url_fetcher_.get();
1037}
1038
[email protected]11f4857282009-11-13 19:56:171039SearchVersusNavigateClassifier*
1040ProfileImpl::GetSearchVersusNavigateClassifier() {
[email protected]90085af02009-10-29 17:53:211041 if (!search_versus_navigate_classifier_.get()) {
1042 search_versus_navigate_classifier_.reset(
1043 new SearchVersusNavigateClassifier(this));
1044 }
1045 return search_versus_navigate_classifier_.get();
1046}
1047
initial.commit09911bf2008-07-26 23:55:291048WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1049 if (!created_web_data_service_)
1050 CreateWebDataService();
1051 return web_data_service_.get();
1052}
1053
[email protected]9cddbe372009-10-23 21:23:531054WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1055 return web_data_service_.get();
1056}
1057
initial.commit09911bf2008-07-26 23:55:291058void ProfileImpl::CreateWebDataService() {
1059 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1060 created_web_data_service_ = true;
1061 scoped_refptr<WebDataService> wds(new WebDataService());
1062 if (!wds->Init(GetPath()))
1063 return;
1064 web_data_service_.swap(wds);
1065}
1066
[email protected]e69d33952009-06-03 22:00:411067PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1068 if (!created_password_store_)
1069 CreatePasswordStore();
1070 return password_store_.get();
1071}
1072
1073void ProfileImpl::CreatePasswordStore() {
1074 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1075 created_password_store_ = true;
1076 scoped_refptr<PasswordStore> ps;
[email protected]753efc42010-03-09 19:52:161077#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:411078 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561079#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171080 FilePath login_db_file_path = GetPath();
1081 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1082 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1083 if (!login_db->Init(login_db_file_path)) {
1084 LOG(ERROR) << "Could not initialize login database.";
1085 delete login_db;
1086 return;
1087 }
1088 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161089#elif defined(OS_POSIX)
1090 // TODO(evanm): implement "native" password management.
1091 // This bug describes the issues.
1092 // http://code.google.com/p/chromium/issues/detail?id=12351
1093 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1094 if (!ps->Init())
1095 return;
[email protected]e69d33952009-06-03 22:00:411096#else
1097 NOTIMPLEMENTED();
1098#endif
1099 if (!ps || !ps->Init()) {
1100 // Try falling back to the default password manager
1101 LOG(WARNING) << "Could not initialise native password manager - "
1102 "falling back to default";
1103 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1104 if (!ps->Init())
1105 return;
1106 }
1107 password_store_.swap(ps);
1108}
1109
initial.commit09911bf2008-07-26 23:55:291110DownloadManager* ProfileImpl::GetDownloadManager() {
1111 if (!created_download_manager_) {
1112 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1113 dlm->Init(this);
1114 created_download_manager_ = true;
1115 download_manager_.swap(dlm);
1116 }
1117 return download_manager_.get();
1118}
1119
1120bool ProfileImpl::HasCreatedDownloadManager() const {
1121 return created_download_manager_;
1122}
1123
[email protected]def11712009-11-06 00:42:151124PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1125 if (!personal_data_manager_.get()) {
[email protected]2609bc12010-01-24 08:32:551126 personal_data_manager_.reset(new PersonalDataManager(this));
[email protected]def11712009-11-06 00:42:151127 }
1128 return personal_data_manager_.get();
1129}
1130
[email protected]4a190632009-05-09 01:07:421131void ProfileImpl::InitThemes() {
1132 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161133#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151134 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291135#else
[email protected]761962c2009-09-25 00:18:151136 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291137#endif
[email protected]761962c2009-09-25 00:18:151138 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421139 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421140 }
1141}
1142
1143void ProfileImpl::SetTheme(Extension* extension) {
1144 InitThemes();
1145 theme_provider_.get()->SetTheme(extension);
1146}
1147
[email protected]a5166af62009-07-03 00:42:291148void ProfileImpl::SetNativeTheme() {
1149 InitThemes();
1150 theme_provider_.get()->SetNativeTheme();
1151}
1152
[email protected]4a190632009-05-09 01:07:421153void ProfileImpl::ClearTheme() {
1154 InitThemes();
1155 theme_provider_.get()->UseDefaultTheme();
1156}
1157
[email protected]51c490b2009-08-03 16:34:341158Extension* ProfileImpl::GetTheme() {
1159 InitThemes();
1160
1161 std::string id = theme_provider_.get()->GetThemeID();
1162 if (id == BrowserThemeProvider::kDefaultThemeID)
1163 return NULL;
1164
[email protected]61b411612009-11-10 23:17:411165 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341166}
1167
[email protected]5786d3d2009-12-18 00:18:441168BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421169 InitThemes();
1170 return theme_provider_.get();
1171}
1172
initial.commit09911bf2008-07-26 23:55:291173SessionService* ProfileImpl::GetSessionService() {
1174 if (!session_service_.get() && !shutdown_session_service_) {
1175 session_service_ = new SessionService(this);
1176 session_service_->ResetFromCurrentBrowsers();
1177 }
1178 return session_service_.get();
1179}
1180
1181void ProfileImpl::ShutdownSessionService() {
1182 if (shutdown_session_service_)
1183 return;
1184
1185 // We're about to exit, force creation of the session service if it hasn't
1186 // been created yet. We do this to ensure session state matches the point in
1187 // time the user exited.
1188 GetSessionService();
1189 shutdown_session_service_ = true;
1190 session_service_ = NULL;
1191}
1192
1193bool ProfileImpl::HasSessionService() const {
1194 return (session_service_.get() != NULL);
1195}
1196
initial.commit09911bf2008-07-26 23:55:291197bool ProfileImpl::DidLastSessionExitCleanly() {
1198 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1199 // it to be set by asking for the prefs.
1200 GetPrefs();
1201 return last_session_exited_cleanly_;
1202}
1203
[email protected]d8e41ed2008-09-11 15:22:321204BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461205 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321206 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461207 bookmark_bar_model_->Load();
1208 }
initial.commit09911bf2008-07-26 23:55:291209 return bookmark_bar_model_.get();
1210}
1211
1212bool ProfileImpl::IsSameProfile(Profile* profile) {
1213 if (profile == static_cast<Profile*>(this))
1214 return true;
1215 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1216 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1217}
1218
1219Time ProfileImpl::GetStartTime() const {
1220 return start_time_;
1221}
1222
1223TabRestoreService* ProfileImpl::GetTabRestoreService() {
1224 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191225 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291226 return tab_restore_service_.get();
1227}
1228
[email protected]449478302009-06-09 20:04:281229ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1230 if (!thumbnail_store_.get()) {
1231 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251232 thumbnail_store_->Init(
1233 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281234 }
1235 return thumbnail_store_.get();
1236}
1237
initial.commit09911bf2008-07-26 23:55:291238void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191239 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291240}
1241
[email protected]85c55dc2009-11-06 03:05:461242SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1243 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1244}
1245
1246void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1247 // If we are already loading the spellchecker, and this is just a hint to
1248 // load the spellchecker, do nothing.
1249 if (!force && spellcheck_host_.get())
1250 return;
1251
[email protected]f41301e2009-11-16 21:30:071252 spellcheck_host_ready_ = false;
1253
[email protected]85c55dc2009-11-06 03:05:461254 bool notify = false;
1255 if (spellcheck_host_.get()) {
1256 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051257 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461258 notify = true;
1259 }
1260
1261 PrefService* prefs = GetPrefs();
1262 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1263 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1264 spellcheck_host_ = new SpellCheckHost(this,
1265 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1266 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071267 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461268 } else if (notify) {
1269 // The spellchecker has been disabled.
1270 SpellCheckHostInitialized();
1271 }
1272}
1273
1274void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171275 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291276 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1277 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461278 NotificationService::current()->Notify(
1279 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1280 Source<Profile>(this), NotificationService::NoDetails());
1281}
initial.commit09911bf2008-07-26 23:55:291282
[email protected]3bf335a2009-06-26 20:46:061283WebKitContext* ProfileImpl::GetWebKitContext() {
1284 if (!webkit_context_.get())
1285 webkit_context_ = new WebKitContext(path_, false);
1286 DCHECK(webkit_context_.get());
1287 return webkit_context_.get();
1288}
1289
[email protected]4bb336302009-10-12 05:44:261290DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1291 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1292 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261293 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031294 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261295 }
[email protected]4bb336302009-10-12 05:44:261296 return desktop_notification_service_.get();
1297}
1298
initial.commit09911bf2008-07-26 23:55:291299void ProfileImpl::MarkAsCleanShutdown() {
1300 if (prefs_.get()) {
1301 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1302 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1303
1304 // NOTE: If you change what thread this writes on, be sure and update
1305 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361306 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291307 }
1308}
1309
[email protected]e7244d82008-10-29 18:13:261310void ProfileImpl::Observe(NotificationType type,
1311 const NotificationSource& source,
1312 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561313 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261314 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1315 PrefService* prefs = Source<PrefService>(source).ptr();
1316 DCHECK(pref_name_in && prefs);
1317 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461318 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461319 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291320 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1321 NotificationService::current()->Notify(
1322 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1323 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261324 }
[email protected]4a190632009-05-09 01:07:421325 } else if (NotificationType::THEME_INSTALLED == type) {
1326 Extension* extension = Details<Extension>(details).ptr();
1327 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111328 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1329 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1330 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1331 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261332 }
1333}
1334
initial.commit09911bf2008-07-26 23:55:291335void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141336 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291337}
[email protected]3a453fa2008-08-15 18:46:341338
[email protected]48352c12009-08-15 01:19:111339ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431340 if (!ProfileSyncService::IsSyncEnabled()) {
1341 return NULL;
[email protected]7367f1a2009-10-10 01:09:441342 }
[email protected]eec3bcfa2009-11-12 17:23:431343 if (!sync_service_.get())
1344 InitSyncService();
1345 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111346}
1347
1348void ProfileImpl::InitSyncService() {
[email protected]4aea04a2010-02-10 20:13:431349 profile_sync_factory_.reset(
1350 new ProfileSyncFactoryImpl(this,
1351 CommandLine::ForCurrentProcess()));
1352 sync_service_.reset(
1353 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111354 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111355}