OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/net/proxy_service_factory.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/string_number_conversions.h" | |
9 #include "chrome/browser/browser_process.h" | |
10 #include "chrome/browser/browser_thread.h" | |
11 #include "chrome/browser/net/pref_proxy_config_service.h" | |
12 #include "chrome/browser/io_thread.h" | |
13 #include "chrome/browser/profiles/profile.h" | |
14 #include "chrome/common/chrome_switches.h" | |
15 #include "net/base/net_log.h" | |
16 #include "net/proxy/proxy_config_service.h" | |
17 #include "net/proxy/proxy_script_fetcher_impl.h" | |
18 #include "net/url_request/url_request_context.h" | |
19 | |
20 #if defined(OS_CHROMEOS) | |
willchan no longer on Chromium
2011/02/21 23:05:49
You should include "build/build_config.h" for this
battre
2011/03/08 17:38:58
Are you sure about this? chrome/browser/net/chrome
| |
21 #include "chrome/browser/chromeos/cros/cros_library.h" | |
22 #include "chrome/browser/chromeos/cros/libcros_service_library.h" | |
23 #include "chrome/browser/chromeos/proxy_config_service.h" | |
24 #endif // defined(OS_CHROMEOS) | |
25 | |
26 // static | |
27 net::ProxyConfigService* ProxyServiceFactory::CreateProxyConfigService( | |
28 PrefProxyConfigTracker* proxy_config_tracker) { | |
29 // The linux gconf-based proxy settings getter relies on being initialized | |
30 // from the UI thread. | |
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
32 | |
33 // Create a baseline service that provides proxy configuration in case nothing | |
34 // is configured through prefs (Note: prefs include command line and | |
35 // configuration policy). | |
36 net::ProxyConfigService* base_service = NULL; | |
37 | |
38 // TODO(port): the IO and FILE message loops are only used by Linux. Can | |
39 // that code be moved to chrome/browser instead of being in net, so that it | |
40 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. | |
41 #if defined(OS_CHROMEOS) | |
42 base_service = new chromeos::ProxyConfigService( | |
43 g_browser_process->chromeos_proxy_config_service_impl()); | |
44 #else | |
45 base_service = net::ProxyService::CreateSystemProxyConfigService( | |
46 g_browser_process->io_thread()->message_loop(), | |
47 g_browser_process->file_thread()->message_loop()); | |
48 #endif // defined(OS_CHROMEOS) | |
49 | |
50 return new PrefProxyConfigService(proxy_config_tracker, base_service); | |
51 } | |
52 | |
53 // static | |
54 net::ProxyService* ProxyServiceFactory::CreateProxyService( | |
55 net::NetLog* net_log, | |
56 net::URLRequestContext* context, | |
57 net::ProxyConfigService* proxy_config_service, | |
58 const CommandLine& command_line) { | |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
60 | |
61 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); | |
62 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { | |
63 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h | |
64 // to understand why we have this limitation. | |
65 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; | |
66 use_v8 = false; // Fallback to non-v8 implementation. | |
67 } | |
68 | |
69 size_t num_pac_threads = 0u; // Use default number of threads. | |
70 | |
71 // Check the command line for an override on the number of proxy resolver | |
72 // threads to use. | |
73 if (command_line.HasSwitch(switches::kNumPacThreads)) { | |
74 std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads); | |
75 | |
76 // Parse the switch (it should be a positive integer formatted as decimal). | |
77 int n; | |
78 if (base::StringToInt(s, &n) && n > 0) { | |
79 num_pac_threads = static_cast<size_t>(n); | |
80 } else { | |
81 LOG(ERROR) << "Invalid switch for number of PAC threads: " << s; | |
82 } | |
83 } | |
84 | |
85 net::ProxyService* proxy_service; | |
86 if (use_v8) { | |
87 proxy_service = net::ProxyService::CreateUsingV8ProxyResolver( | |
88 proxy_config_service, | |
89 num_pac_threads, | |
90 new net::ProxyScriptFetcherImpl(context), | |
91 context->host_resolver(), | |
92 net_log); | |
93 } else { | |
94 proxy_service = net::ProxyService::CreateUsingSystemProxyResolver( | |
95 proxy_config_service, | |
96 num_pac_threads, | |
97 net_log); | |
98 } | |
99 | |
100 #if defined(OS_CHROMEOS) | |
101 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { | |
102 chromeos::CrosLibrary::Get()->GetLibCrosServiceLibrary()-> | |
103 RegisterNetworkProxyHandler(proxy_service); | |
104 } | |
105 #endif // defined(OS_CHROMEOS) | |
106 | |
107 return proxy_service; | |
108 } | |
OLD | NEW |