blob: f1593aeb8c3dd93800904e35876524102d2bc1fa [file] [log] [blame]
[email protected]e284e6d82010-01-29 19:49:451// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/profile.h"
6
[email protected]1952c7d2010-03-04 23:48:347#include "app/resource_bundle.h"
[email protected]2735e3692009-09-25 18:19:398#include "app/theme_provider.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/command_line.h"
[email protected]04fba9a92008-10-28 17:25:2510#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4411#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/path_service.h"
13#include "base/scoped_ptr.h"
14#include "base/string_util.h"
[email protected]0082d7e0d2010-02-27 14:34:1215#include "chrome/browser/appcache/chrome_appcache_service.h"
[email protected]66ee4432010-03-30 00:19:1816#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]def11712009-11-06 00:42:1517#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4218#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2919#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5120#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5721#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0222#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3723#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4224#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5625#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0726#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3727#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0528#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2529#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3530#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4831#include "chrome/browser/favicon_service.h"
[email protected]aee541e2010-03-19 01:52:4532#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]9c92d192009-12-02 08:03:1633#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4234#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4235#include "chrome/browser/history/history.h"
[email protected]e284e6d82010-01-29 19:49:4536#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5137#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0638#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5039#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4240#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2641#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4142#include "chrome/browser/password_manager/password_store_default.h"
[email protected]8c6335d32010-01-20 09:21:5043#include "chrome/browser/privacy_blacklist/blacklist.h"
initial.commit09911bf2008-07-26 23:55:2944#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2645#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3346#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4647#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4448#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3049#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3350#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1151#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4352#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4053#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2854#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0655#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2956#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3957#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5659#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2960#include "chrome/common/chrome_constants.h"
61#include "chrome/common/chrome_paths.h"
62#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5863#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2964#include "chrome/common/notification_service.h"
65#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3266#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3467#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5868#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4269#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3470#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2971
[email protected]753efc42010-03-09 19:52:1672#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2973#include "chrome/browser/gtk/gtk_theme_provider.h"
74#endif
75
[email protected]e1acf6f2008-10-27 20:43:3376using base::Time;
77using base::TimeDelta;
78
[email protected]e5642992009-06-26 23:06:3179namespace {
80
initial.commit09911bf2008-07-26 23:55:2981// Delay, in milliseconds, before we explicitly create the SessionService.
82static const int kCreateSessionServiceDelayMS = 500;
83
[email protected]e5642992009-06-26 23:06:3184enum ContextType {
85 kNormalContext,
86 kMediaContext
87};
88
89// Gets the cache parameters from the command line. |type| is the type of
90// request context that we need, |cache_path| will be set to the user provided
91// path, or will not be touched if there is not an argument. |max_size| will
92// be the user provided value or zero by default.
93void GetCacheParameters(ContextType type, FilePath* cache_path,
94 int* max_size) {
95 DCHECK(cache_path);
96 DCHECK(max_size);
97
98 // Override the cache location if specified by the user.
99 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
100 switches::kDiskCacheDir));
101
102 if (!user_path.empty()) {
103 *cache_path = FilePath::FromWStringHack(user_path);
104 }
105
[email protected]b7e0a2a2009-10-13 02:07:25106 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
107 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31108 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25109 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31110
111 // By default we let the cache determine the right size.
112 *max_size = 0;
113 if (!StringToInt(value, max_size)) {
114 *max_size = 0;
115 } else if (max_size < 0) {
116 *max_size = 0;
117 }
118}
119
[email protected]405a64b2009-09-16 21:03:44120FilePath GetCachePath(const FilePath& base) {
121 return base.Append(chrome::kCacheDirname);
122}
123
124FilePath GetMediaCachePath(const FilePath& base) {
125 return base.Append(chrome::kMediaCacheDirname);
126}
127
128bool HasACacheSubdir(const FilePath &dir) {
129 return file_util::PathExists(GetCachePath(dir)) ||
130 file_util::PathExists(GetMediaCachePath(dir));
131}
132
[email protected]57a777f72010-03-31 01:09:42133void PostExtensionLoadedToContextGetter(ChromeURLRequestContextGetter* getter,
134 Extension* extension) {
135 if (!getter)
136 return;
137 // Callee takes ownership of new ExtensionInfo struct.
138 ChromeThread::PostTask(
139 ChromeThread::IO, FROM_HERE,
140 NewRunnableMethod(getter,
141 &ChromeURLRequestContextGetter::OnNewExtensions,
142 extension->id(),
143 new ChromeURLRequestContext::ExtensionInfo(
144 extension->path(),
145 extension->default_locale(),
146 extension->web_extent(),
147 extension->api_permissions())));
148}
149
150void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
151 Extension* extension) {
152 if (!getter)
153 return;
154 ChromeThread::PostTask(
155 ChromeThread::IO, FROM_HERE,
156 NewRunnableMethod(getter,
157 &ChromeURLRequestContextGetter::OnUnloadedExtension,
158 extension->id()));
159}
160
[email protected]e5642992009-06-26 23:06:31161} // namespace
162
initial.commit09911bf2008-07-26 23:55:29163// A pointer to the request context for the default profile. See comments on
164// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31165URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29166
[email protected]be180c802009-10-23 06:33:31167static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19168 if (context)
[email protected]47accfd62009-05-14 18:46:21169 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21170}
171
[email protected]34cc84f2009-02-13 10:04:35172// static
[email protected]4bf6afd2009-10-08 14:00:11173const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
174
175// static
initial.commit09911bf2008-07-26 23:55:29176void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55177 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29178 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
179 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12180 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26181 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
182 IDS_SPELLCHECK_DICTIONARY);
183 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58184 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16185#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06186 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
187 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29188#endif
[email protected]f017cc92009-12-14 20:48:07189 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34190 prefs->RegisterStringPref(prefs::kCurrentThemeID,
191 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42192 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
193 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
194 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50195 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23196 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29197}
198
[email protected]34cc84f2009-02-13 10:04:35199// static
[email protected]f7011fcb2009-01-28 21:54:32200Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29201 return new ProfileImpl(path);
202}
203
[email protected]34cc84f2009-02-13 10:04:35204// static
[email protected]be180c802009-10-23 06:33:31205URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29206 return default_request_context_;
207}
208
[email protected]753efc42010-03-09 19:52:16209#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41210#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56211#elif defined(OS_MACOSX)
212#include "chrome/browser/keychain_mac.h"
213#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16214#elif defined(OS_POSIX)
215// Temporarily disabled while we figure some stuff out.
216// http://code.google.com/p/chromium/issues/detail?id=12351
217// #include "chrome/browser/password_manager/password_store_gnome.h"
218// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41219#endif
initial.commit09911bf2008-07-26 23:55:29220
initial.commit09911bf2008-07-26 23:55:29221////////////////////////////////////////////////////////////////////////////////
222//
223// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42224// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29225//
226////////////////////////////////////////////////////////////////////////////////
227class OffTheRecordProfileImpl : public Profile,
228 public NotificationObserver {
229 public:
230 explicit OffTheRecordProfileImpl(Profile* real_profile)
231 : profile_(real_profile),
232 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31233 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05234
initial.commit09911bf2008-07-26 23:55:29235 // Register for browser close notifications so we can detect when the last
236 // off-the-record window is closed, in which case we can clean our states
237 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43238 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
239 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29240 }
241
242 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21243 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29244 }
245
[email protected]4bf6afd2009-10-08 14:00:11246 virtual ProfileId GetRuntimeId() {
247 return reinterpret_cast<ProfileId>(this);
248 }
249
[email protected]a6d0f182010-01-12 08:01:44250 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29251
252 virtual bool IsOffTheRecord() {
253 return true;
254 }
255
256 virtual Profile* GetOffTheRecordProfile() {
257 return this;
258 }
259
[email protected]860f55492009-03-27 19:50:59260 virtual void DestroyOffTheRecordProfile() {
261 // Suicide is bad!
262 NOTREACHED();
263 }
264
initial.commit09911bf2008-07-26 23:55:29265 virtual Profile* GetOriginalProfile() {
266 return profile_;
267 }
268
[email protected]2f351cb2009-11-09 23:43:34269 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
270 if (!db_tracker_)
271 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
272 return db_tracker_;
273 }
274
initial.commit09911bf2008-07-26 23:55:29275 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49276 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
277 // because we don't want to leak the sites that the user has visited before.
278 return NULL;
initial.commit09911bf2008-07-26 23:55:29279 }
280
[email protected]6014d672008-12-05 00:38:25281 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21282 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25283 }
284
[email protected]0938d3c2009-01-09 20:37:35285 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21286 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25287 }
288
[email protected]89ebc7e2009-08-24 22:11:07289 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21290 // TODO(mpcomplete): figure out whether we should return the original
291 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07292 return NULL;
293 }
294
[email protected]481e1a42009-05-06 20:56:05295 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21296 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05297 }
298
[email protected]7120f132009-07-20 21:05:37299 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21300 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37301 }
302
[email protected]34cc84f2009-02-13 10:04:35303 virtual SSLHostState* GetSSLHostState() {
304 if (!ssl_host_state_.get())
305 ssl_host_state_.reset(new SSLHostState());
306
307 DCHECK(ssl_host_state_->CalledOnValidThread());
308 return ssl_host_state_.get();
309 }
310
[email protected]326e6792009-12-11 21:04:42311 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54312 if (!transport_security_state_.get())
313 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23314
[email protected]326e6792009-12-11 21:04:42315 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23316 }
317
initial.commit09911bf2008-07-26 23:55:29318 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54319 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29320 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54321
322 NOTREACHED() << "This profile is OffTheRecord";
323 return NULL;
initial.commit09911bf2008-07-26 23:55:29324 }
325
[email protected]0850fa62009-10-08 22:34:29326 virtual HistoryService* GetHistoryServiceWithoutCreating() {
327 return profile_->GetHistoryServiceWithoutCreating();
328 }
329
[email protected]0189bc722009-08-28 21:56:48330 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54331 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48332 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54333
334 NOTREACHED() << "This profile is OffTheRecord";
335 return NULL;
[email protected]0189bc722009-08-28 21:56:48336 }
337
[email protected]66ee4432010-03-30 00:19:18338 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
339 return profile_->GetAutocompleteClassifier();
[email protected]90085af02009-10-29 17:53:21340 }
341
initial.commit09911bf2008-07-26 23:55:29342 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54343 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29344 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54345
346 NOTREACHED() << "This profile is OffTheRecord";
347 return NULL;
initial.commit09911bf2008-07-26 23:55:29348 }
349
[email protected]9cddbe372009-10-23 21:23:53350 virtual WebDataService* GetWebDataServiceWithoutCreating() {
351 return profile_->GetWebDataServiceWithoutCreating();
352 }
353
[email protected]e69d33952009-06-03 22:00:41354 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54355 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41356 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54357
358 NOTREACHED() << "This profile is OffTheRecord";
359 return NULL;
[email protected]e69d33952009-06-03 22:00:41360 }
361
initial.commit09911bf2008-07-26 23:55:29362 virtual PrefService* GetPrefs() {
363 return profile_->GetPrefs();
364 }
365
366 virtual TemplateURLModel* GetTemplateURLModel() {
367 return profile_->GetTemplateURLModel();
368 }
369
370 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
371 return profile_->GetTemplateURLFetcher();
372 }
373
374 virtual DownloadManager* GetDownloadManager() {
375 if (!download_manager_.get()) {
376 scoped_refptr<DownloadManager> dlm(new DownloadManager);
377 dlm->Init(this);
378 download_manager_.swap(dlm);
379 }
380 return download_manager_.get();
381 }
382
383 virtual bool HasCreatedDownloadManager() const {
384 return (download_manager_.get() != NULL);
385 }
386
[email protected]def11712009-11-06 00:42:15387 virtual PersonalDataManager* GetPersonalDataManager() {
388 return NULL;
389 }
390
[email protected]4a190632009-05-09 01:07:42391 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54392 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42393 }
394
395 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54396 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42397 }
398
[email protected]a5166af62009-07-03 00:42:29399 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54400 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29401 }
402
[email protected]4a190632009-05-09 01:07:42403 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54404 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42405 }
406
[email protected]51c490b2009-08-03 16:34:34407 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54408 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34409 }
410
[email protected]5786d3d2009-12-18 00:18:44411 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54412 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42413 }
414
[email protected]be180c802009-10-23 06:33:31415 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29416 return request_context_;
417 }
418
[email protected]be180c802009-10-23 06:33:31419 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11420 // In OTR mode, media request context is the same as the original one.
421 return request_context_;
[email protected]e7f29642009-03-02 22:53:18422 }
423
[email protected]be180c802009-10-23 06:33:31424 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21425 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21426 }
427
[email protected]db36938c2009-08-19 21:48:42428 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54429 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42430 }
431
[email protected]e284e6d82010-01-29 19:49:45432 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]bd147842010-04-09 15:29:17433 // Retrieve the host content settings map of the parent profile in order to
434 // ensure the preferences have been migrated.
435 profile_->GetHostContentSettingsMap();
436 if (!host_content_settings_map_.get())
437 host_content_settings_map_ = new HostContentSettingsMap(this);
438 return host_content_settings_map_.get();
[email protected]e284e6d82010-01-29 19:49:45439 }
440
[email protected]40bd6582009-12-04 23:49:51441 virtual HostZoomMap* GetHostZoomMap() {
[email protected]779c3362010-01-30 01:09:33442 return profile_->GetHostZoomMap();
[email protected]40bd6582009-12-04 23:49:51443 }
444
[email protected]aee541e2010-03-19 01:52:45445 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
446 return profile_->GetGeolocationContentSettingsMap();
447 }
448
[email protected]8c6335d32010-01-20 09:21:50449 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54450 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23451 }
452
[email protected]6c32ce72010-03-08 05:18:06453 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
454 return profile_->GetUserStyleSheetWatcher();
455 }
456
initial.commit09911bf2008-07-26 23:55:29457 virtual SessionService* GetSessionService() {
458 // Don't save any sessions when off the record.
459 return NULL;
460 }
461
462 virtual void ShutdownSessionService() {
463 // We don't allow a session service, nothing to do.
464 }
465
466 virtual bool HasSessionService() const {
467 // We never have a session service.
468 return false;
469 }
470
initial.commit09911bf2008-07-26 23:55:29471 virtual bool DidLastSessionExitCleanly() {
472 return profile_->DidLastSessionExitCleanly();
473 }
474
[email protected]d8e41ed2008-09-11 15:22:32475 virtual BookmarkModel* GetBookmarkModel() {
476 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29477 }
478
[email protected]4bb336302009-10-12 05:44:26479 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58480 if (!desktop_notification_service_.get()) {
481 desktop_notification_service_.reset(new DesktopNotificationService(
482 this, g_browser_process->notification_ui_manager()));
483 }
484 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26485 }
486
[email protected]48352c12009-08-15 01:19:11487 virtual ProfileSyncService* GetProfileSyncService() {
488 return NULL;
[email protected]3a453fa2008-08-15 18:46:34489 }
[email protected]3a453fa2008-08-15 18:46:34490
initial.commit09911bf2008-07-26 23:55:29491 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54492 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29493 }
494
495 virtual Time GetStartTime() const {
496 return start_time_;
497 }
498
499 virtual TabRestoreService* GetTabRestoreService() {
500 return NULL;
501 }
502
[email protected]e7244d82008-10-29 18:13:26503 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41504 }
505
[email protected]85c55dc2009-11-06 03:05:46506 virtual SpellCheckHost* GetSpellCheckHost() {
507 return profile_->GetSpellCheckHost();
508 }
509
510 virtual void ReinitializeSpellCheckHost(bool force) {
511 profile_->ReinitializeSpellCheckHost(force);
512 }
[email protected]85c55dc2009-11-06 03:05:46513
[email protected]3bf335a2009-06-26 20:46:06514 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29515 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21516 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29517 DCHECK(webkit_context_.get());
518 return webkit_context_.get();
519 }
[email protected]3bf335a2009-06-26 20:46:06520
[email protected]449478302009-06-09 20:04:28521 virtual ThumbnailStore* GetThumbnailStore() {
522 return NULL;
523 }
524
initial.commit09911bf2008-07-26 23:55:29525 virtual void MarkAsCleanShutdown() {
526 }
527
[email protected]bdbc87c2009-01-25 05:08:54528 virtual void InitExtensions() {
529 NOTREACHED();
530 }
531
[email protected]ea0c98cf2009-06-18 23:02:54532 virtual void InitWebResources() {
533 NOTREACHED();
534 }
535
[email protected]9c8dd902009-11-19 17:50:42536 virtual NTPResourceCache* GetNTPResourceCache() {
537 // Just return the real profile resource cache.
538 return profile_->GetNTPResourceCache();
539 }
540
initial.commit09911bf2008-07-26 23:55:29541 virtual void ExitedOffTheRecordMode() {
542 // Drop our download manager so we forget about all the downloads made
543 // in off-the-record mode.
544 download_manager_ = NULL;
545 }
546
547 virtual void Observe(NotificationType type,
548 const NotificationSource& source,
549 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56550 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29551 // We are only interested in OTR browser closing.
552 if (Source<Browser>(source)->profile() != this)
553 return;
554
555 // Let's check if we still have an Off The Record window opened.
556 // Note that we check against 1 as this notification is sent before the
557 // browser window is actually removed from the list.
558 if (BrowserList::GetBrowserCount(this) <= 1)
559 ExitedOffTheRecordMode();
560 }
561
562 private:
[email protected]88cf3292009-05-22 01:48:43563 NotificationRegistrar registrar_;
564
initial.commit09911bf2008-07-26 23:55:29565 // The real underlying profile.
566 Profile* profile_;
567
[email protected]6ab9b202008-12-23 22:34:50568 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19569 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29570
571 // The download manager that only stores downloaded items in memory.
572 scoped_refptr<DownloadManager> download_manager_;
573
[email protected]7d7696c52009-12-01 20:54:58574 // Use a separate desktop notification service for OTR.
575 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
576
[email protected]bd147842010-04-09 15:29:17577 // We use a non-writable content settings map for OTR.
578 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
579
[email protected]3bf335a2009-06-26 20:46:06580 // Use a special WebKit context for OTR browsing.
581 scoped_refptr<WebKitContext> webkit_context_;
582
[email protected]34cc84f2009-02-13 10:04:35583 // We don't want SSLHostState from the OTR profile to leak back to the main
584 // profile because then the main profile would learn some of the host names
585 // the user visited while OTR.
586 scoped_ptr<SSLHostState> ssl_host_state_;
587
[email protected]326e6792009-12-11 21:04:42588 // The TransportSecurityState that only stores enabled sites in memory.
589 scoped_refptr<net::TransportSecurityState>
590 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23591
initial.commit09911bf2008-07-26 23:55:29592 // Time we were started.
593 Time start_time_;
594
[email protected]2f351cb2009-11-09 23:43:34595 // The main database tracker for this profile.
596 // Should be used only on the file thread.
597 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
598
[email protected]90085af02009-10-29 17:53:21599 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29600};
601
[email protected]f7011fcb2009-01-28 21:54:32602ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29603 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44604 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07605 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32606 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57607 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21608 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45609 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51610 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32611 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48612 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32613 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41614 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32615 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42616 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32617 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46618 spellcheck_host_(NULL),
619 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29620 shutdown_session_service_(false) {
621 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
622 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14623 create_session_service_timer_.Start(
624 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
625 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54626
[email protected]89ebc7e2009-08-24 22:11:07627 if (CommandLine::ForCurrentProcess()->HasSwitch(
628 switches::kEnableExtensionTimelineApi)) {
629 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
630 }
631
[email protected]382a0702009-06-26 17:12:27632 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37633 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27634
[email protected]e7244d82008-10-29 18:13:26635 PrefService* prefs = GetPrefs();
636 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
637 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58638 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58639
[email protected]405a64b2009-09-16 21:03:44640#if defined(OS_MACOSX)
641 // If the profile directory doesn't already have a cache directory and it
642 // is under ~/Library/Application Support, use a suitable cache directory
643 // under ~/Library/Caches. For example, a profile directory of
644 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
645 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
646 // ~/Library/Caches/Google/Chrome/MyProfileName.
647 //
648 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44649 if (!HasACacheSubdir(path_)) {
650 FilePath app_data_path, user_cache_path;
651 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12652 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44653 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
654 base_cache_path_ = user_cache_path;
655 }
656 }
[email protected]9e9b6e8e2009-12-02 08:45:01657#elif defined(OS_POSIX) // Posix minus Mac.
658 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
659 // for a spec on where cache files go. The net effect for most systems is we
660 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
661 // official builds.
662 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
663#if defined(GOOGLE_CHROME_BUILD)
664 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44665#else
[email protected]9e9b6e8e2009-12-02 08:45:01666 const char kCacheDir[] = "chromium";
667#endif
668 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
669 base_cache_path_ = base_cache_path_.Append(kCacheDir);
670 if (!file_util::PathExists(base_cache_path_))
671 file_util::CreateDirectory(base_cache_path_);
672 }
[email protected]405a64b2009-09-16 21:03:44673#endif
[email protected]bc96d562009-08-11 18:45:13674 if (base_cache_path_.empty())
675 base_cache_path_ = path_;
676
[email protected]4a190632009-05-09 01:07:42677 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43678 registrar_.Add(this, NotificationType::THEME_INSTALLED,
679 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11680
681 // Listen for bookmark model load, to bootstrap the sync service.
682 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
683 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42684
685 ssl_config_service_manager_.reset(
686 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53687
688#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29689 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53690#endif
[email protected]911f8152010-03-18 16:46:40691
692 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29693}
694
[email protected]bdbc87c2009-01-25 05:08:54695void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41696 if (user_script_master_ || extensions_service_)
697 return; // Already initialized.
698
[email protected]bdbc87c2009-01-25 05:08:54699 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18700 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36701
702 FilePath script_dir; // Don't look for user scripts in any directory.
703 // TODO(aa): We should just remove this functionality,
704 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51705 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36706
[email protected]894bb502009-05-21 22:39:57707 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23708 this,
709 CommandLine::ForCurrentProcess(),
710 GetPrefs(),
711 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36712 true);
[email protected]bdbc87c2009-01-25 05:08:54713
[email protected]1952c7d2010-03-04 23:48:34714 // Register the bookmark manager extension.
[email protected]4b776892010-03-19 22:57:33715 if (!CommandLine::ForCurrentProcess()->HasSwitch(
716 switches::kDisableTabbedBookmarkManager)) {
[email protected]1952c7d2010-03-04 23:48:34717 FilePath bookmark_manager_path;
718 if (PathService::Get(chrome::DIR_BOOKMARK_MANAGER,
719 &bookmark_manager_path)) {
720 std::string manifest =
721 ResourceBundle::GetSharedInstance().GetRawDataResource(
722 IDR_BOOKMARKS_MANIFEST).as_string();
723 extensions_service_->register_component_extension(
724 ExtensionsService::ComponentExtensionInfo(manifest,
725 bookmark_manager_path));
726 } else {
727 NOTREACHED();
728 }
729 }
730
[email protected]9197f3b2009-06-02 00:49:27731 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12732
733 // Load any extensions specified with --load-extension.
734 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10735 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12736 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12737 }
[email protected]bdbc87c2009-01-25 05:08:54738}
739
[email protected]ea0c98cf2009-06-18 23:02:54740void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07741 if (web_resource_service_)
742 return; // Already initialized.
743
[email protected]6fad2632009-11-02 05:59:37744 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54745 web_resource_service_->StartAfterDelay();
746}
747
[email protected]9c8dd902009-11-19 17:50:42748NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
749 if (!ntp_resource_cache_.get())
750 ntp_resource_cache_.reset(new NTPResourceCache(this));
751 return ntp_resource_cache_.get();
752}
753
initial.commit09911bf2008-07-26 23:55:29754ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56755 NotificationService::current()->Notify(
756 NotificationType::PROFILE_DESTROYED,
757 Source<Profile>(this),
758 NotificationService::NoDetails());
759
[email protected]169627b2008-12-06 19:30:19760 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29761
762 StopCreateSessionServiceTimer();
763 // TemplateURLModel schedules a task on the WebDataService from its
764 // destructor. Delete it first to ensure the task gets scheduled before we
765 // shut down the database.
766 template_url_model_.reset();
767
768 // The download manager queries the history system and should be deleted
769 // before the history is shutdown so it can properly cancel all requests.
770 download_manager_ = NULL;
771
[email protected]4a190632009-05-09 01:07:42772 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15773 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42774
[email protected]44961292009-07-20 20:03:09775 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
776 // save any new thumbnails to disk and release its reference to the
777 // HistoryService.
778 if (thumbnail_store_.get())
779 thumbnail_store_->Shutdown();
780
[email protected]e7244d82008-10-29 18:13:26781 // Remove pref observers.
782 PrefService* prefs = GetPrefs();
783 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
784 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58785 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26786
[email protected]9c8dd902009-11-19 17:50:42787 // Delete the NTP resource cache so we can unregister pref observers.
788 ntp_resource_cache_.reset();
789
[email protected]48352c12009-08-15 01:19:11790 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34791
initial.commit09911bf2008-07-26 23:55:29792 // Both HistoryService and WebDataService maintain threads for background
793 // processing. Its possible each thread still has tasks on it that have
794 // increased the ref count of the service. In such a situation, when we
795 // decrement the refcount, it won't be 0, and the threads/databases aren't
796 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
797 // databases are properly closed.
798 if (web_data_service_.get())
799 web_data_service_->Shutdown();
800
801 if (history_service_.get())
802 history_service_->Cleanup();
803
[email protected]85c55dc2009-11-06 03:05:46804 if (spellcheck_host_.get())
805 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29806
[email protected]cfc06f122009-11-16 22:18:55807 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21808 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50809
[email protected]47accfd62009-05-14 18:46:21810 CleanupRequestContext(request_context_);
811 CleanupRequestContext(media_request_context_);
812 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17813
[email protected]d8e41ed2008-09-11 15:22:32814 // HistoryService may call into the BookmarkModel, as such we need to
815 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46816 // HistoryService will join with HistoryService's backend thread so that
817 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32818 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46819 history_service_ = NULL;
820 bookmark_bar_model_.reset();
821
[email protected]0189bc722009-08-28 21:56:48822 // FaviconService depends on HistoryServce so make sure we delete
823 // HistoryService first.
824 favicon_service_ = NULL;
825
[email protected]7120f132009-07-20 21:05:37826 extension_message_service_->ProfileDestroyed();
827
[email protected]6ef635e42009-07-26 06:16:12828 if (extensions_service_)
829 extensions_service_->ProfileDestroyed();
830
[email protected]66da08b2009-10-19 22:27:00831 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29832 MarkAsCleanShutdown();
833}
834
[email protected]4bf6afd2009-10-08 14:00:11835ProfileId ProfileImpl::GetRuntimeId() {
836 return reinterpret_cast<ProfileId>(this);
837}
838
[email protected]f7011fcb2009-01-28 21:54:32839FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29840 return path_;
841}
842
843bool ProfileImpl::IsOffTheRecord() {
844 return false;
845}
846
847Profile* ProfileImpl::GetOffTheRecordProfile() {
848 if (!off_the_record_profile_.get()) {
849 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
850 off_the_record_profile_.swap(p);
851 }
852 return off_the_record_profile_.get();
853}
854
[email protected]860f55492009-03-27 19:50:59855void ProfileImpl::DestroyOffTheRecordProfile() {
856 off_the_record_profile_.reset();
857}
858
initial.commit09911bf2008-07-26 23:55:29859Profile* ProfileImpl::GetOriginalProfile() {
860 return this;
861}
862
[email protected]2f351cb2009-11-09 23:43:34863webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
864 if (!db_tracker_)
865 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
866 return db_tracker_;
867}
868
initial.commit09911bf2008-07-26 23:55:29869VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44870 if (!visited_link_master_.get()) {
871 scoped_ptr<VisitedLinkMaster> visited_links(
872 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
873 if (!visited_links->Init())
874 return NULL;
875 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53876 }
[email protected]a6d0f182010-01-12 08:01:44877
878 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29879}
880
[email protected]6014d672008-12-05 00:38:25881ExtensionsService* ProfileImpl::GetExtensionsService() {
882 return extensions_service_.get();
883}
884
[email protected]0938d3c2009-01-09 20:37:35885UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35886 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25887}
888
[email protected]89ebc7e2009-08-24 22:11:07889ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
890 return extension_devtools_manager_.get();
891}
892
[email protected]481e1a42009-05-06 20:56:05893ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27894 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05895}
896
[email protected]7120f132009-07-20 21:05:37897ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
898 return extension_message_service_.get();
899}
900
[email protected]34cc84f2009-02-13 10:04:35901SSLHostState* ProfileImpl::GetSSLHostState() {
902 if (!ssl_host_state_.get())
903 ssl_host_state_.reset(new SSLHostState());
904
905 DCHECK(ssl_host_state_->CalledOnValidThread());
906 return ssl_host_state_.get();
907}
908
[email protected]326e6792009-12-11 21:04:42909net::TransportSecurityState*
910 ProfileImpl::GetTransportSecurityState() {
911 if (!transport_security_state_.get()) {
912 transport_security_state_ = new net::TransportSecurityState();
913 transport_security_persister_ =
914 new TransportSecurityPersister();
915 transport_security_persister_->Initialize(
916 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51917 }
[email protected]a9cea7542009-05-20 04:30:23918
[email protected]326e6792009-12-11 21:04:42919 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23920}
921
initial.commit09911bf2008-07-26 23:55:29922PrefService* ProfileImpl::GetPrefs() {
923 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37924 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29925
926 // The Profile class and ProfileManager class may read some prefs so
927 // register known prefs as soon as possible.
928 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51929 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29930
931 // The last session exited cleanly if there is no pref for
932 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
933 last_session_exited_cleanly_ =
934 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
935 // Mark the session as open.
936 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
937 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36938 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29939 }
940
941 return prefs_.get();
942}
943
[email protected]f7011fcb2009-01-28 21:54:32944FilePath ProfileImpl::GetPrefFilePath() {
945 FilePath pref_file_path = path_;
946 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29947 return pref_file_path;
948}
949
[email protected]be180c802009-10-23 06:33:31950URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29951 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32952 FilePath cookie_path = GetPath();
953 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13954 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31955 int max_size;
956 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42957
[email protected]405a64b2009-09-16 21:03:44958 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31959 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
960 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29961
[email protected]6ab9b202008-12-23 22:34:50962 // The first request context is always a normal (non-OTR) request context.
963 // Even when Chromium is started in OTR mode, a normal profile is always
964 // created first.
965 if (!default_request_context_) {
966 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31967 // TODO(eroman): this isn't terribly useful anymore now that the
968 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50969 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56970 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50971 NotificationService::AllSources(), NotificationService::NoDetails());
972 }
initial.commit09911bf2008-07-26 23:55:29973 }
974
975 return request_context_;
976}
977
[email protected]be180c802009-10-23 06:33:31978URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18979 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13980 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31981 int max_size;
982 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14983
[email protected]405a64b2009-09-16 21:03:44984 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31985 media_request_context_ =
986 ChromeURLRequestContextGetter::CreateOriginalForMedia(
987 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18988 }
989
990 return media_request_context_;
991}
992
[email protected]0189bc722009-08-28 21:56:48993FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
994 if (!favicon_service_created_) {
995 favicon_service_created_ = true;
996 scoped_refptr<FaviconService> service(new FaviconService(this));
997 favicon_service_.swap(service);
998 }
999 return favicon_service_.get();
1000}
1001
[email protected]be180c802009-10-23 06:33:311002URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:211003 if (!extensions_request_context_) {
1004 FilePath cookie_path = GetPath();
1005 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1006
1007 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:311008 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
1009 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:211010 }
1011
1012 return extensions_request_context_;
1013}
1014
[email protected]57a777f72010-03-31 01:09:421015void ProfileImpl::RegisterExtensionWithRequestContexts(
1016 Extension* extension) {
1017 // Notify the default, extension and media contexts on the IO thread.
1018 PostExtensionLoadedToContextGetter(
1019 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1020 extension);
1021 PostExtensionLoadedToContextGetter(
1022 static_cast<ChromeURLRequestContextGetter*>(
1023 GetRequestContextForExtensions()),
1024 extension);
1025 PostExtensionLoadedToContextGetter(
1026 static_cast<ChromeURLRequestContextGetter*>(
1027 GetRequestContextForMedia()),
1028 extension);
1029}
1030
1031void ProfileImpl::UnregisterExtensionWithRequestContexts(
1032 Extension* extension) {
1033 // Notify the default, extension and media contexts on the IO thread.
1034 PostExtensionUnloadedToContextGetter(
1035 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1036 extension);
1037 PostExtensionUnloadedToContextGetter(
1038 static_cast<ChromeURLRequestContextGetter*>(
1039 GetRequestContextForExtensions()),
1040 extension);
1041 PostExtensionUnloadedToContextGetter(
1042 static_cast<ChromeURLRequestContextGetter*>(
1043 GetRequestContextForMedia()),
1044 extension);
1045}
1046
[email protected]db36938c2009-08-19 21:48:421047net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1048 return ssl_config_service_manager_->Get();
1049}
1050
[email protected]e284e6d82010-01-29 19:49:451051HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
1052 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:391053 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:451054 return host_content_settings_map_.get();
1055}
1056
[email protected]40bd6582009-12-04 23:49:511057HostZoomMap* ProfileImpl::GetHostZoomMap() {
1058 if (!host_zoom_map_)
1059 host_zoom_map_ = new HostZoomMap(this);
1060 return host_zoom_map_.get();
1061}
1062
[email protected]aee541e2010-03-19 01:52:451063GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
1064 if (!geolocation_content_settings_map_.get())
1065 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
1066 return geolocation_content_settings_map_.get();
1067}
1068
[email protected]8c6335d32010-01-20 09:21:501069Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271070 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141071 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271072 return NULL;
[email protected]c37f8b42010-01-23 16:22:141073 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541074 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501075 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231076}
1077
[email protected]6c32ce72010-03-08 05:18:061078UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1079 if (!user_style_sheet_watcher_.get()) {
1080 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1081 user_style_sheet_watcher_->Init();
1082 }
1083 return user_style_sheet_watcher_.get();
1084}
1085
initial.commit09911bf2008-07-26 23:55:291086HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1087 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461088 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291089 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321090 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291091 return NULL;
1092 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291093
1094 // Send out the notification that the history service was created.
1095 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561096 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291097 Details<HistoryService>(history_service_.get()));
1098 }
1099 return history_service_.get();
1100}
1101
[email protected]0850fa62009-10-08 22:34:291102HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1103 return history_service_.get();
1104}
1105
initial.commit09911bf2008-07-26 23:55:291106TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1107 if (!template_url_model_.get())
1108 template_url_model_.reset(new TemplateURLModel(this));
1109 return template_url_model_.get();
1110}
1111
1112TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1113 if (!template_url_fetcher_.get())
1114 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1115 return template_url_fetcher_.get();
1116}
1117
[email protected]66ee4432010-03-30 00:19:181118AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
1119 if (!autocomplete_classifier_.get())
1120 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
1121 return autocomplete_classifier_.get();
[email protected]90085af02009-10-29 17:53:211122}
1123
initial.commit09911bf2008-07-26 23:55:291124WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1125 if (!created_web_data_service_)
1126 CreateWebDataService();
1127 return web_data_service_.get();
1128}
1129
[email protected]9cddbe372009-10-23 21:23:531130WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1131 return web_data_service_.get();
1132}
1133
initial.commit09911bf2008-07-26 23:55:291134void ProfileImpl::CreateWebDataService() {
1135 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1136 created_web_data_service_ = true;
1137 scoped_refptr<WebDataService> wds(new WebDataService());
1138 if (!wds->Init(GetPath()))
1139 return;
1140 web_data_service_.swap(wds);
1141}
1142
[email protected]e69d33952009-06-03 22:00:411143PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1144 if (!created_password_store_)
1145 CreatePasswordStore();
1146 return password_store_.get();
1147}
1148
1149void ProfileImpl::CreatePasswordStore() {
1150 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1151 created_password_store_ = true;
1152 scoped_refptr<PasswordStore> ps;
[email protected]753efc42010-03-09 19:52:161153#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:411154 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561155#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171156 FilePath login_db_file_path = GetPath();
1157 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
[email protected]ec44cd52010-04-05 22:30:471158 LoginDatabase* login_db = new LoginDatabase();
[email protected]e0411ae52009-06-30 23:59:171159 if (!login_db->Init(login_db_file_path)) {
1160 LOG(ERROR) << "Could not initialize login database.";
1161 delete login_db;
1162 return;
1163 }
1164 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161165#elif defined(OS_POSIX)
1166 // TODO(evanm): implement "native" password management.
1167 // This bug describes the issues.
1168 // http://code.google.com/p/chromium/issues/detail?id=12351
1169 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1170 if (!ps->Init())
1171 return;
[email protected]e69d33952009-06-03 22:00:411172#else
1173 NOTIMPLEMENTED();
1174#endif
1175 if (!ps || !ps->Init()) {
1176 // Try falling back to the default password manager
1177 LOG(WARNING) << "Could not initialise native password manager - "
1178 "falling back to default";
1179 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1180 if (!ps->Init())
1181 return;
1182 }
1183 password_store_.swap(ps);
1184}
1185
initial.commit09911bf2008-07-26 23:55:291186DownloadManager* ProfileImpl::GetDownloadManager() {
1187 if (!created_download_manager_) {
1188 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1189 dlm->Init(this);
1190 created_download_manager_ = true;
1191 download_manager_.swap(dlm);
1192 }
1193 return download_manager_.get();
1194}
1195
1196bool ProfileImpl::HasCreatedDownloadManager() const {
1197 return created_download_manager_;
1198}
1199
[email protected]def11712009-11-06 00:42:151200PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1201 if (!personal_data_manager_.get()) {
[email protected]e0976a72010-04-02 01:25:241202 personal_data_manager_.reset(new PersonalDataManager());
1203 personal_data_manager_->Init(this);
[email protected]def11712009-11-06 00:42:151204 }
1205 return personal_data_manager_.get();
1206}
1207
[email protected]4a190632009-05-09 01:07:421208void ProfileImpl::InitThemes() {
1209 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161210#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151211 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291212#else
[email protected]761962c2009-09-25 00:18:151213 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291214#endif
[email protected]761962c2009-09-25 00:18:151215 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421216 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421217 }
1218}
1219
1220void ProfileImpl::SetTheme(Extension* extension) {
1221 InitThemes();
1222 theme_provider_.get()->SetTheme(extension);
1223}
1224
[email protected]a5166af62009-07-03 00:42:291225void ProfileImpl::SetNativeTheme() {
1226 InitThemes();
1227 theme_provider_.get()->SetNativeTheme();
1228}
1229
[email protected]4a190632009-05-09 01:07:421230void ProfileImpl::ClearTheme() {
1231 InitThemes();
1232 theme_provider_.get()->UseDefaultTheme();
1233}
1234
[email protected]51c490b2009-08-03 16:34:341235Extension* ProfileImpl::GetTheme() {
1236 InitThemes();
1237
1238 std::string id = theme_provider_.get()->GetThemeID();
1239 if (id == BrowserThemeProvider::kDefaultThemeID)
1240 return NULL;
1241
[email protected]61b411612009-11-10 23:17:411242 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341243}
1244
[email protected]5786d3d2009-12-18 00:18:441245BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421246 InitThemes();
1247 return theme_provider_.get();
1248}
1249
initial.commit09911bf2008-07-26 23:55:291250SessionService* ProfileImpl::GetSessionService() {
1251 if (!session_service_.get() && !shutdown_session_service_) {
1252 session_service_ = new SessionService(this);
1253 session_service_->ResetFromCurrentBrowsers();
1254 }
1255 return session_service_.get();
1256}
1257
1258void ProfileImpl::ShutdownSessionService() {
1259 if (shutdown_session_service_)
1260 return;
1261
1262 // We're about to exit, force creation of the session service if it hasn't
1263 // been created yet. We do this to ensure session state matches the point in
1264 // time the user exited.
1265 GetSessionService();
1266 shutdown_session_service_ = true;
1267 session_service_ = NULL;
1268}
1269
1270bool ProfileImpl::HasSessionService() const {
1271 return (session_service_.get() != NULL);
1272}
1273
initial.commit09911bf2008-07-26 23:55:291274bool ProfileImpl::DidLastSessionExitCleanly() {
1275 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1276 // it to be set by asking for the prefs.
1277 GetPrefs();
1278 return last_session_exited_cleanly_;
1279}
1280
[email protected]d8e41ed2008-09-11 15:22:321281BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461282 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321283 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461284 bookmark_bar_model_->Load();
1285 }
initial.commit09911bf2008-07-26 23:55:291286 return bookmark_bar_model_.get();
1287}
1288
1289bool ProfileImpl::IsSameProfile(Profile* profile) {
1290 if (profile == static_cast<Profile*>(this))
1291 return true;
1292 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1293 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1294}
1295
1296Time ProfileImpl::GetStartTime() const {
1297 return start_time_;
1298}
1299
1300TabRestoreService* ProfileImpl::GetTabRestoreService() {
1301 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191302 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291303 return tab_restore_service_.get();
1304}
1305
[email protected]449478302009-06-09 20:04:281306ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1307 if (!thumbnail_store_.get()) {
1308 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251309 thumbnail_store_->Init(
1310 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281311 }
1312 return thumbnail_store_.get();
1313}
1314
initial.commit09911bf2008-07-26 23:55:291315void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191316 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291317}
1318
[email protected]85c55dc2009-11-06 03:05:461319SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1320 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1321}
1322
1323void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1324 // If we are already loading the spellchecker, and this is just a hint to
1325 // load the spellchecker, do nothing.
1326 if (!force && spellcheck_host_.get())
1327 return;
1328
[email protected]f41301e2009-11-16 21:30:071329 spellcheck_host_ready_ = false;
1330
[email protected]85c55dc2009-11-06 03:05:461331 bool notify = false;
1332 if (spellcheck_host_.get()) {
1333 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051334 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461335 notify = true;
1336 }
1337
1338 PrefService* prefs = GetPrefs();
1339 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1340 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1341 spellcheck_host_ = new SpellCheckHost(this,
1342 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1343 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071344 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461345 } else if (notify) {
1346 // The spellchecker has been disabled.
1347 SpellCheckHostInitialized();
1348 }
1349}
1350
1351void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171352 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291353 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1354 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461355 NotificationService::current()->Notify(
1356 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1357 Source<Profile>(this), NotificationService::NoDetails());
1358}
initial.commit09911bf2008-07-26 23:55:291359
[email protected]3bf335a2009-06-26 20:46:061360WebKitContext* ProfileImpl::GetWebKitContext() {
1361 if (!webkit_context_.get())
1362 webkit_context_ = new WebKitContext(path_, false);
1363 DCHECK(webkit_context_.get());
1364 return webkit_context_.get();
1365}
1366
[email protected]4bb336302009-10-12 05:44:261367DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1368 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1369 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261370 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031371 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261372 }
[email protected]4bb336302009-10-12 05:44:261373 return desktop_notification_service_.get();
1374}
1375
initial.commit09911bf2008-07-26 23:55:291376void ProfileImpl::MarkAsCleanShutdown() {
1377 if (prefs_.get()) {
1378 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1379 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1380
1381 // NOTE: If you change what thread this writes on, be sure and update
1382 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361383 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291384 }
1385}
1386
[email protected]e7244d82008-10-29 18:13:261387void ProfileImpl::Observe(NotificationType type,
1388 const NotificationSource& source,
1389 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561390 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261391 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1392 PrefService* prefs = Source<PrefService>(source).ptr();
1393 DCHECK(pref_name_in && prefs);
1394 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461395 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461396 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291397 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1398 NotificationService::current()->Notify(
1399 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1400 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261401 }
[email protected]4a190632009-05-09 01:07:421402 } else if (NotificationType::THEME_INSTALLED == type) {
1403 Extension* extension = Details<Extension>(details).ptr();
1404 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111405 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1406 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1407 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1408 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261409 }
1410}
1411
initial.commit09911bf2008-07-26 23:55:291412void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141413 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291414}
[email protected]3a453fa2008-08-15 18:46:341415
[email protected]48352c12009-08-15 01:19:111416ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431417 if (!ProfileSyncService::IsSyncEnabled()) {
1418 return NULL;
[email protected]7367f1a2009-10-10 01:09:441419 }
[email protected]eec3bcfa2009-11-12 17:23:431420 if (!sync_service_.get())
1421 InitSyncService();
1422 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111423}
1424
1425void ProfileImpl::InitSyncService() {
[email protected]4aea04a2010-02-10 20:13:431426 profile_sync_factory_.reset(
1427 new ProfileSyncFactoryImpl(this,
1428 CommandLine::ForCurrentProcess()));
1429 sync_service_.reset(
1430 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111431 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111432}