| 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/policy/device_management_service.h" | 5 #include "chrome/browser/policy/device_management_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.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 "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 case net::ERR_HTTPS_PROXY_TUNNEL_RESPONSE: | 38 case net::ERR_HTTPS_PROXY_TUNNEL_RESPONSE: |
| 39 case net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED: | 39 case net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED: |
| 40 case net::ERR_PROXY_CERTIFICATE_INVALID: | 40 case net::ERR_PROXY_CERTIFICATE_INVALID: |
| 41 case net::ERR_SOCKS_CONNECTION_FAILED: | 41 case net::ERR_SOCKS_CONNECTION_FAILED: |
| 42 case net::ERR_SOCKS_CONNECTION_HOST_UNREACHABLE: | 42 case net::ERR_SOCKS_CONNECTION_HOST_UNREACHABLE: |
| 43 return true; | 43 return true; |
| 44 } | 44 } |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool IsProtobufMimeType(const URLFetcher* source) { | 48 bool IsProtobufMimeType(const content::URLFetcher* source) { |
| 49 return source->response_headers()->HasHeaderValue( | 49 return source->GetResponseHeaders()->HasHeaderValue( |
| 50 "content-type", "application/x-protobuffer"); | 50 "content-type", "application/x-protobuffer"); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Custom request context implementation that allows to override the user agent, | 53 // Custom request context implementation that allows to override the user agent, |
| 54 // amongst others. Wraps a baseline request context from which we reuse the | 54 // amongst others. Wraps a baseline request context from which we reuse the |
| 55 // networking components. | 55 // networking components. |
| 56 class DeviceManagementRequestContext : public net::URLRequestContext { | 56 class DeviceManagementRequestContext : public net::URLRequestContext { |
| 57 public: | 57 public: |
| 58 explicit DeviceManagementRequestContext(net::URLRequestContext* base_context); | 58 explicit DeviceManagementRequestContext(net::URLRequestContext* base_context); |
| 59 virtual ~DeviceManagementRequestContext(); | 59 virtual ~DeviceManagementRequestContext(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 const JobQueue::iterator elem = | 205 const JobQueue::iterator elem = |
| 206 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); | 206 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); |
| 207 if (elem != queued_jobs_.end()) | 207 if (elem != queued_jobs_.end()) |
| 208 queued_jobs_.erase(elem); | 208 queued_jobs_.erase(elem); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void DeviceManagementService::StartJob(DeviceManagementJob* job, | 211 void DeviceManagementService::StartJob(DeviceManagementJob* job, |
| 212 bool bypass_proxy) { | 212 bool bypass_proxy) { |
| 213 URLFetcher* fetcher = URLFetcher::Create(0, job->GetURL(server_url_), | 213 URLFetcher* fetcher = URLFetcher::Create(0, job->GetURL(server_url_), |
| 214 URLFetcher::POST, this); | 214 URLFetcher::POST, this); |
| 215 fetcher->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | | 215 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 216 net::LOAD_DO_NOT_SAVE_COOKIES | | 216 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 217 net::LOAD_DISABLE_CACHE | | 217 net::LOAD_DISABLE_CACHE | |
| 218 (bypass_proxy ? net::LOAD_BYPASS_PROXY : 0)); | 218 (bypass_proxy ? net::LOAD_BYPASS_PROXY : 0)); |
| 219 fetcher->set_request_context(request_context_getter_.get()); | 219 fetcher->SetRequestContext(request_context_getter_.get()); |
| 220 job->ConfigureRequest(fetcher); | 220 job->ConfigureRequest(fetcher); |
| 221 pending_jobs_[fetcher] = job; | 221 pending_jobs_[fetcher] = job; |
| 222 fetcher->Start(); | 222 fetcher->Start(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void DeviceManagementService::OnURLFetchComplete(const URLFetcher* source) { | 225 void DeviceManagementService::OnURLFetchComplete( |
| 226 const content::URLFetcher* source) { |
| 226 JobFetcherMap::iterator entry(pending_jobs_.find(source)); | 227 JobFetcherMap::iterator entry(pending_jobs_.find(source)); |
| 227 if (entry != pending_jobs_.end()) { | 228 if (entry != pending_jobs_.end()) { |
| 228 DeviceManagementJob* job = entry->second; | 229 DeviceManagementJob* job = entry->second; |
| 229 pending_jobs_.erase(entry); | 230 pending_jobs_.erase(entry); |
| 230 | 231 |
| 231 // Retry the job if it failed due to a broken proxy, by bypassing the | 232 // Retry the job if it failed due to a broken proxy, by bypassing the |
| 232 // proxy on the next try. Don't retry if this URLFetcher already bypassed | 233 // proxy on the next try. Don't retry if this URLFetcher already bypassed |
| 233 // the proxy. | 234 // the proxy. |
| 234 bool retry = false; | 235 bool retry = false; |
| 235 if ((source->load_flags() & net::LOAD_BYPASS_PROXY) == 0) { | 236 if ((source->GetLoadFlags() & net::LOAD_BYPASS_PROXY) == 0) { |
| 236 if (!source->status().is_success() && IsProxyError(source->status())) { | 237 if (!source->GetStatus().is_success() && |
| 238 IsProxyError(source->GetStatus())) { |
| 237 LOG(WARNING) << "Proxy failed while contacting dmserver."; | 239 LOG(WARNING) << "Proxy failed while contacting dmserver."; |
| 238 retry = true; | 240 retry = true; |
| 239 } else if (source->status().is_success() && | 241 } else if (source->GetStatus().is_success() && |
| 240 source->was_fetched_via_proxy() && | 242 source->WasFetchedViaProxy() && |
| 241 !IsProtobufMimeType(source)) { | 243 !IsProtobufMimeType(source)) { |
| 242 // The proxy server can be misconfigured but pointing to an existing | 244 // The proxy server can be misconfigured but pointing to an existing |
| 243 // server that replies to requests. Try to recover if a successful | 245 // server that replies to requests. Try to recover if a successful |
| 244 // request that went through a proxy returns an unexpected mime type. | 246 // request that went through a proxy returns an unexpected mime type. |
| 245 LOG(WARNING) << "Got bad mime-type in response from dmserver that was " | 247 LOG(WARNING) << "Got bad mime-type in response from dmserver that was " |
| 246 << "fetched via a proxy."; | 248 << "fetched via a proxy."; |
| 247 retry = true; | 249 retry = true; |
| 248 } | 250 } |
| 249 } | 251 } |
| 250 | 252 |
| 251 if (retry) { | 253 if (retry) { |
| 252 LOG(WARNING) << "Retrying dmserver request without using a proxy."; | 254 LOG(WARNING) << "Retrying dmserver request without using a proxy."; |
| 253 StartJob(job, true); | 255 StartJob(job, true); |
| 254 } else { | 256 } else { |
| 255 std::string data; | 257 std::string data; |
| 256 source->GetResponseAsString(&data); | 258 source->GetResponseAsString(&data); |
| 257 job->HandleResponse(source->status(), source->response_code(), | 259 job->HandleResponse(source->GetStatus(), source->GetResponseCode(), |
| 258 source->cookies(), data); | 260 source->GetCookies(), data); |
| 259 } | 261 } |
| 260 } else { | 262 } else { |
| 261 NOTREACHED() << "Callback from foreign URL fetcher"; | 263 NOTREACHED() << "Callback from foreign URL fetcher"; |
| 262 } | 264 } |
| 263 delete source; | 265 delete source; |
| 264 } | 266 } |
| 265 | 267 |
| 266 } // namespace policy | 268 } // namespace policy |
| OLD | NEW |