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

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

Issue 8373021: Convert URLFetcher::Delegates to use an interface in content/public/common. Also remove the old U... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync and remove unncessary forward declares Created 9 years, 1 month 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/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"
11 #include "chrome/browser/net/chrome_net_log.h" 11 #include "chrome/browser/net/chrome_net_log.h"
12 #include "chrome/browser/policy/device_management_backend.h" 12 #include "chrome/browser/policy/device_management_backend.h"
13 #include "chrome/browser/policy/device_management_backend_impl.h" 13 #include "chrome/browser/policy/device_management_backend_impl.h"
14 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
15 #include "content/public/common/content_client.h" 15 #include "content/public/common/content_client.h"
16 #include "content/common/net/url_fetcher.h"
16 #include "net/base/cookie_monster.h" 17 #include "net/base/cookie_monster.h"
17 #include "net/base/host_resolver.h" 18 #include "net/base/host_resolver.h"
18 #include "net/base/load_flags.h" 19 #include "net/base/load_flags.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
20 #include "net/base/ssl_config_service_defaults.h" 21 #include "net/base/ssl_config_service_defaults.h"
21 #include "net/http/http_network_layer.h" 22 #include "net/http/http_network_layer.h"
22 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
23 #include "net/proxy/proxy_service.h" 24 #include "net/proxy/proxy_service.h"
24 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
25 #include "net/url_request/url_request_context_getter.h" 26 #include "net/url_request/url_request_context_getter.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 fetcher->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | 215 fetcher->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES |
215 net::LOAD_DO_NOT_SAVE_COOKIES | 216 net::LOAD_DO_NOT_SAVE_COOKIES |
216 net::LOAD_DISABLE_CACHE | 217 net::LOAD_DISABLE_CACHE |
217 (bypass_proxy ? net::LOAD_BYPASS_PROXY : 0)); 218 (bypass_proxy ? net::LOAD_BYPASS_PROXY : 0));
218 fetcher->set_request_context(request_context_getter_.get()); 219 fetcher->set_request_context(request_context_getter_.get());
219 job->ConfigureRequest(fetcher); 220 job->ConfigureRequest(fetcher);
220 pending_jobs_[fetcher] = job; 221 pending_jobs_[fetcher] = job;
221 fetcher->Start(); 222 fetcher->Start();
222 } 223 }
223 224
224 void DeviceManagementService::OnURLFetchComplete( 225 void DeviceManagementService::OnURLFetchComplete(const URLFetcher* source) {
225 const URLFetcher* source,
226 const GURL& url,
227 const net::URLRequestStatus& status,
228 int response_code,
229 const net::ResponseCookies& cookies,
230 const std::string& data) {
231 JobFetcherMap::iterator entry(pending_jobs_.find(source)); 226 JobFetcherMap::iterator entry(pending_jobs_.find(source));
232 if (entry != pending_jobs_.end()) { 227 if (entry != pending_jobs_.end()) {
233 DeviceManagementJob* job = entry->second; 228 DeviceManagementJob* job = entry->second;
234 pending_jobs_.erase(entry); 229 pending_jobs_.erase(entry);
235 230
236 // Retry the job if it failed due to a broken proxy, by bypassing the 231 // Retry the job if it failed due to a broken proxy, by bypassing the
237 // proxy on the next try. Don't retry if this URLFetcher already bypassed 232 // proxy on the next try. Don't retry if this URLFetcher already bypassed
238 // the proxy. 233 // the proxy.
239 bool retry = false; 234 bool retry = false;
240 if ((source->load_flags() & net::LOAD_BYPASS_PROXY) == 0) { 235 if ((source->load_flags() & net::LOAD_BYPASS_PROXY) == 0) {
241 if (!status.is_success() && IsProxyError(status)) { 236 if (!source->status().is_success() && IsProxyError(source->status())) {
242 LOG(WARNING) << "Proxy failed while contacting dmserver."; 237 LOG(WARNING) << "Proxy failed while contacting dmserver.";
243 retry = true; 238 retry = true;
244 } else if (status.is_success() && 239 } else if (source->status().is_success() &&
245 source->was_fetched_via_proxy() && 240 source->was_fetched_via_proxy() &&
246 !IsProtobufMimeType(source)) { 241 !IsProtobufMimeType(source)) {
247 // The proxy server can be misconfigured but pointing to an existing 242 // The proxy server can be misconfigured but pointing to an existing
248 // server that replies to requests. Try to recover if a successful 243 // server that replies to requests. Try to recover if a successful
249 // request that went through a proxy returns an unexpected mime type. 244 // request that went through a proxy returns an unexpected mime type.
250 LOG(WARNING) << "Got bad mime-type in response from dmserver that was " 245 LOG(WARNING) << "Got bad mime-type in response from dmserver that was "
251 << "fetched via a proxy."; 246 << "fetched via a proxy.";
252 retry = true; 247 retry = true;
253 } 248 }
254 } 249 }
255 250
256 if (retry) { 251 if (retry) {
257 LOG(WARNING) << "Retrying dmserver request without using a proxy."; 252 LOG(WARNING) << "Retrying dmserver request without using a proxy.";
258 StartJob(job, true); 253 StartJob(job, true);
259 } else { 254 } else {
260 job->HandleResponse(status, response_code, cookies, data); 255 std::string data;
256 source->GetResponseAsString(&data);
257 job->HandleResponse(source->status(), source->response_code(),
258 source->cookies(), data);
261 } 259 }
262 } else { 260 } else {
263 NOTREACHED() << "Callback from foreign URL fetcher"; 261 NOTREACHED() << "Callback from foreign URL fetcher";
264 } 262 }
265 delete source; 263 delete source;
266 } 264 }
267 265
268 } // namespace policy 266 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698