blob: bbfd60d2f62517fe3010be575c748ff94cab6ce0 [file] [log] [blame]
[email protected]e284e6d82010-01-29 19:49:451// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/profile.h"
6
[email protected]1952c7d2010-03-04 23:48:347#include "app/resource_bundle.h"
[email protected]2735e3692009-09-25 18:19:398#include "app/theme_provider.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/command_line.h"
[email protected]fee67982010-04-23 17:24:2210#include "base/env_var.h"
[email protected]04fba9a92008-10-28 17:25:2511#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4412#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/path_service.h"
14#include "base/scoped_ptr.h"
15#include "base/string_util.h"
[email protected]0082d7e0d2010-02-27 14:34:1216#include "chrome/browser/appcache/chrome_appcache_service.h"
[email protected]69c579e2010-04-23 20:01:0017#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]def11712009-11-06 00:42:1518#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4219#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/browser/browser_list.h"
[email protected]9acc48602009-11-30 21:18:5121#include "chrome/browser/browser_prefs.h"
[email protected]8a4892d8d2009-11-23 20:40:5722#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0223#include "chrome/browser/browser_theme_provider.h"
[email protected]6fad2632009-11-02 05:59:3724#include "chrome/browser/chrome_thread.h"
[email protected]9c8dd902009-11-19 17:50:4225#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]b7f05882009-02-22 01:21:5626#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0727#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]14a000d2010-04-29 21:44:2428#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]7120f132009-07-20 21:05:3729#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0530#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2531#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3532#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4833#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5334#include "chrome/browser/find_bar_state.h"
[email protected]aee541e2010-03-19 01:52:4535#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]8b4b84ee2010-05-11 13:08:5236#include "chrome/browser/geolocation/geolocation_permission_context.h"
[email protected]9c92d192009-12-02 08:03:1637#include "chrome/browser/spellcheck_host.h"
[email protected]326e6792009-12-11 21:04:4238#include "chrome/browser/transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4239#include "chrome/browser/history/history.h"
[email protected]523623c2010-05-19 16:03:4240#include "chrome/browser/history/top_sites.h"
[email protected]e284e6d82010-01-29 19:49:4541#include "chrome/browser/host_content_settings_map.h"
[email protected]40bd6582009-12-04 23:49:5142#include "chrome/browser/host_zoom_map.h"
[email protected]3bf335a2009-06-26 20:46:0643#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5044#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4245#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2646#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4147#include "chrome/browser/password_manager/password_store_default.h"
[email protected]d8b08c92010-06-07 13:13:2848#include "chrome/browser/pref_value_store.h"
[email protected]8c6335d32010-01-20 09:21:5049#include "chrome/browser/privacy_blacklist/blacklist.h"
[email protected]1bd056e2010-04-20 02:03:4850#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
initial.commit09911bf2008-07-26 23:55:2951#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2652#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3353#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4654#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4455#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3056#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]1132436e2009-04-08 20:06:3357#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]82d9d2952010-05-15 00:36:1658#include "chrome/browser/sync/net/network_change_notifier_io_thread.h"
[email protected]48352c12009-08-15 01:19:1159#include "chrome/browser/sync/profile_sync_service.h"
[email protected]4aea04a2010-02-10 20:13:4360#include "chrome/browser/sync/profile_sync_factory_impl.h"
[email protected]911f8152010-03-18 16:46:4061#include "chrome/browser/tabs/pinned_tab_service.h"
[email protected]449478302009-06-09 20:04:2862#include "chrome/browser/thumbnail_store.h"
[email protected]6c32ce72010-03-08 05:18:0663#include "chrome/browser/user_style_sheet_watcher.h"
initial.commit09911bf2008-07-26 23:55:2964#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3965#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2966#include "chrome/browser/webdata/web_data_service.h"
[email protected]b1748b1d82009-11-30 20:32:5667#include "chrome/browser/web_resource/web_resource_service.h"
initial.commit09911bf2008-07-26 23:55:2968#include "chrome/common/chrome_constants.h"
69#include "chrome/common/chrome_paths.h"
70#include "chrome/common/chrome_switches.h"
[email protected]ea587b02010-05-21 15:01:3571#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2972#include "chrome/common/notification_service.h"
73#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3274#include "chrome/common/render_messages.h"
[email protected]1952c7d2010-03-04 23:48:3475#include "grit/browser_resources.h"
[email protected]f90f5c512009-02-18 19:10:5876#include "grit/locale_settings.h"
[email protected]326e6792009-12-11 21:04:4277#include "net/base/transport_security_state.h"
[email protected]2f351cb2009-11-09 23:43:3478#include "webkit/database/database_tracker.h"
initial.commit09911bf2008-07-26 23:55:2979
[email protected]753efc42010-03-09 19:52:1680#if defined(TOOLKIT_USES_GTK)
[email protected]a5166af62009-07-03 00:42:2981#include "chrome/browser/gtk/gtk_theme_provider.h"
82#endif
83
[email protected]e1acf6f2008-10-27 20:43:3384using base::Time;
85using base::TimeDelta;
86
[email protected]e5642992009-06-26 23:06:3187namespace {
88
initial.commit09911bf2008-07-26 23:55:2989// Delay, in milliseconds, before we explicitly create the SessionService.
90static const int kCreateSessionServiceDelayMS = 500;
91
[email protected]e5642992009-06-26 23:06:3192enum ContextType {
93 kNormalContext,
94 kMediaContext
95};
96
97// Gets the cache parameters from the command line. |type| is the type of
98// request context that we need, |cache_path| will be set to the user provided
99// path, or will not be touched if there is not an argument. |max_size| will
100// be the user provided value or zero by default.
101void GetCacheParameters(ContextType type, FilePath* cache_path,
102 int* max_size) {
103 DCHECK(cache_path);
104 DCHECK(max_size);
105
106 // Override the cache location if specified by the user.
107 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
108 switches::kDiskCacheDir));
109
110 if (!user_path.empty()) {
111 *cache_path = FilePath::FromWStringHack(user_path);
112 }
113
[email protected]b7e0a2a2009-10-13 02:07:25114 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
115 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:31116 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:25117 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31118
119 // By default we let the cache determine the right size.
120 *max_size = 0;
121 if (!StringToInt(value, max_size)) {
122 *max_size = 0;
123 } else if (max_size < 0) {
124 *max_size = 0;
125 }
126}
127
[email protected]405a64b2009-09-16 21:03:44128FilePath GetCachePath(const FilePath& base) {
129 return base.Append(chrome::kCacheDirname);
130}
131
132FilePath GetMediaCachePath(const FilePath& base) {
133 return base.Append(chrome::kMediaCacheDirname);
134}
135
136bool HasACacheSubdir(const FilePath &dir) {
137 return file_util::PathExists(GetCachePath(dir)) ||
138 file_util::PathExists(GetMediaCachePath(dir));
139}
140
[email protected]57a777f72010-03-31 01:09:42141void PostExtensionLoadedToContextGetter(ChromeURLRequestContextGetter* getter,
142 Extension* extension) {
143 if (!getter)
144 return;
145 // Callee takes ownership of new ExtensionInfo struct.
146 ChromeThread::PostTask(
147 ChromeThread::IO, FROM_HERE,
148 NewRunnableMethod(getter,
149 &ChromeURLRequestContextGetter::OnNewExtensions,
150 extension->id(),
151 new ChromeURLRequestContext::ExtensionInfo(
[email protected]cb58c8cf2010-05-20 05:42:59152 extension->name(),
[email protected]57a777f72010-03-31 01:09:42153 extension->path(),
154 extension->default_locale(),
155 extension->web_extent(),
156 extension->api_permissions())));
157}
158
159void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
160 Extension* extension) {
161 if (!getter)
162 return;
163 ChromeThread::PostTask(
164 ChromeThread::IO, FROM_HERE,
165 NewRunnableMethod(getter,
166 &ChromeURLRequestContextGetter::OnUnloadedExtension,
167 extension->id()));
168}
169
[email protected]5e1bf5d2010-05-26 20:52:18170// Returns true if the default apps should be loaded (so that the app panel is
171// not empty).
172bool IncludeDefaultApps() {
173#if defined(OS_WIN)
174 std::string user_domain;
175 return base::EnvVarGetter::Create()->GetEnv("USERDOMAIN", &user_domain) &&
176 user_domain == "GOOGLE";
177#elif defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
178 return true;
179#endif
180 return false;
181}
[email protected]a04876b92010-06-11 22:53:43182
183// Simple task to log the size of the current profile.
184class ProfileSizeTask : public Task {
185 public:
186 explicit ProfileSizeTask(const FilePath& path) : path_(path) {}
187 virtual ~ProfileSizeTask() {}
188
189 virtual void Run();
190 private:
191 FilePath path_;
192};
193
194void ProfileSizeTask::Run() {
195 int64 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("*"));
196 int size_MB = static_cast<int>(size / (1024 * 1024));
197 UMA_HISTOGRAM_COUNTS_10000("Profile.TotalSize", size_MB);
198
199 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("History"));
200 size_MB = static_cast<int>(size / (1024 * 1024));
201 UMA_HISTOGRAM_COUNTS_10000("Profile.HistorySize", size_MB);
202
203 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("History*"));
204 size_MB = static_cast<int>(size / (1024 * 1024));
205 UMA_HISTOGRAM_COUNTS_10000("Profile.TotalHistorySize", size_MB);
206
207 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Cookies"));
208 size_MB = static_cast<int>(size / (1024 * 1024));
209 UMA_HISTOGRAM_COUNTS_10000("Profile.CookiesSize", size_MB);
210
211 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Bookmarks"));
212 size_MB = static_cast<int>(size / (1024 * 1024));
213 UMA_HISTOGRAM_COUNTS_10000("Profile.BookmarksSize", size_MB);
214
215 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Thumbnails"));
216 size_MB = static_cast<int>(size / (1024 * 1024));
217 UMA_HISTOGRAM_COUNTS_10000("Profile.ThumbnailsSize", size_MB);
218
219 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Visited Links"));
220 size_MB = static_cast<int>(size / (1024 * 1024));
221 UMA_HISTOGRAM_COUNTS_10000("Profile.VisitedLinksSize", size_MB);
222
223 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Web Data"));
224 size_MB = static_cast<int>(size / (1024 * 1024));
225 UMA_HISTOGRAM_COUNTS_10000("Profile.WebDataSize", size_MB);
226
227 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Extension*"));
228 size_MB = static_cast<int>(size / (1024 * 1024));
229 UMA_HISTOGRAM_COUNTS_10000("Profile.ExtensionSize", size_MB);
230}
231
[email protected]e5642992009-06-26 23:06:31232} // namespace
233
initial.commit09911bf2008-07-26 23:55:29234// A pointer to the request context for the default profile. See comments on
235// Profile::GetDefaultRequestContext.
[email protected]be180c802009-10-23 06:33:31236URLRequestContextGetter* Profile::default_request_context_;
initial.commit09911bf2008-07-26 23:55:29237
[email protected]be180c802009-10-23 06:33:31238static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
[email protected]13c30922009-11-19 03:43:19239 if (context)
[email protected]47accfd62009-05-14 18:46:21240 context->CleanupOnUIThread();
[email protected]47accfd62009-05-14 18:46:21241}
242
[email protected]34cc84f2009-02-13 10:04:35243// static
[email protected]4bf6afd2009-10-08 14:00:11244const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
245
246// static
initial.commit09911bf2008-07-26 23:55:29247void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55248 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29249 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
250 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12251 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26252 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
253 IDS_SPELLCHECK_DICTIONARY);
254 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58255 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]753efc42010-03-09 19:52:16256#if defined(TOOLKIT_USES_GTK)
[email protected]88c50ab2010-03-26 20:04:06257 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme,
258 GtkThemeProvider::DefaultUsesSystemTheme());
[email protected]a5166af62009-07-03 00:42:29259#endif
[email protected]f017cc92009-12-14 20:48:07260 prefs->RegisterFilePathPref(prefs::kCurrentThemePackFilename, FilePath());
[email protected]51c490b2009-08-03 16:34:34261 prefs->RegisterStringPref(prefs::kCurrentThemeID,
[email protected]20ce516d2010-06-18 02:20:04262 BrowserThemeProvider::kDefaultThemeID);
[email protected]4a190632009-05-09 01:07:42263 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
264 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
265 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50266 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23267 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
[email protected]20ce516d2010-06-18 02:20:04268 prefs->RegisterStringPref(prefs::kSelectFileLastDirectory, "");
initial.commit09911bf2008-07-26 23:55:29269}
270
[email protected]34cc84f2009-02-13 10:04:35271// static
[email protected]f7011fcb2009-01-28 21:54:32272Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29273 return new ProfileImpl(path);
274}
275
[email protected]34cc84f2009-02-13 10:04:35276// static
[email protected]be180c802009-10-23 06:33:31277URLRequestContextGetter* Profile::GetDefaultRequestContext() {
initial.commit09911bf2008-07-26 23:55:29278 return default_request_context_;
279}
280
[email protected]753efc42010-03-09 19:52:16281#if defined(OS_WIN)
[email protected]e69d33952009-06-03 22:00:41282#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56283#elif defined(OS_MACOSX)
284#include "chrome/browser/keychain_mac.h"
285#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]753efc42010-03-09 19:52:16286#elif defined(OS_POSIX)
287// Temporarily disabled while we figure some stuff out.
288// http://code.google.com/p/chromium/issues/detail?id=12351
289// #include "chrome/browser/password_manager/password_store_gnome.h"
290// #include "chrome/browser/password_manager/password_store_kwallet.h"
[email protected]e69d33952009-06-03 22:00:41291#endif
initial.commit09911bf2008-07-26 23:55:29292
initial.commit09911bf2008-07-26 23:55:29293////////////////////////////////////////////////////////////////////////////////
294//
295// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42296// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29297//
298////////////////////////////////////////////////////////////////////////////////
299class OffTheRecordProfileImpl : public Profile,
300 public NotificationObserver {
301 public:
302 explicit OffTheRecordProfileImpl(Profile* real_profile)
303 : profile_(real_profile),
304 start_time_(Time::Now()) {
[email protected]be180c802009-10-23 06:33:31305 request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
[email protected]481e1a42009-05-06 20:56:05306
initial.commit09911bf2008-07-26 23:55:29307 // Register for browser close notifications so we can detect when the last
308 // off-the-record window is closed, in which case we can clean our states
309 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43310 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
311 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29312 }
313
314 virtual ~OffTheRecordProfileImpl() {
[email protected]a04876b92010-06-11 22:53:43315 NotificationService::current()->Notify(NotificationType::PROFILE_DESTROYED,
316 Source<Profile>(this),
317 NotificationService::NoDetails());
318 CleanupRequestContext(request_context_);
[email protected]fe615f32010-06-13 09:08:41319
320 // Clean up all DB files/directories
321 ChromeThread::PostTask(
322 ChromeThread::FILE, FROM_HERE,
323 NewRunnableMethod(
324 db_tracker_.get(),
325 &webkit_database::DatabaseTracker::DeleteIncognitoDBDirectory));
initial.commit09911bf2008-07-26 23:55:29326 }
327
[email protected]4bf6afd2009-10-08 14:00:11328 virtual ProfileId GetRuntimeId() {
329 return reinterpret_cast<ProfileId>(this);
330 }
331
[email protected]a6d0f182010-01-12 08:01:44332 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29333
334 virtual bool IsOffTheRecord() {
335 return true;
336 }
337
338 virtual Profile* GetOffTheRecordProfile() {
339 return this;
340 }
341
[email protected]860f55492009-03-27 19:50:59342 virtual void DestroyOffTheRecordProfile() {
343 // Suicide is bad!
344 NOTREACHED();
345 }
346
initial.commit09911bf2008-07-26 23:55:29347 virtual Profile* GetOriginalProfile() {
348 return profile_;
349 }
350
[email protected]2f351cb2009-11-09 23:43:34351 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
[email protected]fe615f32010-06-13 09:08:41352 if (!db_tracker_) {
353 db_tracker_ = new webkit_database::DatabaseTracker(
354 GetPath(), IsOffTheRecord());
355 }
[email protected]2f351cb2009-11-09 23:43:34356 return db_tracker_;
357 }
358
initial.commit09911bf2008-07-26 23:55:29359 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49360 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
361 // because we don't want to leak the sites that the user has visited before.
362 return NULL;
initial.commit09911bf2008-07-26 23:55:29363 }
364
[email protected]6014d672008-12-05 00:38:25365 virtual ExtensionsService* GetExtensionsService() {
[email protected]55a35692010-02-11 23:25:21366 return GetOriginalProfile()->GetExtensionsService();
[email protected]6014d672008-12-05 00:38:25367 }
368
[email protected]0938d3c2009-01-09 20:37:35369 virtual UserScriptMaster* GetUserScriptMaster() {
[email protected]55a35692010-02-11 23:25:21370 return GetOriginalProfile()->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25371 }
372
[email protected]89ebc7e2009-08-24 22:11:07373 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
[email protected]55a35692010-02-11 23:25:21374 // TODO(mpcomplete): figure out whether we should return the original
375 // profile's version.
[email protected]89ebc7e2009-08-24 22:11:07376 return NULL;
377 }
378
[email protected]481e1a42009-05-06 20:56:05379 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]55a35692010-02-11 23:25:21380 return GetOriginalProfile()->GetExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:05381 }
382
[email protected]7120f132009-07-20 21:05:37383 virtual ExtensionMessageService* GetExtensionMessageService() {
[email protected]55a35692010-02-11 23:25:21384 return GetOriginalProfile()->GetExtensionMessageService();
[email protected]7120f132009-07-20 21:05:37385 }
386
[email protected]34cc84f2009-02-13 10:04:35387 virtual SSLHostState* GetSSLHostState() {
388 if (!ssl_host_state_.get())
389 ssl_host_state_.reset(new SSLHostState());
390
391 DCHECK(ssl_host_state_->CalledOnValidThread());
392 return ssl_host_state_.get();
393 }
394
[email protected]326e6792009-12-11 21:04:42395 virtual net::TransportSecurityState* GetTransportSecurityState() {
[email protected]7a1251842010-01-30 01:17:54396 if (!transport_security_state_.get())
397 transport_security_state_ = new net::TransportSecurityState();
[email protected]a9cea7542009-05-20 04:30:23398
[email protected]326e6792009-12-11 21:04:42399 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23400 }
401
initial.commit09911bf2008-07-26 23:55:29402 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54403 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29404 return profile_->GetHistoryService(sat);
[email protected]7a1251842010-01-30 01:17:54405
406 NOTREACHED() << "This profile is OffTheRecord";
407 return NULL;
initial.commit09911bf2008-07-26 23:55:29408 }
409
[email protected]0850fa62009-10-08 22:34:29410 virtual HistoryService* GetHistoryServiceWithoutCreating() {
411 return profile_->GetHistoryServiceWithoutCreating();
412 }
413
[email protected]0189bc722009-08-28 21:56:48414 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54415 if (sat == EXPLICIT_ACCESS)
[email protected]0189bc722009-08-28 21:56:48416 return profile_->GetFaviconService(sat);
[email protected]7a1251842010-01-30 01:17:54417
418 NOTREACHED() << "This profile is OffTheRecord";
419 return NULL;
[email protected]0189bc722009-08-28 21:56:48420 }
421
[email protected]69c579e2010-04-23 20:01:00422 virtual AutocompleteClassifier* GetAutocompleteClassifier() {
423 return profile_->GetAutocompleteClassifier();
[email protected]90085af02009-10-29 17:53:21424 }
425
initial.commit09911bf2008-07-26 23:55:29426 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54427 if (sat == EXPLICIT_ACCESS)
initial.commit09911bf2008-07-26 23:55:29428 return profile_->GetWebDataService(sat);
[email protected]7a1251842010-01-30 01:17:54429
430 NOTREACHED() << "This profile is OffTheRecord";
431 return NULL;
initial.commit09911bf2008-07-26 23:55:29432 }
433
[email protected]9cddbe372009-10-23 21:23:53434 virtual WebDataService* GetWebDataServiceWithoutCreating() {
435 return profile_->GetWebDataServiceWithoutCreating();
436 }
437
[email protected]e69d33952009-06-03 22:00:41438 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
[email protected]7a1251842010-01-30 01:17:54439 if (sat == EXPLICIT_ACCESS)
[email protected]e69d33952009-06-03 22:00:41440 return profile_->GetPasswordStore(sat);
[email protected]7a1251842010-01-30 01:17:54441
442 NOTREACHED() << "This profile is OffTheRecord";
443 return NULL;
[email protected]e69d33952009-06-03 22:00:41444 }
445
initial.commit09911bf2008-07-26 23:55:29446 virtual PrefService* GetPrefs() {
447 return profile_->GetPrefs();
448 }
449
450 virtual TemplateURLModel* GetTemplateURLModel() {
451 return profile_->GetTemplateURLModel();
452 }
453
454 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
455 return profile_->GetTemplateURLFetcher();
456 }
457
458 virtual DownloadManager* GetDownloadManager() {
459 if (!download_manager_.get()) {
460 scoped_refptr<DownloadManager> dlm(new DownloadManager);
461 dlm->Init(this);
462 download_manager_.swap(dlm);
463 }
464 return download_manager_.get();
465 }
466
467 virtual bool HasCreatedDownloadManager() const {
468 return (download_manager_.get() != NULL);
469 }
470
[email protected]def11712009-11-06 00:42:15471 virtual PersonalDataManager* GetPersonalDataManager() {
472 return NULL;
473 }
474
[email protected]4a190632009-05-09 01:07:42475 virtual void InitThemes() {
[email protected]7a1251842010-01-30 01:17:54476 profile_->InitThemes();
[email protected]4a190632009-05-09 01:07:42477 }
478
479 virtual void SetTheme(Extension* extension) {
[email protected]7a1251842010-01-30 01:17:54480 profile_->SetTheme(extension);
[email protected]4a190632009-05-09 01:07:42481 }
482
[email protected]a5166af62009-07-03 00:42:29483 virtual void SetNativeTheme() {
[email protected]7a1251842010-01-30 01:17:54484 profile_->SetNativeTheme();
[email protected]a5166af62009-07-03 00:42:29485 }
486
[email protected]4a190632009-05-09 01:07:42487 virtual void ClearTheme() {
[email protected]7a1251842010-01-30 01:17:54488 profile_->ClearTheme();
[email protected]4a190632009-05-09 01:07:42489 }
490
[email protected]51c490b2009-08-03 16:34:34491 virtual Extension* GetTheme() {
[email protected]7a1251842010-01-30 01:17:54492 return profile_->GetTheme();
[email protected]51c490b2009-08-03 16:34:34493 }
494
[email protected]5786d3d2009-12-18 00:18:44495 virtual BrowserThemeProvider* GetThemeProvider() {
[email protected]7a1251842010-01-30 01:17:54496 return profile_->GetThemeProvider();
[email protected]4a190632009-05-09 01:07:42497 }
498
[email protected]be180c802009-10-23 06:33:31499 virtual URLRequestContextGetter* GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:29500 return request_context_;
501 }
502
[email protected]be180c802009-10-23 06:33:31503 virtual URLRequestContextGetter* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11504 // In OTR mode, media request context is the same as the original one.
505 return request_context_;
[email protected]e7f29642009-03-02 22:53:18506 }
507
[email protected]be180c802009-10-23 06:33:31508 URLRequestContextGetter* GetRequestContextForExtensions() {
[email protected]55a35692010-02-11 23:25:21509 return GetOriginalProfile()->GetRequestContextForExtensions();
[email protected]47accfd62009-05-14 18:46:21510 }
511
[email protected]db36938c2009-08-19 21:48:42512 virtual net::SSLConfigService* GetSSLConfigService() {
[email protected]7a1251842010-01-30 01:17:54513 return profile_->GetSSLConfigService();
[email protected]db36938c2009-08-19 21:48:42514 }
515
[email protected]e284e6d82010-01-29 19:49:45516 virtual HostContentSettingsMap* GetHostContentSettingsMap() {
[email protected]bd147842010-04-09 15:29:17517 // Retrieve the host content settings map of the parent profile in order to
518 // ensure the preferences have been migrated.
519 profile_->GetHostContentSettingsMap();
520 if (!host_content_settings_map_.get())
521 host_content_settings_map_ = new HostContentSettingsMap(this);
522 return host_content_settings_map_.get();
[email protected]e284e6d82010-01-29 19:49:45523 }
524
[email protected]40bd6582009-12-04 23:49:51525 virtual HostZoomMap* GetHostZoomMap() {
[email protected]c18d4f482010-05-18 21:19:50526 if (!host_zoom_map_)
527 host_zoom_map_ = new HostZoomMap(this);
528 return host_zoom_map_.get();
[email protected]40bd6582009-12-04 23:49:51529 }
530
[email protected]aee541e2010-03-19 01:52:45531 virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() {
532 return profile_->GetGeolocationContentSettingsMap();
533 }
534
[email protected]8b4b84ee2010-05-11 13:08:52535 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() {
536 return profile_->GetGeolocationPermissionContext();
537 }
538
[email protected]8c6335d32010-01-20 09:21:50539 virtual Blacklist* GetPrivacyBlacklist() {
[email protected]7a1251842010-01-30 01:17:54540 return profile_->GetPrivacyBlacklist();
[email protected]eaadd9052009-06-23 18:02:23541 }
542
[email protected]6c32ce72010-03-08 05:18:06543 virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() {
544 return profile_->GetUserStyleSheetWatcher();
545 }
546
[email protected]e5d2f7132010-04-09 18:13:53547 virtual FindBarState* GetFindBarState() {
548 if (!find_bar_state_.get())
549 find_bar_state_.reset(new FindBarState());
550 return find_bar_state_.get();
551 }
552
initial.commit09911bf2008-07-26 23:55:29553 virtual SessionService* GetSessionService() {
554 // Don't save any sessions when off the record.
555 return NULL;
556 }
557
558 virtual void ShutdownSessionService() {
559 // We don't allow a session service, nothing to do.
560 }
561
562 virtual bool HasSessionService() const {
563 // We never have a session service.
564 return false;
565 }
566
initial.commit09911bf2008-07-26 23:55:29567 virtual bool DidLastSessionExitCleanly() {
568 return profile_->DidLastSessionExitCleanly();
569 }
570
[email protected]d8e41ed2008-09-11 15:22:32571 virtual BookmarkModel* GetBookmarkModel() {
572 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29573 }
574
[email protected]4bb336302009-10-12 05:44:26575 virtual DesktopNotificationService* GetDesktopNotificationService() {
[email protected]7d7696c52009-12-01 20:54:58576 if (!desktop_notification_service_.get()) {
577 desktop_notification_service_.reset(new DesktopNotificationService(
578 this, g_browser_process->notification_ui_manager()));
579 }
580 return desktop_notification_service_.get();
[email protected]4bb336302009-10-12 05:44:26581 }
582
[email protected]48352c12009-08-15 01:19:11583 virtual ProfileSyncService* GetProfileSyncService() {
584 return NULL;
[email protected]3a453fa2008-08-15 18:46:34585 }
[email protected]3a453fa2008-08-15 18:46:34586
[email protected]1bd056e2010-04-20 02:03:48587 virtual CloudPrintProxyService* GetCloudPrintProxyService() {
588 return NULL;
589 }
590
initial.commit09911bf2008-07-26 23:55:29591 virtual bool IsSameProfile(Profile* profile) {
[email protected]7a1251842010-01-30 01:17:54592 return (profile == this) || (profile == profile_);
initial.commit09911bf2008-07-26 23:55:29593 }
594
595 virtual Time GetStartTime() const {
596 return start_time_;
597 }
598
599 virtual TabRestoreService* GetTabRestoreService() {
600 return NULL;
601 }
602
[email protected]e7244d82008-10-29 18:13:26603 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41604 }
605
[email protected]85c55dc2009-11-06 03:05:46606 virtual SpellCheckHost* GetSpellCheckHost() {
607 return profile_->GetSpellCheckHost();
608 }
609
610 virtual void ReinitializeSpellCheckHost(bool force) {
611 profile_->ReinitializeSpellCheckHost(force);
612 }
[email protected]85c55dc2009-11-06 03:05:46613
[email protected]3bf335a2009-06-26 20:46:06614 virtual WebKitContext* GetWebKitContext() {
[email protected]c27324b2009-11-19 22:44:29615 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:11616 webkit_context_ = new WebKitContext(this);
[email protected]c27324b2009-11-19 22:44:29617 DCHECK(webkit_context_.get());
618 return webkit_context_.get();
619 }
[email protected]3bf335a2009-06-26 20:46:06620
[email protected]449478302009-06-09 20:04:28621 virtual ThumbnailStore* GetThumbnailStore() {
622 return NULL;
623 }
624
[email protected]523623c2010-05-19 16:03:42625 virtual history::TopSites* GetTopSites() {
626 return NULL;
627 }
628
initial.commit09911bf2008-07-26 23:55:29629 virtual void MarkAsCleanShutdown() {
630 }
631
[email protected]bdbc87c2009-01-25 05:08:54632 virtual void InitExtensions() {
633 NOTREACHED();
634 }
635
[email protected]ea0c98cf2009-06-18 23:02:54636 virtual void InitWebResources() {
637 NOTREACHED();
638 }
639
[email protected]9c8dd902009-11-19 17:50:42640 virtual NTPResourceCache* GetNTPResourceCache() {
641 // Just return the real profile resource cache.
642 return profile_->GetNTPResourceCache();
643 }
644
[email protected]35896a32010-06-09 08:42:51645 virtual FilePath last_selected_directory() {
646 const FilePath& directory = last_selected_directory_;
647 if (directory.empty()) {
648 return profile_->last_selected_directory();
649 }
650 return directory;
651 }
652
653 virtual void set_last_selected_directory(const FilePath& path) {
654 last_selected_directory_ = path;
655 }
656
initial.commit09911bf2008-07-26 23:55:29657 virtual void ExitedOffTheRecordMode() {
658 // Drop our download manager so we forget about all the downloads made
659 // in off-the-record mode.
660 download_manager_ = NULL;
661 }
662
663 virtual void Observe(NotificationType type,
664 const NotificationSource& source,
665 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56666 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29667 // We are only interested in OTR browser closing.
668 if (Source<Browser>(source)->profile() != this)
669 return;
670
671 // Let's check if we still have an Off The Record window opened.
672 // Note that we check against 1 as this notification is sent before the
673 // browser window is actually removed from the list.
674 if (BrowserList::GetBrowserCount(this) <= 1)
675 ExitedOffTheRecordMode();
676 }
677
678 private:
[email protected]88cf3292009-05-22 01:48:43679 NotificationRegistrar registrar_;
680
initial.commit09911bf2008-07-26 23:55:29681 // The real underlying profile.
682 Profile* profile_;
683
[email protected]6ab9b202008-12-23 22:34:50684 // The context to use for requests made from this OTR session.
[email protected]13c30922009-11-19 03:43:19685 scoped_refptr<ChromeURLRequestContextGetter> request_context_;
initial.commit09911bf2008-07-26 23:55:29686
687 // The download manager that only stores downloaded items in memory.
688 scoped_refptr<DownloadManager> download_manager_;
689
[email protected]7d7696c52009-12-01 20:54:58690 // Use a separate desktop notification service for OTR.
691 scoped_ptr<DesktopNotificationService> desktop_notification_service_;
692
[email protected]bd147842010-04-09 15:29:17693 // We use a non-writable content settings map for OTR.
694 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
695
[email protected]c18d4f482010-05-18 21:19:50696 // Use a separate zoom map for OTR.
697 scoped_refptr<HostZoomMap> host_zoom_map_;
698
[email protected]3bf335a2009-06-26 20:46:06699 // Use a special WebKit context for OTR browsing.
700 scoped_refptr<WebKitContext> webkit_context_;
701
[email protected]34cc84f2009-02-13 10:04:35702 // We don't want SSLHostState from the OTR profile to leak back to the main
703 // profile because then the main profile would learn some of the host names
704 // the user visited while OTR.
705 scoped_ptr<SSLHostState> ssl_host_state_;
706
[email protected]e5d2f7132010-04-09 18:13:53707 // Use a separate FindBarState so search terms do not leak back to the main
708 // profile.
709 scoped_ptr<FindBarState> find_bar_state_;
710
[email protected]326e6792009-12-11 21:04:42711 // The TransportSecurityState that only stores enabled sites in memory.
712 scoped_refptr<net::TransportSecurityState>
713 transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23714
initial.commit09911bf2008-07-26 23:55:29715 // Time we were started.
716 Time start_time_;
717
[email protected]2f351cb2009-11-09 23:43:34718 // The main database tracker for this profile.
719 // Should be used only on the file thread.
720 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
721
[email protected]35896a32010-06-09 08:42:51722 FilePath last_selected_directory_;
723
[email protected]90085af02009-10-29 17:53:21724 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
initial.commit09911bf2008-07-26 23:55:29725};
726
[email protected]f7011fcb2009-01-28 21:54:32727ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29728 : path_(path),
[email protected]a6d0f182010-01-12 08:01:44729 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07730 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32731 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57732 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21733 extensions_request_context_(NULL),
[email protected]e284e6d82010-01-29 19:49:45734 host_content_settings_map_(NULL),
[email protected]40bd6582009-12-04 23:49:51735 host_zoom_map_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32736 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48737 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32738 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41739 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32740 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42741 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32742 start_time_(Time::Now()),
[email protected]85c55dc2009-11-06 03:05:46743 spellcheck_host_(NULL),
744 spellcheck_host_ready_(false),
initial.commit09911bf2008-07-26 23:55:29745 shutdown_session_service_(false) {
746 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
747 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14748 create_session_service_timer_.Start(
749 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
750 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54751
[email protected]e7244d82008-10-29 18:13:26752 PrefService* prefs = GetPrefs();
753 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
754 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58755 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58756
[email protected]405a64b2009-09-16 21:03:44757#if defined(OS_MACOSX)
758 // If the profile directory doesn't already have a cache directory and it
759 // is under ~/Library/Application Support, use a suitable cache directory
760 // under ~/Library/Caches. For example, a profile directory of
761 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
762 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
763 // ~/Library/Caches/Google/Chrome/MyProfileName.
764 //
765 // TODO(akalin): Come up with unit tests for this.
[email protected]405a64b2009-09-16 21:03:44766 if (!HasACacheSubdir(path_)) {
767 FilePath app_data_path, user_cache_path;
768 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
[email protected]b70454862009-12-03 01:07:12769 PathService::Get(base::DIR_USER_CACHE, &user_cache_path) &&
[email protected]405a64b2009-09-16 21:03:44770 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
771 base_cache_path_ = user_cache_path;
772 }
773 }
[email protected]9e9b6e8e2009-12-02 08:45:01774#elif defined(OS_POSIX) // Posix minus Mac.
775 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
776 // for a spec on where cache files go. The net effect for most systems is we
777 // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
778 // official builds.
779 if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
780#if defined(GOOGLE_CHROME_BUILD)
781 const char kCacheDir[] = "google-chrome";
[email protected]405a64b2009-09-16 21:03:44782#else
[email protected]9e9b6e8e2009-12-02 08:45:01783 const char kCacheDir[] = "chromium";
784#endif
785 PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
786 base_cache_path_ = base_cache_path_.Append(kCacheDir);
787 if (!file_util::PathExists(base_cache_path_))
788 file_util::CreateDirectory(base_cache_path_);
789 }
[email protected]405a64b2009-09-16 21:03:44790#endif
[email protected]bc96d562009-08-11 18:45:13791 if (base_cache_path_.empty())
792 base_cache_path_ = path_;
793
[email protected]4a190632009-05-09 01:07:42794 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43795 registrar_.Add(this, NotificationType::THEME_INSTALLED,
796 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11797
798 // Listen for bookmark model load, to bootstrap the sync service.
799 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
800 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42801
802 ssl_config_service_manager_.reset(
803 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53804
805#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29806 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53807#endif
[email protected]911f8152010-03-18 16:46:40808
809 pinned_tab_service_.reset(new PinnedTabService(this));
[email protected]a04876b92010-06-11 22:53:43810
811 // Log the profile size after a reasonable startup delay.
812 ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE,
813 new ProfileSizeTask(path_), 112000);
initial.commit09911bf2008-07-26 23:55:29814}
815
[email protected]bdbc87c2009-01-25 05:08:54816void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41817 if (user_script_master_ || extensions_service_)
818 return; // Already initialized.
819
[email protected]bdbc87c2009-01-25 05:08:54820 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]1172ba72010-05-21 22:21:11821 if (command_line->HasSwitch(
822 switches::kEnableExtensionTimelineApi)) {
823 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
824 }
825
826 extension_process_manager_.reset(new ExtensionProcessManager(this));
827 extension_message_service_ = new ExtensionMessageService(this);
828
[email protected]bb28e062009-02-27 17:19:18829 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]faed6e12009-11-24 22:38:36830
831 FilePath script_dir; // Don't look for user scripts in any directory.
832 // TODO(aa): We should just remove this functionality,
833 // since it isn't used anymore.
[email protected]c931db62009-12-23 03:28:51834 user_script_master_ = new UserScriptMaster(script_dir, this);
[email protected]faed6e12009-11-24 22:38:36835
[email protected]894bb502009-05-21 22:39:57836 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23837 this,
838 CommandLine::ForCurrentProcess(),
839 GetPrefs(),
840 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
[email protected]c8b437d2009-07-20 21:26:36841 true);
[email protected]bdbc87c2009-01-25 05:08:54842
[email protected]fee67982010-04-23 17:24:22843 // Register the component extensions.
[email protected]285a0672010-06-11 01:54:52844 typedef std::list<std::pair<std::string, int> > ComponentExtensionList;
845 ComponentExtensionList component_extensions;
[email protected]fee67982010-04-23 17:24:22846
847 // Bookmark manager.
[email protected]285a0672010-06-11 01:54:52848 component_extensions.push_back(
849 std::make_pair("bookmark_manager", IDR_BOOKMARKS_MANIFEST));
[email protected]fee67982010-04-23 17:24:22850
[email protected]abdc9fb52010-05-06 01:44:48851#if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
[email protected]ae90f252010-05-04 18:28:03852 // Chat manager.
853 if (CommandLine::ForCurrentProcess()->HasSwitch(
854 switches::kEnableChatManager)) {
[email protected]285a0672010-06-11 01:54:52855 component_extensions.push_back(
856 std::make_pair("chat_manager", IDR_CHAT_MANAGER_MANIFEST));
[email protected]ae90f252010-05-04 18:28:03857 }
858#endif
859
[email protected]fee67982010-04-23 17:24:22860 // Some sample apps to make our lives easier while we are developing extension
861 // apps. This way we don't have to constantly install these over and over.
[email protected]5e1bf5d2010-05-26 20:52:18862 if (Extension::AppsAreEnabled() && IncludeDefaultApps()) {
[email protected]285a0672010-06-11 01:54:52863 component_extensions.push_back(
864 std::make_pair("gmail_app", IDR_GMAIL_APP_MANIFEST));
865 component_extensions.push_back(
866 std::make_pair("calendar_app", IDR_CALENDAR_APP_MANIFEST));
867 component_extensions.push_back(
868 std::make_pair("docs_app", IDR_DOCS_APP_MANIFEST));
[email protected]fee67982010-04-23 17:24:22869 }
870
[email protected]285a0672010-06-11 01:54:52871 for (ComponentExtensionList::iterator iter = component_extensions.begin();
872 iter != component_extensions.end(); ++iter) {
[email protected]fee67982010-04-23 17:24:22873 FilePath path;
874 if (PathService::Get(chrome::DIR_RESOURCES, &path)) {
875 path = path.AppendASCII(iter->first);
[email protected]1952c7d2010-03-04 23:48:34876 } else {
877 NOTREACHED();
878 }
[email protected]fee67982010-04-23 17:24:22879
880 std::string manifest =
881 ResourceBundle::GetSharedInstance().GetRawDataResource(
882 iter->second).as_string();
883 extensions_service_->register_component_extension(
884 ExtensionsService::ComponentExtensionInfo(manifest, path));
[email protected]1952c7d2010-03-04 23:48:34885 }
886
[email protected]9197f3b2009-06-02 00:49:27887 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12888
889 // Load any extensions specified with --load-extension.
890 if (command_line->HasSwitch(switches::kLoadExtension)) {
[email protected]5d39e3142009-12-17 05:54:10891 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension);
[email protected]919ddc82009-07-15 04:30:12892 extensions_service_->LoadExtension(path);
[email protected]919ddc82009-07-15 04:30:12893 }
[email protected]bdbc87c2009-01-25 05:08:54894}
895
[email protected]ea0c98cf2009-06-18 23:02:54896void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07897 if (web_resource_service_)
898 return; // Already initialized.
899
[email protected]6fad2632009-11-02 05:59:37900 web_resource_service_ = new WebResourceService(this);
[email protected]ea0c98cf2009-06-18 23:02:54901 web_resource_service_->StartAfterDelay();
902}
903
[email protected]9c8dd902009-11-19 17:50:42904NTPResourceCache* ProfileImpl::GetNTPResourceCache() {
905 if (!ntp_resource_cache_.get())
906 ntp_resource_cache_.reset(new NTPResourceCache(this));
907 return ntp_resource_cache_.get();
908}
909
[email protected]35896a32010-06-09 08:42:51910FilePath ProfileImpl::last_selected_directory() {
911 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory);
912}
913
914void ProfileImpl::set_last_selected_directory(const FilePath& path) {
915 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path);
916}
917
initial.commit09911bf2008-07-26 23:55:29918ProfileImpl::~ProfileImpl() {
[email protected]d2879af2010-02-08 16:02:56919 NotificationService::current()->Notify(
920 NotificationType::PROFILE_DESTROYED,
921 Source<Profile>(this),
922 NotificationService::NoDetails());
923
[email protected]169627b2008-12-06 19:30:19924 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29925
926 StopCreateSessionServiceTimer();
927 // TemplateURLModel schedules a task on the WebDataService from its
928 // destructor. Delete it first to ensure the task gets scheduled before we
929 // shut down the database.
930 template_url_model_.reset();
931
932 // The download manager queries the history system and should be deleted
933 // before the history is shutdown so it can properly cancel all requests.
934 download_manager_ = NULL;
935
[email protected]4a190632009-05-09 01:07:42936 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15937 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42938
[email protected]44961292009-07-20 20:03:09939 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
940 // save any new thumbnails to disk and release its reference to the
941 // HistoryService.
942 if (thumbnail_store_.get())
943 thumbnail_store_->Shutdown();
944
[email protected]e7244d82008-10-29 18:13:26945 // Remove pref observers.
946 PrefService* prefs = GetPrefs();
947 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
948 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58949 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26950
[email protected]9c8dd902009-11-19 17:50:42951 // Delete the NTP resource cache so we can unregister pref observers.
952 ntp_resource_cache_.reset();
953
[email protected]48352c12009-08-15 01:19:11954 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34955
initial.commit09911bf2008-07-26 23:55:29956 // Both HistoryService and WebDataService maintain threads for background
957 // processing. Its possible each thread still has tasks on it that have
958 // increased the ref count of the service. In such a situation, when we
959 // decrement the refcount, it won't be 0, and the threads/databases aren't
960 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
961 // databases are properly closed.
962 if (web_data_service_.get())
963 web_data_service_->Shutdown();
964
965 if (history_service_.get())
966 history_service_->Cleanup();
967
[email protected]85c55dc2009-11-06 03:05:46968 if (spellcheck_host_.get())
969 spellcheck_host_->UnsetObserver();
initial.commit09911bf2008-07-26 23:55:29970
[email protected]cfc06f122009-11-16 22:18:55971 if (default_request_context_ == request_context_)
[email protected]47accfd62009-05-14 18:46:21972 default_request_context_ = NULL;
[email protected]6ab9b202008-12-23 22:34:50973
[email protected]47accfd62009-05-14 18:46:21974 CleanupRequestContext(request_context_);
975 CleanupRequestContext(media_request_context_);
976 CleanupRequestContext(extensions_request_context_);
[email protected]1e744f22009-04-08 01:00:17977
[email protected]d8e41ed2008-09-11 15:22:32978 // HistoryService may call into the BookmarkModel, as such we need to
979 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46980 // HistoryService will join with HistoryService's backend thread so that
981 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32982 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46983 history_service_ = NULL;
984 bookmark_bar_model_.reset();
985
[email protected]0189bc722009-08-28 21:56:48986 // FaviconService depends on HistoryServce so make sure we delete
987 // HistoryService first.
988 favicon_service_ = NULL;
989
[email protected]1172ba72010-05-21 22:21:11990 if (extension_message_service_)
991 extension_message_service_->ProfileDestroyed();
[email protected]7120f132009-07-20 21:05:37992
[email protected]6ef635e42009-07-26 06:16:12993 if (extensions_service_)
994 extensions_service_->ProfileDestroyed();
995
[email protected]66da08b2009-10-19 22:27:00996 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29997 MarkAsCleanShutdown();
998}
999
[email protected]4bf6afd2009-10-08 14:00:111000ProfileId ProfileImpl::GetRuntimeId() {
1001 return reinterpret_cast<ProfileId>(this);
1002}
1003
[email protected]f7011fcb2009-01-28 21:54:321004FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:291005 return path_;
1006}
1007
1008bool ProfileImpl::IsOffTheRecord() {
1009 return false;
1010}
1011
1012Profile* ProfileImpl::GetOffTheRecordProfile() {
1013 if (!off_the_record_profile_.get()) {
1014 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
1015 off_the_record_profile_.swap(p);
1016 }
1017 return off_the_record_profile_.get();
1018}
1019
[email protected]860f55492009-03-27 19:50:591020void ProfileImpl::DestroyOffTheRecordProfile() {
1021 off_the_record_profile_.reset();
1022}
1023
initial.commit09911bf2008-07-26 23:55:291024Profile* ProfileImpl::GetOriginalProfile() {
1025 return this;
1026}
1027
[email protected]2f351cb2009-11-09 23:43:341028webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
[email protected]fe615f32010-06-13 09:08:411029 if (!db_tracker_) {
1030 db_tracker_ = new webkit_database::DatabaseTracker(
1031 GetPath(), IsOffTheRecord());
1032 }
[email protected]2f351cb2009-11-09 23:43:341033 return db_tracker_;
1034}
1035
initial.commit09911bf2008-07-26 23:55:291036VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
[email protected]a6d0f182010-01-12 08:01:441037 if (!visited_link_master_.get()) {
1038 scoped_ptr<VisitedLinkMaster> visited_links(
1039 new VisitedLinkMaster(visited_link_event_listener_.get(), this));
1040 if (!visited_links->Init())
1041 return NULL;
1042 visited_link_master_.swap(visited_links);
[email protected]a5fb1c52010-01-12 03:39:531043 }
[email protected]a6d0f182010-01-12 08:01:441044
1045 return visited_link_master_.get();
initial.commit09911bf2008-07-26 23:55:291046}
1047
[email protected]6014d672008-12-05 00:38:251048ExtensionsService* ProfileImpl::GetExtensionsService() {
1049 return extensions_service_.get();
1050}
1051
[email protected]0938d3c2009-01-09 20:37:351052UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:351053 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:251054}
1055
[email protected]89ebc7e2009-08-24 22:11:071056ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
1057 return extension_devtools_manager_.get();
1058}
1059
[email protected]481e1a42009-05-06 20:56:051060ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:271061 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:051062}
1063
[email protected]7120f132009-07-20 21:05:371064ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
1065 return extension_message_service_.get();
1066}
1067
[email protected]34cc84f2009-02-13 10:04:351068SSLHostState* ProfileImpl::GetSSLHostState() {
1069 if (!ssl_host_state_.get())
1070 ssl_host_state_.reset(new SSLHostState());
1071
1072 DCHECK(ssl_host_state_->CalledOnValidThread());
1073 return ssl_host_state_.get();
1074}
1075
[email protected]326e6792009-12-11 21:04:421076net::TransportSecurityState*
1077 ProfileImpl::GetTransportSecurityState() {
1078 if (!transport_security_state_.get()) {
1079 transport_security_state_ = new net::TransportSecurityState();
1080 transport_security_persister_ =
1081 new TransportSecurityPersister();
1082 transport_security_persister_->Initialize(
1083 transport_security_state_.get(), path_);
[email protected]887f80d2009-09-04 16:57:511084 }
[email protected]a9cea7542009-05-20 04:30:231085
[email protected]326e6792009-12-11 21:04:421086 return transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:231087}
1088
initial.commit09911bf2008-07-26 23:55:291089PrefService* ProfileImpl::GetPrefs() {
1090 if (!prefs_.get()) {
[email protected]d8b08c92010-06-07 13:13:281091 prefs_.reset(PrefService::CreatePrefService(GetPrefFilePath()));
initial.commit09911bf2008-07-26 23:55:291092
1093 // The Profile class and ProfileManager class may read some prefs so
1094 // register known prefs as soon as possible.
1095 Profile::RegisterUserPrefs(prefs_.get());
[email protected]9acc48602009-11-30 21:18:511096 browser::RegisterUserPrefs(prefs_.get());
initial.commit09911bf2008-07-26 23:55:291097
1098 // The last session exited cleanly if there is no pref for
1099 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
1100 last_session_exited_cleanly_ =
1101 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
1102 // Mark the session as open.
1103 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
1104 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:361105 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291106 }
1107
1108 return prefs_.get();
1109}
1110
[email protected]f7011fcb2009-01-28 21:54:321111FilePath ProfileImpl::GetPrefFilePath() {
1112 FilePath pref_file_path = path_;
1113 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:291114 return pref_file_path;
1115}
1116
[email protected]be180c802009-10-23 06:33:311117URLRequestContextGetter* ProfileImpl::GetRequestContext() {
initial.commit09911bf2008-07-26 23:55:291118 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:321119 FilePath cookie_path = GetPath();
1120 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:131121 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311122 int max_size;
1123 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:421124
[email protected]405a64b2009-09-16 21:03:441125 cache_path = GetCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311126 request_context_ = ChromeURLRequestContextGetter::CreateOriginal(
1127 this, cookie_path, cache_path, max_size);
initial.commit09911bf2008-07-26 23:55:291128
[email protected]6ab9b202008-12-23 22:34:501129 // The first request context is always a normal (non-OTR) request context.
1130 // Even when Chromium is started in OTR mode, a normal profile is always
1131 // created first.
1132 if (!default_request_context_) {
1133 default_request_context_ = request_context_;
[email protected]be180c802009-10-23 06:33:311134 // TODO(eroman): this isn't terribly useful anymore now that the
1135 // URLRequestContext is constructed by the IO thread...
[email protected]6ab9b202008-12-23 22:34:501136 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561137 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:501138 NotificationService::AllSources(), NotificationService::NoDetails());
1139 }
initial.commit09911bf2008-07-26 23:55:291140 }
1141
1142 return request_context_;
1143}
1144
[email protected]be180c802009-10-23 06:33:311145URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() {
[email protected]e7f29642009-03-02 22:53:181146 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:131147 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:311148 int max_size;
1149 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:141150
[email protected]405a64b2009-09-16 21:03:441151 cache_path = GetMediaCachePath(cache_path);
[email protected]be180c802009-10-23 06:33:311152 media_request_context_ =
1153 ChromeURLRequestContextGetter::CreateOriginalForMedia(
1154 this, cache_path, max_size);
[email protected]e7f29642009-03-02 22:53:181155 }
1156
1157 return media_request_context_;
1158}
1159
[email protected]0189bc722009-08-28 21:56:481160FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
1161 if (!favicon_service_created_) {
1162 favicon_service_created_ = true;
1163 scoped_refptr<FaviconService> service(new FaviconService(this));
1164 favicon_service_.swap(service);
1165 }
1166 return favicon_service_.get();
1167}
1168
[email protected]be180c802009-10-23 06:33:311169URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
[email protected]47accfd62009-05-14 18:46:211170 if (!extensions_request_context_) {
1171 FilePath cookie_path = GetPath();
1172 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1173
1174 extensions_request_context_ =
[email protected]be180c802009-10-23 06:33:311175 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
1176 this, cookie_path);
[email protected]47accfd62009-05-14 18:46:211177 }
1178
1179 return extensions_request_context_;
1180}
1181
[email protected]57a777f72010-03-31 01:09:421182void ProfileImpl::RegisterExtensionWithRequestContexts(
1183 Extension* extension) {
1184 // Notify the default, extension and media contexts on the IO thread.
1185 PostExtensionLoadedToContextGetter(
1186 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1187 extension);
1188 PostExtensionLoadedToContextGetter(
1189 static_cast<ChromeURLRequestContextGetter*>(
1190 GetRequestContextForExtensions()),
1191 extension);
1192 PostExtensionLoadedToContextGetter(
1193 static_cast<ChromeURLRequestContextGetter*>(
1194 GetRequestContextForMedia()),
1195 extension);
1196}
1197
1198void ProfileImpl::UnregisterExtensionWithRequestContexts(
1199 Extension* extension) {
1200 // Notify the default, extension and media contexts on the IO thread.
1201 PostExtensionUnloadedToContextGetter(
1202 static_cast<ChromeURLRequestContextGetter*>(GetRequestContext()),
1203 extension);
1204 PostExtensionUnloadedToContextGetter(
1205 static_cast<ChromeURLRequestContextGetter*>(
1206 GetRequestContextForExtensions()),
1207 extension);
1208 PostExtensionUnloadedToContextGetter(
1209 static_cast<ChromeURLRequestContextGetter*>(
1210 GetRequestContextForMedia()),
1211 extension);
1212}
1213
[email protected]db36938c2009-08-19 21:48:421214net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1215 return ssl_config_service_manager_->Get();
1216}
1217
[email protected]e284e6d82010-01-29 19:49:451218HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
1219 if (!host_content_settings_map_.get())
[email protected]08bc6302010-01-30 02:53:391220 host_content_settings_map_ = new HostContentSettingsMap(this);
[email protected]e284e6d82010-01-29 19:49:451221 return host_content_settings_map_.get();
1222}
1223
[email protected]40bd6582009-12-04 23:49:511224HostZoomMap* ProfileImpl::GetHostZoomMap() {
1225 if (!host_zoom_map_)
1226 host_zoom_map_ = new HostZoomMap(this);
1227 return host_zoom_map_.get();
1228}
1229
[email protected]aee541e2010-03-19 01:52:451230GeolocationContentSettingsMap* ProfileImpl::GetGeolocationContentSettingsMap() {
1231 if (!geolocation_content_settings_map_.get())
1232 geolocation_content_settings_map_ = new GeolocationContentSettingsMap(this);
1233 return geolocation_content_settings_map_.get();
1234}
1235
[email protected]8b4b84ee2010-05-11 13:08:521236GeolocationPermissionContext* ProfileImpl::GetGeolocationPermissionContext() {
1237 if (!geolocation_permission_context_.get())
1238 geolocation_permission_context_ = new GeolocationPermissionContext(this);
1239 return geolocation_permission_context_.get();
1240}
1241
[email protected]8c6335d32010-01-20 09:21:501242Blacklist* ProfileImpl::GetPrivacyBlacklist() {
[email protected]a307e31e2009-11-30 16:11:271243 if (!CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]c37f8b42010-01-23 16:22:141244 switches::kEnablePrivacyBlacklists))
[email protected]a307e31e2009-11-30 16:11:271245 return NULL;
[email protected]c37f8b42010-01-23 16:22:141246 if (!privacy_blacklist_.get())
[email protected]7a1251842010-01-30 01:17:541247 privacy_blacklist_ = new Blacklist(GetPrefs());
[email protected]8c6335d32010-01-20 09:21:501248 return privacy_blacklist_.get();
[email protected]eaadd9052009-06-23 18:02:231249}
1250
[email protected]6c32ce72010-03-08 05:18:061251UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
1252 if (!user_style_sheet_watcher_.get()) {
1253 user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath());
1254 user_style_sheet_watcher_->Init();
1255 }
1256 return user_style_sheet_watcher_.get();
1257}
1258
[email protected]e5d2f7132010-04-09 18:13:531259FindBarState* ProfileImpl::GetFindBarState() {
1260 if (!find_bar_state_.get()) {
1261 find_bar_state_.reset(new FindBarState());
1262 }
1263 return find_bar_state_.get();
1264}
1265
initial.commit09911bf2008-07-26 23:55:291266HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1267 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461268 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291269 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321270 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291271 return NULL;
1272 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291273
1274 // Send out the notification that the history service was created.
1275 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561276 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291277 Details<HistoryService>(history_service_.get()));
1278 }
1279 return history_service_.get();
1280}
1281
[email protected]0850fa62009-10-08 22:34:291282HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1283 return history_service_.get();
1284}
1285
initial.commit09911bf2008-07-26 23:55:291286TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1287 if (!template_url_model_.get())
1288 template_url_model_.reset(new TemplateURLModel(this));
1289 return template_url_model_.get();
1290}
1291
1292TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1293 if (!template_url_fetcher_.get())
1294 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1295 return template_url_fetcher_.get();
1296}
1297
[email protected]69c579e2010-04-23 20:01:001298AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
1299 if (!autocomplete_classifier_.get())
1300 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
1301 return autocomplete_classifier_.get();
[email protected]90085af02009-10-29 17:53:211302}
1303
initial.commit09911bf2008-07-26 23:55:291304WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1305 if (!created_web_data_service_)
1306 CreateWebDataService();
1307 return web_data_service_.get();
1308}
1309
[email protected]9cddbe372009-10-23 21:23:531310WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
1311 return web_data_service_.get();
1312}
1313
initial.commit09911bf2008-07-26 23:55:291314void ProfileImpl::CreateWebDataService() {
1315 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1316 created_web_data_service_ = true;
1317 scoped_refptr<WebDataService> wds(new WebDataService());
1318 if (!wds->Init(GetPath()))
1319 return;
1320 web_data_service_.swap(wds);
1321}
1322
[email protected]e69d33952009-06-03 22:00:411323PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1324 if (!created_password_store_)
1325 CreatePasswordStore();
1326 return password_store_.get();
1327}
1328
1329void ProfileImpl::CreatePasswordStore() {
1330 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1331 created_password_store_ = true;
1332 scoped_refptr<PasswordStore> ps;
[email protected]e0411ae52009-06-30 23:59:171333 FilePath login_db_file_path = GetPath();
1334 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
[email protected]ec44cd52010-04-05 22:30:471335 LoginDatabase* login_db = new LoginDatabase();
[email protected]e0411ae52009-06-30 23:59:171336 if (!login_db->Init(login_db_file_path)) {
1337 LOG(ERROR) << "Could not initialize login database.";
1338 delete login_db;
1339 return;
1340 }
[email protected]e8380f52010-04-30 16:39:421341#if defined(OS_WIN)
1342 ps = new PasswordStoreWin(login_db, this,
1343 GetWebDataService(Profile::IMPLICIT_ACCESS));
1344#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171345 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]753efc42010-03-09 19:52:161346#elif defined(OS_POSIX)
1347 // TODO(evanm): implement "native" password management.
1348 // This bug describes the issues.
1349 // http://code.google.com/p/chromium/issues/detail?id=12351
[email protected]e8380f52010-04-30 16:39:421350 ps = new PasswordStoreDefault(login_db, this,
1351 GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]e69d33952009-06-03 22:00:411352#else
1353 NOTIMPLEMENTED();
1354#endif
[email protected]e8380f52010-04-30 16:39:421355 if (!ps)
1356 delete login_db;
1357
[email protected]e69d33952009-06-03 22:00:411358 if (!ps || !ps->Init()) {
[email protected]e8380f52010-04-30 16:39:421359 NOTREACHED() << "Could not initialise password manager";
1360 return;
[email protected]e69d33952009-06-03 22:00:411361 }
1362 password_store_.swap(ps);
1363}
1364
initial.commit09911bf2008-07-26 23:55:291365DownloadManager* ProfileImpl::GetDownloadManager() {
1366 if (!created_download_manager_) {
1367 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1368 dlm->Init(this);
1369 created_download_manager_ = true;
1370 download_manager_.swap(dlm);
1371 }
1372 return download_manager_.get();
1373}
1374
1375bool ProfileImpl::HasCreatedDownloadManager() const {
1376 return created_download_manager_;
1377}
1378
[email protected]def11712009-11-06 00:42:151379PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
1380 if (!personal_data_manager_.get()) {
[email protected]36c1ff9fd2010-06-03 20:08:591381 personal_data_manager_ = new PersonalDataManager();
[email protected]e0976a72010-04-02 01:25:241382 personal_data_manager_->Init(this);
[email protected]def11712009-11-06 00:42:151383 }
1384 return personal_data_manager_.get();
1385}
1386
[email protected]4a190632009-05-09 01:07:421387void ProfileImpl::InitThemes() {
1388 if (!created_theme_provider_) {
[email protected]753efc42010-03-09 19:52:161389#if defined(TOOLKIT_USES_GTK)
[email protected]761962c2009-09-25 00:18:151390 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291391#else
[email protected]761962c2009-09-25 00:18:151392 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291393#endif
[email protected]761962c2009-09-25 00:18:151394 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421395 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421396 }
1397}
1398
1399void ProfileImpl::SetTheme(Extension* extension) {
1400 InitThemes();
1401 theme_provider_.get()->SetTheme(extension);
1402}
1403
[email protected]a5166af62009-07-03 00:42:291404void ProfileImpl::SetNativeTheme() {
1405 InitThemes();
1406 theme_provider_.get()->SetNativeTheme();
1407}
1408
[email protected]4a190632009-05-09 01:07:421409void ProfileImpl::ClearTheme() {
1410 InitThemes();
1411 theme_provider_.get()->UseDefaultTheme();
1412}
1413
[email protected]51c490b2009-08-03 16:34:341414Extension* ProfileImpl::GetTheme() {
1415 InitThemes();
1416
1417 std::string id = theme_provider_.get()->GetThemeID();
1418 if (id == BrowserThemeProvider::kDefaultThemeID)
1419 return NULL;
1420
[email protected]61b411612009-11-10 23:17:411421 return extensions_service_->GetExtensionById(id, false);
[email protected]51c490b2009-08-03 16:34:341422}
1423
[email protected]5786d3d2009-12-18 00:18:441424BrowserThemeProvider* ProfileImpl::GetThemeProvider() {
[email protected]4a190632009-05-09 01:07:421425 InitThemes();
1426 return theme_provider_.get();
1427}
1428
initial.commit09911bf2008-07-26 23:55:291429SessionService* ProfileImpl::GetSessionService() {
1430 if (!session_service_.get() && !shutdown_session_service_) {
1431 session_service_ = new SessionService(this);
1432 session_service_->ResetFromCurrentBrowsers();
1433 }
1434 return session_service_.get();
1435}
1436
1437void ProfileImpl::ShutdownSessionService() {
1438 if (shutdown_session_service_)
1439 return;
1440
1441 // We're about to exit, force creation of the session service if it hasn't
1442 // been created yet. We do this to ensure session state matches the point in
1443 // time the user exited.
1444 GetSessionService();
1445 shutdown_session_service_ = true;
1446 session_service_ = NULL;
1447}
1448
1449bool ProfileImpl::HasSessionService() const {
1450 return (session_service_.get() != NULL);
1451}
1452
initial.commit09911bf2008-07-26 23:55:291453bool ProfileImpl::DidLastSessionExitCleanly() {
1454 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1455 // it to be set by asking for the prefs.
1456 GetPrefs();
1457 return last_session_exited_cleanly_;
1458}
1459
[email protected]d8e41ed2008-09-11 15:22:321460BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461461 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321462 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461463 bookmark_bar_model_->Load();
1464 }
initial.commit09911bf2008-07-26 23:55:291465 return bookmark_bar_model_.get();
1466}
1467
1468bool ProfileImpl::IsSameProfile(Profile* profile) {
1469 if (profile == static_cast<Profile*>(this))
1470 return true;
1471 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1472 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1473}
1474
1475Time ProfileImpl::GetStartTime() const {
1476 return start_time_;
1477}
1478
1479TabRestoreService* ProfileImpl::GetTabRestoreService() {
1480 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191481 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291482 return tab_restore_service_.get();
1483}
1484
[email protected]449478302009-06-09 20:04:281485ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1486 if (!thumbnail_store_.get()) {
1487 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251488 thumbnail_store_->Init(
1489 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281490 }
1491 return thumbnail_store_.get();
1492}
1493
[email protected]523623c2010-05-19 16:03:421494history::TopSites* ProfileImpl::GetTopSites() {
1495 if (!top_sites_.get()) {
1496 top_sites_ = new history::TopSites(this);
[email protected]f3954042010-06-09 18:37:491497 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename));
[email protected]523623c2010-05-19 16:03:421498 }
1499 return top_sites_;
1500}
1501
initial.commit09911bf2008-07-26 23:55:291502void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191503 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291504}
1505
[email protected]85c55dc2009-11-06 03:05:461506SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1507 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1508}
1509
1510void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1511 // If we are already loading the spellchecker, and this is just a hint to
1512 // load the spellchecker, do nothing.
1513 if (!force && spellcheck_host_.get())
1514 return;
1515
[email protected]f41301e2009-11-16 21:30:071516 spellcheck_host_ready_ = false;
1517
[email protected]85c55dc2009-11-06 03:05:461518 bool notify = false;
1519 if (spellcheck_host_.get()) {
1520 spellcheck_host_->UnsetObserver();
[email protected]71c012a2009-11-10 01:33:051521 spellcheck_host_ = NULL;
[email protected]85c55dc2009-11-06 03:05:461522 notify = true;
1523 }
1524
1525 PrefService* prefs = GetPrefs();
1526 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1527 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1528 spellcheck_host_ = new SpellCheckHost(this,
1529 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1530 GetRequestContext());
[email protected]f41301e2009-11-16 21:30:071531 spellcheck_host_->Initialize();
[email protected]85c55dc2009-11-06 03:05:461532 } else if (notify) {
1533 // The spellchecker has been disabled.
1534 SpellCheckHostInitialized();
1535 }
1536}
1537
1538void ProfileImpl::SpellCheckHostInitialized() {
[email protected]cb6037d2009-11-16 22:55:171539 spellcheck_host_ready_ = spellcheck_host_ &&
[email protected]c27324b2009-11-19 22:44:291540 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1541 spellcheck_host_->use_platform_spellchecker());
[email protected]85c55dc2009-11-06 03:05:461542 NotificationService::current()->Notify(
1543 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1544 Source<Profile>(this), NotificationService::NoDetails());
1545}
initial.commit09911bf2008-07-26 23:55:291546
[email protected]3bf335a2009-06-26 20:46:061547WebKitContext* ProfileImpl::GetWebKitContext() {
1548 if (!webkit_context_.get())
[email protected]70c19a932010-05-14 12:59:111549 webkit_context_ = new WebKitContext(this);
[email protected]3bf335a2009-06-26 20:46:061550 DCHECK(webkit_context_.get());
1551 return webkit_context_.get();
1552}
1553
[email protected]4bb336302009-10-12 05:44:261554DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1555 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1556 if (!desktop_notification_service_.get()) {
[email protected]4bb336302009-10-12 05:44:261557 desktop_notification_service_.reset(new DesktopNotificationService(
[email protected]29672ab2009-10-30 03:44:031558 this, g_browser_process->notification_ui_manager()));
[email protected]4bb336302009-10-12 05:44:261559 }
[email protected]4bb336302009-10-12 05:44:261560 return desktop_notification_service_.get();
1561}
1562
initial.commit09911bf2008-07-26 23:55:291563void ProfileImpl::MarkAsCleanShutdown() {
1564 if (prefs_.get()) {
1565 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1566 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1567
1568 // NOTE: If you change what thread this writes on, be sure and update
1569 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361570 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291571 }
1572}
1573
[email protected]e7244d82008-10-29 18:13:261574void ProfileImpl::Observe(NotificationType type,
1575 const NotificationSource& source,
1576 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561577 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261578 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1579 PrefService* prefs = Source<PrefService>(source).ptr();
1580 DCHECK(pref_name_in && prefs);
1581 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]85c55dc2009-11-06 03:05:461582 *pref_name_in == prefs::kEnableSpellCheck) {
[email protected]85c55dc2009-11-06 03:05:461583 ReinitializeSpellCheckHost(true);
[email protected]c27324b2009-11-19 22:44:291584 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1585 NotificationService::current()->Notify(
1586 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1587 Source<Profile>(this), NotificationService::NoDetails());
[email protected]e7244d82008-10-29 18:13:261588 }
[email protected]4a190632009-05-09 01:07:421589 } else if (NotificationType::THEME_INSTALLED == type) {
1590 Extension* extension = Details<Extension>(details).ptr();
1591 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111592 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1593 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1594 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1595 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261596 }
1597}
1598
initial.commit09911bf2008-07-26 23:55:291599void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141600 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291601}
[email protected]3a453fa2008-08-15 18:46:341602
[email protected]48352c12009-08-15 01:19:111603ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]eec3bcfa2009-11-12 17:23:431604 if (!ProfileSyncService::IsSyncEnabled()) {
1605 return NULL;
[email protected]7367f1a2009-10-10 01:09:441606 }
[email protected]eec3bcfa2009-11-12 17:23:431607 if (!sync_service_.get())
1608 InitSyncService();
1609 return sync_service_.get();
[email protected]48352c12009-08-15 01:19:111610}
1611
[email protected]1bd056e2010-04-20 02:03:481612CloudPrintProxyService* ProfileImpl::GetCloudPrintProxyService() {
1613 if (!cloud_print_proxy_service_.get())
1614 InitCloudPrintProxyService();
1615 return cloud_print_proxy_service_.get();
1616}
1617
[email protected]48352c12009-08-15 01:19:111618void ProfileImpl::InitSyncService() {
[email protected]82d9d2952010-05-15 00:36:161619 network_change_notifier_thread_.reset(
1620 new NetworkChangeNotifierIOThread(g_browser_process->io_thread()));
[email protected]4aea04a2010-02-10 20:13:431621 profile_sync_factory_.reset(
1622 new ProfileSyncFactoryImpl(this,
[email protected]82d9d2952010-05-15 00:36:161623 network_change_notifier_thread_.get(),
[email protected]4aea04a2010-02-10 20:13:431624 CommandLine::ForCurrentProcess()));
1625 sync_service_.reset(
1626 profile_sync_factory_->CreateProfileSyncService());
[email protected]48352c12009-08-15 01:19:111627 sync_service_->Initialize();
[email protected]48352c12009-08-15 01:19:111628}
[email protected]1bd056e2010-04-20 02:03:481629
1630void ProfileImpl::InitCloudPrintProxyService() {
1631 cloud_print_proxy_service_.reset(new CloudPrintProxyService(this));
1632 cloud_print_proxy_service_->Initialize();
1633}