blob: 83b2ad3e9538203e1d3ed73b963c15dc0c6869f3 [file] [log] [blame]
[email protected]e284e6d82010-01-29 19:49:451// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/profile.h"
6
[email protected]1952c7d2010-03-04 23:48:347#include "app/resource_bundle.h"
[email protected]2735e3692009-09-25 18:19:398#include "app/theme_provider.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/command_line.h"
[email protected]04fba9a92008-10-28 17:25:2510#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4411#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/path_service.h"
13#include "base/scoped_ptr.h"
14#include "base/string_util.h"
[email protected]0082d7e0d2010-02-27 14:34:1215#include "chrome/browser/appcache/chrome_appcache_service.h"
[email protected]66ee4432010-03-30 00:19:1816#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]def11712009-11-06 00:42:1517#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4218#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2919#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5120#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5721#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0222#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3723#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4224#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5625#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0726#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3727#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0528#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2529#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3530#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4831#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5332#include "chrome/browser/find_bar_state.h"
[email protected]aee541e2010-03-19 01:52:4533#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]9c92d192009-12-02 08:03:1634#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4235#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4236#include "chrome/browser/history/history.h"
[email protected]e284e6d82010-01-29 19:49:4537#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5138#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0639#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5040#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4241#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2642#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4143#include "chrome/browser/password_manager/password_store_default.h"
[email protected]8c6335d32010-01-20 09:21:5044#include "chrome/browser/privacy_blacklist/blacklist.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2646#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3347#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4648#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4449#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3050#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3351#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1152#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4353#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4054#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2855#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0656#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2957#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3958#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5660#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2961#include "chrome/common/chrome_constants.h"
62#include "chrome/common/chrome_paths.h"
63#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5864#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2965#include "chrome/common/notification_service.h"
66#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3267#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3468#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5869#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4270#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3471#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2972
[email protected]753efc42010-03-09 19:52:1673#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2974#include "chrome/browser/gtk/gtk_theme_provider.h"
75#endif
76
[email protected]e1acf6f2008-10-27 20:43:3377using base::Time;
78using base::TimeDelta;
79
[email protected]e5642992009-06-26 23:06:3180namespace {
81
initial.commit09911bf2008-07-26 23:55:2982// Delay, in milliseconds, before we explicitly create the SessionService.
83static const int kCreateSessionServiceDelayMS = 500;
84
[email protected]e5642992009-06-26 23:06:3185enum ContextType {
86 kNormalContext,
87 kMediaContext
88};
89
90// Gets the cache parameters from the command line. |type| is the type of
91// request context that we need, |cache_path| will be set to the user provided
92// path, or will not be touched if there is not an argument. |max_size| will
93// be the user provided value or zero by default.
94void GetCacheParameters(ContextType type, FilePath* cache_path,
95 int* max_size) {
96 DCHECK(cache_path);
97 DCHECK(max_size);
98
99 // Override the cache location if specified by the user.
100 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
101 switches::kDiskCacheDir));
102
103 if (!user_path.empty()) {
104 *cache_path = FilePath::FromWStringHack(user_path);
105 }
106
[email protected]b7e0a2a2009-10-13 02:07:25107 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
108 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31109 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25110 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31111
112 // By default we let the cache determine the right size.
113 *max_size = 0;
114 if (!StringToInt(value, max_size)) {
115 *max_size = 0;
116 } else if (max_size < 0) {
117 *max_size = 0;
118 }
119}
120
[email protected]405a64b2009-09-16 21:03:44121FilePath GetCachePath(const FilePath& base) {
122 return base.Append(chrome::kCacheDirname);
123}
124
125FilePath GetMediaCachePath(const FilePath& base) {
126 return base.Append(chrome::kMediaCacheDirname);
127}
128
129bool HasACacheSubdir(const FilePath &dir) {
130 return file_util::PathExists(GetCachePath(dir)) ||
131 file_util::PathExists(GetMediaCachePath(dir));
132}
133
[email protected]57a777f72010-03-31 01:09:42134void PostExtensionLoadedToContextGetter(ChromeURLRequestContextGetter* getter,
135 Extension* extension) {
136 if (!getter)
137 return;
138 // Callee takes ownership of new ExtensionInfo struct.
139 ChromeThread::PostTask(
140 ChromeThread::IO, FROM_HERE,
141 NewRunnableMethod(getter,
142 &ChromeURLRequestContextGetter::OnNewExtensions,
143 extension->id(),
144 new ChromeURLRequestContext::ExtensionInfo(
145 extension->path(),
146 extension->default_locale(),
147 extension->web_extent(),
148 extension->api_permissions())));
149}
150
151void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
152 Extension* extension) {
153 if (!getter)
154 return;
155 ChromeThread::PostTask(
156 ChromeThread::IO, FROM_HERE,
157 NewRunnableMethod(getter,
158 &ChromeURLRequestContextGetter::OnUnloadedExtension,
159 extension->id()));
160}
161
[email protected]e5642992009-06-26 23:06:31162} // namespace
163
initial.commit09911bf2008-07-26 23:55:29164// A pointer to the request context for the default profile. See comments on
165// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31166URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29167
[email protected]be180c802009-10-23 06:33:31168static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19169 if (context)
[email protected]47accfd62009-05-14 18:46:21170 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21171}
172
[email protected]34cc84f2009-02-13 10:04:35173// static
[email protected]4bf6afd2009-10-08 14:00:11174const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
175
176// static
initial.commit09911bf2008-07-26 23:55:29177void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55178 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29179 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
180 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12181 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26182 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
183 IDS_SPELLCHECK_DICTIONARY);
184 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58185 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16186#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06187 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
188 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29189#endif
[email protected]f017cc92009-12-14 20:48:07190 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34191 prefs->RegisterStringPref(prefs::kCurrentThemeID,
192 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42193 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
194 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
195 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50196 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23197 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29198}
199
[email protected]34cc84f2009-02-13 10:04:35200// static
[email protected]f7011fcb2009-01-28 21:54:32201Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29202 return new ProfileImpl(path);
203}
204
[email protected]34cc84f2009-02-13 10:04:35205// static
[email protected]be180c802009-10-23 06:33:31206URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29207 return default_request_context_;
208}
209
[email protected]753efc42010-03-09 19:52:16210#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41211#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56212#elif defined(OS_MACOSX)
213#include "chrome/browser/keychain_mac.h"
214#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16215#elif defined(OS_POSIX)
216// Temporarily disabled while we figure some stuff out.
217// http://code.google.com/p/chromium/issues/detail?id=12351
218// #include "chrome/browser/password_manager/password_store_gnome.h"
219// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41220#endif
initial.commit09911bf2008-07-26 23:55:29221
initial.commit09911bf2008-07-26 23:55:29222////////////////////////////////////////////////////////////////////////////////
223//
224// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42225// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29226//
227////////////////////////////////////////////////////////////////////////////////
228class OffTheRecordProfileImpl : public Profile,
229 public NotificationObserver {
230 public:
231 explicit OffTheRecordProfileImpl(Profile* real_profile)
232 : profile_(real_profile),
233 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31234 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05235
initial.commit09911bf2008-07-26 23:55:29236 // Register for browser close notifications so we can detect when the last
237 // off-the-record window is closed, in which case we can clean our states
238 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43239 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
240 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29241 }
242
243 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21244 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29245 }
246
[email protected]4bf6afd2009-10-08 14:00:11247 virtual ProfileId GetRuntimeId() {
248 return reinterpret_cast<ProfileId>(this);
249 }
250
[email protected]a6d0f182010-01-12 08:01:44251 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29252
253 virtual bool IsOffTheRecord() {
254 return true;
255 }
256
257 virtual Profile* GetOffTheRecordProfile() {
258 return this;
259 }
260
[email protected]860f55492009-03-27 19:50:59261 virtual void DestroyOffTheRecordProfile() {
262 // Suicide is bad!
263 NOTREACHED();
264 }
265
initial.commit09911bf2008-07-26 23:55:29266 virtual Profile* GetOriginalProfile() {
267 return profile_;
268 }
269
[email protected]2f351cb2009-11-09 23:43:34270 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
271 if (!db_tracker_)
272 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
273 return db_tracker_;
274 }
275
initial.commit09911bf2008-07-26 23:55:29276 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49277 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
278 // because we don't want to leak the sites that the user has visited before.
279 return NULL;
initial.commit09911bf2008-07-26 23:55:29280 }
281
[email protected]6014d672008-12-05 00:38:25282 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21283 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25284 }
285
[email protected]0938d3c2009-01-09 20:37:35286 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21287 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25288 }
289
[email protected]89ebc7e2009-08-24 22:11:07290 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21291 // TODO(mpcomplete): figure out whether we should return the original
292 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07293 return NULL;
294 }
295
[email protected]481e1a42009-05-06 20:56:05296 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21297 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05298 }
299
[email protected]7120f132009-07-20 21:05:37300 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21301 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37302 }
303
[email protected]34cc84f2009-02-13 10:04:35304 virtual SSLHostState* GetSSLHostState() {
305 if (!ssl_host_state_.get())
306 ssl_host_state_.reset(new SSLHostState());
307
308 DCHECK(ssl_host_state_->CalledOnValidThread());
309 return ssl_host_state_.get();
310 }
311
[email protected]326e6792009-12-11 21:04:42312 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54313 if (!transport_security_state_.get())
314 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23315
[email protected]326e6792009-12-11 21:04:42316 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23317 }
318
initial.commit09911bf2008-07-26 23:55:29319 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54320 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29321 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54322
323 NOTREACHED() << "This profile is OffTheRecord";
324 return NULL;
initial.commit09911bf2008-07-26 23:55:29325 }
326
[email protected]0850fa62009-10-08 22:34:29327 virtual HistoryService* GetHistoryServiceWithoutCreating() {
328 return profile_->GetHistoryServiceWithoutCreating();
329 }
330
[email protected]0189bc722009-08-28 21:56:48331 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54332 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48333 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54334
335 NOTREACHED() << "This profile is OffTheRecord";
336 return NULL;
[email protected]0189bc722009-08-28 21:56:48337 }
338
[email protected]66ee4432010-03-30 00:19:18339 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
340 return profile_->GetAutocompleteClassifier();
[email protected]90085af02009-10-29 17:53:21341 }
342
initial.commit09911bf2008-07-26 23:55:29343 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54344 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29345 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54346
347 NOTREACHED() << "This profile is OffTheRecord";
348 return NULL;
initial.commit09911bf2008-07-26 23:55:29349 }
350
[email protected]9cddbe372009-10-23 21:23:53351 virtual WebDataService* GetWebDataServiceWithoutCreating() {
352 return profile_->GetWebDataServiceWithoutCreating();
353 }
354
[email protected]e69d33952009-06-03 22:00:41355 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54356 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41357 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54358
359 NOTREACHED() << "This profile is OffTheRecord";
360 return NULL;
[email protected]e69d33952009-06-03 22:00:41361 }
362
initial.commit09911bf2008-07-26 23:55:29363 virtual PrefService* GetPrefs() {
364 return profile_->GetPrefs();
365 }
366
367 virtual TemplateURLModel* GetTemplateURLModel() {
368 return profile_->GetTemplateURLModel();
369 }
370
371 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
372 return profile_->GetTemplateURLFetcher();
373 }
374
375 virtual DownloadManager* GetDownloadManager() {
376 if (!download_manager_.get()) {
377 scoped_refptr<DownloadManager> dlm(new DownloadManager);
378 dlm->Init(this);
379 download_manager_.swap(dlm);
380 }
381 return download_manager_.get();
382 }
383
384 virtual bool HasCreatedDownloadManager() const {
385 return (download_manager_.get() != NULL);
386 }
387
[email protected]def11712009-11-06 00:42:15388 virtual PersonalDataManager* GetPersonalDataManager() {
389 return NULL;
390 }
391
[email protected]4a190632009-05-09 01:07:42392 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54393 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42394 }
395
396 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54397 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42398 }
399
[email protected]a5166af62009-07-03 00:42:29400 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54401 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29402 }
403
[email protected]4a190632009-05-09 01:07:42404 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54405 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42406 }
407
[email protected]51c490b2009-08-03 16:34:34408 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54409 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34410 }
411
[email protected]5786d3d2009-12-18 00:18:44412 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54413 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42414 }
415
[email protected]be180c802009-10-23 06:33:31416 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29417 return request_context_;
418 }
419
[email protected]be180c802009-10-23 06:33:31420 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11421 // In OTR mode, media request context is the same as the original one.
422 return request_context_;
[email protected]e7f29642009-03-02 22:53:18423 }
424
[email protected]be180c802009-10-23 06:33:31425 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21426 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21427 }
428
[email protected]db36938c2009-08-19 21:48:42429 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54430 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42431 }
432
[email protected]e284e6d82010-01-29 19:49:45433 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]bd147842010-04-09 15:29:17434 // Retrieve the host content settings map of the parent profile in order to
435 // ensure the preferences have been migrated.
436 profile_->GetHostContentSettingsMap();
437 if (!host_content_settings_map_.get())
438 host_content_settings_map_ = new HostContentSettingsMap(this);
439 return host_content_settings_map_.get();
[email protected]e284e6d82010-01-29 19:49:45440 }
441
[email protected]40bd6582009-12-04 23:49:51442 virtual HostZoomMap* GetHostZoomMap() {
[email protected]779c3362010-01-30 01:09:33443 return profile_->GetHostZoomMap();
[email protected]40bd6582009-12-04 23:49:51444 }
445
[email protected]aee541e2010-03-19 01:52:45446 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
447 return profile_->GetGeolocationContentSettingsMap();
448 }
449
[email protected]8c6335d32010-01-20 09:21:50450 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54451 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23452 }
453
[email protected]6c32ce72010-03-08 05:18:06454 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
455 return profile_->GetUserStyleSheetWatcher();
456 }
457
[email protected]e5d2f7132010-04-09 18:13:53458 virtual FindBarState* GetFindBarState() {
459 if (!find_bar_state_.get())
460 find_bar_state_.reset(new FindBarState());
461 return find_bar_state_.get();
462 }
463
initial.commit09911bf2008-07-26 23:55:29464 virtual SessionService* GetSessionService() {
465 // Don't save any sessions when off the record.
466 return NULL;
467 }
468
469 virtual void ShutdownSessionService() {
470 // We don't allow a session service, nothing to do.
471 }
472
473 virtual bool HasSessionService() const {
474 // We never have a session service.
475 return false;
476 }
477
initial.commit09911bf2008-07-26 23:55:29478 virtual bool DidLastSessionExitCleanly() {
479 return profile_->DidLastSessionExitCleanly();
480 }
481
[email protected]d8e41ed2008-09-11 15:22:32482 virtual BookmarkModel* GetBookmarkModel() {
483 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29484 }
485
[email protected]4bb336302009-10-12 05:44:26486 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58487 if (!desktop_notification_service_.get()) {
488 desktop_notification_service_.reset(new DesktopNotificationService(
489 this, g_browser_process->notification_ui_manager()));
490 }
491 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26492 }
493
[email protected]48352c12009-08-15 01:19:11494 virtual ProfileSyncService* GetProfileSyncService() {
495 return NULL;
[email protected]3a453fa2008-08-15 18:46:34496 }
[email protected]3a453fa2008-08-15 18:46:34497
initial.commit09911bf2008-07-26 23:55:29498 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54499 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29500 }
501
502 virtual Time GetStartTime() const {
503 return start_time_;
504 }
505
506 virtual TabRestoreService* GetTabRestoreService() {
507 return NULL;
508 }
509
[email protected]e7244d82008-10-29 18:13:26510 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41511 }
512
[email protected]85c55dc2009-11-06 03:05:46513 virtual SpellCheckHost* GetSpellCheckHost() {
514 return profile_->GetSpellCheckHost();
515 }
516
517 virtual void ReinitializeSpellCheckHost(bool force) {
518 profile_->ReinitializeSpellCheckHost(force);
519 }
[email protected]85c55dc2009-11-06 03:05:46520
[email protected]3bf335a2009-06-26 20:46:06521 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29522 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21523 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29524 DCHECK(webkit_context_.get());
525 return webkit_context_.get();
526 }
[email protected]3bf335a2009-06-26 20:46:06527
[email protected]449478302009-06-09 20:04:28528 virtual ThumbnailStore* GetThumbnailStore() {
529 return NULL;
530 }
531
initial.commit09911bf2008-07-26 23:55:29532 virtual void MarkAsCleanShutdown() {
533 }
534
[email protected]bdbc87c2009-01-25 05:08:54535 virtual void InitExtensions() {
536 NOTREACHED();
537 }
538
[email protected]ea0c98cf2009-06-18 23:02:54539 virtual void InitWebResources() {
540 NOTREACHED();
541 }
542
[email protected]9c8dd902009-11-19 17:50:42543 virtual NTPResourceCache* GetNTPResourceCache() {
544 // Just return the real profile resource cache.
545 return profile_->GetNTPResourceCache();
546 }
547
initial.commit09911bf2008-07-26 23:55:29548 virtual void ExitedOffTheRecordMode() {
549 // Drop our download manager so we forget about all the downloads made
550 // in off-the-record mode.
551 download_manager_ = NULL;
552 }
553
554 virtual void Observe(NotificationType type,
555 const NotificationSource& source,
556 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56557 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29558 // We are only interested in OTR browser closing.
559 if (Source<Browser>(source)->profile() != this)
560 return;
561
562 // Let's check if we still have an Off The Record window opened.
563 // Note that we check against 1 as this notification is sent before the
564 // browser window is actually removed from the list.
565 if (BrowserList::GetBrowserCount(this) <= 1)
566 ExitedOffTheRecordMode();
567 }
568
569 private:
[email protected]88cf3292009-05-22 01:48:43570 NotificationRegistrar registrar_;
571
initial.commit09911bf2008-07-26 23:55:29572 // The real underlying profile.
573 Profile* profile_;
574
[email protected]6ab9b202008-12-23 22:34:50575 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19576 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29577
578 // The download manager that only stores downloaded items in memory.
579 scoped_refptr<DownloadManager> download_manager_;
580
[email protected]7d7696c52009-12-01 20:54:58581 // Use a separate desktop notification service for OTR.
582 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
583
[email protected]bd147842010-04-09 15:29:17584 // We use a non-writable content settings map for OTR.
585 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
586
[email protected]3bf335a2009-06-26 20:46:06587 // Use a special WebKit context for OTR browsing.
588 scoped_refptr<WebKitContext> webkit_context_;
589
[email protected]34cc84f2009-02-13 10:04:35590 // We don't want SSLHostState from the OTR profile to leak back to the main
591 // profile because then the main profile would learn some of the host names
592 // the user visited while OTR.
593 scoped_ptr<SSLHostState> ssl_host_state_;
594
[email protected]e5d2f7132010-04-09 18:13:53595 // Use a separate FindBarState so search terms do not leak back to the main
596 // profile.
597 scoped_ptr<FindBarState> find_bar_state_;
598
[email protected]326e6792009-12-11 21:04:42599 // The TransportSecurityState that only stores enabled sites in memory.
600 scoped_refptr<net::TransportSecurityState>
601 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23602
initial.commit09911bf2008-07-26 23:55:29603 // Time we were started.
604 Time start_time_;
605
[email protected]2f351cb2009-11-09 23:43:34606 // The main database tracker for this profile.
607 // Should be used only on the file thread.
608 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
609
[email protected]90085af02009-10-29 17:53:21610 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29611};
612
[email protected]f7011fcb2009-01-28 21:54:32613ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29614 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44615 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07616 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32617 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57618 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21619 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45620 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51621 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32622 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48623 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32624 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41625 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32626 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42627 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32628 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46629 spellcheck_host_(NULL),
630 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29631 shutdown_session_service_(false) {
632 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
633 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14634 create_session_service_timer_.Start(
635 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
636 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54637
[email protected]89ebc7e2009-08-24 22:11:07638 if (CommandLine::ForCurrentProcess()->HasSwitch(
639 switches::kEnableExtensionTimelineApi)) {
640 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
641 }
642
[email protected]382a0702009-06-26 17:12:27643 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37644 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27645
[email protected]e7244d82008-10-29 18:13:26646 PrefService* prefs = GetPrefs();
647 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
648 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58649 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58650
[email protected]405a64b2009-09-16 21:03:44651#if defined(OS_MACOSX)
652 // If the profile directory doesn't already have a cache directory and it
653 // is under ~/Library/Application Support, use a suitable cache directory
654 // under ~/Library/Caches. For example, a profile directory of
655 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
656 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
657 // ~/Library/Caches/Google/Chrome/MyProfileName.
658 //
659 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44660 if (!HasACacheSubdir(path_)) {
661 FilePath app_data_path, user_cache_path;
662 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12663 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44664 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
665 base_cache_path_ = user_cache_path;
666 }
667 }
[email protected]9e9b6e8e2009-12-02 08:45:01668#elif defined(OS_POSIX) // Posix minus Mac.
669 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
670 // for a spec on where cache files go. The net effect for most systems is we
671 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
672 // official builds.
673 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
674#if defined(GOOGLE_CHROME_BUILD)
675 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44676#else
[email protected]9e9b6e8e2009-12-02 08:45:01677 const char kCacheDir[] = "chromium";
678#endif
679 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
680 base_cache_path_ = base_cache_path_.Append(kCacheDir);
681 if (!file_util::PathExists(base_cache_path_))
682 file_util::CreateDirectory(base_cache_path_);
683 }
[email protected]405a64b2009-09-16 21:03:44684#endif
[email protected]bc96d562009-08-11 18:45:13685 if (base_cache_path_.empty())
686 base_cache_path_ = path_;
687
[email protected]4a190632009-05-09 01:07:42688 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43689 registrar_.Add(this, NotificationType::THEME_INSTALLED,
690 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11691
692 // Listen for bookmark model load, to bootstrap the sync service.
693 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
694 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42695
696 ssl_config_service_manager_.reset(
697 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53698
699#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29700 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53701#endif
[email protected]911f8152010-03-18 16:46:40702
703 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29704}
705
[email protected]bdbc87c2009-01-25 05:08:54706void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41707 if (user_script_master_ || extensions_service_)
708 return; // Already initialized.
709
[email protected]bdbc87c2009-01-25 05:08:54710 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18711 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36712
713 FilePath script_dir; // Don't look for user scripts in any directory.
714 // TODO(aa): We should just remove this functionality,
715 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51716 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36717
[email protected]894bb502009-05-21 22:39:57718 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23719 this,
720 CommandLine::ForCurrentProcess(),
721 GetPrefs(),
722 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36723 true);
[email protected]bdbc87c2009-01-25 05:08:54724
[email protected]1952c7d2010-03-04 23:48:34725 // Register the bookmark manager extension.
[email protected]4b776892010-03-19 22:57:33726 if (!CommandLine::ForCurrentProcess()->HasSwitch(
727 switches::kDisableTabbedBookmarkManager)) {
[email protected]1952c7d2010-03-04 23:48:34728 FilePath bookmark_manager_path;
729 if (PathService::Get(chrome::DIR_BOOKMARK_MANAGER,
730 &bookmark_manager_path)) {
731 std::string manifest =
732 ResourceBundle::GetSharedInstance().GetRawDataResource(
733 IDR_BOOKMARKS_MANIFEST).as_string();
734 extensions_service_->register_component_extension(
735 ExtensionsService::ComponentExtensionInfo(manifest,
736 bookmark_manager_path));
737 } else {
738 NOTREACHED();
739 }
740 }
741
[email protected]9197f3b2009-06-02 00:49:27742 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12743
744 // Load any extensions specified with --load-extension.
745 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10746 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12747 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12748 }
[email protected]bdbc87c2009-01-25 05:08:54749}
750
[email protected]ea0c98cf2009-06-18 23:02:54751void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07752 if (web_resource_service_)
753 return; // Already initialized.
754
[email protected]6fad2632009-11-02 05:59:37755 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54756 web_resource_service_->StartAfterDelay();
757}
758
[email protected]9c8dd902009-11-19 17:50:42759NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
760 if (!ntp_resource_cache_.get())
761 ntp_resource_cache_.reset(new NTPResourceCache(this));
762 return ntp_resource_cache_.get();
763}
764
initial.commit09911bf2008-07-26 23:55:29765ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56766 NotificationService::current()->Notify(
767 NotificationType::PROFILE_DESTROYED,
768 Source<Profile>(this),
769 NotificationService::NoDetails());
770
[email protected]169627b2008-12-06 19:30:19771 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29772
773 StopCreateSessionServiceTimer();
774 // TemplateURLModel schedules a task on the WebDataService from its
775 // destructor. Delete it first to ensure the task gets scheduled before we
776 // shut down the database.
777 template_url_model_.reset();
778
779 // The download manager queries the history system and should be deleted
780 // before the history is shutdown so it can properly cancel all requests.
781 download_manager_ = NULL;
782
[email protected]4a190632009-05-09 01:07:42783 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15784 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42785
[email protected]44961292009-07-20 20:03:09786 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
787 // save any new thumbnails to disk and release its reference to the
788 // HistoryService.
789 if (thumbnail_store_.get())
790 thumbnail_store_->Shutdown();
791
[email protected]e7244d82008-10-29 18:13:26792 // Remove pref observers.
793 PrefService* prefs = GetPrefs();
794 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
795 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58796 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26797
[email protected]9c8dd902009-11-19 17:50:42798 // Delete the NTP resource cache so we can unregister pref observers.
799 ntp_resource_cache_.reset();
800
[email protected]48352c12009-08-15 01:19:11801 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34802
initial.commit09911bf2008-07-26 23:55:29803 // Both HistoryService and WebDataService maintain threads for background
804 // processing. Its possible each thread still has tasks on it that have
805 // increased the ref count of the service. In such a situation, when we
806 // decrement the refcount, it won't be 0, and the threads/databases aren't
807 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
808 // databases are properly closed.
809 if (web_data_service_.get())
810 web_data_service_->Shutdown();
811
812 if (history_service_.get())
813 history_service_->Cleanup();
814
[email protected]85c55dc2009-11-06 03:05:46815 if (spellcheck_host_.get())
816 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29817
[email protected]cfc06f122009-11-16 22:18:55818 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21819 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50820
[email protected]47accfd62009-05-14 18:46:21821 CleanupRequestContext(request_context_);
822 CleanupRequestContext(media_request_context_);
823 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17824
[email protected]d8e41ed2008-09-11 15:22:32825 // HistoryService may call into the BookmarkModel, as such we need to
826 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46827 // HistoryService will join with HistoryService's backend thread so that
828 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32829 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46830 history_service_ = NULL;
831 bookmark_bar_model_.reset();
832
[email protected]0189bc722009-08-28 21:56:48833 // FaviconService depends on HistoryServce so make sure we delete
834 // HistoryService first.
835 favicon_service_ = NULL;
836
[email protected]7120f132009-07-20 21:05:37837 extension_message_service_->ProfileDestroyed();
838
[email protected]6ef635e42009-07-26 06:16:12839 if (extensions_service_)
840 extensions_service_->ProfileDestroyed();
841
[email protected]66da08b2009-10-19 22:27:00842 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29843 MarkAsCleanShutdown();
844}
845
[email protected]4bf6afd2009-10-08 14:00:11846ProfileId ProfileImpl::GetRuntimeId() {
847 return reinterpret_cast<ProfileId>(this);
848}
849
[email protected]f7011fcb2009-01-28 21:54:32850FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29851 return path_;
852}
853
854bool ProfileImpl::IsOffTheRecord() {
855 return false;
856}
857
858Profile* ProfileImpl::GetOffTheRecordProfile() {
859 if (!off_the_record_profile_.get()) {
860 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
861 off_the_record_profile_.swap(p);
862 }
863 return off_the_record_profile_.get();
864}
865
[email protected]860f55492009-03-27 19:50:59866void ProfileImpl::DestroyOffTheRecordProfile() {
867 off_the_record_profile_.reset();
868}
869
initial.commit09911bf2008-07-26 23:55:29870Profile* ProfileImpl::GetOriginalProfile() {
871 return this;
872}
873
[email protected]2f351cb2009-11-09 23:43:34874webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
875 if (!db_tracker_)
876 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
877 return db_tracker_;
878}
879
initial.commit09911bf2008-07-26 23:55:29880VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44881 if (!visited_link_master_.get()) {
882 scoped_ptr<VisitedLinkMaster> visited_links(
883 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
884 if (!visited_links->Init())
885 return NULL;
886 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53887 }
[email protected]a6d0f182010-01-12 08:01:44888
889 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29890}
891
[email protected]6014d672008-12-05 00:38:25892ExtensionsService* ProfileImpl::GetExtensionsService() {
893 return extensions_service_.get();
894}
895
[email protected]0938d3c2009-01-09 20:37:35896UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35897 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25898}
899
[email protected]89ebc7e2009-08-24 22:11:07900ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
901 return extension_devtools_manager_.get();
902}
903
[email protected]481e1a42009-05-06 20:56:05904ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27905 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05906}
907
[email protected]7120f132009-07-20 21:05:37908ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
909 return extension_message_service_.get();
910}
911
[email protected]34cc84f2009-02-13 10:04:35912SSLHostState* ProfileImpl::GetSSLHostState() {
913 if (!ssl_host_state_.get())
914 ssl_host_state_.reset(new SSLHostState());
915
916 DCHECK(ssl_host_state_->CalledOnValidThread());
917 return ssl_host_state_.get();
918}
919
[email protected]326e6792009-12-11 21:04:42920net::TransportSecurityState*
921 ProfileImpl::GetTransportSecurityState() {
922 if (!transport_security_state_.get()) {
923 transport_security_state_ = new net::TransportSecurityState();
924 transport_security_persister_ =
925 new TransportSecurityPersister();
926 transport_security_persister_->Initialize(
927 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51928 }
[email protected]a9cea7542009-05-20 04:30:23929
[email protected]326e6792009-12-11 21:04:42930 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23931}
932
initial.commit09911bf2008-07-26 23:55:29933PrefService* ProfileImpl::GetPrefs() {
934 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37935 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29936
937 // The Profile class and ProfileManager class may read some prefs so
938 // register known prefs as soon as possible.
939 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51940 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29941
942 // The last session exited cleanly if there is no pref for
943 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
944 last_session_exited_cleanly_ =
945 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
946 // Mark the session as open.
947 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
948 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36949 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29950 }
951
952 return prefs_.get();
953}
954
[email protected]f7011fcb2009-01-28 21:54:32955FilePath ProfileImpl::GetPrefFilePath() {
956 FilePath pref_file_path = path_;
957 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29958 return pref_file_path;
959}
960
[email protected]be180c802009-10-23 06:33:31961URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29962 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32963 FilePath cookie_path = GetPath();
964 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13965 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31966 int max_size;
967 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42968
[email protected]405a64b2009-09-16 21:03:44969 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31970 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
971 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29972
[email protected]6ab9b202008-12-23 22:34:50973 // The first request context is always a normal (non-OTR) request context.
974 // Even when Chromium is started in OTR mode, a normal profile is always
975 // created first.
976 if (!default_request_context_) {
977 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31978 // TODO(eroman): this isn't terribly useful anymore now that the
979 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50980 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56981 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50982 NotificationService::AllSources(), NotificationService::NoDetails());
983 }
initial.commit09911bf2008-07-26 23:55:29984 }
985
986 return request_context_;
987}
988
[email protected]be180c802009-10-23 06:33:31989URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18990 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13991 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31992 int max_size;
993 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14994
[email protected]405a64b2009-09-16 21:03:44995 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31996 media_request_context_ =
997 ChromeURLRequestContextGetter::CreateOriginalForMedia(
998 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18999 }
1000
1001 return media_request_context_;
1002}
1003
[email protected]0189bc722009-08-28 21:56:481004FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
1005 if (!favicon_service_created_) {
1006 favicon_service_created_ = true;
1007 scoped_refptr<FaviconService> service(new FaviconService(this));
1008 favicon_service_.swap(service);
1009 }
1010 return favicon_service_.get();
1011}
1012
[email protected]be180c802009-10-23 06:33:311013URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:211014 if (!extensions_request_context_) {
1015 FilePath cookie_path = GetPath();
1016 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1017
1018 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:311019 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
1020 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:211021 }
1022
1023 return extensions_request_context_;
1024}
1025
[email protected]57a777f72010-03-31 01:09:421026void ProfileImpl::RegisterExtensionWithRequestContexts(
1027 Extension* extension) {
1028 // Notify the default, extension and media contexts on the IO thread.
1029 PostExtensionLoadedToContextGetter(
1030 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1031 extension);
1032 PostExtensionLoadedToContextGetter(
1033 static_cast<ChromeURLRequestContextGetter*>(
1034 GetRequestContextForExtensions()),
1035 extension);
1036 PostExtensionLoadedToContextGetter(
1037 static_cast<ChromeURLRequestContextGetter*>(
1038 GetRequestContextForMedia()),
1039 extension);
1040}
1041
1042void ProfileImpl::UnregisterExtensionWithRequestContexts(
1043 Extension* extension) {
1044 // Notify the default, extension and media contexts on the IO thread.
1045 PostExtensionUnloadedToContextGetter(
1046 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1047 extension);
1048 PostExtensionUnloadedToContextGetter(
1049 static_cast<ChromeURLRequestContextGetter*>(
1050 GetRequestContextForExtensions()),
1051 extension);
1052 PostExtensionUnloadedToContextGetter(
1053 static_cast<ChromeURLRequestContextGetter*>(
1054 GetRequestContextForMedia()),
1055 extension);
1056}
1057
[email protected]db36938c2009-08-19 21:48:421058net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1059 return ssl_config_service_manager_->Get();
1060}
1061
[email protected]e284e6d82010-01-29 19:49:451062HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
1063 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:391064 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:451065 return host_content_settings_map_.get();
1066}
1067
[email protected]40bd6582009-12-04 23:49:511068HostZoomMap* ProfileImpl::GetHostZoomMap() {
1069 if (!host_zoom_map_)
1070 host_zoom_map_ = new HostZoomMap(this);
1071 return host_zoom_map_.get();
1072}
1073
[email protected]aee541e2010-03-19 01:52:451074GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
1075 if (!geolocation_content_settings_map_.get())
1076 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
1077 return geolocation_content_settings_map_.get();
1078}
1079
[email protected]8c6335d32010-01-20 09:21:501080Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271081 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141082 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271083 return NULL;
[email protected]c37f8b42010-01-23 16:22:141084 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541085 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501086 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231087}
1088
[email protected]6c32ce72010-03-08 05:18:061089UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1090 if (!user_style_sheet_watcher_.get()) {
1091 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1092 user_style_sheet_watcher_->Init();
1093 }
1094 return user_style_sheet_watcher_.get();
1095}
1096
[email protected]e5d2f7132010-04-09 18:13:531097FindBarState* ProfileImpl::GetFindBarState() {
1098 if (!find_bar_state_.get()) {
1099 find_bar_state_.reset(new FindBarState());
1100 }
1101 return find_bar_state_.get();
1102}
1103
initial.commit09911bf2008-07-26 23:55:291104HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1105 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461106 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291107 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321108 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291109 return NULL;
1110 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291111
1112 // Send out the notification that the history service was created.
1113 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561114 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291115 Details<HistoryService>(history_service_.get()));
1116 }
1117 return history_service_.get();
1118}
1119
[email protected]0850fa62009-10-08 22:34:291120HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1121 return history_service_.get();
1122}
1123
initial.commit09911bf2008-07-26 23:55:291124TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1125 if (!template_url_model_.get())
1126 template_url_model_.reset(new TemplateURLModel(this));
1127 return template_url_model_.get();
1128}
1129
1130TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1131 if (!template_url_fetcher_.get())
1132 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1133 return template_url_fetcher_.get();
1134}
1135
[email protected]66ee4432010-03-30 00:19:181136AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
1137 if (!autocomplete_classifier_.get())
1138 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
1139 return autocomplete_classifier_.get();
[email protected]90085af02009-10-29 17:53:211140}
1141
initial.commit09911bf2008-07-26 23:55:291142WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1143 if (!created_web_data_service_)
1144 CreateWebDataService();
1145 return web_data_service_.get();
1146}
1147
[email protected]9cddbe372009-10-23 21:23:531148WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1149 return web_data_service_.get();
1150}
1151
initial.commit09911bf2008-07-26 23:55:291152void ProfileImpl::CreateWebDataService() {
1153 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1154 created_web_data_service_ = true;
1155 scoped_refptr<WebDataService> wds(new WebDataService());
1156 if (!wds->Init(GetPath()))
1157 return;
1158 web_data_service_.swap(wds);
1159}
1160
[email protected]e69d33952009-06-03 22:00:411161PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1162 if (!created_password_store_)
1163 CreatePasswordStore();
1164 return password_store_.get();
1165}
1166
1167void ProfileImpl::CreatePasswordStore() {
1168 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1169 created_password_store_ = true;
1170 scoped_refptr<PasswordStore> ps;
[email protected]753efc42010-03-09 19:52:161171#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:411172 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561173#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171174 FilePath login_db_file_path = GetPath();
1175 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
[email protected]ec44cd52010-04-05 22:30:471176 LoginDatabase* login_db = new LoginDatabase();
[email protected]e0411ae52009-06-30 23:59:171177 if (!login_db->Init(login_db_file_path)) {
1178 LOG(ERROR) << "Could not initialize login database.";
1179 delete login_db;
1180 return;
1181 }
1182 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161183#elif defined(OS_POSIX)
1184 // TODO(evanm): implement "native" password management.
1185 // This bug describes the issues.
1186 // http://code.google.com/p/chromium/issues/detail?id=12351
1187 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1188 if (!ps->Init())
1189 return;
[email protected]e69d33952009-06-03 22:00:411190#else
1191 NOTIMPLEMENTED();
1192#endif
1193 if (!ps || !ps->Init()) {
1194 // Try falling back to the default password manager
1195 LOG(WARNING) << "Could not initialise native password manager - "
1196 "falling back to default";
1197 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1198 if (!ps->Init())
1199 return;
1200 }
1201 password_store_.swap(ps);
1202}
1203
initial.commit09911bf2008-07-26 23:55:291204DownloadManager* ProfileImpl::GetDownloadManager() {
1205 if (!created_download_manager_) {
1206 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1207 dlm->Init(this);
1208 created_download_manager_ = true;
1209 download_manager_.swap(dlm);
1210 }
1211 return download_manager_.get();
1212}
1213
1214bool ProfileImpl::HasCreatedDownloadManager() const {
1215 return created_download_manager_;
1216}
1217
[email protected]def11712009-11-06 00:42:151218PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1219 if (!personal_data_manager_.get()) {
[email protected]e0976a72010-04-02 01:25:241220 personal_data_manager_.reset(new PersonalDataManager());
1221 personal_data_manager_->Init(this);
[email protected]def11712009-11-06 00:42:151222 }
1223 return personal_data_manager_.get();
1224}
1225
[email protected]4a190632009-05-09 01:07:421226void ProfileImpl::InitThemes() {
1227 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161228#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151229 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291230#else
[email protected]761962c2009-09-25 00:18:151231 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291232#endif
[email protected]761962c2009-09-25 00:18:151233 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421234 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421235 }
1236}
1237
1238void ProfileImpl::SetTheme(Extension* extension) {
1239 InitThemes();
1240 theme_provider_.get()->SetTheme(extension);
1241}
1242
[email protected]a5166af62009-07-03 00:42:291243void ProfileImpl::SetNativeTheme() {
1244 InitThemes();
1245 theme_provider_.get()->SetNativeTheme();
1246}
1247
[email protected]4a190632009-05-09 01:07:421248void ProfileImpl::ClearTheme() {
1249 InitThemes();
1250 theme_provider_.get()->UseDefaultTheme();
1251}
1252
[email protected]51c490b2009-08-03 16:34:341253Extension* ProfileImpl::GetTheme() {
1254 InitThemes();
1255
1256 std::string id = theme_provider_.get()->GetThemeID();
1257 if (id == BrowserThemeProvider::kDefaultThemeID)
1258 return NULL;
1259
[email protected]61b411612009-11-10 23:17:411260 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341261}
1262
[email protected]5786d3d2009-12-18 00:18:441263BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421264 InitThemes();
1265 return theme_provider_.get();
1266}
1267
initial.commit09911bf2008-07-26 23:55:291268SessionService* ProfileImpl::GetSessionService() {
1269 if (!session_service_.get() && !shutdown_session_service_) {
1270 session_service_ = new SessionService(this);
1271 session_service_->ResetFromCurrentBrowsers();
1272 }
1273 return session_service_.get();
1274}
1275
1276void ProfileImpl::ShutdownSessionService() {
1277 if (shutdown_session_service_)
1278 return;
1279
1280 // We're about to exit, force creation of the session service if it hasn't
1281 // been created yet. We do this to ensure session state matches the point in
1282 // time the user exited.
1283 GetSessionService();
1284 shutdown_session_service_ = true;
1285 session_service_ = NULL;
1286}
1287
1288bool ProfileImpl::HasSessionService() const {
1289 return (session_service_.get() != NULL);
1290}
1291
initial.commit09911bf2008-07-26 23:55:291292bool ProfileImpl::DidLastSessionExitCleanly() {
1293 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1294 // it to be set by asking for the prefs.
1295 GetPrefs();
1296 return last_session_exited_cleanly_;
1297}
1298
[email protected]d8e41ed2008-09-11 15:22:321299BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461300 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321301 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461302 bookmark_bar_model_->Load();
1303 }
initial.commit09911bf2008-07-26 23:55:291304 return bookmark_bar_model_.get();
1305}
1306
1307bool ProfileImpl::IsSameProfile(Profile* profile) {
1308 if (profile == static_cast<Profile*>(this))
1309 return true;
1310 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1311 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1312}
1313
1314Time ProfileImpl::GetStartTime() const {
1315 return start_time_;
1316}
1317
1318TabRestoreService* ProfileImpl::GetTabRestoreService() {
1319 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191320 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291321 return tab_restore_service_.get();
1322}
1323
[email protected]449478302009-06-09 20:04:281324ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1325 if (!thumbnail_store_.get()) {
1326 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251327 thumbnail_store_->Init(
1328 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281329 }
1330 return thumbnail_store_.get();
1331}
1332
initial.commit09911bf2008-07-26 23:55:291333void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191334 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291335}
1336
[email protected]85c55dc2009-11-06 03:05:461337SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1338 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1339}
1340
1341void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1342 // If we are already loading the spellchecker, and this is just a hint to
1343 // load the spellchecker, do nothing.
1344 if (!force && spellcheck_host_.get())
1345 return;
1346
[email protected]f41301e2009-11-16 21:30:071347 spellcheck_host_ready_ = false;
1348
[email protected]85c55dc2009-11-06 03:05:461349 bool notify = false;
1350 if (spellcheck_host_.get()) {
1351 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051352 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461353 notify = true;
1354 }
1355
1356 PrefService* prefs = GetPrefs();
1357 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1358 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1359 spellcheck_host_ = new SpellCheckHost(this,
1360 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1361 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071362 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461363 } else if (notify) {
1364 // The spellchecker has been disabled.
1365 SpellCheckHostInitialized();
1366 }
1367}
1368
1369void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171370 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291371 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1372 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461373 NotificationService::current()->Notify(
1374 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1375 Source<Profile>(this), NotificationService::NoDetails());
1376}
initial.commit09911bf2008-07-26 23:55:291377
[email protected]3bf335a2009-06-26 20:46:061378WebKitContext* ProfileImpl::GetWebKitContext() {
1379 if (!webkit_context_.get())
1380 webkit_context_ = new WebKitContext(path_, false);
1381 DCHECK(webkit_context_.get());
1382 return webkit_context_.get();
1383}
1384
[email protected]4bb336302009-10-12 05:44:261385DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1386 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1387 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261388 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031389 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261390 }
[email protected]4bb336302009-10-12 05:44:261391 return desktop_notification_service_.get();
1392}
1393
initial.commit09911bf2008-07-26 23:55:291394void ProfileImpl::MarkAsCleanShutdown() {
1395 if (prefs_.get()) {
1396 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1397 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1398
1399 // NOTE: If you change what thread this writes on, be sure and update
1400 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361401 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291402 }
1403}
1404
[email protected]e7244d82008-10-29 18:13:261405void ProfileImpl::Observe(NotificationType type,
1406 const NotificationSource& source,
1407 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561408 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261409 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1410 PrefService* prefs = Source<PrefService>(source).ptr();
1411 DCHECK(pref_name_in && prefs);
1412 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461413 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461414 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291415 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1416 NotificationService::current()->Notify(
1417 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1418 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261419 }
[email protected]4a190632009-05-09 01:07:421420 } else if (NotificationType::THEME_INSTALLED == type) {
1421 Extension* extension = Details<Extension>(details).ptr();
1422 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111423 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1424 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1425 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1426 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261427 }
1428}
1429
initial.commit09911bf2008-07-26 23:55:291430void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141431 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291432}
[email protected]3a453fa2008-08-15 18:46:341433
[email protected]48352c12009-08-15 01:19:111434ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431435 if (!ProfileSyncService::IsSyncEnabled()) {
1436 return NULL;
[email protected]7367f1a2009-10-10 01:09:441437 }
[email protected]eec3bcfa2009-11-12 17:23:431438 if (!sync_service_.get())
1439 InitSyncService();
1440 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111441}
1442
1443void ProfileImpl::InitSyncService() {
[email protected]4aea04a2010-02-10 20:13:431444 profile_sync_factory_.reset(
1445 new ProfileSyncFactoryImpl(this,
1446 CommandLine::ForCurrentProcess()));
1447 sync_service_.reset(
1448 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111449 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111450}