blob: f5223604a030896f1495ab0713fcf39afc329f30 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/profile.h"
6
[email protected]2735e3692009-09-25 18:19:397#include "app/theme_provider.h"
initial.commit09911bf2008-07-26 23:55:298#include "base/command_line.h"
[email protected]04fba9a92008-10-28 17:25:259#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4410#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/path_service.h"
12#include "base/scoped_ptr.h"
13#include "base/string_util.h"
[email protected]def11712009-11-06 00:42:1514#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4215#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2916#include "chrome/browser/browser_list.h"
[email protected]67a46b7f2009-06-16 21:41:0217#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3718#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4219#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5620#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0721#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3722#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0523#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2524#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3525#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4826#include "chrome/browser/favicon_service.h"
[email protected]77f6fb432009-09-05 14:21:0927#include "chrome/browser/strict_transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4228#include "chrome/browser/history/history.h"
[email protected]3bf335a2009-06-26 20:46:0629#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5030#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4231#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2632#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4133#include "chrome/browser/password_manager/password_store_default.h"
[email protected]588074f2009-10-29 09:40:1034#include "chrome/browser/privacy_blacklist/blacklist_io.h"
initial.commit09911bf2008-07-26 23:55:2935#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2636#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]90085af02009-10-29 17:53:2137#include "chrome/browser/search_versus_navigate_classifier.h"
[email protected]1132436e2009-04-08 20:06:3338#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4639#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4440#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3041#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3342#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1143#include "chrome/browser/sync/profile_sync_service.h"
[email protected]449478302009-06-09 20:04:2844#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3946#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2947#include "chrome/browser/webdata/web_data_service.h"
[email protected]23f1ef12009-09-01 22:30:3048#include "chrome/common/appcache/chrome_appcache_service.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/common/chrome_constants.h"
50#include "chrome/common/chrome_paths.h"
51#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5852#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2953#include "chrome/common/notification_service.h"
54#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3255#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5856#include "grit/locale_settings.h"
[email protected]77f6fb432009-09-05 14:21:0957#include "net/base/strict_transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3458#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2959
[email protected]a5166af62009-07-03 00:42:2960#if defined(OS_LINUX)
61#include "chrome/browser/gtk/gtk_theme_provider.h"
62#endif
63
[email protected]2627431b2009-09-15 20:21:5364#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:2965#include "chrome/browser/chromeos/preferences.h"
[email protected]2627431b2009-09-15 20:21:5366#endif
67
[email protected]e1acf6f2008-10-27 20:43:3368using base::Time;
69using base::TimeDelta;
70
[email protected]e5642992009-06-26 23:06:3171namespace {
72
initial.commit09911bf2008-07-26 23:55:2973// Delay, in milliseconds, before we explicitly create the SessionService.
74static const int kCreateSessionServiceDelayMS = 500;
75
[email protected]e5642992009-06-26 23:06:3176enum ContextType {
77 kNormalContext,
78 kMediaContext
79};
80
81// Gets the cache parameters from the command line. |type| is the type of
82// request context that we need, |cache_path| will be set to the user provided
83// path, or will not be touched if there is not an argument. |max_size| will
84// be the user provided value or zero by default.
85void GetCacheParameters(ContextType type, FilePath* cache_path,
86 int* max_size) {
87 DCHECK(cache_path);
88 DCHECK(max_size);
89
90 // Override the cache location if specified by the user.
91 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
92 switches::kDiskCacheDir));
93
94 if (!user_path.empty()) {
95 *cache_path = FilePath::FromWStringHack(user_path);
96 }
97
[email protected]b7e0a2a2009-10-13 02:07:2598 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
99 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31100 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25101 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31102
103 // By default we let the cache determine the right size.
104 *max_size = 0;
105 if (!StringToInt(value, max_size)) {
106 *max_size = 0;
107 } else if (max_size < 0) {
108 *max_size = 0;
109 }
110}
111
[email protected]405a64b2009-09-16 21:03:44112FilePath GetCachePath(const FilePath& base) {
113 return base.Append(chrome::kCacheDirname);
114}
115
116FilePath GetMediaCachePath(const FilePath& base) {
117 return base.Append(chrome::kMediaCacheDirname);
118}
119
120bool HasACacheSubdir(const FilePath &dir) {
121 return file_util::PathExists(GetCachePath(dir)) ||
122 file_util::PathExists(GetMediaCachePath(dir));
123}
124
[email protected]e5642992009-06-26 23:06:31125} // namespace
126
initial.commit09911bf2008-07-26 23:55:29127// A pointer to the request context for the default profile. See comments on
128// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31129URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29130
[email protected]be180c802009-10-23 06:33:31131static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19132 if (context)
[email protected]47accfd62009-05-14 18:46:21133 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21134}
135
[email protected]34cc84f2009-02-13 10:04:35136// static
[email protected]4bf6afd2009-10-08 14:00:11137const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
138
139// static
initial.commit09911bf2008-07-26 23:55:29140void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55141 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29142 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
143 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12144 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26145 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
146 IDS_SPELLCHECK_DICTIONARY);
147 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58148 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]f93fe782009-02-19 01:26:13149 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
[email protected]a5166af62009-07-03 00:42:29150#if defined(OS_LINUX)
151 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
152#endif
[email protected]51c490b2009-08-03 16:34:34153 prefs->RegisterStringPref(prefs::kCurrentThemeID,
154 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42155 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
156 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
157 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50158 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23159 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29160}
161
[email protected]34cc84f2009-02-13 10:04:35162// static
[email protected]f7011fcb2009-01-28 21:54:32163Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29164 return new ProfileImpl(path);
165}
166
[email protected]34cc84f2009-02-13 10:04:35167// static
[email protected]be180c802009-10-23 06:33:31168URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29169 return default_request_context_;
170}
171
[email protected]e69d33952009-06-03 22:00:41172#if defined(OS_LINUX)
173// Temporarily disabled while we figure some stuff out.
174// http://code.google.com/p/chromium/issues/detail?id=12351
175// #include "chrome/browser/password_manager/password_store_gnome.h"
176// #include "chrome/browser/password_manager/password_store_kwallet.h"
177#elif defined(OS_WIN)
178#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56179#elif defined(OS_MACOSX)
180#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17181#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56182#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41183#endif
initial.commit09911bf2008-07-26 23:55:29184
initial.commit09911bf2008-07-26 23:55:29185////////////////////////////////////////////////////////////////////////////////
186//
187// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42188// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29189//
190////////////////////////////////////////////////////////////////////////////////
191class OffTheRecordProfileImpl : public Profile,
192 public NotificationObserver {
193 public:
194 explicit OffTheRecordProfileImpl(Profile* real_profile)
195 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21196 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29197 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31198 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05199
initial.commit09911bf2008-07-26 23:55:29200 // Register for browser close notifications so we can detect when the last
201 // off-the-record window is closed, in which case we can clean our states
202 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43203 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
204 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29205 }
206
207 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21208 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21209 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29210 }
211
[email protected]4bf6afd2009-10-08 14:00:11212 virtual ProfileId GetRuntimeId() {
213 return reinterpret_cast<ProfileId>(this);
214 }
215
[email protected]f7011fcb2009-01-28 21:54:32216 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29217
218 virtual bool IsOffTheRecord() {
219 return true;
220 }
221
222 virtual Profile* GetOffTheRecordProfile() {
223 return this;
224 }
225
[email protected]860f55492009-03-27 19:50:59226 virtual void DestroyOffTheRecordProfile() {
227 // Suicide is bad!
228 NOTREACHED();
229 }
230
initial.commit09911bf2008-07-26 23:55:29231 virtual Profile* GetOriginalProfile() {
232 return profile_;
233 }
234
[email protected]2f351cb2009-11-09 23:43:34235 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
236 if (!db_tracker_)
237 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
238 return db_tracker_;
239 }
240
initial.commit09911bf2008-07-26 23:55:29241 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49242 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
243 // because we don't want to leak the sites that the user has visited before.
244 return NULL;
initial.commit09911bf2008-07-26 23:55:29245 }
246
[email protected]6014d672008-12-05 00:38:25247 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34248 return NULL;
[email protected]6014d672008-12-05 00:38:25249 }
250
[email protected]0938d3c2009-01-09 20:37:35251 virtual UserScriptMaster* GetUserScriptMaster() {
252 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25253 }
254
[email protected]89ebc7e2009-08-24 22:11:07255 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
256 return NULL;
257 }
258
[email protected]481e1a42009-05-06 20:56:05259 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34260 return NULL;
[email protected]481e1a42009-05-06 20:56:05261 }
262
[email protected]7120f132009-07-20 21:05:37263 virtual ExtensionMessageService* GetExtensionMessageService() {
264 return NULL;
265 }
266
[email protected]34cc84f2009-02-13 10:04:35267 virtual SSLHostState* GetSSLHostState() {
268 if (!ssl_host_state_.get())
269 ssl_host_state_.reset(new SSLHostState());
270
271 DCHECK(ssl_host_state_->CalledOnValidThread());
272 return ssl_host_state_.get();
273 }
274
[email protected]77f6fb432009-09-05 14:21:09275 virtual net::StrictTransportSecurityState* GetStrictTransportSecurityState() {
276 if (!strict_transport_security_state_.get()) {
277 strict_transport_security_state_ =
278 new net::StrictTransportSecurityState();
279 }
[email protected]a9cea7542009-05-20 04:30:23280
[email protected]77f6fb432009-09-05 14:21:09281 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23282 }
283
initial.commit09911bf2008-07-26 23:55:29284 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
285 if (sat == EXPLICIT_ACCESS) {
286 return profile_->GetHistoryService(sat);
287 } else {
288 NOTREACHED() << "This profile is OffTheRecord";
289 return NULL;
290 }
291 }
292
[email protected]0850fa62009-10-08 22:34:29293 virtual HistoryService* GetHistoryServiceWithoutCreating() {
294 return profile_->GetHistoryServiceWithoutCreating();
295 }
296
[email protected]0189bc722009-08-28 21:56:48297 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
298 if (sat == EXPLICIT_ACCESS) {
299 return profile_->GetFaviconService(sat);
300 } else {
301 NOTREACHED() << "This profile is OffTheRecord";
302 return NULL;
303 }
304 }
305
[email protected]90085af02009-10-29 17:53:21306 virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
307 return profile_->GetSearchVersusNavigateClassifier();
308 }
309
initial.commit09911bf2008-07-26 23:55:29310 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
311 if (sat == EXPLICIT_ACCESS) {
312 return profile_->GetWebDataService(sat);
313 } else {
314 NOTREACHED() << "This profile is OffTheRecord";
315 return NULL;
316 }
317 }
318
[email protected]9cddbe372009-10-23 21:23:53319 virtual WebDataService* GetWebDataServiceWithoutCreating() {
320 return profile_->GetWebDataServiceWithoutCreating();
321 }
322
[email protected]e69d33952009-06-03 22:00:41323 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
324 if (sat == EXPLICIT_ACCESS) {
325 return profile_->GetPasswordStore(sat);
326 } else {
327 NOTREACHED() << "This profile is OffTheRecord";
328 return NULL;
329 }
330 }
331
initial.commit09911bf2008-07-26 23:55:29332 virtual PrefService* GetPrefs() {
333 return profile_->GetPrefs();
334 }
335
336 virtual TemplateURLModel* GetTemplateURLModel() {
337 return profile_->GetTemplateURLModel();
338 }
339
340 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
341 return profile_->GetTemplateURLFetcher();
342 }
343
344 virtual DownloadManager* GetDownloadManager() {
345 if (!download_manager_.get()) {
346 scoped_refptr<DownloadManager> dlm(new DownloadManager);
347 dlm->Init(this);
348 download_manager_.swap(dlm);
349 }
350 return download_manager_.get();
351 }
352
353 virtual bool HasCreatedDownloadManager() const {
354 return (download_manager_.get() != NULL);
355 }
356
[email protected]def11712009-11-06 00:42:15357 virtual PersonalDataManager* GetPersonalDataManager() {
358 return NULL;
359 }
360
[email protected]4a190632009-05-09 01:07:42361 virtual void InitThemes() {
362 GetOriginalProfile()->InitThemes();
363 }
364
365 virtual void SetTheme(Extension* extension) {
366 GetOriginalProfile()->SetTheme(extension);
367 }
368
[email protected]a5166af62009-07-03 00:42:29369 virtual void SetNativeTheme() {
370 GetOriginalProfile()->SetNativeTheme();
371 }
372
[email protected]4a190632009-05-09 01:07:42373 virtual void ClearTheme() {
374 GetOriginalProfile()->ClearTheme();
375 }
376
[email protected]51c490b2009-08-03 16:34:34377 virtual Extension* GetTheme() {
378 return GetOriginalProfile()->GetTheme();
379 }
380
[email protected]4a190632009-05-09 01:07:42381 virtual ThemeProvider* GetThemeProvider() {
382 return GetOriginalProfile()->GetThemeProvider();
383 }
384
[email protected]be180c802009-10-23 06:33:31385 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29386 return request_context_;
387 }
388
[email protected]be180c802009-10-23 06:33:31389 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11390 // In OTR mode, media request context is the same as the original one.
391 return request_context_;
[email protected]e7f29642009-03-02 22:53:18392 }
393
[email protected]be180c802009-10-23 06:33:31394 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21395 if (!extensions_request_context_) {
396 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31397 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this);
[email protected]47accfd62009-05-14 18:46:21398 }
399
400 return extensions_request_context_;
401 }
402
[email protected]db36938c2009-08-19 21:48:42403 virtual net::SSLConfigService* GetSSLConfigService() {
404 return GetOriginalProfile()->GetSSLConfigService();
405 }
406
[email protected]eaadd9052009-06-23 18:02:23407 virtual Blacklist* GetBlacklist() {
408 return GetOriginalProfile()->GetBlacklist();
409 }
410
initial.commit09911bf2008-07-26 23:55:29411 virtual SessionService* GetSessionService() {
412 // Don't save any sessions when off the record.
413 return NULL;
414 }
415
416 virtual void ShutdownSessionService() {
417 // We don't allow a session service, nothing to do.
418 }
419
420 virtual bool HasSessionService() const {
421 // We never have a session service.
422 return false;
423 }
424
425 virtual std::wstring GetName() {
426 return profile_->GetName();
427 }
428
429 virtual void SetName(const std::wstring& name) {
430 profile_->SetName(name);
431 }
432
433 virtual std::wstring GetID() {
434 return profile_->GetID();
435 }
436
437 virtual void SetID(const std::wstring& id) {
438 profile_->SetID(id);
439 }
440
initial.commit09911bf2008-07-26 23:55:29441 virtual bool DidLastSessionExitCleanly() {
442 return profile_->DidLastSessionExitCleanly();
443 }
444
[email protected]d8e41ed2008-09-11 15:22:32445 virtual BookmarkModel* GetBookmarkModel() {
446 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29447 }
448
[email protected]4bb336302009-10-12 05:44:26449 virtual DesktopNotificationService* GetDesktopNotificationService() {
450 return profile_->GetDesktopNotificationService();
451 }
452
[email protected]48352c12009-08-15 01:19:11453 virtual ProfileSyncService* GetProfileSyncService() {
454 return NULL;
[email protected]3a453fa2008-08-15 18:46:34455 }
[email protected]3a453fa2008-08-15 18:46:34456
initial.commit09911bf2008-07-26 23:55:29457 virtual bool IsSameProfile(Profile* profile) {
458 if (profile == static_cast<Profile*>(this))
459 return true;
460 return profile == profile_;
461 }
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())
484 webkit_context_ = new WebKitContext(GetPath(), true);
485 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
[email protected]13c30922009-11-19 03:43:19539 scoped_refptr<ChromeURLRequestContextGetter> extensions_request_context_;
[email protected]23f1ef12009-09-01 22:30:30540
initial.commit09911bf2008-07-26 23:55:29541 // The download manager that only stores downloaded items in memory.
542 scoped_refptr<DownloadManager> download_manager_;
543
[email protected]3bf335a2009-06-26 20:46:06544 // Use a special WebKit context for OTR browsing.
545 scoped_refptr<WebKitContext> webkit_context_;
546
[email protected]34cc84f2009-02-13 10:04:35547 // We don't want SSLHostState from the OTR profile to leak back to the main
548 // profile because then the main profile would learn some of the host names
549 // the user visited while OTR.
550 scoped_ptr<SSLHostState> ssl_host_state_;
551
[email protected]77f6fb432009-09-05 14:21:09552 // The StrictTransportSecurityState that only stores enabled sites in memory.
553 scoped_refptr<net::StrictTransportSecurityState>
554 strict_transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23555
initial.commit09911bf2008-07-26 23:55:29556 // Time we were started.
557 Time start_time_;
558
[email protected]2f351cb2009-11-09 23:43:34559 // The main database tracker for this profile.
560 // Should be used only on the file thread.
561 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
562
[email protected]90085af02009-10-29 17:53:21563 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29564};
565
[email protected]f7011fcb2009-01-28 21:54:32566ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29567 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39568 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07569 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32570 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57571 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21572 extensions_request_context_(NULL),
[email protected]eaadd9052009-06-23 18:02:23573 blacklist_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32574 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48575 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32576 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41577 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32578 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42579 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32580 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46581 spellcheck_host_(NULL),
582 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29583 shutdown_session_service_(false) {
584 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
585 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14586 create_session_service_timer_.Start(
587 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
588 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54589
[email protected]89ebc7e2009-08-24 22:11:07590 if (CommandLine::ForCurrentProcess()->HasSwitch(
591 switches::kEnableExtensionTimelineApi)) {
592 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
593 }
594
[email protected]382a0702009-06-26 17:12:27595 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37596 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27597
[email protected]e7244d82008-10-29 18:13:26598 PrefService* prefs = GetPrefs();
599 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
600 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58601 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58602
[email protected]eaadd9052009-06-23 18:02:23603 if (CommandLine::ForCurrentProcess()->
604 HasSwitch(switches::kPrivacyBlacklist)) {
605 std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue(
606 switches::kPrivacyBlacklist);
607#if defined(OS_POSIX)
608 FilePath path(WideToUTF8(option));
609#else
610 FilePath path(option);
611#endif
[email protected]588074f2009-10-29 09:40:10612 blacklist_.reset(new Blacklist);
613 // TODO(phajdan.jr): Handle errors when reading blacklist.
614 BlacklistIO::ReadBinary(blacklist_.get(), path);
[email protected]eaadd9052009-06-23 18:02:23615 }
616
[email protected]405a64b2009-09-16 21:03:44617#if defined(OS_MACOSX)
618 // If the profile directory doesn't already have a cache directory and it
619 // is under ~/Library/Application Support, use a suitable cache directory
620 // under ~/Library/Caches. For example, a profile directory of
621 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
622 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
623 // ~/Library/Caches/Google/Chrome/MyProfileName.
624 //
625 // TODO(akalin): Come up with unit tests for this.
626 // TODO(akalin): Use for Linux, too?
627 if (!HasACacheSubdir(path_)) {
628 FilePath app_data_path, user_cache_path;
629 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
630 PathService::Get(base::DIR_CACHE, &user_cache_path) &&
631 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
632 base_cache_path_ = user_cache_path;
633 }
634 }
635#else
[email protected]bc96d562009-08-11 18:45:13636 if (!PathService::IsOverridden(chrome::DIR_USER_DATA))
637 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_);
[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
initial.commit09911bf2008-07-26 23:55:29656}
657
[email protected]bdbc87c2009-01-25 05:08:54658void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41659 if (user_script_master_ || extensions_service_)
660 return; // Already initialized.
661
[email protected]bdbc87c2009-01-25 05:08:54662 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]f93fe782009-02-19 01:26:13663 PrefService* prefs = GetPrefs();
[email protected]bdbc87c2009-01-25 05:08:54664 bool user_scripts_enabled =
[email protected]f0a51fb52009-03-05 12:46:38665 command_line->HasSwitch(switches::kEnableUserScripts) ||
[email protected]f93fe782009-02-19 01:26:13666 prefs->GetBoolean(prefs::kEnableUserScripts);
[email protected]bdbc87c2009-01-25 05:08:54667
[email protected]f7011fcb2009-01-28 21:54:32668 FilePath script_dir;
[email protected]bdbc87c2009-01-25 05:08:54669 if (user_scripts_enabled) {
[email protected]0cd957b2009-03-06 20:13:23670 if (command_line->HasSwitch(switches::kUserScriptsDir)) {
671 std::wstring path_string =
672 command_line->GetSwitchValue(switches::kUserScriptsDir);
673 script_dir = FilePath::FromWStringHack(path_string);
674 } else {
675 script_dir = GetPath();
676 script_dir = script_dir.Append(chrome::kUserScriptsDirname);
677 }
[email protected]bdbc87c2009-01-25 05:08:54678 }
679
[email protected]bb28e062009-02-27 17:19:18680 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]95d29192009-10-30 01:49:06681 user_script_master_ = new UserScriptMaster(script_dir);
[email protected]894bb502009-05-21 22:39:57682 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23683 this,
684 CommandLine::ForCurrentProcess(),
685 GetPrefs(),
686 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36687 true);
[email protected]bdbc87c2009-01-25 05:08:54688
[email protected]9197f3b2009-06-02 00:49:27689 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12690
691 // Load any extensions specified with --load-extension.
692 if (command_line->HasSwitch(switches::kLoadExtension)) {
693 std::wstring path_string =
694 command_line->GetSwitchValue(switches::kLoadExtension);
695 FilePath path = FilePath::FromWStringHack(path_string);
696 extensions_service_->LoadExtension(path);
697
698 // Tell UserScriptMaser to watch this extension's directory for changes so
699 // you can live edit content scripts during development.
700 user_script_master_->AddWatchedPath(path);
701 }
[email protected]bdbc87c2009-01-25 05:08:54702}
703
[email protected]ea0c98cf2009-06-18 23:02:54704void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07705 if (web_resource_service_)
706 return; // Already initialized.
707
[email protected]6fad2632009-11-02 05:59:37708 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54709 web_resource_service_->StartAfterDelay();
710}
711
[email protected]9c8dd902009-11-19 17:50:42712NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
713 if (!ntp_resource_cache_.get())
714 ntp_resource_cache_.reset(new NTPResourceCache(this));
715 return ntp_resource_cache_.get();
716}
717
initial.commit09911bf2008-07-26 23:55:29718ProfileImpl::~ProfileImpl() {
[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]eaadd9052009-06-23 18:02:23773 // When the request contexts are gone, the blacklist wont be needed anymore.
[email protected]588074f2009-10-29 09:40:10774 blacklist_.reset();
[email protected]eaadd9052009-06-23 18:02:23775
[email protected]d8e41ed2008-09-11 15:22:32776 // HistoryService may call into the BookmarkModel, as such we need to
777 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46778 // HistoryService will join with HistoryService's backend thread so that
779 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32780 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46781 history_service_ = NULL;
782 bookmark_bar_model_.reset();
783
[email protected]0189bc722009-08-28 21:56:48784 // FaviconService depends on HistoryServce so make sure we delete
785 // HistoryService first.
786 favicon_service_ = NULL;
787
[email protected]7120f132009-07-20 21:05:37788 extension_message_service_->ProfileDestroyed();
789
[email protected]6ef635e42009-07-26 06:16:12790 if (extensions_service_)
791 extensions_service_->ProfileDestroyed();
792
[email protected]66da08b2009-10-19 22:27:00793 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29794 MarkAsCleanShutdown();
795}
796
[email protected]4bf6afd2009-10-08 14:00:11797ProfileId ProfileImpl::GetRuntimeId() {
798 return reinterpret_cast<ProfileId>(this);
799}
800
[email protected]f7011fcb2009-01-28 21:54:32801FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29802 return path_;
803}
804
805bool ProfileImpl::IsOffTheRecord() {
806 return false;
807}
808
809Profile* ProfileImpl::GetOffTheRecordProfile() {
810 if (!off_the_record_profile_.get()) {
811 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
812 off_the_record_profile_.swap(p);
813 }
814 return off_the_record_profile_.get();
815}
816
[email protected]860f55492009-03-27 19:50:59817void ProfileImpl::DestroyOffTheRecordProfile() {
818 off_the_record_profile_.reset();
819}
820
initial.commit09911bf2008-07-26 23:55:29821Profile* ProfileImpl::GetOriginalProfile() {
822 return this;
823}
824
[email protected]2f351cb2009-11-09 23:43:34825webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
826 if (!db_tracker_)
827 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
828 return db_tracker_;
829}
830
initial.commit09911bf2008-07-26 23:55:29831VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
832 if (!visited_link_master_.get()) {
833 scoped_ptr<VisitedLinkMaster> visited_links(
[email protected]6fad2632009-11-02 05:59:37834 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29835 if (!visited_links->Init())
836 return NULL;
837 visited_link_master_.swap(visited_links);
838 }
839
840 return visited_link_master_.get();
841}
842
[email protected]6014d672008-12-05 00:38:25843ExtensionsService* ProfileImpl::GetExtensionsService() {
844 return extensions_service_.get();
845}
846
[email protected]0938d3c2009-01-09 20:37:35847UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35848 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25849}
850
[email protected]89ebc7e2009-08-24 22:11:07851ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
852 return extension_devtools_manager_.get();
853}
854
[email protected]481e1a42009-05-06 20:56:05855ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27856 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05857}
858
[email protected]7120f132009-07-20 21:05:37859ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
860 return extension_message_service_.get();
861}
862
[email protected]34cc84f2009-02-13 10:04:35863SSLHostState* ProfileImpl::GetSSLHostState() {
864 if (!ssl_host_state_.get())
865 ssl_host_state_.reset(new SSLHostState());
866
867 DCHECK(ssl_host_state_->CalledOnValidThread());
868 return ssl_host_state_.get();
869}
870
[email protected]77f6fb432009-09-05 14:21:09871net::StrictTransportSecurityState*
872 ProfileImpl::GetStrictTransportSecurityState() {
873 if (!strict_transport_security_state_.get()) {
874 strict_transport_security_state_ = new net::StrictTransportSecurityState();
[email protected]0c03b432009-11-17 21:41:08875 strict_transport_security_persister_ =
876 new StrictTransportSecurityPersister();
877 strict_transport_security_persister_->Initialize(
[email protected]6fad2632009-11-02 05:59:37878 strict_transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51879 }
[email protected]a9cea7542009-05-20 04:30:23880
[email protected]77f6fb432009-09-05 14:21:09881 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23882}
883
initial.commit09911bf2008-07-26 23:55:29884PrefService* ProfileImpl::GetPrefs() {
885 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37886 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29887
888 // The Profile class and ProfileManager class may read some prefs so
889 // register known prefs as soon as possible.
890 Profile::RegisterUserPrefs(prefs_.get());
891 ProfileManager::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53892#if defined(OS_CHROMEOS)
893 // Register Touchpad prefs here instead of in browser_prefs because these
894 // prefs are used in the constructor of ProfileImpl which happens before
895 // browser_prefs' RegisterAllPrefs is called.
[email protected]fecc1522009-10-15 21:08:29896 chromeos::Preferences::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53897#endif
initial.commit09911bf2008-07-26 23:55:29898
899 // The last session exited cleanly if there is no pref for
900 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
901 last_session_exited_cleanly_ =
902 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
903 // Mark the session as open.
904 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
905 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36906 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29907 }
908
909 return prefs_.get();
910}
911
[email protected]f7011fcb2009-01-28 21:54:32912FilePath ProfileImpl::GetPrefFilePath() {
913 FilePath pref_file_path = path_;
914 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29915 return pref_file_path;
916}
917
[email protected]be180c802009-10-23 06:33:31918URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29919 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32920 FilePath cookie_path = GetPath();
921 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13922 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31923 int max_size;
924 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42925
[email protected]405a64b2009-09-16 21:03:44926 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31927 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
928 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29929
[email protected]6ab9b202008-12-23 22:34:50930 // The first request context is always a normal (non-OTR) request context.
931 // Even when Chromium is started in OTR mode, a normal profile is always
932 // created first.
933 if (!default_request_context_) {
934 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31935 // TODO(eroman): this isn't terribly useful anymore now that the
936 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50937 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56938 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50939 NotificationService::AllSources(), NotificationService::NoDetails());
940 }
initial.commit09911bf2008-07-26 23:55:29941 }
942
943 return request_context_;
944}
945
[email protected]be180c802009-10-23 06:33:31946URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18947 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13948 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31949 int max_size;
950 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14951
[email protected]405a64b2009-09-16 21:03:44952 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31953 media_request_context_ =
954 ChromeURLRequestContextGetter::CreateOriginalForMedia(
955 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18956 }
957
958 return media_request_context_;
959}
960
[email protected]0189bc722009-08-28 21:56:48961FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
962 if (!favicon_service_created_) {
963 favicon_service_created_ = true;
964 scoped_refptr<FaviconService> service(new FaviconService(this));
965 favicon_service_.swap(service);
966 }
967 return favicon_service_.get();
968}
969
[email protected]be180c802009-10-23 06:33:31970URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21971 if (!extensions_request_context_) {
972 FilePath cookie_path = GetPath();
973 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
974
975 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31976 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
977 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21978 }
979
980 return extensions_request_context_;
981}
982
[email protected]db36938c2009-08-19 21:48:42983net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
984 return ssl_config_service_manager_->Get();
985}
986
[email protected]eaadd9052009-06-23 18:02:23987Blacklist* ProfileImpl::GetBlacklist() {
[email protected]588074f2009-10-29 09:40:10988 return blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:23989}
990
initial.commit09911bf2008-07-26 23:55:29991HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
992 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:46993 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:29994 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:32995 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:29996 return NULL;
997 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:29998
999 // Send out the notification that the history service was created.
1000 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561001 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291002 Details<HistoryService>(history_service_.get()));
1003 }
1004 return history_service_.get();
1005}
1006
[email protected]0850fa62009-10-08 22:34:291007HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1008 return history_service_.get();
1009}
1010
initial.commit09911bf2008-07-26 23:55:291011TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1012 if (!template_url_model_.get())
1013 template_url_model_.reset(new TemplateURLModel(this));
1014 return template_url_model_.get();
1015}
1016
1017TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1018 if (!template_url_fetcher_.get())
1019 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1020 return template_url_fetcher_.get();
1021}
1022
[email protected]11f4857282009-11-13 19:56:171023SearchVersusNavigateClassifier*
1024ProfileImpl::GetSearchVersusNavigateClassifier() {
[email protected]90085af02009-10-29 17:53:211025 if (!search_versus_navigate_classifier_.get()) {
1026 search_versus_navigate_classifier_.reset(
1027 new SearchVersusNavigateClassifier(this));
1028 }
1029 return search_versus_navigate_classifier_.get();
1030}
1031
initial.commit09911bf2008-07-26 23:55:291032WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1033 if (!created_web_data_service_)
1034 CreateWebDataService();
1035 return web_data_service_.get();
1036}
1037
[email protected]9cddbe372009-10-23 21:23:531038WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1039 return web_data_service_.get();
1040}
1041
initial.commit09911bf2008-07-26 23:55:291042void ProfileImpl::CreateWebDataService() {
1043 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1044 created_web_data_service_ = true;
1045 scoped_refptr<WebDataService> wds(new WebDataService());
1046 if (!wds->Init(GetPath()))
1047 return;
1048 web_data_service_.swap(wds);
1049}
1050
[email protected]e69d33952009-06-03 22:00:411051PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1052 if (!created_password_store_)
1053 CreatePasswordStore();
1054 return password_store_.get();
1055}
1056
1057void ProfileImpl::CreatePasswordStore() {
1058 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1059 created_password_store_ = true;
1060 scoped_refptr<PasswordStore> ps;
1061#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251062 // TODO(evanm): implement "native" password management.
1063 // This bug describes the issues.
1064 // http://code.google.com/p/chromium/issues/detail?id=12351
1065 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1066 if (!ps->Init())
1067 return;
[email protected]e69d33952009-06-03 22:00:411068#elif defined(OS_WIN)
1069 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561070#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171071 FilePath login_db_file_path = GetPath();
1072 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1073 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1074 if (!login_db->Init(login_db_file_path)) {
1075 LOG(ERROR) << "Could not initialize login database.";
1076 delete login_db;
1077 return;
1078 }
1079 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411080#else
1081 NOTIMPLEMENTED();
1082#endif
1083 if (!ps || !ps->Init()) {
1084 // Try falling back to the default password manager
1085 LOG(WARNING) << "Could not initialise native password manager - "
1086 "falling back to default";
1087 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1088 if (!ps->Init())
1089 return;
1090 }
1091 password_store_.swap(ps);
1092}
1093
initial.commit09911bf2008-07-26 23:55:291094DownloadManager* ProfileImpl::GetDownloadManager() {
1095 if (!created_download_manager_) {
1096 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1097 dlm->Init(this);
1098 created_download_manager_ = true;
1099 download_manager_.swap(dlm);
1100 }
1101 return download_manager_.get();
1102}
1103
1104bool ProfileImpl::HasCreatedDownloadManager() const {
1105 return created_download_manager_;
1106}
1107
[email protected]def11712009-11-06 00:42:151108PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1109 if (!personal_data_manager_.get()) {
1110 personal_data_manager_.reset(new PersonalDataManager);
1111 }
1112 return personal_data_manager_.get();
1113}
1114
[email protected]4a190632009-05-09 01:07:421115void ProfileImpl::InitThemes() {
1116 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571117#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151118 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291119#else
[email protected]761962c2009-09-25 00:18:151120 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291121#endif
[email protected]761962c2009-09-25 00:18:151122 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421123 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421124 }
1125}
1126
1127void ProfileImpl::SetTheme(Extension* extension) {
1128 InitThemes();
1129 theme_provider_.get()->SetTheme(extension);
1130}
1131
[email protected]a5166af62009-07-03 00:42:291132void ProfileImpl::SetNativeTheme() {
1133 InitThemes();
1134 theme_provider_.get()->SetNativeTheme();
1135}
1136
[email protected]4a190632009-05-09 01:07:421137void ProfileImpl::ClearTheme() {
1138 InitThemes();
1139 theme_provider_.get()->UseDefaultTheme();
1140}
1141
[email protected]51c490b2009-08-03 16:34:341142Extension* ProfileImpl::GetTheme() {
1143 InitThemes();
1144
1145 std::string id = theme_provider_.get()->GetThemeID();
1146 if (id == BrowserThemeProvider::kDefaultThemeID)
1147 return NULL;
1148
[email protected]61b411612009-11-10 23:17:411149 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341150}
1151
[email protected]4a190632009-05-09 01:07:421152ThemeProvider* ProfileImpl::GetThemeProvider() {
1153 InitThemes();
1154 return theme_provider_.get();
1155}
1156
initial.commit09911bf2008-07-26 23:55:291157SessionService* ProfileImpl::GetSessionService() {
1158 if (!session_service_.get() && !shutdown_session_service_) {
1159 session_service_ = new SessionService(this);
1160 session_service_->ResetFromCurrentBrowsers();
1161 }
1162 return session_service_.get();
1163}
1164
1165void ProfileImpl::ShutdownSessionService() {
1166 if (shutdown_session_service_)
1167 return;
1168
1169 // We're about to exit, force creation of the session service if it hasn't
1170 // been created yet. We do this to ensure session state matches the point in
1171 // time the user exited.
1172 GetSessionService();
1173 shutdown_session_service_ = true;
1174 session_service_ = NULL;
1175}
1176
1177bool ProfileImpl::HasSessionService() const {
1178 return (session_service_.get() != NULL);
1179}
1180
1181std::wstring ProfileImpl::GetName() {
1182 return GetPrefs()->GetString(prefs::kProfileName);
1183}
1184void ProfileImpl::SetName(const std::wstring& name) {
1185 GetPrefs()->SetString(prefs::kProfileName, name);
1186}
1187
1188std::wstring ProfileImpl::GetID() {
1189 return GetPrefs()->GetString(prefs::kProfileID);
1190}
1191void ProfileImpl::SetID(const std::wstring& id) {
1192 GetPrefs()->SetString(prefs::kProfileID, id);
1193}
1194
initial.commit09911bf2008-07-26 23:55:291195bool ProfileImpl::DidLastSessionExitCleanly() {
1196 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1197 // it to be set by asking for the prefs.
1198 GetPrefs();
1199 return last_session_exited_cleanly_;
1200}
1201
[email protected]d8e41ed2008-09-11 15:22:321202BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461203 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321204 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461205 bookmark_bar_model_->Load();
1206 }
initial.commit09911bf2008-07-26 23:55:291207 return bookmark_bar_model_.get();
1208}
1209
1210bool ProfileImpl::IsSameProfile(Profile* profile) {
1211 if (profile == static_cast<Profile*>(this))
1212 return true;
1213 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1214 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1215}
1216
1217Time ProfileImpl::GetStartTime() const {
1218 return start_time_;
1219}
1220
1221TabRestoreService* ProfileImpl::GetTabRestoreService() {
1222 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191223 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291224 return tab_restore_service_.get();
1225}
1226
[email protected]449478302009-06-09 20:04:281227ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1228 if (!thumbnail_store_.get()) {
1229 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251230 thumbnail_store_->Init(
1231 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281232 }
1233 return thumbnail_store_.get();
1234}
1235
initial.commit09911bf2008-07-26 23:55:291236void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191237 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291238}
1239
[email protected]85c55dc2009-11-06 03:05:461240SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1241 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1242}
1243
1244void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1245 // If we are already loading the spellchecker, and this is just a hint to
1246 // load the spellchecker, do nothing.
1247 if (!force && spellcheck_host_.get())
1248 return;
1249
[email protected]f41301e2009-11-16 21:30:071250 spellcheck_host_ready_ = false;
1251
[email protected]85c55dc2009-11-06 03:05:461252 bool notify = false;
1253 if (spellcheck_host_.get()) {
1254 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051255 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461256 notify = true;
1257 }
1258
1259 PrefService* prefs = GetPrefs();
1260 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1261 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1262 spellcheck_host_ = new SpellCheckHost(this,
1263 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1264 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071265 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461266 } else if (notify) {
1267 // The spellchecker has been disabled.
1268 SpellCheckHostInitialized();
1269 }
1270}
1271
1272void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171273 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291274 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1275 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461276 NotificationService::current()->Notify(
1277 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1278 Source<Profile>(this), NotificationService::NoDetails());
1279}
initial.commit09911bf2008-07-26 23:55:291280
[email protected]3bf335a2009-06-26 20:46:061281WebKitContext* ProfileImpl::GetWebKitContext() {
1282 if (!webkit_context_.get())
1283 webkit_context_ = new WebKitContext(path_, false);
1284 DCHECK(webkit_context_.get());
1285 return webkit_context_.get();
1286}
1287
[email protected]4bb336302009-10-12 05:44:261288DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1289 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1290 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261291 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031292 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261293 }
[email protected]4bb336302009-10-12 05:44:261294 return desktop_notification_service_.get();
1295}
1296
initial.commit09911bf2008-07-26 23:55:291297void ProfileImpl::MarkAsCleanShutdown() {
1298 if (prefs_.get()) {
1299 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1300 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1301
1302 // NOTE: If you change what thread this writes on, be sure and update
1303 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361304 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291305 }
1306}
1307
[email protected]e7244d82008-10-29 18:13:261308void ProfileImpl::Observe(NotificationType type,
1309 const NotificationSource& source,
1310 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561311 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261312 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1313 PrefService* prefs = Source<PrefService>(source).ptr();
1314 DCHECK(pref_name_in && prefs);
1315 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461316 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461317 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291318 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1319 NotificationService::current()->Notify(
1320 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1321 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261322 }
[email protected]4a190632009-05-09 01:07:421323 } else if (NotificationType::THEME_INSTALLED == type) {
1324 Extension* extension = Details<Extension>(details).ptr();
1325 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111326 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1327 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1328 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1329 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261330 }
1331}
1332
initial.commit09911bf2008-07-26 23:55:291333void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141334 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291335}
[email protected]3a453fa2008-08-15 18:46:341336
[email protected]48352c12009-08-15 01:19:111337ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431338 if (!ProfileSyncService::IsSyncEnabled()) {
1339 return NULL;
[email protected]7367f1a2009-10-10 01:09:441340 }
[email protected]eec3bcfa2009-11-12 17:23:431341 if (!sync_service_.get())
1342 InitSyncService();
1343 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111344}
1345
1346void ProfileImpl::InitSyncService() {
[email protected]48352c12009-08-15 01:19:111347 sync_service_.reset(new ProfileSyncService(this));
1348 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111349}