Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/profile.cc

Issue 115204: Add a separate cookie store that's used for extensions.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profile.h" 5 #include "chrome/browser/profile.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/sessions/session_service.h" 27 #include "chrome/browser/sessions/session_service.h"
28 #include "chrome/browser/sessions/tab_restore_service.h" 28 #include "chrome/browser/sessions/tab_restore_service.h"
29 #include "chrome/browser/spellchecker.h" 29 #include "chrome/browser/spellchecker.h"
30 #include "chrome/browser/ssl/ssl_host_state.h" 30 #include "chrome/browser/ssl/ssl_host_state.h"
31 #include "chrome/browser/browser_theme_provider.h" 31 #include "chrome/browser/browser_theme_provider.h"
32 #include "chrome/browser/visitedlink_master.h" 32 #include "chrome/browser/visitedlink_master.h"
33 #include "chrome/browser/webdata/web_data_service.h" 33 #include "chrome/browser/webdata/web_data_service.h"
34 #include "chrome/common/chrome_constants.h" 34 #include "chrome/common/chrome_constants.h"
35 #include "chrome/common/chrome_paths.h" 35 #include "chrome/common/chrome_paths.h"
36 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
37 #include "chrome/common/net/cookie_monster_sqlite.h"
37 #include "chrome/common/notification_service.h" 38 #include "chrome/common/notification_service.h"
38 #include "chrome/common/pref_names.h" 39 #include "chrome/common/pref_names.h"
39 #include "chrome/common/render_messages.h" 40 #include "chrome/common/render_messages.h"
40 #include "grit/locale_settings.h" 41 #include "grit/locale_settings.h"
41 42
42 using base::Time; 43 using base::Time;
43 using base::TimeDelta; 44 using base::TimeDelta;
44 45
45 // Delay, in milliseconds, before we explicitly create the SessionService. 46 // Delay, in milliseconds, before we explicitly create the SessionService.
46 static const int kCreateSessionServiceDelayMS = 500; 47 static const int kCreateSessionServiceDelayMS = 500;
47 48
48 // A pointer to the request context for the default profile. See comments on 49 // A pointer to the request context for the default profile. See comments on
49 // Profile::GetDefaultRequestContext. 50 // Profile::GetDefaultRequestContext.
50 URLRequestContext* Profile::default_request_context_; 51 URLRequestContext* Profile::default_request_context_;
51 52
53 static void CleanupRequestContext(ChromeURLRequestContext* context) {
54 if (context) {
55 context->CleanupOnUIThread();
56
57 // Clean up request context on IO thread.
58 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE,
59 context);
60 }
61 }
62
52 // static 63 // static
53 void Profile::RegisterUserPrefs(PrefService* prefs) { 64 void Profile::RegisterUserPrefs(PrefService* prefs) {
54 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); 65 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
55 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); 66 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
56 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); 67 prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
57 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string. 68 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
58 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary, 69 prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
59 IDS_SPELLCHECK_DICTIONARY); 70 IDS_SPELLCHECK_DICTIONARY);
60 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true); 71 prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
61 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false); 72 prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
(...skipping 20 matching lines...) Expand all
82 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile 93 // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
83 // to make it suitable for the off the record mode. 94 // to make it suitable for the off the record mode.
84 // 95 //
85 //////////////////////////////////////////////////////////////////////////////// 96 ////////////////////////////////////////////////////////////////////////////////
86 class OffTheRecordProfileImpl : public Profile, 97 class OffTheRecordProfileImpl : public Profile,
87 public NotificationObserver { 98 public NotificationObserver {
88 public: 99 public:
89 explicit OffTheRecordProfileImpl(Profile* real_profile) 100 explicit OffTheRecordProfileImpl(Profile* real_profile)
90 : profile_(real_profile), 101 : profile_(real_profile),
91 media_request_context_(NULL), 102 media_request_context_(NULL),
103 extensions_request_context_(NULL),
92 start_time_(Time::Now()) { 104 start_time_(Time::Now()) {
93 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); 105 request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this);
94 request_context_->AddRef(); 106 request_context_->AddRef();
95 107
96 extension_process_manager_.reset(new ExtensionProcessManager(this)); 108 extension_process_manager_.reset(new ExtensionProcessManager(this));
97 109
98 // Register for browser close notifications so we can detect when the last 110 // Register for browser close notifications so we can detect when the last
99 // off-the-record window is closed, in which case we can clean our states 111 // off-the-record window is closed, in which case we can clean our states
100 // (cookies, downloads...). 112 // (cookies, downloads...).
101 NotificationService::current()->AddObserver( 113 NotificationService::current()->AddObserver(
102 this, 114 this,
103 NotificationType::BROWSER_CLOSED, 115 NotificationType::BROWSER_CLOSED,
104 NotificationService::AllSources()); 116 NotificationService::AllSources());
105 } 117 }
106 118
107 virtual ~OffTheRecordProfileImpl() { 119 virtual ~OffTheRecordProfileImpl() {
108 if (request_context_) { 120 CleanupRequestContext(request_context_);
109 request_context_->CleanupOnUIThread(); 121 CleanupRequestContext(media_request_context_);
110 122 CleanupRequestContext(extensions_request_context_);
111 // Clean up request context on IO thread.
112 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
113 NewRunnableMethod(request_context_,
114 &base::RefCountedThreadSafe<URLRequestContext>::Release));
115 request_context_ = NULL;
116 }
117 NotificationService::current()->RemoveObserver( 123 NotificationService::current()->RemoveObserver(
118 this, 124 this,
119 NotificationType::BROWSER_CLOSED, 125 NotificationType::BROWSER_CLOSED,
120 NotificationService::AllSources()); 126 NotificationService::AllSources());
121 } 127 }
122 128
123 virtual FilePath GetPath() { return profile_->GetPath(); } 129 virtual FilePath GetPath() { return profile_->GetPath(); }
124 130
125 virtual bool IsOffTheRecord() { 131 virtual bool IsOffTheRecord() {
126 return true; 132 return true;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 media_request_context_ = 250 media_request_context_ =
245 ChromeURLRequestContext::CreateOffTheRecordForMedia( 251 ChromeURLRequestContext::CreateOffTheRecordForMedia(
246 this, cache_path); 252 this, cache_path);
247 media_request_context_->AddRef(); 253 media_request_context_->AddRef();
248 254
249 DCHECK(media_request_context_->cookie_store()); 255 DCHECK(media_request_context_->cookie_store());
250 } 256 }
251 return media_request_context_; 257 return media_request_context_;
252 } 258 }
253 259
260 URLRequestContext* GetRequestContextForExtensions() {
261 if (!extensions_request_context_) {
262 extensions_request_context_ =
263 ChromeURLRequestContext::CreateOffTheRecordForExtensions(this);
264 extensions_request_context_->AddRef();
265
266 DCHECK(extensions_request_context_->cookie_store());
267 }
268
269 return extensions_request_context_;
270 }
271
254 virtual SessionService* GetSessionService() { 272 virtual SessionService* GetSessionService() {
255 // Don't save any sessions when off the record. 273 // Don't save any sessions when off the record.
256 return NULL; 274 return NULL;
257 } 275 }
258 276
259 virtual void ShutdownSessionService() { 277 virtual void ShutdownSessionService() {
260 // We don't allow a session service, nothing to do. 278 // We don't allow a session service, nothing to do.
261 } 279 }
262 280
263 virtual bool HasSessionService() const { 281 virtual bool HasSessionService() const {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 private: 369 private:
352 // The real underlying profile. 370 // The real underlying profile.
353 Profile* profile_; 371 Profile* profile_;
354 372
355 // The context to use for requests made from this OTR session. 373 // The context to use for requests made from this OTR session.
356 ChromeURLRequestContext* request_context_; 374 ChromeURLRequestContext* request_context_;
357 375
358 // The context for requests for media resources. 376 // The context for requests for media resources.
359 ChromeURLRequestContext* media_request_context_; 377 ChromeURLRequestContext* media_request_context_;
360 378
379 ChromeURLRequestContext* extensions_request_context_;
380
361 // The download manager that only stores downloaded items in memory. 381 // The download manager that only stores downloaded items in memory.
362 scoped_refptr<DownloadManager> download_manager_; 382 scoped_refptr<DownloadManager> download_manager_;
363 383
364 // The download manager that only stores downloaded items in memory. 384 // The download manager that only stores downloaded items in memory.
365 scoped_refptr<BrowserThemeProvider> theme_provider_; 385 scoped_refptr<BrowserThemeProvider> theme_provider_;
366 386
367 // We don't want SSLHostState from the OTR profile to leak back to the main 387 // We don't want SSLHostState from the OTR profile to leak back to the main
368 // profile because then the main profile would learn some of the host names 388 // profile because then the main profile would learn some of the host names
369 // the user visited while OTR. 389 // the user visited while OTR.
370 scoped_ptr<SSLHostState> ssl_host_state_; 390 scoped_ptr<SSLHostState> ssl_host_state_;
371 391
372 // Extensions run in a different context in incognito mode. 392 // Extensions run in a different context in incognito mode.
373 scoped_ptr<ExtensionProcessManager> extension_process_manager_; 393 scoped_ptr<ExtensionProcessManager> extension_process_manager_;
374 394
375 // Time we were started. 395 // Time we were started.
376 Time start_time_; 396 Time start_time_;
377 397
378 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl); 398 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl);
379 }; 399 };
380 400
381 ProfileImpl::ProfileImpl(const FilePath& path) 401 ProfileImpl::ProfileImpl(const FilePath& path)
382 : path_(path), 402 : path_(path),
383 request_context_(NULL), 403 request_context_(NULL),
384 media_request_context_(NULL), 404 media_request_context_(NULL),
405 extensions_request_context_(NULL),
385 history_service_created_(false), 406 history_service_created_(false),
386 created_web_data_service_(false), 407 created_web_data_service_(false),
387 created_download_manager_(false), 408 created_download_manager_(false),
388 created_theme_provider_(false), 409 created_theme_provider_(false),
389 start_time_(Time::Now()), 410 start_time_(Time::Now()),
390 spellchecker_(NULL), 411 spellchecker_(NULL),
391 shutdown_session_service_(false) { 412 shutdown_session_service_(false) {
392 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 413 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
393 "profile files to the root directory!"; 414 "profile files to the root directory!";
394 create_session_service_timer_.Start( 415 create_session_service_timer_.Start(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 522
502 if (spellchecker_) { 523 if (spellchecker_) {
503 // The spellchecker must be deleted on the I/O thread. During testing, we 524 // The spellchecker must be deleted on the I/O thread. During testing, we
504 // don't have an I/O thread. 525 // don't have an I/O thread.
505 if (io_thread) 526 if (io_thread)
506 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_); 527 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
507 else 528 else
508 spellchecker_->Release(); 529 spellchecker_->Release();
509 } 530 }
510 531
511 if (request_context_) { 532 if (default_request_context_ == request_context_)
512 request_context_->CleanupOnUIThread(); 533 default_request_context_ = NULL;
513 534
514 if (default_request_context_ == request_context_) 535 CleanupRequestContext(request_context_);
515 default_request_context_ = NULL; 536 CleanupRequestContext(media_request_context_);
516 537 CleanupRequestContext(extensions_request_context_);
517 // Clean up request context on IO thread.
518 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
519 NewRunnableMethod(request_context_,
520 &base::RefCountedThreadSafe<URLRequestContext>::Release));
521 request_context_ = NULL;
522 }
523
524 if (media_request_context_) {
525 media_request_context_->CleanupOnUIThread();
526
527 // Clean up request context on IO thread.
528 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
529 NewRunnableMethod(media_request_context_,
530 &base::RefCountedThreadSafe<URLRequestContext>::Release));
531 media_request_context_ = NULL;
532 }
533 538
534 // HistoryService may call into the BookmarkModel, as such we need to 539 // HistoryService may call into the BookmarkModel, as such we need to
535 // delete HistoryService before the BookmarkModel. The destructor for 540 // delete HistoryService before the BookmarkModel. The destructor for
536 // HistoryService will join with HistoryService's backend thread so that 541 // HistoryService will join with HistoryService's backend thread so that
537 // by the time the destructor has finished we're sure it will no longer call 542 // by the time the destructor has finished we're sure it will no longer call
538 // into the BookmarkModel. 543 // into the BookmarkModel.
539 history_service_ = NULL; 544 history_service_ = NULL;
540 bookmark_bar_model_.reset(); 545 bookmark_bar_model_.reset();
541 546
542 MarkAsCleanShutdown(); 547 MarkAsCleanShutdown();
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( 707 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia(
703 this, cache_path); 708 this, cache_path);
704 media_request_context_->AddRef(); 709 media_request_context_->AddRef();
705 710
706 DCHECK(media_request_context_->cookie_store()); 711 DCHECK(media_request_context_->cookie_store());
707 } 712 }
708 713
709 return media_request_context_; 714 return media_request_context_;
710 } 715 }
711 716
717 URLRequestContext* ProfileImpl::GetRequestContextForExtensions() {
718 if (!extensions_request_context_) {
719 FilePath cookie_path = GetPath();
720 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename);
721
722 extensions_request_context_ =
723 ChromeURLRequestContext::CreateOriginalForExtensions(this, cookie_path);
724 extensions_request_context_->AddRef();
725
726 DCHECK(extensions_request_context_->cookie_store());
727 }
728
729 return extensions_request_context_;
730 }
731
712 HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { 732 HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
713 if (!history_service_created_) { 733 if (!history_service_created_) {
714 history_service_created_ = true; 734 history_service_created_ = true;
715 scoped_refptr<HistoryService> history(new HistoryService(this)); 735 scoped_refptr<HistoryService> history(new HistoryService(this));
716 if (!history->Init(GetPath(), GetBookmarkModel())) 736 if (!history->Init(GetPath(), GetBookmarkModel()))
717 return NULL; 737 return NULL;
718 history_service_.swap(history); 738 history_service_.swap(history);
719 739
720 // Send out the notification that the history service was created. 740 // Send out the notification that the history service was created.
721 NotificationService::current()-> 741 NotificationService::current()->
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 998
979 void ProfileImpl::StopCreateSessionServiceTimer() { 999 void ProfileImpl::StopCreateSessionServiceTimer() {
980 create_session_service_timer_.Stop(); 1000 create_session_service_timer_.Stop();
981 } 1001 }
982 1002
983 #ifdef CHROME_PERSONALIZATION 1003 #ifdef CHROME_PERSONALIZATION
984 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { 1004 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() {
985 return personalization_.get(); 1005 return personalization_.get();
986 } 1006 }
987 #endif 1007 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698