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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 114193009: [Download] Return DownloadInterruptReason from OnStartedCallback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 #if defined(OS_WIN) 247 #if defined(OS_WIN)
248 #pragma warning(disable: 4748) 248 #pragma warning(disable: 4748)
249 #pragma optimize("", off) 249 #pragma optimize("", off)
250 #endif 250 #endif
251 251
252 #if defined(OS_WIN) 252 #if defined(OS_WIN)
253 #pragma optimize("", on) 253 #pragma optimize("", on)
254 #pragma warning(default: 4748) 254 #pragma warning(default: 4748)
255 #endif 255 #endif
256 256
257 net::Error CallbackAndReturn( 257 DownloadInterruptReason CallbackAndReturn(
258 const DownloadUrlParameters::OnStartedCallback& started_cb, 258 const DownloadUrlParameters::OnStartedCallback& started_cb,
259 net::Error net_error) { 259 DownloadInterruptReason interrupt_reason) {
260 if (started_cb.is_null()) 260 if (started_cb.is_null())
261 return net_error; 261 return interrupt_reason;
262 BrowserThread::PostTask( 262 BrowserThread::PostTask(
263 BrowserThread::UI, FROM_HERE, 263 BrowserThread::UI,
264 base::Bind(started_cb, static_cast<DownloadItem*>(NULL), net_error)); 264 FROM_HERE,
265 base::Bind(
266 started_cb, static_cast<DownloadItem*>(NULL), interrupt_reason));
265 267
266 return net_error; 268 return interrupt_reason;
267 } 269 }
268 270
269 int GetCertID(net::URLRequest* request, int child_id) { 271 int GetCertID(net::URLRequest* request, int child_id) {
270 if (request->ssl_info().cert.get()) { 272 if (request->ssl_info().cert.get()) {
271 return CertStore::GetInstance()->StoreCert(request->ssl_info().cert.get(), 273 return CertStore::GetInstance()->StoreCert(request->ssl_info().cert.get(),
272 child_id); 274 child_id);
273 } 275 }
274 return 0; 276 return 0;
275 } 277 }
276 278
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 i != blocked_loaders_map_.end(); ++i) { 460 i != blocked_loaders_map_.end(); ++i) {
459 BlockedLoadersList* loaders = i->second; 461 BlockedLoadersList* loaders = i->second;
460 if (!loaders->empty()) { 462 if (!loaders->empty()) {
461 ResourceRequestInfoImpl* info = loaders->front()->GetRequestInfo(); 463 ResourceRequestInfoImpl* info = loaders->front()->GetRequestInfo();
462 // http://crbug.com/90971 464 // http://crbug.com/90971
463 CHECK_NE(info->GetContext(), context); 465 CHECK_NE(info->GetContext(), context);
464 } 466 }
465 } 467 }
466 } 468 }
467 469
468 net::Error ResourceDispatcherHostImpl::BeginDownload( 470 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload(
469 scoped_ptr<net::URLRequest> request, 471 scoped_ptr<net::URLRequest> request,
470 const Referrer& referrer, 472 const Referrer& referrer,
471 bool is_content_initiated, 473 bool is_content_initiated,
472 ResourceContext* context, 474 ResourceContext* context,
473 int child_id, 475 int child_id,
474 int route_id, 476 int route_id,
475 bool prefer_cache, 477 bool prefer_cache,
476 scoped_ptr<DownloadSaveInfo> save_info, 478 scoped_ptr<DownloadSaveInfo> save_info,
477 uint32 download_id, 479 uint32 download_id,
478 const DownloadStartedCallback& started_callback) { 480 const DownloadStartedCallback& started_callback) {
479 if (is_shutdown_) 481 if (is_shutdown_)
480 return CallbackAndReturn(started_callback, net::ERR_INSUFFICIENT_RESOURCES); 482 return CallbackAndReturn(started_callback,
483 DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN);
481 484
482 const GURL& url = request->original_url(); 485 const GURL& url = request->original_url();
483 486
484 // http://crbug.com/90971 487 // http://crbug.com/90971
485 char url_buf[128]; 488 char url_buf[128];
486 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); 489 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf));
487 base::debug::Alias(url_buf); 490 base::debug::Alias(url_buf);
488 CHECK(ContainsKey(active_resource_contexts_, context)); 491 CHECK(ContainsKey(active_resource_contexts_, context));
489 492
490 SetReferrerForRequest(request.get(), referrer); 493 SetReferrerForRequest(request.get(), referrer);
(...skipping 17 matching lines...) Expand all
508 // we have an OfflinePolicy to receive request completions. 511 // we have an OfflinePolicy to receive request completions.
509 GlobalRoutingID id(child_id, route_id); 512 GlobalRoutingID id(child_id, route_id);
510 if (!offline_policy_map_[id]) 513 if (!offline_policy_map_[id])
511 offline_policy_map_[id] = new OfflinePolicy(); 514 offline_policy_map_[id] = new OfflinePolicy();
512 515
513 // Check if the renderer is permitted to request the requested URL. 516 // Check if the renderer is permitted to request the requested URL.
514 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> 517 if (!ChildProcessSecurityPolicyImpl::GetInstance()->
515 CanRequestURL(child_id, url)) { 518 CanRequestURL(child_id, url)) {
516 VLOG(1) << "Denied unauthorized download request for " 519 VLOG(1) << "Denied unauthorized download request for "
517 << url.possibly_invalid_spec(); 520 << url.possibly_invalid_spec();
518 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); 521 return CallbackAndReturn(started_callback,
522 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST);
519 } 523 }
520 524
521 request_id_--; 525 request_id_--;
522 526
523 const net::URLRequestContext* request_context = context->GetRequestContext(); 527 const net::URLRequestContext* request_context = context->GetRequestContext();
524 if (!request_context->job_factory()->IsHandledURL(url)) { 528 if (!request_context->job_factory()->IsHandledURL(url)) {
525 VLOG(1) << "Download request for unsupported protocol: " 529 VLOG(1) << "Download request for unsupported protocol: "
526 << url.possibly_invalid_spec(); 530 << url.possibly_invalid_spec();
527 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); 531 return CallbackAndReturn(started_callback,
532 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST);
528 } 533 }
529 534
530 ResourceRequestInfoImpl* extra_info = 535 ResourceRequestInfoImpl* extra_info =
531 CreateRequestInfo(child_id, route_id, true, context); 536 CreateRequestInfo(child_id, route_id, true, context);
532 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. 537 extra_info->AssociateWithRequest(request.get()); // Request takes ownership.
533 538
534 if (request->url().SchemeIs(chrome::kBlobScheme)) { 539 if (request->url().SchemeIs(chrome::kBlobScheme)) {
535 ChromeBlobStorageContext* blob_context = 540 ChromeBlobStorageContext* blob_context =
536 GetChromeBlobStorageContextForResourceContext(context); 541 GetChromeBlobStorageContextForResourceContext(context);
537 webkit_blob::BlobProtocolHandler::SetRequestedBlobDataHandle( 542 webkit_blob::BlobProtocolHandler::SetRequestedBlobDataHandle(
538 request.get(), 543 request.get(),
539 blob_context->context()->GetBlobDataFromPublicURL(request->url())); 544 blob_context->context()->GetBlobDataFromPublicURL(request->url()));
540 } 545 }
541 546
542 // From this point forward, the |DownloadResourceHandler| is responsible for 547 // From this point forward, the |DownloadResourceHandler| is responsible for
543 // |started_callback|. 548 // |started_callback|.
544 scoped_ptr<ResourceHandler> handler( 549 scoped_ptr<ResourceHandler> handler(
545 CreateResourceHandlerForDownload(request.get(), is_content_initiated, 550 CreateResourceHandlerForDownload(request.get(), is_content_initiated,
546 true, download_id, save_info.Pass(), 551 true, download_id, save_info.Pass(),
547 started_callback)); 552 started_callback));
548 553
549 BeginRequestInternal(request.Pass(), handler.Pass()); 554 BeginRequestInternal(request.Pass(), handler.Pass());
550 555
551 return net::OK; 556 return DOWNLOAD_INTERRUPT_REASON_NONE;
552 } 557 }
553 558
554 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest( 559 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest(
555 net::URLRequest* request) { 560 net::URLRequest* request) {
556 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 561 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
557 if (info) { 562 if (info) {
558 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID()); 563 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID());
559 if (loader) 564 if (loader)
560 loader->ClearLoginDelegate(); 565 loader->ClearLoginDelegate();
561 } 566 }
(...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) 1959 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS)
1955 && !policy->CanReadRawCookies(child_id)) { 1960 && !policy->CanReadRawCookies(child_id)) {
1956 VLOG(1) << "Denied unauthorized request for raw headers"; 1961 VLOG(1) << "Denied unauthorized request for raw headers";
1957 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; 1962 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS;
1958 } 1963 }
1959 1964
1960 return load_flags; 1965 return load_flags;
1961 } 1966 }
1962 1967
1963 } // namespace content 1968 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/public/browser/download_interrupt_reason_values.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698