| OLD | NEW |
| 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 29 matching lines...) Expand all Loading... |
| 40 #include "chrome/common/net/cookie_monster_sqlite.h" | 40 #include "chrome/common/net/cookie_monster_sqlite.h" |
| 41 #include "chrome/common/notification_service.h" | 41 #include "chrome/common/notification_service.h" |
| 42 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/common/render_messages.h" | 43 #include "chrome/common/render_messages.h" |
| 44 #include "grit/locale_settings.h" | 44 #include "grit/locale_settings.h" |
| 45 #include "net/base/force_tls_state.h" | 45 #include "net/base/force_tls_state.h" |
| 46 | 46 |
| 47 using base::Time; | 47 using base::Time; |
| 48 using base::TimeDelta; | 48 using base::TimeDelta; |
| 49 | 49 |
| 50 namespace { |
| 51 |
| 50 // Delay, in milliseconds, before we explicitly create the SessionService. | 52 // Delay, in milliseconds, before we explicitly create the SessionService. |
| 51 static const int kCreateSessionServiceDelayMS = 500; | 53 static const int kCreateSessionServiceDelayMS = 500; |
| 52 | 54 |
| 55 enum ContextType { |
| 56 kNormalContext, |
| 57 kMediaContext |
| 58 }; |
| 59 |
| 60 // Gets the cache parameters from the command line. |type| is the type of |
| 61 // request context that we need, |cache_path| will be set to the user provided |
| 62 // path, or will not be touched if there is not an argument. |max_size| will |
| 63 // be the user provided value or zero by default. |
| 64 void GetCacheParameters(ContextType type, FilePath* cache_path, |
| 65 int* max_size) { |
| 66 DCHECK(cache_path); |
| 67 DCHECK(max_size); |
| 68 |
| 69 // Override the cache location if specified by the user. |
| 70 std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue( |
| 71 switches::kDiskCacheDir)); |
| 72 |
| 73 if (!user_path.empty()) { |
| 74 *cache_path = FilePath::FromWStringHack(user_path); |
| 75 } |
| 76 |
| 77 const wchar_t* arg = kNormalContext == type ? switches::kDiskCacheSize : |
| 78 switches::kMediaCacheSize; |
| 79 std::string value = |
| 80 WideToASCII(CommandLine::ForCurrentProcess()->GetSwitchValue(arg)); |
| 81 |
| 82 // By default we let the cache determine the right size. |
| 83 *max_size = 0; |
| 84 if (!StringToInt(value, max_size)) { |
| 85 *max_size = 0; |
| 86 } else if (max_size < 0) { |
| 87 *max_size = 0; |
| 88 } |
| 89 } |
| 90 |
| 91 } // namespace |
| 92 |
| 53 // A pointer to the request context for the default profile. See comments on | 93 // A pointer to the request context for the default profile. See comments on |
| 54 // Profile::GetDefaultRequestContext. | 94 // Profile::GetDefaultRequestContext. |
| 55 URLRequestContext* Profile::default_request_context_; | 95 URLRequestContext* Profile::default_request_context_; |
| 56 | 96 |
| 57 static void CleanupRequestContext(ChromeURLRequestContext* context) { | 97 static void CleanupRequestContext(ChromeURLRequestContext* context) { |
| 58 if (context) { | 98 if (context) { |
| 59 context->CleanupOnUIThread(); | 99 context->CleanupOnUIThread(); |
| 60 | 100 |
| 61 // Clean up request context on IO thread. | 101 // Clean up request context on IO thread. |
| 62 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE, | 102 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE, |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 FilePath pref_file_path = path_; | 736 FilePath pref_file_path = path_; |
| 697 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); | 737 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); |
| 698 return pref_file_path; | 738 return pref_file_path; |
| 699 } | 739 } |
| 700 | 740 |
| 701 URLRequestContext* ProfileImpl::GetRequestContext() { | 741 URLRequestContext* ProfileImpl::GetRequestContext() { |
| 702 if (!request_context_) { | 742 if (!request_context_) { |
| 703 FilePath cookie_path = GetPath(); | 743 FilePath cookie_path = GetPath(); |
| 704 cookie_path = cookie_path.Append(chrome::kCookieFilename); | 744 cookie_path = cookie_path.Append(chrome::kCookieFilename); |
| 705 FilePath cache_path = GetPath(); | 745 FilePath cache_path = GetPath(); |
| 706 | 746 int max_size; |
| 707 // Override the cache location if specified by the user. | 747 GetCacheParameters(kNormalContext, &cache_path, &max_size); |
| 708 const std::wstring user_cache_dir( | |
| 709 CommandLine::ForCurrentProcess()->GetSwitchValue( | |
| 710 switches::kDiskCacheDir)); | |
| 711 if (!user_cache_dir.empty()) { | |
| 712 cache_path = FilePath::FromWStringHack(user_cache_dir); | |
| 713 } | |
| 714 | 748 |
| 715 cache_path = cache_path.Append(chrome::kCacheDirname); | 749 cache_path = cache_path.Append(chrome::kCacheDirname); |
| 716 request_context_ = ChromeURLRequestContext::CreateOriginal( | 750 request_context_ = ChromeURLRequestContext::CreateOriginal( |
| 717 this, cookie_path, cache_path); | 751 this, cookie_path, cache_path, max_size); |
| 718 request_context_->AddRef(); | 752 request_context_->AddRef(); |
| 719 | 753 |
| 720 // The first request context is always a normal (non-OTR) request context. | 754 // The first request context is always a normal (non-OTR) request context. |
| 721 // Even when Chromium is started in OTR mode, a normal profile is always | 755 // Even when Chromium is started in OTR mode, a normal profile is always |
| 722 // created first. | 756 // created first. |
| 723 if (!default_request_context_) { | 757 if (!default_request_context_) { |
| 724 default_request_context_ = request_context_; | 758 default_request_context_ = request_context_; |
| 725 NotificationService::current()->Notify( | 759 NotificationService::current()->Notify( |
| 726 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 760 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
| 727 NotificationService::AllSources(), NotificationService::NoDetails()); | 761 NotificationService::AllSources(), NotificationService::NoDetails()); |
| 728 } | 762 } |
| 729 | 763 |
| 730 DCHECK(request_context_->cookie_store()); | 764 DCHECK(request_context_->cookie_store()); |
| 731 } | 765 } |
| 732 | 766 |
| 733 return request_context_; | 767 return request_context_; |
| 734 } | 768 } |
| 735 | 769 |
| 736 URLRequestContext* ProfileImpl::GetRequestContextForMedia() { | 770 URLRequestContext* ProfileImpl::GetRequestContextForMedia() { |
| 737 if (!media_request_context_) { | 771 if (!media_request_context_) { |
| 738 FilePath cache_path = GetPath(); | 772 FilePath cache_path = GetPath(); |
| 739 | 773 int max_size; |
| 740 // Override the cache location if specified by the user. | 774 GetCacheParameters(kMediaContext, &cache_path, &max_size); |
| 741 const std::wstring user_cache_dir( | |
| 742 CommandLine::ForCurrentProcess()->GetSwitchValue( | |
| 743 switches::kDiskCacheDir)); | |
| 744 if (!user_cache_dir.empty()) { | |
| 745 cache_path = FilePath::FromWStringHack(user_cache_dir); | |
| 746 } | |
| 747 | 775 |
| 748 cache_path = cache_path.Append(chrome::kMediaCacheDirname); | 776 cache_path = cache_path.Append(chrome::kMediaCacheDirname); |
| 749 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( | 777 media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( |
| 750 this, cache_path); | 778 this, cache_path, max_size); |
| 751 media_request_context_->AddRef(); | 779 media_request_context_->AddRef(); |
| 752 | 780 |
| 753 DCHECK(media_request_context_->cookie_store()); | 781 DCHECK(media_request_context_->cookie_store()); |
| 754 } | 782 } |
| 755 | 783 |
| 756 return media_request_context_; | 784 return media_request_context_; |
| 757 } | 785 } |
| 758 | 786 |
| 759 URLRequestContext* ProfileImpl::GetRequestContextForExtensions() { | 787 URLRequestContext* ProfileImpl::GetRequestContextForExtensions() { |
| 760 if (!extensions_request_context_) { | 788 if (!extensions_request_context_) { |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 | 1124 |
| 1097 void ProfileImpl::StopCreateSessionServiceTimer() { | 1125 void ProfileImpl::StopCreateSessionServiceTimer() { |
| 1098 create_session_service_timer_.Stop(); | 1126 create_session_service_timer_.Stop(); |
| 1099 } | 1127 } |
| 1100 | 1128 |
| 1101 #ifdef CHROME_PERSONALIZATION | 1129 #ifdef CHROME_PERSONALIZATION |
| 1102 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { | 1130 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { |
| 1103 return personalization_.get(); | 1131 return personalization_.get(); |
| 1104 } | 1132 } |
| 1105 #endif | 1133 #endif |
| OLD | NEW |