blob: fd82db14c54bf8abaa7accc24a15eb730c752584 [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]7120f132009-07-20 21:05:3728#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0529#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2530#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3531#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4832#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5333#include "chrome/browser/find_bar_state.h"
[email protected]aee541e2010-03-19 01:52:4534#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]9c92d192009-12-02 08:03:1635#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4236#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4237#include "chrome/browser/history/history.h"
[email protected]e284e6d82010-01-29 19:49:4538#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5139#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0640#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]277404c22010-04-22 13:09:4541#include "chrome/browser/json_pref_store.h"
[email protected]6ab9b202008-12-23 22:34:5042#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4243#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2644#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4145#include "chrome/browser/password_manager/password_store_default.h"
[email protected]3cf7b302010-04-15 19:02:5846#include "chrome/browser/password_manager/password_store_linux.h"
[email protected]8c6335d32010-01-20 09:21:5047#include "chrome/browser/privacy_blacklist/blacklist.h"
[email protected]1bd056e2010-04-20 02:03:4848#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2650#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3351#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4652#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4453#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3054#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3355#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1156#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4357#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4058#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2859#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0660#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2961#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3962#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2963#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5664#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2965#include "chrome/common/chrome_constants.h"
66#include "chrome/common/chrome_paths.h"
67#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5868#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2969#include "chrome/common/notification_service.h"
70#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3271#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3472#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5873#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4274#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3475#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2976
[email protected]753efc42010-03-09 19:52:1677#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2978#include "chrome/browser/gtk/gtk_theme_provider.h"
79#endif
80
[email protected]e1acf6f2008-10-27 20:43:3381using base::Time;
82using base::TimeDelta;
83
[email protected]e5642992009-06-26 23:06:3184namespace {
85
initial.commit09911bf2008-07-26 23:55:2986// Delay, in milliseconds, before we explicitly create the SessionService.
87static const int kCreateSessionServiceDelayMS = 500;
88
[email protected]e5642992009-06-26 23:06:3189enum ContextType {
90 kNormalContext,
91 kMediaContext
92};
93
94// Gets the cache parameters from the command line. |type| is the type of
95// request context that we need, |cache_path| will be set to the user provided
96// path, or will not be touched if there is not an argument. |max_size| will
97// be the user provided value or zero by default.
98void GetCacheParameters(ContextType type, FilePath* cache_path,
99 int* max_size) {
100 DCHECK(cache_path);
101 DCHECK(max_size);
102
103 // Override the cache location if specified by the user.
104 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
105 switches::kDiskCacheDir));
106
107 if (!user_path.empty()) {
108 *cache_path = FilePath::FromWStringHack(user_path);
109 }
110
[email protected]b7e0a2a2009-10-13 02:07:25111 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
112 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31113 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25114 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31115
116 // By default we let the cache determine the right size.
117 *max_size = 0;
118 if (!StringToInt(value, max_size)) {
119 *max_size = 0;
120 } else if (max_size < 0) {
121 *max_size = 0;
122 }
123}
124
[email protected]405a64b2009-09-16 21:03:44125FilePath GetCachePath(const FilePath& base) {
126 return base.Append(chrome::kCacheDirname);
127}
128
129FilePath GetMediaCachePath(const FilePath& base) {
130 return base.Append(chrome::kMediaCacheDirname);
131}
132
133bool HasACacheSubdir(const FilePath &dir) {
134 return file_util::PathExists(GetCachePath(dir)) ||
135 file_util::PathExists(GetMediaCachePath(dir));
136}
137
[email protected]57a777f72010-03-31 01:09:42138void PostExtensionLoadedToContextGetter(ChromeURLRequestContextGetter* getter,
139 Extension* extension) {
140 if (!getter)
141 return;
142 // Callee takes ownership of new ExtensionInfo struct.
143 ChromeThread::PostTask(
144 ChromeThread::IO, FROM_HERE,
145 NewRunnableMethod(getter,
146 &ChromeURLRequestContextGetter::OnNewExtensions,
147 extension->id(),
148 new ChromeURLRequestContext::ExtensionInfo(
149 extension->path(),
150 extension->default_locale(),
151 extension->web_extent(),
152 extension->api_permissions())));
153}
154
155void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
156 Extension* extension) {
157 if (!getter)
158 return;
159 ChromeThread::PostTask(
160 ChromeThread::IO, FROM_HERE,
161 NewRunnableMethod(getter,
162 &ChromeURLRequestContextGetter::OnUnloadedExtension,
163 extension->id()));
164}
165
[email protected]e5642992009-06-26 23:06:31166} // namespace
167
initial.commit09911bf2008-07-26 23:55:29168// A pointer to the request context for the default profile. See comments on
169// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31170URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29171
[email protected]be180c802009-10-23 06:33:31172static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19173 if (context)
[email protected]47accfd62009-05-14 18:46:21174 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21175}
176
[email protected]34cc84f2009-02-13 10:04:35177// static
[email protected]4bf6afd2009-10-08 14:00:11178const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
179
180// static
initial.commit09911bf2008-07-26 23:55:29181void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55182 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29183 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
184 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12185 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26186 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
187 IDS_SPELLCHECK_DICTIONARY);
188 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58189 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16190#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06191 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
192 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29193#endif
[email protected]f017cc92009-12-14 20:48:07194 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34195 prefs->RegisterStringPref(prefs::kCurrentThemeID,
196 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42197 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
198 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
199 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50200 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23201 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29202}
203
[email protected]34cc84f2009-02-13 10:04:35204// static
[email protected]f7011fcb2009-01-28 21:54:32205Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29206 return new ProfileImpl(path);
207}
208
[email protected]34cc84f2009-02-13 10:04:35209// static
[email protected]be180c802009-10-23 06:33:31210URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29211 return default_request_context_;
212}
213
[email protected]753efc42010-03-09 19:52:16214#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41215#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56216#elif defined(OS_MACOSX)
217#include "chrome/browser/keychain_mac.h"
218#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16219#elif defined(OS_POSIX)
220// Temporarily disabled while we figure some stuff out.
221// http://code.google.com/p/chromium/issues/detail?id=12351
222// #include "chrome/browser/password_manager/password_store_gnome.h"
223// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41224#endif
initial.commit09911bf2008-07-26 23:55:29225
initial.commit09911bf2008-07-26 23:55:29226////////////////////////////////////////////////////////////////////////////////
227//
228// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42229// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29230//
231////////////////////////////////////////////////////////////////////////////////
232class OffTheRecordProfileImpl : public Profile,
233 public NotificationObserver {
234 public:
235 explicit OffTheRecordProfileImpl(Profile* real_profile)
236 : profile_(real_profile),
237 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31238 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05239
initial.commit09911bf2008-07-26 23:55:29240 // Register for browser close notifications so we can detect when the last
241 // off-the-record window is closed, in which case we can clean our states
242 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43243 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
244 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29245 }
246
247 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21248 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29249 }
250
[email protected]4bf6afd2009-10-08 14:00:11251 virtual ProfileId GetRuntimeId() {
252 return reinterpret_cast<ProfileId>(this);
253 }
254
[email protected]a6d0f182010-01-12 08:01:44255 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29256
257 virtual bool IsOffTheRecord() {
258 return true;
259 }
260
261 virtual Profile* GetOffTheRecordProfile() {
262 return this;
263 }
264
[email protected]860f55492009-03-27 19:50:59265 virtual void DestroyOffTheRecordProfile() {
266 // Suicide is bad!
267 NOTREACHED();
268 }
269
initial.commit09911bf2008-07-26 23:55:29270 virtual Profile* GetOriginalProfile() {
271 return profile_;
272 }
273
[email protected]2f351cb2009-11-09 23:43:34274 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
275 if (!db_tracker_)
276 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
277 return db_tracker_;
278 }
279
initial.commit09911bf2008-07-26 23:55:29280 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49281 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
282 // because we don't want to leak the sites that the user has visited before.
283 return NULL;
initial.commit09911bf2008-07-26 23:55:29284 }
285
[email protected]6014d672008-12-05 00:38:25286 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21287 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25288 }
289
[email protected]0938d3c2009-01-09 20:37:35290 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21291 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25292 }
293
[email protected]89ebc7e2009-08-24 22:11:07294 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21295 // TODO(mpcomplete): figure out whether we should return the original
296 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07297 return NULL;
298 }
299
[email protected]481e1a42009-05-06 20:56:05300 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21301 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05302 }
303
[email protected]7120f132009-07-20 21:05:37304 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21305 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37306 }
307
[email protected]34cc84f2009-02-13 10:04:35308 virtual SSLHostState* GetSSLHostState() {
309 if (!ssl_host_state_.get())
310 ssl_host_state_.reset(new SSLHostState());
311
312 DCHECK(ssl_host_state_->CalledOnValidThread());
313 return ssl_host_state_.get();
314 }
315
[email protected]326e6792009-12-11 21:04:42316 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54317 if (!transport_security_state_.get())
318 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23319
[email protected]326e6792009-12-11 21:04:42320 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23321 }
322
initial.commit09911bf2008-07-26 23:55:29323 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54324 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29325 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54326
327 NOTREACHED() << "This profile is OffTheRecord";
328 return NULL;
initial.commit09911bf2008-07-26 23:55:29329 }
330
[email protected]0850fa62009-10-08 22:34:29331 virtual HistoryService* GetHistoryServiceWithoutCreating() {
332 return profile_->GetHistoryServiceWithoutCreating();
333 }
334
[email protected]0189bc722009-08-28 21:56:48335 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54336 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48337 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54338
339 NOTREACHED() << "This profile is OffTheRecord";
340 return NULL;
[email protected]0189bc722009-08-28 21:56:48341 }
342
[email protected]69c579e2010-04-23 20:01:00343 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
344 return profile_->GetAutocompleteClassifier();
[email protected]90085af02009-10-29 17:53:21345 }
346
initial.commit09911bf2008-07-26 23:55:29347 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54348 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29349 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54350
351 NOTREACHED() << "This profile is OffTheRecord";
352 return NULL;
initial.commit09911bf2008-07-26 23:55:29353 }
354
[email protected]9cddbe372009-10-23 21:23:53355 virtual WebDataService* GetWebDataServiceWithoutCreating() {
356 return profile_->GetWebDataServiceWithoutCreating();
357 }
358
[email protected]e69d33952009-06-03 22:00:41359 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54360 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41361 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54362
363 NOTREACHED() << "This profile is OffTheRecord";
364 return NULL;
[email protected]e69d33952009-06-03 22:00:41365 }
366
initial.commit09911bf2008-07-26 23:55:29367 virtual PrefService* GetPrefs() {
368 return profile_->GetPrefs();
369 }
370
371 virtual TemplateURLModel* GetTemplateURLModel() {
372 return profile_->GetTemplateURLModel();
373 }
374
375 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
376 return profile_->GetTemplateURLFetcher();
377 }
378
379 virtual DownloadManager* GetDownloadManager() {
380 if (!download_manager_.get()) {
381 scoped_refptr<DownloadManager> dlm(new DownloadManager);
382 dlm->Init(this);
383 download_manager_.swap(dlm);
384 }
385 return download_manager_.get();
386 }
387
388 virtual bool HasCreatedDownloadManager() const {
389 return (download_manager_.get() != NULL);
390 }
391
[email protected]def11712009-11-06 00:42:15392 virtual PersonalDataManager* GetPersonalDataManager() {
393 return NULL;
394 }
395
[email protected]4a190632009-05-09 01:07:42396 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54397 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42398 }
399
400 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54401 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42402 }
403
[email protected]a5166af62009-07-03 00:42:29404 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54405 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29406 }
407
[email protected]4a190632009-05-09 01:07:42408 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54409 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42410 }
411
[email protected]51c490b2009-08-03 16:34:34412 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54413 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34414 }
415
[email protected]5786d3d2009-12-18 00:18:44416 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54417 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42418 }
419
[email protected]be180c802009-10-23 06:33:31420 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29421 return request_context_;
422 }
423
[email protected]be180c802009-10-23 06:33:31424 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11425 // In OTR mode, media request context is the same as the original one.
426 return request_context_;
[email protected]e7f29642009-03-02 22:53:18427 }
428
[email protected]be180c802009-10-23 06:33:31429 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21430 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21431 }
432
[email protected]db36938c2009-08-19 21:48:42433 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54434 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42435 }
436
[email protected]e284e6d82010-01-29 19:49:45437 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]bd147842010-04-09 15:29:17438 // Retrieve the host content settings map of the parent profile in order to
439 // ensure the preferences have been migrated.
440 profile_->GetHostContentSettingsMap();
441 if (!host_content_settings_map_.get())
442 host_content_settings_map_ = new HostContentSettingsMap(this);
443 return host_content_settings_map_.get();
[email protected]e284e6d82010-01-29 19:49:45444 }
445
[email protected]40bd6582009-12-04 23:49:51446 virtual HostZoomMap* GetHostZoomMap() {
[email protected]779c3362010-01-30 01:09:33447 return profile_->GetHostZoomMap();
[email protected]40bd6582009-12-04 23:49:51448 }
449
[email protected]aee541e2010-03-19 01:52:45450 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
451 return profile_->GetGeolocationContentSettingsMap();
452 }
453
[email protected]8c6335d32010-01-20 09:21:50454 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54455 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23456 }
457
[email protected]6c32ce72010-03-08 05:18:06458 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
459 return profile_->GetUserStyleSheetWatcher();
460 }
461
[email protected]e5d2f7132010-04-09 18:13:53462 virtual FindBarState* GetFindBarState() {
463 if (!find_bar_state_.get())
464 find_bar_state_.reset(new FindBarState());
465 return find_bar_state_.get();
466 }
467
initial.commit09911bf2008-07-26 23:55:29468 virtual SessionService* GetSessionService() {
469 // Don't save any sessions when off the record.
470 return NULL;
471 }
472
473 virtual void ShutdownSessionService() {
474 // We don't allow a session service, nothing to do.
475 }
476
477 virtual bool HasSessionService() const {
478 // We never have a session service.
479 return false;
480 }
481
initial.commit09911bf2008-07-26 23:55:29482 virtual bool DidLastSessionExitCleanly() {
483 return profile_->DidLastSessionExitCleanly();
484 }
485
[email protected]d8e41ed2008-09-11 15:22:32486 virtual BookmarkModel* GetBookmarkModel() {
487 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29488 }
489
[email protected]4bb336302009-10-12 05:44:26490 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58491 if (!desktop_notification_service_.get()) {
492 desktop_notification_service_.reset(new DesktopNotificationService(
493 this, g_browser_process->notification_ui_manager()));
494 }
495 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26496 }
497
[email protected]48352c12009-08-15 01:19:11498 virtual ProfileSyncService* GetProfileSyncService() {
499 return NULL;
[email protected]3a453fa2008-08-15 18:46:34500 }
[email protected]3a453fa2008-08-15 18:46:34501
[email protected]1bd056e2010-04-20 02:03:48502 virtual CloudPrintProxyService* GetCloudPrintProxyService() {
503 return NULL;
504 }
505
initial.commit09911bf2008-07-26 23:55:29506 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54507 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29508 }
509
510 virtual Time GetStartTime() const {
511 return start_time_;
512 }
513
514 virtual TabRestoreService* GetTabRestoreService() {
515 return NULL;
516 }
517
[email protected]e7244d82008-10-29 18:13:26518 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41519 }
520
[email protected]85c55dc2009-11-06 03:05:46521 virtual SpellCheckHost* GetSpellCheckHost() {
522 return profile_->GetSpellCheckHost();
523 }
524
525 virtual void ReinitializeSpellCheckHost(bool force) {
526 profile_->ReinitializeSpellCheckHost(force);
527 }
[email protected]85c55dc2009-11-06 03:05:46528
[email protected]3bf335a2009-06-26 20:46:06529 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29530 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21531 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29532 DCHECK(webkit_context_.get());
533 return webkit_context_.get();
534 }
[email protected]3bf335a2009-06-26 20:46:06535
[email protected]449478302009-06-09 20:04:28536 virtual ThumbnailStore* GetThumbnailStore() {
537 return NULL;
538 }
539
initial.commit09911bf2008-07-26 23:55:29540 virtual void MarkAsCleanShutdown() {
541 }
542
[email protected]bdbc87c2009-01-25 05:08:54543 virtual void InitExtensions() {
544 NOTREACHED();
545 }
546
[email protected]ea0c98cf2009-06-18 23:02:54547 virtual void InitWebResources() {
548 NOTREACHED();
549 }
550
[email protected]9c8dd902009-11-19 17:50:42551 virtual NTPResourceCache* GetNTPResourceCache() {
552 // Just return the real profile resource cache.
553 return profile_->GetNTPResourceCache();
554 }
555
initial.commit09911bf2008-07-26 23:55:29556 virtual void ExitedOffTheRecordMode() {
557 // Drop our download manager so we forget about all the downloads made
558 // in off-the-record mode.
559 download_manager_ = NULL;
560 }
561
562 virtual void Observe(NotificationType type,
563 const NotificationSource& source,
564 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56565 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29566 // We are only interested in OTR browser closing.
567 if (Source<Browser>(source)->profile() != this)
568 return;
569
570 // Let's check if we still have an Off The Record window opened.
571 // Note that we check against 1 as this notification is sent before the
572 // browser window is actually removed from the list.
573 if (BrowserList::GetBrowserCount(this) <= 1)
574 ExitedOffTheRecordMode();
575 }
576
577 private:
[email protected]88cf3292009-05-22 01:48:43578 NotificationRegistrar registrar_;
579
initial.commit09911bf2008-07-26 23:55:29580 // The real underlying profile.
581 Profile* profile_;
582
[email protected]6ab9b202008-12-23 22:34:50583 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19584 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29585
586 // The download manager that only stores downloaded items in memory.
587 scoped_refptr<DownloadManager> download_manager_;
588
[email protected]7d7696c52009-12-01 20:54:58589 // Use a separate desktop notification service for OTR.
590 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
591
[email protected]bd147842010-04-09 15:29:17592 // We use a non-writable content settings map for OTR.
593 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
594
[email protected]3bf335a2009-06-26 20:46:06595 // Use a special WebKit context for OTR browsing.
596 scoped_refptr<WebKitContext> webkit_context_;
597
[email protected]34cc84f2009-02-13 10:04:35598 // We don't want SSLHostState from the OTR profile to leak back to the main
599 // profile because then the main profile would learn some of the host names
600 // the user visited while OTR.
601 scoped_ptr<SSLHostState> ssl_host_state_;
602
[email protected]e5d2f7132010-04-09 18:13:53603 // Use a separate FindBarState so search terms do not leak back to the main
604 // profile.
605 scoped_ptr<FindBarState> find_bar_state_;
606
[email protected]326e6792009-12-11 21:04:42607 // The TransportSecurityState that only stores enabled sites in memory.
608 scoped_refptr<net::TransportSecurityState>
609 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23610
initial.commit09911bf2008-07-26 23:55:29611 // Time we were started.
612 Time start_time_;
613
[email protected]2f351cb2009-11-09 23:43:34614 // The main database tracker for this profile.
615 // Should be used only on the file thread.
616 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
617
[email protected]90085af02009-10-29 17:53:21618 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29619};
620
[email protected]f7011fcb2009-01-28 21:54:32621ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29622 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44623 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07624 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32625 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57626 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21627 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45628 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51629 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32630 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48631 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32632 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41633 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32634 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42635 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32636 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46637 spellcheck_host_(NULL),
638 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29639 shutdown_session_service_(false) {
640 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
641 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14642 create_session_service_timer_.Start(
643 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
644 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54645
[email protected]89ebc7e2009-08-24 22:11:07646 if (CommandLine::ForCurrentProcess()->HasSwitch(
647 switches::kEnableExtensionTimelineApi)) {
648 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
649 }
650
[email protected]382a0702009-06-26 17:12:27651 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37652 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27653
[email protected]e7244d82008-10-29 18:13:26654 PrefService* prefs = GetPrefs();
655 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
656 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58657 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58658
[email protected]405a64b2009-09-16 21:03:44659#if defined(OS_MACOSX)
660 // If the profile directory doesn't already have a cache directory and it
661 // is under ~/Library/Application Support, use a suitable cache directory
662 // under ~/Library/Caches. For example, a profile directory of
663 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
664 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
665 // ~/Library/Caches/Google/Chrome/MyProfileName.
666 //
667 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44668 if (!HasACacheSubdir(path_)) {
669 FilePath app_data_path, user_cache_path;
670 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12671 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44672 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
673 base_cache_path_ = user_cache_path;
674 }
675 }
[email protected]9e9b6e8e2009-12-02 08:45:01676#elif defined(OS_POSIX) // Posix minus Mac.
677 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
678 // for a spec on where cache files go. The net effect for most systems is we
679 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
680 // official builds.
681 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
682#if defined(GOOGLE_CHROME_BUILD)
683 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44684#else
[email protected]9e9b6e8e2009-12-02 08:45:01685 const char kCacheDir[] = "chromium";
686#endif
687 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
688 base_cache_path_ = base_cache_path_.Append(kCacheDir);
689 if (!file_util::PathExists(base_cache_path_))
690 file_util::CreateDirectory(base_cache_path_);
691 }
[email protected]405a64b2009-09-16 21:03:44692#endif
[email protected]bc96d562009-08-11 18:45:13693 if (base_cache_path_.empty())
694 base_cache_path_ = path_;
695
[email protected]4a190632009-05-09 01:07:42696 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43697 registrar_.Add(this, NotificationType::THEME_INSTALLED,
698 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11699
700 // Listen for bookmark model load, to bootstrap the sync service.
701 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
702 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42703
704 ssl_config_service_manager_.reset(
705 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53706
707#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29708 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53709#endif
[email protected]911f8152010-03-18 16:46:40710
711 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29712}
713
[email protected]bdbc87c2009-01-25 05:08:54714void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41715 if (user_script_master_ || extensions_service_)
716 return; // Already initialized.
717
[email protected]bdbc87c2009-01-25 05:08:54718 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18719 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36720
721 FilePath script_dir; // Don't look for user scripts in any directory.
722 // TODO(aa): We should just remove this functionality,
723 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51724 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36725
[email protected]894bb502009-05-21 22:39:57726 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23727 this,
728 CommandLine::ForCurrentProcess(),
729 GetPrefs(),
730 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36731 true);
[email protected]bdbc87c2009-01-25 05:08:54732
[email protected]fee67982010-04-23 17:24:22733 // Register the component extensions.
734 std::map<std::string, int> component_extensions;
735
736 // Bookmark manager.
[email protected]47e532b2010-04-23 17:46:40737 component_extensions["bookmark_manager"] = IDR_BOOKMARKS_MANIFEST;
[email protected]fee67982010-04-23 17:24:22738
739 // Some sample apps to make our lives easier while we are developing extension
740 // apps. This way we don't have to constantly install these over and over.
741 if (CommandLine::ForCurrentProcess()->HasSwitch(
742 switches::kEnableExtensionApps)) {
743#if defined(OS_WIN)
744 std::string user_domain;
745 if (base::EnvVarGetter::Create()->GetEnv("USERDOMAIN", &user_domain) &&
746 user_domain == "GOOGLE") {
747 component_extensions["gmail_app"] = IDR_GMAIL_APP_MANIFEST;
748 component_extensions["calendar_app"] = IDR_CALENDAR_APP_MANIFEST;
749 component_extensions["docs_app"] = IDR_DOCS_APP_MANIFEST;
750 }
751#endif
752 }
753
754 for (std::map<std::string, int>::iterator iter = component_extensions.begin();
755 iter != component_extensions.end(); ++iter) {
756 FilePath path;
757 if (PathService::Get(chrome::DIR_RESOURCES, &path)) {
758 path = path.AppendASCII(iter->first);
[email protected]1952c7d2010-03-04 23:48:34759 } else {
760 NOTREACHED();
761 }
[email protected]fee67982010-04-23 17:24:22762
763 std::string manifest =
764 ResourceBundle::GetSharedInstance().GetRawDataResource(
765 iter->second).as_string();
766 extensions_service_->register_component_extension(
767 ExtensionsService::ComponentExtensionInfo(manifest, path));
[email protected]1952c7d2010-03-04 23:48:34768 }
769
[email protected]9197f3b2009-06-02 00:49:27770 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12771
772 // Load any extensions specified with --load-extension.
773 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10774 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12775 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12776 }
[email protected]bdbc87c2009-01-25 05:08:54777}
778
[email protected]ea0c98cf2009-06-18 23:02:54779void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07780 if (web_resource_service_)
781 return; // Already initialized.
782
[email protected]6fad2632009-11-02 05:59:37783 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54784 web_resource_service_->StartAfterDelay();
785}
786
[email protected]9c8dd902009-11-19 17:50:42787NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
788 if (!ntp_resource_cache_.get())
789 ntp_resource_cache_.reset(new NTPResourceCache(this));
790 return ntp_resource_cache_.get();
791}
792
initial.commit09911bf2008-07-26 23:55:29793ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56794 NotificationService::current()->Notify(
795 NotificationType::PROFILE_DESTROYED,
796 Source<Profile>(this),
797 NotificationService::NoDetails());
798
[email protected]169627b2008-12-06 19:30:19799 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29800
801 StopCreateSessionServiceTimer();
802 // TemplateURLModel schedules a task on the WebDataService from its
803 // destructor. Delete it first to ensure the task gets scheduled before we
804 // shut down the database.
805 template_url_model_.reset();
806
807 // The download manager queries the history system and should be deleted
808 // before the history is shutdown so it can properly cancel all requests.
809 download_manager_ = NULL;
810
[email protected]4a190632009-05-09 01:07:42811 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15812 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42813
[email protected]44961292009-07-20 20:03:09814 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
815 // save any new thumbnails to disk and release its reference to the
816 // HistoryService.
817 if (thumbnail_store_.get())
818 thumbnail_store_->Shutdown();
819
[email protected]e7244d82008-10-29 18:13:26820 // Remove pref observers.
821 PrefService* prefs = GetPrefs();
822 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
823 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58824 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26825
[email protected]9c8dd902009-11-19 17:50:42826 // Delete the NTP resource cache so we can unregister pref observers.
827 ntp_resource_cache_.reset();
828
[email protected]48352c12009-08-15 01:19:11829 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34830
initial.commit09911bf2008-07-26 23:55:29831 // Both HistoryService and WebDataService maintain threads for background
832 // processing. Its possible each thread still has tasks on it that have
833 // increased the ref count of the service. In such a situation, when we
834 // decrement the refcount, it won't be 0, and the threads/databases aren't
835 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
836 // databases are properly closed.
837 if (web_data_service_.get())
838 web_data_service_->Shutdown();
839
840 if (history_service_.get())
841 history_service_->Cleanup();
842
[email protected]85c55dc2009-11-06 03:05:46843 if (spellcheck_host_.get())
844 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29845
[email protected]cfc06f122009-11-16 22:18:55846 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21847 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50848
[email protected]47accfd62009-05-14 18:46:21849 CleanupRequestContext(request_context_);
850 CleanupRequestContext(media_request_context_);
851 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17852
[email protected]d8e41ed2008-09-11 15:22:32853 // HistoryService may call into the BookmarkModel, as such we need to
854 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46855 // HistoryService will join with HistoryService's backend thread so that
856 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32857 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46858 history_service_ = NULL;
859 bookmark_bar_model_.reset();
860
[email protected]0189bc722009-08-28 21:56:48861 // FaviconService depends on HistoryServce so make sure we delete
862 // HistoryService first.
863 favicon_service_ = NULL;
864
[email protected]7120f132009-07-20 21:05:37865 extension_message_service_->ProfileDestroyed();
866
[email protected]6ef635e42009-07-26 06:16:12867 if (extensions_service_)
868 extensions_service_->ProfileDestroyed();
869
[email protected]66da08b2009-10-19 22:27:00870 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29871 MarkAsCleanShutdown();
872}
873
[email protected]4bf6afd2009-10-08 14:00:11874ProfileId ProfileImpl::GetRuntimeId() {
875 return reinterpret_cast<ProfileId>(this);
876}
877
[email protected]f7011fcb2009-01-28 21:54:32878FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29879 return path_;
880}
881
882bool ProfileImpl::IsOffTheRecord() {
883 return false;
884}
885
886Profile* ProfileImpl::GetOffTheRecordProfile() {
887 if (!off_the_record_profile_.get()) {
888 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
889 off_the_record_profile_.swap(p);
890 }
891 return off_the_record_profile_.get();
892}
893
[email protected]860f55492009-03-27 19:50:59894void ProfileImpl::DestroyOffTheRecordProfile() {
895 off_the_record_profile_.reset();
896}
897
initial.commit09911bf2008-07-26 23:55:29898Profile* ProfileImpl::GetOriginalProfile() {
899 return this;
900}
901
[email protected]2f351cb2009-11-09 23:43:34902webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
903 if (!db_tracker_)
904 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
905 return db_tracker_;
906}
907
initial.commit09911bf2008-07-26 23:55:29908VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44909 if (!visited_link_master_.get()) {
910 scoped_ptr<VisitedLinkMaster> visited_links(
911 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
912 if (!visited_links->Init())
913 return NULL;
914 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53915 }
[email protected]a6d0f182010-01-12 08:01:44916
917 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29918}
919
[email protected]6014d672008-12-05 00:38:25920ExtensionsService* ProfileImpl::GetExtensionsService() {
921 return extensions_service_.get();
922}
923
[email protected]0938d3c2009-01-09 20:37:35924UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35925 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25926}
927
[email protected]89ebc7e2009-08-24 22:11:07928ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
929 return extension_devtools_manager_.get();
930}
931
[email protected]481e1a42009-05-06 20:56:05932ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27933 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05934}
935
[email protected]7120f132009-07-20 21:05:37936ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
937 return extension_message_service_.get();
938}
939
[email protected]34cc84f2009-02-13 10:04:35940SSLHostState* ProfileImpl::GetSSLHostState() {
941 if (!ssl_host_state_.get())
942 ssl_host_state_.reset(new SSLHostState());
943
944 DCHECK(ssl_host_state_->CalledOnValidThread());
945 return ssl_host_state_.get();
946}
947
[email protected]326e6792009-12-11 21:04:42948net::TransportSecurityState*
949 ProfileImpl::GetTransportSecurityState() {
950 if (!transport_security_state_.get()) {
951 transport_security_state_ = new net::TransportSecurityState();
952 transport_security_persister_ =
953 new TransportSecurityPersister();
954 transport_security_persister_->Initialize(
955 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51956 }
[email protected]a9cea7542009-05-20 04:30:23957
[email protected]326e6792009-12-11 21:04:42958 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23959}
960
initial.commit09911bf2008-07-26 23:55:29961PrefService* ProfileImpl::GetPrefs() {
962 if (!prefs_.get()) {
[email protected]277404c22010-04-22 13:09:45963 prefs_.reset(new PrefService(new JsonPrefStore(GetPrefFilePath())));
initial.commit09911bf2008-07-26 23:55:29964
965 // The Profile class and ProfileManager class may read some prefs so
966 // register known prefs as soon as possible.
967 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51968 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29969
970 // The last session exited cleanly if there is no pref for
971 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
972 last_session_exited_cleanly_ =
973 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
974 // Mark the session as open.
975 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
976 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36977 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29978 }
979
980 return prefs_.get();
981}
982
[email protected]f7011fcb2009-01-28 21:54:32983FilePath ProfileImpl::GetPrefFilePath() {
984 FilePath pref_file_path = path_;
985 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29986 return pref_file_path;
987}
988
[email protected]be180c802009-10-23 06:33:31989URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29990 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32991 FilePath cookie_path = GetPath();
992 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13993 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31994 int max_size;
995 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42996
[email protected]405a64b2009-09-16 21:03:44997 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31998 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
999 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:291000
[email protected]6ab9b202008-12-23 22:34:501001 // The first request context is always a normal (non-OTR) request context.
1002 // Even when Chromium is started in OTR mode, a normal profile is always
1003 // created first.
1004 if (!default_request_context_) {
1005 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:311006 // TODO(eroman): this isn't terribly useful anymore now that the
1007 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:501008 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561009 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:501010 NotificationService::AllSources(), NotificationService::NoDetails());
1011 }
initial.commit09911bf2008-07-26 23:55:291012 }
1013
1014 return request_context_;
1015}
1016
[email protected]be180c802009-10-23 06:33:311017URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:181018 if (!media_request_context_) {
[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(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:141022
[email protected]405a64b2009-09-16 21:03:441023 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311024 media_request_context_ =
1025 ChromeURLRequestContextGetter::CreateOriginalForMedia(
1026 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:181027 }
1028
1029 return media_request_context_;
1030}
1031
[email protected]0189bc722009-08-28 21:56:481032FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
1033 if (!favicon_service_created_) {
1034 favicon_service_created_ = true;
1035 scoped_refptr<FaviconService> service(new FaviconService(this));
1036 favicon_service_.swap(service);
1037 }
1038 return favicon_service_.get();
1039}
1040
[email protected]be180c802009-10-23 06:33:311041URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:211042 if (!extensions_request_context_) {
1043 FilePath cookie_path = GetPath();
1044 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1045
1046 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:311047 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
1048 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:211049 }
1050
1051 return extensions_request_context_;
1052}
1053
[email protected]57a777f72010-03-31 01:09:421054void ProfileImpl::RegisterExtensionWithRequestContexts(
1055 Extension* extension) {
1056 // Notify the default, extension and media contexts on the IO thread.
1057 PostExtensionLoadedToContextGetter(
1058 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1059 extension);
1060 PostExtensionLoadedToContextGetter(
1061 static_cast<ChromeURLRequestContextGetter*>(
1062 GetRequestContextForExtensions()),
1063 extension);
1064 PostExtensionLoadedToContextGetter(
1065 static_cast<ChromeURLRequestContextGetter*>(
1066 GetRequestContextForMedia()),
1067 extension);
1068}
1069
1070void ProfileImpl::UnregisterExtensionWithRequestContexts(
1071 Extension* extension) {
1072 // Notify the default, extension and media contexts on the IO thread.
1073 PostExtensionUnloadedToContextGetter(
1074 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1075 extension);
1076 PostExtensionUnloadedToContextGetter(
1077 static_cast<ChromeURLRequestContextGetter*>(
1078 GetRequestContextForExtensions()),
1079 extension);
1080 PostExtensionUnloadedToContextGetter(
1081 static_cast<ChromeURLRequestContextGetter*>(
1082 GetRequestContextForMedia()),
1083 extension);
1084}
1085
[email protected]db36938c2009-08-19 21:48:421086net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1087 return ssl_config_service_manager_->Get();
1088}
1089
[email protected]e284e6d82010-01-29 19:49:451090HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
1091 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:391092 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:451093 return host_content_settings_map_.get();
1094}
1095
[email protected]40bd6582009-12-04 23:49:511096HostZoomMap* ProfileImpl::GetHostZoomMap() {
1097 if (!host_zoom_map_)
1098 host_zoom_map_ = new HostZoomMap(this);
1099 return host_zoom_map_.get();
1100}
1101
[email protected]aee541e2010-03-19 01:52:451102GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
1103 if (!geolocation_content_settings_map_.get())
1104 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
1105 return geolocation_content_settings_map_.get();
1106}
1107
[email protected]8c6335d32010-01-20 09:21:501108Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271109 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141110 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271111 return NULL;
[email protected]c37f8b42010-01-23 16:22:141112 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541113 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501114 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231115}
1116
[email protected]6c32ce72010-03-08 05:18:061117UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1118 if (!user_style_sheet_watcher_.get()) {
1119 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1120 user_style_sheet_watcher_->Init();
1121 }
1122 return user_style_sheet_watcher_.get();
1123}
1124
[email protected]e5d2f7132010-04-09 18:13:531125FindBarState* ProfileImpl::GetFindBarState() {
1126 if (!find_bar_state_.get()) {
1127 find_bar_state_.reset(new FindBarState());
1128 }
1129 return find_bar_state_.get();
1130}
1131
initial.commit09911bf2008-07-26 23:55:291132HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1133 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461134 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291135 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321136 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291137 return NULL;
1138 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291139
1140 // Send out the notification that the history service was created.
1141 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561142 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291143 Details<HistoryService>(history_service_.get()));
1144 }
1145 return history_service_.get();
1146}
1147
[email protected]0850fa62009-10-08 22:34:291148HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1149 return history_service_.get();
1150}
1151
initial.commit09911bf2008-07-26 23:55:291152TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1153 if (!template_url_model_.get())
1154 template_url_model_.reset(new TemplateURLModel(this));
1155 return template_url_model_.get();
1156}
1157
1158TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1159 if (!template_url_fetcher_.get())
1160 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1161 return template_url_fetcher_.get();
1162}
1163
[email protected]69c579e2010-04-23 20:01:001164AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
1165 if (!autocomplete_classifier_.get())
1166 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
1167 return autocomplete_classifier_.get();
[email protected]90085af02009-10-29 17:53:211168}
1169
initial.commit09911bf2008-07-26 23:55:291170WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1171 if (!created_web_data_service_)
1172 CreateWebDataService();
1173 return web_data_service_.get();
1174}
1175
[email protected]9cddbe372009-10-23 21:23:531176WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1177 return web_data_service_.get();
1178}
1179
initial.commit09911bf2008-07-26 23:55:291180void ProfileImpl::CreateWebDataService() {
1181 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1182 created_web_data_service_ = true;
1183 scoped_refptr<WebDataService> wds(new WebDataService());
1184 if (!wds->Init(GetPath()))
1185 return;
1186 web_data_service_.swap(wds);
1187}
1188
[email protected]e69d33952009-06-03 22:00:411189PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1190 if (!created_password_store_)
1191 CreatePasswordStore();
1192 return password_store_.get();
1193}
1194
1195void ProfileImpl::CreatePasswordStore() {
1196 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1197 created_password_store_ = true;
1198 scoped_refptr<PasswordStore> ps;
[email protected]753efc42010-03-09 19:52:161199#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:411200 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561201#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171202 FilePath login_db_file_path = GetPath();
1203 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
[email protected]ec44cd52010-04-05 22:30:471204 LoginDatabase* login_db = new LoginDatabase();
[email protected]e0411ae52009-06-30 23:59:171205 if (!login_db->Init(login_db_file_path)) {
1206 LOG(ERROR) << "Could not initialize login database.";
1207 delete login_db;
1208 return;
1209 }
1210 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161211#elif defined(OS_POSIX)
1212 // TODO(evanm): implement "native" password management.
1213 // This bug describes the issues.
1214 // http://code.google.com/p/chromium/issues/detail?id=12351
[email protected]3cf7b302010-04-15 19:02:581215 FilePath login_db_file_path = GetPath();
1216 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1217 LoginDatabase* login_db = new LoginDatabase();
1218 if (!login_db->Init(login_db_file_path)) {
1219 LOG(ERROR) << "Could not initialize login database.";
1220 delete login_db;
[email protected]753efc42010-03-09 19:52:161221 return;
[email protected]3cf7b302010-04-15 19:02:581222 }
1223 ps = new PasswordStoreLinux(login_db, this,
1224 GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]e69d33952009-06-03 22:00:411225#else
1226 NOTIMPLEMENTED();
1227#endif
1228 if (!ps || !ps->Init()) {
1229 // Try falling back to the default password manager
[email protected]dd34de02010-04-14 15:14:241230 NOTREACHED() << "Could not initialise native password manager - "
[email protected]e69d33952009-06-03 22:00:411231 "falling back to default";
1232 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1233 if (!ps->Init())
1234 return;
1235 }
1236 password_store_.swap(ps);
1237}
1238
initial.commit09911bf2008-07-26 23:55:291239DownloadManager* ProfileImpl::GetDownloadManager() {
1240 if (!created_download_manager_) {
1241 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1242 dlm->Init(this);
1243 created_download_manager_ = true;
1244 download_manager_.swap(dlm);
1245 }
1246 return download_manager_.get();
1247}
1248
1249bool ProfileImpl::HasCreatedDownloadManager() const {
1250 return created_download_manager_;
1251}
1252
[email protected]def11712009-11-06 00:42:151253PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1254 if (!personal_data_manager_.get()) {
[email protected]e0976a72010-04-02 01:25:241255 personal_data_manager_.reset(new PersonalDataManager());
1256 personal_data_manager_->Init(this);
[email protected]def11712009-11-06 00:42:151257 }
1258 return personal_data_manager_.get();
1259}
1260
[email protected]4a190632009-05-09 01:07:421261void ProfileImpl::InitThemes() {
1262 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161263#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151264 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291265#else
[email protected]761962c2009-09-25 00:18:151266 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291267#endif
[email protected]761962c2009-09-25 00:18:151268 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421269 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421270 }
1271}
1272
1273void ProfileImpl::SetTheme(Extension* extension) {
1274 InitThemes();
1275 theme_provider_.get()->SetTheme(extension);
1276}
1277
[email protected]a5166af62009-07-03 00:42:291278void ProfileImpl::SetNativeTheme() {
1279 InitThemes();
1280 theme_provider_.get()->SetNativeTheme();
1281}
1282
[email protected]4a190632009-05-09 01:07:421283void ProfileImpl::ClearTheme() {
1284 InitThemes();
1285 theme_provider_.get()->UseDefaultTheme();
1286}
1287
[email protected]51c490b2009-08-03 16:34:341288Extension* ProfileImpl::GetTheme() {
1289 InitThemes();
1290
1291 std::string id = theme_provider_.get()->GetThemeID();
1292 if (id == BrowserThemeProvider::kDefaultThemeID)
1293 return NULL;
1294
[email protected]61b411612009-11-10 23:17:411295 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341296}
1297
[email protected]5786d3d2009-12-18 00:18:441298BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421299 InitThemes();
1300 return theme_provider_.get();
1301}
1302
initial.commit09911bf2008-07-26 23:55:291303SessionService* ProfileImpl::GetSessionService() {
1304 if (!session_service_.get() && !shutdown_session_service_) {
1305 session_service_ = new SessionService(this);
1306 session_service_->ResetFromCurrentBrowsers();
1307 }
1308 return session_service_.get();
1309}
1310
1311void ProfileImpl::ShutdownSessionService() {
1312 if (shutdown_session_service_)
1313 return;
1314
1315 // We're about to exit, force creation of the session service if it hasn't
1316 // been created yet. We do this to ensure session state matches the point in
1317 // time the user exited.
1318 GetSessionService();
1319 shutdown_session_service_ = true;
1320 session_service_ = NULL;
1321}
1322
1323bool ProfileImpl::HasSessionService() const {
1324 return (session_service_.get() != NULL);
1325}
1326
initial.commit09911bf2008-07-26 23:55:291327bool ProfileImpl::DidLastSessionExitCleanly() {
1328 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1329 // it to be set by asking for the prefs.
1330 GetPrefs();
1331 return last_session_exited_cleanly_;
1332}
1333
[email protected]d8e41ed2008-09-11 15:22:321334BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461335 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321336 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461337 bookmark_bar_model_->Load();
1338 }
initial.commit09911bf2008-07-26 23:55:291339 return bookmark_bar_model_.get();
1340}
1341
1342bool ProfileImpl::IsSameProfile(Profile* profile) {
1343 if (profile == static_cast<Profile*>(this))
1344 return true;
1345 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1346 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1347}
1348
1349Time ProfileImpl::GetStartTime() const {
1350 return start_time_;
1351}
1352
1353TabRestoreService* ProfileImpl::GetTabRestoreService() {
1354 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191355 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291356 return tab_restore_service_.get();
1357}
1358
[email protected]449478302009-06-09 20:04:281359ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1360 if (!thumbnail_store_.get()) {
1361 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251362 thumbnail_store_->Init(
1363 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281364 }
1365 return thumbnail_store_.get();
1366}
1367
initial.commit09911bf2008-07-26 23:55:291368void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191369 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291370}
1371
[email protected]85c55dc2009-11-06 03:05:461372SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1373 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1374}
1375
1376void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1377 // If we are already loading the spellchecker, and this is just a hint to
1378 // load the spellchecker, do nothing.
1379 if (!force && spellcheck_host_.get())
1380 return;
1381
[email protected]f41301e2009-11-16 21:30:071382 spellcheck_host_ready_ = false;
1383
[email protected]85c55dc2009-11-06 03:05:461384 bool notify = false;
1385 if (spellcheck_host_.get()) {
1386 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051387 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461388 notify = true;
1389 }
1390
1391 PrefService* prefs = GetPrefs();
1392 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1393 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1394 spellcheck_host_ = new SpellCheckHost(this,
1395 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1396 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071397 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461398 } else if (notify) {
1399 // The spellchecker has been disabled.
1400 SpellCheckHostInitialized();
1401 }
1402}
1403
1404void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171405 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291406 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1407 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461408 NotificationService::current()->Notify(
1409 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1410 Source<Profile>(this), NotificationService::NoDetails());
1411}
initial.commit09911bf2008-07-26 23:55:291412
[email protected]3bf335a2009-06-26 20:46:061413WebKitContext* ProfileImpl::GetWebKitContext() {
1414 if (!webkit_context_.get())
1415 webkit_context_ = new WebKitContext(path_, false);
1416 DCHECK(webkit_context_.get());
1417 return webkit_context_.get();
1418}
1419
[email protected]4bb336302009-10-12 05:44:261420DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1421 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1422 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261423 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031424 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261425 }
[email protected]4bb336302009-10-12 05:44:261426 return desktop_notification_service_.get();
1427}
1428
initial.commit09911bf2008-07-26 23:55:291429void ProfileImpl::MarkAsCleanShutdown() {
1430 if (prefs_.get()) {
1431 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1432 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1433
1434 // NOTE: If you change what thread this writes on, be sure and update
1435 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361436 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291437 }
1438}
1439
[email protected]e7244d82008-10-29 18:13:261440void ProfileImpl::Observe(NotificationType type,
1441 const NotificationSource& source,
1442 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561443 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261444 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1445 PrefService* prefs = Source<PrefService>(source).ptr();
1446 DCHECK(pref_name_in && prefs);
1447 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461448 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461449 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291450 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1451 NotificationService::current()->Notify(
1452 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1453 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261454 }
[email protected]4a190632009-05-09 01:07:421455 } else if (NotificationType::THEME_INSTALLED == type) {
1456 Extension* extension = Details<Extension>(details).ptr();
1457 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111458 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1459 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1460 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1461 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261462 }
1463}
1464
initial.commit09911bf2008-07-26 23:55:291465void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141466 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291467}
[email protected]3a453fa2008-08-15 18:46:341468
[email protected]48352c12009-08-15 01:19:111469ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431470 if (!ProfileSyncService::IsSyncEnabled()) {
1471 return NULL;
[email protected]7367f1a2009-10-10 01:09:441472 }
[email protected]eec3bcfa2009-11-12 17:23:431473 if (!sync_service_.get())
1474 InitSyncService();
1475 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111476}
1477
[email protected]1bd056e2010-04-20 02:03:481478CloudPrintProxyService* ProfileImpl::GetCloudPrintProxyService() {
1479 if (!cloud_print_proxy_service_.get())
1480 InitCloudPrintProxyService();
1481 return cloud_print_proxy_service_.get();
1482}
1483
[email protected]48352c12009-08-15 01:19:111484void ProfileImpl::InitSyncService() {
[email protected]4aea04a2010-02-10 20:13:431485 profile_sync_factory_.reset(
1486 new ProfileSyncFactoryImpl(this,
1487 CommandLine::ForCurrentProcess()));
1488 sync_service_.reset(
1489 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111490 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111491}
[email protected]1bd056e2010-04-20 02:03:481492
1493void ProfileImpl::InitCloudPrintProxyService() {
1494 cloud_print_proxy_service_.reset(new CloudPrintProxyService(this));
1495 cloud_print_proxy_service_->Initialize();
1496}
1497