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" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
14 #include "chrome/browser/extensions/extensions_service.h" | 14 #include "chrome/browser/extensions/extensions_service.h" |
15 #include "chrome/browser/extensions/user_script_master.h" | 15 #include "chrome/browser/extensions/user_script_master.h" |
16 #include "chrome/browser/io_thread.h" | 16 #include "chrome/browser/io_thread.h" |
17 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 17 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
18 #include "chrome/browser/net/chrome_net_log.h" | 18 #include "chrome/browser/net/chrome_net_log.h" |
19 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 19 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
20 #include "chrome/browser/net/predictor_api.h" | 20 #include "chrome/browser/net/predictor_api.h" |
21 #include "chrome/browser/net/pref_proxy_config_service.h" | |
21 #include "chrome/browser/profile.h" | 22 #include "chrome/browser/profile.h" |
22 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
25 #include "chrome/common/notification_service.h" | 26 #include "chrome/common/notification_service.h" |
26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
28 #include "net/base/static_cookie_policy.h" | 29 #include "net/base/static_cookie_policy.h" |
29 #include "net/ftp/ftp_network_layer.h" | 30 #include "net/ftp/ftp_network_layer.h" |
30 #include "net/http/http_cache.h" | 31 #include "net/http/http_cache.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
60 | 61 |
61 // ---------------------------------------------------------------------------- | 62 // ---------------------------------------------------------------------------- |
62 // Helper methods to initialize proxy | 63 // Helper methods to initialize proxy |
63 // ---------------------------------------------------------------------------- | 64 // ---------------------------------------------------------------------------- |
64 | 65 |
65 net::ProxyConfigService* CreateProxyConfigService(Profile* profile) { | 66 net::ProxyConfigService* CreateProxyConfigService(Profile* profile) { |
66 // The linux gconf-based proxy settings getter relies on being initialized | 67 // The linux gconf-based proxy settings getter relies on being initialized |
67 // from the UI thread. | 68 // from the UI thread. |
68 CheckCurrentlyOnMainThread(); | 69 CheckCurrentlyOnMainThread(); |
69 | 70 |
70 scoped_ptr<net::ProxyConfig> proxy_config(CreateProxyConfig( | 71 // Create a baseline service that provides proxy configuration in case nothing |
71 profile->GetPrefs())); | 72 // is configured through prefs (NB: prefs include command line and |
eroman
2010/11/17 02:14:49
What does "NB:" mean?
Mattias Nissler (ping if slow)
2010/11/17 12:55:37
Nota bene. Changed it to "Note".
Done.
| |
73 // configuration policy). | |
74 net::ProxyConfigService* base_service = NULL; | |
72 | 75 |
73 if (!proxy_config.get()) { | 76 // TODO(port): the IO and FILE message loops are only used by Linux. Can |
74 // Use system settings. | 77 // that code be moved to chrome/browser instead of being in net, so that it |
75 // TODO(port): the IO and FILE message loops are only used by Linux. Can | 78 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. |
76 // that code be moved to chrome/browser instead of being in net, so that it | |
77 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. | |
78 #if defined(OS_CHROMEOS) | 79 #if defined(OS_CHROMEOS) |
79 return new chromeos::ProxyConfigService( | 80 base_service = new chromeos::ProxyConfigService( |
80 profile->GetChromeOSProxyConfigServiceImpl()); | 81 profile->GetChromeOSProxyConfigServiceImpl()); |
81 #else | 82 #else |
82 return net::ProxyService::CreateSystemProxyConfigService( | 83 base_service = net::ProxyService::CreateSystemProxyConfigService( |
83 g_browser_process->io_thread()->message_loop(), | 84 g_browser_process->io_thread()->message_loop(), |
84 g_browser_process->file_thread()->message_loop()); | 85 g_browser_process->file_thread()->message_loop()); |
85 #endif // defined(OS_CHROMEOS) | 86 #endif // defined(OS_CHROMEOS) |
86 } | |
87 | 87 |
88 // Otherwise use the fixed settings from the command line. | 88 return new PrefProxyConfigService(profile->GetPrefs(), base_service); |
89 return new net::ProxyConfigServiceFixed(*proxy_config.get()); | |
90 } | 89 } |
91 | 90 |
92 // Create a proxy service according to the options on command line. | 91 // Create a proxy service according to the options on command line. |
93 net::ProxyService* CreateProxyService( | 92 net::ProxyService* CreateProxyService( |
94 net::NetLog* net_log, | 93 net::NetLog* net_log, |
95 URLRequestContext* context, | 94 URLRequestContext* context, |
96 net::ProxyConfigService* proxy_config_service, | 95 net::ProxyConfigService* proxy_config_service, |
97 const CommandLine& command_line, | 96 const CommandLine& command_line, |
98 IOThread* io_thread) { | 97 IOThread* io_thread) { |
99 CheckCurrentlyOnIOThread(); | 98 CheckCurrentlyOnIOThread(); |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
924 context->set_host_zoom_map(host_zoom_map_); | 923 context->set_host_zoom_map(host_zoom_map_); |
925 context->set_transport_security_state( | 924 context->set_transport_security_state( |
926 transport_security_state_); | 925 transport_security_state_); |
927 context->set_ssl_config_service(ssl_config_service_); | 926 context->set_ssl_config_service(ssl_config_service_); |
928 context->set_appcache_service(appcache_service_); | 927 context->set_appcache_service(appcache_service_); |
929 context->set_database_tracker(database_tracker_); | 928 context->set_database_tracker(database_tracker_); |
930 context->set_blob_storage_context(blob_storage_context_); | 929 context->set_blob_storage_context(blob_storage_context_); |
931 context->set_browser_file_system_context(browser_file_system_context_); | 930 context->set_browser_file_system_context(browser_file_system_context_); |
932 context->set_extension_info_map(extension_info_map_); | 931 context->set_extension_info_map(extension_info_map_); |
933 } | 932 } |
934 | |
935 // ---------------------------------------------------------------------------- | |
936 | |
937 net::ProxyConfig* CreateProxyConfig(const PrefService* pref_service) { | |
938 // Scan for all "enable" type proxy switches. | |
939 static const char* proxy_prefs[] = { | |
940 prefs::kProxyPacUrl, | |
941 prefs::kProxyServer, | |
942 prefs::kProxyBypassList, | |
943 prefs::kProxyAutoDetect | |
944 }; | |
945 | |
946 // Check whether the preference system holds a valid proxy configuration. Note | |
947 // that preferences coming from a lower-priority source than the user settings | |
948 // are ignored. That's because chrome treats the system settings as the | |
949 // default values, which should apply if there's no explicit value forced by | |
950 // policy or the user. | |
951 bool found_enable_proxy_pref = false; | |
952 for (size_t i = 0; i < arraysize(proxy_prefs); i++) { | |
953 const PrefService::Preference* pref = | |
954 pref_service->FindPreference(proxy_prefs[i]); | |
955 DCHECK(pref); | |
956 if (pref && (!pref->IsUserModifiable() || pref->HasUserSetting())) { | |
957 found_enable_proxy_pref = true; | |
958 break; | |
959 } | |
960 } | |
961 | |
962 if (!found_enable_proxy_pref && | |
963 !pref_service->GetBoolean(prefs::kNoProxyServer)) { | |
964 return NULL; | |
965 } | |
966 | |
967 net::ProxyConfig* proxy_config = new net::ProxyConfig(); | |
968 if (pref_service->GetBoolean(prefs::kNoProxyServer)) { | |
969 // Ignore all the other proxy config preferences if the use of a proxy | |
970 // has been explicitly disabled. | |
971 return proxy_config; | |
972 } | |
973 | |
974 if (pref_service->HasPrefPath(prefs::kProxyServer)) { | |
975 std::string proxy_server = pref_service->GetString(prefs::kProxyServer); | |
976 proxy_config->proxy_rules().ParseFromString(proxy_server); | |
977 } | |
978 | |
979 if (pref_service->HasPrefPath(prefs::kProxyPacUrl)) { | |
980 std::string proxy_pac = pref_service->GetString(prefs::kProxyPacUrl); | |
981 proxy_config->set_pac_url(GURL(proxy_pac)); | |
982 } | |
983 | |
984 proxy_config->set_auto_detect(pref_service->GetBoolean( | |
985 prefs::kProxyAutoDetect)); | |
986 | |
987 if (pref_service->HasPrefPath(prefs::kProxyBypassList)) { | |
988 std::string proxy_bypass = | |
989 pref_service->GetString(prefs::kProxyBypassList); | |
990 proxy_config->proxy_rules().bypass_rules.ParseFromString(proxy_bypass); | |
991 } | |
992 | |
993 return proxy_config; | |
994 } | |
OLD | NEW |