blob: c8a1559c77f072f584fdcba14384cbdda4eee735 [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]277404c22010-04-22 13:09:4544#include "chrome/browser/json_pref_store.h"
[email protected]6ab9b202008-12-23 22:34:5045#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4246#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2647#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4148#include "chrome/browser/password_manager/password_store_default.h"
[email protected]8c6335d32010-01-20 09:21:5049#include "chrome/browser/privacy_blacklist/blacklist.h"
[email protected]1bd056e2010-04-20 02:03:4850#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
initial.commit09911bf2008-07-26 23:55:2951#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2652#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3353#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4654#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4455#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3056#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3357#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]82d9d2952010-05-15 00:36:1658#include "chrome/browser/sync/net/network_change_notifier_io_thread.h"
[email protected]48352c12009-08-15 01:19:1159#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4360#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4061#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2862#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0663#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2964#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3965#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2966#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5667#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2968#include "chrome/common/chrome_constants.h"
69#include "chrome/common/chrome_paths.h"
70#include "chrome/common/chrome_switches.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(
151 extension->path(),
152 extension->default_locale(),
153 extension->web_extent(),
154 extension->api_permissions())));
155}
156
157void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
158 Extension* extension) {
159 if (!getter)
160 return;
161 ChromeThread::PostTask(
162 ChromeThread::IO, FROM_HERE,
163 NewRunnableMethod(getter,
164 &ChromeURLRequestContextGetter::OnUnloadedExtension,
165 extension->id()));
166}
167
[email protected]e5642992009-06-26 23:06:31168} // namespace
169
initial.commit09911bf2008-07-26 23:55:29170// A pointer to the request context for the default profile. See comments on
171// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31172URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29173
[email protected]be180c802009-10-23 06:33:31174static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19175 if (context)
[email protected]47accfd62009-05-14 18:46:21176 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21177}
178
[email protected]34cc84f2009-02-13 10:04:35179// static
[email protected]4bf6afd2009-10-08 14:00:11180const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
181
182// static
initial.commit09911bf2008-07-26 23:55:29183void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55184 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29185 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
186 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12187 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26188 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
189 IDS_SPELLCHECK_DICTIONARY);
190 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58191 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16192#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06193 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
194 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29195#endif
[email protected]f017cc92009-12-14 20:48:07196 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34197 prefs->RegisterStringPref(prefs::kCurrentThemeID,
198 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42199 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
200 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
201 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50202 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23203 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29204}
205
[email protected]34cc84f2009-02-13 10:04:35206// static
[email protected]f7011fcb2009-01-28 21:54:32207Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29208 return new ProfileImpl(path);
209}
210
[email protected]34cc84f2009-02-13 10:04:35211// static
[email protected]be180c802009-10-23 06:33:31212URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29213 return default_request_context_;
214}
215
[email protected]753efc42010-03-09 19:52:16216#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41217#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56218#elif defined(OS_MACOSX)
219#include "chrome/browser/keychain_mac.h"
220#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16221#elif defined(OS_POSIX)
222// Temporarily disabled while we figure some stuff out.
223// http://code.google.com/p/chromium/issues/detail?id=12351
224// #include "chrome/browser/password_manager/password_store_gnome.h"
225// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41226#endif
initial.commit09911bf2008-07-26 23:55:29227
initial.commit09911bf2008-07-26 23:55:29228////////////////////////////////////////////////////////////////////////////////
229//
230// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42231// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29232//
233////////////////////////////////////////////////////////////////////////////////
234class OffTheRecordProfileImpl : public Profile,
235 public NotificationObserver {
236 public:
237 explicit OffTheRecordProfileImpl(Profile* real_profile)
238 : profile_(real_profile),
239 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31240 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05241
initial.commit09911bf2008-07-26 23:55:29242 // Register for browser close notifications so we can detect when the last
243 // off-the-record window is closed, in which case we can clean our states
244 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43245 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
246 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29247 }
248
249 virtual ~OffTheRecordProfileImpl() {
[email protected]098c743d2010-05-04 07:58:59250 NotificationService::current()->Notify(
251 NotificationType::PROFILE_DESTROYED,
252 Source<Profile>(this),
253 NotificationService::NoDetails());
254 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29255 }
256
[email protected]4bf6afd2009-10-08 14:00:11257 virtual ProfileId GetRuntimeId() {
258 return reinterpret_cast<ProfileId>(this);
259 }
260
[email protected]a6d0f182010-01-12 08:01:44261 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29262
263 virtual bool IsOffTheRecord() {
264 return true;
265 }
266
267 virtual Profile* GetOffTheRecordProfile() {
268 return this;
269 }
270
[email protected]860f55492009-03-27 19:50:59271 virtual void DestroyOffTheRecordProfile() {
272 // Suicide is bad!
273 NOTREACHED();
274 }
275
initial.commit09911bf2008-07-26 23:55:29276 virtual Profile* GetOriginalProfile() {
277 return profile_;
278 }
279
[email protected]2f351cb2009-11-09 23:43:34280 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
281 if (!db_tracker_)
282 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
283 return db_tracker_;
284 }
285
initial.commit09911bf2008-07-26 23:55:29286 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49287 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
288 // because we don't want to leak the sites that the user has visited before.
289 return NULL;
initial.commit09911bf2008-07-26 23:55:29290 }
291
[email protected]6014d672008-12-05 00:38:25292 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21293 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25294 }
295
[email protected]0938d3c2009-01-09 20:37:35296 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21297 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25298 }
299
[email protected]89ebc7e2009-08-24 22:11:07300 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21301 // TODO(mpcomplete): figure out whether we should return the original
302 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07303 return NULL;
304 }
305
[email protected]481e1a42009-05-06 20:56:05306 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21307 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05308 }
309
[email protected]7120f132009-07-20 21:05:37310 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21311 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37312 }
313
[email protected]34cc84f2009-02-13 10:04:35314 virtual SSLHostState* GetSSLHostState() {
315 if (!ssl_host_state_.get())
316 ssl_host_state_.reset(new SSLHostState());
317
318 DCHECK(ssl_host_state_->CalledOnValidThread());
319 return ssl_host_state_.get();
320 }
321
[email protected]326e6792009-12-11 21:04:42322 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54323 if (!transport_security_state_.get())
324 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23325
[email protected]326e6792009-12-11 21:04:42326 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23327 }
328
initial.commit09911bf2008-07-26 23:55:29329 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54330 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29331 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54332
333 NOTREACHED() << "This profile is OffTheRecord";
334 return NULL;
initial.commit09911bf2008-07-26 23:55:29335 }
336
[email protected]0850fa62009-10-08 22:34:29337 virtual HistoryService* GetHistoryServiceWithoutCreating() {
338 return profile_->GetHistoryServiceWithoutCreating();
339 }
340
[email protected]0189bc722009-08-28 21:56:48341 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54342 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48343 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54344
345 NOTREACHED() << "This profile is OffTheRecord";
346 return NULL;
[email protected]0189bc722009-08-28 21:56:48347 }
348
[email protected]69c579e2010-04-23 20:01:00349 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
350 return profile_->GetAutocompleteClassifier();
[email protected]90085af02009-10-29 17:53:21351 }
352
initial.commit09911bf2008-07-26 23:55:29353 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54354 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29355 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54356
357 NOTREACHED() << "This profile is OffTheRecord";
358 return NULL;
initial.commit09911bf2008-07-26 23:55:29359 }
360
[email protected]9cddbe372009-10-23 21:23:53361 virtual WebDataService* GetWebDataServiceWithoutCreating() {
362 return profile_->GetWebDataServiceWithoutCreating();
363 }
364
[email protected]e69d33952009-06-03 22:00:41365 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54366 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41367 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54368
369 NOTREACHED() << "This profile is OffTheRecord";
370 return NULL;
[email protected]e69d33952009-06-03 22:00:41371 }
372
initial.commit09911bf2008-07-26 23:55:29373 virtual PrefService* GetPrefs() {
374 return profile_->GetPrefs();
375 }
376
377 virtual TemplateURLModel* GetTemplateURLModel() {
378 return profile_->GetTemplateURLModel();
379 }
380
381 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
382 return profile_->GetTemplateURLFetcher();
383 }
384
385 virtual DownloadManager* GetDownloadManager() {
386 if (!download_manager_.get()) {
387 scoped_refptr<DownloadManager> dlm(new DownloadManager);
388 dlm->Init(this);
389 download_manager_.swap(dlm);
390 }
391 return download_manager_.get();
392 }
393
394 virtual bool HasCreatedDownloadManager() const {
395 return (download_manager_.get() != NULL);
396 }
397
[email protected]def11712009-11-06 00:42:15398 virtual PersonalDataManager* GetPersonalDataManager() {
399 return NULL;
400 }
401
[email protected]4a190632009-05-09 01:07:42402 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54403 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42404 }
405
406 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54407 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42408 }
409
[email protected]a5166af62009-07-03 00:42:29410 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54411 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29412 }
413
[email protected]4a190632009-05-09 01:07:42414 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54415 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42416 }
417
[email protected]51c490b2009-08-03 16:34:34418 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54419 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34420 }
421
[email protected]5786d3d2009-12-18 00:18:44422 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54423 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42424 }
425
[email protected]be180c802009-10-23 06:33:31426 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29427 return request_context_;
428 }
429
[email protected]be180c802009-10-23 06:33:31430 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11431 // In OTR mode, media request context is the same as the original one.
432 return request_context_;
[email protected]e7f29642009-03-02 22:53:18433 }
434
[email protected]be180c802009-10-23 06:33:31435 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21436 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21437 }
438
[email protected]db36938c2009-08-19 21:48:42439 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54440 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42441 }
442
[email protected]e284e6d82010-01-29 19:49:45443 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]bd147842010-04-09 15:29:17444 // Retrieve the host content settings map of the parent profile in order to
445 // ensure the preferences have been migrated.
446 profile_->GetHostContentSettingsMap();
447 if (!host_content_settings_map_.get())
448 host_content_settings_map_ = new HostContentSettingsMap(this);
449 return host_content_settings_map_.get();
[email protected]e284e6d82010-01-29 19:49:45450 }
451
[email protected]40bd6582009-12-04 23:49:51452 virtual HostZoomMap* GetHostZoomMap() {
[email protected]c18d4f482010-05-18 21:19:50453 if (!host_zoom_map_)
454 host_zoom_map_ = new HostZoomMap(this);
455 return host_zoom_map_.get();
[email protected]40bd6582009-12-04 23:49:51456 }
457
[email protected]aee541e2010-03-19 01:52:45458 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
459 return profile_->GetGeolocationContentSettingsMap();
460 }
461
[email protected]8b4b84ee2010-05-11 13:08:52462 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() {
463 return profile_->GetGeolocationPermissionContext();
464 }
465
[email protected]8c6335d32010-01-20 09:21:50466 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54467 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23468 }
469
[email protected]6c32ce72010-03-08 05:18:06470 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
471 return profile_->GetUserStyleSheetWatcher();
472 }
473
[email protected]e5d2f7132010-04-09 18:13:53474 virtual FindBarState* GetFindBarState() {
475 if (!find_bar_state_.get())
476 find_bar_state_.reset(new FindBarState());
477 return find_bar_state_.get();
478 }
479
initial.commit09911bf2008-07-26 23:55:29480 virtual SessionService* GetSessionService() {
481 // Don't save any sessions when off the record.
482 return NULL;
483 }
484
485 virtual void ShutdownSessionService() {
486 // We don't allow a session service, nothing to do.
487 }
488
489 virtual bool HasSessionService() const {
490 // We never have a session service.
491 return false;
492 }
493
initial.commit09911bf2008-07-26 23:55:29494 virtual bool DidLastSessionExitCleanly() {
495 return profile_->DidLastSessionExitCleanly();
496 }
497
[email protected]d8e41ed2008-09-11 15:22:32498 virtual BookmarkModel* GetBookmarkModel() {
499 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29500 }
501
[email protected]4bb336302009-10-12 05:44:26502 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58503 if (!desktop_notification_service_.get()) {
504 desktop_notification_service_.reset(new DesktopNotificationService(
505 this, g_browser_process->notification_ui_manager()));
506 }
507 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26508 }
509
[email protected]48352c12009-08-15 01:19:11510 virtual ProfileSyncService* GetProfileSyncService() {
511 return NULL;
[email protected]3a453fa2008-08-15 18:46:34512 }
[email protected]3a453fa2008-08-15 18:46:34513
[email protected]1bd056e2010-04-20 02:03:48514 virtual CloudPrintProxyService* GetCloudPrintProxyService() {
515 return NULL;
516 }
517
initial.commit09911bf2008-07-26 23:55:29518 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54519 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29520 }
521
522 virtual Time GetStartTime() const {
523 return start_time_;
524 }
525
526 virtual TabRestoreService* GetTabRestoreService() {
527 return NULL;
528 }
529
[email protected]e7244d82008-10-29 18:13:26530 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41531 }
532
[email protected]85c55dc2009-11-06 03:05:46533 virtual SpellCheckHost* GetSpellCheckHost() {
534 return profile_->GetSpellCheckHost();
535 }
536
537 virtual void ReinitializeSpellCheckHost(bool force) {
538 profile_->ReinitializeSpellCheckHost(force);
539 }
[email protected]85c55dc2009-11-06 03:05:46540
[email protected]3bf335a2009-06-26 20:46:06541 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29542 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:11543 webkit_context_ = new WebKitContext(this);
[email protected]c27324b2009-11-19 22:44:29544 DCHECK(webkit_context_.get());
545 return webkit_context_.get();
546 }
[email protected]3bf335a2009-06-26 20:46:06547
[email protected]449478302009-06-09 20:04:28548 virtual ThumbnailStore* GetThumbnailStore() {
549 return NULL;
550 }
551
[email protected]523623c2010-05-19 16:03:42552 virtual history::TopSites* GetTopSites() {
553 return NULL;
554 }
555
initial.commit09911bf2008-07-26 23:55:29556 virtual void MarkAsCleanShutdown() {
557 }
558
[email protected]bdbc87c2009-01-25 05:08:54559 virtual void InitExtensions() {
560 NOTREACHED();
561 }
562
[email protected]ea0c98cf2009-06-18 23:02:54563 virtual void InitWebResources() {
564 NOTREACHED();
565 }
566
[email protected]9c8dd902009-11-19 17:50:42567 virtual NTPResourceCache* GetNTPResourceCache() {
568 // Just return the real profile resource cache.
569 return profile_->GetNTPResourceCache();
570 }
571
initial.commit09911bf2008-07-26 23:55:29572 virtual void ExitedOffTheRecordMode() {
573 // Drop our download manager so we forget about all the downloads made
574 // in off-the-record mode.
575 download_manager_ = NULL;
576 }
577
578 virtual void Observe(NotificationType type,
579 const NotificationSource& source,
580 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56581 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29582 // We are only interested in OTR browser closing.
583 if (Source<Browser>(source)->profile() != this)
584 return;
585
586 // Let's check if we still have an Off The Record window opened.
587 // Note that we check against 1 as this notification is sent before the
588 // browser window is actually removed from the list.
589 if (BrowserList::GetBrowserCount(this) <= 1)
590 ExitedOffTheRecordMode();
591 }
592
593 private:
[email protected]88cf3292009-05-22 01:48:43594 NotificationRegistrar registrar_;
595
initial.commit09911bf2008-07-26 23:55:29596 // The real underlying profile.
597 Profile* profile_;
598
[email protected]6ab9b202008-12-23 22:34:50599 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19600 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29601
602 // The download manager that only stores downloaded items in memory.
603 scoped_refptr<DownloadManager> download_manager_;
604
[email protected]7d7696c52009-12-01 20:54:58605 // Use a separate desktop notification service for OTR.
606 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
607
[email protected]bd147842010-04-09 15:29:17608 // We use a non-writable content settings map for OTR.
609 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
610
[email protected]c18d4f482010-05-18 21:19:50611 // Use a separate zoom map for OTR.
612 scoped_refptr<HostZoomMap> host_zoom_map_;
613
[email protected]3bf335a2009-06-26 20:46:06614 // Use a special WebKit context for OTR browsing.
615 scoped_refptr<WebKitContext> webkit_context_;
616
[email protected]34cc84f2009-02-13 10:04:35617 // We don't want SSLHostState from the OTR profile to leak back to the main
618 // profile because then the main profile would learn some of the host names
619 // the user visited while OTR.
620 scoped_ptr<SSLHostState> ssl_host_state_;
621
[email protected]e5d2f7132010-04-09 18:13:53622 // Use a separate FindBarState so search terms do not leak back to the main
623 // profile.
624 scoped_ptr<FindBarState> find_bar_state_;
625
[email protected]326e6792009-12-11 21:04:42626 // The TransportSecurityState that only stores enabled sites in memory.
627 scoped_refptr<net::TransportSecurityState>
628 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23629
initial.commit09911bf2008-07-26 23:55:29630 // Time we were started.
631 Time start_time_;
632
[email protected]2f351cb2009-11-09 23:43:34633 // The main database tracker for this profile.
634 // Should be used only on the file thread.
635 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
636
[email protected]90085af02009-10-29 17:53:21637 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29638};
639
[email protected]f7011fcb2009-01-28 21:54:32640ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29641 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44642 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07643 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32644 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57645 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21646 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45647 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51648 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32649 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48650 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32651 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41652 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32653 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42654 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32655 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46656 spellcheck_host_(NULL),
657 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29658 shutdown_session_service_(false) {
659 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
660 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14661 create_session_service_timer_.Start(
662 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
663 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54664
[email protected]89ebc7e2009-08-24 22:11:07665 if (CommandLine::ForCurrentProcess()->HasSwitch(
666 switches::kEnableExtensionTimelineApi)) {
667 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
668 }
669
[email protected]382a0702009-06-26 17:12:27670 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37671 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27672
[email protected]e7244d82008-10-29 18:13:26673 PrefService* prefs = GetPrefs();
674 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
675 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58676 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58677
[email protected]405a64b2009-09-16 21:03:44678#if defined(OS_MACOSX)
679 // If the profile directory doesn't already have a cache directory and it
680 // is under ~/Library/Application Support, use a suitable cache directory
681 // under ~/Library/Caches. For example, a profile directory of
682 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
683 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
684 // ~/Library/Caches/Google/Chrome/MyProfileName.
685 //
686 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44687 if (!HasACacheSubdir(path_)) {
688 FilePath app_data_path, user_cache_path;
689 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12690 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44691 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
692 base_cache_path_ = user_cache_path;
693 }
694 }
[email protected]9e9b6e8e2009-12-02 08:45:01695#elif defined(OS_POSIX) // Posix minus Mac.
696 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
697 // for a spec on where cache files go. The net effect for most systems is we
698 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
699 // official builds.
700 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
701#if defined(GOOGLE_CHROME_BUILD)
702 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44703#else
[email protected]9e9b6e8e2009-12-02 08:45:01704 const char kCacheDir[] = "chromium";
705#endif
706 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
707 base_cache_path_ = base_cache_path_.Append(kCacheDir);
708 if (!file_util::PathExists(base_cache_path_))
709 file_util::CreateDirectory(base_cache_path_);
710 }
[email protected]405a64b2009-09-16 21:03:44711#endif
[email protected]bc96d562009-08-11 18:45:13712 if (base_cache_path_.empty())
713 base_cache_path_ = path_;
714
[email protected]4a190632009-05-09 01:07:42715 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43716 registrar_.Add(this, NotificationType::THEME_INSTALLED,
717 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11718
719 // Listen for bookmark model load, to bootstrap the sync service.
720 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
721 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42722
723 ssl_config_service_manager_.reset(
724 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53725
726#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29727 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53728#endif
[email protected]911f8152010-03-18 16:46:40729
730 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29731}
732
[email protected]bdbc87c2009-01-25 05:08:54733void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41734 if (user_script_master_ || extensions_service_)
735 return; // Already initialized.
736
[email protected]bdbc87c2009-01-25 05:08:54737 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18738 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36739
740 FilePath script_dir; // Don't look for user scripts in any directory.
741 // TODO(aa): We should just remove this functionality,
742 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51743 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36744
[email protected]894bb502009-05-21 22:39:57745 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23746 this,
747 CommandLine::ForCurrentProcess(),
748 GetPrefs(),
749 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36750 true);
[email protected]bdbc87c2009-01-25 05:08:54751
[email protected]fee67982010-04-23 17:24:22752 // Register the component extensions.
753 std::map<std::string, int> component_extensions;
754
755 // Bookmark manager.
[email protected]47e532b2010-04-23 17:46:40756 component_extensions["bookmark_manager"] = IDR_BOOKMARKS_MANIFEST;
[email protected]fee67982010-04-23 17:24:22757
[email protected]abdc9fb52010-05-06 01:44:48758#if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
[email protected]ae90f252010-05-04 18:28:03759 // Chat manager.
760 if (CommandLine::ForCurrentProcess()->HasSwitch(
761 switches::kEnableChatManager)) {
762 component_extensions["chat_manager"] = IDR_CHAT_MANAGER_MANIFEST;
763 }
764#endif
765
[email protected]fee67982010-04-23 17:24:22766 // Some sample apps to make our lives easier while we are developing extension
767 // apps. This way we don't have to constantly install these over and over.
[email protected]2bce5e12010-05-13 01:18:07768 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableApps)) {
[email protected]fee67982010-04-23 17:24:22769#if defined(OS_WIN)
770 std::string user_domain;
771 if (base::EnvVarGetter::Create()->GetEnv("USERDOMAIN", &user_domain) &&
772 user_domain == "GOOGLE") {
773 component_extensions["gmail_app"] = IDR_GMAIL_APP_MANIFEST;
774 component_extensions["calendar_app"] = IDR_CALENDAR_APP_MANIFEST;
775 component_extensions["docs_app"] = IDR_DOCS_APP_MANIFEST;
776 }
777#endif
778 }
779
780 for (std::map<std::string, int>::iterator iter = component_extensions.begin();
781 iter != component_extensions.end(); ++iter) {
782 FilePath path;
783 if (PathService::Get(chrome::DIR_RESOURCES, &path)) {
784 path = path.AppendASCII(iter->first);
[email protected]1952c7d2010-03-04 23:48:34785 } else {
786 NOTREACHED();
787 }
[email protected]fee67982010-04-23 17:24:22788
789 std::string manifest =
790 ResourceBundle::GetSharedInstance().GetRawDataResource(
791 iter->second).as_string();
792 extensions_service_->register_component_extension(
793 ExtensionsService::ComponentExtensionInfo(manifest, path));
[email protected]1952c7d2010-03-04 23:48:34794 }
795
[email protected]9197f3b2009-06-02 00:49:27796 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12797
798 // Load any extensions specified with --load-extension.
799 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10800 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12801 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12802 }
[email protected]bdbc87c2009-01-25 05:08:54803}
804
[email protected]ea0c98cf2009-06-18 23:02:54805void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07806 if (web_resource_service_)
807 return; // Already initialized.
808
[email protected]6fad2632009-11-02 05:59:37809 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54810 web_resource_service_->StartAfterDelay();
811}
812
[email protected]9c8dd902009-11-19 17:50:42813NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
814 if (!ntp_resource_cache_.get())
815 ntp_resource_cache_.reset(new NTPResourceCache(this));
816 return ntp_resource_cache_.get();
817}
818
initial.commit09911bf2008-07-26 23:55:29819ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56820 NotificationService::current()->Notify(
821 NotificationType::PROFILE_DESTROYED,
822 Source<Profile>(this),
823 NotificationService::NoDetails());
824
[email protected]169627b2008-12-06 19:30:19825 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29826
827 StopCreateSessionServiceTimer();
828 // TemplateURLModel schedules a task on the WebDataService from its
829 // destructor. Delete it first to ensure the task gets scheduled before we
830 // shut down the database.
831 template_url_model_.reset();
832
833 // The download manager queries the history system and should be deleted
834 // before the history is shutdown so it can properly cancel all requests.
835 download_manager_ = NULL;
836
[email protected]4a190632009-05-09 01:07:42837 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15838 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42839
[email protected]44961292009-07-20 20:03:09840 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
841 // save any new thumbnails to disk and release its reference to the
842 // HistoryService.
843 if (thumbnail_store_.get())
844 thumbnail_store_->Shutdown();
845
[email protected]e7244d82008-10-29 18:13:26846 // Remove pref observers.
847 PrefService* prefs = GetPrefs();
848 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
849 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58850 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26851
[email protected]9c8dd902009-11-19 17:50:42852 // Delete the NTP resource cache so we can unregister pref observers.
853 ntp_resource_cache_.reset();
854
[email protected]48352c12009-08-15 01:19:11855 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34856
initial.commit09911bf2008-07-26 23:55:29857 // Both HistoryService and WebDataService maintain threads for background
858 // processing. Its possible each thread still has tasks on it that have
859 // increased the ref count of the service. In such a situation, when we
860 // decrement the refcount, it won't be 0, and the threads/databases aren't
861 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
862 // databases are properly closed.
863 if (web_data_service_.get())
864 web_data_service_->Shutdown();
865
866 if (history_service_.get())
867 history_service_->Cleanup();
868
[email protected]85c55dc2009-11-06 03:05:46869 if (spellcheck_host_.get())
870 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29871
[email protected]cfc06f122009-11-16 22:18:55872 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21873 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50874
[email protected]47accfd62009-05-14 18:46:21875 CleanupRequestContext(request_context_);
876 CleanupRequestContext(media_request_context_);
877 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17878
[email protected]d8e41ed2008-09-11 15:22:32879 // HistoryService may call into the BookmarkModel, as such we need to
880 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46881 // HistoryService will join with HistoryService's backend thread so that
882 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32883 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46884 history_service_ = NULL;
885 bookmark_bar_model_.reset();
886
[email protected]0189bc722009-08-28 21:56:48887 // FaviconService depends on HistoryServce so make sure we delete
888 // HistoryService first.
889 favicon_service_ = NULL;
890
[email protected]7120f132009-07-20 21:05:37891 extension_message_service_->ProfileDestroyed();
892
[email protected]6ef635e42009-07-26 06:16:12893 if (extensions_service_)
894 extensions_service_->ProfileDestroyed();
895
[email protected]66da08b2009-10-19 22:27:00896 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29897 MarkAsCleanShutdown();
898}
899
[email protected]4bf6afd2009-10-08 14:00:11900ProfileId ProfileImpl::GetRuntimeId() {
901 return reinterpret_cast<ProfileId>(this);
902}
903
[email protected]f7011fcb2009-01-28 21:54:32904FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29905 return path_;
906}
907
908bool ProfileImpl::IsOffTheRecord() {
909 return false;
910}
911
912Profile* ProfileImpl::GetOffTheRecordProfile() {
913 if (!off_the_record_profile_.get()) {
914 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
915 off_the_record_profile_.swap(p);
916 }
917 return off_the_record_profile_.get();
918}
919
[email protected]860f55492009-03-27 19:50:59920void ProfileImpl::DestroyOffTheRecordProfile() {
921 off_the_record_profile_.reset();
922}
923
initial.commit09911bf2008-07-26 23:55:29924Profile* ProfileImpl::GetOriginalProfile() {
925 return this;
926}
927
[email protected]2f351cb2009-11-09 23:43:34928webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
929 if (!db_tracker_)
930 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
931 return db_tracker_;
932}
933
initial.commit09911bf2008-07-26 23:55:29934VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44935 if (!visited_link_master_.get()) {
936 scoped_ptr<VisitedLinkMaster> visited_links(
937 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
938 if (!visited_links->Init())
939 return NULL;
940 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53941 }
[email protected]a6d0f182010-01-12 08:01:44942
943 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29944}
945
[email protected]6014d672008-12-05 00:38:25946ExtensionsService* ProfileImpl::GetExtensionsService() {
947 return extensions_service_.get();
948}
949
[email protected]0938d3c2009-01-09 20:37:35950UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35951 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25952}
953
[email protected]89ebc7e2009-08-24 22:11:07954ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
955 return extension_devtools_manager_.get();
956}
957
[email protected]481e1a42009-05-06 20:56:05958ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27959 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05960}
961
[email protected]7120f132009-07-20 21:05:37962ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
963 return extension_message_service_.get();
964}
965
[email protected]34cc84f2009-02-13 10:04:35966SSLHostState* ProfileImpl::GetSSLHostState() {
967 if (!ssl_host_state_.get())
968 ssl_host_state_.reset(new SSLHostState());
969
970 DCHECK(ssl_host_state_->CalledOnValidThread());
971 return ssl_host_state_.get();
972}
973
[email protected]326e6792009-12-11 21:04:42974net::TransportSecurityState*
975 ProfileImpl::GetTransportSecurityState() {
976 if (!transport_security_state_.get()) {
977 transport_security_state_ = new net::TransportSecurityState();
978 transport_security_persister_ =
979 new TransportSecurityPersister();
980 transport_security_persister_->Initialize(
981 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51982 }
[email protected]a9cea7542009-05-20 04:30:23983
[email protected]326e6792009-12-11 21:04:42984 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23985}
986
initial.commit09911bf2008-07-26 23:55:29987PrefService* ProfileImpl::GetPrefs() {
988 if (!prefs_.get()) {
[email protected]277404c22010-04-22 13:09:45989 prefs_.reset(new PrefService(new JsonPrefStore(GetPrefFilePath())));
initial.commit09911bf2008-07-26 23:55:29990
991 // The Profile class and ProfileManager class may read some prefs so
992 // register known prefs as soon as possible.
993 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51994 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29995
996 // The last session exited cleanly if there is no pref for
997 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
998 last_session_exited_cleanly_ =
999 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
1000 // Mark the session as open.
1001 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
1002 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:361003 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291004 }
1005
1006 return prefs_.get();
1007}
1008
[email protected]f7011fcb2009-01-28 21:54:321009FilePath ProfileImpl::GetPrefFilePath() {
1010 FilePath pref_file_path = path_;
1011 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:291012 return pref_file_path;
1013}
1014
[email protected]be180c802009-10-23 06:33:311015URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:291016 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:321017 FilePath cookie_path = GetPath();
1018 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:131019 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311020 int max_size;
1021 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:421022
[email protected]405a64b2009-09-16 21:03:441023 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311024 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
1025 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:291026
[email protected]6ab9b202008-12-23 22:34:501027 // The first request context is always a normal (non-OTR) request context.
1028 // Even when Chromium is started in OTR mode, a normal profile is always
1029 // created first.
1030 if (!default_request_context_) {
1031 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:311032 // TODO(eroman): this isn't terribly useful anymore now that the
1033 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:501034 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561035 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:501036 NotificationService::AllSources(), NotificationService::NoDetails());
1037 }
initial.commit09911bf2008-07-26 23:55:291038 }
1039
1040 return request_context_;
1041}
1042
[email protected]be180c802009-10-23 06:33:311043URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:181044 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:131045 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311046 int max_size;
1047 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:141048
[email protected]405a64b2009-09-16 21:03:441049 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311050 media_request_context_ =
1051 ChromeURLRequestContextGetter::CreateOriginalForMedia(
1052 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:181053 }
1054
1055 return media_request_context_;
1056}
1057
[email protected]0189bc722009-08-28 21:56:481058FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
1059 if (!favicon_service_created_) {
1060 favicon_service_created_ = true;
1061 scoped_refptr<FaviconService> service(new FaviconService(this));
1062 favicon_service_.swap(service);
1063 }
1064 return favicon_service_.get();
1065}
1066
[email protected]be180c802009-10-23 06:33:311067URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:211068 if (!extensions_request_context_) {
1069 FilePath cookie_path = GetPath();
1070 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1071
1072 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:311073 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
1074 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:211075 }
1076
1077 return extensions_request_context_;
1078}
1079
[email protected]57a777f72010-03-31 01:09:421080void ProfileImpl::RegisterExtensionWithRequestContexts(
1081 Extension* extension) {
1082 // Notify the default, extension and media contexts on the IO thread.
1083 PostExtensionLoadedToContextGetter(
1084 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1085 extension);
1086 PostExtensionLoadedToContextGetter(
1087 static_cast<ChromeURLRequestContextGetter*>(
1088 GetRequestContextForExtensions()),
1089 extension);
1090 PostExtensionLoadedToContextGetter(
1091 static_cast<ChromeURLRequestContextGetter*>(
1092 GetRequestContextForMedia()),
1093 extension);
1094}
1095
1096void ProfileImpl::UnregisterExtensionWithRequestContexts(
1097 Extension* extension) {
1098 // Notify the default, extension and media contexts on the IO thread.
1099 PostExtensionUnloadedToContextGetter(
1100 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1101 extension);
1102 PostExtensionUnloadedToContextGetter(
1103 static_cast<ChromeURLRequestContextGetter*>(
1104 GetRequestContextForExtensions()),
1105 extension);
1106 PostExtensionUnloadedToContextGetter(
1107 static_cast<ChromeURLRequestContextGetter*>(
1108 GetRequestContextForMedia()),
1109 extension);
1110}
1111
[email protected]db36938c2009-08-19 21:48:421112net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1113 return ssl_config_service_manager_->Get();
1114}
1115
[email protected]e284e6d82010-01-29 19:49:451116HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
1117 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:391118 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:451119 return host_content_settings_map_.get();
1120}
1121
[email protected]40bd6582009-12-04 23:49:511122HostZoomMap* ProfileImpl::GetHostZoomMap() {
1123 if (!host_zoom_map_)
1124 host_zoom_map_ = new HostZoomMap(this);
1125 return host_zoom_map_.get();
1126}
1127
[email protected]aee541e2010-03-19 01:52:451128GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
1129 if (!geolocation_content_settings_map_.get())
1130 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
1131 return geolocation_content_settings_map_.get();
1132}
1133
[email protected]8b4b84ee2010-05-11 13:08:521134GeolocationPermissionContext* ProfileImpl::GetGeolocationPermissionContext() {
1135 if (!geolocation_permission_context_.get())
1136 geolocation_permission_context_ = new GeolocationPermissionContext(this);
1137 return geolocation_permission_context_.get();
1138}
1139
[email protected]8c6335d32010-01-20 09:21:501140Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271141 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141142 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271143 return NULL;
[email protected]c37f8b42010-01-23 16:22:141144 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541145 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501146 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231147}
1148
[email protected]6c32ce72010-03-08 05:18:061149UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1150 if (!user_style_sheet_watcher_.get()) {
1151 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1152 user_style_sheet_watcher_->Init();
1153 }
1154 return user_style_sheet_watcher_.get();
1155}
1156
[email protected]e5d2f7132010-04-09 18:13:531157FindBarState* ProfileImpl::GetFindBarState() {
1158 if (!find_bar_state_.get()) {
1159 find_bar_state_.reset(new FindBarState());
1160 }
1161 return find_bar_state_.get();
1162}
1163
initial.commit09911bf2008-07-26 23:55:291164HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1165 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461166 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291167 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321168 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291169 return NULL;
1170 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291171
1172 // Send out the notification that the history service was created.
1173 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561174 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291175 Details<HistoryService>(history_service_.get()));
1176 }
1177 return history_service_.get();
1178}
1179
[email protected]0850fa62009-10-08 22:34:291180HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1181 return history_service_.get();
1182}
1183
initial.commit09911bf2008-07-26 23:55:291184TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1185 if (!template_url_model_.get())
1186 template_url_model_.reset(new TemplateURLModel(this));
1187 return template_url_model_.get();
1188}
1189
1190TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1191 if (!template_url_fetcher_.get())
1192 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1193 return template_url_fetcher_.get();
1194}
1195
[email protected]69c579e2010-04-23 20:01:001196AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
1197 if (!autocomplete_classifier_.get())
1198 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
1199 return autocomplete_classifier_.get();
[email protected]90085af02009-10-29 17:53:211200}
1201
initial.commit09911bf2008-07-26 23:55:291202WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1203 if (!created_web_data_service_)
1204 CreateWebDataService();
1205 return web_data_service_.get();
1206}
1207
[email protected]9cddbe372009-10-23 21:23:531208WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1209 return web_data_service_.get();
1210}
1211
initial.commit09911bf2008-07-26 23:55:291212void ProfileImpl::CreateWebDataService() {
1213 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1214 created_web_data_service_ = true;
1215 scoped_refptr<WebDataService> wds(new WebDataService());
1216 if (!wds->Init(GetPath()))
1217 return;
1218 web_data_service_.swap(wds);
1219}
1220
[email protected]e69d33952009-06-03 22:00:411221PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1222 if (!created_password_store_)
1223 CreatePasswordStore();
1224 return password_store_.get();
1225}
1226
1227void ProfileImpl::CreatePasswordStore() {
1228 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1229 created_password_store_ = true;
1230 scoped_refptr<PasswordStore> ps;
[email protected]e0411ae52009-06-30 23:59:171231 FilePath login_db_file_path = GetPath();
1232 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
[email protected]ec44cd52010-04-05 22:30:471233 LoginDatabase* login_db = new LoginDatabase();
[email protected]e0411ae52009-06-30 23:59:171234 if (!login_db->Init(login_db_file_path)) {
1235 LOG(ERROR) << "Could not initialize login database.";
1236 delete login_db;
1237 return;
1238 }
[email protected]e8380f52010-04-30 16:39:421239#if defined(OS_WIN)
1240 ps = new PasswordStoreWin(login_db, this,
1241 GetWebDataService(Profile::IMPLICIT_ACCESS));
1242#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171243 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161244#elif defined(OS_POSIX)
1245 // TODO(evanm): implement "native" password management.
1246 // This bug describes the issues.
1247 // http://code.google.com/p/chromium/issues/detail?id=12351
[email protected]e8380f52010-04-30 16:39:421248 ps = new PasswordStoreDefault(login_db, this,
1249 GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]e69d33952009-06-03 22:00:411250#else
1251 NOTIMPLEMENTED();
1252#endif
[email protected]e8380f52010-04-30 16:39:421253 if (!ps)
1254 delete login_db;
1255
[email protected]e69d33952009-06-03 22:00:411256 if (!ps || !ps->Init()) {
[email protected]e8380f52010-04-30 16:39:421257 NOTREACHED() << "Could not initialise password manager";
1258 return;
[email protected]e69d33952009-06-03 22:00:411259 }
1260 password_store_.swap(ps);
1261}
1262
initial.commit09911bf2008-07-26 23:55:291263DownloadManager* ProfileImpl::GetDownloadManager() {
1264 if (!created_download_manager_) {
1265 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1266 dlm->Init(this);
1267 created_download_manager_ = true;
1268 download_manager_.swap(dlm);
1269 }
1270 return download_manager_.get();
1271}
1272
1273bool ProfileImpl::HasCreatedDownloadManager() const {
1274 return created_download_manager_;
1275}
1276
[email protected]def11712009-11-06 00:42:151277PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1278 if (!personal_data_manager_.get()) {
[email protected]e0976a72010-04-02 01:25:241279 personal_data_manager_.reset(new PersonalDataManager());
1280 personal_data_manager_->Init(this);
[email protected]def11712009-11-06 00:42:151281 }
1282 return personal_data_manager_.get();
1283}
1284
[email protected]4a190632009-05-09 01:07:421285void ProfileImpl::InitThemes() {
1286 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161287#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151288 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291289#else
[email protected]761962c2009-09-25 00:18:151290 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291291#endif
[email protected]761962c2009-09-25 00:18:151292 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421293 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421294 }
1295}
1296
1297void ProfileImpl::SetTheme(Extension* extension) {
1298 InitThemes();
1299 theme_provider_.get()->SetTheme(extension);
1300}
1301
[email protected]a5166af62009-07-03 00:42:291302void ProfileImpl::SetNativeTheme() {
1303 InitThemes();
1304 theme_provider_.get()->SetNativeTheme();
1305}
1306
[email protected]4a190632009-05-09 01:07:421307void ProfileImpl::ClearTheme() {
1308 InitThemes();
1309 theme_provider_.get()->UseDefaultTheme();
1310}
1311
[email protected]51c490b2009-08-03 16:34:341312Extension* ProfileImpl::GetTheme() {
1313 InitThemes();
1314
1315 std::string id = theme_provider_.get()->GetThemeID();
1316 if (id == BrowserThemeProvider::kDefaultThemeID)
1317 return NULL;
1318
[email protected]61b411612009-11-10 23:17:411319 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341320}
1321
[email protected]5786d3d2009-12-18 00:18:441322BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421323 InitThemes();
1324 return theme_provider_.get();
1325}
1326
initial.commit09911bf2008-07-26 23:55:291327SessionService* ProfileImpl::GetSessionService() {
1328 if (!session_service_.get() && !shutdown_session_service_) {
1329 session_service_ = new SessionService(this);
1330 session_service_->ResetFromCurrentBrowsers();
1331 }
1332 return session_service_.get();
1333}
1334
1335void ProfileImpl::ShutdownSessionService() {
1336 if (shutdown_session_service_)
1337 return;
1338
1339 // We're about to exit, force creation of the session service if it hasn't
1340 // been created yet. We do this to ensure session state matches the point in
1341 // time the user exited.
1342 GetSessionService();
1343 shutdown_session_service_ = true;
1344 session_service_ = NULL;
1345}
1346
1347bool ProfileImpl::HasSessionService() const {
1348 return (session_service_.get() != NULL);
1349}
1350
initial.commit09911bf2008-07-26 23:55:291351bool ProfileImpl::DidLastSessionExitCleanly() {
1352 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1353 // it to be set by asking for the prefs.
1354 GetPrefs();
1355 return last_session_exited_cleanly_;
1356}
1357
[email protected]d8e41ed2008-09-11 15:22:321358BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461359 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321360 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461361 bookmark_bar_model_->Load();
1362 }
initial.commit09911bf2008-07-26 23:55:291363 return bookmark_bar_model_.get();
1364}
1365
1366bool ProfileImpl::IsSameProfile(Profile* profile) {
1367 if (profile == static_cast<Profile*>(this))
1368 return true;
1369 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1370 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1371}
1372
1373Time ProfileImpl::GetStartTime() const {
1374 return start_time_;
1375}
1376
1377TabRestoreService* ProfileImpl::GetTabRestoreService() {
1378 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191379 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291380 return tab_restore_service_.get();
1381}
1382
[email protected]449478302009-06-09 20:04:281383ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1384 if (!thumbnail_store_.get()) {
1385 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251386 thumbnail_store_->Init(
1387 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281388 }
1389 return thumbnail_store_.get();
1390}
1391
[email protected]523623c2010-05-19 16:03:421392history::TopSites* ProfileImpl::GetTopSites() {
1393 if (!top_sites_.get()) {
1394 top_sites_ = new history::TopSites(this);
1395 top_sites_->Init();
1396 }
1397 return top_sites_;
1398}
1399
initial.commit09911bf2008-07-26 23:55:291400void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191401 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291402}
1403
[email protected]85c55dc2009-11-06 03:05:461404SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1405 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1406}
1407
1408void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1409 // If we are already loading the spellchecker, and this is just a hint to
1410 // load the spellchecker, do nothing.
1411 if (!force && spellcheck_host_.get())
1412 return;
1413
[email protected]f41301e2009-11-16 21:30:071414 spellcheck_host_ready_ = false;
1415
[email protected]85c55dc2009-11-06 03:05:461416 bool notify = false;
1417 if (spellcheck_host_.get()) {
1418 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051419 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461420 notify = true;
1421 }
1422
1423 PrefService* prefs = GetPrefs();
1424 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1425 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1426 spellcheck_host_ = new SpellCheckHost(this,
1427 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1428 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071429 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461430 } else if (notify) {
1431 // The spellchecker has been disabled.
1432 SpellCheckHostInitialized();
1433 }
1434}
1435
1436void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171437 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291438 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1439 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461440 NotificationService::current()->Notify(
1441 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1442 Source<Profile>(this), NotificationService::NoDetails());
1443}
initial.commit09911bf2008-07-26 23:55:291444
[email protected]3bf335a2009-06-26 20:46:061445WebKitContext* ProfileImpl::GetWebKitContext() {
1446 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:111447 webkit_context_ = new WebKitContext(this);
[email protected]3bf335a2009-06-26 20:46:061448 DCHECK(webkit_context_.get());
1449 return webkit_context_.get();
1450}
1451
[email protected]4bb336302009-10-12 05:44:261452DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1453 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1454 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261455 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031456 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261457 }
[email protected]4bb336302009-10-12 05:44:261458 return desktop_notification_service_.get();
1459}
1460
initial.commit09911bf2008-07-26 23:55:291461void ProfileImpl::MarkAsCleanShutdown() {
1462 if (prefs_.get()) {
1463 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1464 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1465
1466 // NOTE: If you change what thread this writes on, be sure and update
1467 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361468 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291469 }
1470}
1471
[email protected]e7244d82008-10-29 18:13:261472void ProfileImpl::Observe(NotificationType type,
1473 const NotificationSource& source,
1474 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561475 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261476 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1477 PrefService* prefs = Source<PrefService>(source).ptr();
1478 DCHECK(pref_name_in && prefs);
1479 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461480 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461481 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291482 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1483 NotificationService::current()->Notify(
1484 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1485 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261486 }
[email protected]4a190632009-05-09 01:07:421487 } else if (NotificationType::THEME_INSTALLED == type) {
1488 Extension* extension = Details<Extension>(details).ptr();
1489 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111490 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1491 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1492 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1493 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261494 }
1495}
1496
initial.commit09911bf2008-07-26 23:55:291497void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141498 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291499}
[email protected]3a453fa2008-08-15 18:46:341500
[email protected]48352c12009-08-15 01:19:111501ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431502 if (!ProfileSyncService::IsSyncEnabled()) {
1503 return NULL;
[email protected]7367f1a2009-10-10 01:09:441504 }
[email protected]eec3bcfa2009-11-12 17:23:431505 if (!sync_service_.get())
1506 InitSyncService();
1507 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111508}
1509
[email protected]1bd056e2010-04-20 02:03:481510CloudPrintProxyService* ProfileImpl::GetCloudPrintProxyService() {
1511 if (!cloud_print_proxy_service_.get())
1512 InitCloudPrintProxyService();
1513 return cloud_print_proxy_service_.get();
1514}
1515
[email protected]48352c12009-08-15 01:19:111516void ProfileImpl::InitSyncService() {
[email protected]82d9d2952010-05-15 00:36:161517 network_change_notifier_thread_.reset(
1518 new NetworkChangeNotifierIOThread(g_browser_process->io_thread()));
[email protected]4aea04a2010-02-10 20:13:431519 profile_sync_factory_.reset(
1520 new ProfileSyncFactoryImpl(this,
[email protected]82d9d2952010-05-15 00:36:161521 network_change_notifier_thread_.get(),
[email protected]4aea04a2010-02-10 20:13:431522 CommandLine::ForCurrentProcess()));
1523 sync_service_.reset(
1524 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111525 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111526}
[email protected]1bd056e2010-04-20 02:03:481527
1528void ProfileImpl::InitCloudPrintProxyService() {
1529 cloud_print_proxy_service_.reset(new CloudPrintProxyService(this));
1530 cloud_print_proxy_service_->Initialize();
1531}