OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/profile_io_data.h" | 5 #include "chrome/browser/profiles/profile_io_data.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.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/pref_proxy_config_service.h" | 18 #include "chrome/browser/net/pref_proxy_config_service.h" |
| 19 #include "chrome/browser/net/proxy_service_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
20 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
23 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
24 #include "content/common/notification_service.h" | 26 #include "content/common/notification_service.h" |
25 #include "net/http/http_util.h" | 27 #include "net/http/http_util.h" |
26 #include "net/proxy/proxy_config_service_fixed.h" | 28 #include "net/proxy/proxy_config_service_fixed.h" |
27 #include "net/proxy/proxy_script_fetcher_impl.h" | 29 #include "net/proxy/proxy_script_fetcher_impl.h" |
28 #include "net/proxy/proxy_service.h" | 30 #include "net/proxy/proxy_service.h" |
29 | 31 |
30 #if defined(OS_CHROMEOS) | |
31 #include "chrome/browser/chromeos/cros/cros_library.h" | |
32 #include "chrome/browser/chromeos/cros/libcros_service_library.h" | |
33 #include "chrome/browser/chromeos/proxy_config_service.h" | |
34 #endif // defined(OS_CHROMEOS) | |
35 | |
36 namespace { | 32 namespace { |
37 | 33 |
38 // ---------------------------------------------------------------------------- | 34 // ---------------------------------------------------------------------------- |
39 // CookieMonster::Delegate implementation | 35 // CookieMonster::Delegate implementation |
40 // ---------------------------------------------------------------------------- | 36 // ---------------------------------------------------------------------------- |
41 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { | 37 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { |
42 public: | 38 public: |
43 explicit ChromeCookieMonsterDelegate(Profile* profile) { | 39 explicit ChromeCookieMonsterDelegate(Profile* profile) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
45 profile_getter_ = new ProfileGetter(profile); | 41 profile_getter_ = new ProfileGetter(profile); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 params->ssl_config_service = profile->GetSSLConfigService(); | 162 params->ssl_config_service = profile->GetSSLConfigService(); |
167 params->cookie_monster_delegate = new ChromeCookieMonsterDelegate(profile); | 163 params->cookie_monster_delegate = new ChromeCookieMonsterDelegate(profile); |
168 params->database_tracker = profile->GetDatabaseTracker(); | 164 params->database_tracker = profile->GetDatabaseTracker(); |
169 params->appcache_service = profile->GetAppCacheService(); | 165 params->appcache_service = profile->GetAppCacheService(); |
170 params->blob_storage_context = profile->GetBlobStorageContext(); | 166 params->blob_storage_context = profile->GetBlobStorageContext(); |
171 params->file_system_context = profile->GetFileSystemContext(); | 167 params->file_system_context = profile->GetFileSystemContext(); |
172 params->extension_info_map = profile->GetExtensionInfoMap(); | 168 params->extension_info_map = profile->GetExtensionInfoMap(); |
173 params->prerender_manager = profile->GetPrerenderManager(); | 169 params->prerender_manager = profile->GetPrerenderManager(); |
174 params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); | 170 params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); |
175 | 171 |
176 params->proxy_config_service.reset(CreateProxyConfigService(profile)); | 172 params->proxy_config_service.reset( |
| 173 ProxyServiceFactory::CreateProxyConfigService( |
| 174 profile->GetProxyConfigTracker())); |
177 params->profile_id = profile->GetRuntimeId(); | 175 params->profile_id = profile->GetRuntimeId(); |
178 } | 176 } |
179 | 177 |
180 ProfileIOData::RequestContext::RequestContext() {} | 178 ProfileIOData::RequestContext::RequestContext() {} |
181 ProfileIOData::RequestContext::~RequestContext() {} | 179 ProfileIOData::RequestContext::~RequestContext() {} |
182 | 180 |
183 ProfileIOData::ProfileParams::ProfileParams() | 181 ProfileIOData::ProfileParams::ProfileParams() |
184 : is_off_the_record(false), | 182 : is_off_the_record(false), |
185 clear_local_state_on_exit(false), | 183 clear_local_state_on_exit(false), |
186 profile_id(Profile::kInvalidProfileId) {} | 184 profile_id(Profile::kInvalidProfileId) {} |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 context->set_transport_security_state( | 250 context->set_transport_security_state( |
253 profile_params.transport_security_state); | 251 profile_params.transport_security_state); |
254 context->set_ssl_config_service(profile_params.ssl_config_service); | 252 context->set_ssl_config_service(profile_params.ssl_config_service); |
255 context->set_database_tracker(profile_params.database_tracker); | 253 context->set_database_tracker(profile_params.database_tracker); |
256 context->set_appcache_service(profile_params.appcache_service); | 254 context->set_appcache_service(profile_params.appcache_service); |
257 context->set_blob_storage_context(profile_params.blob_storage_context); | 255 context->set_blob_storage_context(profile_params.blob_storage_context); |
258 context->set_file_system_context(profile_params.file_system_context); | 256 context->set_file_system_context(profile_params.file_system_context); |
259 context->set_extension_info_map(profile_params.extension_info_map); | 257 context->set_extension_info_map(profile_params.extension_info_map); |
260 context->set_prerender_manager(profile_params.prerender_manager); | 258 context->set_prerender_manager(profile_params.prerender_manager); |
261 } | 259 } |
262 | |
263 // static | |
264 net::ProxyConfigService* ProfileIOData::CreateProxyConfigService( | |
265 Profile* profile) { | |
266 // The linux gconf-based proxy settings getter relies on being initialized | |
267 // from the UI thread. | |
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
269 | |
270 // Create a baseline service that provides proxy configuration in case nothing | |
271 // is configured through prefs (Note: prefs include command line and | |
272 // configuration policy). | |
273 net::ProxyConfigService* base_service = NULL; | |
274 | |
275 // TODO(port): the IO and FILE message loops are only used by Linux. Can | |
276 // that code be moved to chrome/browser instead of being in net, so that it | |
277 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. | |
278 #if defined(OS_CHROMEOS) | |
279 base_service = new chromeos::ProxyConfigService( | |
280 profile->GetChromeOSProxyConfigServiceImpl()); | |
281 #else | |
282 base_service = net::ProxyService::CreateSystemProxyConfigService( | |
283 g_browser_process->io_thread()->message_loop(), | |
284 g_browser_process->file_thread()->message_loop()); | |
285 #endif // defined(OS_CHROMEOS) | |
286 | |
287 return new PrefProxyConfigService(profile->GetProxyConfigTracker(), | |
288 base_service); | |
289 } | |
290 | |
291 // static | |
292 net::ProxyService* ProfileIOData::CreateProxyService( | |
293 net::NetLog* net_log, | |
294 net::URLRequestContext* context, | |
295 net::ProxyConfigService* proxy_config_service, | |
296 const CommandLine& command_line) { | |
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
298 | |
299 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); | |
300 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { | |
301 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h | |
302 // to understand why we have this limitation. | |
303 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; | |
304 use_v8 = false; // Fallback to non-v8 implementation. | |
305 } | |
306 | |
307 size_t num_pac_threads = 0u; // Use default number of threads. | |
308 | |
309 // Check the command line for an override on the number of proxy resolver | |
310 // threads to use. | |
311 if (command_line.HasSwitch(switches::kNumPacThreads)) { | |
312 std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads); | |
313 | |
314 // Parse the switch (it should be a positive integer formatted as decimal). | |
315 int n; | |
316 if (base::StringToInt(s, &n) && n > 0) { | |
317 num_pac_threads = static_cast<size_t>(n); | |
318 } else { | |
319 LOG(ERROR) << "Invalid switch for number of PAC threads: " << s; | |
320 } | |
321 } | |
322 | |
323 net::ProxyService* proxy_service; | |
324 if (use_v8) { | |
325 proxy_service = net::ProxyService::CreateUsingV8ProxyResolver( | |
326 proxy_config_service, | |
327 num_pac_threads, | |
328 new net::ProxyScriptFetcherImpl(context), | |
329 context->host_resolver(), | |
330 net_log); | |
331 } else { | |
332 proxy_service = net::ProxyService::CreateUsingSystemProxyResolver( | |
333 proxy_config_service, | |
334 num_pac_threads, | |
335 net_log); | |
336 } | |
337 | |
338 #if defined(OS_CHROMEOS) | |
339 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { | |
340 chromeos::CrosLibrary::Get()->GetLibCrosServiceLibrary()-> | |
341 RegisterNetworkProxyHandler(proxy_service); | |
342 } | |
343 #endif // defined(OS_CHROMEOS) | |
344 | |
345 return proxy_service; | |
346 } | |
OLD | NEW |