blob: c78b64a161ad36ebf578b1d30fcea46ad2dea04b [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]def11712009-11-06 00:42:1516#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4217#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2918#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5119#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5720#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0221#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3722#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4223#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5624#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0725#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3726#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0527#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2528#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3529#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4830#include "chrome/browser/favicon_service.h"
[email protected]9c92d192009-12-02 08:03:1631#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4232#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4233#include "chrome/browser/history/history.h"
[email protected]e284e6d82010-01-29 19:49:4534#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5135#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0636#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5037#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4238#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2639#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4140#include "chrome/browser/password_manager/password_store_default.h"
[email protected]8c6335d32010-01-20 09:21:5041#include "chrome/browser/privacy_blacklist/blacklist.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2643#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]90085af02009-10-29 17:53:2144#include "chrome/browser/search_versus_navigate_classifier.h"
[email protected]1132436e2009-04-08 20:06:3345#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4646#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4447#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3048#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3349#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1150#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4351#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]449478302009-06-09 20:04:2852#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0653#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2954#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3955#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2956#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5657#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/common/chrome_constants.h"
59#include "chrome/common/chrome_paths.h"
60#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5861#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2962#include "chrome/common/notification_service.h"
63#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3264#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3465#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5866#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4267#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3468#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2969
[email protected]a5166af62009-07-03 00:42:2970#if defined(OS_LINUX)
71#include "chrome/browser/gtk/gtk_theme_provider.h"
72#endif
73
[email protected]e1acf6f2008-10-27 20:43:3374using base::Time;
75using base::TimeDelta;
76
[email protected]e5642992009-06-26 23:06:3177namespace {
78
initial.commit09911bf2008-07-26 23:55:2979// Delay, in milliseconds, before we explicitly create the SessionService.
80static const int kCreateSessionServiceDelayMS = 500;
81
[email protected]e5642992009-06-26 23:06:3182enum ContextType {
83 kNormalContext,
84 kMediaContext
85};
86
87// Gets the cache parameters from the command line. |type| is the type of
88// request context that we need, |cache_path| will be set to the user provided
89// path, or will not be touched if there is not an argument. |max_size| will
90// be the user provided value or zero by default.
91void GetCacheParameters(ContextType type, FilePath* cache_path,
92 int* max_size) {
93 DCHECK(cache_path);
94 DCHECK(max_size);
95
96 // Override the cache location if specified by the user.
97 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
98 switches::kDiskCacheDir));
99
100 if (!user_path.empty()) {
101 *cache_path = FilePath::FromWStringHack(user_path);
102 }
103
[email protected]b7e0a2a2009-10-13 02:07:25104 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
105 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31106 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25107 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31108
109 // By default we let the cache determine the right size.
110 *max_size = 0;
111 if (!StringToInt(value, max_size)) {
112 *max_size = 0;
113 } else if (max_size < 0) {
114 *max_size = 0;
115 }
116}
117
[email protected]405a64b2009-09-16 21:03:44118FilePath GetCachePath(const FilePath& base) {
119 return base.Append(chrome::kCacheDirname);
120}
121
122FilePath GetMediaCachePath(const FilePath& base) {
123 return base.Append(chrome::kMediaCacheDirname);
124}
125
126bool HasACacheSubdir(const FilePath &dir) {
127 return file_util::PathExists(GetCachePath(dir)) ||
128 file_util::PathExists(GetMediaCachePath(dir));
129}
130
[email protected]e5642992009-06-26 23:06:31131} // namespace
132
initial.commit09911bf2008-07-26 23:55:29133// A pointer to the request context for the default profile. See comments on
134// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31135URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29136
[email protected]be180c802009-10-23 06:33:31137static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19138 if (context)
[email protected]47accfd62009-05-14 18:46:21139 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21140}
141
[email protected]34cc84f2009-02-13 10:04:35142// static
[email protected]4bf6afd2009-10-08 14:00:11143const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
144
145// static
initial.commit09911bf2008-07-26 23:55:29146void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55147 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29148 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
149 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12150 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26151 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
152 IDS_SPELLCHECK_DICTIONARY);
153 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58154 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]a5166af62009-07-03 00:42:29155#if defined(OS_LINUX)
156 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
157#endif
[email protected]f017cc92009-12-14 20:48:07158 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34159 prefs->RegisterStringPref(prefs::kCurrentThemeID,
160 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42161 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
162 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
163 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50164 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23165 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29166}
167
[email protected]34cc84f2009-02-13 10:04:35168// static
[email protected]f7011fcb2009-01-28 21:54:32169Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29170 return new ProfileImpl(path);
171}
172
[email protected]34cc84f2009-02-13 10:04:35173// static
[email protected]be180c802009-10-23 06:33:31174URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29175 return default_request_context_;
176}
177
[email protected]e69d33952009-06-03 22:00:41178#if defined(OS_LINUX)
179// Temporarily disabled while we figure some stuff out.
180// http://code.google.com/p/chromium/issues/detail?id=12351
181// #include "chrome/browser/password_manager/password_store_gnome.h"
182// #include "chrome/browser/password_manager/password_store_kwallet.h"
183#elif defined(OS_WIN)
184#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56185#elif defined(OS_MACOSX)
186#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17187#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56188#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41189#endif
initial.commit09911bf2008-07-26 23:55:29190
initial.commit09911bf2008-07-26 23:55:29191////////////////////////////////////////////////////////////////////////////////
192//
193// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42194// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29195//
196////////////////////////////////////////////////////////////////////////////////
197class OffTheRecordProfileImpl : public Profile,
198 public NotificationObserver {
199 public:
200 explicit OffTheRecordProfileImpl(Profile* real_profile)
201 : profile_(real_profile),
202 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31203 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05204
initial.commit09911bf2008-07-26 23:55:29205 // Register for browser close notifications so we can detect when the last
206 // off-the-record window is closed, in which case we can clean our states
207 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43208 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
209 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29210 }
211
212 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21213 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29214 }
215
[email protected]4bf6afd2009-10-08 14:00:11216 virtual ProfileId GetRuntimeId() {
217 return reinterpret_cast<ProfileId>(this);
218 }
219
[email protected]a6d0f182010-01-12 08:01:44220 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29221
222 virtual bool IsOffTheRecord() {
223 return true;
224 }
225
226 virtual Profile* GetOffTheRecordProfile() {
227 return this;
228 }
229
[email protected]860f55492009-03-27 19:50:59230 virtual void DestroyOffTheRecordProfile() {
231 // Suicide is bad!
232 NOTREACHED();
233 }
234
initial.commit09911bf2008-07-26 23:55:29235 virtual Profile* GetOriginalProfile() {
236 return profile_;
237 }
238
[email protected]2f351cb2009-11-09 23:43:34239 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
240 if (!db_tracker_)
241 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
242 return db_tracker_;
243 }
244
initial.commit09911bf2008-07-26 23:55:29245 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49246 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
247 // because we don't want to leak the sites that the user has visited before.
248 return NULL;
initial.commit09911bf2008-07-26 23:55:29249 }
250
[email protected]6014d672008-12-05 00:38:25251 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21252 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25253 }
254
[email protected]0938d3c2009-01-09 20:37:35255 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21256 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25257 }
258
[email protected]89ebc7e2009-08-24 22:11:07259 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21260 // TODO(mpcomplete): figure out whether we should return the original
261 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07262 return NULL;
263 }
264
[email protected]481e1a42009-05-06 20:56:05265 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21266 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05267 }
268
[email protected]7120f132009-07-20 21:05:37269 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21270 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37271 }
272
[email protected]34cc84f2009-02-13 10:04:35273 virtual SSLHostState* GetSSLHostState() {
274 if (!ssl_host_state_.get())
275 ssl_host_state_.reset(new SSLHostState());
276
277 DCHECK(ssl_host_state_->CalledOnValidThread());
278 return ssl_host_state_.get();
279 }
280
[email protected]326e6792009-12-11 21:04:42281 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54282 if (!transport_security_state_.get())
283 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23284
[email protected]326e6792009-12-11 21:04:42285 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23286 }
287
initial.commit09911bf2008-07-26 23:55:29288 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54289 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29290 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54291
292 NOTREACHED() << "This profile is OffTheRecord";
293 return NULL;
initial.commit09911bf2008-07-26 23:55:29294 }
295
[email protected]0850fa62009-10-08 22:34:29296 virtual HistoryService* GetHistoryServiceWithoutCreating() {
297 return profile_->GetHistoryServiceWithoutCreating();
298 }
299
[email protected]0189bc722009-08-28 21:56:48300 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54301 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48302 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54303
304 NOTREACHED() << "This profile is OffTheRecord";
305 return NULL;
[email protected]0189bc722009-08-28 21:56:48306 }
307
[email protected]90085af02009-10-29 17:53:21308 virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
309 return profile_->GetSearchVersusNavigateClassifier();
310 }
311
initial.commit09911bf2008-07-26 23:55:29312 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54313 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29314 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54315
316 NOTREACHED() << "This profile is OffTheRecord";
317 return NULL;
initial.commit09911bf2008-07-26 23:55:29318 }
319
[email protected]9cddbe372009-10-23 21:23:53320 virtual WebDataService* GetWebDataServiceWithoutCreating() {
321 return profile_->GetWebDataServiceWithoutCreating();
322 }
323
[email protected]e69d33952009-06-03 22:00:41324 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54325 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41326 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54327
328 NOTREACHED() << "This profile is OffTheRecord";
329 return NULL;
[email protected]e69d33952009-06-03 22:00:41330 }
331
initial.commit09911bf2008-07-26 23:55:29332 virtual PrefService* GetPrefs() {
333 return profile_->GetPrefs();
334 }
335
336 virtual TemplateURLModel* GetTemplateURLModel() {
337 return profile_->GetTemplateURLModel();
338 }
339
340 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
341 return profile_->GetTemplateURLFetcher();
342 }
343
344 virtual DownloadManager* GetDownloadManager() {
345 if (!download_manager_.get()) {
346 scoped_refptr<DownloadManager> dlm(new DownloadManager);
347 dlm->Init(this);
348 download_manager_.swap(dlm);
349 }
350 return download_manager_.get();
351 }
352
353 virtual bool HasCreatedDownloadManager() const {
354 return (download_manager_.get() != NULL);
355 }
356
[email protected]def11712009-11-06 00:42:15357 virtual PersonalDataManager* GetPersonalDataManager() {
358 return NULL;
359 }
360
[email protected]4a190632009-05-09 01:07:42361 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54362 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42363 }
364
365 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54366 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42367 }
368
[email protected]a5166af62009-07-03 00:42:29369 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54370 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29371 }
372
[email protected]4a190632009-05-09 01:07:42373 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54374 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42375 }
376
[email protected]51c490b2009-08-03 16:34:34377 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54378 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34379 }
380
[email protected]5786d3d2009-12-18 00:18:44381 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54382 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42383 }
384
[email protected]be180c802009-10-23 06:33:31385 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29386 return request_context_;
387 }
388
[email protected]be180c802009-10-23 06:33:31389 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11390 // In OTR mode, media request context is the same as the original one.
391 return request_context_;
[email protected]e7f29642009-03-02 22:53:18392 }
393
[email protected]be180c802009-10-23 06:33:31394 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21395 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21396 }
397
[email protected]db36938c2009-08-19 21:48:42398 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54399 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42400 }
401
[email protected]e284e6d82010-01-29 19:49:45402 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]08bc6302010-01-30 02:53:39403 return profile_->GetHostContentSettingsMap();
[email protected]e284e6d82010-01-29 19:49:45404 }
405
[email protected]40bd6582009-12-04 23:49:51406 virtual HostZoomMap* GetHostZoomMap() {
[email protected]779c3362010-01-30 01:09:33407 return profile_->GetHostZoomMap();
[email protected]40bd6582009-12-04 23:49:51408 }
409
[email protected]8c6335d32010-01-20 09:21:50410 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54411 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23412 }
413
[email protected]6c32ce72010-03-08 05:18:06414 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
415 return profile_->GetUserStyleSheetWatcher();
416 }
417
initial.commit09911bf2008-07-26 23:55:29418 virtual SessionService* GetSessionService() {
419 // Don't save any sessions when off the record.
420 return NULL;
421 }
422
423 virtual void ShutdownSessionService() {
424 // We don't allow a session service, nothing to do.
425 }
426
427 virtual bool HasSessionService() const {
428 // We never have a session service.
429 return false;
430 }
431
initial.commit09911bf2008-07-26 23:55:29432 virtual bool DidLastSessionExitCleanly() {
433 return profile_->DidLastSessionExitCleanly();
434 }
435
[email protected]d8e41ed2008-09-11 15:22:32436 virtual BookmarkModel* GetBookmarkModel() {
437 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29438 }
439
[email protected]4bb336302009-10-12 05:44:26440 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58441 if (!desktop_notification_service_.get()) {
442 desktop_notification_service_.reset(new DesktopNotificationService(
443 this, g_browser_process->notification_ui_manager()));
444 }
445 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26446 }
447
[email protected]48352c12009-08-15 01:19:11448 virtual ProfileSyncService* GetProfileSyncService() {
449 return NULL;
[email protected]3a453fa2008-08-15 18:46:34450 }
[email protected]3a453fa2008-08-15 18:46:34451
initial.commit09911bf2008-07-26 23:55:29452 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54453 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29454 }
455
456 virtual Time GetStartTime() const {
457 return start_time_;
458 }
459
460 virtual TabRestoreService* GetTabRestoreService() {
461 return NULL;
462 }
463
[email protected]e7244d82008-10-29 18:13:26464 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41465 }
466
[email protected]85c55dc2009-11-06 03:05:46467 virtual SpellCheckHost* GetSpellCheckHost() {
468 return profile_->GetSpellCheckHost();
469 }
470
471 virtual void ReinitializeSpellCheckHost(bool force) {
472 profile_->ReinitializeSpellCheckHost(force);
473 }
[email protected]85c55dc2009-11-06 03:05:46474
[email protected]3bf335a2009-06-26 20:46:06475 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29476 if (!webkit_context_.get())
[email protected]cfe8a112009-11-25 22:52:21477 webkit_context_ = new WebKitContext(FilePath(), true);
[email protected]c27324b2009-11-19 22:44:29478 DCHECK(webkit_context_.get());
479 return webkit_context_.get();
480 }
[email protected]3bf335a2009-06-26 20:46:06481
[email protected]449478302009-06-09 20:04:28482 virtual ThumbnailStore* GetThumbnailStore() {
483 return NULL;
484 }
485
initial.commit09911bf2008-07-26 23:55:29486 virtual void MarkAsCleanShutdown() {
487 }
488
[email protected]bdbc87c2009-01-25 05:08:54489 virtual void InitExtensions() {
490 NOTREACHED();
491 }
492
[email protected]ea0c98cf2009-06-18 23:02:54493 virtual void InitWebResources() {
494 NOTREACHED();
495 }
496
[email protected]9c8dd902009-11-19 17:50:42497 virtual NTPResourceCache* GetNTPResourceCache() {
498 // Just return the real profile resource cache.
499 return profile_->GetNTPResourceCache();
500 }
501
initial.commit09911bf2008-07-26 23:55:29502 virtual void ExitedOffTheRecordMode() {
503 // Drop our download manager so we forget about all the downloads made
504 // in off-the-record mode.
505 download_manager_ = NULL;
506 }
507
508 virtual void Observe(NotificationType type,
509 const NotificationSource& source,
510 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56511 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29512 // We are only interested in OTR browser closing.
513 if (Source<Browser>(source)->profile() != this)
514 return;
515
516 // Let's check if we still have an Off The Record window opened.
517 // Note that we check against 1 as this notification is sent before the
518 // browser window is actually removed from the list.
519 if (BrowserList::GetBrowserCount(this) <= 1)
520 ExitedOffTheRecordMode();
521 }
522
523 private:
[email protected]88cf3292009-05-22 01:48:43524 NotificationRegistrar registrar_;
525
initial.commit09911bf2008-07-26 23:55:29526 // The real underlying profile.
527 Profile* profile_;
528
[email protected]6ab9b202008-12-23 22:34:50529 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19530 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29531
532 // The download manager that only stores downloaded items in memory.
533 scoped_refptr<DownloadManager> download_manager_;
534
[email protected]7d7696c52009-12-01 20:54:58535 // Use a separate desktop notification service for OTR.
536 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
537
[email protected]3bf335a2009-06-26 20:46:06538 // Use a special WebKit context for OTR browsing.
539 scoped_refptr<WebKitContext> webkit_context_;
540
[email protected]34cc84f2009-02-13 10:04:35541 // We don't want SSLHostState from the OTR profile to leak back to the main
542 // profile because then the main profile would learn some of the host names
543 // the user visited while OTR.
544 scoped_ptr<SSLHostState> ssl_host_state_;
545
[email protected]326e6792009-12-11 21:04:42546 // The TransportSecurityState that only stores enabled sites in memory.
547 scoped_refptr<net::TransportSecurityState>
548 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23549
initial.commit09911bf2008-07-26 23:55:29550 // Time we were started.
551 Time start_time_;
552
[email protected]2f351cb2009-11-09 23:43:34553 // The main database tracker for this profile.
554 // Should be used only on the file thread.
555 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
556
[email protected]90085af02009-10-29 17:53:21557 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29558};
559
[email protected]f7011fcb2009-01-28 21:54:32560ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29561 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44562 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07563 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32564 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57565 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21566 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45567 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51568 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32569 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48570 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32571 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41572 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32573 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42574 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32575 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46576 spellcheck_host_(NULL),
577 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29578 shutdown_session_service_(false) {
579 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
580 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14581 create_session_service_timer_.Start(
582 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
583 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54584
[email protected]89ebc7e2009-08-24 22:11:07585 if (CommandLine::ForCurrentProcess()->HasSwitch(
586 switches::kEnableExtensionTimelineApi)) {
587 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
588 }
589
[email protected]382a0702009-06-26 17:12:27590 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37591 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27592
[email protected]e7244d82008-10-29 18:13:26593 PrefService* prefs = GetPrefs();
594 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
595 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58596 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58597
[email protected]405a64b2009-09-16 21:03:44598#if defined(OS_MACOSX)
599 // If the profile directory doesn't already have a cache directory and it
600 // is under ~/Library/Application Support, use a suitable cache directory
601 // under ~/Library/Caches. For example, a profile directory of
602 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
603 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
604 // ~/Library/Caches/Google/Chrome/MyProfileName.
605 //
606 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44607 if (!HasACacheSubdir(path_)) {
608 FilePath app_data_path, user_cache_path;
609 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12610 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44611 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
612 base_cache_path_ = user_cache_path;
613 }
614 }
[email protected]9e9b6e8e2009-12-02 08:45:01615#elif defined(OS_POSIX) // Posix minus Mac.
616 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
617 // for a spec on where cache files go. The net effect for most systems is we
618 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
619 // official builds.
620 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
621#if defined(GOOGLE_CHROME_BUILD)
622 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44623#else
[email protected]9e9b6e8e2009-12-02 08:45:01624 const char kCacheDir[] = "chromium";
625#endif
626 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
627 base_cache_path_ = base_cache_path_.Append(kCacheDir);
628 if (!file_util::PathExists(base_cache_path_))
629 file_util::CreateDirectory(base_cache_path_);
630 }
[email protected]405a64b2009-09-16 21:03:44631#endif
[email protected]bc96d562009-08-11 18:45:13632 if (base_cache_path_.empty())
633 base_cache_path_ = path_;
634
[email protected]4a190632009-05-09 01:07:42635 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43636 registrar_.Add(this, NotificationType::THEME_INSTALLED,
637 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11638
639 // Listen for bookmark model load, to bootstrap the sync service.
640 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
641 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42642
643 ssl_config_service_manager_.reset(
644 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53645
646#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29647 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53648#endif
initial.commit09911bf2008-07-26 23:55:29649}
650
[email protected]bdbc87c2009-01-25 05:08:54651void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41652 if (user_script_master_ || extensions_service_)
653 return; // Already initialized.
654
[email protected]bdbc87c2009-01-25 05:08:54655 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18656 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36657
658 FilePath script_dir; // Don't look for user scripts in any directory.
659 // TODO(aa): We should just remove this functionality,
660 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51661 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36662
[email protected]894bb502009-05-21 22:39:57663 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23664 this,
665 CommandLine::ForCurrentProcess(),
666 GetPrefs(),
667 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36668 true);
[email protected]bdbc87c2009-01-25 05:08:54669
[email protected]1952c7d2010-03-04 23:48:34670 // Register the bookmark manager extension.
671 if (CommandLine::ForCurrentProcess()->HasSwitch(
672 switches::kEnableTabbedBookmarkManager)) {
673 FilePath bookmark_manager_path;
674 if (PathService::Get(chrome::DIR_BOOKMARK_MANAGER,
675 &bookmark_manager_path)) {
676 std::string manifest =
677 ResourceBundle::GetSharedInstance().GetRawDataResource(
678 IDR_BOOKMARKS_MANIFEST).as_string();
679 extensions_service_->register_component_extension(
680 ExtensionsService::ComponentExtensionInfo(manifest,
681 bookmark_manager_path));
682 } else {
683 NOTREACHED();
684 }
685 }
686
[email protected]9197f3b2009-06-02 00:49:27687 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12688
689 // Load any extensions specified with --load-extension.
690 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10691 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12692 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12693 }
[email protected]bdbc87c2009-01-25 05:08:54694}
695
[email protected]ea0c98cf2009-06-18 23:02:54696void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07697 if (web_resource_service_)
698 return; // Already initialized.
699
[email protected]6fad2632009-11-02 05:59:37700 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54701 web_resource_service_->StartAfterDelay();
702}
703
[email protected]9c8dd902009-11-19 17:50:42704NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
705 if (!ntp_resource_cache_.get())
706 ntp_resource_cache_.reset(new NTPResourceCache(this));
707 return ntp_resource_cache_.get();
708}
709
initial.commit09911bf2008-07-26 23:55:29710ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56711 NotificationService::current()->Notify(
712 NotificationType::PROFILE_DESTROYED,
713 Source<Profile>(this),
714 NotificationService::NoDetails());
715
[email protected]169627b2008-12-06 19:30:19716 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29717
718 StopCreateSessionServiceTimer();
719 // TemplateURLModel schedules a task on the WebDataService from its
720 // destructor. Delete it first to ensure the task gets scheduled before we
721 // shut down the database.
722 template_url_model_.reset();
723
724 // The download manager queries the history system and should be deleted
725 // before the history is shutdown so it can properly cancel all requests.
726 download_manager_ = NULL;
727
[email protected]4a190632009-05-09 01:07:42728 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15729 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42730
[email protected]44961292009-07-20 20:03:09731 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
732 // save any new thumbnails to disk and release its reference to the
733 // HistoryService.
734 if (thumbnail_store_.get())
735 thumbnail_store_->Shutdown();
736
[email protected]e7244d82008-10-29 18:13:26737 // Remove pref observers.
738 PrefService* prefs = GetPrefs();
739 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
740 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58741 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26742
[email protected]9c8dd902009-11-19 17:50:42743 // Delete the NTP resource cache so we can unregister pref observers.
744 ntp_resource_cache_.reset();
745
[email protected]48352c12009-08-15 01:19:11746 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34747
initial.commit09911bf2008-07-26 23:55:29748 // Both HistoryService and WebDataService maintain threads for background
749 // processing. Its possible each thread still has tasks on it that have
750 // increased the ref count of the service. In such a situation, when we
751 // decrement the refcount, it won't be 0, and the threads/databases aren't
752 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
753 // databases are properly closed.
754 if (web_data_service_.get())
755 web_data_service_->Shutdown();
756
757 if (history_service_.get())
758 history_service_->Cleanup();
759
[email protected]85c55dc2009-11-06 03:05:46760 if (spellcheck_host_.get())
761 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29762
[email protected]cfc06f122009-11-16 22:18:55763 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21764 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50765
[email protected]47accfd62009-05-14 18:46:21766 CleanupRequestContext(request_context_);
767 CleanupRequestContext(media_request_context_);
768 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17769
[email protected]d8e41ed2008-09-11 15:22:32770 // HistoryService may call into the BookmarkModel, as such we need to
771 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46772 // HistoryService will join with HistoryService's backend thread so that
773 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32774 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46775 history_service_ = NULL;
776 bookmark_bar_model_.reset();
777
[email protected]0189bc722009-08-28 21:56:48778 // FaviconService depends on HistoryServce so make sure we delete
779 // HistoryService first.
780 favicon_service_ = NULL;
781
[email protected]7120f132009-07-20 21:05:37782 extension_message_service_->ProfileDestroyed();
783
[email protected]6ef635e42009-07-26 06:16:12784 if (extensions_service_)
785 extensions_service_->ProfileDestroyed();
786
[email protected]66da08b2009-10-19 22:27:00787 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29788 MarkAsCleanShutdown();
789}
790
[email protected]4bf6afd2009-10-08 14:00:11791ProfileId ProfileImpl::GetRuntimeId() {
792 return reinterpret_cast<ProfileId>(this);
793}
794
[email protected]f7011fcb2009-01-28 21:54:32795FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29796 return path_;
797}
798
799bool ProfileImpl::IsOffTheRecord() {
800 return false;
801}
802
803Profile* ProfileImpl::GetOffTheRecordProfile() {
804 if (!off_the_record_profile_.get()) {
805 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
806 off_the_record_profile_.swap(p);
807 }
808 return off_the_record_profile_.get();
809}
810
[email protected]860f55492009-03-27 19:50:59811void ProfileImpl::DestroyOffTheRecordProfile() {
812 off_the_record_profile_.reset();
813}
814
initial.commit09911bf2008-07-26 23:55:29815Profile* ProfileImpl::GetOriginalProfile() {
816 return this;
817}
818
[email protected]2f351cb2009-11-09 23:43:34819webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
820 if (!db_tracker_)
821 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
822 return db_tracker_;
823}
824
initial.commit09911bf2008-07-26 23:55:29825VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44826 if (!visited_link_master_.get()) {
827 scoped_ptr<VisitedLinkMaster> visited_links(
828 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
829 if (!visited_links->Init())
830 return NULL;
831 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53832 }
[email protected]a6d0f182010-01-12 08:01:44833
834 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29835}
836
[email protected]6014d672008-12-05 00:38:25837ExtensionsService* ProfileImpl::GetExtensionsService() {
838 return extensions_service_.get();
839}
840
[email protected]0938d3c2009-01-09 20:37:35841UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35842 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25843}
844
[email protected]89ebc7e2009-08-24 22:11:07845ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
846 return extension_devtools_manager_.get();
847}
848
[email protected]481e1a42009-05-06 20:56:05849ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27850 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05851}
852
[email protected]7120f132009-07-20 21:05:37853ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
854 return extension_message_service_.get();
855}
856
[email protected]34cc84f2009-02-13 10:04:35857SSLHostState* ProfileImpl::GetSSLHostState() {
858 if (!ssl_host_state_.get())
859 ssl_host_state_.reset(new SSLHostState());
860
861 DCHECK(ssl_host_state_->CalledOnValidThread());
862 return ssl_host_state_.get();
863}
864
[email protected]326e6792009-12-11 21:04:42865net::TransportSecurityState*
866 ProfileImpl::GetTransportSecurityState() {
867 if (!transport_security_state_.get()) {
868 transport_security_state_ = new net::TransportSecurityState();
869 transport_security_persister_ =
870 new TransportSecurityPersister();
871 transport_security_persister_->Initialize(
872 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51873 }
[email protected]a9cea7542009-05-20 04:30:23874
[email protected]326e6792009-12-11 21:04:42875 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23876}
877
initial.commit09911bf2008-07-26 23:55:29878PrefService* ProfileImpl::GetPrefs() {
879 if (!prefs_.get()) {
[email protected]6fad2632009-11-02 05:59:37880 prefs_.reset(new PrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:29881
882 // The Profile class and ProfileManager class may read some prefs so
883 // register known prefs as soon as possible.
884 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51885 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29886
887 // The last session exited cleanly if there is no pref for
888 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
889 last_session_exited_cleanly_ =
890 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
891 // Mark the session as open.
892 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
893 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36894 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29895 }
896
897 return prefs_.get();
898}
899
[email protected]f7011fcb2009-01-28 21:54:32900FilePath ProfileImpl::GetPrefFilePath() {
901 FilePath pref_file_path = path_;
902 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29903 return pref_file_path;
904}
905
[email protected]be180c802009-10-23 06:33:31906URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29907 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32908 FilePath cookie_path = GetPath();
909 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13910 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31911 int max_size;
912 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42913
[email protected]405a64b2009-09-16 21:03:44914 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31915 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
916 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:29917
[email protected]6ab9b202008-12-23 22:34:50918 // The first request context is always a normal (non-OTR) request context.
919 // Even when Chromium is started in OTR mode, a normal profile is always
920 // created first.
921 if (!default_request_context_) {
922 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:31923 // TODO(eroman): this isn't terribly useful anymore now that the
924 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:50925 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56926 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50927 NotificationService::AllSources(), NotificationService::NoDetails());
928 }
initial.commit09911bf2008-07-26 23:55:29929 }
930
931 return request_context_;
932}
933
[email protected]be180c802009-10-23 06:33:31934URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:18935 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13936 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31937 int max_size;
938 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14939
[email protected]405a64b2009-09-16 21:03:44940 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:31941 media_request_context_ =
942 ChromeURLRequestContextGetter::CreateOriginalForMedia(
943 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:18944 }
945
946 return media_request_context_;
947}
948
[email protected]0189bc722009-08-28 21:56:48949FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
950 if (!favicon_service_created_) {
951 favicon_service_created_ = true;
952 scoped_refptr<FaviconService> service(new FaviconService(this));
953 favicon_service_.swap(service);
954 }
955 return favicon_service_.get();
956}
957
[email protected]be180c802009-10-23 06:33:31958URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:21959 if (!extensions_request_context_) {
960 FilePath cookie_path = GetPath();
961 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
962
963 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:31964 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
965 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:21966 }
967
968 return extensions_request_context_;
969}
970
[email protected]db36938c2009-08-19 21:48:42971net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
972 return ssl_config_service_manager_->Get();
973}
974
[email protected]e284e6d82010-01-29 19:49:45975HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
976 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:39977 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:45978 return host_content_settings_map_.get();
979}
980
[email protected]40bd6582009-12-04 23:49:51981HostZoomMap* ProfileImpl::GetHostZoomMap() {
982 if (!host_zoom_map_)
983 host_zoom_map_ = new HostZoomMap(this);
984 return host_zoom_map_.get();
985}
986
[email protected]8c6335d32010-01-20 09:21:50987Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:27988 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:14989 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:27990 return NULL;
[email protected]c37f8b42010-01-23 16:22:14991 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:54992 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:50993 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:23994}
995
[email protected]6c32ce72010-03-08 05:18:06996UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
997 if (!user_style_sheet_watcher_.get()) {
998 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
999 user_style_sheet_watcher_->Init();
1000 }
1001 return user_style_sheet_watcher_.get();
1002}
1003
initial.commit09911bf2008-07-26 23:55:291004HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1005 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461006 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291007 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321008 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291009 return NULL;
1010 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291011
1012 // Send out the notification that the history service was created.
1013 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561014 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291015 Details<HistoryService>(history_service_.get()));
1016 }
1017 return history_service_.get();
1018}
1019
[email protected]0850fa62009-10-08 22:34:291020HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1021 return history_service_.get();
1022}
1023
initial.commit09911bf2008-07-26 23:55:291024TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1025 if (!template_url_model_.get())
1026 template_url_model_.reset(new TemplateURLModel(this));
1027 return template_url_model_.get();
1028}
1029
1030TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1031 if (!template_url_fetcher_.get())
1032 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1033 return template_url_fetcher_.get();
1034}
1035
[email protected]11f4857282009-11-13 19:56:171036SearchVersusNavigateClassifier*
1037ProfileImpl::GetSearchVersusNavigateClassifier() {
[email protected]90085af02009-10-29 17:53:211038 if (!search_versus_navigate_classifier_.get()) {
1039 search_versus_navigate_classifier_.reset(
1040 new SearchVersusNavigateClassifier(this));
1041 }
1042 return search_versus_navigate_classifier_.get();
1043}
1044
initial.commit09911bf2008-07-26 23:55:291045WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1046 if (!created_web_data_service_)
1047 CreateWebDataService();
1048 return web_data_service_.get();
1049}
1050
[email protected]9cddbe372009-10-23 21:23:531051WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1052 return web_data_service_.get();
1053}
1054
initial.commit09911bf2008-07-26 23:55:291055void ProfileImpl::CreateWebDataService() {
1056 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1057 created_web_data_service_ = true;
1058 scoped_refptr<WebDataService> wds(new WebDataService());
1059 if (!wds->Init(GetPath()))
1060 return;
1061 web_data_service_.swap(wds);
1062}
1063
[email protected]e69d33952009-06-03 22:00:411064PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1065 if (!created_password_store_)
1066 CreatePasswordStore();
1067 return password_store_.get();
1068}
1069
1070void ProfileImpl::CreatePasswordStore() {
1071 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1072 created_password_store_ = true;
1073 scoped_refptr<PasswordStore> ps;
1074#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251075 // TODO(evanm): implement "native" password management.
1076 // This bug describes the issues.
1077 // http://code.google.com/p/chromium/issues/detail?id=12351
1078 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1079 if (!ps->Init())
1080 return;
[email protected]e69d33952009-06-03 22:00:411081#elif defined(OS_WIN)
1082 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561083#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171084 FilePath login_db_file_path = GetPath();
1085 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1086 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1087 if (!login_db->Init(login_db_file_path)) {
1088 LOG(ERROR) << "Could not initialize login database.";
1089 delete login_db;
1090 return;
1091 }
1092 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411093#else
1094 NOTIMPLEMENTED();
1095#endif
1096 if (!ps || !ps->Init()) {
1097 // Try falling back to the default password manager
1098 LOG(WARNING) << "Could not initialise native password manager - "
1099 "falling back to default";
1100 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1101 if (!ps->Init())
1102 return;
1103 }
1104 password_store_.swap(ps);
1105}
1106
initial.commit09911bf2008-07-26 23:55:291107DownloadManager* ProfileImpl::GetDownloadManager() {
1108 if (!created_download_manager_) {
1109 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1110 dlm->Init(this);
1111 created_download_manager_ = true;
1112 download_manager_.swap(dlm);
1113 }
1114 return download_manager_.get();
1115}
1116
1117bool ProfileImpl::HasCreatedDownloadManager() const {
1118 return created_download_manager_;
1119}
1120
[email protected]def11712009-11-06 00:42:151121PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1122 if (!personal_data_manager_.get()) {
[email protected]2609bc12010-01-24 08:32:551123 personal_data_manager_.reset(new PersonalDataManager(this));
[email protected]def11712009-11-06 00:42:151124 }
1125 return personal_data_manager_.get();
1126}
1127
[email protected]4a190632009-05-09 01:07:421128void ProfileImpl::InitThemes() {
1129 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571130#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151131 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291132#else
[email protected]761962c2009-09-25 00:18:151133 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291134#endif
[email protected]761962c2009-09-25 00:18:151135 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421136 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421137 }
1138}
1139
1140void ProfileImpl::SetTheme(Extension* extension) {
1141 InitThemes();
1142 theme_provider_.get()->SetTheme(extension);
1143}
1144
[email protected]a5166af62009-07-03 00:42:291145void ProfileImpl::SetNativeTheme() {
1146 InitThemes();
1147 theme_provider_.get()->SetNativeTheme();
1148}
1149
[email protected]4a190632009-05-09 01:07:421150void ProfileImpl::ClearTheme() {
1151 InitThemes();
1152 theme_provider_.get()->UseDefaultTheme();
1153}
1154
[email protected]51c490b2009-08-03 16:34:341155Extension* ProfileImpl::GetTheme() {
1156 InitThemes();
1157
1158 std::string id = theme_provider_.get()->GetThemeID();
1159 if (id == BrowserThemeProvider::kDefaultThemeID)
1160 return NULL;
1161
[email protected]61b411612009-11-10 23:17:411162 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341163}
1164
[email protected]5786d3d2009-12-18 00:18:441165BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421166 InitThemes();
1167 return theme_provider_.get();
1168}
1169
initial.commit09911bf2008-07-26 23:55:291170SessionService* ProfileImpl::GetSessionService() {
1171 if (!session_service_.get() && !shutdown_session_service_) {
1172 session_service_ = new SessionService(this);
1173 session_service_->ResetFromCurrentBrowsers();
1174 }
1175 return session_service_.get();
1176}
1177
1178void ProfileImpl::ShutdownSessionService() {
1179 if (shutdown_session_service_)
1180 return;
1181
1182 // We're about to exit, force creation of the session service if it hasn't
1183 // been created yet. We do this to ensure session state matches the point in
1184 // time the user exited.
1185 GetSessionService();
1186 shutdown_session_service_ = true;
1187 session_service_ = NULL;
1188}
1189
1190bool ProfileImpl::HasSessionService() const {
1191 return (session_service_.get() != NULL);
1192}
1193
initial.commit09911bf2008-07-26 23:55:291194bool ProfileImpl::DidLastSessionExitCleanly() {
1195 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1196 // it to be set by asking for the prefs.
1197 GetPrefs();
1198 return last_session_exited_cleanly_;
1199}
1200
[email protected]d8e41ed2008-09-11 15:22:321201BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461202 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321203 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461204 bookmark_bar_model_->Load();
1205 }
initial.commit09911bf2008-07-26 23:55:291206 return bookmark_bar_model_.get();
1207}
1208
1209bool ProfileImpl::IsSameProfile(Profile* profile) {
1210 if (profile == static_cast<Profile*>(this))
1211 return true;
1212 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1213 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1214}
1215
1216Time ProfileImpl::GetStartTime() const {
1217 return start_time_;
1218}
1219
1220TabRestoreService* ProfileImpl::GetTabRestoreService() {
1221 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191222 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291223 return tab_restore_service_.get();
1224}
1225
[email protected]449478302009-06-09 20:04:281226ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1227 if (!thumbnail_store_.get()) {
1228 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251229 thumbnail_store_->Init(
1230 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281231 }
1232 return thumbnail_store_.get();
1233}
1234
initial.commit09911bf2008-07-26 23:55:291235void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191236 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291237}
1238
[email protected]85c55dc2009-11-06 03:05:461239SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1240 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1241}
1242
1243void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1244 // If we are already loading the spellchecker, and this is just a hint to
1245 // load the spellchecker, do nothing.
1246 if (!force && spellcheck_host_.get())
1247 return;
1248
[email protected]f41301e2009-11-16 21:30:071249 spellcheck_host_ready_ = false;
1250
[email protected]85c55dc2009-11-06 03:05:461251 bool notify = false;
1252 if (spellcheck_host_.get()) {
1253 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051254 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461255 notify = true;
1256 }
1257
1258 PrefService* prefs = GetPrefs();
1259 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1260 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1261 spellcheck_host_ = new SpellCheckHost(this,
1262 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1263 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071264 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461265 } else if (notify) {
1266 // The spellchecker has been disabled.
1267 SpellCheckHostInitialized();
1268 }
1269}
1270
1271void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171272 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291273 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1274 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461275 NotificationService::current()->Notify(
1276 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1277 Source<Profile>(this), NotificationService::NoDetails());
1278}
initial.commit09911bf2008-07-26 23:55:291279
[email protected]3bf335a2009-06-26 20:46:061280WebKitContext* ProfileImpl::GetWebKitContext() {
1281 if (!webkit_context_.get())
1282 webkit_context_ = new WebKitContext(path_, false);
1283 DCHECK(webkit_context_.get());
1284 return webkit_context_.get();
1285}
1286
[email protected]4bb336302009-10-12 05:44:261287DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1288 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1289 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261290 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031291 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261292 }
[email protected]4bb336302009-10-12 05:44:261293 return desktop_notification_service_.get();
1294}
1295
initial.commit09911bf2008-07-26 23:55:291296void ProfileImpl::MarkAsCleanShutdown() {
1297 if (prefs_.get()) {
1298 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1299 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1300
1301 // NOTE: If you change what thread this writes on, be sure and update
1302 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361303 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291304 }
1305}
1306
[email protected]e7244d82008-10-29 18:13:261307void ProfileImpl::Observe(NotificationType type,
1308 const NotificationSource& source,
1309 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561310 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261311 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1312 PrefService* prefs = Source<PrefService>(source).ptr();
1313 DCHECK(pref_name_in && prefs);
1314 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461315 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461316 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291317 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1318 NotificationService::current()->Notify(
1319 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1320 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261321 }
[email protected]4a190632009-05-09 01:07:421322 } else if (NotificationType::THEME_INSTALLED == type) {
1323 Extension* extension = Details<Extension>(details).ptr();
1324 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111325 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1326 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1327 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1328 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261329 }
1330}
1331
initial.commit09911bf2008-07-26 23:55:291332void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141333 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291334}
[email protected]3a453fa2008-08-15 18:46:341335
[email protected]48352c12009-08-15 01:19:111336ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431337 if (!ProfileSyncService::IsSyncEnabled()) {
1338 return NULL;
[email protected]7367f1a2009-10-10 01:09:441339 }
[email protected]eec3bcfa2009-11-12 17:23:431340 if (!sync_service_.get())
1341 InitSyncService();
1342 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111343}
1344
1345void ProfileImpl::InitSyncService() {
[email protected]4aea04a2010-02-10 20:13:431346 profile_sync_factory_.reset(
1347 new ProfileSyncFactoryImpl(this,
1348 CommandLine::ForCurrentProcess()));
1349 sync_service_.reset(
1350 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111351 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111352}