blob: 1a015234f492fe36c38a0e02ed853cd68858baaf [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]fee67982010-04-23 17:24:2210#include "base/env_var.h"
[email protected]04fba9a92008-10-28 17:25:2511#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4412#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/path_service.h"
14#include "base/scoped_ptr.h"
15#include "base/string_util.h"
[email protected]0082d7e0d2010-02-27 14:34:1216#include "chrome/browser/appcache/chrome_appcache_service.h"
[email protected]69c579e2010-04-23 20:01:0017#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]def11712009-11-06 00:42:1518#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4219#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5121#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5722#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0223#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3724#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4225#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5626#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0727#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]14a000d2010-04-29 21:44:2428#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]7120f132009-07-20 21:05:3729#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0530#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2531#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3532#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4833#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5334#include "chrome/browser/find_bar_state.h"
[email protected]aee541e2010-03-19 01:52:4535#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]8b4b84ee2010-05-11 13:08:5236#include "chrome/browser/geolocation/geolocation_permission_context.h"
[email protected]9c92d192009-12-02 08:03:1637#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4238#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4239#include "chrome/browser/history/history.h"
[email protected]523623c2010-05-19 16:03:4240#include "chrome/browser/history/top_sites.h"
[email protected]e284e6d82010-01-29 19:49:4541#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5142#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0643#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5044#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4245#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2646#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4147#include "chrome/browser/password_manager/password_store_default.h"
[email protected]8c6335d32010-01-20 09:21:5048#include "chrome/browser/privacy_blacklist/blacklist.h"
[email protected]1bd056e2010-04-20 02:03:4849#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
initial.commit09911bf2008-07-26 23:55:2950#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2651#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3352#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4653#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4454#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3055#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3356#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]82d9d2952010-05-15 00:36:1657#include "chrome/browser/sync/net/network_change_notifier_io_thread.h"
[email protected]48352c12009-08-15 01:19:1158#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4359#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4060#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2861#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0662#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2963#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3964#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2965#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5666#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2967#include "chrome/common/chrome_constants.h"
68#include "chrome/common/chrome_paths.h"
69#include "chrome/common/chrome_switches.h"
[email protected]ea587b02010-05-21 15:01:3570#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2971#include "chrome/common/notification_service.h"
72#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3273#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3474#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5875#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4276#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3477#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2978
[email protected]753efc42010-03-09 19:52:1679#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2980#include "chrome/browser/gtk/gtk_theme_provider.h"
81#endif
82
[email protected]e1acf6f2008-10-27 20:43:3383using base::Time;
84using base::TimeDelta;
85
[email protected]e5642992009-06-26 23:06:3186namespace {
87
initial.commit09911bf2008-07-26 23:55:2988// Delay, in milliseconds, before we explicitly create the SessionService.
89static const int kCreateSessionServiceDelayMS = 500;
90
[email protected]e5642992009-06-26 23:06:3191enum ContextType {
92 kNormalContext,
93 kMediaContext
94};
95
96// Gets the cache parameters from the command line. |type| is the type of
97// request context that we need, |cache_path| will be set to the user provided
98// path, or will not be touched if there is not an argument. |max_size| will
99// be the user provided value or zero by default.
100void GetCacheParameters(ContextType type, FilePath* cache_path,
101 int* max_size) {
102 DCHECK(cache_path);
103 DCHECK(max_size);
104
105 // Override the cache location if specified by the user.
106 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
107 switches::kDiskCacheDir));
108
109 if (!user_path.empty()) {
110 *cache_path = FilePath::FromWStringHack(user_path);
111 }
112
[email protected]b7e0a2a2009-10-13 02:07:25113 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
114 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31115 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25116 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31117
118 // By default we let the cache determine the right size.
119 *max_size = 0;
120 if (!StringToInt(value, max_size)) {
121 *max_size = 0;
122 } else if (max_size < 0) {
123 *max_size = 0;
124 }
125}
126
[email protected]405a64b2009-09-16 21:03:44127FilePath GetCachePath(const FilePath& base) {
128 return base.Append(chrome::kCacheDirname);
129}
130
131FilePath GetMediaCachePath(const FilePath& base) {
132 return base.Append(chrome::kMediaCacheDirname);
133}
134
135bool HasACacheSubdir(const FilePath &dir) {
136 return file_util::PathExists(GetCachePath(dir)) ||
137 file_util::PathExists(GetMediaCachePath(dir));
138}
139
[email protected]57a777f72010-03-31 01:09:42140void PostExtensionLoadedToContextGetter(ChromeURLRequestContextGetter* getter,
141 Extension* extension) {
142 if (!getter)
143 return;
144 // Callee takes ownership of new ExtensionInfo struct.
145 ChromeThread::PostTask(
146 ChromeThread::IO, FROM_HERE,
147 NewRunnableMethod(getter,
148 &ChromeURLRequestContextGetter::OnNewExtensions,
149 extension->id(),
150 new ChromeURLRequestContext::ExtensionInfo(
[email protected]cb58c8cf2010-05-20 05:42:59151 extension->name(),
[email protected]57a777f72010-03-31 01:09:42152 extension->path(),
153 extension->default_locale(),
154 extension->web_extent(),
155 extension->api_permissions())));
156}
157
158void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
159 Extension* extension) {
160 if (!getter)
161 return;
162 ChromeThread::PostTask(
163 ChromeThread::IO, FROM_HERE,
164 NewRunnableMethod(getter,
165 &ChromeURLRequestContextGetter::OnUnloadedExtension,
166 extension->id()));
167}
168
[email protected]e5642992009-06-26 23:06:31169} // namespace
170
initial.commit09911bf2008-07-26 23:55:29171// A pointer to the request context for the default profile. See comments on
172// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31173URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29174
[email protected]be180c802009-10-23 06:33:31175static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19176 if (context)
[email protected]47accfd62009-05-14 18:46:21177 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21178}
179
[email protected]34cc84f2009-02-13 10:04:35180// static
[email protected]4bf6afd2009-10-08 14:00:11181const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
182
183// static
initial.commit09911bf2008-07-26 23:55:29184void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55185 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29186 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
187 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12188 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26189 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
190 IDS_SPELLCHECK_DICTIONARY);
191 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58192 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16193#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06194 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
195 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29196#endif
[email protected]f017cc92009-12-14 20:48:07197 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34198 prefs->RegisterStringPref(prefs::kCurrentThemeID,
199 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42200 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
201 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
202 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50203 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23204 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29205}
206
[email protected]34cc84f2009-02-13 10:04:35207// static
[email protected]f7011fcb2009-01-28 21:54:32208Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29209 return new ProfileImpl(path);
210}
211
[email protected]34cc84f2009-02-13 10:04:35212// static
[email protected]be180c802009-10-23 06:33:31213URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29214 return default_request_context_;
215}
216
[email protected]753efc42010-03-09 19:52:16217#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41218#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56219#elif defined(OS_MACOSX)
220#include "chrome/browser/keychain_mac.h"
221#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16222#elif defined(OS_POSIX)
223// Temporarily disabled while we figure some stuff out.
224// http://code.google.com/p/chromium/issues/detail?id=12351
225// #include "chrome/browser/password_manager/password_store_gnome.h"
226// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41227#endif
initial.commit09911bf2008-07-26 23:55:29228
initial.commit09911bf2008-07-26 23:55:29229////////////////////////////////////////////////////////////////////////////////
230//
231// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42232// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29233//
234////////////////////////////////////////////////////////////////////////////////
235class OffTheRecordProfileImpl : public Profile,
236 public NotificationObserver {
237 public:
238 explicit OffTheRecordProfileImpl(Profile* real_profile)
239 : profile_(real_profile),
240 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31241 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05242
initial.commit09911bf2008-07-26 23:55:29243 // Register for browser close notifications so we can detect when the last
244 // off-the-record window is closed, in which case we can clean our states
245 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43246 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
247 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29248 }
249
250 virtual ~OffTheRecordProfileImpl() {
[email protected]098c743d2010-05-04 07:58:59251 NotificationService::current()->Notify(
252 NotificationType::PROFILE_DESTROYED,
253 Source<Profile>(this),
254 NotificationService::NoDetails());
255 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29256 }
257
[email protected]4bf6afd2009-10-08 14:00:11258 virtual ProfileId GetRuntimeId() {
259 return reinterpret_cast<ProfileId>(this);
260 }
261
[email protected]a6d0f182010-01-12 08:01:44262 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29263
264 virtual bool IsOffTheRecord() {
265 return true;
266 }
267
268 virtual Profile* GetOffTheRecordProfile() {
269 return this;
270 }
271
[email protected]860f55492009-03-27 19:50:59272 virtual void DestroyOffTheRecordProfile() {
273 // Suicide is bad!
274 NOTREACHED();
275 }
276
initial.commit09911bf2008-07-26 23:55:29277 virtual Profile* GetOriginalProfile() {
278 return profile_;
279 }
280
[email protected]2f351cb2009-11-09 23:43:34281 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
282 if (!db_tracker_)
283 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
284 return db_tracker_;
285 }
286
initial.commit09911bf2008-07-26 23:55:29287 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49288 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
289 // because we don't want to leak the sites that the user has visited before.
290 return NULL;
initial.commit09911bf2008-07-26 23:55:29291 }
292
[email protected]6014d672008-12-05 00:38:25293 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21294 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25295 }
296
[email protected]0938d3c2009-01-09 20:37:35297 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21298 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25299 }
300
[email protected]89ebc7e2009-08-24 22:11:07301 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21302 // TODO(mpcomplete): figure out whether we should return the original
303 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07304 return NULL;
305 }
306
[email protected]481e1a42009-05-06 20:56:05307 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21308 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05309 }
310
[email protected]7120f132009-07-20 21:05:37311 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21312 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37313 }
314
[email protected]34cc84f2009-02-13 10:04:35315 virtual SSLHostState* GetSSLHostState() {
316 if (!ssl_host_state_.get())
317 ssl_host_state_.reset(new SSLHostState());
318
319 DCHECK(ssl_host_state_->CalledOnValidThread());
320 return ssl_host_state_.get();
321 }
322
[email protected]326e6792009-12-11 21:04:42323 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54324 if (!transport_security_state_.get())
325 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23326
[email protected]326e6792009-12-11 21:04:42327 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23328 }
329
initial.commit09911bf2008-07-26 23:55:29330 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54331 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29332 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54333
334 NOTREACHED() << "This profile is OffTheRecord";
335 return NULL;
initial.commit09911bf2008-07-26 23:55:29336 }
337
[email protected]0850fa62009-10-08 22:34:29338 virtual HistoryService* GetHistoryServiceWithoutCreating() {
339 return profile_->GetHistoryServiceWithoutCreating();
340 }
341
[email protected]0189bc722009-08-28 21:56:48342 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54343 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48344 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54345
346 NOTREACHED() << "This profile is OffTheRecord";
347 return NULL;
[email protected]0189bc722009-08-28 21:56:48348 }
349
[email protected]69c579e2010-04-23 20:01:00350 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
351 return profile_->GetAutocompleteClassifier();
[email protected]90085af02009-10-29 17:53:21352 }
353
initial.commit09911bf2008-07-26 23:55:29354 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54355 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29356 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54357
358 NOTREACHED() << "This profile is OffTheRecord";
359 return NULL;
initial.commit09911bf2008-07-26 23:55:29360 }
361
[email protected]9cddbe372009-10-23 21:23:53362 virtual WebDataService* GetWebDataServiceWithoutCreating() {
363 return profile_->GetWebDataServiceWithoutCreating();
364 }
365
[email protected]e69d33952009-06-03 22:00:41366 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54367 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41368 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54369
370 NOTREACHED() << "This profile is OffTheRecord";
371 return NULL;
[email protected]e69d33952009-06-03 22:00:41372 }
373
initial.commit09911bf2008-07-26 23:55:29374 virtual PrefService* GetPrefs() {
375 return profile_->GetPrefs();
376 }
377
378 virtual TemplateURLModel* GetTemplateURLModel() {
379 return profile_->GetTemplateURLModel();
380 }
381
382 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
383 return profile_->GetTemplateURLFetcher();
384 }
385
386 virtual DownloadManager* GetDownloadManager() {
387 if (!download_manager_.get()) {
388 scoped_refptr<DownloadManager> dlm(new DownloadManager);
389 dlm->Init(this);
390 download_manager_.swap(dlm);
391 }
392 return download_manager_.get();
393 }
394
395 virtual bool HasCreatedDownloadManager() const {
396 return (download_manager_.get() != NULL);
397 }
398
[email protected]def11712009-11-06 00:42:15399 virtual PersonalDataManager* GetPersonalDataManager() {
400 return NULL;
401 }
402
[email protected]4a190632009-05-09 01:07:42403 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54404 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42405 }
406
407 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54408 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42409 }
410
[email protected]a5166af62009-07-03 00:42:29411 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54412 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29413 }
414
[email protected]4a190632009-05-09 01:07:42415 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54416 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42417 }
418
[email protected]51c490b2009-08-03 16:34:34419 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54420 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34421 }
422
[email protected]5786d3d2009-12-18 00:18:44423 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54424 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42425 }
426
[email protected]be180c802009-10-23 06:33:31427 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29428 return request_context_;
429 }
430
[email protected]be180c802009-10-23 06:33:31431 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11432 // In OTR mode, media request context is the same as the original one.
433 return request_context_;
[email protected]e7f29642009-03-02 22:53:18434 }
435
[email protected]be180c802009-10-23 06:33:31436 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21437 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21438 }
439
[email protected]db36938c2009-08-19 21:48:42440 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54441 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42442 }
443
[email protected]e284e6d82010-01-29 19:49:45444 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]bd147842010-04-09 15:29:17445 // Retrieve the host content settings map of the parent profile in order to
446 // ensure the preferences have been migrated.
447 profile_->GetHostContentSettingsMap();
448 if (!host_content_settings_map_.get())
449 host_content_settings_map_ = new HostContentSettingsMap(this);
450 return host_content_settings_map_.get();
[email protected]e284e6d82010-01-29 19:49:45451 }
452
[email protected]40bd6582009-12-04 23:49:51453 virtual HostZoomMap* GetHostZoomMap() {
[email protected]c18d4f482010-05-18 21:19:50454 if (!host_zoom_map_)
455 host_zoom_map_ = new HostZoomMap(this);
456 return host_zoom_map_.get();
[email protected]40bd6582009-12-04 23:49:51457 }
458
[email protected]aee541e2010-03-19 01:52:45459 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
460 return profile_->GetGeolocationContentSettingsMap();
461 }
462
[email protected]8b4b84ee2010-05-11 13:08:52463 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() {
464 return profile_->GetGeolocationPermissionContext();
465 }
466
[email protected]8c6335d32010-01-20 09:21:50467 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54468 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23469 }
470
[email protected]6c32ce72010-03-08 05:18:06471 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
472 return profile_->GetUserStyleSheetWatcher();
473 }
474
[email protected]e5d2f7132010-04-09 18:13:53475 virtual FindBarState* GetFindBarState() {
476 if (!find_bar_state_.get())
477 find_bar_state_.reset(new FindBarState());
478 return find_bar_state_.get();
479 }
480
initial.commit09911bf2008-07-26 23:55:29481 virtual SessionService* GetSessionService() {
482 // Don't save any sessions when off the record.
483 return NULL;
484 }
485
486 virtual void ShutdownSessionService() {
487 // We don't allow a session service, nothing to do.
488 }
489
490 virtual bool HasSessionService() const {
491 // We never have a session service.
492 return false;
493 }
494
initial.commit09911bf2008-07-26 23:55:29495 virtual bool DidLastSessionExitCleanly() {
496 return profile_->DidLastSessionExitCleanly();
497 }
498
[email protected]d8e41ed2008-09-11 15:22:32499 virtual BookmarkModel* GetBookmarkModel() {
500 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29501 }
502
[email protected]4bb336302009-10-12 05:44:26503 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58504 if (!desktop_notification_service_.get()) {
505 desktop_notification_service_.reset(new DesktopNotificationService(
506 this, g_browser_process->notification_ui_manager()));
507 }
508 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26509 }
510
[email protected]48352c12009-08-15 01:19:11511 virtual ProfileSyncService* GetProfileSyncService() {
512 return NULL;
[email protected]3a453fa2008-08-15 18:46:34513 }
[email protected]3a453fa2008-08-15 18:46:34514
[email protected]1bd056e2010-04-20 02:03:48515 virtual CloudPrintProxyService* GetCloudPrintProxyService() {
516 return NULL;
517 }
518
initial.commit09911bf2008-07-26 23:55:29519 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54520 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29521 }
522
523 virtual Time GetStartTime() const {
524 return start_time_;
525 }
526
527 virtual TabRestoreService* GetTabRestoreService() {
528 return NULL;
529 }
530
[email protected]e7244d82008-10-29 18:13:26531 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41532 }
533
[email protected]85c55dc2009-11-06 03:05:46534 virtual SpellCheckHost* GetSpellCheckHost() {
535 return profile_->GetSpellCheckHost();
536 }
537
538 virtual void ReinitializeSpellCheckHost(bool force) {
539 profile_->ReinitializeSpellCheckHost(force);
540 }
[email protected]85c55dc2009-11-06 03:05:46541
[email protected]3bf335a2009-06-26 20:46:06542 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29543 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:11544 webkit_context_ = new WebKitContext(this);
[email protected]c27324b2009-11-19 22:44:29545 DCHECK(webkit_context_.get());
546 return webkit_context_.get();
547 }
[email protected]3bf335a2009-06-26 20:46:06548
[email protected]449478302009-06-09 20:04:28549 virtual ThumbnailStore* GetThumbnailStore() {
550 return NULL;
551 }
552
[email protected]523623c2010-05-19 16:03:42553 virtual history::TopSites* GetTopSites() {
554 return NULL;
555 }
556
initial.commit09911bf2008-07-26 23:55:29557 virtual void MarkAsCleanShutdown() {
558 }
559
[email protected]bdbc87c2009-01-25 05:08:54560 virtual void InitExtensions() {
561 NOTREACHED();
562 }
563
[email protected]ea0c98cf2009-06-18 23:02:54564 virtual void InitWebResources() {
565 NOTREACHED();
566 }
567
[email protected]9c8dd902009-11-19 17:50:42568 virtual NTPResourceCache* GetNTPResourceCache() {
569 // Just return the real profile resource cache.
570 return profile_->GetNTPResourceCache();
571 }
572
initial.commit09911bf2008-07-26 23:55:29573 virtual void ExitedOffTheRecordMode() {
574 // Drop our download manager so we forget about all the downloads made
575 // in off-the-record mode.
576 download_manager_ = NULL;
577 }
578
579 virtual void Observe(NotificationType type,
580 const NotificationSource& source,
581 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56582 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29583 // We are only interested in OTR browser closing.
584 if (Source<Browser>(source)->profile() != this)
585 return;
586
587 // Let's check if we still have an Off The Record window opened.
588 // Note that we check against 1 as this notification is sent before the
589 // browser window is actually removed from the list.
590 if (BrowserList::GetBrowserCount(this) <= 1)
591 ExitedOffTheRecordMode();
592 }
593
594 private:
[email protected]88cf3292009-05-22 01:48:43595 NotificationRegistrar registrar_;
596
initial.commit09911bf2008-07-26 23:55:29597 // The real underlying profile.
598 Profile* profile_;
599
[email protected]6ab9b202008-12-23 22:34:50600 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19601 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29602
603 // The download manager that only stores downloaded items in memory.
604 scoped_refptr<DownloadManager> download_manager_;
605
[email protected]7d7696c52009-12-01 20:54:58606 // Use a separate desktop notification service for OTR.
607 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
608
[email protected]bd147842010-04-09 15:29:17609 // We use a non-writable content settings map for OTR.
610 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
611
[email protected]c18d4f482010-05-18 21:19:50612 // Use a separate zoom map for OTR.
613 scoped_refptr<HostZoomMap> host_zoom_map_;
614
[email protected]3bf335a2009-06-26 20:46:06615 // Use a special WebKit context for OTR browsing.
616 scoped_refptr<WebKitContext> webkit_context_;
617
[email protected]34cc84f2009-02-13 10:04:35618 // We don't want SSLHostState from the OTR profile to leak back to the main
619 // profile because then the main profile would learn some of the host names
620 // the user visited while OTR.
621 scoped_ptr<SSLHostState> ssl_host_state_;
622
[email protected]e5d2f7132010-04-09 18:13:53623 // Use a separate FindBarState so search terms do not leak back to the main
624 // profile.
625 scoped_ptr<FindBarState> find_bar_state_;
626
[email protected]326e6792009-12-11 21:04:42627 // The TransportSecurityState that only stores enabled sites in memory.
628 scoped_refptr<net::TransportSecurityState>
629 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23630
initial.commit09911bf2008-07-26 23:55:29631 // Time we were started.
632 Time start_time_;
633
[email protected]2f351cb2009-11-09 23:43:34634 // The main database tracker for this profile.
635 // Should be used only on the file thread.
636 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
637
[email protected]90085af02009-10-29 17:53:21638 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29639};
640
[email protected]f7011fcb2009-01-28 21:54:32641ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29642 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44643 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07644 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32645 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57646 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21647 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45648 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51649 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32650 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48651 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32652 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41653 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32654 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42655 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32656 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46657 spellcheck_host_(NULL),
658 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29659 shutdown_session_service_(false) {
660 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
661 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14662 create_session_service_timer_.Start(
663 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
664 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54665
[email protected]89ebc7e2009-08-24 22:11:07666 if (CommandLine::ForCurrentProcess()->HasSwitch(
667 switches::kEnableExtensionTimelineApi)) {
668 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
669 }
670
[email protected]382a0702009-06-26 17:12:27671 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37672 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27673
[email protected]e7244d82008-10-29 18:13:26674 PrefService* prefs = GetPrefs();
675 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
676 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58677 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58678
[email protected]405a64b2009-09-16 21:03:44679#if defined(OS_MACOSX)
680 // If the profile directory doesn't already have a cache directory and it
681 // is under ~/Library/Application Support, use a suitable cache directory
682 // under ~/Library/Caches. For example, a profile directory of
683 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
684 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
685 // ~/Library/Caches/Google/Chrome/MyProfileName.
686 //
687 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44688 if (!HasACacheSubdir(path_)) {
689 FilePath app_data_path, user_cache_path;
690 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12691 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44692 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
693 base_cache_path_ = user_cache_path;
694 }
695 }
[email protected]9e9b6e8e2009-12-02 08:45:01696#elif defined(OS_POSIX) // Posix minus Mac.
697 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
698 // for a spec on where cache files go. The net effect for most systems is we
699 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
700 // official builds.
701 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
702#if defined(GOOGLE_CHROME_BUILD)
703 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44704#else
[email protected]9e9b6e8e2009-12-02 08:45:01705 const char kCacheDir[] = "chromium";
706#endif
707 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
708 base_cache_path_ = base_cache_path_.Append(kCacheDir);
709 if (!file_util::PathExists(base_cache_path_))
710 file_util::CreateDirectory(base_cache_path_);
711 }
[email protected]405a64b2009-09-16 21:03:44712#endif
[email protected]bc96d562009-08-11 18:45:13713 if (base_cache_path_.empty())
714 base_cache_path_ = path_;
715
[email protected]4a190632009-05-09 01:07:42716 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43717 registrar_.Add(this, NotificationType::THEME_INSTALLED,
718 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11719
720 // Listen for bookmark model load, to bootstrap the sync service.
721 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
722 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42723
724 ssl_config_service_manager_.reset(
725 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53726
727#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29728 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53729#endif
[email protected]911f8152010-03-18 16:46:40730
731 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29732}
733
[email protected]bdbc87c2009-01-25 05:08:54734void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41735 if (user_script_master_ || extensions_service_)
736 return; // Already initialized.
737
[email protected]bdbc87c2009-01-25 05:08:54738 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18739 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36740
741 FilePath script_dir; // Don't look for user scripts in any directory.
742 // TODO(aa): We should just remove this functionality,
743 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51744 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36745
[email protected]894bb502009-05-21 22:39:57746 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23747 this,
748 CommandLine::ForCurrentProcess(),
749 GetPrefs(),
750 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36751 true);
[email protected]bdbc87c2009-01-25 05:08:54752
[email protected]fee67982010-04-23 17:24:22753 // Register the component extensions.
754 std::map<std::string, int> component_extensions;
755
756 // Bookmark manager.
[email protected]47e532b2010-04-23 17:46:40757 component_extensions["bookmark_manager"] = IDR_BOOKMARKS_MANIFEST;
[email protected]fee67982010-04-23 17:24:22758
[email protected]abdc9fb52010-05-06 01:44:48759#if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
[email protected]ae90f252010-05-04 18:28:03760 // Chat manager.
761 if (CommandLine::ForCurrentProcess()->HasSwitch(
762 switches::kEnableChatManager)) {
763 component_extensions["chat_manager"] = IDR_CHAT_MANAGER_MANIFEST;
764 }
765#endif
766
[email protected]fee67982010-04-23 17:24:22767 // Some sample apps to make our lives easier while we are developing extension
768 // apps. This way we don't have to constantly install these over and over.
[email protected]2bce5e12010-05-13 01:18:07769 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableApps)) {
[email protected]fee67982010-04-23 17:24:22770#if defined(OS_WIN)
771 std::string user_domain;
772 if (base::EnvVarGetter::Create()->GetEnv("USERDOMAIN", &user_domain) &&
773 user_domain == "GOOGLE") {
774 component_extensions["gmail_app"] = IDR_GMAIL_APP_MANIFEST;
775 component_extensions["calendar_app"] = IDR_CALENDAR_APP_MANIFEST;
776 component_extensions["docs_app"] = IDR_DOCS_APP_MANIFEST;
777 }
778#endif
779 }
780
781 for (std::map<std::string, int>::iterator iter = component_extensions.begin();
782 iter != component_extensions.end(); ++iter) {
783 FilePath path;
784 if (PathService::Get(chrome::DIR_RESOURCES, &path)) {
785 path = path.AppendASCII(iter->first);
[email protected]1952c7d2010-03-04 23:48:34786 } else {
787 NOTREACHED();
788 }
[email protected]fee67982010-04-23 17:24:22789
790 std::string manifest =
791 ResourceBundle::GetSharedInstance().GetRawDataResource(
792 iter->second).as_string();
793 extensions_service_->register_component_extension(
794 ExtensionsService::ComponentExtensionInfo(manifest, path));
[email protected]1952c7d2010-03-04 23:48:34795 }
796
[email protected]9197f3b2009-06-02 00:49:27797 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12798
799 // Load any extensions specified with --load-extension.
800 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10801 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12802 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12803 }
[email protected]bdbc87c2009-01-25 05:08:54804}
805
[email protected]ea0c98cf2009-06-18 23:02:54806void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07807 if (web_resource_service_)
808 return; // Already initialized.
809
[email protected]6fad2632009-11-02 05:59:37810 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54811 web_resource_service_->StartAfterDelay();
812}
813
[email protected]9c8dd902009-11-19 17:50:42814NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
815 if (!ntp_resource_cache_.get())
816 ntp_resource_cache_.reset(new NTPResourceCache(this));
817 return ntp_resource_cache_.get();
818}
819
initial.commit09911bf2008-07-26 23:55:29820ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56821 NotificationService::current()->Notify(
822 NotificationType::PROFILE_DESTROYED,
823 Source<Profile>(this),
824 NotificationService::NoDetails());
825
[email protected]169627b2008-12-06 19:30:19826 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29827
828 StopCreateSessionServiceTimer();
829 // TemplateURLModel schedules a task on the WebDataService from its
830 // destructor. Delete it first to ensure the task gets scheduled before we
831 // shut down the database.
832 template_url_model_.reset();
833
834 // The download manager queries the history system and should be deleted
835 // before the history is shutdown so it can properly cancel all requests.
836 download_manager_ = NULL;
837
[email protected]4a190632009-05-09 01:07:42838 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15839 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42840
[email protected]44961292009-07-20 20:03:09841 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
842 // save any new thumbnails to disk and release its reference to the
843 // HistoryService.
844 if (thumbnail_store_.get())
845 thumbnail_store_->Shutdown();
846
[email protected]e7244d82008-10-29 18:13:26847 // Remove pref observers.
848 PrefService* prefs = GetPrefs();
849 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
850 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58851 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26852
[email protected]9c8dd902009-11-19 17:50:42853 // Delete the NTP resource cache so we can unregister pref observers.
854 ntp_resource_cache_.reset();
855
[email protected]48352c12009-08-15 01:19:11856 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34857
initial.commit09911bf2008-07-26 23:55:29858 // Both HistoryService and WebDataService maintain threads for background
859 // processing. Its possible each thread still has tasks on it that have
860 // increased the ref count of the service. In such a situation, when we
861 // decrement the refcount, it won't be 0, and the threads/databases aren't
862 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
863 // databases are properly closed.
864 if (web_data_service_.get())
865 web_data_service_->Shutdown();
866
867 if (history_service_.get())
868 history_service_->Cleanup();
869
[email protected]85c55dc2009-11-06 03:05:46870 if (spellcheck_host_.get())
871 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29872
[email protected]cfc06f122009-11-16 22:18:55873 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21874 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50875
[email protected]47accfd62009-05-14 18:46:21876 CleanupRequestContext(request_context_);
877 CleanupRequestContext(media_request_context_);
878 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17879
[email protected]d8e41ed2008-09-11 15:22:32880 // HistoryService may call into the BookmarkModel, as such we need to
881 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46882 // HistoryService will join with HistoryService's backend thread so that
883 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32884 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46885 history_service_ = NULL;
886 bookmark_bar_model_.reset();
887
[email protected]0189bc722009-08-28 21:56:48888 // FaviconService depends on HistoryServce so make sure we delete
889 // HistoryService first.
890 favicon_service_ = NULL;
891
[email protected]7120f132009-07-20 21:05:37892 extension_message_service_->ProfileDestroyed();
893
[email protected]6ef635e42009-07-26 06:16:12894 if (extensions_service_)
895 extensions_service_->ProfileDestroyed();
896
[email protected]66da08b2009-10-19 22:27:00897 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29898 MarkAsCleanShutdown();
899}
900
[email protected]4bf6afd2009-10-08 14:00:11901ProfileId ProfileImpl::GetRuntimeId() {
902 return reinterpret_cast<ProfileId>(this);
903}
904
[email protected]f7011fcb2009-01-28 21:54:32905FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29906 return path_;
907}
908
909bool ProfileImpl::IsOffTheRecord() {
910 return false;
911}
912
913Profile* ProfileImpl::GetOffTheRecordProfile() {
914 if (!off_the_record_profile_.get()) {
915 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
916 off_the_record_profile_.swap(p);
917 }
918 return off_the_record_profile_.get();
919}
920
[email protected]860f55492009-03-27 19:50:59921void ProfileImpl::DestroyOffTheRecordProfile() {
922 off_the_record_profile_.reset();
923}
924
initial.commit09911bf2008-07-26 23:55:29925Profile* ProfileImpl::GetOriginalProfile() {
926 return this;
927}
928
[email protected]2f351cb2009-11-09 23:43:34929webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
930 if (!db_tracker_)
931 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
932 return db_tracker_;
933}
934
initial.commit09911bf2008-07-26 23:55:29935VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44936 if (!visited_link_master_.get()) {
937 scoped_ptr<VisitedLinkMaster> visited_links(
938 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
939 if (!visited_links->Init())
940 return NULL;
941 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53942 }
[email protected]a6d0f182010-01-12 08:01:44943
944 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29945}
946
[email protected]6014d672008-12-05 00:38:25947ExtensionsService* ProfileImpl::GetExtensionsService() {
948 return extensions_service_.get();
949}
950
[email protected]0938d3c2009-01-09 20:37:35951UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35952 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25953}
954
[email protected]89ebc7e2009-08-24 22:11:07955ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
956 return extension_devtools_manager_.get();
957}
958
[email protected]481e1a42009-05-06 20:56:05959ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27960 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05961}
962
[email protected]7120f132009-07-20 21:05:37963ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
964 return extension_message_service_.get();
965}
966
[email protected]34cc84f2009-02-13 10:04:35967SSLHostState* ProfileImpl::GetSSLHostState() {
968 if (!ssl_host_state_.get())
969 ssl_host_state_.reset(new SSLHostState());
970
971 DCHECK(ssl_host_state_->CalledOnValidThread());
972 return ssl_host_state_.get();
973}
974
[email protected]326e6792009-12-11 21:04:42975net::TransportSecurityState*
976 ProfileImpl::GetTransportSecurityState() {
977 if (!transport_security_state_.get()) {
978 transport_security_state_ = new net::TransportSecurityState();
979 transport_security_persister_ =
980 new TransportSecurityPersister();
981 transport_security_persister_->Initialize(
982 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51983 }
[email protected]a9cea7542009-05-20 04:30:23984
[email protected]326e6792009-12-11 21:04:42985 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23986}
987
initial.commit09911bf2008-07-26 23:55:29988PrefService* ProfileImpl::GetPrefs() {
989 if (!prefs_.get()) {
[email protected]ea587b02010-05-21 15:01:35990 prefs_.reset(new PrefService(
991 new JsonPrefStore(
992 GetPrefFilePath(),
993 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE))));
initial.commit09911bf2008-07-26 23:55:29994
995 // The Profile class and ProfileManager class may read some prefs so
996 // register known prefs as soon as possible.
997 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51998 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29999
1000 // The last session exited cleanly if there is no pref for
1001 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
1002 last_session_exited_cleanly_ =
1003 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
1004 // Mark the session as open.
1005 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
1006 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:361007 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291008 }
1009
1010 return prefs_.get();
1011}
1012
[email protected]f7011fcb2009-01-28 21:54:321013FilePath ProfileImpl::GetPrefFilePath() {
1014 FilePath pref_file_path = path_;
1015 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:291016 return pref_file_path;
1017}
1018
[email protected]be180c802009-10-23 06:33:311019URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:291020 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:321021 FilePath cookie_path = GetPath();
1022 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:131023 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311024 int max_size;
1025 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:421026
[email protected]405a64b2009-09-16 21:03:441027 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311028 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
1029 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:291030
[email protected]6ab9b202008-12-23 22:34:501031 // The first request context is always a normal (non-OTR) request context.
1032 // Even when Chromium is started in OTR mode, a normal profile is always
1033 // created first.
1034 if (!default_request_context_) {
1035 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:311036 // TODO(eroman): this isn't terribly useful anymore now that the
1037 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:501038 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561039 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:501040 NotificationService::AllSources(), NotificationService::NoDetails());
1041 }
initial.commit09911bf2008-07-26 23:55:291042 }
1043
1044 return request_context_;
1045}
1046
[email protected]be180c802009-10-23 06:33:311047URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:181048 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:131049 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311050 int max_size;
1051 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:141052
[email protected]405a64b2009-09-16 21:03:441053 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311054 media_request_context_ =
1055 ChromeURLRequestContextGetter::CreateOriginalForMedia(
1056 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:181057 }
1058
1059 return media_request_context_;
1060}
1061
[email protected]0189bc722009-08-28 21:56:481062FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
1063 if (!favicon_service_created_) {
1064 favicon_service_created_ = true;
1065 scoped_refptr<FaviconService> service(new FaviconService(this));
1066 favicon_service_.swap(service);
1067 }
1068 return favicon_service_.get();
1069}
1070
[email protected]be180c802009-10-23 06:33:311071URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:211072 if (!extensions_request_context_) {
1073 FilePath cookie_path = GetPath();
1074 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1075
1076 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:311077 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
1078 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:211079 }
1080
1081 return extensions_request_context_;
1082}
1083
[email protected]57a777f72010-03-31 01:09:421084void ProfileImpl::RegisterExtensionWithRequestContexts(
1085 Extension* extension) {
1086 // Notify the default, extension and media contexts on the IO thread.
1087 PostExtensionLoadedToContextGetter(
1088 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1089 extension);
1090 PostExtensionLoadedToContextGetter(
1091 static_cast<ChromeURLRequestContextGetter*>(
1092 GetRequestContextForExtensions()),
1093 extension);
1094 PostExtensionLoadedToContextGetter(
1095 static_cast<ChromeURLRequestContextGetter*>(
1096 GetRequestContextForMedia()),
1097 extension);
1098}
1099
1100void ProfileImpl::UnregisterExtensionWithRequestContexts(
1101 Extension* extension) {
1102 // Notify the default, extension and media contexts on the IO thread.
1103 PostExtensionUnloadedToContextGetter(
1104 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1105 extension);
1106 PostExtensionUnloadedToContextGetter(
1107 static_cast<ChromeURLRequestContextGetter*>(
1108 GetRequestContextForExtensions()),
1109 extension);
1110 PostExtensionUnloadedToContextGetter(
1111 static_cast<ChromeURLRequestContextGetter*>(
1112 GetRequestContextForMedia()),
1113 extension);
1114}
1115
[email protected]db36938c2009-08-19 21:48:421116net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1117 return ssl_config_service_manager_->Get();
1118}
1119
[email protected]e284e6d82010-01-29 19:49:451120HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
1121 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:391122 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:451123 return host_content_settings_map_.get();
1124}
1125
[email protected]40bd6582009-12-04 23:49:511126HostZoomMap* ProfileImpl::GetHostZoomMap() {
1127 if (!host_zoom_map_)
1128 host_zoom_map_ = new HostZoomMap(this);
1129 return host_zoom_map_.get();
1130}
1131
[email protected]aee541e2010-03-19 01:52:451132GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
1133 if (!geolocation_content_settings_map_.get())
1134 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
1135 return geolocation_content_settings_map_.get();
1136}
1137
[email protected]8b4b84ee2010-05-11 13:08:521138GeolocationPermissionContext* ProfileImpl::GetGeolocationPermissionContext() {
1139 if (!geolocation_permission_context_.get())
1140 geolocation_permission_context_ = new GeolocationPermissionContext(this);
1141 return geolocation_permission_context_.get();
1142}
1143
[email protected]8c6335d32010-01-20 09:21:501144Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271145 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141146 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271147 return NULL;
[email protected]c37f8b42010-01-23 16:22:141148 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541149 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501150 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231151}
1152
[email protected]6c32ce72010-03-08 05:18:061153UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1154 if (!user_style_sheet_watcher_.get()) {
1155 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1156 user_style_sheet_watcher_->Init();
1157 }
1158 return user_style_sheet_watcher_.get();
1159}
1160
[email protected]e5d2f7132010-04-09 18:13:531161FindBarState* ProfileImpl::GetFindBarState() {
1162 if (!find_bar_state_.get()) {
1163 find_bar_state_.reset(new FindBarState());
1164 }
1165 return find_bar_state_.get();
1166}
1167
initial.commit09911bf2008-07-26 23:55:291168HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1169 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461170 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291171 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321172 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291173 return NULL;
1174 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291175
1176 // Send out the notification that the history service was created.
1177 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561178 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291179 Details<HistoryService>(history_service_.get()));
1180 }
1181 return history_service_.get();
1182}
1183
[email protected]0850fa62009-10-08 22:34:291184HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1185 return history_service_.get();
1186}
1187
initial.commit09911bf2008-07-26 23:55:291188TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1189 if (!template_url_model_.get())
1190 template_url_model_.reset(new TemplateURLModel(this));
1191 return template_url_model_.get();
1192}
1193
1194TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1195 if (!template_url_fetcher_.get())
1196 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1197 return template_url_fetcher_.get();
1198}
1199
[email protected]69c579e2010-04-23 20:01:001200AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
1201 if (!autocomplete_classifier_.get())
1202 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
1203 return autocomplete_classifier_.get();
[email protected]90085af02009-10-29 17:53:211204}
1205
initial.commit09911bf2008-07-26 23:55:291206WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1207 if (!created_web_data_service_)
1208 CreateWebDataService();
1209 return web_data_service_.get();
1210}
1211
[email protected]9cddbe372009-10-23 21:23:531212WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1213 return web_data_service_.get();
1214}
1215
initial.commit09911bf2008-07-26 23:55:291216void ProfileImpl::CreateWebDataService() {
1217 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1218 created_web_data_service_ = true;
1219 scoped_refptr<WebDataService> wds(new WebDataService());
1220 if (!wds->Init(GetPath()))
1221 return;
1222 web_data_service_.swap(wds);
1223}
1224
[email protected]e69d33952009-06-03 22:00:411225PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1226 if (!created_password_store_)
1227 CreatePasswordStore();
1228 return password_store_.get();
1229}
1230
1231void ProfileImpl::CreatePasswordStore() {
1232 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1233 created_password_store_ = true;
1234 scoped_refptr<PasswordStore> ps;
[email protected]e0411ae52009-06-30 23:59:171235 FilePath login_db_file_path = GetPath();
1236 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
[email protected]ec44cd52010-04-05 22:30:471237 LoginDatabase* login_db = new LoginDatabase();
[email protected]e0411ae52009-06-30 23:59:171238 if (!login_db->Init(login_db_file_path)) {
1239 LOG(ERROR) << "Could not initialize login database.";
1240 delete login_db;
1241 return;
1242 }
[email protected]e8380f52010-04-30 16:39:421243#if defined(OS_WIN)
1244 ps = new PasswordStoreWin(login_db, this,
1245 GetWebDataService(Profile::IMPLICIT_ACCESS));
1246#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171247 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161248#elif defined(OS_POSIX)
1249 // TODO(evanm): implement "native" password management.
1250 // This bug describes the issues.
1251 // http://code.google.com/p/chromium/issues/detail?id=12351
[email protected]e8380f52010-04-30 16:39:421252 ps = new PasswordStoreDefault(login_db, this,
1253 GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]e69d33952009-06-03 22:00:411254#else
1255 NOTIMPLEMENTED();
1256#endif
[email protected]e8380f52010-04-30 16:39:421257 if (!ps)
1258 delete login_db;
1259
[email protected]e69d33952009-06-03 22:00:411260 if (!ps || !ps->Init()) {
[email protected]e8380f52010-04-30 16:39:421261 NOTREACHED() << "Could not initialise password manager";
1262 return;
[email protected]e69d33952009-06-03 22:00:411263 }
1264 password_store_.swap(ps);
1265}
1266
initial.commit09911bf2008-07-26 23:55:291267DownloadManager* ProfileImpl::GetDownloadManager() {
1268 if (!created_download_manager_) {
1269 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1270 dlm->Init(this);
1271 created_download_manager_ = true;
1272 download_manager_.swap(dlm);
1273 }
1274 return download_manager_.get();
1275}
1276
1277bool ProfileImpl::HasCreatedDownloadManager() const {
1278 return created_download_manager_;
1279}
1280
[email protected]def11712009-11-06 00:42:151281PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1282 if (!personal_data_manager_.get()) {
[email protected]e0976a72010-04-02 01:25:241283 personal_data_manager_.reset(new PersonalDataManager());
1284 personal_data_manager_->Init(this);
[email protected]def11712009-11-06 00:42:151285 }
1286 return personal_data_manager_.get();
1287}
1288
[email protected]4a190632009-05-09 01:07:421289void ProfileImpl::InitThemes() {
1290 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161291#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151292 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291293#else
[email protected]761962c2009-09-25 00:18:151294 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291295#endif
[email protected]761962c2009-09-25 00:18:151296 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421297 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421298 }
1299}
1300
1301void ProfileImpl::SetTheme(Extension* extension) {
1302 InitThemes();
1303 theme_provider_.get()->SetTheme(extension);
1304}
1305
[email protected]a5166af62009-07-03 00:42:291306void ProfileImpl::SetNativeTheme() {
1307 InitThemes();
1308 theme_provider_.get()->SetNativeTheme();
1309}
1310
[email protected]4a190632009-05-09 01:07:421311void ProfileImpl::ClearTheme() {
1312 InitThemes();
1313 theme_provider_.get()->UseDefaultTheme();
1314}
1315
[email protected]51c490b2009-08-03 16:34:341316Extension* ProfileImpl::GetTheme() {
1317 InitThemes();
1318
1319 std::string id = theme_provider_.get()->GetThemeID();
1320 if (id == BrowserThemeProvider::kDefaultThemeID)
1321 return NULL;
1322
[email protected]61b411612009-11-10 23:17:411323 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341324}
1325
[email protected]5786d3d2009-12-18 00:18:441326BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421327 InitThemes();
1328 return theme_provider_.get();
1329}
1330
initial.commit09911bf2008-07-26 23:55:291331SessionService* ProfileImpl::GetSessionService() {
1332 if (!session_service_.get() && !shutdown_session_service_) {
1333 session_service_ = new SessionService(this);
1334 session_service_->ResetFromCurrentBrowsers();
1335 }
1336 return session_service_.get();
1337}
1338
1339void ProfileImpl::ShutdownSessionService() {
1340 if (shutdown_session_service_)
1341 return;
1342
1343 // We're about to exit, force creation of the session service if it hasn't
1344 // been created yet. We do this to ensure session state matches the point in
1345 // time the user exited.
1346 GetSessionService();
1347 shutdown_session_service_ = true;
1348 session_service_ = NULL;
1349}
1350
1351bool ProfileImpl::HasSessionService() const {
1352 return (session_service_.get() != NULL);
1353}
1354
initial.commit09911bf2008-07-26 23:55:291355bool ProfileImpl::DidLastSessionExitCleanly() {
1356 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1357 // it to be set by asking for the prefs.
1358 GetPrefs();
1359 return last_session_exited_cleanly_;
1360}
1361
[email protected]d8e41ed2008-09-11 15:22:321362BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461363 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321364 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461365 bookmark_bar_model_->Load();
1366 }
initial.commit09911bf2008-07-26 23:55:291367 return bookmark_bar_model_.get();
1368}
1369
1370bool ProfileImpl::IsSameProfile(Profile* profile) {
1371 if (profile == static_cast<Profile*>(this))
1372 return true;
1373 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1374 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1375}
1376
1377Time ProfileImpl::GetStartTime() const {
1378 return start_time_;
1379}
1380
1381TabRestoreService* ProfileImpl::GetTabRestoreService() {
1382 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191383 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291384 return tab_restore_service_.get();
1385}
1386
[email protected]449478302009-06-09 20:04:281387ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1388 if (!thumbnail_store_.get()) {
1389 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251390 thumbnail_store_->Init(
1391 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281392 }
1393 return thumbnail_store_.get();
1394}
1395
[email protected]523623c2010-05-19 16:03:421396history::TopSites* ProfileImpl::GetTopSites() {
1397 if (!top_sites_.get()) {
1398 top_sites_ = new history::TopSites(this);
1399 top_sites_->Init();
1400 }
1401 return top_sites_;
1402}
1403
initial.commit09911bf2008-07-26 23:55:291404void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191405 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291406}
1407
[email protected]85c55dc2009-11-06 03:05:461408SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1409 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1410}
1411
1412void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1413 // If we are already loading the spellchecker, and this is just a hint to
1414 // load the spellchecker, do nothing.
1415 if (!force && spellcheck_host_.get())
1416 return;
1417
[email protected]f41301e2009-11-16 21:30:071418 spellcheck_host_ready_ = false;
1419
[email protected]85c55dc2009-11-06 03:05:461420 bool notify = false;
1421 if (spellcheck_host_.get()) {
1422 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051423 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461424 notify = true;
1425 }
1426
1427 PrefService* prefs = GetPrefs();
1428 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1429 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1430 spellcheck_host_ = new SpellCheckHost(this,
1431 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1432 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071433 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461434 } else if (notify) {
1435 // The spellchecker has been disabled.
1436 SpellCheckHostInitialized();
1437 }
1438}
1439
1440void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171441 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291442 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1443 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461444 NotificationService::current()->Notify(
1445 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1446 Source<Profile>(this), NotificationService::NoDetails());
1447}
initial.commit09911bf2008-07-26 23:55:291448
[email protected]3bf335a2009-06-26 20:46:061449WebKitContext* ProfileImpl::GetWebKitContext() {
1450 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:111451 webkit_context_ = new WebKitContext(this);
[email protected]3bf335a2009-06-26 20:46:061452 DCHECK(webkit_context_.get());
1453 return webkit_context_.get();
1454}
1455
[email protected]4bb336302009-10-12 05:44:261456DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1457 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1458 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261459 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031460 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261461 }
[email protected]4bb336302009-10-12 05:44:261462 return desktop_notification_service_.get();
1463}
1464
initial.commit09911bf2008-07-26 23:55:291465void ProfileImpl::MarkAsCleanShutdown() {
1466 if (prefs_.get()) {
1467 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1468 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1469
1470 // NOTE: If you change what thread this writes on, be sure and update
1471 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361472 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291473 }
1474}
1475
[email protected]e7244d82008-10-29 18:13:261476void ProfileImpl::Observe(NotificationType type,
1477 const NotificationSource& source,
1478 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561479 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261480 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1481 PrefService* prefs = Source<PrefService>(source).ptr();
1482 DCHECK(pref_name_in && prefs);
1483 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461484 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461485 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291486 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1487 NotificationService::current()->Notify(
1488 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1489 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261490 }
[email protected]4a190632009-05-09 01:07:421491 } else if (NotificationType::THEME_INSTALLED == type) {
1492 Extension* extension = Details<Extension>(details).ptr();
1493 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111494 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1495 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1496 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1497 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261498 }
1499}
1500
initial.commit09911bf2008-07-26 23:55:291501void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141502 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291503}
[email protected]3a453fa2008-08-15 18:46:341504
[email protected]48352c12009-08-15 01:19:111505ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431506 if (!ProfileSyncService::IsSyncEnabled()) {
1507 return NULL;
[email protected]7367f1a2009-10-10 01:09:441508 }
[email protected]eec3bcfa2009-11-12 17:23:431509 if (!sync_service_.get())
1510 InitSyncService();
1511 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111512}
1513
[email protected]1bd056e2010-04-20 02:03:481514CloudPrintProxyService* ProfileImpl::GetCloudPrintProxyService() {
1515 if (!cloud_print_proxy_service_.get())
1516 InitCloudPrintProxyService();
1517 return cloud_print_proxy_service_.get();
1518}
1519
[email protected]48352c12009-08-15 01:19:111520void ProfileImpl::InitSyncService() {
[email protected]82d9d2952010-05-15 00:36:161521 network_change_notifier_thread_.reset(
1522 new NetworkChangeNotifierIOThread(g_browser_process->io_thread()));
[email protected]4aea04a2010-02-10 20:13:431523 profile_sync_factory_.reset(
1524 new ProfileSyncFactoryImpl(this,
[email protected]82d9d2952010-05-15 00:36:161525 network_change_notifier_thread_.get(),
[email protected]4aea04a2010-02-10 20:13:431526 CommandLine::ForCurrentProcess()));
1527 sync_service_.reset(
1528 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111529 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111530}
[email protected]1bd056e2010-04-20 02:03:481531
1532void ProfileImpl::InitCloudPrintProxyService() {
1533 cloud_print_proxy_service_.reset(new CloudPrintProxyService(this));
1534 cloud_print_proxy_service_->Initialize();
1535}