blob: ac9f01a5108dcc2ff083818e5e0fa2eeb9b3ca62 [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]4bb336302009-10-12 05:44:2630#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4131#include "chrome/browser/password_manager/password_store_default.h"
[email protected]588074f2009-10-29 09:40:1032#include "chrome/browser/privacy_blacklist/blacklist_io.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2634#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3335#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4636#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4437#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3038#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]f0a644292009-02-25 23:32:4739#include "chrome/browser/spellchecker.h"
[email protected]1132436e2009-04-08 20:06:3340#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1141#include "chrome/browser/sync/profile_sync_service.h"
[email protected]449478302009-06-09 20:04:2842#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2943#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3944#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/browser/webdata/web_data_service.h"
[email protected]23f1ef12009-09-01 22:30:3046#include "chrome/common/appcache/chrome_appcache_service.h"
initial.commit09911bf2008-07-26 23:55:2947#include "chrome/common/chrome_constants.h"
48#include "chrome/common/chrome_paths.h"
49#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5850#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2951#include "chrome/common/notification_service.h"
52#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3253#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5854#include "grit/locale_settings.h"
[email protected]77f6fb432009-09-05 14:21:0955#include "net/base/strict_transport_security_state.h"
initial.commit09911bf2008-07-26 23:55:2956
[email protected]a5166af62009-07-03 00:42:2957#if defined(OS_LINUX)
[email protected]2a0c0a52009-07-31 07:51:3258#include "net/ocsp/nss_ocsp.h"
[email protected]a5166af62009-07-03 00:42:2959#include "chrome/browser/gtk/gtk_theme_provider.h"
60#endif
61
[email protected]2627431b2009-09-15 20:21:5362#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:2963#include "chrome/browser/chromeos/preferences.h"
[email protected]2627431b2009-09-15 20:21:5364#endif
65
[email protected]e1acf6f2008-10-27 20:43:3366using base::Time;
67using base::TimeDelta;
68
[email protected]e5642992009-06-26 23:06:3169namespace {
70
initial.commit09911bf2008-07-26 23:55:2971// Delay, in milliseconds, before we explicitly create the SessionService.
72static const int kCreateSessionServiceDelayMS = 500;
73
[email protected]e5642992009-06-26 23:06:3174enum ContextType {
75 kNormalContext,
76 kMediaContext
77};
78
79// Gets the cache parameters from the command line. |type| is the type of
80// request context that we need, |cache_path| will be set to the user provided
81// path, or will not be touched if there is not an argument. |max_size| will
82// be the user provided value or zero by default.
83void GetCacheParameters(ContextType type, FilePath* cache_path,
84 int* max_size) {
85 DCHECK(cache_path);
86 DCHECK(max_size);
87
88 // Override the cache location if specified by the user.
89 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
90 switches::kDiskCacheDir));
91
92 if (!user_path.empty()) {
93 *cache_path = FilePath::FromWStringHack(user_path);
94 }
95
[email protected]b7e0a2a2009-10-13 02:07:2596 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
97 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:3198 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:2599 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31100
101 // By default we let the cache determine the right size.
102 *max_size = 0;
103 if (!StringToInt(value, max_size)) {
104 *max_size = 0;
105 } else if (max_size < 0) {
106 *max_size = 0;
107 }
108}
109
[email protected]405a64b2009-09-16 21:03:44110FilePath GetCachePath(const FilePath& base) {
111 return base.Append(chrome::kCacheDirname);
112}
113
114FilePath GetMediaCachePath(const FilePath& base) {
115 return base.Append(chrome::kMediaCacheDirname);
116}
117
118bool HasACacheSubdir(const FilePath &dir) {
119 return file_util::PathExists(GetCachePath(dir)) ||
120 file_util::PathExists(GetMediaCachePath(dir));
121}
122
[email protected]e5642992009-06-26 23:06:31123} // namespace
124
initial.commit09911bf2008-07-26 23:55:29125// A pointer to the request context for the default profile. See comments on
126// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31127URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29128
[email protected]be180c802009-10-23 06:33:31129static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]47accfd62009-05-14 18:46:21130 if (context) {
131 context->CleanupOnUIThread();
132
133 // Clean up request context on IO thread.
134 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE,
135 context);
136 }
137}
138
[email protected]34cc84f2009-02-13 10:04:35139// static
[email protected]4bf6afd2009-10-08 14:00:11140const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
141
142// static
initial.commit09911bf2008-07-26 23:55:29143void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55144 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29145 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
146 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12147 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26148 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
149 IDS_SPELLCHECK_DICTIONARY);
150 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58151 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]f93fe782009-02-19 01:26:13152 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
[email protected]a5166af62009-07-03 00:42:29153#if defined(OS_LINUX)
154 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
155#endif
[email protected]51c490b2009-08-03 16:34:34156 prefs->RegisterStringPref(prefs::kCurrentThemeID,
157 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42158 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
159 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
160 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50161 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23162 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29163}
164
[email protected]34cc84f2009-02-13 10:04:35165// static
[email protected]f7011fcb2009-01-28 21:54:32166Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29167 return new ProfileImpl(path);
168}
169
[email protected]34cc84f2009-02-13 10:04:35170// static
[email protected]be180c802009-10-23 06:33:31171URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29172 return default_request_context_;
173}
174
[email protected]e69d33952009-06-03 22:00:41175#if defined(OS_LINUX)
176// Temporarily disabled while we figure some stuff out.
177// http://code.google.com/p/chromium/issues/detail?id=12351
178// #include "chrome/browser/password_manager/password_store_gnome.h"
179// #include "chrome/browser/password_manager/password_store_kwallet.h"
180#elif defined(OS_WIN)
181#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56182#elif defined(OS_MACOSX)
183#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17184#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56185#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41186#endif
initial.commit09911bf2008-07-26 23:55:29187
initial.commit09911bf2008-07-26 23:55:29188////////////////////////////////////////////////////////////////////////////////
189//
190// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42191// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29192//
193////////////////////////////////////////////////////////////////////////////////
194class OffTheRecordProfileImpl : public Profile,
195 public NotificationObserver {
196 public:
197 explicit OffTheRecordProfileImpl(Profile* real_profile)
198 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21199 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29200 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31201 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
initial.commit09911bf2008-07-26 23:55:29202 request_context_->AddRef();
[email protected]481e1a42009-05-06 20:56:05203
initial.commit09911bf2008-07-26 23:55:29204 // Register for browser close notifications so we can detect when the last
205 // off-the-record window is closed, in which case we can clean our states
206 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43207 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
208 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29209 }
210
211 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21212 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21213 CleanupRequestContext(extensions_request_context_);
initial.commit09911bf2008-07-26 23:55:29214 }
215
[email protected]4bf6afd2009-10-08 14:00:11216 virtual ProfileId GetRuntimeId() {
217 return reinterpret_cast<ProfileId>(this);
218 }
219
[email protected]f7011fcb2009-01-28 21:54:32220 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29221
222 virtual bool IsOffTheRecord() {
223 return true;
224 }
225
226 virtual Profile* GetOffTheRecordProfile() {
227 return this;
228 }
229
[email protected]860f55492009-03-27 19:50:59230 virtual void DestroyOffTheRecordProfile() {
231 // Suicide is bad!
232 NOTREACHED();
233 }
234
initial.commit09911bf2008-07-26 23:55:29235 virtual Profile* GetOriginalProfile() {
236 return profile_;
237 }
238
239 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49240 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
241 // because we don't want to leak the sites that the user has visited before.
242 return NULL;
initial.commit09911bf2008-07-26 23:55:29243 }
244
[email protected]6014d672008-12-05 00:38:25245 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34246 return NULL;
[email protected]6014d672008-12-05 00:38:25247 }
248
[email protected]0938d3c2009-01-09 20:37:35249 virtual UserScriptMaster* GetUserScriptMaster() {
250 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25251 }
252
[email protected]89ebc7e2009-08-24 22:11:07253 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
254 return NULL;
255 }
256
[email protected]481e1a42009-05-06 20:56:05257 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34258 return NULL;
[email protected]481e1a42009-05-06 20:56:05259 }
260
[email protected]7120f132009-07-20 21:05:37261 virtual ExtensionMessageService* GetExtensionMessageService() {
262 return NULL;
263 }
264
[email protected]34cc84f2009-02-13 10:04:35265 virtual SSLHostState* GetSSLHostState() {
266 if (!ssl_host_state_.get())
267 ssl_host_state_.reset(new SSLHostState());
268
269 DCHECK(ssl_host_state_->CalledOnValidThread());
270 return ssl_host_state_.get();
271 }
272
[email protected]77f6fb432009-09-05 14:21:09273 virtual net::StrictTransportSecurityState* GetStrictTransportSecurityState() {
274 if (!strict_transport_security_state_.get()) {
275 strict_transport_security_state_ =
276 new net::StrictTransportSecurityState();
277 }
[email protected]a9cea7542009-05-20 04:30:23278
[email protected]77f6fb432009-09-05 14:21:09279 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23280 }
281
initial.commit09911bf2008-07-26 23:55:29282 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
283 if (sat == EXPLICIT_ACCESS) {
284 return profile_->GetHistoryService(sat);
285 } else {
286 NOTREACHED() << "This profile is OffTheRecord";
287 return NULL;
288 }
289 }
290
[email protected]0850fa62009-10-08 22:34:29291 virtual HistoryService* GetHistoryServiceWithoutCreating() {
292 return profile_->GetHistoryServiceWithoutCreating();
293 }
294
[email protected]0189bc722009-08-28 21:56:48295 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
296 if (sat == EXPLICIT_ACCESS) {
297 return profile_->GetFaviconService(sat);
298 } else {
299 NOTREACHED() << "This profile is OffTheRecord";
300 return NULL;
301 }
302 }
303
initial.commit09911bf2008-07-26 23:55:29304 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
305 if (sat == EXPLICIT_ACCESS) {
306 return profile_->GetWebDataService(sat);
307 } else {
308 NOTREACHED() << "This profile is OffTheRecord";
309 return NULL;
310 }
311 }
312
[email protected]9cddbe372009-10-23 21:23:53313 virtual WebDataService* GetWebDataServiceWithoutCreating() {
314 return profile_->GetWebDataServiceWithoutCreating();
315 }
316
[email protected]e69d33952009-06-03 22:00:41317 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
318 if (sat == EXPLICIT_ACCESS) {
319 return profile_->GetPasswordStore(sat);
320 } else {
321 NOTREACHED() << "This profile is OffTheRecord";
322 return NULL;
323 }
324 }
325
initial.commit09911bf2008-07-26 23:55:29326 virtual PrefService* GetPrefs() {
327 return profile_->GetPrefs();
328 }
329
330 virtual TemplateURLModel* GetTemplateURLModel() {
331 return profile_->GetTemplateURLModel();
332 }
333
334 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
335 return profile_->GetTemplateURLFetcher();
336 }
337
338 virtual DownloadManager* GetDownloadManager() {
339 if (!download_manager_.get()) {
340 scoped_refptr<DownloadManager> dlm(new DownloadManager);
341 dlm->Init(this);
342 download_manager_.swap(dlm);
343 }
344 return download_manager_.get();
345 }
346
347 virtual bool HasCreatedDownloadManager() const {
348 return (download_manager_.get() != NULL);
349 }
350
[email protected]4a190632009-05-09 01:07:42351 virtual void InitThemes() {
352 GetOriginalProfile()->InitThemes();
353 }
354
355 virtual void SetTheme(Extension* extension) {
356 GetOriginalProfile()->SetTheme(extension);
357 }
358
[email protected]a5166af62009-07-03 00:42:29359 virtual void SetNativeTheme() {
360 GetOriginalProfile()->SetNativeTheme();
361 }
362
[email protected]4a190632009-05-09 01:07:42363 virtual void ClearTheme() {
364 GetOriginalProfile()->ClearTheme();
365 }
366
[email protected]51c490b2009-08-03 16:34:34367 virtual Extension* GetTheme() {
368 return GetOriginalProfile()->GetTheme();
369 }
370
[email protected]4a190632009-05-09 01:07:42371 virtual ThemeProvider* GetThemeProvider() {
372 return GetOriginalProfile()->GetThemeProvider();
373 }
374
[email protected]be180c802009-10-23 06:33:31375 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29376 return request_context_;
377 }
378
[email protected]be180c802009-10-23 06:33:31379 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11380 // In OTR mode, media request context is the same as the original one.
381 return request_context_;
[email protected]e7f29642009-03-02 22:53:18382 }
383
[email protected]be180c802009-10-23 06:33:31384 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21385 if (!extensions_request_context_) {
386 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31387 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(this);
[email protected]47accfd62009-05-14 18:46:21388 extensions_request_context_->AddRef();
[email protected]47accfd62009-05-14 18:46:21389 }
390
391 return extensions_request_context_;
392 }
393
[email protected]db36938c2009-08-19 21:48:42394 virtual net::SSLConfigService* GetSSLConfigService() {
395 return GetOriginalProfile()->GetSSLConfigService();
396 }
397
[email protected]eaadd9052009-06-23 18:02:23398 virtual Blacklist* GetBlacklist() {
399 return GetOriginalProfile()->GetBlacklist();
400 }
401
initial.commit09911bf2008-07-26 23:55:29402 virtual SessionService* GetSessionService() {
403 // Don't save any sessions when off the record.
404 return NULL;
405 }
406
407 virtual void ShutdownSessionService() {
408 // We don't allow a session service, nothing to do.
409 }
410
411 virtual bool HasSessionService() const {
412 // We never have a session service.
413 return false;
414 }
415
416 virtual std::wstring GetName() {
417 return profile_->GetName();
418 }
419
420 virtual void SetName(const std::wstring& name) {
421 profile_->SetName(name);
422 }
423
424 virtual std::wstring GetID() {
425 return profile_->GetID();
426 }
427
428 virtual void SetID(const std::wstring& id) {
429 profile_->SetID(id);
430 }
431
initial.commit09911bf2008-07-26 23:55:29432 virtual bool DidLastSessionExitCleanly() {
433 return profile_->DidLastSessionExitCleanly();
434 }
435
[email protected]d8e41ed2008-09-11 15:22:32436 virtual BookmarkModel* GetBookmarkModel() {
437 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29438 }
439
[email protected]4bb336302009-10-12 05:44:26440 virtual DesktopNotificationService* GetDesktopNotificationService() {
441 return profile_->GetDesktopNotificationService();
442 }
443
[email protected]48352c12009-08-15 01:19:11444 virtual ProfileSyncService* GetProfileSyncService() {
445 return NULL;
[email protected]3a453fa2008-08-15 18:46:34446 }
[email protected]3a453fa2008-08-15 18:46:34447
initial.commit09911bf2008-07-26 23:55:29448 virtual bool IsSameProfile(Profile* profile) {
449 if (profile == static_cast<Profile*>(this))
450 return true;
451 return profile == profile_;
452 }
453
454 virtual Time GetStartTime() const {
455 return start_time_;
456 }
457
458 virtual TabRestoreService* GetTabRestoreService() {
459 return NULL;
460 }
461
[email protected]e7244d82008-10-29 18:13:26462 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41463 }
464
[email protected]e7244d82008-10-29 18:13:26465 virtual void ReinitializeSpellChecker() {
466 profile_->ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:29467 }
468
469 virtual SpellChecker* GetSpellChecker() {
470 return profile_->GetSpellChecker();
471 }
472
[email protected]e3448ea2009-10-02 01:29:29473 virtual void DeleteSpellChecker() {
474 profile_->DeleteSpellChecker();
475 }
476
[email protected]3bf335a2009-06-26 20:46:06477 virtual WebKitContext* GetWebKitContext() {
478 if (!webkit_context_.get())
479 webkit_context_ = new WebKitContext(GetPath(), true);
480 DCHECK(webkit_context_.get());
481 return webkit_context_.get();
482}
483
[email protected]449478302009-06-09 20:04:28484 virtual ThumbnailStore* GetThumbnailStore() {
485 return NULL;
486 }
487
initial.commit09911bf2008-07-26 23:55:29488 virtual void MarkAsCleanShutdown() {
489 }
490
[email protected]bdbc87c2009-01-25 05:08:54491 virtual void InitExtensions() {
492 NOTREACHED();
493 }
494
[email protected]ea0c98cf2009-06-18 23:02:54495 virtual void InitWebResources() {
496 NOTREACHED();
497 }
498
initial.commit09911bf2008-07-26 23:55:29499 virtual void ExitedOffTheRecordMode() {
500 // Drop our download manager so we forget about all the downloads made
501 // in off-the-record mode.
502 download_manager_ = NULL;
503 }
504
505 virtual void Observe(NotificationType type,
506 const NotificationSource& source,
507 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56508 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29509 // We are only interested in OTR browser closing.
510 if (Source<Browser>(source)->profile() != this)
511 return;
512
513 // Let's check if we still have an Off The Record window opened.
514 // Note that we check against 1 as this notification is sent before the
515 // browser window is actually removed from the list.
516 if (BrowserList::GetBrowserCount(this) <= 1)
517 ExitedOffTheRecordMode();
518 }
519
520 private:
[email protected]88cf3292009-05-22 01:48:43521 NotificationRegistrar registrar_;
522
initial.commit09911bf2008-07-26 23:55:29523 // The real underlying profile.
524 Profile* profile_;
525
[email protected]6ab9b202008-12-23 22:34:50526 // The context to use for requests made from this OTR session.
[email protected]be180c802009-10-23 06:33:31527 ChromeURLRequestContextGetter* request_context_;
initial.commit09911bf2008-07-26 23:55:29528
[email protected]be180c802009-10-23 06:33:31529 ChromeURLRequestContextGetter* extensions_request_context_;
[email protected]23f1ef12009-09-01 22:30:30530
initial.commit09911bf2008-07-26 23:55:29531 // The download manager that only stores downloaded items in memory.
532 scoped_refptr<DownloadManager> download_manager_;
533
[email protected]3bf335a2009-06-26 20:46:06534 // Use a special WebKit context for OTR browsing.
535 scoped_refptr<WebKitContext> webkit_context_;
536
[email protected]34cc84f2009-02-13 10:04:35537 // We don't want SSLHostState from the OTR profile to leak back to the main
538 // profile because then the main profile would learn some of the host names
539 // the user visited while OTR.
540 scoped_ptr<SSLHostState> ssl_host_state_;
541
[email protected]77f6fb432009-09-05 14:21:09542 // The StrictTransportSecurityState that only stores enabled sites in memory.
543 scoped_refptr<net::StrictTransportSecurityState>
544 strict_transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23545
initial.commit09911bf2008-07-26 23:55:29546 // Time we were started.
547 Time start_time_;
548
549 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl);
550};
551
[email protected]f7011fcb2009-01-28 21:54:32552ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29553 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39554 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07555 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32556 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57557 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21558 extensions_request_context_(NULL),
[email protected]eaadd9052009-06-23 18:02:23559 blacklist_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32560 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48561 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32562 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41563 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32564 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42565 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32566 start_time_(Time::Now()),
567 spellchecker_(NULL),
initial.commit09911bf2008-07-26 23:55:29568 shutdown_session_service_(false) {
569 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
570 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14571 create_session_service_timer_.Start(
572 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
573 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54574
[email protected]89ebc7e2009-08-24 22:11:07575 if (CommandLine::ForCurrentProcess()->HasSwitch(
576 switches::kEnableExtensionTimelineApi)) {
577 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
578 }
579
[email protected]382a0702009-06-26 17:12:27580 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37581 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27582
[email protected]e7244d82008-10-29 18:13:26583 PrefService* prefs = GetPrefs();
584 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
585 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58586 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58587
[email protected]eaadd9052009-06-23 18:02:23588 if (CommandLine::ForCurrentProcess()->
589 HasSwitch(switches::kPrivacyBlacklist)) {
590 std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue(
591 switches::kPrivacyBlacklist);
592#if defined(OS_POSIX)
593 FilePath path(WideToUTF8(option));
594#else
595 FilePath path(option);
596#endif
[email protected]588074f2009-10-29 09:40:10597 blacklist_.reset(new Blacklist);
598 // TODO(phajdan.jr): Handle errors when reading blacklist.
599 BlacklistIO::ReadBinary(blacklist_.get(), path);
[email protected]eaadd9052009-06-23 18:02:23600 }
601
[email protected]405a64b2009-09-16 21:03:44602#if defined(OS_MACOSX)
603 // If the profile directory doesn't already have a cache directory and it
604 // is under ~/Library/Application Support, use a suitable cache directory
605 // under ~/Library/Caches. For example, a profile directory of
606 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
607 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
608 // ~/Library/Caches/Google/Chrome/MyProfileName.
609 //
610 // TODO(akalin): Come up with unit tests for this.
611 // TODO(akalin): Use for Linux, too?
612 if (!HasACacheSubdir(path_)) {
613 FilePath app_data_path, user_cache_path;
614 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
615 PathService::Get(base::DIR_CACHE, &user_cache_path) &&
616 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
617 base_cache_path_ = user_cache_path;
618 }
619 }
620#else
[email protected]bc96d562009-08-11 18:45:13621 if (!PathService::IsOverridden(chrome::DIR_USER_DATA))
622 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_);
[email protected]405a64b2009-09-16 21:03:44623#endif
[email protected]bc96d562009-08-11 18:45:13624 if (base_cache_path_.empty())
625 base_cache_path_ = path_;
626
[email protected]4a190632009-05-09 01:07:42627 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43628 registrar_.Add(this, NotificationType::THEME_INSTALLED,
629 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11630
631 // Listen for bookmark model load, to bootstrap the sync service.
632 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
633 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42634
635 ssl_config_service_manager_.reset(
636 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53637
638#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29639 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53640#endif
initial.commit09911bf2008-07-26 23:55:29641}
642
[email protected]bdbc87c2009-01-25 05:08:54643void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41644 if (user_script_master_ || extensions_service_)
645 return; // Already initialized.
646
[email protected]bdbc87c2009-01-25 05:08:54647 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]f93fe782009-02-19 01:26:13648 PrefService* prefs = GetPrefs();
[email protected]bdbc87c2009-01-25 05:08:54649 bool user_scripts_enabled =
[email protected]f0a51fb52009-03-05 12:46:38650 command_line->HasSwitch(switches::kEnableUserScripts) ||
[email protected]f93fe782009-02-19 01:26:13651 prefs->GetBoolean(prefs::kEnableUserScripts);
[email protected]bdbc87c2009-01-25 05:08:54652
[email protected]f7011fcb2009-01-28 21:54:32653 FilePath script_dir;
[email protected]bdbc87c2009-01-25 05:08:54654 if (user_scripts_enabled) {
[email protected]0cd957b2009-03-06 20:13:23655 if (command_line->HasSwitch(switches::kUserScriptsDir)) {
656 std::wstring path_string =
657 command_line->GetSwitchValue(switches::kUserScriptsDir);
658 script_dir = FilePath::FromWStringHack(path_string);
659 } else {
660 script_dir = GetPath();
661 script_dir = script_dir.Append(chrome::kUserScriptsDirname);
662 }
[email protected]bdbc87c2009-01-25 05:08:54663 }
664
[email protected]bb28e062009-02-27 17:19:18665 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]bdbc87c2009-01-25 05:08:54666 user_script_master_ = new UserScriptMaster(
[email protected]9197f3b2009-06-02 00:49:27667 g_browser_process->file_thread()->message_loop(),
668 script_dir);
[email protected]894bb502009-05-21 22:39:57669 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23670 this,
671 CommandLine::ForCurrentProcess(),
672 GetPrefs(),
673 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
674 MessageLoop::current(),
[email protected]93fd78f42009-07-10 16:43:17675 g_browser_process->file_thread()->message_loop(),
[email protected]c8b437d2009-07-20 21:26:36676 true);
[email protected]bdbc87c2009-01-25 05:08:54677
[email protected]9197f3b2009-06-02 00:49:27678 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12679
680 // Load any extensions specified with --load-extension.
681 if (command_line->HasSwitch(switches::kLoadExtension)) {
682 std::wstring path_string =
683 command_line->GetSwitchValue(switches::kLoadExtension);
684 FilePath path = FilePath::FromWStringHack(path_string);
685 extensions_service_->LoadExtension(path);
686
687 // Tell UserScriptMaser to watch this extension's directory for changes so
688 // you can live edit content scripts during development.
689 user_script_master_->AddWatchedPath(path);
690 }
[email protected]bdbc87c2009-01-25 05:08:54691}
692
[email protected]ea0c98cf2009-06-18 23:02:54693void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07694 if (web_resource_service_)
695 return; // Already initialized.
696
[email protected]ea0c98cf2009-06-18 23:02:54697 web_resource_service_ = new WebResourceService(
698 this,
699 g_browser_process->file_thread()->message_loop());
700
701 web_resource_service_->StartAfterDelay();
702}
703
initial.commit09911bf2008-07-26 23:55:29704ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19705 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29706
707 StopCreateSessionServiceTimer();
708 // TemplateURLModel schedules a task on the WebDataService from its
709 // destructor. Delete it first to ensure the task gets scheduled before we
710 // shut down the database.
711 template_url_model_.reset();
712
713 // The download manager queries the history system and should be deleted
714 // before the history is shutdown so it can properly cancel all requests.
715 download_manager_ = NULL;
716
[email protected]4a190632009-05-09 01:07:42717 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15718 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42719
[email protected]44961292009-07-20 20:03:09720 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
721 // save any new thumbnails to disk and release its reference to the
722 // HistoryService.
723 if (thumbnail_store_.get())
724 thumbnail_store_->Shutdown();
725
[email protected]e7244d82008-10-29 18:13:26726 // Remove pref observers.
727 PrefService* prefs = GetPrefs();
728 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
729 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58730 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26731
[email protected]48352c12009-08-15 01:19:11732 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34733
initial.commit09911bf2008-07-26 23:55:29734 // Both HistoryService and WebDataService maintain threads for background
735 // processing. Its possible each thread still has tasks on it that have
736 // increased the ref count of the service. In such a situation, when we
737 // decrement the refcount, it won't be 0, and the threads/databases aren't
738 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
739 // databases are properly closed.
740 if (web_data_service_.get())
741 web_data_service_->Shutdown();
742
743 if (history_service_.get())
744 history_service_->Cleanup();
745
[email protected]e3448ea2009-10-02 01:29:29746 DeleteSpellCheckerImpl(false);
initial.commit09911bf2008-07-26 23:55:29747
[email protected]2a0c0a52009-07-31 07:51:32748 if (default_request_context_ == request_context_) {
749#if defined(OS_LINUX)
750 // We use default_request_context_ for OCSP.
751 // Release URLRequestContext used in OCSP handlers.
752 net::SetURLRequestContextForOCSP(NULL);
753#endif
[email protected]47accfd62009-05-14 18:46:21754 default_request_context_ = NULL;
[email protected]2a0c0a52009-07-31 07:51:32755 }
[email protected]6ab9b202008-12-23 22:34:50756
[email protected]47accfd62009-05-14 18:46:21757 CleanupRequestContext(request_context_);
758 CleanupRequestContext(media_request_context_);
759 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17760
[email protected]eaadd9052009-06-23 18:02:23761 // When the request contexts are gone, the blacklist wont be needed anymore.
[email protected]588074f2009-10-29 09:40:10762 blacklist_.reset();
[email protected]eaadd9052009-06-23 18:02:23763
[email protected]d8e41ed2008-09-11 15:22:32764 // HistoryService may call into the BookmarkModel, as such we need to
765 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46766 // HistoryService will join with HistoryService's backend thread so that
767 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32768 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46769 history_service_ = NULL;
770 bookmark_bar_model_.reset();
771
[email protected]0189bc722009-08-28 21:56:48772 // FaviconService depends on HistoryServce so make sure we delete
773 // HistoryService first.
774 favicon_service_ = NULL;
775
[email protected]7120f132009-07-20 21:05:37776 extension_message_service_->ProfileDestroyed();
777
[email protected]6ef635e42009-07-26 06:16:12778 if (extensions_service_)
779 extensions_service_->ProfileDestroyed();
780
[email protected]66da08b2009-10-19 22:27:00781 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29782 MarkAsCleanShutdown();
783}
784
[email protected]4bf6afd2009-10-08 14:00:11785ProfileId ProfileImpl::GetRuntimeId() {
786 return reinterpret_cast<ProfileId>(this);
787}
788
[email protected]f7011fcb2009-01-28 21:54:32789FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29790 return path_;
791}
792
793bool ProfileImpl::IsOffTheRecord() {
794 return false;
795}
796
797Profile* ProfileImpl::GetOffTheRecordProfile() {
798 if (!off_the_record_profile_.get()) {
799 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
800 off_the_record_profile_.swap(p);
801 }
802 return off_the_record_profile_.get();
803}
804
[email protected]860f55492009-03-27 19:50:59805void ProfileImpl::DestroyOffTheRecordProfile() {
806 off_the_record_profile_.reset();
807}
808
initial.commit09911bf2008-07-26 23:55:29809Profile* ProfileImpl::GetOriginalProfile() {
810 return this;
811}
812
initial.commit09911bf2008-07-26 23:55:29813VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
814 if (!visited_link_master_.get()) {
815 scoped_ptr<VisitedLinkMaster> visited_links(
816 new VisitedLinkMaster(g_browser_process->file_thread(),
[email protected]3e90d4a2009-07-03 17:38:39817 visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29818 if (!visited_links->Init())
819 return NULL;
820 visited_link_master_.swap(visited_links);
821 }
822
823 return visited_link_master_.get();
824}
825
[email protected]6014d672008-12-05 00:38:25826ExtensionsService* ProfileImpl::GetExtensionsService() {
827 return extensions_service_.get();
828}
829
[email protected]0938d3c2009-01-09 20:37:35830UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35831 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25832}
833
[email protected]89ebc7e2009-08-24 22:11:07834ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
835 return extension_devtools_manager_.get();
836}
837
[email protected]481e1a42009-05-06 20:56:05838ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27839 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05840}
841
[email protected]7120f132009-07-20 21:05:37842ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
843 return extension_message_service_.get();
844}
845
[email protected]34cc84f2009-02-13 10:04:35846SSLHostState* ProfileImpl::GetSSLHostState() {
847 if (!ssl_host_state_.get())
848 ssl_host_state_.reset(new SSLHostState());
849
850 DCHECK(ssl_host_state_->CalledOnValidThread());
851 return ssl_host_state_.get();
852}
853
[email protected]77f6fb432009-09-05 14:21:09854net::StrictTransportSecurityState*
855 ProfileImpl::GetStrictTransportSecurityState() {
856 if (!strict_transport_security_state_.get()) {
857 strict_transport_security_state_ = new net::StrictTransportSecurityState();
858 strict_transport_security_persister_ = new StrictTransportSecurityPersister(
859 strict_transport_security_state_.get(),
860 g_browser_process->file_thread(), path_);
[email protected]887f80d2009-09-04 16:57:51861 }
[email protected]a9cea7542009-05-20 04:30:23862
[email protected]77f6fb432009-09-05 14:21:09863 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23864}
865
initial.commit09911bf2008-07-26 23:55:29866PrefService* ProfileImpl::GetPrefs() {
867 if (!prefs_.get()) {
[email protected]6faa0e0d2009-04-28 06:50:36868 prefs_.reset(new PrefService(GetPrefFilePath(),
869 g_browser_process->file_thread()));
initial.commit09911bf2008-07-26 23:55:29870
871 // The Profile class and ProfileManager class may read some prefs so
872 // register known prefs as soon as possible.
873 Profile::RegisterUserPrefs(prefs_.get());
874 ProfileManager::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53875#if defined(OS_CHROMEOS)
876 // Register Touchpad prefs here instead of in browser_prefs because these
877 // prefs are used in the constructor of ProfileImpl which happens before
878 // browser_prefs' RegisterAllPrefs is called.
[email protected]fecc1522009-10-15 21:08:29879 chromeos::Preferences::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53880#endif
initial.commit09911bf2008-07-26 23:55:29881
882 // The last session exited cleanly if there is no pref for
883 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
884 last_session_exited_cleanly_ =
885 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
886 // Mark the session as open.
887 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
888 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36889 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29890 }
891
892 return prefs_.get();
893}
894
[email protected]f7011fcb2009-01-28 21:54:32895FilePath ProfileImpl::GetPrefFilePath() {
896 FilePath pref_file_path = path_;
897 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29898 return pref_file_path;
899}
900
[email protected]be180c802009-10-23 06:33:31901URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29902 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32903 FilePath cookie_path = GetPath();
904 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13905 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31906 int max_size;
907 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42908
[email protected]405a64b2009-09-16 21:03:44909 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31910 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
911 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29912 request_context_->AddRef();
913
[email protected]6ab9b202008-12-23 22:34:50914 // The first request context is always a normal (non-OTR) request context.
915 // Even when Chromium is started in OTR mode, a normal profile is always
916 // created first.
917 if (!default_request_context_) {
918 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31919 // TODO(eroman): this isn't terribly useful anymore now that the
920 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50921 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56922 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50923 NotificationService::AllSources(), NotificationService::NoDetails());
924 }
initial.commit09911bf2008-07-26 23:55:29925 }
926
927 return request_context_;
928}
929
[email protected]be180c802009-10-23 06:33:31930URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18931 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13932 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31933 int max_size;
934 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14935
[email protected]405a64b2009-09-16 21:03:44936 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31937 media_request_context_ =
938 ChromeURLRequestContextGetter::CreateOriginalForMedia(
939 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18940 media_request_context_->AddRef();
[email protected]e7f29642009-03-02 22:53:18941 }
942
943 return media_request_context_;
944}
945
[email protected]0189bc722009-08-28 21:56:48946FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
947 if (!favicon_service_created_) {
948 favicon_service_created_ = true;
949 scoped_refptr<FaviconService> service(new FaviconService(this));
950 favicon_service_.swap(service);
951 }
952 return favicon_service_.get();
953}
954
[email protected]be180c802009-10-23 06:33:31955URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21956 if (!extensions_request_context_) {
957 FilePath cookie_path = GetPath();
958 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
959
960 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31961 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
962 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21963 extensions_request_context_->AddRef();
[email protected]47accfd62009-05-14 18:46:21964 }
965
966 return extensions_request_context_;
967}
968
[email protected]db36938c2009-08-19 21:48:42969net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
970 return ssl_config_service_manager_->Get();
971}
972
[email protected]eaadd9052009-06-23 18:02:23973Blacklist* ProfileImpl::GetBlacklist() {
[email protected]588074f2009-10-29 09:40:10974 return blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:23975}
976
initial.commit09911bf2008-07-26 23:55:29977HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
978 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:46979 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:29980 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:32981 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:29982 return NULL;
983 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:29984
985 // Send out the notification that the history service was created.
986 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:56987 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:29988 Details<HistoryService>(history_service_.get()));
989 }
990 return history_service_.get();
991}
992
[email protected]0850fa62009-10-08 22:34:29993HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
994 return history_service_.get();
995}
996
initial.commit09911bf2008-07-26 23:55:29997TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
998 if (!template_url_model_.get())
999 template_url_model_.reset(new TemplateURLModel(this));
1000 return template_url_model_.get();
1001}
1002
1003TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1004 if (!template_url_fetcher_.get())
1005 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1006 return template_url_fetcher_.get();
1007}
1008
1009WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1010 if (!created_web_data_service_)
1011 CreateWebDataService();
1012 return web_data_service_.get();
1013}
1014
[email protected]9cddbe372009-10-23 21:23:531015WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1016 return web_data_service_.get();
1017}
1018
initial.commit09911bf2008-07-26 23:55:291019void ProfileImpl::CreateWebDataService() {
1020 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1021 created_web_data_service_ = true;
1022 scoped_refptr<WebDataService> wds(new WebDataService());
1023 if (!wds->Init(GetPath()))
1024 return;
1025 web_data_service_.swap(wds);
1026}
1027
[email protected]e69d33952009-06-03 22:00:411028PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1029 if (!created_password_store_)
1030 CreatePasswordStore();
1031 return password_store_.get();
1032}
1033
1034void ProfileImpl::CreatePasswordStore() {
1035 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1036 created_password_store_ = true;
1037 scoped_refptr<PasswordStore> ps;
1038#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251039 // TODO(evanm): implement "native" password management.
1040 // This bug describes the issues.
1041 // http://code.google.com/p/chromium/issues/detail?id=12351
1042 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1043 if (!ps->Init())
1044 return;
[email protected]e69d33952009-06-03 22:00:411045#elif defined(OS_WIN)
1046 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561047#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171048 FilePath login_db_file_path = GetPath();
1049 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1050 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1051 if (!login_db->Init(login_db_file_path)) {
1052 LOG(ERROR) << "Could not initialize login database.";
1053 delete login_db;
1054 return;
1055 }
1056 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411057#else
1058 NOTIMPLEMENTED();
1059#endif
1060 if (!ps || !ps->Init()) {
1061 // Try falling back to the default password manager
1062 LOG(WARNING) << "Could not initialise native password manager - "
1063 "falling back to default";
1064 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1065 if (!ps->Init())
1066 return;
1067 }
1068 password_store_.swap(ps);
1069}
1070
initial.commit09911bf2008-07-26 23:55:291071DownloadManager* ProfileImpl::GetDownloadManager() {
1072 if (!created_download_manager_) {
1073 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1074 dlm->Init(this);
1075 created_download_manager_ = true;
1076 download_manager_.swap(dlm);
1077 }
1078 return download_manager_.get();
1079}
1080
1081bool ProfileImpl::HasCreatedDownloadManager() const {
1082 return created_download_manager_;
1083}
1084
[email protected]4a190632009-05-09 01:07:421085void ProfileImpl::InitThemes() {
1086 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571087#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151088 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291089#else
[email protected]761962c2009-09-25 00:18:151090 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291091#endif
[email protected]761962c2009-09-25 00:18:151092 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421093 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421094 }
1095}
1096
1097void ProfileImpl::SetTheme(Extension* extension) {
1098 InitThemes();
1099 theme_provider_.get()->SetTheme(extension);
1100}
1101
[email protected]a5166af62009-07-03 00:42:291102void ProfileImpl::SetNativeTheme() {
1103 InitThemes();
1104 theme_provider_.get()->SetNativeTheme();
1105}
1106
[email protected]4a190632009-05-09 01:07:421107void ProfileImpl::ClearTheme() {
1108 InitThemes();
1109 theme_provider_.get()->UseDefaultTheme();
1110}
1111
[email protected]51c490b2009-08-03 16:34:341112Extension* ProfileImpl::GetTheme() {
1113 InitThemes();
1114
1115 std::string id = theme_provider_.get()->GetThemeID();
1116 if (id == BrowserThemeProvider::kDefaultThemeID)
1117 return NULL;
1118
1119 return extensions_service_->GetExtensionById(id);
1120}
1121
[email protected]4a190632009-05-09 01:07:421122ThemeProvider* ProfileImpl::GetThemeProvider() {
1123 InitThemes();
1124 return theme_provider_.get();
1125}
1126
initial.commit09911bf2008-07-26 23:55:291127SessionService* ProfileImpl::GetSessionService() {
1128 if (!session_service_.get() && !shutdown_session_service_) {
1129 session_service_ = new SessionService(this);
1130 session_service_->ResetFromCurrentBrowsers();
1131 }
1132 return session_service_.get();
1133}
1134
1135void ProfileImpl::ShutdownSessionService() {
1136 if (shutdown_session_service_)
1137 return;
1138
1139 // We're about to exit, force creation of the session service if it hasn't
1140 // been created yet. We do this to ensure session state matches the point in
1141 // time the user exited.
1142 GetSessionService();
1143 shutdown_session_service_ = true;
1144 session_service_ = NULL;
1145}
1146
1147bool ProfileImpl::HasSessionService() const {
1148 return (session_service_.get() != NULL);
1149}
1150
1151std::wstring ProfileImpl::GetName() {
1152 return GetPrefs()->GetString(prefs::kProfileName);
1153}
1154void ProfileImpl::SetName(const std::wstring& name) {
1155 GetPrefs()->SetString(prefs::kProfileName, name);
1156}
1157
1158std::wstring ProfileImpl::GetID() {
1159 return GetPrefs()->GetString(prefs::kProfileID);
1160}
1161void ProfileImpl::SetID(const std::wstring& id) {
1162 GetPrefs()->SetString(prefs::kProfileID, id);
1163}
1164
initial.commit09911bf2008-07-26 23:55:291165bool ProfileImpl::DidLastSessionExitCleanly() {
1166 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1167 // it to be set by asking for the prefs.
1168 GetPrefs();
1169 return last_session_exited_cleanly_;
1170}
1171
[email protected]d8e41ed2008-09-11 15:22:321172BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461173 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321174 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461175 bookmark_bar_model_->Load();
1176 }
initial.commit09911bf2008-07-26 23:55:291177 return bookmark_bar_model_.get();
1178}
1179
1180bool ProfileImpl::IsSameProfile(Profile* profile) {
1181 if (profile == static_cast<Profile*>(this))
1182 return true;
1183 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1184 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1185}
1186
1187Time ProfileImpl::GetStartTime() const {
1188 return start_time_;
1189}
1190
1191TabRestoreService* ProfileImpl::GetTabRestoreService() {
1192 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191193 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291194 return tab_restore_service_.get();
1195}
1196
[email protected]449478302009-06-09 20:04:281197ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1198 if (!thumbnail_store_.get()) {
1199 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251200 thumbnail_store_->Init(
1201 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281202 }
1203 return thumbnail_store_.get();
1204}
1205
initial.commit09911bf2008-07-26 23:55:291206void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191207 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291208}
1209
[email protected]a9afddb2009-02-12 17:49:421210// To be run in the IO thread to notify all resource message filters that the
[email protected]20930852008-10-15 19:30:411211// spellchecker has changed.
1212class NotifySpellcheckerChangeTask : public Task {
1213 public:
1214 NotifySpellcheckerChangeTask(
[email protected]e7244d82008-10-29 18:13:261215 Profile* profile,
1216 const SpellcheckerReinitializedDetails& spellchecker)
[email protected]20930852008-10-15 19:30:411217 : profile_(profile),
1218 spellchecker_(spellchecker) {
1219 }
1220
1221 private:
1222 void Run(void) {
1223 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561224 NotificationType::SPELLCHECKER_REINITIALIZED,
[email protected]20930852008-10-15 19:30:411225 Source<Profile>(profile_),
1226 Details<SpellcheckerReinitializedDetails>(&spellchecker_));
1227 }
1228
1229 Profile* profile_;
1230 SpellcheckerReinitializedDetails spellchecker_;
1231};
1232
[email protected]e3448ea2009-10-02 01:29:291233void ProfileImpl::ReinitializeSpellChecker() {
[email protected]20930852008-10-15 19:30:411234 PrefService* prefs = GetPrefs();
[email protected]e3448ea2009-10-02 01:29:291235 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1236 DeleteSpellCheckerImpl(false);
[email protected]20930852008-10-15 19:30:411237
[email protected]e3448ea2009-10-02 01:29:291238 // Retrieve the (perhaps updated recently) dictionary name from preferences.
[email protected]bd17b702009-02-25 20:44:081239 FilePath dict_dir;
[email protected]e7244d82008-10-29 18:13:261240 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
[email protected]a9afddb2009-02-12 17:49:421241 // Note that, as the object pointed to by previously by spellchecker_
[email protected]e7244d82008-10-29 18:13:261242 // is being deleted in the io thread, the spellchecker_ can be made to point
1243 // to a new object (RE-initialized) in parallel in this UI thread.
[email protected]4b4d1adc2008-12-10 22:28:581244 spellchecker_ = new SpellChecker(dict_dir,
[email protected]74c8b422009-03-11 00:34:121245 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1246 GetRequestContext(),
[email protected]bd17b702009-02-25 20:44:081247 FilePath());
[email protected]e7244d82008-10-29 18:13:261248 spellchecker_->AddRef(); // Manual refcounting.
[email protected]20930852008-10-15 19:30:411249
[email protected]e3448ea2009-10-02 01:29:291250 // Set auto spell correct status for spellchecker.
[email protected]154a4332009-06-03 20:20:581251 spellchecker_->EnableAutoSpellCorrect(
1252 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
[email protected]154a4332009-06-03 20:20:581253
[email protected]e3448ea2009-10-02 01:29:291254 NotifySpellCheckerChanged();
1255 } else {
1256 DeleteSpellCheckerImpl(true);
[email protected]20930852008-10-15 19:30:411257 }
1258}
1259
[email protected]e3448ea2009-10-02 01:29:291260void ProfileImpl::NotifySpellCheckerChanged() {
1261 // The I/O thread may be NULL during testing.
1262 base::Thread* io_thread = g_browser_process->io_thread();
1263 if (io_thread) { // Notify resource message filters.
1264 SpellcheckerReinitializedDetails scoped_spellchecker;
1265 scoped_spellchecker.spellchecker = spellchecker_;
1266 io_thread->message_loop()->PostTask(FROM_HERE,
1267 new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
1268 }
1269}
1270
1271void ProfileImpl::DeleteSpellCheckerImpl(bool notify) {
1272 if (spellchecker_) {
1273 // The spellchecker must be deleted on the I/O thread.
1274 // The I/O thread may be NULL during testing.
1275 base::Thread* io_thread = g_browser_process->io_thread();
1276 if (io_thread)
1277 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
1278 else // during testing, we don't have an I/O thread
1279 spellchecker_->Release();
1280
1281 spellchecker_ = NULL;
1282
1283 if (notify)
1284 NotifySpellCheckerChanged();
1285 }
[email protected]e7244d82008-10-29 18:13:261286}
1287
initial.commit09911bf2008-07-26 23:55:291288SpellChecker* ProfileImpl::GetSpellChecker() {
1289 if (!spellchecker_) {
[email protected]20930852008-10-15 19:30:411290 // This is where spellchecker gets initialized. Note that this is being
1291 // initialized in the ui_thread. However, this is not a problem as long as
1292 // it is *used* in the io thread.
[email protected]34cc84f2009-02-13 10:04:351293 // TODO(sidchat): One day, change everything so that spellchecker gets
[email protected]20930852008-10-15 19:30:411294 // initialized in the IO thread itself.
[email protected]e3448ea2009-10-02 01:29:291295 ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:291296 }
[email protected]20930852008-10-15 19:30:411297
initial.commit09911bf2008-07-26 23:55:291298 return spellchecker_;
1299}
1300
[email protected]3bf335a2009-06-26 20:46:061301WebKitContext* ProfileImpl::GetWebKitContext() {
1302 if (!webkit_context_.get())
1303 webkit_context_ = new WebKitContext(path_, false);
1304 DCHECK(webkit_context_.get());
1305 return webkit_context_.get();
1306}
1307
[email protected]4bb336302009-10-12 05:44:261308DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1309 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1310 if (!desktop_notification_service_.get()) {
1311 // TODO(johnnyg): hook this up with notification UI manager.
1312 desktop_notification_service_.reset(new DesktopNotificationService(
1313 this, NULL));
1314 }
1315
1316 return desktop_notification_service_.get();
1317}
1318
initial.commit09911bf2008-07-26 23:55:291319void ProfileImpl::MarkAsCleanShutdown() {
1320 if (prefs_.get()) {
1321 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1322 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1323
1324 // NOTE: If you change what thread this writes on, be sure and update
1325 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361326 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291327 }
1328}
1329
[email protected]e7244d82008-10-29 18:13:261330void ProfileImpl::Observe(NotificationType type,
1331 const NotificationSource& source,
1332 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561333 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261334 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1335 PrefService* prefs = Source<PrefService>(source).ptr();
1336 DCHECK(pref_name_in && prefs);
1337 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]154a4332009-06-03 20:20:581338 *pref_name_in == prefs::kEnableSpellCheck ||
1339 *pref_name_in == prefs::kEnableAutoSpellCorrect) {
[email protected]e3448ea2009-10-02 01:29:291340 ReinitializeSpellChecker();
[email protected]e7244d82008-10-29 18:13:261341 }
[email protected]4a190632009-05-09 01:07:421342 } else if (NotificationType::THEME_INSTALLED == type) {
1343 Extension* extension = Details<Extension>(details).ptr();
1344 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111345 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1346 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1347 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1348 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261349 }
1350}
1351
initial.commit09911bf2008-07-26 23:55:291352void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141353 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291354}
[email protected]3a453fa2008-08-15 18:46:341355
[email protected]48352c12009-08-15 01:19:111356ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]26413f12009-10-27 22:49:231357#if !defined(OS_POSIX)
[email protected]7367f1a2009-10-10 01:09:441358 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) {
1359 if (!sync_service_.get())
1360 InitSyncService();
1361 return sync_service_.get();
1362 }
1363#endif
[email protected]48352c12009-08-15 01:19:111364 return NULL;
1365}
1366
1367void ProfileImpl::InitSyncService() {
[email protected]48352c12009-08-15 01:19:111368 sync_service_.reset(new ProfileSyncService(this));
1369 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111370}