Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1170)

Side by Side Diff: net/proxy/proxy_service.cc

Issue 115029: Making command-line specified proxy settings more flexible - allowing for set... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/url_request/url_request_unittest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "net/proxy/proxy_service.h" 5 #include "net/proxy/proxy_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 private: 64 private:
65 ProxyResolver* resolver_; 65 ProxyResolver* resolver_;
66 std::string bytes_; 66 std::string bytes_;
67 }; 67 };
68 68
69 // ProxyService::PacRequest --------------------------------------------------- 69 // ProxyService::PacRequest ---------------------------------------------------
70 70
71 // We rely on the fact that the origin thread (and its message loop) will not 71 // We rely on the fact that the origin thread (and its message loop) will not
72 // be destroyed until after the PAC thread is destroyed. 72 // be destroyed until after the PAC thread is destroyed.
73 73
74 class ProxyService::PacRequest : 74 class ProxyService::PacRequest
75 public base::RefCountedThreadSafe<ProxyService::PacRequest> { 75 : public base::RefCountedThreadSafe<ProxyService::PacRequest> {
76 public: 76 public:
77 // |service| -- the ProxyService that owns this request. 77 // |service| -- the ProxyService that owns this request.
78 // |url| -- the url of the query. 78 // |url| -- the url of the query.
79 // |results| -- the structure to fill with proxy resolve results. 79 // |results| -- the structure to fill with proxy resolve results.
80 PacRequest(ProxyService* service, 80 PacRequest(ProxyService* service,
81 const GURL& url, 81 const GURL& url,
82 ProxyInfo* results, 82 ProxyInfo* results,
83 CompletionCallback* callback) 83 CompletionCallback* callback)
84 : service_(service), 84 : service_(service),
85 callback_(callback), 85 callback_(callback),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 next_config_id_(1), 186 next_config_id_(1),
187 config_is_bad_(false), 187 config_is_bad_(false),
188 ALLOW_THIS_IN_INITIALIZER_LIST(proxy_script_fetcher_callback_( 188 ALLOW_THIS_IN_INITIALIZER_LIST(proxy_script_fetcher_callback_(
189 this, &ProxyService::OnScriptFetchCompletion)), 189 this, &ProxyService::OnScriptFetchCompletion)),
190 fetched_pac_config_id_(ProxyConfig::INVALID_ID), 190 fetched_pac_config_id_(ProxyConfig::INVALID_ID),
191 fetched_pac_error_(OK), 191 fetched_pac_error_(OK),
192 in_progress_fetch_config_id_(ProxyConfig::INVALID_ID) { 192 in_progress_fetch_config_id_(ProxyConfig::INVALID_ID) {
193 } 193 }
194 194
195 // static 195 // static
196 ProxyService* ProxyService::Create(const ProxyInfo* pi) { 196 ProxyService* ProxyService::Create(const ProxyConfig* pc) {
197 if (pi) { 197 scoped_ptr<ProxyConfigService> proxy_config_service;
198 // The ProxyResolver is set to NULL, since it should never be called 198 scoped_ptr<ProxyResolver> proxy_resolver;
199 // (because the configuration will never require PAC). 199 if (pc) {
200 return new ProxyService(new ProxyConfigServiceFixed(*pi), NULL); 200 proxy_config_service.reset(new ProxyConfigServiceFixed(*pc));
201 } 201 }
202
202 #if defined(OS_WIN) 203 #if defined(OS_WIN)
203 return new ProxyService(new ProxyConfigServiceWin(), 204 if (proxy_config_service == NULL)
204 new ProxyResolverWinHttp()); 205 proxy_config_service.reset(new ProxyConfigServiceWin());
206 proxy_resolver.reset(new ProxyResolverWinHttp());
205 #elif defined(OS_MACOSX) 207 #elif defined(OS_MACOSX)
206 return new ProxyService(new ProxyConfigServiceMac(), 208 if (proxy_config_service == NULL)
207 new ProxyResolverMac()); 209 proxy_config_service.reset(new ProxyConfigServiceMac());
210 proxy_resolver.reset(new ProxyResolverMac());
208 #elif defined(OS_LINUX) 211 #elif defined(OS_LINUX)
209 // On Linux we use the V8Resolver, no fallback implementation. 212 // On Linux we use the V8Resolver, no fallback implementation.
210 return CreateNull(); 213 // This means that if we got called with a ProxyConfig that could require a
214 // resolver, or if the caller is trying to create a regular ProxyService via
215 // this method instead of CreateUsingV8Resolver() we have to return a
216 // nulled-out ProxyService.
217 if (!pc || pc->MayRequirePACResolver()) {
218 LOG(WARNING) << "Attempting to create a ProxyService with a non-v8 "
219 << "resolver using an invalid ProxyConfig.";
220 return CreateNull();
221 }
211 #else 222 #else
212 return CreateNull(); 223 return CreateNull();
213 #endif 224 #endif
225
226 return new ProxyService(proxy_config_service.release(),
227 proxy_resolver.release());
214 } 228 }
215 229
216 // static 230 // static
217 ProxyService* ProxyService::CreateUsingV8Resolver( 231 ProxyService* ProxyService::CreateUsingV8Resolver(
218 const ProxyInfo* pi, URLRequestContext* url_request_context) { 232 const ProxyConfig* pc, URLRequestContext* url_request_context) {
219 if (pi) { 233 // Choose the system configuration service appropriate for each platform.
220 // The ProxyResolver is set to NULL, since it should never be called 234 ProxyConfigService* config_service = NULL;
221 // (because the configuration will never require PAC). 235 if (pc) {
222 return new ProxyService(new ProxyConfigServiceFixed(*pi), NULL); 236 config_service = new ProxyConfigServiceFixed(*pc);
237 } else {
238 #if defined(OS_WIN)
239 config_service = new ProxyConfigServiceWin();
240 #elif defined(OS_MACOSX)
241 config_service = new ProxyConfigServiceMac();
242 #elif defined(OS_LINUX)
243 config_service = new ProxyConfigServiceLinux();
244 #else
245 return CreateNull();
246 #endif
223 } 247 }
224 248
225 // Choose the system configuration service appropriate for each platform.
226 ProxyConfigService* config_service;
227 #if defined(OS_WIN)
228 config_service = new ProxyConfigServiceWin();
229 #elif defined(OS_MACOSX)
230 config_service = new ProxyConfigServiceMac();
231 #elif defined(OS_LINUX)
232 config_service = new ProxyConfigServiceLinux();
233 #else
234 return CreateNull();
235 #endif
236
237 // Create a ProxyService that uses V8 to evaluate PAC scripts. 249 // Create a ProxyService that uses V8 to evaluate PAC scripts.
238 ProxyService* proxy_service = new ProxyService( 250 ProxyService* proxy_service = new ProxyService(
239 config_service, new ProxyResolverV8()); 251 config_service, new ProxyResolverV8());
240 252
241 // Configure PAC script downloads to be issued using |url_request_context|. 253 // Configure PAC script downloads to be issued using |url_request_context|.
242 proxy_service->SetProxyScriptFetcher( 254 proxy_service->SetProxyScriptFetcher(
243 ProxyScriptFetcher::Create(url_request_context)); 255 ProxyScriptFetcher::Create(url_request_context));
244 256
245 return proxy_service; 257 return proxy_service;
246 } 258 }
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 OnCompletion(result_); 720 OnCompletion(result_);
709 } 721 }
710 } 722 }
711 723
712 void SyncProxyServiceHelper::OnCompletion(int rv) { 724 void SyncProxyServiceHelper::OnCompletion(int rv) {
713 result_ = rv; 725 result_ = rv;
714 event_.Signal(); 726 event_.Signal();
715 } 727 }
716 728
717 } // namespace net 729 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/url_request/url_request_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698