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

Side by Side Diff: chrome/browser/policy/device_management_service.cc

Issue 8054013: Recover from bad proxy settings pointing to non-proxy servers that reply anyway. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased, reviewed Created 9 years, 2 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
OLDNEW
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/policy/device_management_service.h" 5 #include "chrome/browser/policy/device_management_service.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/net/chrome_net_log.h" 10 #include "chrome/browser/net/chrome_net_log.h"
11 #include "chrome/browser/policy/device_management_backend.h" 11 #include "chrome/browser/policy/device_management_backend.h"
12 #include "chrome/browser/policy/device_management_backend_impl.h" 12 #include "chrome/browser/policy/device_management_backend_impl.h"
13 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
14 #include "net/base/cookie_monster.h" 14 #include "net/base/cookie_monster.h"
15 #include "net/base/host_resolver.h" 15 #include "net/base/host_resolver.h"
16 #include "net/base/load_flags.h" 16 #include "net/base/load_flags.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/base/ssl_config_service_defaults.h" 18 #include "net/base/ssl_config_service_defaults.h"
19 #include "net/http/http_network_layer.h" 19 #include "net/http/http_network_layer.h"
20 #include "net/http/http_response_headers.h"
20 #include "net/proxy/proxy_service.h" 21 #include "net/proxy/proxy_service.h"
21 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context.h"
22 #include "net/url_request/url_request_context_getter.h" 23 #include "net/url_request/url_request_context_getter.h"
23 #include "net/url_request/url_request_status.h" 24 #include "net/url_request/url_request_status.h"
24 #include "webkit/glue/webkit_glue.h" 25 #include "webkit/glue/webkit_glue.h"
25 26
26 namespace policy { 27 namespace policy {
27 28
28 namespace { 29 namespace {
29 30
31 bool IsProxyError(const net::URLRequestStatus status) {
32 switch (status.error()) {
33 case net::ERR_PROXY_CONNECTION_FAILED:
34 case net::ERR_TUNNEL_CONNECTION_FAILED:
35 case net::ERR_PROXY_AUTH_UNSUPPORTED:
36 case net::ERR_HTTPS_PROXY_TUNNEL_RESPONSE:
37 case net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED:
38 case net::ERR_PROXY_CERTIFICATE_INVALID:
39 case net::ERR_SOCKS_CONNECTION_FAILED:
40 case net::ERR_SOCKS_CONNECTION_HOST_UNREACHABLE:
41 return true;
42 }
43 return false;
44 }
45
46 bool IsProtobufMimeType(const URLFetcher* source) {
47 return source->response_headers()->HasHeaderValue(
48 "content-type", "application/x-protobuffer");
49 }
50
30 // Custom request context implementation that allows to override the user agent, 51 // Custom request context implementation that allows to override the user agent,
31 // amongst others. Wraps a baseline request context from which we reuse the 52 // amongst others. Wraps a baseline request context from which we reuse the
32 // networking components. 53 // networking components.
33 class DeviceManagementRequestContext : public net::URLRequestContext { 54 class DeviceManagementRequestContext : public net::URLRequestContext {
34 public: 55 public:
35 explicit DeviceManagementRequestContext(net::URLRequestContext* base_context); 56 explicit DeviceManagementRequestContext(net::URLRequestContext* base_context);
36 virtual ~DeviceManagementRequestContext(); 57 virtual ~DeviceManagementRequestContext();
37 58
38 private: 59 private:
39 // Overridden from net::URLRequestContext: 60 // Overridden from net::URLRequestContext:
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 const net::ResponseCookies& cookies, 228 const net::ResponseCookies& cookies,
208 const std::string& data) { 229 const std::string& data) {
209 JobFetcherMap::iterator entry(pending_jobs_.find(source)); 230 JobFetcherMap::iterator entry(pending_jobs_.find(source));
210 if (entry != pending_jobs_.end()) { 231 if (entry != pending_jobs_.end()) {
211 DeviceManagementJob* job = entry->second; 232 DeviceManagementJob* job = entry->second;
212 pending_jobs_.erase(entry); 233 pending_jobs_.erase(entry);
213 234
214 // Retry the job if it failed due to a broken proxy, by bypassing the 235 // Retry the job if it failed due to a broken proxy, by bypassing the
215 // proxy on the next try. Don't retry if this URLFetcher already bypassed 236 // proxy on the next try. Don't retry if this URLFetcher already bypassed
216 // the proxy. 237 // the proxy.
217 int error = status.error(); 238 bool retry = false;
218 if (!status.is_success() && 239 if ((source->load_flags() & net::LOAD_BYPASS_PROXY) == 0) {
219 ((source->load_flags() & net::LOAD_BYPASS_PROXY) == 0) && 240 if (!status.is_success() && IsProxyError(status)) {
220 (error == net::ERR_PROXY_CONNECTION_FAILED || 241 LOG(WARNING) << "Proxy failed while contacting dmserver.";
221 error == net::ERR_TUNNEL_CONNECTION_FAILED || 242 retry = true;
222 error == net::ERR_PROXY_AUTH_UNSUPPORTED || 243 } else if (status.is_success() &&
223 error == net::ERR_HTTPS_PROXY_TUNNEL_RESPONSE || 244 source->was_fetched_via_proxy() &&
224 error == net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED || 245 !IsProtobufMimeType(source)) {
225 error == net::ERR_PROXY_CERTIFICATE_INVALID || 246 // The proxy server can be misconfigured but pointing to an existing
226 error == net::ERR_SOCKS_CONNECTION_FAILED || 247 // server that replies to requests. Try to recover if a successful
227 error == net::ERR_SOCKS_CONNECTION_HOST_UNREACHABLE)) { 248 // request that went through a proxy returns an unexpected mime type.
228 LOG(WARNING) << "Proxy failed while contacting dmserver. Retrying " 249 LOG(WARNING) << "Got bad mime-type in response from dmserver that was "
229 << "without using the proxy."; 250 << "fetched via a proxy.";
251 retry = true;
252 }
253 }
254
255 if (retry) {
256 LOG(WARNING) << "Retrying dmserver request without using a proxy.";
230 StartJob(job, true); 257 StartJob(job, true);
231 } else { 258 } else {
232 job->HandleResponse(status, response_code, cookies, data); 259 job->HandleResponse(status, response_code, cookies, data);
233 } 260 }
234 } else { 261 } else {
235 NOTREACHED() << "Callback from foreign URL fetcher"; 262 NOTREACHED() << "Callback from foreign URL fetcher";
236 } 263 }
237 delete source; 264 delete source;
238 } 265 }
239 266
240 } // namespace policy 267 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_controller.h ('k') | chrome/browser/policy/device_management_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698