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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 308 |
309 context->set_ftp_transaction_factory( | 309 context->set_ftp_transaction_factory( |
310 new net::FtpNetworkLayer(context->host_resolver())); | 310 new net::FtpNetworkLayer(context->host_resolver())); |
311 | 311 |
312 // setup cookie store | 312 // setup cookie store |
313 if (!context->cookie_store()) { | 313 if (!context->cookie_store()) { |
314 DCHECK(!cookie_store_path_.empty()); | 314 DCHECK(!cookie_store_path_.empty()); |
315 | 315 |
316 scoped_refptr<SQLitePersistentCookieStore> cookie_db = | 316 scoped_refptr<SQLitePersistentCookieStore> cookie_db = |
317 new SQLitePersistentCookieStore(cookie_store_path_); | 317 new SQLitePersistentCookieStore(cookie_store_path_); |
| 318 cookie_db->SetClearLocalStateOnExit(clear_local_state_on_exit_); |
318 context->set_cookie_store(new net::CookieMonster(cookie_db.get(), | 319 context->set_cookie_store(new net::CookieMonster(cookie_db.get(), |
319 cookie_monster_delegate_)); | 320 cookie_monster_delegate_)); |
320 } | 321 } |
321 | 322 |
322 context->set_cookie_policy( | 323 context->set_cookie_policy( |
323 new ChromeCookiePolicy(host_content_settings_map_)); | 324 new ChromeCookiePolicy(host_content_settings_map_)); |
324 | 325 |
325 appcache_service_->set_request_context(context); | 326 appcache_service_->set_request_context(context); |
326 | 327 |
327 context->set_net_log(io_thread()->net_log()); | 328 context->set_net_log(io_thread()->net_log()); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 accept_language)); | 699 accept_language)); |
699 } else if (*pref_name_in == prefs::kDefaultCharset) { | 700 } else if (*pref_name_in == prefs::kDefaultCharset) { |
700 std::string default_charset = | 701 std::string default_charset = |
701 prefs->GetString(prefs::kDefaultCharset); | 702 prefs->GetString(prefs::kDefaultCharset); |
702 BrowserThread::PostTask( | 703 BrowserThread::PostTask( |
703 BrowserThread::IO, FROM_HERE, | 704 BrowserThread::IO, FROM_HERE, |
704 NewRunnableMethod( | 705 NewRunnableMethod( |
705 this, | 706 this, |
706 &ChromeURLRequestContextGetter::OnDefaultCharsetChange, | 707 &ChromeURLRequestContextGetter::OnDefaultCharsetChange, |
707 default_charset)); | 708 default_charset)); |
| 709 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { |
| 710 bool clear_site_data = |
| 711 prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
| 712 BrowserThread::PostTask( |
| 713 BrowserThread::IO, FROM_HERE, |
| 714 NewRunnableMethod( |
| 715 this, |
| 716 &ChromeURLRequestContextGetter::OnClearSiteDataOnExitChange, |
| 717 clear_site_data)); |
708 } | 718 } |
709 } else { | 719 } else { |
710 NOTREACHED(); | 720 NOTREACHED(); |
711 } | 721 } |
712 } | 722 } |
713 | 723 |
714 void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) { | 724 void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) { |
715 CheckCurrentlyOnMainThread(); | 725 CheckCurrentlyOnMainThread(); |
716 | 726 |
717 registrar_.Init(profile->GetPrefs()); | 727 registrar_.Init(profile->GetPrefs()); |
718 registrar_.Add(prefs::kAcceptLanguages, this); | 728 registrar_.Add(prefs::kAcceptLanguages, this); |
719 registrar_.Add(prefs::kDefaultCharset, this); | 729 registrar_.Add(prefs::kDefaultCharset, this); |
| 730 registrar_.Add(prefs::kClearSiteDataOnExit, this); |
720 } | 731 } |
721 | 732 |
722 // static | 733 // static |
723 ChromeURLRequestContextGetter* | 734 ChromeURLRequestContextGetter* |
724 ChromeURLRequestContextGetter::CreateRequestContextForMedia( | 735 ChromeURLRequestContextGetter::CreateRequestContextForMedia( |
725 Profile* profile, const FilePath& disk_cache_path, int cache_size, | 736 Profile* profile, const FilePath& disk_cache_path, int cache_size, |
726 bool off_the_record) { | 737 bool off_the_record) { |
727 return new ChromeURLRequestContextGetter( | 738 return new ChromeURLRequestContextGetter( |
728 profile, | 739 profile, |
729 new FactoryForMedia(profile, | 740 new FactoryForMedia(profile, |
730 disk_cache_path, | 741 disk_cache_path, |
731 cache_size, | 742 cache_size, |
732 off_the_record)); | 743 off_the_record)); |
733 } | 744 } |
734 | 745 |
735 void ChromeURLRequestContextGetter::OnAcceptLanguageChange( | 746 void ChromeURLRequestContextGetter::OnAcceptLanguageChange( |
736 const std::string& accept_language) { | 747 const std::string& accept_language) { |
737 GetIOContext()->OnAcceptLanguageChange(accept_language); | 748 GetIOContext()->OnAcceptLanguageChange(accept_language); |
738 } | 749 } |
739 | 750 |
740 void ChromeURLRequestContextGetter::OnDefaultCharsetChange( | 751 void ChromeURLRequestContextGetter::OnDefaultCharsetChange( |
741 const std::string& default_charset) { | 752 const std::string& default_charset) { |
742 GetIOContext()->OnDefaultCharsetChange(default_charset); | 753 GetIOContext()->OnDefaultCharsetChange(default_charset); |
743 } | 754 } |
744 | 755 |
| 756 void ChromeURLRequestContextGetter::OnClearSiteDataOnExitChange( |
| 757 bool clear_site_data) { |
| 758 GetCookieStore()->GetCookieMonster()-> |
| 759 SetClearPersistentStoreOnExit(clear_site_data); |
| 760 } |
| 761 |
745 void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper( | 762 void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper( |
746 base::WaitableEvent* completion, | 763 base::WaitableEvent* completion, |
747 net::CookieStore** result) { | 764 net::CookieStore** result) { |
748 // Note that CookieStore is refcounted, yet we do not add a reference. | 765 // Note that CookieStore is refcounted, yet we do not add a reference. |
749 *result = GetURLRequestContext()->cookie_store(); | 766 *result = GetURLRequestContext()->cookie_store(); |
750 completion->Signal(); | 767 completion->Signal(); |
751 } | 768 } |
752 | 769 |
753 // ---------------------------------------------------------------------------- | 770 // ---------------------------------------------------------------------------- |
754 // ChromeURLRequestContext | 771 // ChromeURLRequestContext |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 io_thread_(g_browser_process->io_thread()) { | 892 io_thread_(g_browser_process->io_thread()) { |
876 CheckCurrentlyOnMainThread(); | 893 CheckCurrentlyOnMainThread(); |
877 PrefService* prefs = profile->GetPrefs(); | 894 PrefService* prefs = profile->GetPrefs(); |
878 | 895 |
879 // Set up Accept-Language and Accept-Charset header values | 896 // Set up Accept-Language and Accept-Charset header values |
880 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( | 897 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( |
881 prefs->GetString(prefs::kAcceptLanguages)); | 898 prefs->GetString(prefs::kAcceptLanguages)); |
882 std::string default_charset = prefs->GetString(prefs::kDefaultCharset); | 899 std::string default_charset = prefs->GetString(prefs::kDefaultCharset); |
883 accept_charset_ = | 900 accept_charset_ = |
884 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); | 901 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); |
| 902 clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
885 | 903 |
886 // At this point, we don't know the charset of the referring page | 904 // 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 | 905 // where a url request originates from. This is used to get a suggested |
888 // filename from Content-Disposition header made of raw 8bit characters. | 906 // filename from Content-Disposition header made of raw 8bit characters. |
889 // Down the road, it can be overriden if it becomes known (for instance, | 907 // 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). | 908 // when download request is made through the context menu in a web page). |
891 // At the moment, it'll remain 'undeterministic' when a user | 909 // 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. | 910 // 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. | 911 // For the latter, we need a change on the webkit-side. |
894 // We initialize it to the default charset here and a user will | 912 // We initialize it to the default charset here and a user will |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 context->set_host_zoom_map(host_zoom_map_); | 950 context->set_host_zoom_map(host_zoom_map_); |
933 context->set_transport_security_state( | 951 context->set_transport_security_state( |
934 transport_security_state_); | 952 transport_security_state_); |
935 context->set_ssl_config_service(ssl_config_service_); | 953 context->set_ssl_config_service(ssl_config_service_); |
936 context->set_appcache_service(appcache_service_); | 954 context->set_appcache_service(appcache_service_); |
937 context->set_database_tracker(database_tracker_); | 955 context->set_database_tracker(database_tracker_); |
938 context->set_blob_storage_context(blob_storage_context_); | 956 context->set_blob_storage_context(blob_storage_context_); |
939 context->set_browser_file_system_context(browser_file_system_context_); | 957 context->set_browser_file_system_context(browser_file_system_context_); |
940 context->set_extension_info_map(extension_info_map_); | 958 context->set_extension_info_map(extension_info_map_); |
941 } | 959 } |
OLD | NEW |