blob: 84f6b447bc78e8e2f6c0283b0ffde5cb847d3924 [file] [log] [blame]
[email protected]e284e6d82010-01-29 19:49:451// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/profile.h"
6
[email protected]1952c7d2010-03-04 23:48:347#include "app/resource_bundle.h"
[email protected]2735e3692009-09-25 18:19:398#include "app/theme_provider.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/command_line.h"
[email protected]fee67982010-04-23 17:24:2210#include "base/env_var.h"
[email protected]04fba9a92008-10-28 17:25:2511#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4412#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/path_service.h"
14#include "base/scoped_ptr.h"
15#include "base/string_util.h"
[email protected]0082d7e0d2010-02-27 14:34:1216#include "chrome/browser/appcache/chrome_appcache_service.h"
[email protected]69c579e2010-04-23 20:01:0017#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]def11712009-11-06 00:42:1518#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4219#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5121#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5722#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0223#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3724#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4225#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5626#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0727#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]14a000d2010-04-29 21:44:2428#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]7120f132009-07-20 21:05:3729#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0530#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2531#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3532#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4833#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5334#include "chrome/browser/find_bar_state.h"
[email protected]aee541e2010-03-19 01:52:4535#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]8b4b84ee2010-05-11 13:08:5236#include "chrome/browser/geolocation/geolocation_permission_context.h"
[email protected]9c92d192009-12-02 08:03:1637#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4238#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4239#include "chrome/browser/history/history.h"
[email protected]e284e6d82010-01-29 19:49:4540#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5141#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0642#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]277404c22010-04-22 13:09:4543#include "chrome/browser/json_pref_store.h"
[email protected]6ab9b202008-12-23 22:34:5044#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4245#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2646#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4147#include "chrome/browser/password_manager/password_store_default.h"
[email protected]8c6335d32010-01-20 09:21:5048#include "chrome/browser/privacy_blacklist/blacklist.h"
[email protected]1bd056e2010-04-20 02:03:4849#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
initial.commit09911bf2008-07-26 23:55:2950#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2651#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3352#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4653#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4454#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3055#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3356#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1157#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4358#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4059#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2860#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0661#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2962#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3963#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2964#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5665#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2966#include "chrome/common/chrome_constants.h"
67#include "chrome/common/chrome_paths.h"
68#include "chrome/common/chrome_switches.h"
initial.commit09911bf2008-07-26 23:55:2969#include "chrome/common/notification_service.h"
70#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3271#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3472#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5873#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4274#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3475#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2976
[email protected]753efc42010-03-09 19:52:1677#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2978#include "chrome/browser/gtk/gtk_theme_provider.h"
79#endif
80
[email protected]e1acf6f2008-10-27 20:43:3381using base::Time;
82using base::TimeDelta;
83
[email protected]e5642992009-06-26 23:06:3184namespace {
85
initial.commit09911bf2008-07-26 23:55:2986// Delay, in milliseconds, before we explicitly create the SessionService.
87static const int kCreateSessionServiceDelayMS = 500;
88
[email protected]e5642992009-06-26 23:06:3189enum ContextType {
90 kNormalContext,
91 kMediaContext
92};
93
94// Gets the cache parameters from the command line. |type| is the type of
95// request context that we need, |cache_path| will be set to the user provided
96// path, or will not be touched if there is not an argument. |max_size| will
97// be the user provided value or zero by default.
98void GetCacheParameters(ContextType type, FilePath* cache_path,
99 int* max_size) {
100 DCHECK(cache_path);
101 DCHECK(max_size);
102
103 // Override the cache location if specified by the user.
104 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
105 switches::kDiskCacheDir));
106
107 if (!user_path.empty()) {
108 *cache_path = FilePath::FromWStringHack(user_path);
109 }
110
[email protected]b7e0a2a2009-10-13 02:07:25111 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
112 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31113 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25114 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31115
116 // By default we let the cache determine the right size.
117 *max_size = 0;
118 if (!StringToInt(value, max_size)) {
119 *max_size = 0;
120 } else if (max_size < 0) {
121 *max_size = 0;
122 }
123}
124
[email protected]405a64b2009-09-16 21:03:44125FilePath GetCachePath(const FilePath& base) {
126 return base.Append(chrome::kCacheDirname);
127}
128
129FilePath GetMediaCachePath(const FilePath& base) {
130 return base.Append(chrome::kMediaCacheDirname);
131}
132
133bool HasACacheSubdir(const FilePath &dir) {
134 return file_util::PathExists(GetCachePath(dir)) ||
135 file_util::PathExists(GetMediaCachePath(dir));
136}
137
[email protected]57a777f72010-03-31 01:09:42138void PostExtensionLoadedToContextGetter(ChromeURLRequestContextGetter* getter,
139 Extension* extension) {
140 if (!getter)
141 return;
142 // Callee takes ownership of new ExtensionInfo struct.
143 ChromeThread::PostTask(
144 ChromeThread::IO, FROM_HERE,
145 NewRunnableMethod(getter,
146 &ChromeURLRequestContextGetter::OnNewExtensions,
147 extension->id(),
148 new ChromeURLRequestContext::ExtensionInfo(
149 extension->path(),
150 extension->default_locale(),
151 extension->web_extent(),
152 extension->api_permissions())));
153}
154
155void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
156 Extension* extension) {
157 if (!getter)
158 return;
159 ChromeThread::PostTask(
160 ChromeThread::IO, FROM_HERE,
161 NewRunnableMethod(getter,
162 &ChromeURLRequestContextGetter::OnUnloadedExtension,
163 extension->id()));
164}
165
[email protected]e5642992009-06-26 23:06:31166} // namespace
167
initial.commit09911bf2008-07-26 23:55:29168// A pointer to the request context for the default profile. See comments on
169// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31170URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29171
[email protected]be180c802009-10-23 06:33:31172static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19173 if (context)
[email protected]47accfd62009-05-14 18:46:21174 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21175}
176
[email protected]34cc84f2009-02-13 10:04:35177// static
[email protected]4bf6afd2009-10-08 14:00:11178const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
179
180// static
initial.commit09911bf2008-07-26 23:55:29181void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55182 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29183 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
184 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12185 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26186 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
187 IDS_SPELLCHECK_DICTIONARY);
188 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58189 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16190#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06191 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
192 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29193#endif
[email protected]f017cc92009-12-14 20:48:07194 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34195 prefs->RegisterStringPref(prefs::kCurrentThemeID,
196 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42197 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
198 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
199 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50200 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23201 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29202}
203
[email protected]34cc84f2009-02-13 10:04:35204// static
[email protected]f7011fcb2009-01-28 21:54:32205Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29206 return new ProfileImpl(path);
207}
208
[email protected]34cc84f2009-02-13 10:04:35209// static
[email protected]be180c802009-10-23 06:33:31210URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29211 return default_request_context_;
212}
213
[email protected]753efc42010-03-09 19:52:16214#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41215#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56216#elif defined(OS_MACOSX)
217#include "chrome/browser/keychain_mac.h"
218#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16219#elif defined(OS_POSIX)
220// Temporarily disabled while we figure some stuff out.
221// http://code.google.com/p/chromium/issues/detail?id=12351
222// #include "chrome/browser/password_manager/password_store_gnome.h"
223// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41224#endif
initial.commit09911bf2008-07-26 23:55:29225
initial.commit09911bf2008-07-26 23:55:29226////////////////////////////////////////////////////////////////////////////////
227//
228// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42229// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29230//
231////////////////////////////////////////////////////////////////////////////////
232class OffTheRecordProfileImpl : public Profile,
233 public NotificationObserver {
234 public:
235 explicit OffTheRecordProfileImpl(Profile* real_profile)
236 : profile_(real_profile),
237 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31238 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05239
initial.commit09911bf2008-07-26 23:55:29240 // Register for browser close notifications so we can detect when the last
241 // off-the-record window is closed, in which case we can clean our states
242 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43243 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
244 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29245 }
246
247 virtual ~OffTheRecordProfileImpl() {
[email protected]098c743d2010-05-04 07:58:59248 NotificationService::current()->Notify(
249 NotificationType::PROFILE_DESTROYED,
250 Source<Profile>(this),
251 NotificationService::NoDetails());
252 CleanupRequestContext(request_context_);
initial.commit09911bf2008-07-26 23:55:29253 }
254
[email protected]4bf6afd2009-10-08 14:00:11255 virtual ProfileId GetRuntimeId() {
256 return reinterpret_cast<ProfileId>(this);
257 }
258
[email protected]a6d0f182010-01-12 08:01:44259 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29260
261 virtual bool IsOffTheRecord() {
262 return true;
263 }
264
265 virtual Profile* GetOffTheRecordProfile() {
266 return this;
267 }
268
[email protected]860f55492009-03-27 19:50:59269 virtual void DestroyOffTheRecordProfile() {
270 // Suicide is bad!
271 NOTREACHED();
272 }
273
initial.commit09911bf2008-07-26 23:55:29274 virtual Profile* GetOriginalProfile() {
275 return profile_;
276 }
277
[email protected]2f351cb2009-11-09 23:43:34278 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
279 if (!db_tracker_)
280 db_tracker_ = new webkit_database::DatabaseTracker(FilePath());
281 return db_tracker_;
282 }
283
initial.commit09911bf2008-07-26 23:55:29284 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49285 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
286 // because we don't want to leak the sites that the user has visited before.
287 return NULL;
initial.commit09911bf2008-07-26 23:55:29288 }
289
[email protected]6014d672008-12-05 00:38:25290 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21291 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25292 }
293
[email protected]0938d3c2009-01-09 20:37:35294 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21295 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25296 }
297
[email protected]89ebc7e2009-08-24 22:11:07298 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21299 // TODO(mpcomplete): figure out whether we should return the original
300 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07301 return NULL;
302 }
303
[email protected]481e1a42009-05-06 20:56:05304 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21305 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05306 }
307
[email protected]7120f132009-07-20 21:05:37308 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21309 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37310 }
311
[email protected]34cc84f2009-02-13 10:04:35312 virtual SSLHostState* GetSSLHostState() {
313 if (!ssl_host_state_.get())
314 ssl_host_state_.reset(new SSLHostState());
315
316 DCHECK(ssl_host_state_->CalledOnValidThread());
317 return ssl_host_state_.get();
318 }
319
[email protected]326e6792009-12-11 21:04:42320 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54321 if (!transport_security_state_.get())
322 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23323
[email protected]326e6792009-12-11 21:04:42324 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23325 }
326
initial.commit09911bf2008-07-26 23:55:29327 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54328 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29329 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54330
331 NOTREACHED() << "This profile is OffTheRecord";
332 return NULL;
initial.commit09911bf2008-07-26 23:55:29333 }
334
[email protected]0850fa62009-10-08 22:34:29335 virtual HistoryService* GetHistoryServiceWithoutCreating() {
336 return profile_->GetHistoryServiceWithoutCreating();
337 }
338
[email protected]0189bc722009-08-28 21:56:48339 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54340 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48341 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54342
343 NOTREACHED() << "This profile is OffTheRecord";
344 return NULL;
[email protected]0189bc722009-08-28 21:56:48345 }
346
[email protected]69c579e2010-04-23 20:01:00347 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
348 return profile_->GetAutocompleteClassifier();
[email protected]90085af02009-10-29 17:53:21349 }
350
initial.commit09911bf2008-07-26 23:55:29351 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54352 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29353 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54354
355 NOTREACHED() << "This profile is OffTheRecord";
356 return NULL;
initial.commit09911bf2008-07-26 23:55:29357 }
358
[email protected]9cddbe372009-10-23 21:23:53359 virtual WebDataService* GetWebDataServiceWithoutCreating() {
360 return profile_->GetWebDataServiceWithoutCreating();
361 }
362
[email protected]e69d33952009-06-03 22:00:41363 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54364 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41365 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54366
367 NOTREACHED() << "This profile is OffTheRecord";
368 return NULL;
[email protected]e69d33952009-06-03 22:00:41369 }
370
initial.commit09911bf2008-07-26 23:55:29371 virtual PrefService* GetPrefs() {
372 return profile_->GetPrefs();
373 }
374
375 virtual TemplateURLModel* GetTemplateURLModel() {
376 return profile_->GetTemplateURLModel();
377 }
378
379 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
380 return profile_->GetTemplateURLFetcher();
381 }
382
383 virtual DownloadManager* GetDownloadManager() {
384 if (!download_manager_.get()) {
385 scoped_refptr<DownloadManager> dlm(new DownloadManager);
386 dlm->Init(this);
387 download_manager_.swap(dlm);
388 }
389 return download_manager_.get();
390 }
391
392 virtual bool HasCreatedDownloadManager() const {
393 return (download_manager_.get() != NULL);
394 }
395
[email protected]def11712009-11-06 00:42:15396 virtual PersonalDataManager* GetPersonalDataManager() {
397 return NULL;
398 }
399
[email protected]4a190632009-05-09 01:07:42400 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54401 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42402 }
403
404 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54405 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42406 }
407
[email protected]a5166af62009-07-03 00:42:29408 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54409 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29410 }
411
[email protected]4a190632009-05-09 01:07:42412 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54413 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42414 }
415
[email protected]51c490b2009-08-03 16:34:34416 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54417 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34418 }
419
[email protected]5786d3d2009-12-18 00:18:44420 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54421 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42422 }
423
[email protected]be180c802009-10-23 06:33:31424 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29425 return request_context_;
426 }
427
[email protected]be180c802009-10-23 06:33:31428 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11429 // In OTR mode, media request context is the same as the original one.
430 return request_context_;
[email protected]e7f29642009-03-02 22:53:18431 }
432
[email protected]be180c802009-10-23 06:33:31433 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21434 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21435 }
436
[email protected]db36938c2009-08-19 21:48:42437 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54438 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42439 }
440
[email protected]e284e6d82010-01-29 19:49:45441 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]bd147842010-04-09 15:29:17442 // Retrieve the host content settings map of the parent profile in order to
443 // ensure the preferences have been migrated.
444 profile_->GetHostContentSettingsMap();
445 if (!host_content_settings_map_.get())
446 host_content_settings_map_ = new HostContentSettingsMap(this);
447 return host_content_settings_map_.get();
[email protected]e284e6d82010-01-29 19:49:45448 }
449
[email protected]40bd6582009-12-04 23:49:51450 virtual HostZoomMap* GetHostZoomMap() {
[email protected]779c3362010-01-30 01:09:33451 return profile_->GetHostZoomMap();
[email protected]40bd6582009-12-04 23:49:51452 }
453
[email protected]aee541e2010-03-19 01:52:45454 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
455 return profile_->GetGeolocationContentSettingsMap();
456 }
457
[email protected]8b4b84ee2010-05-11 13:08:52458 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() {
459 return profile_->GetGeolocationPermissionContext();
460 }
461
[email protected]8c6335d32010-01-20 09:21:50462 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54463 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23464 }
465
[email protected]6c32ce72010-03-08 05:18:06466 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
467 return profile_->GetUserStyleSheetWatcher();
468 }
469
[email protected]e5d2f7132010-04-09 18:13:53470 virtual FindBarState* GetFindBarState() {
471 if (!find_bar_state_.get())
472 find_bar_state_.reset(new FindBarState());
473 return find_bar_state_.get();
474 }
475
initial.commit09911bf2008-07-26 23:55:29476 virtual SessionService* GetSessionService() {
477 // Don't save any sessions when off the record.
478 return NULL;
479 }
480
481 virtual void ShutdownSessionService() {
482 // We don't allow a session service, nothing to do.
483 }
484
485 virtual bool HasSessionService() const {
486 // We never have a session service.
487 return false;
488 }
489
initial.commit09911bf2008-07-26 23:55:29490 virtual bool DidLastSessionExitCleanly() {
491 return profile_->DidLastSessionExitCleanly();
492 }
493
[email protected]d8e41ed2008-09-11 15:22:32494 virtual BookmarkModel* GetBookmarkModel() {
495 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29496 }
497
[email protected]4bb336302009-10-12 05:44:26498 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58499 if (!desktop_notification_service_.get()) {
500 desktop_notification_service_.reset(new DesktopNotificationService(
501 this, g_browser_process->notification_ui_manager()));
502 }
503 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26504 }
505
[email protected]48352c12009-08-15 01:19:11506 virtual ProfileSyncService* GetProfileSyncService() {
507 return NULL;
[email protected]3a453fa2008-08-15 18:46:34508 }
[email protected]3a453fa2008-08-15 18:46:34509
[email protected]1bd056e2010-04-20 02:03:48510 virtual CloudPrintProxyService* GetCloudPrintProxyService() {
511 return NULL;
512 }
513
initial.commit09911bf2008-07-26 23:55:29514 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54515 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29516 }
517
518 virtual Time GetStartTime() const {
519 return start_time_;
520 }
521
522 virtual TabRestoreService* GetTabRestoreService() {
523 return NULL;
524 }
525
[email protected]e7244d82008-10-29 18:13:26526 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41527 }
528
[email protected]85c55dc2009-11-06 03:05:46529 virtual SpellCheckHost* GetSpellCheckHost() {
530 return profile_->GetSpellCheckHost();
531 }
532
533 virtual void ReinitializeSpellCheckHost(bool force) {
534 profile_->ReinitializeSpellCheckHost(force);
535 }
[email protected]85c55dc2009-11-06 03:05:46536
[email protected]3bf335a2009-06-26 20:46:06537 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29538 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:11539 webkit_context_ = new WebKitContext(this);
[email protected]c27324b2009-11-19 22:44:29540 DCHECK(webkit_context_.get());
541 return webkit_context_.get();
542 }
[email protected]3bf335a2009-06-26 20:46:06543
[email protected]449478302009-06-09 20:04:28544 virtual ThumbnailStore* GetThumbnailStore() {
545 return NULL;
546 }
547
initial.commit09911bf2008-07-26 23:55:29548 virtual void MarkAsCleanShutdown() {
549 }
550
[email protected]bdbc87c2009-01-25 05:08:54551 virtual void InitExtensions() {
552 NOTREACHED();
553 }
554
[email protected]ea0c98cf2009-06-18 23:02:54555 virtual void InitWebResources() {
556 NOTREACHED();
557 }
558
[email protected]9c8dd902009-11-19 17:50:42559 virtual NTPResourceCache* GetNTPResourceCache() {
560 // Just return the real profile resource cache.
561 return profile_->GetNTPResourceCache();
562 }
563
initial.commit09911bf2008-07-26 23:55:29564 virtual void ExitedOffTheRecordMode() {
565 // Drop our download manager so we forget about all the downloads made
566 // in off-the-record mode.
567 download_manager_ = NULL;
568 }
569
570 virtual void Observe(NotificationType type,
571 const NotificationSource& source,
572 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56573 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29574 // We are only interested in OTR browser closing.
575 if (Source<Browser>(source)->profile() != this)
576 return;
577
578 // Let's check if we still have an Off The Record window opened.
579 // Note that we check against 1 as this notification is sent before the
580 // browser window is actually removed from the list.
581 if (BrowserList::GetBrowserCount(this) <= 1)
582 ExitedOffTheRecordMode();
583 }
584
585 private:
[email protected]88cf3292009-05-22 01:48:43586 NotificationRegistrar registrar_;
587
initial.commit09911bf2008-07-26 23:55:29588 // The real underlying profile.
589 Profile* profile_;
590
[email protected]6ab9b202008-12-23 22:34:50591 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19592 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29593
594 // The download manager that only stores downloaded items in memory.
595 scoped_refptr<DownloadManager> download_manager_;
596
[email protected]7d7696c52009-12-01 20:54:58597 // Use a separate desktop notification service for OTR.
598 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
599
[email protected]bd147842010-04-09 15:29:17600 // We use a non-writable content settings map for OTR.
601 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
602
[email protected]3bf335a2009-06-26 20:46:06603 // Use a special WebKit context for OTR browsing.
604 scoped_refptr<WebKitContext> webkit_context_;
605
[email protected]34cc84f2009-02-13 10:04:35606 // We don't want SSLHostState from the OTR profile to leak back to the main
607 // profile because then the main profile would learn some of the host names
608 // the user visited while OTR.
609 scoped_ptr<SSLHostState> ssl_host_state_;
610
[email protected]e5d2f7132010-04-09 18:13:53611 // Use a separate FindBarState so search terms do not leak back to the main
612 // profile.
613 scoped_ptr<FindBarState> find_bar_state_;
614
[email protected]326e6792009-12-11 21:04:42615 // The TransportSecurityState that only stores enabled sites in memory.
616 scoped_refptr<net::TransportSecurityState>
617 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23618
initial.commit09911bf2008-07-26 23:55:29619 // Time we were started.
620 Time start_time_;
621
[email protected]2f351cb2009-11-09 23:43:34622 // The main database tracker for this profile.
623 // Should be used only on the file thread.
624 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
625
[email protected]90085af02009-10-29 17:53:21626 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29627};
628
[email protected]f7011fcb2009-01-28 21:54:32629ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29630 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44631 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07632 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32633 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57634 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21635 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45636 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51637 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32638 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48639 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32640 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41641 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32642 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42643 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32644 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46645 spellcheck_host_(NULL),
646 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29647 shutdown_session_service_(false) {
648 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
649 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14650 create_session_service_timer_.Start(
651 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
652 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54653
[email protected]89ebc7e2009-08-24 22:11:07654 if (CommandLine::ForCurrentProcess()->HasSwitch(
655 switches::kEnableExtensionTimelineApi)) {
656 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
657 }
658
[email protected]382a0702009-06-26 17:12:27659 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37660 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27661
[email protected]e7244d82008-10-29 18:13:26662 PrefService* prefs = GetPrefs();
663 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
664 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58665 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58666
[email protected]405a64b2009-09-16 21:03:44667#if defined(OS_MACOSX)
668 // If the profile directory doesn't already have a cache directory and it
669 // is under ~/Library/Application Support, use a suitable cache directory
670 // under ~/Library/Caches. For example, a profile directory of
671 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
672 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
673 // ~/Library/Caches/Google/Chrome/MyProfileName.
674 //
675 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44676 if (!HasACacheSubdir(path_)) {
677 FilePath app_data_path, user_cache_path;
678 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12679 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44680 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
681 base_cache_path_ = user_cache_path;
682 }
683 }
[email protected]9e9b6e8e2009-12-02 08:45:01684#elif defined(OS_POSIX) // Posix minus Mac.
685 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
686 // for a spec on where cache files go. The net effect for most systems is we
687 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
688 // official builds.
689 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
690#if defined(GOOGLE_CHROME_BUILD)
691 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44692#else
[email protected]9e9b6e8e2009-12-02 08:45:01693 const char kCacheDir[] = "chromium";
694#endif
695 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
696 base_cache_path_ = base_cache_path_.Append(kCacheDir);
697 if (!file_util::PathExists(base_cache_path_))
698 file_util::CreateDirectory(base_cache_path_);
699 }
[email protected]405a64b2009-09-16 21:03:44700#endif
[email protected]bc96d562009-08-11 18:45:13701 if (base_cache_path_.empty())
702 base_cache_path_ = path_;
703
[email protected]4a190632009-05-09 01:07:42704 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43705 registrar_.Add(this, NotificationType::THEME_INSTALLED,
706 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11707
708 // Listen for bookmark model load, to bootstrap the sync service.
709 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
710 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42711
712 ssl_config_service_manager_.reset(
713 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53714
715#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29716 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53717#endif
[email protected]911f8152010-03-18 16:46:40718
719 pinned_tab_service_.reset(new PinnedTabService(this));
initial.commit09911bf2008-07-26 23:55:29720}
721
[email protected]bdbc87c2009-01-25 05:08:54722void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41723 if (user_script_master_ || extensions_service_)
724 return; // Already initialized.
725
[email protected]bdbc87c2009-01-25 05:08:54726 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]bb28e062009-02-27 17:19:18727 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36728
729 FilePath script_dir; // Don't look for user scripts in any directory.
730 // TODO(aa): We should just remove this functionality,
731 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51732 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36733
[email protected]894bb502009-05-21 22:39:57734 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23735 this,
736 CommandLine::ForCurrentProcess(),
737 GetPrefs(),
738 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36739 true);
[email protected]bdbc87c2009-01-25 05:08:54740
[email protected]fee67982010-04-23 17:24:22741 // Register the component extensions.
742 std::map<std::string, int> component_extensions;
743
744 // Bookmark manager.
[email protected]47e532b2010-04-23 17:46:40745 component_extensions["bookmark_manager"] = IDR_BOOKMARKS_MANIFEST;
[email protected]fee67982010-04-23 17:24:22746
[email protected]abdc9fb52010-05-06 01:44:48747#if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
[email protected]ae90f252010-05-04 18:28:03748 // Chat manager.
749 if (CommandLine::ForCurrentProcess()->HasSwitch(
750 switches::kEnableChatManager)) {
751 component_extensions["chat_manager"] = IDR_CHAT_MANAGER_MANIFEST;
752 }
753#endif
754
[email protected]fee67982010-04-23 17:24:22755 // Some sample apps to make our lives easier while we are developing extension
756 // apps. This way we don't have to constantly install these over and over.
[email protected]2bce5e12010-05-13 01:18:07757 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableApps)) {
[email protected]fee67982010-04-23 17:24:22758#if defined(OS_WIN)
759 std::string user_domain;
760 if (base::EnvVarGetter::Create()->GetEnv("USERDOMAIN", &user_domain) &&
761 user_domain == "GOOGLE") {
762 component_extensions["gmail_app"] = IDR_GMAIL_APP_MANIFEST;
763 component_extensions["calendar_app"] = IDR_CALENDAR_APP_MANIFEST;
764 component_extensions["docs_app"] = IDR_DOCS_APP_MANIFEST;
765 }
766#endif
767 }
768
769 for (std::map<std::string, int>::iterator iter = component_extensions.begin();
770 iter != component_extensions.end(); ++iter) {
771 FilePath path;
772 if (PathService::Get(chrome::DIR_RESOURCES, &path)) {
773 path = path.AppendASCII(iter->first);
[email protected]1952c7d2010-03-04 23:48:34774 } else {
775 NOTREACHED();
776 }
[email protected]fee67982010-04-23 17:24:22777
778 std::string manifest =
779 ResourceBundle::GetSharedInstance().GetRawDataResource(
780 iter->second).as_string();
781 extensions_service_->register_component_extension(
782 ExtensionsService::ComponentExtensionInfo(manifest, path));
[email protected]1952c7d2010-03-04 23:48:34783 }
784
[email protected]9197f3b2009-06-02 00:49:27785 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12786
787 // Load any extensions specified with --load-extension.
788 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10789 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12790 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12791 }
[email protected]bdbc87c2009-01-25 05:08:54792}
793
[email protected]ea0c98cf2009-06-18 23:02:54794void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07795 if (web_resource_service_)
796 return; // Already initialized.
797
[email protected]6fad2632009-11-02 05:59:37798 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54799 web_resource_service_->StartAfterDelay();
800}
801
[email protected]9c8dd902009-11-19 17:50:42802NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
803 if (!ntp_resource_cache_.get())
804 ntp_resource_cache_.reset(new NTPResourceCache(this));
805 return ntp_resource_cache_.get();
806}
807
initial.commit09911bf2008-07-26 23:55:29808ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56809 NotificationService::current()->Notify(
810 NotificationType::PROFILE_DESTROYED,
811 Source<Profile>(this),
812 NotificationService::NoDetails());
813
[email protected]169627b2008-12-06 19:30:19814 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29815
816 StopCreateSessionServiceTimer();
817 // TemplateURLModel schedules a task on the WebDataService from its
818 // destructor. Delete it first to ensure the task gets scheduled before we
819 // shut down the database.
820 template_url_model_.reset();
821
822 // The download manager queries the history system and should be deleted
823 // before the history is shutdown so it can properly cancel all requests.
824 download_manager_ = NULL;
825
[email protected]4a190632009-05-09 01:07:42826 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15827 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42828
[email protected]44961292009-07-20 20:03:09829 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
830 // save any new thumbnails to disk and release its reference to the
831 // HistoryService.
832 if (thumbnail_store_.get())
833 thumbnail_store_->Shutdown();
834
[email protected]e7244d82008-10-29 18:13:26835 // Remove pref observers.
836 PrefService* prefs = GetPrefs();
837 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
838 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58839 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26840
[email protected]9c8dd902009-11-19 17:50:42841 // Delete the NTP resource cache so we can unregister pref observers.
842 ntp_resource_cache_.reset();
843
[email protected]48352c12009-08-15 01:19:11844 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34845
initial.commit09911bf2008-07-26 23:55:29846 // Both HistoryService and WebDataService maintain threads for background
847 // processing. Its possible each thread still has tasks on it that have
848 // increased the ref count of the service. In such a situation, when we
849 // decrement the refcount, it won't be 0, and the threads/databases aren't
850 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
851 // databases are properly closed.
852 if (web_data_service_.get())
853 web_data_service_->Shutdown();
854
855 if (history_service_.get())
856 history_service_->Cleanup();
857
[email protected]85c55dc2009-11-06 03:05:46858 if (spellcheck_host_.get())
859 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29860
[email protected]cfc06f122009-11-16 22:18:55861 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21862 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50863
[email protected]47accfd62009-05-14 18:46:21864 CleanupRequestContext(request_context_);
865 CleanupRequestContext(media_request_context_);
866 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17867
[email protected]d8e41ed2008-09-11 15:22:32868 // HistoryService may call into the BookmarkModel, as such we need to
869 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46870 // HistoryService will join with HistoryService's backend thread so that
871 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32872 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46873 history_service_ = NULL;
874 bookmark_bar_model_.reset();
875
[email protected]0189bc722009-08-28 21:56:48876 // FaviconService depends on HistoryServce so make sure we delete
877 // HistoryService first.
878 favicon_service_ = NULL;
879
[email protected]7120f132009-07-20 21:05:37880 extension_message_service_->ProfileDestroyed();
881
[email protected]6ef635e42009-07-26 06:16:12882 if (extensions_service_)
883 extensions_service_->ProfileDestroyed();
884
[email protected]66da08b2009-10-19 22:27:00885 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29886 MarkAsCleanShutdown();
887}
888
[email protected]4bf6afd2009-10-08 14:00:11889ProfileId ProfileImpl::GetRuntimeId() {
890 return reinterpret_cast<ProfileId>(this);
891}
892
[email protected]f7011fcb2009-01-28 21:54:32893FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29894 return path_;
895}
896
897bool ProfileImpl::IsOffTheRecord() {
898 return false;
899}
900
901Profile* ProfileImpl::GetOffTheRecordProfile() {
902 if (!off_the_record_profile_.get()) {
903 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
904 off_the_record_profile_.swap(p);
905 }
906 return off_the_record_profile_.get();
907}
908
[email protected]860f55492009-03-27 19:50:59909void ProfileImpl::DestroyOffTheRecordProfile() {
910 off_the_record_profile_.reset();
911}
912
initial.commit09911bf2008-07-26 23:55:29913Profile* ProfileImpl::GetOriginalProfile() {
914 return this;
915}
916
[email protected]2f351cb2009-11-09 23:43:34917webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
918 if (!db_tracker_)
919 db_tracker_ = new webkit_database::DatabaseTracker(GetPath());
920 return db_tracker_;
921}
922
initial.commit09911bf2008-07-26 23:55:29923VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:44924 if (!visited_link_master_.get()) {
925 scoped_ptr<VisitedLinkMaster> visited_links(
926 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
927 if (!visited_links->Init())
928 return NULL;
929 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:53930 }
[email protected]a6d0f182010-01-12 08:01:44931
932 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:29933}
934
[email protected]6014d672008-12-05 00:38:25935ExtensionsService* ProfileImpl::GetExtensionsService() {
936 return extensions_service_.get();
937}
938
[email protected]0938d3c2009-01-09 20:37:35939UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35940 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25941}
942
[email protected]89ebc7e2009-08-24 22:11:07943ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
944 return extension_devtools_manager_.get();
945}
946
[email protected]481e1a42009-05-06 20:56:05947ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27948 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05949}
950
[email protected]7120f132009-07-20 21:05:37951ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
952 return extension_message_service_.get();
953}
954
[email protected]34cc84f2009-02-13 10:04:35955SSLHostState* ProfileImpl::GetSSLHostState() {
956 if (!ssl_host_state_.get())
957 ssl_host_state_.reset(new SSLHostState());
958
959 DCHECK(ssl_host_state_->CalledOnValidThread());
960 return ssl_host_state_.get();
961}
962
[email protected]326e6792009-12-11 21:04:42963net::TransportSecurityState*
964 ProfileImpl::GetTransportSecurityState() {
965 if (!transport_security_state_.get()) {
966 transport_security_state_ = new net::TransportSecurityState();
967 transport_security_persister_ =
968 new TransportSecurityPersister();
969 transport_security_persister_->Initialize(
970 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:51971 }
[email protected]a9cea7542009-05-20 04:30:23972
[email protected]326e6792009-12-11 21:04:42973 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23974}
975
initial.commit09911bf2008-07-26 23:55:29976PrefService* ProfileImpl::GetPrefs() {
977 if (!prefs_.get()) {
[email protected]277404c22010-04-22 13:09:45978 prefs_.reset(new PrefService(new JsonPrefStore(GetPrefFilePath())));
initial.commit09911bf2008-07-26 23:55:29979
980 // The Profile class and ProfileManager class may read some prefs so
981 // register known prefs as soon as possible.
982 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:51983 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:29984
985 // The last session exited cleanly if there is no pref for
986 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
987 last_session_exited_cleanly_ =
988 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
989 // Mark the session as open.
990 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
991 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36992 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29993 }
994
995 return prefs_.get();
996}
997
[email protected]f7011fcb2009-01-28 21:54:32998FilePath ProfileImpl::GetPrefFilePath() {
999 FilePath pref_file_path = path_;
1000 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:291001 return pref_file_path;
1002}
1003
[email protected]be180c802009-10-23 06:33:311004URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:291005 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:321006 FilePath cookie_path = GetPath();
1007 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:131008 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311009 int max_size;
1010 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:421011
[email protected]405a64b2009-09-16 21:03:441012 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311013 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
1014 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:291015
[email protected]6ab9b202008-12-23 22:34:501016 // The first request context is always a normal (non-OTR) request context.
1017 // Even when Chromium is started in OTR mode, a normal profile is always
1018 // created first.
1019 if (!default_request_context_) {
1020 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:311021 // TODO(eroman): this isn't terribly useful anymore now that the
1022 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:501023 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561024 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:501025 NotificationService::AllSources(), NotificationService::NoDetails());
1026 }
initial.commit09911bf2008-07-26 23:55:291027 }
1028
1029 return request_context_;
1030}
1031
[email protected]be180c802009-10-23 06:33:311032URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:181033 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:131034 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311035 int max_size;
1036 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:141037
[email protected]405a64b2009-09-16 21:03:441038 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311039 media_request_context_ =
1040 ChromeURLRequestContextGetter::CreateOriginalForMedia(
1041 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:181042 }
1043
1044 return media_request_context_;
1045}
1046
[email protected]0189bc722009-08-28 21:56:481047FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
1048 if (!favicon_service_created_) {
1049 favicon_service_created_ = true;
1050 scoped_refptr<FaviconService> service(new FaviconService(this));
1051 favicon_service_.swap(service);
1052 }
1053 return favicon_service_.get();
1054}
1055
[email protected]be180c802009-10-23 06:33:311056URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:211057 if (!extensions_request_context_) {
1058 FilePath cookie_path = GetPath();
1059 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1060
1061 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:311062 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
1063 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:211064 }
1065
1066 return extensions_request_context_;
1067}
1068
[email protected]57a777f72010-03-31 01:09:421069void ProfileImpl::RegisterExtensionWithRequestContexts(
1070 Extension* extension) {
1071 // Notify the default, extension and media contexts on the IO thread.
1072 PostExtensionLoadedToContextGetter(
1073 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1074 extension);
1075 PostExtensionLoadedToContextGetter(
1076 static_cast<ChromeURLRequestContextGetter*>(
1077 GetRequestContextForExtensions()),
1078 extension);
1079 PostExtensionLoadedToContextGetter(
1080 static_cast<ChromeURLRequestContextGetter*>(
1081 GetRequestContextForMedia()),
1082 extension);
1083}
1084
1085void ProfileImpl::UnregisterExtensionWithRequestContexts(
1086 Extension* extension) {
1087 // Notify the default, extension and media contexts on the IO thread.
1088 PostExtensionUnloadedToContextGetter(
1089 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1090 extension);
1091 PostExtensionUnloadedToContextGetter(
1092 static_cast<ChromeURLRequestContextGetter*>(
1093 GetRequestContextForExtensions()),
1094 extension);
1095 PostExtensionUnloadedToContextGetter(
1096 static_cast<ChromeURLRequestContextGetter*>(
1097 GetRequestContextForMedia()),
1098 extension);
1099}
1100
[email protected]db36938c2009-08-19 21:48:421101net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1102 return ssl_config_service_manager_->Get();
1103}
1104
[email protected]e284e6d82010-01-29 19:49:451105HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
1106 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:391107 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:451108 return host_content_settings_map_.get();
1109}
1110
[email protected]40bd6582009-12-04 23:49:511111HostZoomMap* ProfileImpl::GetHostZoomMap() {
1112 if (!host_zoom_map_)
1113 host_zoom_map_ = new HostZoomMap(this);
1114 return host_zoom_map_.get();
1115}
1116
[email protected]aee541e2010-03-19 01:52:451117GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
1118 if (!geolocation_content_settings_map_.get())
1119 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
1120 return geolocation_content_settings_map_.get();
1121}
1122
[email protected]8b4b84ee2010-05-11 13:08:521123GeolocationPermissionContext* ProfileImpl::GetGeolocationPermissionContext() {
1124 if (!geolocation_permission_context_.get())
1125 geolocation_permission_context_ = new GeolocationPermissionContext(this);
1126 return geolocation_permission_context_.get();
1127}
1128
[email protected]8c6335d32010-01-20 09:21:501129Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271130 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141131 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271132 return NULL;
[email protected]c37f8b42010-01-23 16:22:141133 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541134 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501135 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231136}
1137
[email protected]6c32ce72010-03-08 05:18:061138UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1139 if (!user_style_sheet_watcher_.get()) {
1140 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1141 user_style_sheet_watcher_->Init();
1142 }
1143 return user_style_sheet_watcher_.get();
1144}
1145
[email protected]e5d2f7132010-04-09 18:13:531146FindBarState* ProfileImpl::GetFindBarState() {
1147 if (!find_bar_state_.get()) {
1148 find_bar_state_.reset(new FindBarState());
1149 }
1150 return find_bar_state_.get();
1151}
1152
initial.commit09911bf2008-07-26 23:55:291153HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1154 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461155 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291156 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321157 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291158 return NULL;
1159 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291160
1161 // Send out the notification that the history service was created.
1162 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561163 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291164 Details<HistoryService>(history_service_.get()));
1165 }
1166 return history_service_.get();
1167}
1168
[email protected]0850fa62009-10-08 22:34:291169HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1170 return history_service_.get();
1171}
1172
initial.commit09911bf2008-07-26 23:55:291173TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1174 if (!template_url_model_.get())
1175 template_url_model_.reset(new TemplateURLModel(this));
1176 return template_url_model_.get();
1177}
1178
1179TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1180 if (!template_url_fetcher_.get())
1181 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1182 return template_url_fetcher_.get();
1183}
1184
[email protected]69c579e2010-04-23 20:01:001185AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
1186 if (!autocomplete_classifier_.get())
1187 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
1188 return autocomplete_classifier_.get();
[email protected]90085af02009-10-29 17:53:211189}
1190
initial.commit09911bf2008-07-26 23:55:291191WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1192 if (!created_web_data_service_)
1193 CreateWebDataService();
1194 return web_data_service_.get();
1195}
1196
[email protected]9cddbe372009-10-23 21:23:531197WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1198 return web_data_service_.get();
1199}
1200
initial.commit09911bf2008-07-26 23:55:291201void ProfileImpl::CreateWebDataService() {
1202 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1203 created_web_data_service_ = true;
1204 scoped_refptr<WebDataService> wds(new WebDataService());
1205 if (!wds->Init(GetPath()))
1206 return;
1207 web_data_service_.swap(wds);
1208}
1209
[email protected]e69d33952009-06-03 22:00:411210PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1211 if (!created_password_store_)
1212 CreatePasswordStore();
1213 return password_store_.get();
1214}
1215
1216void ProfileImpl::CreatePasswordStore() {
1217 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1218 created_password_store_ = true;
1219 scoped_refptr<PasswordStore> ps;
[email protected]e0411ae52009-06-30 23:59:171220 FilePath login_db_file_path = GetPath();
1221 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
[email protected]ec44cd52010-04-05 22:30:471222 LoginDatabase* login_db = new LoginDatabase();
[email protected]e0411ae52009-06-30 23:59:171223 if (!login_db->Init(login_db_file_path)) {
1224 LOG(ERROR) << "Could not initialize login database.";
1225 delete login_db;
1226 return;
1227 }
[email protected]e8380f52010-04-30 16:39:421228#if defined(OS_WIN)
1229 ps = new PasswordStoreWin(login_db, this,
1230 GetWebDataService(Profile::IMPLICIT_ACCESS));
1231#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171232 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161233#elif defined(OS_POSIX)
1234 // TODO(evanm): implement "native" password management.
1235 // This bug describes the issues.
1236 // http://code.google.com/p/chromium/issues/detail?id=12351
[email protected]e8380f52010-04-30 16:39:421237 ps = new PasswordStoreDefault(login_db, this,
1238 GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]e69d33952009-06-03 22:00:411239#else
1240 NOTIMPLEMENTED();
1241#endif
[email protected]e8380f52010-04-30 16:39:421242 if (!ps)
1243 delete login_db;
1244
[email protected]e69d33952009-06-03 22:00:411245 if (!ps || !ps->Init()) {
[email protected]e8380f52010-04-30 16:39:421246 NOTREACHED() << "Could not initialise password manager";
1247 return;
[email protected]e69d33952009-06-03 22:00:411248 }
1249 password_store_.swap(ps);
1250}
1251
initial.commit09911bf2008-07-26 23:55:291252DownloadManager* ProfileImpl::GetDownloadManager() {
1253 if (!created_download_manager_) {
1254 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1255 dlm->Init(this);
1256 created_download_manager_ = true;
1257 download_manager_.swap(dlm);
1258 }
1259 return download_manager_.get();
1260}
1261
1262bool ProfileImpl::HasCreatedDownloadManager() const {
1263 return created_download_manager_;
1264}
1265
[email protected]def11712009-11-06 00:42:151266PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1267 if (!personal_data_manager_.get()) {
[email protected]e0976a72010-04-02 01:25:241268 personal_data_manager_.reset(new PersonalDataManager());
1269 personal_data_manager_->Init(this);
[email protected]def11712009-11-06 00:42:151270 }
1271 return personal_data_manager_.get();
1272}
1273
[email protected]4a190632009-05-09 01:07:421274void ProfileImpl::InitThemes() {
1275 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161276#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151277 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291278#else
[email protected]761962c2009-09-25 00:18:151279 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291280#endif
[email protected]761962c2009-09-25 00:18:151281 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421282 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421283 }
1284}
1285
1286void ProfileImpl::SetTheme(Extension* extension) {
1287 InitThemes();
1288 theme_provider_.get()->SetTheme(extension);
1289}
1290
[email protected]a5166af62009-07-03 00:42:291291void ProfileImpl::SetNativeTheme() {
1292 InitThemes();
1293 theme_provider_.get()->SetNativeTheme();
1294}
1295
[email protected]4a190632009-05-09 01:07:421296void ProfileImpl::ClearTheme() {
1297 InitThemes();
1298 theme_provider_.get()->UseDefaultTheme();
1299}
1300
[email protected]51c490b2009-08-03 16:34:341301Extension* ProfileImpl::GetTheme() {
1302 InitThemes();
1303
1304 std::string id = theme_provider_.get()->GetThemeID();
1305 if (id == BrowserThemeProvider::kDefaultThemeID)
1306 return NULL;
1307
[email protected]61b411612009-11-10 23:17:411308 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341309}
1310
[email protected]5786d3d2009-12-18 00:18:441311BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421312 InitThemes();
1313 return theme_provider_.get();
1314}
1315
initial.commit09911bf2008-07-26 23:55:291316SessionService* ProfileImpl::GetSessionService() {
1317 if (!session_service_.get() && !shutdown_session_service_) {
1318 session_service_ = new SessionService(this);
1319 session_service_->ResetFromCurrentBrowsers();
1320 }
1321 return session_service_.get();
1322}
1323
1324void ProfileImpl::ShutdownSessionService() {
1325 if (shutdown_session_service_)
1326 return;
1327
1328 // We're about to exit, force creation of the session service if it hasn't
1329 // been created yet. We do this to ensure session state matches the point in
1330 // time the user exited.
1331 GetSessionService();
1332 shutdown_session_service_ = true;
1333 session_service_ = NULL;
1334}
1335
1336bool ProfileImpl::HasSessionService() const {
1337 return (session_service_.get() != NULL);
1338}
1339
initial.commit09911bf2008-07-26 23:55:291340bool ProfileImpl::DidLastSessionExitCleanly() {
1341 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1342 // it to be set by asking for the prefs.
1343 GetPrefs();
1344 return last_session_exited_cleanly_;
1345}
1346
[email protected]d8e41ed2008-09-11 15:22:321347BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461348 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321349 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461350 bookmark_bar_model_->Load();
1351 }
initial.commit09911bf2008-07-26 23:55:291352 return bookmark_bar_model_.get();
1353}
1354
1355bool ProfileImpl::IsSameProfile(Profile* profile) {
1356 if (profile == static_cast<Profile*>(this))
1357 return true;
1358 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1359 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1360}
1361
1362Time ProfileImpl::GetStartTime() const {
1363 return start_time_;
1364}
1365
1366TabRestoreService* ProfileImpl::GetTabRestoreService() {
1367 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191368 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291369 return tab_restore_service_.get();
1370}
1371
[email protected]449478302009-06-09 20:04:281372ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1373 if (!thumbnail_store_.get()) {
1374 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251375 thumbnail_store_->Init(
1376 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281377 }
1378 return thumbnail_store_.get();
1379}
1380
initial.commit09911bf2008-07-26 23:55:291381void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191382 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291383}
1384
[email protected]85c55dc2009-11-06 03:05:461385SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1386 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1387}
1388
1389void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1390 // If we are already loading the spellchecker, and this is just a hint to
1391 // load the spellchecker, do nothing.
1392 if (!force && spellcheck_host_.get())
1393 return;
1394
[email protected]f41301e2009-11-16 21:30:071395 spellcheck_host_ready_ = false;
1396
[email protected]85c55dc2009-11-06 03:05:461397 bool notify = false;
1398 if (spellcheck_host_.get()) {
1399 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051400 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461401 notify = true;
1402 }
1403
1404 PrefService* prefs = GetPrefs();
1405 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1406 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1407 spellcheck_host_ = new SpellCheckHost(this,
1408 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1409 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071410 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461411 } else if (notify) {
1412 // The spellchecker has been disabled.
1413 SpellCheckHostInitialized();
1414 }
1415}
1416
1417void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171418 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291419 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1420 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461421 NotificationService::current()->Notify(
1422 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1423 Source<Profile>(this), NotificationService::NoDetails());
1424}
initial.commit09911bf2008-07-26 23:55:291425
[email protected]3bf335a2009-06-26 20:46:061426WebKitContext* ProfileImpl::GetWebKitContext() {
1427 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:111428 webkit_context_ = new WebKitContext(this);
[email protected]3bf335a2009-06-26 20:46:061429 DCHECK(webkit_context_.get());
1430 return webkit_context_.get();
1431}
1432
[email protected]4bb336302009-10-12 05:44:261433DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1434 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1435 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261436 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031437 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261438 }
[email protected]4bb336302009-10-12 05:44:261439 return desktop_notification_service_.get();
1440}
1441
initial.commit09911bf2008-07-26 23:55:291442void ProfileImpl::MarkAsCleanShutdown() {
1443 if (prefs_.get()) {
1444 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1445 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1446
1447 // NOTE: If you change what thread this writes on, be sure and update
1448 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361449 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291450 }
1451}
1452
[email protected]e7244d82008-10-29 18:13:261453void ProfileImpl::Observe(NotificationType type,
1454 const NotificationSource& source,
1455 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561456 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261457 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1458 PrefService* prefs = Source<PrefService>(source).ptr();
1459 DCHECK(pref_name_in && prefs);
1460 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461461 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461462 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291463 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1464 NotificationService::current()->Notify(
1465 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1466 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261467 }
[email protected]4a190632009-05-09 01:07:421468 } else if (NotificationType::THEME_INSTALLED == type) {
1469 Extension* extension = Details<Extension>(details).ptr();
1470 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111471 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1472 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1473 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1474 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261475 }
1476}
1477
initial.commit09911bf2008-07-26 23:55:291478void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141479 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291480}
[email protected]3a453fa2008-08-15 18:46:341481
[email protected]48352c12009-08-15 01:19:111482ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431483 if (!ProfileSyncService::IsSyncEnabled()) {
1484 return NULL;
[email protected]7367f1a2009-10-10 01:09:441485 }
[email protected]eec3bcfa2009-11-12 17:23:431486 if (!sync_service_.get())
1487 InitSyncService();
1488 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111489}
1490
[email protected]1bd056e2010-04-20 02:03:481491CloudPrintProxyService* ProfileImpl::GetCloudPrintProxyService() {
1492 if (!cloud_print_proxy_service_.get())
1493 InitCloudPrintProxyService();
1494 return cloud_print_proxy_service_.get();
1495}
1496
[email protected]48352c12009-08-15 01:19:111497void ProfileImpl::InitSyncService() {
[email protected]4aea04a2010-02-10 20:13:431498 profile_sync_factory_.reset(
1499 new ProfileSyncFactoryImpl(this,
1500 CommandLine::ForCurrentProcess()));
1501 sync_service_.reset(
1502 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111503 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111504}
[email protected]1bd056e2010-04-20 02:03:481505
1506void ProfileImpl::InitCloudPrintProxyService() {
1507 cloud_print_proxy_service_.reset(new CloudPrintProxyService(this));
1508 cloud_print_proxy_service_->Initialize();
1509}