blob: 8e3e43e925dd64d2887397b8f05af93a3e3ad7f2 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// 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]2735e3692009-09-25 18:19:397#include "app/theme_provider.h"
initial.commit09911bf2008-07-26 23:55:298#include "base/command_line.h"
[email protected]04fba9a92008-10-28 17:25:259#include "base/file_path.h"
[email protected]405a64b2009-09-16 21:03:4410#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/path_service.h"
12#include "base/scoped_ptr.h"
13#include "base/string_util.h"
[email protected]a9afddb2009-02-12 17:49:4214#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:2915#include "chrome/browser/browser_list.h"
16#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0217#include "chrome/browser/browser_theme_provider.h"
[email protected]b7f05882009-02-22 01:21:5618#include "chrome/browser/download/download_manager.h"
[email protected]89ebc7e2009-08-24 22:11:0719#include "chrome/browser/extensions/extension_devtools_manager.h"
[email protected]7120f132009-07-20 21:05:3720#include "chrome/browser/extensions/extension_message_service.h"
[email protected]481e1a42009-05-06 20:56:0521#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]6014d672008-12-05 00:38:2522#include "chrome/browser/extensions/extensions_service.h"
[email protected]0938d3c2009-01-09 20:37:3523#include "chrome/browser/extensions/user_script_master.h"
[email protected]0189bc722009-08-28 21:56:4824#include "chrome/browser/favicon_service.h"
[email protected]77f6fb432009-09-05 14:21:0925#include "chrome/browser/strict_transport_security_persister.h"
[email protected]a9afddb2009-02-12 17:49:4226#include "chrome/browser/history/history.h"
[email protected]3bf335a2009-06-26 20:46:0627#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]6ab9b202008-12-23 22:34:5028#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]db36938c2009-08-19 21:48:4229#include "chrome/browser/net/ssl_config_service_manager.h"
[email protected]4bb336302009-10-12 05:44:2630#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]e69d33952009-06-03 22:00:4131#include "chrome/browser/password_manager/password_store_default.h"
[email protected]eaadd9052009-06-23 18:02:2332#include "chrome/browser/privacy_blacklist/blacklist.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2634#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]1132436e2009-04-08 20:06:3335#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]f63ae312009-02-04 17:58:4636#include "chrome/browser/search_engines/template_url_model.h"
[email protected]85e921fb82009-02-11 23:19:4437#include "chrome/browser/sessions/session_service.h"
[email protected]bd580a252009-02-12 01:16:3038#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]f0a644292009-02-25 23:32:4739#include "chrome/browser/spellchecker.h"
[email protected]1132436e2009-04-08 20:06:3340#include "chrome/browser/ssl/ssl_host_state.h"
[email protected]48352c12009-08-15 01:19:1141#include "chrome/browser/sync/profile_sync_service.h"
[email protected]449478302009-06-09 20:04:2842#include "chrome/browser/thumbnail_store.h"
initial.commit09911bf2008-07-26 23:55:2943#include "chrome/browser/visitedlink_master.h"
[email protected]3e90d4a2009-07-03 17:38:3944#include "chrome/browser/visitedlink_event_listener.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/browser/webdata/web_data_service.h"
[email protected]23f1ef12009-09-01 22:30:3046#include "chrome/common/appcache/chrome_appcache_service.h"
initial.commit09911bf2008-07-26 23:55:2947#include "chrome/common/chrome_constants.h"
48#include "chrome/common/chrome_paths.h"
49#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5850#include "chrome/common/extensions/extension_error_reporter.h"
initial.commit09911bf2008-07-26 23:55:2951#include "chrome/common/notification_service.h"
52#include "chrome/common/pref_names.h"
[email protected]f7011fcb2009-01-28 21:54:3253#include "chrome/common/render_messages.h"
[email protected]f90f5c512009-02-18 19:10:5854#include "grit/locale_settings.h"
[email protected]77f6fb432009-09-05 14:21:0955#include "net/base/strict_transport_security_state.h"
initial.commit09911bf2008-07-26 23:55:2956
[email protected]a5166af62009-07-03 00:42:2957#if defined(OS_LINUX)
[email protected]2a0c0a52009-07-31 07:51:3258#include "net/ocsp/nss_ocsp.h"
[email protected]a5166af62009-07-03 00:42:2959#include "chrome/browser/gtk/gtk_theme_provider.h"
60#endif
61
[email protected]2627431b2009-09-15 20:21:5362#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:2963#include "chrome/browser/chromeos/preferences.h"
[email protected]2627431b2009-09-15 20:21:5364#endif
65
[email protected]e1acf6f2008-10-27 20:43:3366using base::Time;
67using base::TimeDelta;
68
[email protected]e5642992009-06-26 23:06:3169namespace {
70
initial.commit09911bf2008-07-26 23:55:2971// Delay, in milliseconds, before we explicitly create the SessionService.
72static const int kCreateSessionServiceDelayMS = 500;
73
[email protected]e5642992009-06-26 23:06:3174enum ContextType {
75 kNormalContext,
76 kMediaContext
77};
78
79// Gets the cache parameters from the command line. |type| is the type of
80// request context that we need, |cache_path| will be set to the user provided
81// path, or will not be touched if there is not an argument. |max_size| will
82// be the user provided value or zero by default.
83void GetCacheParameters(ContextType type, FilePath* cache_path,
84 int* max_size) {
85 DCHECK(cache_path);
86 DCHECK(max_size);
87
88 // Override the cache location if specified by the user.
89 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
90 switches::kDiskCacheDir));
91
92 if (!user_path.empty()) {
93 *cache_path = FilePath::FromWStringHack(user_path);
94 }
95
[email protected]b7e0a2a2009-10-13 02:07:2596 const char* arg = kNormalContext == type ? switches::kDiskCacheSize :
97 switches::kMediaCacheSize;
[email protected]e5642992009-06-26 23:06:3198 std::string value =
[email protected]b7e0a2a2009-10-13 02:07:2599 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(arg);
[email protected]e5642992009-06-26 23:06:31100
101 // By default we let the cache determine the right size.
102 *max_size = 0;
103 if (!StringToInt(value, max_size)) {
104 *max_size = 0;
105 } else if (max_size < 0) {
106 *max_size = 0;
107 }
108}
109
[email protected]405a64b2009-09-16 21:03:44110FilePath GetCachePath(const FilePath& base) {
111 return base.Append(chrome::kCacheDirname);
112}
113
114FilePath GetMediaCachePath(const FilePath& base) {
115 return base.Append(chrome::kMediaCacheDirname);
116}
117
118bool HasACacheSubdir(const FilePath &dir) {
119 return file_util::PathExists(GetCachePath(dir)) ||
120 file_util::PathExists(GetMediaCachePath(dir));
121}
122
[email protected]e5642992009-06-26 23:06:31123} // namespace
124
initial.commit09911bf2008-07-26 23:55:29125// A pointer to the request context for the default profile. See comments on
126// Profile::GetDefaultRequestContext.
127URLRequestContext* Profile::default_request_context_;
128
[email protected]47accfd62009-05-14 18:46:21129static void CleanupRequestContext(ChromeURLRequestContext* context) {
130 if (context) {
131 context->CleanupOnUIThread();
132
133 // Clean up request context on IO thread.
134 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE,
135 context);
136 }
137}
138
[email protected]e2fc3d22009-09-22 19:50:31139static void CleanupAppCacheService(ChromeAppCacheService* appcache_service) {
140 if (appcache_service) {
141 // The I/O thread may be NULL during testing.
142 base::Thread* io_thread = g_browser_process->io_thread();
[email protected]23f1ef12009-09-01 22:30:30143 if (io_thread)
[email protected]e2fc3d22009-09-22 19:50:31144 io_thread->message_loop()->ReleaseSoon(FROM_HERE, appcache_service);
[email protected]23f1ef12009-09-01 22:30:30145 else
[email protected]e2fc3d22009-09-22 19:50:31146 appcache_service->Release();
[email protected]23f1ef12009-09-01 22:30:30147 }
148}
149
[email protected]34cc84f2009-02-13 10:04:35150// static
[email protected]4bf6afd2009-10-08 14:00:11151const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
152
153// static
initial.commit09911bf2008-07-26 23:55:29154void Profile::RegisterUserPrefs(PrefService* prefs) {
[email protected]430d3f72008-10-27 17:56:55155 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
initial.commit09911bf2008-07-26 23:55:29156 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
157 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
[email protected]74c8b422009-03-11 00:34:12158 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
[email protected]e7244d82008-10-29 18:13:26159 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
160 IDS_SPELLCHECK_DICTIONARY);
161 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
[email protected]154a4332009-06-03 20:20:58162 prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
[email protected]f93fe782009-02-19 01:26:13163 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
[email protected]a5166af62009-07-03 00:42:29164#if defined(OS_LINUX)
165 prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
166#endif
[email protected]51c490b2009-08-03 16:34:34167 prefs->RegisterStringPref(prefs::kCurrentThemeID,
168 UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
[email protected]4a190632009-05-09 01:07:42169 prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
170 prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
171 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
[email protected]7895ea22009-06-02 20:53:50172 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
[email protected]6d60703b2009-08-29 01:29:23173 prefs->RegisterBooleanPref(prefs::kDisableExtensions, false);
initial.commit09911bf2008-07-26 23:55:29174}
175
[email protected]34cc84f2009-02-13 10:04:35176// static
[email protected]f7011fcb2009-01-28 21:54:32177Profile* Profile::CreateProfile(const FilePath& path) {
initial.commit09911bf2008-07-26 23:55:29178 return new ProfileImpl(path);
179}
180
[email protected]34cc84f2009-02-13 10:04:35181// static
initial.commit09911bf2008-07-26 23:55:29182URLRequestContext* Profile::GetDefaultRequestContext() {
183 return default_request_context_;
184}
185
[email protected]e69d33952009-06-03 22:00:41186#if defined(OS_LINUX)
187// Temporarily disabled while we figure some stuff out.
188// http://code.google.com/p/chromium/issues/detail?id=12351
189// #include "chrome/browser/password_manager/password_store_gnome.h"
190// #include "chrome/browser/password_manager/password_store_kwallet.h"
191#elif defined(OS_WIN)
192#include "chrome/browser/password_manager/password_store_win.h"
[email protected]034eba52009-06-03 22:50:56193#elif defined(OS_MACOSX)
194#include "chrome/browser/keychain_mac.h"
[email protected]e0411ae52009-06-30 23:59:17195#include "chrome/browser/password_manager/login_database_mac.h"
[email protected]034eba52009-06-03 22:50:56196#include "chrome/browser/password_manager/password_store_mac.h"
[email protected]e69d33952009-06-03 22:00:41197#endif
initial.commit09911bf2008-07-26 23:55:29198
initial.commit09911bf2008-07-26 23:55:29199////////////////////////////////////////////////////////////////////////////////
200//
201// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
[email protected]4a190632009-05-09 01:07:42202// to make it suitable for the off the record mode.
initial.commit09911bf2008-07-26 23:55:29203//
204////////////////////////////////////////////////////////////////////////////////
205class OffTheRecordProfileImpl : public Profile,
206 public NotificationObserver {
207 public:
208 explicit OffTheRecordProfileImpl(Profile* real_profile)
209 : profile_(real_profile),
[email protected]47accfd62009-05-14 18:46:21210 extensions_request_context_(NULL),
initial.commit09911bf2008-07-26 23:55:29211 start_time_(Time::Now()) {
[email protected]e2fc3d22009-09-22 19:50:31212 // Created here but lazily inititialized later, finally released on
213 // on the io thread, see CleanupAppCacheService.
214 appcache_service_ = new ChromeAppCacheService();
215 appcache_service_->AddRef();
216
217 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(
218 this, appcache_service_);
initial.commit09911bf2008-07-26 23:55:29219 request_context_->AddRef();
[email protected]481e1a42009-05-06 20:56:05220
initial.commit09911bf2008-07-26 23:55:29221 // Register for browser close notifications so we can detect when the last
222 // off-the-record window is closed, in which case we can clean our states
223 // (cookies, downloads...).
[email protected]88cf3292009-05-22 01:48:43224 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
225 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29226 }
227
228 virtual ~OffTheRecordProfileImpl() {
[email protected]47accfd62009-05-14 18:46:21229 CleanupRequestContext(request_context_);
[email protected]47accfd62009-05-14 18:46:21230 CleanupRequestContext(extensions_request_context_);
[email protected]e2fc3d22009-09-22 19:50:31231 CleanupAppCacheService(appcache_service_);
initial.commit09911bf2008-07-26 23:55:29232 }
233
[email protected]4bf6afd2009-10-08 14:00:11234 virtual ProfileId GetRuntimeId() {
235 return reinterpret_cast<ProfileId>(this);
236 }
237
[email protected]f7011fcb2009-01-28 21:54:32238 virtual FilePath GetPath() { return profile_->GetPath(); }
initial.commit09911bf2008-07-26 23:55:29239
240 virtual bool IsOffTheRecord() {
241 return true;
242 }
243
244 virtual Profile* GetOffTheRecordProfile() {
245 return this;
246 }
247
[email protected]860f55492009-03-27 19:50:59248 virtual void DestroyOffTheRecordProfile() {
249 // Suicide is bad!
250 NOTREACHED();
251 }
252
initial.commit09911bf2008-07-26 23:55:29253 virtual Profile* GetOriginalProfile() {
254 return profile_;
255 }
256
[email protected]23f1ef12009-09-01 22:30:30257 virtual ChromeAppCacheService* GetAppCacheService() {
[email protected]e2fc3d22009-09-22 19:50:31258 DCHECK(request_context_); // should be created in ctor
259 if (!appcache_service_->is_initialized())
260 appcache_service_->InitializeOnUIThread(GetPath(), true);
261 return appcache_service_;
[email protected]23f1ef12009-09-01 22:30:30262 }
263
initial.commit09911bf2008-07-26 23:55:29264 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
[email protected]7fb6c862009-03-13 02:51:49265 // We don't provide access to the VisitedLinkMaster when we're OffTheRecord
266 // because we don't want to leak the sites that the user has visited before.
267 return NULL;
initial.commit09911bf2008-07-26 23:55:29268 }
269
[email protected]6014d672008-12-05 00:38:25270 virtual ExtensionsService* GetExtensionsService() {
[email protected]1bd54132009-06-11 00:05:34271 return NULL;
[email protected]6014d672008-12-05 00:38:25272 }
273
[email protected]0938d3c2009-01-09 20:37:35274 virtual UserScriptMaster* GetUserScriptMaster() {
275 return profile_->GetUserScriptMaster();
[email protected]04fba9a92008-10-28 17:25:25276 }
277
[email protected]89ebc7e2009-08-24 22:11:07278 virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
279 return NULL;
280 }
281
[email protected]481e1a42009-05-06 20:56:05282 virtual ExtensionProcessManager* GetExtensionProcessManager() {
[email protected]1bd54132009-06-11 00:05:34283 return NULL;
[email protected]481e1a42009-05-06 20:56:05284 }
285
[email protected]7120f132009-07-20 21:05:37286 virtual ExtensionMessageService* GetExtensionMessageService() {
287 return NULL;
288 }
289
[email protected]34cc84f2009-02-13 10:04:35290 virtual SSLHostState* GetSSLHostState() {
291 if (!ssl_host_state_.get())
292 ssl_host_state_.reset(new SSLHostState());
293
294 DCHECK(ssl_host_state_->CalledOnValidThread());
295 return ssl_host_state_.get();
296 }
297
[email protected]77f6fb432009-09-05 14:21:09298 virtual net::StrictTransportSecurityState* GetStrictTransportSecurityState() {
299 if (!strict_transport_security_state_.get()) {
300 strict_transport_security_state_ =
301 new net::StrictTransportSecurityState();
302 }
[email protected]a9cea7542009-05-20 04:30:23303
[email protected]77f6fb432009-09-05 14:21:09304 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23305 }
306
initial.commit09911bf2008-07-26 23:55:29307 virtual HistoryService* GetHistoryService(ServiceAccessType sat) {
308 if (sat == EXPLICIT_ACCESS) {
309 return profile_->GetHistoryService(sat);
310 } else {
311 NOTREACHED() << "This profile is OffTheRecord";
312 return NULL;
313 }
314 }
315
[email protected]0850fa62009-10-08 22:34:29316 virtual HistoryService* GetHistoryServiceWithoutCreating() {
317 return profile_->GetHistoryServiceWithoutCreating();
318 }
319
[email protected]0189bc722009-08-28 21:56:48320 virtual FaviconService* GetFaviconService(ServiceAccessType sat) {
321 if (sat == EXPLICIT_ACCESS) {
322 return profile_->GetFaviconService(sat);
323 } else {
324 NOTREACHED() << "This profile is OffTheRecord";
325 return NULL;
326 }
327 }
328
initial.commit09911bf2008-07-26 23:55:29329 virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
330 if (sat == EXPLICIT_ACCESS) {
331 return profile_->GetWebDataService(sat);
332 } else {
333 NOTREACHED() << "This profile is OffTheRecord";
334 return NULL;
335 }
336 }
337
[email protected]e69d33952009-06-03 22:00:41338 virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) {
339 if (sat == EXPLICIT_ACCESS) {
340 return profile_->GetPasswordStore(sat);
341 } else {
342 NOTREACHED() << "This profile is OffTheRecord";
343 return NULL;
344 }
345 }
346
initial.commit09911bf2008-07-26 23:55:29347 virtual PrefService* GetPrefs() {
348 return profile_->GetPrefs();
349 }
350
351 virtual TemplateURLModel* GetTemplateURLModel() {
352 return profile_->GetTemplateURLModel();
353 }
354
355 virtual TemplateURLFetcher* GetTemplateURLFetcher() {
356 return profile_->GetTemplateURLFetcher();
357 }
358
359 virtual DownloadManager* GetDownloadManager() {
360 if (!download_manager_.get()) {
361 scoped_refptr<DownloadManager> dlm(new DownloadManager);
362 dlm->Init(this);
363 download_manager_.swap(dlm);
364 }
365 return download_manager_.get();
366 }
367
368 virtual bool HasCreatedDownloadManager() const {
369 return (download_manager_.get() != NULL);
370 }
371
[email protected]4a190632009-05-09 01:07:42372 virtual void InitThemes() {
373 GetOriginalProfile()->InitThemes();
374 }
375
376 virtual void SetTheme(Extension* extension) {
377 GetOriginalProfile()->SetTheme(extension);
378 }
379
[email protected]a5166af62009-07-03 00:42:29380 virtual void SetNativeTheme() {
381 GetOriginalProfile()->SetNativeTheme();
382 }
383
[email protected]4a190632009-05-09 01:07:42384 virtual void ClearTheme() {
385 GetOriginalProfile()->ClearTheme();
386 }
387
[email protected]51c490b2009-08-03 16:34:34388 virtual Extension* GetTheme() {
389 return GetOriginalProfile()->GetTheme();
390 }
391
[email protected]4a190632009-05-09 01:07:42392 virtual ThemeProvider* GetThemeProvider() {
393 return GetOriginalProfile()->GetThemeProvider();
394 }
395
initial.commit09911bf2008-07-26 23:55:29396 virtual URLRequestContext* GetRequestContext() {
397 return request_context_;
398 }
399
[email protected]e7f29642009-03-02 22:53:18400 virtual URLRequestContext* GetRequestContextForMedia() {
[email protected]d14c7ac2009-05-29 20:38:11401 // In OTR mode, media request context is the same as the original one.
402 return request_context_;
[email protected]e7f29642009-03-02 22:53:18403 }
404
[email protected]47accfd62009-05-14 18:46:21405 URLRequestContext* GetRequestContextForExtensions() {
406 if (!extensions_request_context_) {
407 extensions_request_context_ =
408 ChromeURLRequestContext::CreateOffTheRecordForExtensions(this);
409 extensions_request_context_->AddRef();
410
411 DCHECK(extensions_request_context_->cookie_store());
412 }
413
414 return extensions_request_context_;
415 }
416
[email protected]db36938c2009-08-19 21:48:42417 virtual net::SSLConfigService* GetSSLConfigService() {
418 return GetOriginalProfile()->GetSSLConfigService();
419 }
420
[email protected]eaadd9052009-06-23 18:02:23421 virtual Blacklist* GetBlacklist() {
422 return GetOriginalProfile()->GetBlacklist();
423 }
424
initial.commit09911bf2008-07-26 23:55:29425 virtual SessionService* GetSessionService() {
426 // Don't save any sessions when off the record.
427 return NULL;
428 }
429
430 virtual void ShutdownSessionService() {
431 // We don't allow a session service, nothing to do.
432 }
433
434 virtual bool HasSessionService() const {
435 // We never have a session service.
436 return false;
437 }
438
439 virtual std::wstring GetName() {
440 return profile_->GetName();
441 }
442
443 virtual void SetName(const std::wstring& name) {
444 profile_->SetName(name);
445 }
446
447 virtual std::wstring GetID() {
448 return profile_->GetID();
449 }
450
451 virtual void SetID(const std::wstring& id) {
452 profile_->SetID(id);
453 }
454
initial.commit09911bf2008-07-26 23:55:29455 virtual bool DidLastSessionExitCleanly() {
456 return profile_->DidLastSessionExitCleanly();
457 }
458
[email protected]d8e41ed2008-09-11 15:22:32459 virtual BookmarkModel* GetBookmarkModel() {
460 return profile_->GetBookmarkModel();
initial.commit09911bf2008-07-26 23:55:29461 }
462
[email protected]4bb336302009-10-12 05:44:26463 virtual DesktopNotificationService* GetDesktopNotificationService() {
464 return profile_->GetDesktopNotificationService();
465 }
466
[email protected]48352c12009-08-15 01:19:11467 virtual ProfileSyncService* GetProfileSyncService() {
468 return NULL;
[email protected]3a453fa2008-08-15 18:46:34469 }
[email protected]3a453fa2008-08-15 18:46:34470
initial.commit09911bf2008-07-26 23:55:29471 virtual bool IsSameProfile(Profile* profile) {
472 if (profile == static_cast<Profile*>(this))
473 return true;
474 return profile == profile_;
475 }
476
477 virtual Time GetStartTime() const {
478 return start_time_;
479 }
480
481 virtual TabRestoreService* GetTabRestoreService() {
482 return NULL;
483 }
484
[email protected]e7244d82008-10-29 18:13:26485 virtual void ResetTabRestoreService() {
[email protected]20930852008-10-15 19:30:41486 }
487
[email protected]e7244d82008-10-29 18:13:26488 virtual void ReinitializeSpellChecker() {
489 profile_->ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:29490 }
491
492 virtual SpellChecker* GetSpellChecker() {
493 return profile_->GetSpellChecker();
494 }
495
[email protected]e3448ea2009-10-02 01:29:29496 virtual void DeleteSpellChecker() {
497 profile_->DeleteSpellChecker();
498 }
499
[email protected]3bf335a2009-06-26 20:46:06500 virtual WebKitContext* GetWebKitContext() {
501 if (!webkit_context_.get())
502 webkit_context_ = new WebKitContext(GetPath(), true);
503 DCHECK(webkit_context_.get());
504 return webkit_context_.get();
505}
506
[email protected]449478302009-06-09 20:04:28507 virtual ThumbnailStore* GetThumbnailStore() {
508 return NULL;
509 }
510
initial.commit09911bf2008-07-26 23:55:29511 virtual void MarkAsCleanShutdown() {
512 }
513
[email protected]bdbc87c2009-01-25 05:08:54514 virtual void InitExtensions() {
515 NOTREACHED();
516 }
517
[email protected]ea0c98cf2009-06-18 23:02:54518 virtual void InitWebResources() {
519 NOTREACHED();
520 }
521
initial.commit09911bf2008-07-26 23:55:29522 virtual void ExitedOffTheRecordMode() {
523 // Drop our download manager so we forget about all the downloads made
524 // in off-the-record mode.
525 download_manager_ = NULL;
526 }
527
528 virtual void Observe(NotificationType type,
529 const NotificationSource& source,
530 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:56531 DCHECK_EQ(NotificationType::BROWSER_CLOSED, type.value);
initial.commit09911bf2008-07-26 23:55:29532 // We are only interested in OTR browser closing.
533 if (Source<Browser>(source)->profile() != this)
534 return;
535
536 // Let's check if we still have an Off The Record window opened.
537 // Note that we check against 1 as this notification is sent before the
538 // browser window is actually removed from the list.
539 if (BrowserList::GetBrowserCount(this) <= 1)
540 ExitedOffTheRecordMode();
541 }
542
543 private:
[email protected]88cf3292009-05-22 01:48:43544 NotificationRegistrar registrar_;
545
initial.commit09911bf2008-07-26 23:55:29546 // The real underlying profile.
547 Profile* profile_;
548
[email protected]6ab9b202008-12-23 22:34:50549 // The context to use for requests made from this OTR session.
550 ChromeURLRequestContext* request_context_;
initial.commit09911bf2008-07-26 23:55:29551
[email protected]47accfd62009-05-14 18:46:21552 ChromeURLRequestContext* extensions_request_context_;
553
[email protected]23f1ef12009-09-01 22:30:30554 // Use a seperate appcache service for OTR.
[email protected]e2fc3d22009-09-22 19:50:31555 ChromeAppCacheService* appcache_service_;
[email protected]23f1ef12009-09-01 22:30:30556
initial.commit09911bf2008-07-26 23:55:29557 // The download manager that only stores downloaded items in memory.
558 scoped_refptr<DownloadManager> download_manager_;
559
[email protected]3bf335a2009-06-26 20:46:06560 // Use a special WebKit context for OTR browsing.
561 scoped_refptr<WebKitContext> webkit_context_;
562
[email protected]34cc84f2009-02-13 10:04:35563 // We don't want SSLHostState from the OTR profile to leak back to the main
564 // profile because then the main profile would learn some of the host names
565 // the user visited while OTR.
566 scoped_ptr<SSLHostState> ssl_host_state_;
567
[email protected]77f6fb432009-09-05 14:21:09568 // The StrictTransportSecurityState that only stores enabled sites in memory.
569 scoped_refptr<net::StrictTransportSecurityState>
570 strict_transport_security_state_;
[email protected]a9cea7542009-05-20 04:30:23571
initial.commit09911bf2008-07-26 23:55:29572 // Time we were started.
573 Time start_time_;
574
575 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl);
576};
577
[email protected]f7011fcb2009-01-28 21:54:32578ProfileImpl::ProfileImpl(const FilePath& path)
initial.commit09911bf2008-07-26 23:55:29579 : path_(path),
[email protected]3e90d4a2009-07-03 17:38:39580 visited_link_event_listener_(new VisitedLinkEventListener()),
[email protected]89ebc7e2009-08-24 22:11:07581 extension_devtools_manager_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32582 request_context_(NULL),
[email protected]363347b2009-03-13 20:06:57583 media_request_context_(NULL),
[email protected]47accfd62009-05-14 18:46:21584 extensions_request_context_(NULL),
[email protected]eaadd9052009-06-23 18:02:23585 blacklist_(NULL),
[email protected]f7011fcb2009-01-28 21:54:32586 history_service_created_(false),
[email protected]0189bc722009-08-28 21:56:48587 favicon_service_created_(false),
[email protected]f7011fcb2009-01-28 21:54:32588 created_web_data_service_(false),
[email protected]e69d33952009-06-03 22:00:41589 created_password_store_(false),
[email protected]f7011fcb2009-01-28 21:54:32590 created_download_manager_(false),
[email protected]4a190632009-05-09 01:07:42591 created_theme_provider_(false),
[email protected]f7011fcb2009-01-28 21:54:32592 start_time_(Time::Now()),
593 spellchecker_(NULL),
initial.commit09911bf2008-07-26 23:55:29594 shutdown_session_service_(false) {
595 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
596 "profile files to the root directory!";
[email protected]2d316662008-09-03 18:18:14597 create_session_service_timer_.Start(
598 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
599 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]bdbc87c2009-01-25 05:08:54600
[email protected]89ebc7e2009-08-24 22:11:07601 if (CommandLine::ForCurrentProcess()->HasSwitch(
602 switches::kEnableExtensionTimelineApi)) {
603 extension_devtools_manager_ = new ExtensionDevToolsManager(this);
604 }
605
[email protected]e2fc3d22009-09-22 19:50:31606 // Created here but lazily inititialized later, finally released on
607 // on the io thread, see CleanupAppCacheService.
608 appcache_service_ = new ChromeAppCacheService();
609 appcache_service_->AddRef();
610
[email protected]382a0702009-06-26 17:12:27611 extension_process_manager_.reset(new ExtensionProcessManager(this));
[email protected]7120f132009-07-20 21:05:37612 extension_message_service_ = new ExtensionMessageService(this);
[email protected]382a0702009-06-26 17:12:27613
[email protected]e7244d82008-10-29 18:13:26614 PrefService* prefs = GetPrefs();
615 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
616 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58617 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]380ab462009-04-24 01:23:58618
[email protected]eaadd9052009-06-23 18:02:23619 if (CommandLine::ForCurrentProcess()->
620 HasSwitch(switches::kPrivacyBlacklist)) {
621 std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue(
622 switches::kPrivacyBlacklist);
623#if defined(OS_POSIX)
624 FilePath path(WideToUTF8(option));
625#else
626 FilePath path(option);
627#endif
628 blacklist_ = new Blacklist(path);
629 }
630
[email protected]405a64b2009-09-16 21:03:44631#if defined(OS_MACOSX)
632 // If the profile directory doesn't already have a cache directory and it
633 // is under ~/Library/Application Support, use a suitable cache directory
634 // under ~/Library/Caches. For example, a profile directory of
635 // ~/Library/Application Support/Google/Chrome/MyProfileName that doesn't
636 // have a "Cache" or "MediaCache" subdirectory would use the cache directory
637 // ~/Library/Caches/Google/Chrome/MyProfileName.
638 //
639 // TODO(akalin): Come up with unit tests for this.
640 // TODO(akalin): Use for Linux, too?
641 if (!HasACacheSubdir(path_)) {
642 FilePath app_data_path, user_cache_path;
643 if (PathService::Get(base::DIR_APP_DATA, &app_data_path) &&
644 PathService::Get(base::DIR_CACHE, &user_cache_path) &&
645 app_data_path.AppendRelativePath(path_, &user_cache_path)) {
646 base_cache_path_ = user_cache_path;
647 }
648 }
649#else
[email protected]bc96d562009-08-11 18:45:13650 if (!PathService::IsOverridden(chrome::DIR_USER_DATA))
651 PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_);
[email protected]405a64b2009-09-16 21:03:44652#endif
[email protected]bc96d562009-08-11 18:45:13653 if (base_cache_path_.empty())
654 base_cache_path_ = path_;
655
[email protected]4a190632009-05-09 01:07:42656 // Listen for theme installation.
[email protected]88cf3292009-05-22 01:48:43657 registrar_.Add(this, NotificationType::THEME_INSTALLED,
658 NotificationService::AllSources());
[email protected]48352c12009-08-15 01:19:11659
660 // Listen for bookmark model load, to bootstrap the sync service.
661 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
662 Source<Profile>(this));
[email protected]db36938c2009-08-19 21:48:42663
664 ssl_config_service_manager_.reset(
665 SSLConfigServiceManager::CreateDefaultManager(this));
[email protected]2627431b2009-09-15 20:21:53666
667#if defined(OS_CHROMEOS)
[email protected]fecc1522009-10-15 21:08:29668 chromeos_preferences_.Init(prefs);
[email protected]2627431b2009-09-15 20:21:53669#endif
initial.commit09911bf2008-07-26 23:55:29670}
671
[email protected]bdbc87c2009-01-25 05:08:54672void ProfileImpl::InitExtensions() {
[email protected]8c756ac2009-01-30 23:36:41673 if (user_script_master_ || extensions_service_)
674 return; // Already initialized.
675
[email protected]bdbc87c2009-01-25 05:08:54676 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]f93fe782009-02-19 01:26:13677 PrefService* prefs = GetPrefs();
[email protected]bdbc87c2009-01-25 05:08:54678 bool user_scripts_enabled =
[email protected]f0a51fb52009-03-05 12:46:38679 command_line->HasSwitch(switches::kEnableUserScripts) ||
[email protected]f93fe782009-02-19 01:26:13680 prefs->GetBoolean(prefs::kEnableUserScripts);
[email protected]bdbc87c2009-01-25 05:08:54681
[email protected]f7011fcb2009-01-28 21:54:32682 FilePath script_dir;
[email protected]bdbc87c2009-01-25 05:08:54683 if (user_scripts_enabled) {
[email protected]0cd957b2009-03-06 20:13:23684 if (command_line->HasSwitch(switches::kUserScriptsDir)) {
685 std::wstring path_string =
686 command_line->GetSwitchValue(switches::kUserScriptsDir);
687 script_dir = FilePath::FromWStringHack(path_string);
688 } else {
689 script_dir = GetPath();
690 script_dir = script_dir.Append(chrome::kUserScriptsDirname);
691 }
[email protected]bdbc87c2009-01-25 05:08:54692 }
693
[email protected]bb28e062009-02-27 17:19:18694 ExtensionErrorReporter::Init(true); // allow noisy errors.
[email protected]bdbc87c2009-01-25 05:08:54695 user_script_master_ = new UserScriptMaster(
[email protected]9197f3b2009-06-02 00:49:27696 g_browser_process->file_thread()->message_loop(),
697 script_dir);
[email protected]894bb502009-05-21 22:39:57698 extensions_service_ = new ExtensionsService(
[email protected]a9b00ac2009-06-25 21:03:23699 this,
700 CommandLine::ForCurrentProcess(),
701 GetPrefs(),
702 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName),
703 MessageLoop::current(),
[email protected]93fd78f42009-07-10 16:43:17704 g_browser_process->file_thread()->message_loop(),
[email protected]c8b437d2009-07-20 21:26:36705 true);
[email protected]bdbc87c2009-01-25 05:08:54706
[email protected]9197f3b2009-06-02 00:49:27707 extensions_service_->Init();
[email protected]919ddc82009-07-15 04:30:12708
709 // Load any extensions specified with --load-extension.
710 if (command_line->HasSwitch(switches::kLoadExtension)) {
711 std::wstring path_string =
712 command_line->GetSwitchValue(switches::kLoadExtension);
713 FilePath path = FilePath::FromWStringHack(path_string);
714 extensions_service_->LoadExtension(path);
715
716 // Tell UserScriptMaser to watch this extension's directory for changes so
717 // you can live edit content scripts during development.
718 user_script_master_->AddWatchedPath(path);
719 }
[email protected]bdbc87c2009-01-25 05:08:54720}
721
[email protected]ea0c98cf2009-06-18 23:02:54722void ProfileImpl::InitWebResources() {
[email protected]0c274c202009-07-12 02:59:07723 if (web_resource_service_)
724 return; // Already initialized.
725
[email protected]ea0c98cf2009-06-18 23:02:54726 web_resource_service_ = new WebResourceService(
727 this,
728 g_browser_process->file_thread()->message_loop());
729
730 web_resource_service_->StartAfterDelay();
731}
732
initial.commit09911bf2008-07-26 23:55:29733ProfileImpl::~ProfileImpl() {
[email protected]169627b2008-12-06 19:30:19734 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:29735
736 StopCreateSessionServiceTimer();
737 // TemplateURLModel schedules a task on the WebDataService from its
738 // destructor. Delete it first to ensure the task gets scheduled before we
739 // shut down the database.
740 template_url_model_.reset();
741
742 // The download manager queries the history system and should be deleted
743 // before the history is shutdown so it can properly cancel all requests.
744 download_manager_ = NULL;
745
[email protected]4a190632009-05-09 01:07:42746 // The theme provider provides bitmaps to whoever wants them.
[email protected]761962c2009-09-25 00:18:15747 theme_provider_.reset();
[email protected]4a190632009-05-09 01:07:42748
[email protected]44961292009-07-20 20:03:09749 // The ThumbnailStore saves thumbnails used by the NTP. Call Shutdown to
750 // save any new thumbnails to disk and release its reference to the
751 // HistoryService.
752 if (thumbnail_store_.get())
753 thumbnail_store_->Shutdown();
754
[email protected]e7244d82008-10-29 18:13:26755 // Remove pref observers.
756 PrefService* prefs = GetPrefs();
757 prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
758 prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
[email protected]154a4332009-06-03 20:20:58759 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
[email protected]e7244d82008-10-29 18:13:26760
[email protected]066629f2009-10-17 00:28:13761#if defined(BROWSER_SYNC)
[email protected]48352c12009-08-15 01:19:11762 sync_service_.reset();
[email protected]3a453fa2008-08-15 18:46:34763#endif
764
initial.commit09911bf2008-07-26 23:55:29765 // Both HistoryService and WebDataService maintain threads for background
766 // processing. Its possible each thread still has tasks on it that have
767 // increased the ref count of the service. In such a situation, when we
768 // decrement the refcount, it won't be 0, and the threads/databases aren't
769 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
770 // databases are properly closed.
771 if (web_data_service_.get())
772 web_data_service_->Shutdown();
773
774 if (history_service_.get())
775 history_service_->Cleanup();
776
[email protected]e3448ea2009-10-02 01:29:29777 DeleteSpellCheckerImpl(false);
initial.commit09911bf2008-07-26 23:55:29778
[email protected]2a0c0a52009-07-31 07:51:32779 if (default_request_context_ == request_context_) {
780#if defined(OS_LINUX)
781 // We use default_request_context_ for OCSP.
782 // Release URLRequestContext used in OCSP handlers.
783 net::SetURLRequestContextForOCSP(NULL);
784#endif
[email protected]47accfd62009-05-14 18:46:21785 default_request_context_ = NULL;
[email protected]2a0c0a52009-07-31 07:51:32786 }
[email protected]6ab9b202008-12-23 22:34:50787
[email protected]47accfd62009-05-14 18:46:21788 CleanupRequestContext(request_context_);
789 CleanupRequestContext(media_request_context_);
790 CleanupRequestContext(extensions_request_context_);
[email protected]e2fc3d22009-09-22 19:50:31791 CleanupAppCacheService(appcache_service_);
[email protected]1e744f22009-04-08 01:00:17792
[email protected]eaadd9052009-06-23 18:02:23793 // When the request contexts are gone, the blacklist wont be needed anymore.
794 delete blacklist_;
795 blacklist_ = 0;
796
[email protected]d8e41ed2008-09-11 15:22:32797 // HistoryService may call into the BookmarkModel, as such we need to
798 // delete HistoryService before the BookmarkModel. The destructor for
[email protected]90ef13132008-08-27 03:27:46799 // HistoryService will join with HistoryService's backend thread so that
800 // by the time the destructor has finished we're sure it will no longer call
[email protected]d8e41ed2008-09-11 15:22:32801 // into the BookmarkModel.
[email protected]90ef13132008-08-27 03:27:46802 history_service_ = NULL;
803 bookmark_bar_model_.reset();
804
[email protected]0189bc722009-08-28 21:56:48805 // FaviconService depends on HistoryServce so make sure we delete
806 // HistoryService first.
807 favicon_service_ = NULL;
808
[email protected]7120f132009-07-20 21:05:37809 extension_message_service_->ProfileDestroyed();
810
[email protected]6ef635e42009-07-26 06:16:12811 if (extensions_service_)
812 extensions_service_->ProfileDestroyed();
813
[email protected]66da08b2009-10-19 22:27:00814 // This causes the Preferences file to be written to disk.
initial.commit09911bf2008-07-26 23:55:29815 MarkAsCleanShutdown();
816}
817
[email protected]4bf6afd2009-10-08 14:00:11818ProfileId ProfileImpl::GetRuntimeId() {
819 return reinterpret_cast<ProfileId>(this);
820}
821
[email protected]f7011fcb2009-01-28 21:54:32822FilePath ProfileImpl::GetPath() {
initial.commit09911bf2008-07-26 23:55:29823 return path_;
824}
825
826bool ProfileImpl::IsOffTheRecord() {
827 return false;
828}
829
830Profile* ProfileImpl::GetOffTheRecordProfile() {
831 if (!off_the_record_profile_.get()) {
832 scoped_ptr<OffTheRecordProfileImpl> p(new OffTheRecordProfileImpl(this));
833 off_the_record_profile_.swap(p);
834 }
835 return off_the_record_profile_.get();
836}
837
[email protected]860f55492009-03-27 19:50:59838void ProfileImpl::DestroyOffTheRecordProfile() {
839 off_the_record_profile_.reset();
840}
841
initial.commit09911bf2008-07-26 23:55:29842Profile* ProfileImpl::GetOriginalProfile() {
843 return this;
844}
845
[email protected]23f1ef12009-09-01 22:30:30846ChromeAppCacheService* ProfileImpl::GetAppCacheService() {
[email protected]e2fc3d22009-09-22 19:50:31847 if (!appcache_service_->is_initialized()) {
848 EnsureRequestContextCreated();
849 appcache_service_->InitializeOnUIThread(GetPath(), false);
[email protected]23f1ef12009-09-01 22:30:30850 }
[email protected]e2fc3d22009-09-22 19:50:31851 return appcache_service_;
[email protected]23f1ef12009-09-01 22:30:30852}
853
initial.commit09911bf2008-07-26 23:55:29854VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
855 if (!visited_link_master_.get()) {
856 scoped_ptr<VisitedLinkMaster> visited_links(
857 new VisitedLinkMaster(g_browser_process->file_thread(),
[email protected]3e90d4a2009-07-03 17:38:39858 visited_link_event_listener_.get(), this));
initial.commit09911bf2008-07-26 23:55:29859 if (!visited_links->Init())
860 return NULL;
861 visited_link_master_.swap(visited_links);
862 }
863
864 return visited_link_master_.get();
865}
866
[email protected]6014d672008-12-05 00:38:25867ExtensionsService* ProfileImpl::GetExtensionsService() {
868 return extensions_service_.get();
869}
870
[email protected]0938d3c2009-01-09 20:37:35871UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
[email protected]0938d3c2009-01-09 20:37:35872 return user_script_master_.get();
[email protected]04fba9a92008-10-28 17:25:25873}
874
[email protected]89ebc7e2009-08-24 22:11:07875ExtensionDevToolsManager* ProfileImpl::GetExtensionDevToolsManager() {
876 return extension_devtools_manager_.get();
877}
878
[email protected]481e1a42009-05-06 20:56:05879ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
[email protected]382a0702009-06-26 17:12:27880 return extension_process_manager_.get();
[email protected]481e1a42009-05-06 20:56:05881}
882
[email protected]7120f132009-07-20 21:05:37883ExtensionMessageService* ProfileImpl::GetExtensionMessageService() {
884 return extension_message_service_.get();
885}
886
[email protected]34cc84f2009-02-13 10:04:35887SSLHostState* ProfileImpl::GetSSLHostState() {
888 if (!ssl_host_state_.get())
889 ssl_host_state_.reset(new SSLHostState());
890
891 DCHECK(ssl_host_state_->CalledOnValidThread());
892 return ssl_host_state_.get();
893}
894
[email protected]77f6fb432009-09-05 14:21:09895net::StrictTransportSecurityState*
896 ProfileImpl::GetStrictTransportSecurityState() {
897 if (!strict_transport_security_state_.get()) {
898 strict_transport_security_state_ = new net::StrictTransportSecurityState();
899 strict_transport_security_persister_ = new StrictTransportSecurityPersister(
900 strict_transport_security_state_.get(),
901 g_browser_process->file_thread(), path_);
[email protected]887f80d2009-09-04 16:57:51902 }
[email protected]a9cea7542009-05-20 04:30:23903
[email protected]77f6fb432009-09-05 14:21:09904 return strict_transport_security_state_.get();
[email protected]a9cea7542009-05-20 04:30:23905}
906
initial.commit09911bf2008-07-26 23:55:29907PrefService* ProfileImpl::GetPrefs() {
908 if (!prefs_.get()) {
[email protected]6faa0e0d2009-04-28 06:50:36909 prefs_.reset(new PrefService(GetPrefFilePath(),
910 g_browser_process->file_thread()));
initial.commit09911bf2008-07-26 23:55:29911
912 // The Profile class and ProfileManager class may read some prefs so
913 // register known prefs as soon as possible.
914 Profile::RegisterUserPrefs(prefs_.get());
915 ProfileManager::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53916#if defined(OS_CHROMEOS)
917 // Register Touchpad prefs here instead of in browser_prefs because these
918 // prefs are used in the constructor of ProfileImpl which happens before
919 // browser_prefs' RegisterAllPrefs is called.
[email protected]fecc1522009-10-15 21:08:29920 chromeos::Preferences::RegisterUserPrefs(prefs_.get());
[email protected]2627431b2009-09-15 20:21:53921#endif
initial.commit09911bf2008-07-26 23:55:29922
923 // The last session exited cleanly if there is no pref for
924 // kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
925 last_session_exited_cleanly_ =
926 prefs_->GetBoolean(prefs::kSessionExitedCleanly);
927 // Mark the session as open.
928 prefs_->SetBoolean(prefs::kSessionExitedCleanly, false);
929 // Make sure we save to disk that the session has opened.
[email protected]6faa0e0d2009-04-28 06:50:36930 prefs_->ScheduleSavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29931 }
932
933 return prefs_.get();
934}
935
[email protected]f7011fcb2009-01-28 21:54:32936FilePath ProfileImpl::GetPrefFilePath() {
937 FilePath pref_file_path = path_;
938 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
initial.commit09911bf2008-07-26 23:55:29939 return pref_file_path;
940}
941
942URLRequestContext* ProfileImpl::GetRequestContext() {
943 if (!request_context_) {
[email protected]f7011fcb2009-01-28 21:54:32944 FilePath cookie_path = GetPath();
945 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]bc96d562009-08-11 18:45:13946 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31947 int max_size;
948 GetCacheParameters(kNormalContext, &cache_path, &max_size);
[email protected]2b2830a2009-02-07 01:58:42949
[email protected]405a64b2009-09-16 21:03:44950 cache_path = GetCachePath(cache_path);
[email protected]6ab9b202008-12-23 22:34:50951 request_context_ = ChromeURLRequestContext::CreateOriginal(
[email protected]e2fc3d22009-09-22 19:50:31952 this, cookie_path, cache_path, max_size, appcache_service_);
initial.commit09911bf2008-07-26 23:55:29953 request_context_->AddRef();
954
[email protected]6ab9b202008-12-23 22:34:50955 // The first request context is always a normal (non-OTR) request context.
956 // Even when Chromium is started in OTR mode, a normal profile is always
957 // created first.
958 if (!default_request_context_) {
959 default_request_context_ = request_context_;
960 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:56961 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
[email protected]6ab9b202008-12-23 22:34:50962 NotificationService::AllSources(), NotificationService::NoDetails());
[email protected]2a0c0a52009-07-31 07:51:32963#if defined(OS_LINUX)
964 // TODO(ukai): find a better way to set the URLRequestContext for OCSP.
965 net::SetURLRequestContextForOCSP(default_request_context_);
966#endif
[email protected]6ab9b202008-12-23 22:34:50967 }
968
initial.commit09911bf2008-07-26 23:55:29969 DCHECK(request_context_->cookie_store());
970 }
971
972 return request_context_;
973}
974
[email protected]e7f29642009-03-02 22:53:18975URLRequestContext* ProfileImpl::GetRequestContextForMedia() {
976 if (!media_request_context_) {
[email protected]bc96d562009-08-11 18:45:13977 FilePath cache_path = base_cache_path_;
[email protected]e5642992009-06-26 23:06:31978 int max_size;
979 GetCacheParameters(kMediaContext, &cache_path, &max_size);
[email protected]e3edeba2009-03-23 18:57:14980
[email protected]405a64b2009-09-16 21:03:44981 cache_path = GetMediaCachePath(cache_path);
[email protected]e7f29642009-03-02 22:53:18982 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia(
[email protected]e2fc3d22009-09-22 19:50:31983 this, cache_path, max_size, appcache_service_);
[email protected]e7f29642009-03-02 22:53:18984 media_request_context_->AddRef();
985
986 DCHECK(media_request_context_->cookie_store());
987 }
988
989 return media_request_context_;
990}
991
[email protected]0189bc722009-08-28 21:56:48992FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) {
993 if (!favicon_service_created_) {
994 favicon_service_created_ = true;
995 scoped_refptr<FaviconService> service(new FaviconService(this));
996 favicon_service_.swap(service);
997 }
998 return favicon_service_.get();
999}
1000
[email protected]47accfd62009-05-14 18:46:211001URLRequestContext* ProfileImpl::GetRequestContextForExtensions() {
1002 if (!extensions_request_context_) {
1003 FilePath cookie_path = GetPath();
1004 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
1005
1006 extensions_request_context_ =
1007 ChromeURLRequestContext::CreateOriginalForExtensions(this, cookie_path);
1008 extensions_request_context_->AddRef();
1009
1010 DCHECK(extensions_request_context_->cookie_store());
1011 }
1012
1013 return extensions_request_context_;
1014}
1015
[email protected]db36938c2009-08-19 21:48:421016net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
1017 return ssl_config_service_manager_->Get();
1018}
1019
[email protected]eaadd9052009-06-23 18:02:231020Blacklist* ProfileImpl::GetBlacklist() {
1021 return blacklist_;
1022}
1023
initial.commit09911bf2008-07-26 23:55:291024HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
1025 if (!history_service_created_) {
[email protected]90ef13132008-08-27 03:27:461026 history_service_created_ = true;
initial.commit09911bf2008-07-26 23:55:291027 scoped_refptr<HistoryService> history(new HistoryService(this));
[email protected]d8e41ed2008-09-11 15:22:321028 if (!history->Init(GetPath(), GetBookmarkModel()))
initial.commit09911bf2008-07-26 23:55:291029 return NULL;
1030 history_service_.swap(history);
initial.commit09911bf2008-07-26 23:55:291031
1032 // Send out the notification that the history service was created.
1033 NotificationService::current()->
[email protected]bfd04a62009-02-01 18:16:561034 Notify(NotificationType::HISTORY_CREATED, Source<Profile>(this),
initial.commit09911bf2008-07-26 23:55:291035 Details<HistoryService>(history_service_.get()));
1036 }
1037 return history_service_.get();
1038}
1039
[email protected]0850fa62009-10-08 22:34:291040HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
1041 return history_service_.get();
1042}
1043
initial.commit09911bf2008-07-26 23:55:291044TemplateURLModel* ProfileImpl::GetTemplateURLModel() {
1045 if (!template_url_model_.get())
1046 template_url_model_.reset(new TemplateURLModel(this));
1047 return template_url_model_.get();
1048}
1049
1050TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
1051 if (!template_url_fetcher_.get())
1052 template_url_fetcher_.reset(new TemplateURLFetcher(this));
1053 return template_url_fetcher_.get();
1054}
1055
1056WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
1057 if (!created_web_data_service_)
1058 CreateWebDataService();
1059 return web_data_service_.get();
1060}
1061
1062void ProfileImpl::CreateWebDataService() {
1063 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
1064 created_web_data_service_ = true;
1065 scoped_refptr<WebDataService> wds(new WebDataService());
1066 if (!wds->Init(GetPath()))
1067 return;
1068 web_data_service_.swap(wds);
1069}
1070
[email protected]e69d33952009-06-03 22:00:411071PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
1072 if (!created_password_store_)
1073 CreatePasswordStore();
1074 return password_store_.get();
1075}
1076
1077void ProfileImpl::CreatePasswordStore() {
1078 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1079 created_password_store_ = true;
1080 scoped_refptr<PasswordStore> ps;
1081#if defined(OS_LINUX)
[email protected]d17634b2009-10-20 18:56:251082 // TODO(evanm): implement "native" password management.
1083 // This bug describes the issues.
1084 // http://code.google.com/p/chromium/issues/detail?id=12351
1085 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1086 if (!ps->Init())
1087 return;
[email protected]e69d33952009-06-03 22:00:411088#elif defined(OS_WIN)
1089 ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS));
[email protected]034eba52009-06-03 22:50:561090#elif defined(OS_MACOSX)
[email protected]e0411ae52009-06-30 23:59:171091 FilePath login_db_file_path = GetPath();
1092 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1093 LoginDatabaseMac* login_db = new LoginDatabaseMac();
1094 if (!login_db->Init(login_db_file_path)) {
1095 LOG(ERROR) << "Could not initialize login database.";
1096 delete login_db;
1097 return;
1098 }
1099 ps = new PasswordStoreMac(new MacKeychain(), login_db);
[email protected]e69d33952009-06-03 22:00:411100#else
1101 NOTIMPLEMENTED();
1102#endif
1103 if (!ps || !ps->Init()) {
1104 // Try falling back to the default password manager
1105 LOG(WARNING) << "Could not initialise native password manager - "
1106 "falling back to default";
1107 ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS));
1108 if (!ps->Init())
1109 return;
1110 }
1111 password_store_.swap(ps);
1112}
1113
initial.commit09911bf2008-07-26 23:55:291114DownloadManager* ProfileImpl::GetDownloadManager() {
1115 if (!created_download_manager_) {
1116 scoped_refptr<DownloadManager> dlm(new DownloadManager);
1117 dlm->Init(this);
1118 created_download_manager_ = true;
1119 download_manager_.swap(dlm);
1120 }
1121 return download_manager_.get();
1122}
1123
1124bool ProfileImpl::HasCreatedDownloadManager() const {
1125 return created_download_manager_;
1126}
1127
[email protected]4a190632009-05-09 01:07:421128void ProfileImpl::InitThemes() {
1129 if (!created_theme_provider_) {
[email protected]0519e112009-09-29 15:49:571130#if defined(OS_LINUX)
[email protected]761962c2009-09-25 00:18:151131 theme_provider_.reset(new GtkThemeProvider);
[email protected]a5166af62009-07-03 00:42:291132#else
[email protected]761962c2009-09-25 00:18:151133 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a5166af62009-07-03 00:42:291134#endif
[email protected]761962c2009-09-25 00:18:151135 theme_provider_->Init(this);
[email protected]4a190632009-05-09 01:07:421136 created_theme_provider_ = true;
[email protected]4a190632009-05-09 01:07:421137 }
1138}
1139
1140void ProfileImpl::SetTheme(Extension* extension) {
1141 InitThemes();
1142 theme_provider_.get()->SetTheme(extension);
1143}
1144
[email protected]a5166af62009-07-03 00:42:291145void ProfileImpl::SetNativeTheme() {
1146 InitThemes();
1147 theme_provider_.get()->SetNativeTheme();
1148}
1149
[email protected]4a190632009-05-09 01:07:421150void ProfileImpl::ClearTheme() {
1151 InitThemes();
1152 theme_provider_.get()->UseDefaultTheme();
1153}
1154
[email protected]51c490b2009-08-03 16:34:341155Extension* ProfileImpl::GetTheme() {
1156 InitThemes();
1157
1158 std::string id = theme_provider_.get()->GetThemeID();
1159 if (id == BrowserThemeProvider::kDefaultThemeID)
1160 return NULL;
1161
1162 return extensions_service_->GetExtensionById(id);
1163}
1164
[email protected]4a190632009-05-09 01:07:421165ThemeProvider* ProfileImpl::GetThemeProvider() {
1166 InitThemes();
1167 return theme_provider_.get();
1168}
1169
initial.commit09911bf2008-07-26 23:55:291170SessionService* ProfileImpl::GetSessionService() {
1171 if (!session_service_.get() && !shutdown_session_service_) {
1172 session_service_ = new SessionService(this);
1173 session_service_->ResetFromCurrentBrowsers();
1174 }
1175 return session_service_.get();
1176}
1177
1178void ProfileImpl::ShutdownSessionService() {
1179 if (shutdown_session_service_)
1180 return;
1181
1182 // We're about to exit, force creation of the session service if it hasn't
1183 // been created yet. We do this to ensure session state matches the point in
1184 // time the user exited.
1185 GetSessionService();
1186 shutdown_session_service_ = true;
1187 session_service_ = NULL;
1188}
1189
1190bool ProfileImpl::HasSessionService() const {
1191 return (session_service_.get() != NULL);
1192}
1193
1194std::wstring ProfileImpl::GetName() {
1195 return GetPrefs()->GetString(prefs::kProfileName);
1196}
1197void ProfileImpl::SetName(const std::wstring& name) {
1198 GetPrefs()->SetString(prefs::kProfileName, name);
1199}
1200
1201std::wstring ProfileImpl::GetID() {
1202 return GetPrefs()->GetString(prefs::kProfileID);
1203}
1204void ProfileImpl::SetID(const std::wstring& id) {
1205 GetPrefs()->SetString(prefs::kProfileID, id);
1206}
1207
initial.commit09911bf2008-07-26 23:55:291208bool ProfileImpl::DidLastSessionExitCleanly() {
1209 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1210 // it to be set by asking for the prefs.
1211 GetPrefs();
1212 return last_session_exited_cleanly_;
1213}
1214
[email protected]d8e41ed2008-09-11 15:22:321215BookmarkModel* ProfileImpl::GetBookmarkModel() {
[email protected]90ef13132008-08-27 03:27:461216 if (!bookmark_bar_model_.get()) {
[email protected]d8e41ed2008-09-11 15:22:321217 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:461218 bookmark_bar_model_->Load();
1219 }
initial.commit09911bf2008-07-26 23:55:291220 return bookmark_bar_model_.get();
1221}
1222
1223bool ProfileImpl::IsSameProfile(Profile* profile) {
1224 if (profile == static_cast<Profile*>(this))
1225 return true;
1226 OffTheRecordProfileImpl* otr_profile = off_the_record_profile_.get();
1227 return otr_profile && profile == static_cast<Profile*>(otr_profile);
1228}
1229
1230Time ProfileImpl::GetStartTime() const {
1231 return start_time_;
1232}
1233
1234TabRestoreService* ProfileImpl::GetTabRestoreService() {
1235 if (!tab_restore_service_.get())
[email protected]169627b2008-12-06 19:30:191236 tab_restore_service_ = new TabRestoreService(this);
initial.commit09911bf2008-07-26 23:55:291237 return tab_restore_service_.get();
1238}
1239
[email protected]449478302009-06-09 20:04:281240ThumbnailStore* ProfileImpl::GetThumbnailStore() {
1241 if (!thumbnail_store_.get()) {
1242 thumbnail_store_ = new ThumbnailStore;
[email protected]daa82dc2009-07-28 01:22:251243 thumbnail_store_->Init(
1244 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
[email protected]449478302009-06-09 20:04:281245 }
1246 return thumbnail_store_.get();
1247}
1248
initial.commit09911bf2008-07-26 23:55:291249void ProfileImpl::ResetTabRestoreService() {
[email protected]169627b2008-12-06 19:30:191250 tab_restore_service_ = NULL;
initial.commit09911bf2008-07-26 23:55:291251}
1252
[email protected]a9afddb2009-02-12 17:49:421253// To be run in the IO thread to notify all resource message filters that the
[email protected]20930852008-10-15 19:30:411254// spellchecker has changed.
1255class NotifySpellcheckerChangeTask : public Task {
1256 public:
1257 NotifySpellcheckerChangeTask(
[email protected]e7244d82008-10-29 18:13:261258 Profile* profile,
1259 const SpellcheckerReinitializedDetails& spellchecker)
[email protected]20930852008-10-15 19:30:411260 : profile_(profile),
1261 spellchecker_(spellchecker) {
1262 }
1263
1264 private:
1265 void Run(void) {
1266 NotificationService::current()->Notify(
[email protected]bfd04a62009-02-01 18:16:561267 NotificationType::SPELLCHECKER_REINITIALIZED,
[email protected]20930852008-10-15 19:30:411268 Source<Profile>(profile_),
1269 Details<SpellcheckerReinitializedDetails>(&spellchecker_));
1270 }
1271
1272 Profile* profile_;
1273 SpellcheckerReinitializedDetails spellchecker_;
1274};
1275
[email protected]e3448ea2009-10-02 01:29:291276void ProfileImpl::ReinitializeSpellChecker() {
[email protected]20930852008-10-15 19:30:411277 PrefService* prefs = GetPrefs();
[email protected]e3448ea2009-10-02 01:29:291278 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1279 DeleteSpellCheckerImpl(false);
[email protected]20930852008-10-15 19:30:411280
[email protected]e3448ea2009-10-02 01:29:291281 // Retrieve the (perhaps updated recently) dictionary name from preferences.
[email protected]bd17b702009-02-25 20:44:081282 FilePath dict_dir;
[email protected]e7244d82008-10-29 18:13:261283 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
[email protected]a9afddb2009-02-12 17:49:421284 // Note that, as the object pointed to by previously by spellchecker_
[email protected]e7244d82008-10-29 18:13:261285 // is being deleted in the io thread, the spellchecker_ can be made to point
1286 // to a new object (RE-initialized) in parallel in this UI thread.
[email protected]4b4d1adc2008-12-10 22:28:581287 spellchecker_ = new SpellChecker(dict_dir,
[email protected]74c8b422009-03-11 00:34:121288 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1289 GetRequestContext(),
[email protected]bd17b702009-02-25 20:44:081290 FilePath());
[email protected]e7244d82008-10-29 18:13:261291 spellchecker_->AddRef(); // Manual refcounting.
[email protected]20930852008-10-15 19:30:411292
[email protected]e3448ea2009-10-02 01:29:291293 // Set auto spell correct status for spellchecker.
[email protected]154a4332009-06-03 20:20:581294 spellchecker_->EnableAutoSpellCorrect(
1295 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
[email protected]154a4332009-06-03 20:20:581296
[email protected]e3448ea2009-10-02 01:29:291297 NotifySpellCheckerChanged();
1298 } else {
1299 DeleteSpellCheckerImpl(true);
[email protected]20930852008-10-15 19:30:411300 }
1301}
1302
[email protected]e3448ea2009-10-02 01:29:291303void ProfileImpl::NotifySpellCheckerChanged() {
1304 // The I/O thread may be NULL during testing.
1305 base::Thread* io_thread = g_browser_process->io_thread();
1306 if (io_thread) { // Notify resource message filters.
1307 SpellcheckerReinitializedDetails scoped_spellchecker;
1308 scoped_spellchecker.spellchecker = spellchecker_;
1309 io_thread->message_loop()->PostTask(FROM_HERE,
1310 new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
1311 }
1312}
1313
1314void ProfileImpl::DeleteSpellCheckerImpl(bool notify) {
1315 if (spellchecker_) {
1316 // The spellchecker must be deleted on the I/O thread.
1317 // The I/O thread may be NULL during testing.
1318 base::Thread* io_thread = g_browser_process->io_thread();
1319 if (io_thread)
1320 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
1321 else // during testing, we don't have an I/O thread
1322 spellchecker_->Release();
1323
1324 spellchecker_ = NULL;
1325
1326 if (notify)
1327 NotifySpellCheckerChanged();
1328 }
[email protected]e7244d82008-10-29 18:13:261329}
1330
initial.commit09911bf2008-07-26 23:55:291331SpellChecker* ProfileImpl::GetSpellChecker() {
1332 if (!spellchecker_) {
[email protected]20930852008-10-15 19:30:411333 // This is where spellchecker gets initialized. Note that this is being
1334 // initialized in the ui_thread. However, this is not a problem as long as
1335 // it is *used* in the io thread.
[email protected]34cc84f2009-02-13 10:04:351336 // TODO(sidchat): One day, change everything so that spellchecker gets
[email protected]20930852008-10-15 19:30:411337 // initialized in the IO thread itself.
[email protected]e3448ea2009-10-02 01:29:291338 ReinitializeSpellChecker();
initial.commit09911bf2008-07-26 23:55:291339 }
[email protected]20930852008-10-15 19:30:411340
initial.commit09911bf2008-07-26 23:55:291341 return spellchecker_;
1342}
1343
[email protected]3bf335a2009-06-26 20:46:061344WebKitContext* ProfileImpl::GetWebKitContext() {
1345 if (!webkit_context_.get())
1346 webkit_context_ = new WebKitContext(path_, false);
1347 DCHECK(webkit_context_.get());
1348 return webkit_context_.get();
1349}
1350
[email protected]4bb336302009-10-12 05:44:261351DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1352 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1353 if (!desktop_notification_service_.get()) {
1354 // TODO(johnnyg): hook this up with notification UI manager.
1355 desktop_notification_service_.reset(new DesktopNotificationService(
1356 this, NULL));
1357 }
1358
1359 return desktop_notification_service_.get();
1360}
1361
initial.commit09911bf2008-07-26 23:55:291362void ProfileImpl::MarkAsCleanShutdown() {
1363 if (prefs_.get()) {
1364 // The session cleanly exited, set kSessionExitedCleanly appropriately.
1365 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
1366
1367 // NOTE: If you change what thread this writes on, be sure and update
1368 // ChromeFrame::EndSession().
[email protected]6faa0e0d2009-04-28 06:50:361369 prefs_->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:291370 }
1371}
1372
[email protected]e7244d82008-10-29 18:13:261373void ProfileImpl::Observe(NotificationType type,
1374 const NotificationSource& source,
1375 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:561376 if (NotificationType::PREF_CHANGED == type) {
[email protected]e7244d82008-10-29 18:13:261377 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1378 PrefService* prefs = Source<PrefService>(source).ptr();
1379 DCHECK(pref_name_in && prefs);
1380 if (*pref_name_in == prefs::kSpellCheckDictionary ||
[email protected]154a4332009-06-03 20:20:581381 *pref_name_in == prefs::kEnableSpellCheck ||
1382 *pref_name_in == prefs::kEnableAutoSpellCorrect) {
[email protected]e3448ea2009-10-02 01:29:291383 ReinitializeSpellChecker();
[email protected]e7244d82008-10-29 18:13:261384 }
[email protected]4a190632009-05-09 01:07:421385 } else if (NotificationType::THEME_INSTALLED == type) {
1386 Extension* extension = Details<Extension>(details).ptr();
1387 SetTheme(extension);
[email protected]48352c12009-08-15 01:19:111388 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1389 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1390 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1391 Source<Profile>(this));
[email protected]e7244d82008-10-29 18:13:261392 }
1393}
1394
initial.commit09911bf2008-07-26 23:55:291395void ProfileImpl::StopCreateSessionServiceTimer() {
[email protected]2d316662008-09-03 18:18:141396 create_session_service_timer_.Stop();
initial.commit09911bf2008-07-26 23:55:291397}
[email protected]3a453fa2008-08-15 18:46:341398
[email protected]48352c12009-08-15 01:19:111399ProfileSyncService* ProfileImpl::GetProfileSyncService() {
[email protected]066629f2009-10-17 00:28:131400#if defined(BROWSER_SYNC)
[email protected]7367f1a2009-10-10 01:09:441401 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) {
1402 if (!sync_service_.get())
1403 InitSyncService();
1404 return sync_service_.get();
1405 }
1406#endif
[email protected]48352c12009-08-15 01:19:111407 return NULL;
1408}
1409
1410void ProfileImpl::InitSyncService() {
[email protected]066629f2009-10-17 00:28:131411#if defined(BROWSER_SYNC)
[email protected]48352c12009-08-15 01:19:111412 sync_service_.reset(new ProfileSyncService(this));
1413 sync_service_->Initialize();
1414#endif
1415}