OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 #include "webkit/glue/webkit_glue.h" | 39 #include "webkit/glue/webkit_glue.h" |
40 | 40 |
41 #if defined(USE_NSS) | 41 #if defined(USE_NSS) |
42 #include "net/ocsp/nss_ocsp.h" | 42 #include "net/ocsp/nss_ocsp.h" |
43 #endif | 43 #endif |
44 | 44 |
45 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
46 #include "chrome/browser/chromeos/proxy_config_service.h" | 46 #include "chrome/browser/chromeos/proxy_config_service.h" |
47 #endif // defined(OS_CHROMEOS) | 47 #endif // defined(OS_CHROMEOS) |
48 | 48 |
49 using net::CookieMonster; | |
Randy Smith (Not in Mondays)
2010/12/01 20:39:50
The Chrome style guide forbids "using" directives.
pastarmovj
2010/12/02 14:54:36
Done.
| |
50 | |
49 namespace { | 51 namespace { |
50 | 52 |
51 // ---------------------------------------------------------------------------- | 53 // ---------------------------------------------------------------------------- |
52 // Helper methods to check current thread | 54 // Helper methods to check current thread |
53 // ---------------------------------------------------------------------------- | 55 // ---------------------------------------------------------------------------- |
54 | 56 |
55 void CheckCurrentlyOnIOThread() { | 57 void CheckCurrentlyOnIOThread() { |
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
57 } | 59 } |
58 | 60 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 DCHECK(factory); | 537 DCHECK(factory); |
536 | 538 |
537 // If a base profile was specified, listen for changes to the preferences. | 539 // If a base profile was specified, listen for changes to the preferences. |
538 if (profile) | 540 if (profile) |
539 RegisterPrefsObserver(profile); | 541 RegisterPrefsObserver(profile); |
540 } | 542 } |
541 | 543 |
542 ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() { | 544 ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() { |
543 CheckCurrentlyOnIOThread(); | 545 CheckCurrentlyOnIOThread(); |
544 | 546 |
547 // Clean up the local state of the context if it was created. | |
548 if (url_request_context_.get()) { | |
549 ChromeURLRequestContext* chrome_url_request_context = | |
550 static_cast<ChromeURLRequestContext*>(url_request_context_.get()); | |
551 chrome_url_request_context->ClearLocalState(); | |
552 } | |
Randy Smith (Not in Mondays)
2010/12/01 20:39:50
It looks to me as if the other url request context
| |
553 | |
545 DCHECK(registrar_.IsEmpty()) << "Probably didn't call CleanupOnUIThread"; | 554 DCHECK(registrar_.IsEmpty()) << "Probably didn't call CleanupOnUIThread"; |
546 | 555 |
547 // Either we already transformed the factory into a URLRequestContext, or | 556 // Either we already transformed the factory into a URLRequestContext, or |
548 // we still have a pending factory. | 557 // we still have a pending factory. |
549 DCHECK((factory_.get() && !url_request_context_.get()) || | 558 DCHECK((factory_.get() && !url_request_context_.get()) || |
550 (!factory_.get() && url_request_context_.get())); | 559 (!factory_.get() && url_request_context_.get())); |
551 | 560 |
552 if (url_request_context_) | 561 if (url_request_context_) |
553 io_thread_->UnregisterURLRequestContextGetter(this); | 562 io_thread_->UnregisterURLRequestContextGetter(this); |
554 | 563 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 accept_language)); | 707 accept_language)); |
699 } else if (*pref_name_in == prefs::kDefaultCharset) { | 708 } else if (*pref_name_in == prefs::kDefaultCharset) { |
700 std::string default_charset = | 709 std::string default_charset = |
701 prefs->GetString(prefs::kDefaultCharset); | 710 prefs->GetString(prefs::kDefaultCharset); |
702 BrowserThread::PostTask( | 711 BrowserThread::PostTask( |
703 BrowserThread::IO, FROM_HERE, | 712 BrowserThread::IO, FROM_HERE, |
704 NewRunnableMethod( | 713 NewRunnableMethod( |
705 this, | 714 this, |
706 &ChromeURLRequestContextGetter::OnDefaultCharsetChange, | 715 &ChromeURLRequestContextGetter::OnDefaultCharsetChange, |
707 default_charset)); | 716 default_charset)); |
717 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { | |
718 bool clear_site_data = | |
719 prefs->GetBoolean(prefs::kClearSiteDataOnExit); | |
720 BrowserThread::PostTask( | |
721 BrowserThread::IO, FROM_HERE, | |
722 NewRunnableMethod( | |
723 this, | |
724 &ChromeURLRequestContextGetter::OnClearSiteDataOnExitChange, | |
725 clear_site_data)); | |
708 } | 726 } |
709 } else { | 727 } else { |
710 NOTREACHED(); | 728 NOTREACHED(); |
711 } | 729 } |
712 } | 730 } |
713 | 731 |
714 void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) { | 732 void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) { |
715 CheckCurrentlyOnMainThread(); | 733 CheckCurrentlyOnMainThread(); |
716 | 734 |
717 registrar_.Init(profile->GetPrefs()); | 735 registrar_.Init(profile->GetPrefs()); |
718 registrar_.Add(prefs::kAcceptLanguages, this); | 736 registrar_.Add(prefs::kAcceptLanguages, this); |
719 registrar_.Add(prefs::kDefaultCharset, this); | 737 registrar_.Add(prefs::kDefaultCharset, this); |
738 registrar_.Add(prefs::kClearSiteDataOnExit, this); | |
720 } | 739 } |
721 | 740 |
722 // static | 741 // static |
723 ChromeURLRequestContextGetter* | 742 ChromeURLRequestContextGetter* |
724 ChromeURLRequestContextGetter::CreateRequestContextForMedia( | 743 ChromeURLRequestContextGetter::CreateRequestContextForMedia( |
725 Profile* profile, const FilePath& disk_cache_path, int cache_size, | 744 Profile* profile, const FilePath& disk_cache_path, int cache_size, |
726 bool off_the_record) { | 745 bool off_the_record) { |
727 return new ChromeURLRequestContextGetter( | 746 return new ChromeURLRequestContextGetter( |
728 profile, | 747 profile, |
729 new FactoryForMedia(profile, | 748 new FactoryForMedia(profile, |
730 disk_cache_path, | 749 disk_cache_path, |
731 cache_size, | 750 cache_size, |
732 off_the_record)); | 751 off_the_record)); |
733 } | 752 } |
734 | 753 |
735 void ChromeURLRequestContextGetter::OnAcceptLanguageChange( | 754 void ChromeURLRequestContextGetter::OnAcceptLanguageChange( |
736 const std::string& accept_language) { | 755 const std::string& accept_language) { |
737 GetIOContext()->OnAcceptLanguageChange(accept_language); | 756 GetIOContext()->OnAcceptLanguageChange(accept_language); |
738 } | 757 } |
739 | 758 |
740 void ChromeURLRequestContextGetter::OnDefaultCharsetChange( | 759 void ChromeURLRequestContextGetter::OnDefaultCharsetChange( |
741 const std::string& default_charset) { | 760 const std::string& default_charset) { |
742 GetIOContext()->OnDefaultCharsetChange(default_charset); | 761 GetIOContext()->OnDefaultCharsetChange(default_charset); |
743 } | 762 } |
744 | 763 |
764 void ChromeURLRequestContextGetter::OnClearSiteDataOnExitChange( | |
765 bool clear_site_data) { | |
766 GetIOContext()->set_clear_local_state_on_exit(clear_site_data); | |
767 } | |
768 | |
745 void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper( | 769 void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper( |
746 base::WaitableEvent* completion, | 770 base::WaitableEvent* completion, |
747 net::CookieStore** result) { | 771 net::CookieStore** result) { |
748 // Note that CookieStore is refcounted, yet we do not add a reference. | 772 // Note that CookieStore is refcounted, yet we do not add a reference. |
749 *result = GetURLRequestContext()->cookie_store(); | 773 *result = GetURLRequestContext()->cookie_store(); |
750 completion->Signal(); | 774 completion->Signal(); |
751 } | 775 } |
752 | 776 |
753 // ---------------------------------------------------------------------------- | 777 // ---------------------------------------------------------------------------- |
754 // ChromeURLRequestContext | 778 // ChromeURLRequestContext |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 appcache_service_ = other->appcache_service_; | 861 appcache_service_ = other->appcache_service_; |
838 database_tracker_ = other->database_tracker_; | 862 database_tracker_ = other->database_tracker_; |
839 chrome_cookie_policy_ = other->chrome_cookie_policy_; | 863 chrome_cookie_policy_ = other->chrome_cookie_policy_; |
840 host_content_settings_map_ = other->host_content_settings_map_; | 864 host_content_settings_map_ = other->host_content_settings_map_; |
841 host_zoom_map_ = other->host_zoom_map_; | 865 host_zoom_map_ = other->host_zoom_map_; |
842 is_media_ = other->is_media_; | 866 is_media_ = other->is_media_; |
843 is_off_the_record_ = other->is_off_the_record_; | 867 is_off_the_record_ = other->is_off_the_record_; |
844 blob_storage_context_ = other->blob_storage_context_; | 868 blob_storage_context_ = other->blob_storage_context_; |
845 browser_file_system_context_ = other->browser_file_system_context_; | 869 browser_file_system_context_ = other->browser_file_system_context_; |
846 extension_info_map_ = other->extension_info_map_; | 870 extension_info_map_ = other->extension_info_map_; |
871 clear_local_state_on_exit_ = other->clear_local_state_on_exit_; | |
847 } | 872 } |
848 | 873 |
849 void ChromeURLRequestContext::OnAcceptLanguageChange( | 874 void ChromeURLRequestContext::OnAcceptLanguageChange( |
850 const std::string& accept_language) { | 875 const std::string& accept_language) { |
851 CheckCurrentlyOnIOThread(); | 876 CheckCurrentlyOnIOThread(); |
852 accept_language_ = | 877 accept_language_ = |
853 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language); | 878 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language); |
854 } | 879 } |
855 | 880 |
856 void ChromeURLRequestContext::OnDefaultCharsetChange( | 881 void ChromeURLRequestContext::OnDefaultCharsetChange( |
857 const std::string& default_charset) { | 882 const std::string& default_charset) { |
858 CheckCurrentlyOnIOThread(); | 883 CheckCurrentlyOnIOThread(); |
859 referrer_charset_ = default_charset; | 884 referrer_charset_ = default_charset; |
860 accept_charset_ = | 885 accept_charset_ = |
861 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); | 886 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); |
862 } | 887 } |
863 | 888 |
889 void ChromeURLRequestContext::ClearLocalState() | |
890 { | |
Mattias Nissler (ping if slow)
2010/12/01 17:23:24
brace goes on previous line.
pastarmovj
2010/12/02 14:54:36
Done.
| |
891 CheckCurrentlyOnIOThread(); | |
892 if (clear_local_state_on_exit_) { | |
893 scoped_refptr<CookieMonster::PersistentCookieStore> store = | |
894 cookie_store_->GetCookieMonster()->GetPersistentCookieStore(); | |
895 cookie_store_->GetCookieMonster()->DetachPersistentCookieStore(); | |
896 BrowserThread::PostTask( | |
897 BrowserThread::FILE, | |
898 FROM_HERE, | |
899 NewRunnableMethod( | |
900 store.get(), | |
901 &CookieMonster::PersistentCookieStore::ClearLocalState)); | |
902 } | |
903 } | |
904 | |
864 // ---------------------------------------------------------------------------- | 905 // ---------------------------------------------------------------------------- |
865 // ChromeURLRequestContextFactory | 906 // ChromeURLRequestContextFactory |
866 // ---------------------------------------------------------------------------- | 907 // ---------------------------------------------------------------------------- |
867 | 908 |
868 // Extract values from |profile| and copy them into | 909 // Extract values from |profile| and copy them into |
869 // ChromeURLRequestContextFactory. We will use them later when constructing the | 910 // ChromeURLRequestContextFactory. We will use them later when constructing the |
870 // ChromeURLRequestContext on the IO thread (see | 911 // ChromeURLRequestContext on the IO thread (see |
871 // ApplyProfileParametersToContext() which reverses this). | 912 // ApplyProfileParametersToContext() which reverses this). |
872 ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile) | 913 ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile) |
873 : is_media_(false), | 914 : is_media_(false), |
874 is_off_the_record_(profile->IsOffTheRecord()), | 915 is_off_the_record_(profile->IsOffTheRecord()), |
875 io_thread_(g_browser_process->io_thread()) { | 916 io_thread_(g_browser_process->io_thread()) { |
876 CheckCurrentlyOnMainThread(); | 917 CheckCurrentlyOnMainThread(); |
877 PrefService* prefs = profile->GetPrefs(); | 918 PrefService* prefs = profile->GetPrefs(); |
878 | 919 |
879 // Set up Accept-Language and Accept-Charset header values | 920 // Set up Accept-Language and Accept-Charset header values |
880 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( | 921 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( |
881 prefs->GetString(prefs::kAcceptLanguages)); | 922 prefs->GetString(prefs::kAcceptLanguages)); |
882 std::string default_charset = prefs->GetString(prefs::kDefaultCharset); | 923 std::string default_charset = prefs->GetString(prefs::kDefaultCharset); |
883 accept_charset_ = | 924 accept_charset_ = |
884 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); | 925 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); |
926 clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); | |
885 | 927 |
886 // At this point, we don't know the charset of the referring page | 928 // At this point, we don't know the charset of the referring page |
887 // where a url request originates from. This is used to get a suggested | 929 // where a url request originates from. This is used to get a suggested |
888 // filename from Content-Disposition header made of raw 8bit characters. | 930 // filename from Content-Disposition header made of raw 8bit characters. |
889 // Down the road, it can be overriden if it becomes known (for instance, | 931 // Down the road, it can be overriden if it becomes known (for instance, |
890 // when download request is made through the context menu in a web page). | 932 // when download request is made through the context menu in a web page). |
891 // At the moment, it'll remain 'undeterministic' when a user | 933 // At the moment, it'll remain 'undeterministic' when a user |
892 // types a URL in the omnibar or click on a download link in a page. | 934 // types a URL in the omnibar or click on a download link in a page. |
893 // For the latter, we need a change on the webkit-side. | 935 // For the latter, we need a change on the webkit-side. |
894 // We initialize it to the default charset here and a user will | 936 // We initialize it to the default charset here and a user will |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
931 context->set_host_content_settings_map(host_content_settings_map_); | 973 context->set_host_content_settings_map(host_content_settings_map_); |
932 context->set_host_zoom_map(host_zoom_map_); | 974 context->set_host_zoom_map(host_zoom_map_); |
933 context->set_transport_security_state( | 975 context->set_transport_security_state( |
934 transport_security_state_); | 976 transport_security_state_); |
935 context->set_ssl_config_service(ssl_config_service_); | 977 context->set_ssl_config_service(ssl_config_service_); |
936 context->set_appcache_service(appcache_service_); | 978 context->set_appcache_service(appcache_service_); |
937 context->set_database_tracker(database_tracker_); | 979 context->set_database_tracker(database_tracker_); |
938 context->set_blob_storage_context(blob_storage_context_); | 980 context->set_blob_storage_context(blob_storage_context_); |
939 context->set_browser_file_system_context(browser_file_system_context_); | 981 context->set_browser_file_system_context(browser_file_system_context_); |
940 context->set_extension_info_map(extension_info_map_); | 982 context->set_extension_info_map(extension_info_map_); |
983 context->set_clear_local_state_on_exit(clear_local_state_on_exit_); | |
941 } | 984 } |
OLD | NEW |