blob: b2bdf7f08c9cc13d9bbf34f5a4fa0415a20ba523 [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]d8b08c92010-06-07 13:13:2848#include "chrome/browser/pref_value_store.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"
[email protected]ea587b02010-05-21 15:01:3571#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2972#include "chrome/common/notification_service.h"
73#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3274#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3475#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5876#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4277#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3478#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2979
[email protected]753efc42010-03-09 19:52:1680#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2981#include "chrome/browser/gtk/gtk_theme_provider.h"
82#endif
83
[email protected]e1acf6f2008-10-27 20:43:3384using base::Time;
85using base::TimeDelta;
86
[email protected]e5642992009-06-26 23:06:3187namespace {
88
initial.commit09911bf2008-07-26 23:55:2989// Delay, in milliseconds, before we explicitly create the SessionService.
90static const int kCreateSessionServiceDelayMS = 500;
91
[email protected]e5642992009-06-26 23:06:3192enum ContextType {
93 kNormalContext,
94 kMediaContext
95};
96
97// Gets the cache parameters from the command line. |type| is the type of
98// request context that we need, |cache_path| will be set to the user provided
99// path, or will not be touched if there is not an argument. |max_size| will
100// be the user provided value or zero by default.
101void GetCacheParameters(ContextType type, FilePath* cache_path,
102 int* max_size) {
103 DCHECK(cache_path);
104 DCHECK(max_size);
105
106 // Override the cache location if specified by the user.
107 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
108 switches::kDiskCacheDir));
109
110 if (!user_path.empty()) {
111 *cache_path = FilePath::FromWStringHack(user_path);
112 }
113
[email protected]b7e0a2a2009-10-13 02:07:25114 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
115 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31116 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25117 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31118
119 // By default we let the cache determine the right size.
120 *max_size = 0;
121 if (!StringToInt(value, max_size)) {
122 *max_size = 0;
123 } else if (max_size < 0) {
124 *max_size = 0;
125 }
126}
127
[email protected]405a64b2009-09-16 21:03:44128FilePath GetCachePath(const FilePath& base) {
129 return base.Append(chrome::kCacheDirname);
130}
131
132FilePath GetMediaCachePath(const FilePath& base) {
133 return base.Append(chrome::kMediaCacheDirname);
134}
135
136bool HasACacheSubdir(const FilePath &dir) {
137 return file_util::PathExists(GetCachePath(dir)) ||
138 file_util::PathExists(GetMediaCachePath(dir));
139}
140
[email protected]57a777f72010-03-31 01:09:42141void PostExtensionLoadedToContextGetter(ChromeURLRequestContextGetter* getter,
142 Extension* extension) {
143 if (!getter)
144 return;
145 // Callee takes ownership of new ExtensionInfo struct.
146 ChromeThread::PostTask(
147 ChromeThread::IO, FROM_HERE,
148 NewRunnableMethod(getter,
149 &ChromeURLRequestContextGetter::OnNewExtensions,
150 extension->id(),
151 new ChromeURLRequestContext::ExtensionInfo(
[email protected]cb58c8cf2010-05-20 05:42:59152 extension->name(),
[email protected]57a777f72010-03-31 01:09:42153 extension->path(),
154 extension->default_locale(),
155 extension->web_extent(),
156 extension->api_permissions())));
157}
158
159void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
160 Extension* extension) {
161 if (!getter)
162 return;
163 ChromeThread::PostTask(
164 ChromeThread::IO, FROM_HERE,
165 NewRunnableMethod(getter,
166 &ChromeURLRequestContextGetter::OnUnloadedExtension,
167 extension->id()));
168}
169
[email protected]5e1bf5d2010-05-26 20:52:18170// Returns true if the default apps should be loaded (so that the app panel is
171// not empty).
172bool IncludeDefaultApps() {
173#if defined(OS_WIN)
174 std::string user_domain;
175 return base::EnvVarGetter::Create()->GetEnv("USERDOMAIN", &user_domain) &&
176 user_domain == "GOOGLE";
177#elif defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
178 return true;
179#endif
180 return false;
181}
[email protected]e5642992009-06-26 23:06:31182} // namespace
183
initial.commit09911bf2008-07-26 23:55:29184// A pointer to the request context for the default profile. See comments on
185// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31186URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29187
[email protected]be180c802009-10-23 06:33:31188static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19189 if (context)
[email protected]47accfd62009-05-14 18:46:21190 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21191}
192
[email protected]34cc84f2009-02-13 10:04:35193// static
[email protected]4bf6afd2009-10-08 14:00:11194const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
195
196// static
initial.commit09911bf2008-07-26 23:55:29197void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55198 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29199 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
200 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12201 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26202 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
203 IDS_SPELLCHECK_DICTIONARY);
204 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58205 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16206#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06207 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
208 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29209#endif
[email protected]f017cc92009-12-14 20:48:07210 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34211 prefs->RegisterStringPref(prefs::kCurrentThemeID,
212 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42213 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
214 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
215 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50216 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23217 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
[email protected]35896a32010-06-09 08:42:51218 prefs->RegisterStringPref(prefs::kSelectFileLastDirectory, L"");
initial.commit09911bf2008-07-26 23:55:29219}
220
[email protected]34cc84f2009-02-13 10:04:35221// static
[email protected]f7011fcb2009-01-28 21:54:32222Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29223 return new ProfileImpl(path);
224}
225
[email protected]34cc84f2009-02-13 10:04:35226// static
[email protected]be180c802009-10-23 06:33:31227URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29228 return default_request_context_;
229}
230
[email protected]753efc42010-03-09 19:52:16231#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41232#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56233#elif defined(OS_MACOSX)
234#include "chrome/browser/keychain_mac.h"
235#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16236#elif defined(OS_POSIX)
237// Temporarily disabled while we figure some stuff out.
238// http://code.google.com/p/chromium/issues/detail?id=12351
239// #include "chrome/browser/password_manager/password_store_gnome.h"
240// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41241#endif
initial.commit09911bf2008-07-26 23:55:29242
initial.commit09911bf2008-07-26 23:55:29243////////////////////////////////////////////////////////////////////////////////
244//
245// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42246// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29247//
248////////////////////////////////////////////////////////////////////////////////
249class OffTheRecordProfileImpl : public Profile,
250 public NotificationObserver {
251 public:
252 explicit OffTheRecordProfileImpl(Profile* real_profile)
253 : profile_(real_profile),
254 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31255 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05256
initial.commit09911bf2008-07-26 23:55:29257 // Register for browser close notifications so we can detect when the last
258 // off-the-record window is closed, in which case we can clean our states
259 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43260 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
261 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29262 }
263
264 virtual ~OffTheRecordProfileImpl() {
[email protected]098c743d2010-05-04 07:58:59265 NotificationService::current()->Notify(
266 NotificationType::PROFILE_DESTROYED,
267 Source<Profile>(this),
268 NotificationService::NoDetails());
269 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29270 }
271
[email protected]4bf6afd2009-10-08 14:00:11272 virtual ProfileId GetRuntimeId() {
273 return reinterpret_cast<ProfileId>(this);
274 }
275
[email protected]a6d0f182010-01-12 08:01:44276 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29277
278 virtual bool IsOffTheRecord() {
279 return true;
280 }
281
282 virtual Profile* GetOffTheRecordProfile() {
283 return this;
284 }
285
[email protected]860f55492009-03-27 19:50:59286 virtual void DestroyOffTheRecordProfile() {
287 // Suicide is bad!
288 NOTREACHED();
289 }
290
initial.commit09911bf2008-07-26 23:55:29291 virtual Profile* GetOriginalProfile() {
292 return profile_;
293 }
294
[email protected]2f351cb2009-11-09 23:43:34295 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
296 if (!db_tracker_)
297 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
298 return db_tracker_;
299 }
300
initial.commit09911bf2008-07-26 23:55:29301 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49302 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
303 // because we don't want to leak the sites that the user has visited before.
304 return NULL;
initial.commit09911bf2008-07-26 23:55:29305 }
306
[email protected]6014d672008-12-05 00:38:25307 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21308 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25309 }
310
[email protected]0938d3c2009-01-09 20:37:35311 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21312 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25313 }
314
[email protected]89ebc7e2009-08-24 22:11:07315 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21316 // TODO(mpcomplete): figure out whether we should return the original
317 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07318 return NULL;
319 }
320
[email protected]481e1a42009-05-06 20:56:05321 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21322 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05323 }
324
[email protected]7120f132009-07-20 21:05:37325 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21326 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37327 }
328
[email protected]34cc84f2009-02-13 10:04:35329 virtual SSLHostState* GetSSLHostState() {
330 if (!ssl_host_state_.get())
331 ssl_host_state_.reset(new SSLHostState());
332
333 DCHECK(ssl_host_state_->CalledOnValidThread());
334 return ssl_host_state_.get();
335 }
336
[email protected]326e6792009-12-11 21:04:42337 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54338 if (!transport_security_state_.get())
339 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23340
[email protected]326e6792009-12-11 21:04:42341 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23342 }
343
initial.commit09911bf2008-07-26 23:55:29344 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54345 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29346 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54347
348 NOTREACHED() << "This profile is OffTheRecord";
349 return NULL;
initial.commit09911bf2008-07-26 23:55:29350 }
351
[email protected]0850fa62009-10-08 22:34:29352 virtual HistoryService* GetHistoryServiceWithoutCreating() {
353 return profile_->GetHistoryServiceWithoutCreating();
354 }
355
[email protected]0189bc722009-08-28 21:56:48356 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54357 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48358 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54359
360 NOTREACHED() << "This profile is OffTheRecord";
361 return NULL;
[email protected]0189bc722009-08-28 21:56:48362 }
363
[email protected]69c579e2010-04-23 20:01:00364 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
365 return profile_->GetAutocompleteClassifier();
[email protected]90085af02009-10-29 17:53:21366 }
367
initial.commit09911bf2008-07-26 23:55:29368 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54369 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29370 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54371
372 NOTREACHED() << "This profile is OffTheRecord";
373 return NULL;
initial.commit09911bf2008-07-26 23:55:29374 }
375
[email protected]9cddbe372009-10-23 21:23:53376 virtual WebDataService* GetWebDataServiceWithoutCreating() {
377 return profile_->GetWebDataServiceWithoutCreating();
378 }
379
[email protected]e69d33952009-06-03 22:00:41380 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54381 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41382 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54383
384 NOTREACHED() << "This profile is OffTheRecord";
385 return NULL;
[email protected]e69d33952009-06-03 22:00:41386 }
387
initial.commit09911bf2008-07-26 23:55:29388 virtual PrefService* GetPrefs() {
389 return profile_->GetPrefs();
390 }
391
392 virtual TemplateURLModel* GetTemplateURLModel() {
393 return profile_->GetTemplateURLModel();
394 }
395
396 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
397 return profile_->GetTemplateURLFetcher();
398 }
399
400 virtual DownloadManager* GetDownloadManager() {
401 if (!download_manager_.get()) {
402 scoped_refptr<DownloadManager> dlm(new DownloadManager);
403 dlm->Init(this);
404 download_manager_.swap(dlm);
405 }
406 return download_manager_.get();
407 }
408
409 virtual bool HasCreatedDownloadManager() const {
410 return (download_manager_.get() != NULL);
411 }
412
[email protected]def11712009-11-06 00:42:15413 virtual PersonalDataManager* GetPersonalDataManager() {
414 return NULL;
415 }
416
[email protected]4a190632009-05-09 01:07:42417 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54418 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42419 }
420
421 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54422 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42423 }
424
[email protected]a5166af62009-07-03 00:42:29425 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54426 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29427 }
428
[email protected]4a190632009-05-09 01:07:42429 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54430 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42431 }
432
[email protected]51c490b2009-08-03 16:34:34433 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54434 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34435 }
436
[email protected]5786d3d2009-12-18 00:18:44437 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54438 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42439 }
440
[email protected]be180c802009-10-23 06:33:31441 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29442 return request_context_;
443 }
444
[email protected]be180c802009-10-23 06:33:31445 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11446 // In OTR mode, media request context is the same as the original one.
447 return request_context_;
[email protected]e7f29642009-03-02 22:53:18448 }
449
[email protected]be180c802009-10-23 06:33:31450 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21451 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21452 }
453
[email protected]db36938c2009-08-19 21:48:42454 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54455 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42456 }
457
[email protected]e284e6d82010-01-29 19:49:45458 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]bd147842010-04-09 15:29:17459 // Retrieve the host content settings map of the parent profile in order to
460 // ensure the preferences have been migrated.
461 profile_->GetHostContentSettingsMap();
462 if (!host_content_settings_map_.get())
463 host_content_settings_map_ = new HostContentSettingsMap(this);
464 return host_content_settings_map_.get();
[email protected]e284e6d82010-01-29 19:49:45465 }
466
[email protected]40bd6582009-12-04 23:49:51467 virtual HostZoomMap* GetHostZoomMap() {
[email protected]c18d4f482010-05-18 21:19:50468 if (!host_zoom_map_)
469 host_zoom_map_ = new HostZoomMap(this);
470 return host_zoom_map_.get();
[email protected]40bd6582009-12-04 23:49:51471 }
472
[email protected]aee541e2010-03-19 01:52:45473 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
474 return profile_->GetGeolocationContentSettingsMap();
475 }
476
[email protected]8b4b84ee2010-05-11 13:08:52477 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() {
478 return profile_->GetGeolocationPermissionContext();
479 }
480
[email protected]8c6335d32010-01-20 09:21:50481 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54482 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23483 }
484
[email protected]6c32ce72010-03-08 05:18:06485 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
486 return profile_->GetUserStyleSheetWatcher();
487 }
488
[email protected]e5d2f7132010-04-09 18:13:53489 virtual FindBarState* GetFindBarState() {
490 if (!find_bar_state_.get())
491 find_bar_state_.reset(new FindBarState());
492 return find_bar_state_.get();
493 }
494
initial.commit09911bf2008-07-26 23:55:29495 virtual SessionService* GetSessionService() {
496 // Don't save any sessions when off the record.
497 return NULL;
498 }
499
500 virtual void ShutdownSessionService() {
501 // We don't allow a session service, nothing to do.
502 }
503
504 virtual bool HasSessionService() const {
505 // We never have a session service.
506 return false;
507 }
508
initial.commit09911bf2008-07-26 23:55:29509 virtual bool DidLastSessionExitCleanly() {
510 return profile_->DidLastSessionExitCleanly();
511 }
512
[email protected]d8e41ed2008-09-11 15:22:32513 virtual BookmarkModel* GetBookmarkModel() {
514 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29515 }
516
[email protected]4bb336302009-10-12 05:44:26517 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58518 if (!desktop_notification_service_.get()) {
519 desktop_notification_service_.reset(new DesktopNotificationService(
520 this, g_browser_process->notification_ui_manager()));
521 }
522 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26523 }
524
[email protected]48352c12009-08-15 01:19:11525 virtual ProfileSyncService* GetProfileSyncService() {
526 return NULL;
[email protected]3a453fa2008-08-15 18:46:34527 }
[email protected]3a453fa2008-08-15 18:46:34528
[email protected]1bd056e2010-04-20 02:03:48529 virtual CloudPrintProxyService* GetCloudPrintProxyService() {
530 return NULL;
531 }
532
initial.commit09911bf2008-07-26 23:55:29533 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54534 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29535 }
536
537 virtual Time GetStartTime() const {
538 return start_time_;
539 }
540
541 virtual TabRestoreService* GetTabRestoreService() {
542 return NULL;
543 }
544
[email protected]e7244d82008-10-29 18:13:26545 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41546 }
547
[email protected]85c55dc2009-11-06 03:05:46548 virtual SpellCheckHost* GetSpellCheckHost() {
549 return profile_->GetSpellCheckHost();
550 }
551
552 virtual void ReinitializeSpellCheckHost(bool force) {
553 profile_->ReinitializeSpellCheckHost(force);
554 }
[email protected]85c55dc2009-11-06 03:05:46555
[email protected]3bf335a2009-06-26 20:46:06556 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29557 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:11558 webkit_context_ = new WebKitContext(this);
[email protected]c27324b2009-11-19 22:44:29559 DCHECK(webkit_context_.get());
560 return webkit_context_.get();
561 }
[email protected]3bf335a2009-06-26 20:46:06562
[email protected]449478302009-06-09 20:04:28563 virtual ThumbnailStore* GetThumbnailStore() {
564 return NULL;
565 }
566
[email protected]523623c2010-05-19 16:03:42567 virtual history::TopSites* GetTopSites() {
568 return NULL;
569 }
570
initial.commit09911bf2008-07-26 23:55:29571 virtual void MarkAsCleanShutdown() {
572 }
573
[email protected]bdbc87c2009-01-25 05:08:54574 virtual void InitExtensions() {
575 NOTREACHED();
576 }
577
[email protected]ea0c98cf2009-06-18 23:02:54578 virtual void InitWebResources() {
579 NOTREACHED();
580 }
581
[email protected]9c8dd902009-11-19 17:50:42582 virtual NTPResourceCache* GetNTPResourceCache() {
583 // Just return the real profile resource cache.
584 return profile_->GetNTPResourceCache();
585 }
586
[email protected]35896a32010-06-09 08:42:51587 virtual FilePath last_selected_directory() {
588 const FilePath& directory = last_selected_directory_;
589 if (directory.empty()) {
590 return profile_->last_selected_directory();
591 }
592 return directory;
593 }
594
595 virtual void set_last_selected_directory(const FilePath& path) {
596 last_selected_directory_ = path;
597 }
598
initial.commit09911bf2008-07-26 23:55:29599 virtual void ExitedOffTheRecordMode() {
600 // Drop our download manager so we forget about all the downloads made
601 // in off-the-record mode.
602 download_manager_ = NULL;
603 }
604
605 virtual void Observe(NotificationType type,
606 const NotificationSource& source,
607 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56608 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29609 // We are only interested in OTR browser closing.
610 if (Source<Browser>(source)->profile() != this)
611 return;
612
613 // Let's check if we still have an Off The Record window opened.
614 // Note that we check against 1 as this notification is sent before the
615 // browser window is actually removed from the list.
616 if (BrowserList::GetBrowserCount(this) <= 1)
617 ExitedOffTheRecordMode();
618 }
619
620 private:
[email protected]88cf3292009-05-22 01:48:43621 NotificationRegistrar registrar_;
622
initial.commit09911bf2008-07-26 23:55:29623 // The real underlying profile.
624 Profile* profile_;
625
[email protected]6ab9b202008-12-23 22:34:50626 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19627 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29628
629 // The download manager that only stores downloaded items in memory.
630 scoped_refptr<DownloadManager> download_manager_;
631
[email protected]7d7696c52009-12-01 20:54:58632 // Use a separate desktop notification service for OTR.
633 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
634
[email protected]bd147842010-04-09 15:29:17635 // We use a non-writable content settings map for OTR.
636 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
637
[email protected]c18d4f482010-05-18 21:19:50638 // Use a separate zoom map for OTR.
639 scoped_refptr<HostZoomMap> host_zoom_map_;
640
[email protected]3bf335a2009-06-26 20:46:06641 // Use a special WebKit context for OTR browsing.
642 scoped_refptr<WebKitContext> webkit_context_;
643
[email protected]34cc84f2009-02-13 10:04:35644 // We don't want SSLHostState from the OTR profile to leak back to the main
645 // profile because then the main profile would learn some of the host names
646 // the user visited while OTR.
647 scoped_ptr<SSLHostState> ssl_host_state_;
648
[email protected]e5d2f7132010-04-09 18:13:53649 // Use a separate FindBarState so search terms do not leak back to the main
650 // profile.
651 scoped_ptr<FindBarState> find_bar_state_;
652
[email protected]326e6792009-12-11 21:04:42653 // The TransportSecurityState that only stores enabled sites in memory.
654 scoped_refptr<net::TransportSecurityState>
655 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23656
initial.commit09911bf2008-07-26 23:55:29657 // Time we were started.
658 Time start_time_;
659
[email protected]2f351cb2009-11-09 23:43:34660 // The main database tracker for this profile.
661 // Should be used only on the file thread.
662 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
663
[email protected]35896a32010-06-09 08:42:51664 FilePath last_selected_directory_;
665
[email protected]90085af02009-10-29 17:53:21666 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29667};
668
[email protected]f7011fcb2009-01-28 21:54:32669ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29670 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44671 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07672 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32673 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57674 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21675 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45676 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51677 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32678 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48679 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32680 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41681 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32682 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42683 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32684 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46685 spellcheck_host_(NULL),
686 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29687 shutdown_session_service_(false) {
688 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
689 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14690 create_session_service_timer_.Start(
691 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
692 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54693
[email protected]e7244d82008-10-29 18:13:26694 PrefService* prefs = GetPrefs();
695 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
696 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58697 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58698
[email protected]405a64b2009-09-16 21:03:44699#if defined(OS_MACOSX)
700 // If the profile directory doesn't already have a cache directory and it
701 // is under ~/Library/Application Support, use a suitable cache directory
702 // under ~/Library/Caches. For example, a profile directory of
703 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
704 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
705 // ~/Library/Caches/Google/Chrome/MyProfileName.
706 //
707 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44708 if (!HasACacheSubdir(path_)) {
709 FilePath app_data_path, user_cache_path;
710 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12711 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44712 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
713 base_cache_path_ = user_cache_path;
714 }
715 }
[email protected]9e9b6e8e2009-12-02 08:45:01716#elif defined(OS_POSIX) // Posix minus Mac.
717 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
718 // for a spec on where cache files go. The net effect for most systems is we
719 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
720 // official builds.
721 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
722#if defined(GOOGLE_CHROME_BUILD)
723 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44724#else
[email protected]9e9b6e8e2009-12-02 08:45:01725 const char kCacheDir[] = "chromium";
726#endif
727 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
728 base_cache_path_ = base_cache_path_.Append(kCacheDir);
729 if (!file_util::PathExists(base_cache_path_))
730 file_util::CreateDirectory(base_cache_path_);
731 }
[email protected]405a64b2009-09-16 21:03:44732#endif
[email protected]bc96d562009-08-11 18:45:13733 if (base_cache_path_.empty())
734 base_cache_path_ = path_;
735
[email protected]4a190632009-05-09 01:07:42736 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43737 registrar_.Add(this, NotificationType::THEME_INSTALLED,
738 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11739
740 // Listen for bookmark model load, to bootstrap the sync service.
741 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
742 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42743
744 ssl_config_service_manager_.reset(
745 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53746
747#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29748 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53749#endif
[email protected]911f8152010-03-18 16:46:40750
751 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29752}
753
[email protected]bdbc87c2009-01-25 05:08:54754void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41755 if (user_script_master_ || extensions_service_)
756 return; // Already initialized.
757
[email protected]bdbc87c2009-01-25 05:08:54758 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]1172ba72010-05-21 22:21:11759 if (command_line->HasSwitch(
760 switches::kEnableExtensionTimelineApi)) {
761 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
762 }
763
764 extension_process_manager_.reset(new ExtensionProcessManager(this));
765 extension_message_service_ = new ExtensionMessageService(this);
766
[email protected]bb28e062009-02-27 17:19:18767 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36768
769 FilePath script_dir; // Don't look for user scripts in any directory.
770 // TODO(aa): We should just remove this functionality,
771 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51772 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36773
[email protected]894bb502009-05-21 22:39:57774 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23775 this,
776 CommandLine::ForCurrentProcess(),
777 GetPrefs(),
778 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36779 true);
[email protected]bdbc87c2009-01-25 05:08:54780
[email protected]fee67982010-04-23 17:24:22781 // Register the component extensions.
782 std::map<std::string, int> component_extensions;
783
784 // Bookmark manager.
[email protected]47e532b2010-04-23 17:46:40785 component_extensions["bookmark_manager"] = IDR_BOOKMARKS_MANIFEST;
[email protected]fee67982010-04-23 17:24:22786
[email protected]abdc9fb52010-05-06 01:44:48787#if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
[email protected]ae90f252010-05-04 18:28:03788 // Chat manager.
789 if (CommandLine::ForCurrentProcess()->HasSwitch(
790 switches::kEnableChatManager)) {
791 component_extensions["chat_manager"] = IDR_CHAT_MANAGER_MANIFEST;
792 }
793#endif
794
[email protected]fee67982010-04-23 17:24:22795 // Some sample apps to make our lives easier while we are developing extension
796 // apps. This way we don't have to constantly install these over and over.
[email protected]5e1bf5d2010-05-26 20:52:18797 if (Extension::AppsAreEnabled() && IncludeDefaultApps()) {
798 component_extensions["gmail_app"] = IDR_GMAIL_APP_MANIFEST;
799 component_extensions["calendar_app"] = IDR_CALENDAR_APP_MANIFEST;
800 component_extensions["docs_app"] = IDR_DOCS_APP_MANIFEST;
[email protected]fee67982010-04-23 17:24:22801 }
802
803 for (std::map<std::string, int>::iterator iter = component_extensions.begin();
804 iter != component_extensions.end(); ++iter) {
805 FilePath path;
806 if (PathService::Get(chrome::DIR_RESOURCES, &path)) {
807 path = path.AppendASCII(iter->first);
[email protected]1952c7d2010-03-04 23:48:34808 } else {
809 NOTREACHED();
810 }
[email protected]fee67982010-04-23 17:24:22811
812 std::string manifest =
813 ResourceBundle::GetSharedInstance().GetRawDataResource(
814 iter->second).as_string();
815 extensions_service_->register_component_extension(
816 ExtensionsService::ComponentExtensionInfo(manifest, path));
[email protected]1952c7d2010-03-04 23:48:34817 }
818
[email protected]9197f3b2009-06-02 00:49:27819 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12820
821 // Load any extensions specified with --load-extension.
822 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10823 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12824 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12825 }
[email protected]bdbc87c2009-01-25 05:08:54826}
827
[email protected]ea0c98cf2009-06-18 23:02:54828void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07829 if (web_resource_service_)
830 return; // Already initialized.
831
[email protected]6fad2632009-11-02 05:59:37832 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54833 web_resource_service_->StartAfterDelay();
834}
835
[email protected]9c8dd902009-11-19 17:50:42836NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
837 if (!ntp_resource_cache_.get())
838 ntp_resource_cache_.reset(new NTPResourceCache(this));
839 return ntp_resource_cache_.get();
840}
841
[email protected]35896a32010-06-09 08:42:51842FilePath ProfileImpl::last_selected_directory() {
843 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory);
844}
845
846void ProfileImpl::set_last_selected_directory(const FilePath& path) {
847 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path);
848}
849
initial.commit09911bf2008-07-26 23:55:29850ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56851 NotificationService::current()->Notify(
852 NotificationType::PROFILE_DESTROYED,
853 Source<Profile>(this),
854 NotificationService::NoDetails());
855
[email protected]169627b2008-12-06 19:30:19856 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29857
858 StopCreateSessionServiceTimer();
859 // TemplateURLModel schedules a task on the WebDataService from its
860 // destructor. Delete it first to ensure the task gets scheduled before we
861 // shut down the database.
862 template_url_model_.reset();
863
864 // The download manager queries the history system and should be deleted
865 // before the history is shutdown so it can properly cancel all requests.
866 download_manager_ = NULL;
867
[email protected]4a190632009-05-09 01:07:42868 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15869 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42870
[email protected]44961292009-07-20 20:03:09871 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
872 // save any new thumbnails to disk and release its reference to the
873 // HistoryService.
874 if (thumbnail_store_.get())
875 thumbnail_store_->Shutdown();
876
[email protected]e7244d82008-10-29 18:13:26877 // Remove pref observers.
878 PrefService* prefs = GetPrefs();
879 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
880 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58881 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26882
[email protected]9c8dd902009-11-19 17:50:42883 // Delete the NTP resource cache so we can unregister pref observers.
884 ntp_resource_cache_.reset();
885
[email protected]48352c12009-08-15 01:19:11886 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34887
initial.commit09911bf2008-07-26 23:55:29888 // Both HistoryService and WebDataService maintain threads for background
889 // processing. Its possible each thread still has tasks on it that have
890 // increased the ref count of the service. In such a situation, when we
891 // decrement the refcount, it won't be 0, and the threads/databases aren't
892 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
893 // databases are properly closed.
894 if (web_data_service_.get())
895 web_data_service_->Shutdown();
896
897 if (history_service_.get())
898 history_service_->Cleanup();
899
[email protected]85c55dc2009-11-06 03:05:46900 if (spellcheck_host_.get())
901 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29902
[email protected]cfc06f122009-11-16 22:18:55903 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21904 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50905
[email protected]47accfd62009-05-14 18:46:21906 CleanupRequestContext(request_context_);
907 CleanupRequestContext(media_request_context_);
908 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17909
[email protected]d8e41ed2008-09-11 15:22:32910 // HistoryService may call into the BookmarkModel, as such we need to
911 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46912 // HistoryService will join with HistoryService's backend thread so that
913 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32914 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46915 history_service_ = NULL;
916 bookmark_bar_model_.reset();
917
[email protected]0189bc722009-08-28 21:56:48918 // FaviconService depends on HistoryServce so make sure we delete
919 // HistoryService first.
920 favicon_service_ = NULL;
921
[email protected]1172ba72010-05-21 22:21:11922 if (extension_message_service_)
923 extension_message_service_->ProfileDestroyed();
[email protected]7120f132009-07-20 21:05:37924
[email protected]6ef635e42009-07-26 06:16:12925 if (extensions_service_)
926 extensions_service_->ProfileDestroyed();
927
[email protected]66da08b2009-10-19 22:27:00928 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29929 MarkAsCleanShutdown();
930}
931
[email protected]4bf6afd2009-10-08 14:00:11932ProfileId ProfileImpl::GetRuntimeId() {
933 return reinterpret_cast<ProfileId>(this);
934}
935
[email protected]f7011fcb2009-01-28 21:54:32936FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29937 return path_;
938}
939
940bool ProfileImpl::IsOffTheRecord() {
941 return false;
942}
943
944Profile* ProfileImpl::GetOffTheRecordProfile() {
945 if (!off_the_record_profile_.get()) {
946 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
947 off_the_record_profile_.swap(p);
948 }
949 return off_the_record_profile_.get();
950}
951
[email protected]860f55492009-03-27 19:50:59952void ProfileImpl::DestroyOffTheRecordProfile() {
953 off_the_record_profile_.reset();
954}
955
initial.commit09911bf2008-07-26 23:55:29956Profile* ProfileImpl::GetOriginalProfile() {
957 return this;
958}
959
[email protected]2f351cb2009-11-09 23:43:34960webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
961 if (!db_tracker_)
962 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
963 return db_tracker_;
964}
965
initial.commit09911bf2008-07-26 23:55:29966VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44967 if (!visited_link_master_.get()) {
968 scoped_ptr<VisitedLinkMaster> visited_links(
969 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
970 if (!visited_links->Init())
971 return NULL;
972 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53973 }
[email protected]a6d0f182010-01-12 08:01:44974
975 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29976}
977
[email protected]6014d672008-12-05 00:38:25978ExtensionsService* ProfileImpl::GetExtensionsService() {
979 return extensions_service_.get();
980}
981
[email protected]0938d3c2009-01-09 20:37:35982UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35983 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25984}
985
[email protected]89ebc7e2009-08-24 22:11:07986ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
987 return extension_devtools_manager_.get();
988}
989
[email protected]481e1a42009-05-06 20:56:05990ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27991 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05992}
993
[email protected]7120f132009-07-20 21:05:37994ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
995 return extension_message_service_.get();
996}
997
[email protected]34cc84f2009-02-13 10:04:35998SSLHostState* ProfileImpl::GetSSLHostState() {
999 if (!ssl_host_state_.get())
1000 ssl_host_state_.reset(new SSLHostState());
1001
1002 DCHECK(ssl_host_state_->CalledOnValidThread());
1003 return ssl_host_state_.get();
1004}
1005
[email protected]326e6792009-12-11 21:04:421006net::TransportSecurityState*
1007 ProfileImpl::GetTransportSecurityState() {
1008 if (!transport_security_state_.get()) {
1009 transport_security_state_ = new net::TransportSecurityState();
1010 transport_security_persister_ =
1011 new TransportSecurityPersister();
1012 transport_security_persister_->Initialize(
1013 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:511014 }
[email protected]a9cea7542009-05-20 04:30:231015
[email protected]326e6792009-12-11 21:04:421016 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:231017}
1018
initial.commit09911bf2008-07-26 23:55:291019PrefService* ProfileImpl::GetPrefs() {
1020 if (!prefs_.get()) {
[email protected]d8b08c92010-06-07 13:13:281021 prefs_.reset(PrefService::CreatePrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:291022
1023 // The Profile class and ProfileManager class may read some prefs so
1024 // register known prefs as soon as possible.
1025 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:511026 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:291027
1028 // The last session exited cleanly if there is no pref for
1029 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
1030 last_session_exited_cleanly_ =
1031 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
1032 // Mark the session as open.
1033 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
1034 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:361035 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291036 }
1037
1038 return prefs_.get();
1039}
1040
[email protected]f7011fcb2009-01-28 21:54:321041FilePath ProfileImpl::GetPrefFilePath() {
1042 FilePath pref_file_path = path_;
1043 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:291044 return pref_file_path;
1045}
1046
[email protected]be180c802009-10-23 06:33:311047URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:291048 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:321049 FilePath cookie_path = GetPath();
1050 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:131051 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311052 int max_size;
1053 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:421054
[email protected]405a64b2009-09-16 21:03:441055 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311056 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
1057 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:291058
[email protected]6ab9b202008-12-23 22:34:501059 // The first request context is always a normal (non-OTR) request context.
1060 // Even when Chromium is started in OTR mode, a normal profile is always
1061 // created first.
1062 if (!default_request_context_) {
1063 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:311064 // TODO(eroman): this isn't terribly useful anymore now that the
1065 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:501066 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561067 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:501068 NotificationService::AllSources(), NotificationService::NoDetails());
1069 }
initial.commit09911bf2008-07-26 23:55:291070 }
1071
1072 return request_context_;
1073}
1074
[email protected]be180c802009-10-23 06:33:311075URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:181076 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:131077 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311078 int max_size;
1079 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:141080
[email protected]405a64b2009-09-16 21:03:441081 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311082 media_request_context_ =
1083 ChromeURLRequestContextGetter::CreateOriginalForMedia(
1084 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:181085 }
1086
1087 return media_request_context_;
1088}
1089
[email protected]0189bc722009-08-28 21:56:481090FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
1091 if (!favicon_service_created_) {
1092 favicon_service_created_ = true;
1093 scoped_refptr<FaviconService> service(new FaviconService(this));
1094 favicon_service_.swap(service);
1095 }
1096 return favicon_service_.get();
1097}
1098
[email protected]be180c802009-10-23 06:33:311099URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:211100 if (!extensions_request_context_) {
1101 FilePath cookie_path = GetPath();
1102 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1103
1104 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:311105 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
1106 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:211107 }
1108
1109 return extensions_request_context_;
1110}
1111
[email protected]57a777f72010-03-31 01:09:421112void ProfileImpl::RegisterExtensionWithRequestContexts(
1113 Extension* extension) {
1114 // Notify the default, extension and media contexts on the IO thread.
1115 PostExtensionLoadedToContextGetter(
1116 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1117 extension);
1118 PostExtensionLoadedToContextGetter(
1119 static_cast<ChromeURLRequestContextGetter*>(
1120 GetRequestContextForExtensions()),
1121 extension);
1122 PostExtensionLoadedToContextGetter(
1123 static_cast<ChromeURLRequestContextGetter*>(
1124 GetRequestContextForMedia()),
1125 extension);
1126}
1127
1128void ProfileImpl::UnregisterExtensionWithRequestContexts(
1129 Extension* extension) {
1130 // Notify the default, extension and media contexts on the IO thread.
1131 PostExtensionUnloadedToContextGetter(
1132 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1133 extension);
1134 PostExtensionUnloadedToContextGetter(
1135 static_cast<ChromeURLRequestContextGetter*>(
1136 GetRequestContextForExtensions()),
1137 extension);
1138 PostExtensionUnloadedToContextGetter(
1139 static_cast<ChromeURLRequestContextGetter*>(
1140 GetRequestContextForMedia()),
1141 extension);
1142}
1143
[email protected]db36938c2009-08-19 21:48:421144net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1145 return ssl_config_service_manager_->Get();
1146}
1147
[email protected]e284e6d82010-01-29 19:49:451148HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
1149 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:391150 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:451151 return host_content_settings_map_.get();
1152}
1153
[email protected]40bd6582009-12-04 23:49:511154HostZoomMap* ProfileImpl::GetHostZoomMap() {
1155 if (!host_zoom_map_)
1156 host_zoom_map_ = new HostZoomMap(this);
1157 return host_zoom_map_.get();
1158}
1159
[email protected]aee541e2010-03-19 01:52:451160GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
1161 if (!geolocation_content_settings_map_.get())
1162 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
1163 return geolocation_content_settings_map_.get();
1164}
1165
[email protected]8b4b84ee2010-05-11 13:08:521166GeolocationPermissionContext* ProfileImpl::GetGeolocationPermissionContext() {
1167 if (!geolocation_permission_context_.get())
1168 geolocation_permission_context_ = new GeolocationPermissionContext(this);
1169 return geolocation_permission_context_.get();
1170}
1171
[email protected]8c6335d32010-01-20 09:21:501172Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271173 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141174 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271175 return NULL;
[email protected]c37f8b42010-01-23 16:22:141176 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541177 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501178 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231179}
1180
[email protected]6c32ce72010-03-08 05:18:061181UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1182 if (!user_style_sheet_watcher_.get()) {
1183 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1184 user_style_sheet_watcher_->Init();
1185 }
1186 return user_style_sheet_watcher_.get();
1187}
1188
[email protected]e5d2f7132010-04-09 18:13:531189FindBarState* ProfileImpl::GetFindBarState() {
1190 if (!find_bar_state_.get()) {
1191 find_bar_state_.reset(new FindBarState());
1192 }
1193 return find_bar_state_.get();
1194}
1195
initial.commit09911bf2008-07-26 23:55:291196HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1197 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461198 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291199 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321200 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291201 return NULL;
1202 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291203
1204 // Send out the notification that the history service was created.
1205 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561206 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291207 Details<HistoryService>(history_service_.get()));
1208 }
1209 return history_service_.get();
1210}
1211
[email protected]0850fa62009-10-08 22:34:291212HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1213 return history_service_.get();
1214}
1215
initial.commit09911bf2008-07-26 23:55:291216TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1217 if (!template_url_model_.get())
1218 template_url_model_.reset(new TemplateURLModel(this));
1219 return template_url_model_.get();
1220}
1221
1222TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1223 if (!template_url_fetcher_.get())
1224 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1225 return template_url_fetcher_.get();
1226}
1227
[email protected]69c579e2010-04-23 20:01:001228AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
1229 if (!autocomplete_classifier_.get())
1230 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
1231 return autocomplete_classifier_.get();
[email protected]90085af02009-10-29 17:53:211232}
1233
initial.commit09911bf2008-07-26 23:55:291234WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1235 if (!created_web_data_service_)
1236 CreateWebDataService();
1237 return web_data_service_.get();
1238}
1239
[email protected]9cddbe372009-10-23 21:23:531240WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1241 return web_data_service_.get();
1242}
1243
initial.commit09911bf2008-07-26 23:55:291244void ProfileImpl::CreateWebDataService() {
1245 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1246 created_web_data_service_ = true;
1247 scoped_refptr<WebDataService> wds(new WebDataService());
1248 if (!wds->Init(GetPath()))
1249 return;
1250 web_data_service_.swap(wds);
1251}
1252
[email protected]e69d33952009-06-03 22:00:411253PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1254 if (!created_password_store_)
1255 CreatePasswordStore();
1256 return password_store_.get();
1257}
1258
1259void ProfileImpl::CreatePasswordStore() {
1260 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1261 created_password_store_ = true;
1262 scoped_refptr<PasswordStore> ps;
[email protected]e0411ae52009-06-30 23:59:171263 FilePath login_db_file_path = GetPath();
1264 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
[email protected]ec44cd52010-04-05 22:30:471265 LoginDatabase* login_db = new LoginDatabase();
[email protected]e0411ae52009-06-30 23:59:171266 if (!login_db->Init(login_db_file_path)) {
1267 LOG(ERROR) << "Could not initialize login database.";
1268 delete login_db;
1269 return;
1270 }
[email protected]e8380f52010-04-30 16:39:421271#if defined(OS_WIN)
1272 ps = new PasswordStoreWin(login_db, this,
1273 GetWebDataService(Profile::IMPLICIT_ACCESS));
1274#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171275 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161276#elif defined(OS_POSIX)
1277 // TODO(evanm): implement "native" password management.
1278 // This bug describes the issues.
1279 // http://code.google.com/p/chromium/issues/detail?id=12351
[email protected]e8380f52010-04-30 16:39:421280 ps = new PasswordStoreDefault(login_db, this,
1281 GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]e69d33952009-06-03 22:00:411282#else
1283 NOTIMPLEMENTED();
1284#endif
[email protected]e8380f52010-04-30 16:39:421285 if (!ps)
1286 delete login_db;
1287
[email protected]e69d33952009-06-03 22:00:411288 if (!ps || !ps->Init()) {
[email protected]e8380f52010-04-30 16:39:421289 NOTREACHED() << "Could not initialise password manager";
1290 return;
[email protected]e69d33952009-06-03 22:00:411291 }
1292 password_store_.swap(ps);
1293}
1294
initial.commit09911bf2008-07-26 23:55:291295DownloadManager* ProfileImpl::GetDownloadManager() {
1296 if (!created_download_manager_) {
1297 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1298 dlm->Init(this);
1299 created_download_manager_ = true;
1300 download_manager_.swap(dlm);
1301 }
1302 return download_manager_.get();
1303}
1304
1305bool ProfileImpl::HasCreatedDownloadManager() const {
1306 return created_download_manager_;
1307}
1308
[email protected]def11712009-11-06 00:42:151309PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1310 if (!personal_data_manager_.get()) {
[email protected]36c1ff9fd2010-06-03 20:08:591311 personal_data_manager_ = new PersonalDataManager();
[email protected]e0976a72010-04-02 01:25:241312 personal_data_manager_->Init(this);
[email protected]def11712009-11-06 00:42:151313 }
1314 return personal_data_manager_.get();
1315}
1316
[email protected]4a190632009-05-09 01:07:421317void ProfileImpl::InitThemes() {
1318 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161319#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151320 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291321#else
[email protected]761962c2009-09-25 00:18:151322 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291323#endif
[email protected]761962c2009-09-25 00:18:151324 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421325 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421326 }
1327}
1328
1329void ProfileImpl::SetTheme(Extension* extension) {
1330 InitThemes();
1331 theme_provider_.get()->SetTheme(extension);
1332}
1333
[email protected]a5166af62009-07-03 00:42:291334void ProfileImpl::SetNativeTheme() {
1335 InitThemes();
1336 theme_provider_.get()->SetNativeTheme();
1337}
1338
[email protected]4a190632009-05-09 01:07:421339void ProfileImpl::ClearTheme() {
1340 InitThemes();
1341 theme_provider_.get()->UseDefaultTheme();
1342}
1343
[email protected]51c490b2009-08-03 16:34:341344Extension* ProfileImpl::GetTheme() {
1345 InitThemes();
1346
1347 std::string id = theme_provider_.get()->GetThemeID();
1348 if (id == BrowserThemeProvider::kDefaultThemeID)
1349 return NULL;
1350
[email protected]61b411612009-11-10 23:17:411351 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341352}
1353
[email protected]5786d3d2009-12-18 00:18:441354BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421355 InitThemes();
1356 return theme_provider_.get();
1357}
1358
initial.commit09911bf2008-07-26 23:55:291359SessionService* ProfileImpl::GetSessionService() {
1360 if (!session_service_.get() && !shutdown_session_service_) {
1361 session_service_ = new SessionService(this);
1362 session_service_->ResetFromCurrentBrowsers();
1363 }
1364 return session_service_.get();
1365}
1366
1367void ProfileImpl::ShutdownSessionService() {
1368 if (shutdown_session_service_)
1369 return;
1370
1371 // We're about to exit, force creation of the session service if it hasn't
1372 // been created yet. We do this to ensure session state matches the point in
1373 // time the user exited.
1374 GetSessionService();
1375 shutdown_session_service_ = true;
1376 session_service_ = NULL;
1377}
1378
1379bool ProfileImpl::HasSessionService() const {
1380 return (session_service_.get() != NULL);
1381}
1382
initial.commit09911bf2008-07-26 23:55:291383bool ProfileImpl::DidLastSessionExitCleanly() {
1384 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1385 // it to be set by asking for the prefs.
1386 GetPrefs();
1387 return last_session_exited_cleanly_;
1388}
1389
[email protected]d8e41ed2008-09-11 15:22:321390BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461391 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321392 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461393 bookmark_bar_model_->Load();
1394 }
initial.commit09911bf2008-07-26 23:55:291395 return bookmark_bar_model_.get();
1396}
1397
1398bool ProfileImpl::IsSameProfile(Profile* profile) {
1399 if (profile == static_cast<Profile*>(this))
1400 return true;
1401 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1402 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1403}
1404
1405Time ProfileImpl::GetStartTime() const {
1406 return start_time_;
1407}
1408
1409TabRestoreService* ProfileImpl::GetTabRestoreService() {
1410 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191411 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291412 return tab_restore_service_.get();
1413}
1414
[email protected]449478302009-06-09 20:04:281415ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1416 if (!thumbnail_store_.get()) {
1417 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251418 thumbnail_store_->Init(
1419 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281420 }
1421 return thumbnail_store_.get();
1422}
1423
[email protected]523623c2010-05-19 16:03:421424history::TopSites* ProfileImpl::GetTopSites() {
1425 if (!top_sites_.get()) {
1426 top_sites_ = new history::TopSites(this);
1427 top_sites_->Init();
1428 }
1429 return top_sites_;
1430}
1431
initial.commit09911bf2008-07-26 23:55:291432void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191433 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291434}
1435
[email protected]85c55dc2009-11-06 03:05:461436SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1437 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1438}
1439
1440void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1441 // If we are already loading the spellchecker, and this is just a hint to
1442 // load the spellchecker, do nothing.
1443 if (!force && spellcheck_host_.get())
1444 return;
1445
[email protected]f41301e2009-11-16 21:30:071446 spellcheck_host_ready_ = false;
1447
[email protected]85c55dc2009-11-06 03:05:461448 bool notify = false;
1449 if (spellcheck_host_.get()) {
1450 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051451 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461452 notify = true;
1453 }
1454
1455 PrefService* prefs = GetPrefs();
1456 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1457 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1458 spellcheck_host_ = new SpellCheckHost(this,
1459 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1460 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071461 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461462 } else if (notify) {
1463 // The spellchecker has been disabled.
1464 SpellCheckHostInitialized();
1465 }
1466}
1467
1468void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171469 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291470 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1471 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461472 NotificationService::current()->Notify(
1473 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1474 Source<Profile>(this), NotificationService::NoDetails());
1475}
initial.commit09911bf2008-07-26 23:55:291476
[email protected]3bf335a2009-06-26 20:46:061477WebKitContext* ProfileImpl::GetWebKitContext() {
1478 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:111479 webkit_context_ = new WebKitContext(this);
[email protected]3bf335a2009-06-26 20:46:061480 DCHECK(webkit_context_.get());
1481 return webkit_context_.get();
1482}
1483
[email protected]4bb336302009-10-12 05:44:261484DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1485 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1486 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261487 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031488 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261489 }
[email protected]4bb336302009-10-12 05:44:261490 return desktop_notification_service_.get();
1491}
1492
initial.commit09911bf2008-07-26 23:55:291493void ProfileImpl::MarkAsCleanShutdown() {
1494 if (prefs_.get()) {
1495 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1496 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1497
1498 // NOTE: If you change what thread this writes on, be sure and update
1499 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361500 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291501 }
1502}
1503
[email protected]e7244d82008-10-29 18:13:261504void ProfileImpl::Observe(NotificationType type,
1505 const NotificationSource& source,
1506 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561507 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261508 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1509 PrefService* prefs = Source<PrefService>(source).ptr();
1510 DCHECK(pref_name_in && prefs);
1511 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461512 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461513 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291514 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1515 NotificationService::current()->Notify(
1516 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1517 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261518 }
[email protected]4a190632009-05-09 01:07:421519 } else if (NotificationType::THEME_INSTALLED == type) {
1520 Extension* extension = Details<Extension>(details).ptr();
1521 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111522 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1523 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1524 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1525 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261526 }
1527}
1528
initial.commit09911bf2008-07-26 23:55:291529void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141530 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291531}
[email protected]3a453fa2008-08-15 18:46:341532
[email protected]48352c12009-08-15 01:19:111533ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431534 if (!ProfileSyncService::IsSyncEnabled()) {
1535 return NULL;
[email protected]7367f1a2009-10-10 01:09:441536 }
[email protected]eec3bcfa2009-11-12 17:23:431537 if (!sync_service_.get())
1538 InitSyncService();
1539 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111540}
1541
[email protected]1bd056e2010-04-20 02:03:481542CloudPrintProxyService* ProfileImpl::GetCloudPrintProxyService() {
1543 if (!cloud_print_proxy_service_.get())
1544 InitCloudPrintProxyService();
1545 return cloud_print_proxy_service_.get();
1546}
1547
[email protected]48352c12009-08-15 01:19:111548void ProfileImpl::InitSyncService() {
[email protected]82d9d2952010-05-15 00:36:161549 network_change_notifier_thread_.reset(
1550 new NetworkChangeNotifierIOThread(g_browser_process->io_thread()));
[email protected]4aea04a2010-02-10 20:13:431551 profile_sync_factory_.reset(
1552 new ProfileSyncFactoryImpl(this,
[email protected]82d9d2952010-05-15 00:36:161553 network_change_notifier_thread_.get(),
[email protected]4aea04a2010-02-10 20:13:431554 CommandLine::ForCurrentProcess()));
1555 sync_service_.reset(
1556 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111557 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111558}
[email protected]1bd056e2010-04-20 02:03:481559
1560void ProfileImpl::InitCloudPrintProxyService() {
1561 cloud_print_proxy_service_.reset(new CloudPrintProxyService(this));
1562 cloud_print_proxy_service_->Initialize();
1563}