blob: 2099e994fe1d89842fe0f19bc34d4479022bfd2d [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]a9afddb2009-02-12 17:49:4214#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2915#include "chrome/browser/browser_list.h"
16#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0217#include "chrome/browser/browser_theme_provider.h"
[email protected]b7f05882009-02-22 01:21:5618#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0719#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3720#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0521#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2522#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3523#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4824#include "chrome/browser/favicon_service.h"
[email protected]77f6fb432009-09-05 14:21:0925#include "chrome/browser/strict_transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4226#include "chrome/browser/history/history.h"
[email protected]3bf335a2009-06-26 20:46:0627#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5028#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4229#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]e69d33952009-06-03 22:00:4130#include "chrome/browser/password_manager/password_store_default.h"
[email protected]eaadd9052009-06-23 18:02:2331#include "chrome/browser/privacy_blacklist/blacklist.h"
initial.commit09911bf2008-07-26 23:55:2932#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2633#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3334#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4635#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4436#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3037#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]f0a644292009-02-25 23:32:4738#include "chrome/browser/spellchecker.h"
[email protected]1132436e2009-04-08 20:06:3339#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1140#include "chrome/browser/sync/profile_sync_service.h"
[email protected]449478302009-06-09 20:04:2841#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3943#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2944#include "chrome/browser/webdata/web_data_service.h"
[email protected]23f1ef12009-09-01 22:30:3045#include "chrome/common/appcache/chrome_appcache_service.h"
initial.commit09911bf2008-07-26 23:55:2946#include "chrome/common/chrome_constants.h"
47#include "chrome/common/chrome_paths.h"
48#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5849#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2950#include "chrome/common/notification_service.h"
51#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3252#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5853#include "grit/locale_settings.h"
[email protected]77f6fb432009-09-05 14:21:0954#include "net/base/strict_transport_security_state.h"
initial.commit09911bf2008-07-26 23:55:2955
[email protected]a5166af62009-07-03 00:42:2956#if defined(OS_LINUX)
[email protected]2a0c0a52009-07-31 07:51:3257#include "net/ocsp/nss_ocsp.h"
[email protected]a5166af62009-07-03 00:42:2958#include "chrome/browser/gtk/gtk_theme_provider.h"
59#endif
60
[email protected]2627431b2009-09-15 20:21:5361#if defined(OS_CHROMEOS)
62#include "chrome/browser/chromeos/touchpad.h"
63#endif
64
[email protected]e1acf6f2008-10-27 20:43:3365using base::Time;
66using base::TimeDelta;
67
[email protected]e5642992009-06-26 23:06:3168namespace {
69
initial.commit09911bf2008-07-26 23:55:2970// Delay, in milliseconds, before we explicitly create the SessionService.
71static const int kCreateSessionServiceDelayMS = 500;
72
[email protected]e5642992009-06-26 23:06:3173enum ContextType {
74 kNormalContext,
75 kMediaContext
76};
77
78// Gets the cache parameters from the command line. |type| is the type of
79// request context that we need, |cache_path| will be set to the user provided
80// path, or will not be touched if there is not an argument. |max_size| will
81// be the user provided value or zero by default.
82void GetCacheParameters(ContextType type, FilePath* cache_path,
83 int* max_size) {
84 DCHECK(cache_path);
85 DCHECK(max_size);
86
87 // Override the cache location if specified by the user.
88 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
89 switches::kDiskCacheDir));
90
91 if (!user_path.empty()) {
92 *cache_path = FilePath::FromWStringHack(user_path);
93 }
94
95 const wchar_t* arg = kNormalContext == type ? switches::kDiskCacheSize :
96 switches::kMediaCacheSize;
97 std::string value =
98 WideToASCII(CommandLine::ForCurrentProcess()->GetSwitchValue(arg));
99
100 // By default we let the cache determine the right size.
101 *max_size = 0;
102 if (!StringToInt(value, max_size)) {
103 *max_size = 0;
104 } else if (max_size < 0) {
105 *max_size = 0;
106 }
107}
108
[email protected]405a64b2009-09-16 21:03:44109FilePath GetCachePath(const FilePath& base) {
110 return base.Append(chrome::kCacheDirname);
111}
112
113FilePath GetMediaCachePath(const FilePath& base) {
114 return base.Append(chrome::kMediaCacheDirname);
115}
116
117bool HasACacheSubdir(const FilePath &dir) {
118 return file_util::PathExists(GetCachePath(dir)) ||
119 file_util::PathExists(GetMediaCachePath(dir));
120}
121
[email protected]e5642992009-06-26 23:06:31122} // namespace
123
initial.commit09911bf2008-07-26 23:55:29124// A pointer to the request context for the default profile. See comments on
125// Profile::GetDefaultRequestContext.
126URLRequestContext* Profile::default_request_context_;
127
[email protected]47accfd62009-05-14 18:46:21128static void CleanupRequestContext(ChromeURLRequestContext* context) {
129 if (context) {
130 context->CleanupOnUIThread();
131
132 // Clean up request context on IO thread.
133 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE,
134 context);
135 }
136}
137
[email protected]e2fc3d22009-09-22 19:50:31138static void CleanupAppCacheService(ChromeAppCacheService* appcache_service) {
139 if (appcache_service) {
140 // The I/O thread may be NULL during testing.
141 base::Thread* io_thread = g_browser_process->io_thread();
[email protected]23f1ef12009-09-01 22:30:30142 if (io_thread)
[email protected]e2fc3d22009-09-22 19:50:31143 io_thread->message_loop()->ReleaseSoon(FROM_HERE, appcache_service);
[email protected]23f1ef12009-09-01 22:30:30144 else
[email protected]e2fc3d22009-09-22 19:50:31145 appcache_service->Release();
[email protected]23f1ef12009-09-01 22:30:30146 }
147}
148
[email protected]34cc84f2009-02-13 10:04:35149// static
[email protected]4bf6afd2009-10-08 14:00:11150const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
151
152// static
initial.commit09911bf2008-07-26 23:55:29153void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55154 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29155 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
156 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12157 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26158 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
159 IDS_SPELLCHECK_DICTIONARY);
160 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58161 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]f93fe782009-02-19 01:26:13162 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
[email protected]a5166af62009-07-03 00:42:29163#if defined(OS_LINUX)
164 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
165#endif
[email protected]51c490b2009-08-03 16:34:34166 prefs->RegisterStringPref(prefs::kCurrentThemeID,
167 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42168 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
169 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
170 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50171 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23172 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29173}
174
[email protected]34cc84f2009-02-13 10:04:35175// static
[email protected]f7011fcb2009-01-28 21:54:32176Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29177 return new ProfileImpl(path);
178}
179
[email protected]34cc84f2009-02-13 10:04:35180// static
initial.commit09911bf2008-07-26 23:55:29181URLRequestContext* Profile::GetDefaultRequestContext() {
182 return default_request_context_;
183}
184
[email protected]e69d33952009-06-03 22:00:41185#if defined(OS_LINUX)
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"
190#elif defined(OS_WIN)
191#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56192#elif defined(OS_MACOSX)
193#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17194#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56195#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41196#endif
initial.commit09911bf2008-07-26 23:55:29197
initial.commit09911bf2008-07-26 23:55:29198////////////////////////////////////////////////////////////////////////////////
199//
200// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42201// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29202//
203////////////////////////////////////////////////////////////////////////////////
204class OffTheRecordProfileImpl : public Profile,
205 public NotificationObserver {
206 public:
207 explicit OffTheRecordProfileImpl(Profile* real_profile)
208 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21209 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29210 start_time_(Time::Now()) {
[email protected]e2fc3d22009-09-22 19:50:31211 // Created here but lazily inititialized later, finally released on
212 // on the io thread, see CleanupAppCacheService.
213 appcache_service_ = new ChromeAppCacheService();
214 appcache_service_->AddRef();
215
216 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(
217 this, appcache_service_);
initial.commit09911bf2008-07-26 23:55:29218 request_context_->AddRef();
[email protected]481e1a42009-05-06 20:56:05219
initial.commit09911bf2008-07-26 23:55:29220 // Register for browser close notifications so we can detect when the last
221 // off-the-record window is closed, in which case we can clean our states
222 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43223 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
224 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29225 }
226
227 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21228 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21229 CleanupRequestContext(extensions_request_context_);
[email protected]e2fc3d22009-09-22 19:50:31230 CleanupAppCacheService(appcache_service_);
initial.commit09911bf2008-07-26 23:55:29231 }
232
[email protected]4bf6afd2009-10-08 14:00:11233 virtual ProfileId GetRuntimeId() {
234 return reinterpret_cast<ProfileId>(this);
235 }
236
[email protected]f7011fcb2009-01-28 21:54:32237 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29238
239 virtual bool IsOffTheRecord() {
240 return true;
241 }
242
243 virtual Profile* GetOffTheRecordProfile() {
244 return this;
245 }
246
[email protected]860f55492009-03-27 19:50:59247 virtual void DestroyOffTheRecordProfile() {
248 // Suicide is bad!
249 NOTREACHED();
250 }
251
initial.commit09911bf2008-07-26 23:55:29252 virtual Profile* GetOriginalProfile() {
253 return profile_;
254 }
255
[email protected]23f1ef12009-09-01 22:30:30256 virtual ChromeAppCacheService* GetAppCacheService() {
[email protected]e2fc3d22009-09-22 19:50:31257 DCHECK(request_context_); // should be created in ctor
258 if (!appcache_service_->is_initialized())
259 appcache_service_->InitializeOnUIThread(GetPath(), true);
260 return appcache_service_;
[email protected]23f1ef12009-09-01 22:30:30261 }
262
initial.commit09911bf2008-07-26 23:55:29263 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49264 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
265 // because we don't want to leak the sites that the user has visited before.
266 return NULL;
initial.commit09911bf2008-07-26 23:55:29267 }
268
[email protected]6014d672008-12-05 00:38:25269 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34270 return NULL;
[email protected]6014d672008-12-05 00:38:25271 }
272
[email protected]0938d3c2009-01-09 20:37:35273 virtual UserScriptMaster* GetUserScriptMaster() {
274 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25275 }
276
[email protected]89ebc7e2009-08-24 22:11:07277 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
278 return NULL;
279 }
280
[email protected]481e1a42009-05-06 20:56:05281 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34282 return NULL;
[email protected]481e1a42009-05-06 20:56:05283 }
284
[email protected]7120f132009-07-20 21:05:37285 virtual ExtensionMessageService* GetExtensionMessageService() {
286 return NULL;
287 }
288
[email protected]34cc84f2009-02-13 10:04:35289 virtual SSLHostState* GetSSLHostState() {
290 if (!ssl_host_state_.get())
291 ssl_host_state_.reset(new SSLHostState());
292
293 DCHECK(ssl_host_state_->CalledOnValidThread());
294 return ssl_host_state_.get();
295 }
296
[email protected]77f6fb432009-09-05 14:21:09297 virtual net::StrictTransportSecurityState* GetStrictTransportSecurityState() {
298 if (!strict_transport_security_state_.get()) {
299 strict_transport_security_state_ =
300 new net::StrictTransportSecurityState();
301 }
[email protected]a9cea7542009-05-20 04:30:23302
[email protected]77f6fb432009-09-05 14:21:09303 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23304 }
305
initial.commit09911bf2008-07-26 23:55:29306 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
307 if (sat == EXPLICIT_ACCESS) {
308 return profile_->GetHistoryService(sat);
309 } else {
310 NOTREACHED() << "This profile is OffTheRecord";
311 return NULL;
312 }
313 }
314
[email protected]0189bc722009-08-28 21:56:48315 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
316 if (sat == EXPLICIT_ACCESS) {
317 return profile_->GetFaviconService(sat);
318 } else {
319 NOTREACHED() << "This profile is OffTheRecord";
320 return NULL;
321 }
322 }
323
initial.commit09911bf2008-07-26 23:55:29324 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
325 if (sat == EXPLICIT_ACCESS) {
326 return profile_->GetWebDataService(sat);
327 } else {
328 NOTREACHED() << "This profile is OffTheRecord";
329 return NULL;
330 }
331 }
332
[email protected]e69d33952009-06-03 22:00:41333 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
334 if (sat == EXPLICIT_ACCESS) {
335 return profile_->GetPasswordStore(sat);
336 } else {
337 NOTREACHED() << "This profile is OffTheRecord";
338 return NULL;
339 }
340 }
341
initial.commit09911bf2008-07-26 23:55:29342 virtual PrefService* GetPrefs() {
343 return profile_->GetPrefs();
344 }
345
346 virtual TemplateURLModel* GetTemplateURLModel() {
347 return profile_->GetTemplateURLModel();
348 }
349
350 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
351 return profile_->GetTemplateURLFetcher();
352 }
353
354 virtual DownloadManager* GetDownloadManager() {
355 if (!download_manager_.get()) {
356 scoped_refptr<DownloadManager> dlm(new DownloadManager);
357 dlm->Init(this);
358 download_manager_.swap(dlm);
359 }
360 return download_manager_.get();
361 }
362
363 virtual bool HasCreatedDownloadManager() const {
364 return (download_manager_.get() != NULL);
365 }
366
[email protected]4a190632009-05-09 01:07:42367 virtual void InitThemes() {
368 GetOriginalProfile()->InitThemes();
369 }
370
371 virtual void SetTheme(Extension* extension) {
372 GetOriginalProfile()->SetTheme(extension);
373 }
374
[email protected]a5166af62009-07-03 00:42:29375 virtual void SetNativeTheme() {
376 GetOriginalProfile()->SetNativeTheme();
377 }
378
[email protected]4a190632009-05-09 01:07:42379 virtual void ClearTheme() {
380 GetOriginalProfile()->ClearTheme();
381 }
382
[email protected]51c490b2009-08-03 16:34:34383 virtual Extension* GetTheme() {
384 return GetOriginalProfile()->GetTheme();
385 }
386
[email protected]4a190632009-05-09 01:07:42387 virtual ThemeProvider* GetThemeProvider() {
388 return GetOriginalProfile()->GetThemeProvider();
389 }
390
initial.commit09911bf2008-07-26 23:55:29391 virtual URLRequestContext* GetRequestContext() {
392 return request_context_;
393 }
394
[email protected]e7f29642009-03-02 22:53:18395 virtual URLRequestContext* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11396 // In OTR mode, media request context is the same as the original one.
397 return request_context_;
[email protected]e7f29642009-03-02 22:53:18398 }
399
[email protected]47accfd62009-05-14 18:46:21400 URLRequestContext* GetRequestContextForExtensions() {
401 if (!extensions_request_context_) {
402 extensions_request_context_ =
403 ChromeURLRequestContext::CreateOffTheRecordForExtensions(this);
404 extensions_request_context_->AddRef();
405
406 DCHECK(extensions_request_context_->cookie_store());
407 }
408
409 return extensions_request_context_;
410 }
411
[email protected]db36938c2009-08-19 21:48:42412 virtual net::SSLConfigService* GetSSLConfigService() {
413 return GetOriginalProfile()->GetSSLConfigService();
414 }
415
[email protected]eaadd9052009-06-23 18:02:23416 virtual Blacklist* GetBlacklist() {
417 return GetOriginalProfile()->GetBlacklist();
418 }
419
initial.commit09911bf2008-07-26 23:55:29420 virtual SessionService* GetSessionService() {
421 // Don't save any sessions when off the record.
422 return NULL;
423 }
424
425 virtual void ShutdownSessionService() {
426 // We don't allow a session service, nothing to do.
427 }
428
429 virtual bool HasSessionService() const {
430 // We never have a session service.
431 return false;
432 }
433
434 virtual std::wstring GetName() {
435 return profile_->GetName();
436 }
437
438 virtual void SetName(const std::wstring& name) {
439 profile_->SetName(name);
440 }
441
442 virtual std::wstring GetID() {
443 return profile_->GetID();
444 }
445
446 virtual void SetID(const std::wstring& id) {
447 profile_->SetID(id);
448 }
449
initial.commit09911bf2008-07-26 23:55:29450 virtual bool DidLastSessionExitCleanly() {
451 return profile_->DidLastSessionExitCleanly();
452 }
453
[email protected]d8e41ed2008-09-11 15:22:32454 virtual BookmarkModel* GetBookmarkModel() {
455 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29456 }
457
[email protected]48352c12009-08-15 01:19:11458 virtual ProfileSyncService* GetProfileSyncService() {
459 return NULL;
[email protected]3a453fa2008-08-15 18:46:34460 }
[email protected]3a453fa2008-08-15 18:46:34461
initial.commit09911bf2008-07-26 23:55:29462 virtual bool IsSameProfile(Profile* profile) {
463 if (profile == static_cast<Profile*>(this))
464 return true;
465 return profile == profile_;
466 }
467
468 virtual Time GetStartTime() const {
469 return start_time_;
470 }
471
472 virtual TabRestoreService* GetTabRestoreService() {
473 return NULL;
474 }
475
[email protected]e7244d82008-10-29 18:13:26476 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41477 }
478
[email protected]e7244d82008-10-29 18:13:26479 virtual void ReinitializeSpellChecker() {
480 profile_->ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:29481 }
482
483 virtual SpellChecker* GetSpellChecker() {
484 return profile_->GetSpellChecker();
485 }
486
[email protected]e3448ea2009-10-02 01:29:29487 virtual void DeleteSpellChecker() {
488 profile_->DeleteSpellChecker();
489 }
490
[email protected]3bf335a2009-06-26 20:46:06491 virtual WebKitContext* GetWebKitContext() {
492 if (!webkit_context_.get())
493 webkit_context_ = new WebKitContext(GetPath(), true);
494 DCHECK(webkit_context_.get());
495 return webkit_context_.get();
496}
497
[email protected]449478302009-06-09 20:04:28498 virtual ThumbnailStore* GetThumbnailStore() {
499 return NULL;
500 }
501
initial.commit09911bf2008-07-26 23:55:29502 virtual void MarkAsCleanShutdown() {
503 }
504
[email protected]bdbc87c2009-01-25 05:08:54505 virtual void InitExtensions() {
506 NOTREACHED();
507 }
508
[email protected]ea0c98cf2009-06-18 23:02:54509 virtual void InitWebResources() {
510 NOTREACHED();
511 }
512
initial.commit09911bf2008-07-26 23:55:29513 virtual void ExitedOffTheRecordMode() {
514 // Drop our download manager so we forget about all the downloads made
515 // in off-the-record mode.
516 download_manager_ = NULL;
517 }
518
519 virtual void Observe(NotificationType type,
520 const NotificationSource& source,
521 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56522 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29523 // We are only interested in OTR browser closing.
524 if (Source<Browser>(source)->profile() != this)
525 return;
526
527 // Let's check if we still have an Off The Record window opened.
528 // Note that we check against 1 as this notification is sent before the
529 // browser window is actually removed from the list.
530 if (BrowserList::GetBrowserCount(this) <= 1)
531 ExitedOffTheRecordMode();
532 }
533
534 private:
[email protected]88cf3292009-05-22 01:48:43535 NotificationRegistrar registrar_;
536
initial.commit09911bf2008-07-26 23:55:29537 // The real underlying profile.
538 Profile* profile_;
539
[email protected]6ab9b202008-12-23 22:34:50540 // The context to use for requests made from this OTR session.
541 ChromeURLRequestContext* request_context_;
initial.commit09911bf2008-07-26 23:55:29542
[email protected]47accfd62009-05-14 18:46:21543 ChromeURLRequestContext* extensions_request_context_;
544
[email protected]23f1ef12009-09-01 22:30:30545 // Use a seperate appcache service for OTR.
[email protected]e2fc3d22009-09-22 19:50:31546 ChromeAppCacheService* appcache_service_;
[email protected]23f1ef12009-09-01 22:30:30547
initial.commit09911bf2008-07-26 23:55:29548 // The download manager that only stores downloaded items in memory.
549 scoped_refptr<DownloadManager> download_manager_;
550
[email protected]3bf335a2009-06-26 20:46:06551 // Use a special WebKit context for OTR browsing.
552 scoped_refptr<WebKitContext> webkit_context_;
553
[email protected]34cc84f2009-02-13 10:04:35554 // We don't want SSLHostState from the OTR profile to leak back to the main
555 // profile because then the main profile would learn some of the host names
556 // the user visited while OTR.
557 scoped_ptr<SSLHostState> ssl_host_state_;
558
[email protected]77f6fb432009-09-05 14:21:09559 // The StrictTransportSecurityState that only stores enabled sites in memory.
560 scoped_refptr<net::StrictTransportSecurityState>
561 strict_transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23562
initial.commit09911bf2008-07-26 23:55:29563 // Time we were started.
564 Time start_time_;
565
566 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl);
567};
568
[email protected]f7011fcb2009-01-28 21:54:32569ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29570 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39571 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07572 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32573 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57574 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21575 extensions_request_context_(NULL),
[email protected]eaadd9052009-06-23 18:02:23576 blacklist_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32577 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48578 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32579 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41580 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32581 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42582 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32583 start_time_(Time::Now()),
584 spellchecker_(NULL),
initial.commit09911bf2008-07-26 23:55:29585 shutdown_session_service_(false) {
586 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
587 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14588 create_session_service_timer_.Start(
589 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
590 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54591
[email protected]89ebc7e2009-08-24 22:11:07592 if (CommandLine::ForCurrentProcess()->HasSwitch(
593 switches::kEnableExtensionTimelineApi)) {
594 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
595 }
596
[email protected]e2fc3d22009-09-22 19:50:31597 // Created here but lazily inititialized later, finally released on
598 // on the io thread, see CleanupAppCacheService.
599 appcache_service_ = new ChromeAppCacheService();
600 appcache_service_->AddRef();
601
[email protected]382a0702009-06-26 17:12:27602 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37603 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27604
[email protected]e7244d82008-10-29 18:13:26605 PrefService* prefs = GetPrefs();
606 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
607 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58608 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58609
[email protected]eaadd9052009-06-23 18:02:23610 if (CommandLine::ForCurrentProcess()->
611 HasSwitch(switches::kPrivacyBlacklist)) {
612 std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue(
613 switches::kPrivacyBlacklist);
614#if defined(OS_POSIX)
615 FilePath path(WideToUTF8(option));
616#else
617 FilePath path(option);
618#endif
619 blacklist_ = new Blacklist(path);
620 }
621
[email protected]405a64b2009-09-16 21:03:44622#if defined(OS_MACOSX)
623 // If the profile directory doesn't already have a cache directory and it
624 // is under ~/Library/Application Support, use a suitable cache directory
625 // under ~/Library/Caches. For example, a profile directory of
626 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
627 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
628 // ~/Library/Caches/Google/Chrome/MyProfileName.
629 //
630 // TODO(akalin): Come up with unit tests for this.
631 // TODO(akalin): Use for Linux, too?
632 if (!HasACacheSubdir(path_)) {
633 FilePath app_data_path, user_cache_path;
634 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
635 PathService::Get(base::DIR_CACHE, &user_cache_path) &&
636 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
637 base_cache_path_ = user_cache_path;
638 }
639 }
640#else
[email protected]bc96d562009-08-11 18:45:13641 if (!PathService::IsOverridden(chrome::DIR_USER_DATA))
642 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_);
[email protected]405a64b2009-09-16 21:03:44643#endif
[email protected]bc96d562009-08-11 18:45:13644 if (base_cache_path_.empty())
645 base_cache_path_ = path_;
646
[email protected]4a190632009-05-09 01:07:42647 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43648 registrar_.Add(this, NotificationType::THEME_INSTALLED,
649 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11650
651 // Listen for bookmark model load, to bootstrap the sync service.
652 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
653 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42654
655 ssl_config_service_manager_.reset(
656 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53657
658#if defined(OS_CHROMEOS)
659 touchpad_.Init(prefs);
660#endif
initial.commit09911bf2008-07-26 23:55:29661}
662
[email protected]bdbc87c2009-01-25 05:08:54663void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41664 if (user_script_master_ || extensions_service_)
665 return; // Already initialized.
666
[email protected]bdbc87c2009-01-25 05:08:54667 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]f93fe782009-02-19 01:26:13668 PrefService* prefs = GetPrefs();
[email protected]bdbc87c2009-01-25 05:08:54669 bool user_scripts_enabled =
[email protected]f0a51fb52009-03-05 12:46:38670 command_line->HasSwitch(switches::kEnableUserScripts) ||
[email protected]f93fe782009-02-19 01:26:13671 prefs->GetBoolean(prefs::kEnableUserScripts);
[email protected]bdbc87c2009-01-25 05:08:54672
[email protected]f7011fcb2009-01-28 21:54:32673 FilePath script_dir;
[email protected]bdbc87c2009-01-25 05:08:54674 if (user_scripts_enabled) {
[email protected]0cd957b2009-03-06 20:13:23675 if (command_line->HasSwitch(switches::kUserScriptsDir)) {
676 std::wstring path_string =
677 command_line->GetSwitchValue(switches::kUserScriptsDir);
678 script_dir = FilePath::FromWStringHack(path_string);
679 } else {
680 script_dir = GetPath();
681 script_dir = script_dir.Append(chrome::kUserScriptsDirname);
682 }
[email protected]bdbc87c2009-01-25 05:08:54683 }
684
[email protected]bb28e062009-02-27 17:19:18685 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]bdbc87c2009-01-25 05:08:54686 user_script_master_ = new UserScriptMaster(
[email protected]9197f3b2009-06-02 00:49:27687 g_browser_process->file_thread()->message_loop(),
688 script_dir);
[email protected]894bb502009-05-21 22:39:57689 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23690 this,
691 CommandLine::ForCurrentProcess(),
692 GetPrefs(),
693 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
694 MessageLoop::current(),
[email protected]93fd78f42009-07-10 16:43:17695 g_browser_process->file_thread()->message_loop(),
[email protected]c8b437d2009-07-20 21:26:36696 true);
[email protected]bdbc87c2009-01-25 05:08:54697
[email protected]9197f3b2009-06-02 00:49:27698 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12699
700 // Load any extensions specified with --load-extension.
701 if (command_line->HasSwitch(switches::kLoadExtension)) {
702 std::wstring path_string =
703 command_line->GetSwitchValue(switches::kLoadExtension);
704 FilePath path = FilePath::FromWStringHack(path_string);
705 extensions_service_->LoadExtension(path);
706
707 // Tell UserScriptMaser to watch this extension's directory for changes so
708 // you can live edit content scripts during development.
709 user_script_master_->AddWatchedPath(path);
710 }
[email protected]bdbc87c2009-01-25 05:08:54711}
712
[email protected]ea0c98cf2009-06-18 23:02:54713void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07714 if (web_resource_service_)
715 return; // Already initialized.
716
[email protected]ea0c98cf2009-06-18 23:02:54717 web_resource_service_ = new WebResourceService(
718 this,
719 g_browser_process->file_thread()->message_loop());
720
721 web_resource_service_->StartAfterDelay();
722}
723
initial.commit09911bf2008-07-26 23:55:29724ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19725 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29726
727 StopCreateSessionServiceTimer();
728 // TemplateURLModel schedules a task on the WebDataService from its
729 // destructor. Delete it first to ensure the task gets scheduled before we
730 // shut down the database.
731 template_url_model_.reset();
732
733 // The download manager queries the history system and should be deleted
734 // before the history is shutdown so it can properly cancel all requests.
735 download_manager_ = NULL;
736
[email protected]4a190632009-05-09 01:07:42737 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15738 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42739
[email protected]44961292009-07-20 20:03:09740 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
741 // save any new thumbnails to disk and release its reference to the
742 // HistoryService.
743 if (thumbnail_store_.get())
744 thumbnail_store_->Shutdown();
745
[email protected]e7244d82008-10-29 18:13:26746 // Remove pref observers.
747 PrefService* prefs = GetPrefs();
748 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
749 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58750 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26751
[email protected]3a453fa2008-08-15 18:46:34752#ifdef CHROME_PERSONALIZATION
[email protected]48352c12009-08-15 01:19:11753 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34754#endif
755
initial.commit09911bf2008-07-26 23:55:29756 // Both HistoryService and WebDataService maintain threads for background
757 // processing. Its possible each thread still has tasks on it that have
758 // increased the ref count of the service. In such a situation, when we
759 // decrement the refcount, it won't be 0, and the threads/databases aren't
760 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
761 // databases are properly closed.
762 if (web_data_service_.get())
763 web_data_service_->Shutdown();
764
765 if (history_service_.get())
766 history_service_->Cleanup();
767
[email protected]e3448ea2009-10-02 01:29:29768 DeleteSpellCheckerImpl(false);
initial.commit09911bf2008-07-26 23:55:29769
[email protected]2a0c0a52009-07-31 07:51:32770 if (default_request_context_ == request_context_) {
771#if defined(OS_LINUX)
772 // We use default_request_context_ for OCSP.
773 // Release URLRequestContext used in OCSP handlers.
774 net::SetURLRequestContextForOCSP(NULL);
775#endif
[email protected]47accfd62009-05-14 18:46:21776 default_request_context_ = NULL;
[email protected]2a0c0a52009-07-31 07:51:32777 }
[email protected]6ab9b202008-12-23 22:34:50778
[email protected]47accfd62009-05-14 18:46:21779 CleanupRequestContext(request_context_);
780 CleanupRequestContext(media_request_context_);
781 CleanupRequestContext(extensions_request_context_);
[email protected]e2fc3d22009-09-22 19:50:31782 CleanupAppCacheService(appcache_service_);
[email protected]1e744f22009-04-08 01:00:17783
[email protected]eaadd9052009-06-23 18:02:23784 // When the request contexts are gone, the blacklist wont be needed anymore.
785 delete blacklist_;
786 blacklist_ = 0;
787
[email protected]d8e41ed2008-09-11 15:22:32788 // HistoryService may call into the BookmarkModel, as such we need to
789 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46790 // HistoryService will join with HistoryService's backend thread so that
791 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32792 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46793 history_service_ = NULL;
794 bookmark_bar_model_.reset();
795
[email protected]0189bc722009-08-28 21:56:48796 // FaviconService depends on HistoryServce so make sure we delete
797 // HistoryService first.
798 favicon_service_ = NULL;
799
[email protected]7120f132009-07-20 21:05:37800 extension_message_service_->ProfileDestroyed();
801
[email protected]6ef635e42009-07-26 06:16:12802 if (extensions_service_)
803 extensions_service_->ProfileDestroyed();
804
initial.commit09911bf2008-07-26 23:55:29805 MarkAsCleanShutdown();
806}
807
[email protected]4bf6afd2009-10-08 14:00:11808ProfileId ProfileImpl::GetRuntimeId() {
809 return reinterpret_cast<ProfileId>(this);
810}
811
[email protected]f7011fcb2009-01-28 21:54:32812FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29813 return path_;
814}
815
816bool ProfileImpl::IsOffTheRecord() {
817 return false;
818}
819
820Profile* ProfileImpl::GetOffTheRecordProfile() {
821 if (!off_the_record_profile_.get()) {
822 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
823 off_the_record_profile_.swap(p);
824 }
825 return off_the_record_profile_.get();
826}
827
[email protected]860f55492009-03-27 19:50:59828void ProfileImpl::DestroyOffTheRecordProfile() {
829 off_the_record_profile_.reset();
830}
831
initial.commit09911bf2008-07-26 23:55:29832Profile* ProfileImpl::GetOriginalProfile() {
833 return this;
834}
835
[email protected]23f1ef12009-09-01 22:30:30836ChromeAppCacheService* ProfileImpl::GetAppCacheService() {
[email protected]e2fc3d22009-09-22 19:50:31837 if (!appcache_service_->is_initialized()) {
838 EnsureRequestContextCreated();
839 appcache_service_->InitializeOnUIThread(GetPath(), false);
[email protected]23f1ef12009-09-01 22:30:30840 }
[email protected]e2fc3d22009-09-22 19:50:31841 return appcache_service_;
[email protected]23f1ef12009-09-01 22:30:30842}
843
initial.commit09911bf2008-07-26 23:55:29844VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
845 if (!visited_link_master_.get()) {
846 scoped_ptr<VisitedLinkMaster> visited_links(
847 new VisitedLinkMaster(g_browser_process->file_thread(),
[email protected]3e90d4a2009-07-03 17:38:39848 visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29849 if (!visited_links->Init())
850 return NULL;
851 visited_link_master_.swap(visited_links);
852 }
853
854 return visited_link_master_.get();
855}
856
[email protected]6014d672008-12-05 00:38:25857ExtensionsService* ProfileImpl::GetExtensionsService() {
858 return extensions_service_.get();
859}
860
[email protected]0938d3c2009-01-09 20:37:35861UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35862 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25863}
864
[email protected]89ebc7e2009-08-24 22:11:07865ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
866 return extension_devtools_manager_.get();
867}
868
[email protected]481e1a42009-05-06 20:56:05869ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27870 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05871}
872
[email protected]7120f132009-07-20 21:05:37873ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
874 return extension_message_service_.get();
875}
876
[email protected]34cc84f2009-02-13 10:04:35877SSLHostState* ProfileImpl::GetSSLHostState() {
878 if (!ssl_host_state_.get())
879 ssl_host_state_.reset(new SSLHostState());
880
881 DCHECK(ssl_host_state_->CalledOnValidThread());
882 return ssl_host_state_.get();
883}
884
[email protected]77f6fb432009-09-05 14:21:09885net::StrictTransportSecurityState*
886 ProfileImpl::GetStrictTransportSecurityState() {
887 if (!strict_transport_security_state_.get()) {
888 strict_transport_security_state_ = new net::StrictTransportSecurityState();
889 strict_transport_security_persister_ = new StrictTransportSecurityPersister(
890 strict_transport_security_state_.get(),
891 g_browser_process->file_thread(), path_);
[email protected]887f80d2009-09-04 16:57:51892 }
[email protected]a9cea7542009-05-20 04:30:23893
[email protected]77f6fb432009-09-05 14:21:09894 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23895}
896
initial.commit09911bf2008-07-26 23:55:29897PrefService* ProfileImpl::GetPrefs() {
898 if (!prefs_.get()) {
[email protected]6faa0e0d2009-04-28 06:50:36899 prefs_.reset(new PrefService(GetPrefFilePath(),
900 g_browser_process->file_thread()));
initial.commit09911bf2008-07-26 23:55:29901
902 // The Profile class and ProfileManager class may read some prefs so
903 // register known prefs as soon as possible.
904 Profile::RegisterUserPrefs(prefs_.get());
905 ProfileManager::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53906#if defined(OS_CHROMEOS)
907 // Register Touchpad prefs here instead of in browser_prefs because these
908 // prefs are used in the constructor of ProfileImpl which happens before
909 // browser_prefs' RegisterAllPrefs is called.
910 Touchpad::RegisterUserPrefs(prefs_.get());
911#endif
initial.commit09911bf2008-07-26 23:55:29912
913 // The last session exited cleanly if there is no pref for
914 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
915 last_session_exited_cleanly_ =
916 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
917 // Mark the session as open.
918 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
919 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36920 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29921 }
922
923 return prefs_.get();
924}
925
[email protected]f7011fcb2009-01-28 21:54:32926FilePath ProfileImpl::GetPrefFilePath() {
927 FilePath pref_file_path = path_;
928 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29929 return pref_file_path;
930}
931
932URLRequestContext* ProfileImpl::GetRequestContext() {
933 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32934 FilePath cookie_path = GetPath();
935 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13936 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31937 int max_size;
938 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42939
[email protected]405a64b2009-09-16 21:03:44940 cache_path = GetCachePath(cache_path);
[email protected]6ab9b202008-12-23 22:34:50941 request_context_ = ChromeURLRequestContext::CreateOriginal(
[email protected]e2fc3d22009-09-22 19:50:31942 this, cookie_path, cache_path, max_size, appcache_service_);
initial.commit09911bf2008-07-26 23:55:29943 request_context_->AddRef();
944
[email protected]6ab9b202008-12-23 22:34:50945 // The first request context is always a normal (non-OTR) request context.
946 // Even when Chromium is started in OTR mode, a normal profile is always
947 // created first.
948 if (!default_request_context_) {
949 default_request_context_ = request_context_;
950 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56951 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50952 NotificationService::AllSources(), NotificationService::NoDetails());
[email protected]2a0c0a52009-07-31 07:51:32953#if defined(OS_LINUX)
954 // TODO(ukai): find a better way to set the URLRequestContext for OCSP.
955 net::SetURLRequestContextForOCSP(default_request_context_);
956#endif
[email protected]6ab9b202008-12-23 22:34:50957 }
958
initial.commit09911bf2008-07-26 23:55:29959 DCHECK(request_context_->cookie_store());
960 }
961
962 return request_context_;
963}
964
[email protected]e7f29642009-03-02 22:53:18965URLRequestContext* ProfileImpl::GetRequestContextForMedia() {
966 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13967 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31968 int max_size;
969 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14970
[email protected]405a64b2009-09-16 21:03:44971 cache_path = GetMediaCachePath(cache_path);
[email protected]e7f29642009-03-02 22:53:18972 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia(
[email protected]e2fc3d22009-09-22 19:50:31973 this, cache_path, max_size, appcache_service_);
[email protected]e7f29642009-03-02 22:53:18974 media_request_context_->AddRef();
975
976 DCHECK(media_request_context_->cookie_store());
977 }
978
979 return media_request_context_;
980}
981
[email protected]0189bc722009-08-28 21:56:48982FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
983 if (!favicon_service_created_) {
984 favicon_service_created_ = true;
985 scoped_refptr<FaviconService> service(new FaviconService(this));
986 favicon_service_.swap(service);
987 }
988 return favicon_service_.get();
989}
990
[email protected]47accfd62009-05-14 18:46:21991URLRequestContext* ProfileImpl::GetRequestContextForExtensions() {
992 if (!extensions_request_context_) {
993 FilePath cookie_path = GetPath();
994 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
995
996 extensions_request_context_ =
997 ChromeURLRequestContext::CreateOriginalForExtensions(this, cookie_path);
998 extensions_request_context_->AddRef();
999
1000 DCHECK(extensions_request_context_->cookie_store());
1001 }
1002
1003 return extensions_request_context_;
1004}
1005
[email protected]db36938c2009-08-19 21:48:421006net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1007 return ssl_config_service_manager_->Get();
1008}
1009
[email protected]eaadd9052009-06-23 18:02:231010Blacklist* ProfileImpl::GetBlacklist() {
1011 return blacklist_;
1012}
1013
initial.commit09911bf2008-07-26 23:55:291014HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1015 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461016 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291017 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321018 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291019 return NULL;
1020 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291021
1022 // Send out the notification that the history service was created.
1023 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561024 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291025 Details<HistoryService>(history_service_.get()));
1026 }
1027 return history_service_.get();
1028}
1029
initial.commit09911bf2008-07-26 23:55:291030TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1031 if (!template_url_model_.get())
1032 template_url_model_.reset(new TemplateURLModel(this));
1033 return template_url_model_.get();
1034}
1035
1036TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1037 if (!template_url_fetcher_.get())
1038 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1039 return template_url_fetcher_.get();
1040}
1041
1042WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1043 if (!created_web_data_service_)
1044 CreateWebDataService();
1045 return web_data_service_.get();
1046}
1047
1048void ProfileImpl::CreateWebDataService() {
1049 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1050 created_web_data_service_ = true;
1051 scoped_refptr<WebDataService> wds(new WebDataService());
1052 if (!wds->Init(GetPath()))
1053 return;
1054 web_data_service_.swap(wds);
1055}
1056
[email protected]e69d33952009-06-03 22:00:411057PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1058 if (!created_password_store_)
1059 CreatePasswordStore();
1060 return password_store_.get();
1061}
1062
1063void ProfileImpl::CreatePasswordStore() {
1064 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1065 created_password_store_ = true;
1066 scoped_refptr<PasswordStore> ps;
1067#if defined(OS_LINUX)
1068// Temporarily disabled while we figure some stuff out.
1069// http://code.google.com/p/chromium/issues/detail?id=12351
1070// if (getenv("KDE_FULL_SESSION")) {
1071// ps = new PasswordStoreKWallet();
1072// } else {
1073// ps = new PasswordStoreGnome();
1074// }
1075 NOTIMPLEMENTED();
1076#elif defined(OS_WIN)
1077 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561078#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171079 FilePath login_db_file_path = GetPath();
1080 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1081 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1082 if (!login_db->Init(login_db_file_path)) {
1083 LOG(ERROR) << "Could not initialize login database.";
1084 delete login_db;
1085 return;
1086 }
1087 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411088#else
1089 NOTIMPLEMENTED();
1090#endif
1091 if (!ps || !ps->Init()) {
1092 // Try falling back to the default password manager
1093 LOG(WARNING) << "Could not initialise native password manager - "
1094 "falling back to default";
1095 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1096 if (!ps->Init())
1097 return;
1098 }
1099 password_store_.swap(ps);
1100}
1101
initial.commit09911bf2008-07-26 23:55:291102DownloadManager* ProfileImpl::GetDownloadManager() {
1103 if (!created_download_manager_) {
1104 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1105 dlm->Init(this);
1106 created_download_manager_ = true;
1107 download_manager_.swap(dlm);
1108 }
1109 return download_manager_.get();
1110}
1111
1112bool ProfileImpl::HasCreatedDownloadManager() const {
1113 return created_download_manager_;
1114}
1115
[email protected]4a190632009-05-09 01:07:421116void ProfileImpl::InitThemes() {
1117 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571118#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151119 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291120#else
[email protected]761962c2009-09-25 00:18:151121 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291122#endif
[email protected]761962c2009-09-25 00:18:151123 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421124 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421125 }
1126}
1127
1128void ProfileImpl::SetTheme(Extension* extension) {
1129 InitThemes();
1130 theme_provider_.get()->SetTheme(extension);
1131}
1132
[email protected]a5166af62009-07-03 00:42:291133void ProfileImpl::SetNativeTheme() {
1134 InitThemes();
1135 theme_provider_.get()->SetNativeTheme();
1136}
1137
[email protected]4a190632009-05-09 01:07:421138void ProfileImpl::ClearTheme() {
1139 InitThemes();
1140 theme_provider_.get()->UseDefaultTheme();
1141}
1142
[email protected]51c490b2009-08-03 16:34:341143Extension* ProfileImpl::GetTheme() {
1144 InitThemes();
1145
1146 std::string id = theme_provider_.get()->GetThemeID();
1147 if (id == BrowserThemeProvider::kDefaultThemeID)
1148 return NULL;
1149
1150 return extensions_service_->GetExtensionById(id);
1151}
1152
[email protected]4a190632009-05-09 01:07:421153ThemeProvider* ProfileImpl::GetThemeProvider() {
1154 InitThemes();
1155 return theme_provider_.get();
1156}
1157
initial.commit09911bf2008-07-26 23:55:291158SessionService* ProfileImpl::GetSessionService() {
1159 if (!session_service_.get() && !shutdown_session_service_) {
1160 session_service_ = new SessionService(this);
1161 session_service_->ResetFromCurrentBrowsers();
1162 }
1163 return session_service_.get();
1164}
1165
1166void ProfileImpl::ShutdownSessionService() {
1167 if (shutdown_session_service_)
1168 return;
1169
1170 // We're about to exit, force creation of the session service if it hasn't
1171 // been created yet. We do this to ensure session state matches the point in
1172 // time the user exited.
1173 GetSessionService();
1174 shutdown_session_service_ = true;
1175 session_service_ = NULL;
1176}
1177
1178bool ProfileImpl::HasSessionService() const {
1179 return (session_service_.get() != NULL);
1180}
1181
1182std::wstring ProfileImpl::GetName() {
1183 return GetPrefs()->GetString(prefs::kProfileName);
1184}
1185void ProfileImpl::SetName(const std::wstring& name) {
1186 GetPrefs()->SetString(prefs::kProfileName, name);
1187}
1188
1189std::wstring ProfileImpl::GetID() {
1190 return GetPrefs()->GetString(prefs::kProfileID);
1191}
1192void ProfileImpl::SetID(const std::wstring& id) {
1193 GetPrefs()->SetString(prefs::kProfileID, id);
1194}
1195
initial.commit09911bf2008-07-26 23:55:291196bool ProfileImpl::DidLastSessionExitCleanly() {
1197 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1198 // it to be set by asking for the prefs.
1199 GetPrefs();
1200 return last_session_exited_cleanly_;
1201}
1202
[email protected]d8e41ed2008-09-11 15:22:321203BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461204 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321205 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461206 bookmark_bar_model_->Load();
1207 }
initial.commit09911bf2008-07-26 23:55:291208 return bookmark_bar_model_.get();
1209}
1210
1211bool ProfileImpl::IsSameProfile(Profile* profile) {
1212 if (profile == static_cast<Profile*>(this))
1213 return true;
1214 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1215 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1216}
1217
1218Time ProfileImpl::GetStartTime() const {
1219 return start_time_;
1220}
1221
1222TabRestoreService* ProfileImpl::GetTabRestoreService() {
1223 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191224 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291225 return tab_restore_service_.get();
1226}
1227
[email protected]449478302009-06-09 20:04:281228ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1229 if (!thumbnail_store_.get()) {
1230 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251231 thumbnail_store_->Init(
1232 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281233 }
1234 return thumbnail_store_.get();
1235}
1236
initial.commit09911bf2008-07-26 23:55:291237void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191238 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291239}
1240
[email protected]a9afddb2009-02-12 17:49:421241// To be run in the IO thread to notify all resource message filters that the
[email protected]20930852008-10-15 19:30:411242// spellchecker has changed.
1243class NotifySpellcheckerChangeTask : public Task {
1244 public:
1245 NotifySpellcheckerChangeTask(
[email protected]e7244d82008-10-29 18:13:261246 Profile* profile,
1247 const SpellcheckerReinitializedDetails& spellchecker)
[email protected]20930852008-10-15 19:30:411248 : profile_(profile),
1249 spellchecker_(spellchecker) {
1250 }
1251
1252 private:
1253 void Run(void) {
1254 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561255 NotificationType::SPELLCHECKER_REINITIALIZED,
[email protected]20930852008-10-15 19:30:411256 Source<Profile>(profile_),
1257 Details<SpellcheckerReinitializedDetails>(&spellchecker_));
1258 }
1259
1260 Profile* profile_;
1261 SpellcheckerReinitializedDetails spellchecker_;
1262};
1263
[email protected]e3448ea2009-10-02 01:29:291264void ProfileImpl::ReinitializeSpellChecker() {
[email protected]20930852008-10-15 19:30:411265 PrefService* prefs = GetPrefs();
[email protected]e3448ea2009-10-02 01:29:291266 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1267 DeleteSpellCheckerImpl(false);
[email protected]20930852008-10-15 19:30:411268
[email protected]e3448ea2009-10-02 01:29:291269 // Retrieve the (perhaps updated recently) dictionary name from preferences.
[email protected]bd17b702009-02-25 20:44:081270 FilePath dict_dir;
[email protected]e7244d82008-10-29 18:13:261271 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
[email protected]a9afddb2009-02-12 17:49:421272 // Note that, as the object pointed to by previously by spellchecker_
[email protected]e7244d82008-10-29 18:13:261273 // is being deleted in the io thread, the spellchecker_ can be made to point
1274 // to a new object (RE-initialized) in parallel in this UI thread.
[email protected]4b4d1adc2008-12-10 22:28:581275 spellchecker_ = new SpellChecker(dict_dir,
[email protected]74c8b422009-03-11 00:34:121276 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1277 GetRequestContext(),
[email protected]bd17b702009-02-25 20:44:081278 FilePath());
[email protected]e7244d82008-10-29 18:13:261279 spellchecker_->AddRef(); // Manual refcounting.
[email protected]20930852008-10-15 19:30:411280
[email protected]e3448ea2009-10-02 01:29:291281 // Set auto spell correct status for spellchecker.
[email protected]154a4332009-06-03 20:20:581282 spellchecker_->EnableAutoSpellCorrect(
1283 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
[email protected]154a4332009-06-03 20:20:581284
[email protected]e3448ea2009-10-02 01:29:291285 NotifySpellCheckerChanged();
1286 } else {
1287 DeleteSpellCheckerImpl(true);
[email protected]20930852008-10-15 19:30:411288 }
1289}
1290
[email protected]e3448ea2009-10-02 01:29:291291void ProfileImpl::NotifySpellCheckerChanged() {
1292 // The I/O thread may be NULL during testing.
1293 base::Thread* io_thread = g_browser_process->io_thread();
1294 if (io_thread) { // Notify resource message filters.
1295 SpellcheckerReinitializedDetails scoped_spellchecker;
1296 scoped_spellchecker.spellchecker = spellchecker_;
1297 io_thread->message_loop()->PostTask(FROM_HERE,
1298 new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
1299 }
1300}
1301
1302void ProfileImpl::DeleteSpellCheckerImpl(bool notify) {
1303 if (spellchecker_) {
1304 // The spellchecker must be deleted on the I/O thread.
1305 // The I/O thread may be NULL during testing.
1306 base::Thread* io_thread = g_browser_process->io_thread();
1307 if (io_thread)
1308 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
1309 else // during testing, we don't have an I/O thread
1310 spellchecker_->Release();
1311
1312 spellchecker_ = NULL;
1313
1314 if (notify)
1315 NotifySpellCheckerChanged();
1316 }
[email protected]e7244d82008-10-29 18:13:261317}
1318
initial.commit09911bf2008-07-26 23:55:291319SpellChecker* ProfileImpl::GetSpellChecker() {
1320 if (!spellchecker_) {
[email protected]20930852008-10-15 19:30:411321 // This is where spellchecker gets initialized. Note that this is being
1322 // initialized in the ui_thread. However, this is not a problem as long as
1323 // it is *used* in the io thread.
[email protected]34cc84f2009-02-13 10:04:351324 // TODO(sidchat): One day, change everything so that spellchecker gets
[email protected]20930852008-10-15 19:30:411325 // initialized in the IO thread itself.
[email protected]e3448ea2009-10-02 01:29:291326 ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:291327 }
[email protected]20930852008-10-15 19:30:411328
initial.commit09911bf2008-07-26 23:55:291329 return spellchecker_;
1330}
1331
[email protected]3bf335a2009-06-26 20:46:061332WebKitContext* ProfileImpl::GetWebKitContext() {
1333 if (!webkit_context_.get())
1334 webkit_context_ = new WebKitContext(path_, false);
1335 DCHECK(webkit_context_.get());
1336 return webkit_context_.get();
1337}
1338
initial.commit09911bf2008-07-26 23:55:291339void ProfileImpl::MarkAsCleanShutdown() {
1340 if (prefs_.get()) {
1341 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1342 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1343
1344 // NOTE: If you change what thread this writes on, be sure and update
1345 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361346 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291347 }
1348}
1349
[email protected]e7244d82008-10-29 18:13:261350void ProfileImpl::Observe(NotificationType type,
1351 const NotificationSource& source,
1352 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561353 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261354 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1355 PrefService* prefs = Source<PrefService>(source).ptr();
1356 DCHECK(pref_name_in && prefs);
1357 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]154a4332009-06-03 20:20:581358 *pref_name_in == prefs::kEnableSpellCheck ||
1359 *pref_name_in == prefs::kEnableAutoSpellCorrect) {
[email protected]e3448ea2009-10-02 01:29:291360 ReinitializeSpellChecker();
[email protected]e7244d82008-10-29 18:13:261361 }
[email protected]4a190632009-05-09 01:07:421362 } else if (NotificationType::THEME_INSTALLED == type) {
1363 Extension* extension = Details<Extension>(details).ptr();
1364 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111365 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1366 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1367 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1368 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261369 }
1370}
1371
initial.commit09911bf2008-07-26 23:55:291372void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141373 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291374}
[email protected]3a453fa2008-08-15 18:46:341375
[email protected]48352c12009-08-15 01:19:111376ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]3a453fa2008-08-15 18:46:341377#ifdef CHROME_PERSONALIZATION
[email protected]345a8b72009-09-29 09:11:441378 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) {
[email protected]48352c12009-08-15 01:19:111379 if (!sync_service_.get())
1380 InitSyncService();
1381 return sync_service_.get();
1382 }
license.botbf09a502008-08-24 00:55:551383#endif
[email protected]48352c12009-08-15 01:19:111384 return NULL;
1385}
1386
1387void ProfileImpl::InitSyncService() {
1388#ifdef CHROME_PERSONALIZATION
1389 sync_service_.reset(new ProfileSyncService(this));
1390 sync_service_->Initialize();
1391#endif
1392}