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

Unified Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 23496076: WIP - Refactor programmatic downloads Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/net/referrer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/loader/resource_dispatcher_host_impl.cc
diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc
index 9c29a28cb911278decb182d32d28838666afcb00..9ff7fb9f09acebf0cca094e2b121da5a1944f8bc 100644
--- a/content/browser/loader/resource_dispatcher_host_impl.cc
+++ b/content/browser/loader/resource_dispatcher_host_impl.cc
@@ -11,7 +11,6 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
#include "base/logging.h"
@@ -42,6 +41,7 @@
#include "content/browser/loader/throttling_resource_handler.h"
#include "content/browser/loader/transfer_navigation_resource_throttle.h"
#include "content/browser/loader/upload_data_stream_builder.h"
+#include "content/browser/net/referrer.h"
#include "content/browser/plugin_service_impl.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
@@ -63,7 +63,6 @@
#include "content/public/browser/resource_throttle.h"
#include "content/public/browser/stream_handle.h"
#include "content/public/browser/user_metrics.h"
-#include "content/public/common/content_switches.h"
#include "content/public/common/process_type.h"
#include "content/public/common/url_constants.h"
#include "ipc/ipc_message_macros.h"
@@ -128,14 +127,6 @@ const int kUserGestureWindowMs = 3500;
// use. Arbitrarily chosen.
const double kMaxRequestsPerProcessRatio = 0.45;
-// All possible error codes from the network module. Note that the error codes
-// are all positive (since histograms expect positive sample values).
-const int kAllNetErrorCodes[] = {
-#define NET_ERROR(label, value) -(value),
-#include "net/base/net_error_list.h"
-#undef NET_ERROR
-};
-
// Aborts a request before an URLRequest has actually been created.
void AbortRequestBeforeItStarts(ResourceMessageFilter* filter,
IPC::Message* sync_result,
@@ -156,30 +147,6 @@ void AbortRequestBeforeItStarts(ResourceMessageFilter* filter,
}
}
-void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) {
- if (!referrer.url.is_valid() ||
- CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) {
- request->SetReferrer(std::string());
- } else {
- request->SetReferrer(referrer.url.spec());
- }
-
- net::URLRequest::ReferrerPolicy net_referrer_policy =
- net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
- switch (referrer.policy) {
- case WebKit::WebReferrerPolicyDefault:
- net_referrer_policy =
- net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
- break;
- case WebKit::WebReferrerPolicyAlways:
- case WebKit::WebReferrerPolicyNever:
- case WebKit::WebReferrerPolicyOrigin:
- net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER;
- break;
- }
- request->set_referrer_policy(net_referrer_policy);
-}
-
// Consults the RendererSecurity policy to determine whether the
// ResourceDispatcherHostImpl should service this request. A request might be
// disallowed if the renderer is not authorized to retrieve the request URL or
@@ -244,18 +211,6 @@ void RemoveDownloadFileFromChildSecurityPolicy(int child_id,
#pragma warning(default: 4748)
#endif
-net::Error CallbackAndReturn(
- const DownloadUrlParameters::OnStartedCallback& started_cb,
- net::Error net_error) {
- if (started_cb.is_null())
- return net_error;
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(started_cb, static_cast<DownloadItem*>(NULL), net_error));
-
- return net_error;
-}
-
int GetCertID(net::URLRequest* request, int child_id) {
if (request->ssl_info().cert.get()) {
return CertStore::GetInstance()->StoreCert(request->ssl_info().cert.get(),
@@ -445,92 +400,6 @@ void ResourceDispatcherHostImpl::CancelRequestsForContext(
}
}
-net::Error ResourceDispatcherHostImpl::BeginDownload(
- scoped_ptr<net::URLRequest> request,
- const Referrer& referrer,
- bool is_content_initiated,
- ResourceContext* context,
- int child_id,
- int route_id,
- bool prefer_cache,
- scoped_ptr<DownloadSaveInfo> save_info,
- uint32 download_id,
- const DownloadStartedCallback& started_callback) {
- if (is_shutdown_)
- return CallbackAndReturn(started_callback, net::ERR_INSUFFICIENT_RESOURCES);
-
- const GURL& url = request->original_url();
-
- // http://crbug.com/90971
- char url_buf[128];
- base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf));
- base::debug::Alias(url_buf);
- CHECK(ContainsKey(active_resource_contexts_, context));
-
- SetReferrerForRequest(request.get(), referrer);
-
- int extra_load_flags = net::LOAD_IS_DOWNLOAD;
- if (prefer_cache) {
- // If there is upload data attached, only retrieve from cache because there
- // is no current mechanism to prompt the user for their consent for a
- // re-post. For GETs, try to retrieve data from the cache and skip
- // validating the entry if present.
- if (request->get_upload() != NULL)
- extra_load_flags |= net::LOAD_ONLY_FROM_CACHE;
- else
- extra_load_flags |= net::LOAD_PREFERRING_CACHE;
- } else {
- extra_load_flags |= net::LOAD_DISABLE_CACHE;
- }
- request->set_load_flags(request->load_flags() | extra_load_flags);
-
- // No need to get offline load flags for downloads, but make sure
- // we have an OfflinePolicy to receive request completions.
- GlobalRoutingID id(child_id, route_id);
- if (!offline_policy_map_[id])
- offline_policy_map_[id] = new OfflinePolicy();
-
- // Check if the renderer is permitted to request the requested URL.
- if (!ChildProcessSecurityPolicyImpl::GetInstance()->
- CanRequestURL(child_id, url)) {
- VLOG(1) << "Denied unauthorized download request for "
- << url.possibly_invalid_spec();
- return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED);
- }
-
- request_id_--;
-
- const net::URLRequestContext* request_context = context->GetRequestContext();
- if (!request_context->job_factory()->IsHandledURL(url)) {
- VLOG(1) << "Download request for unsupported protocol: "
- << url.possibly_invalid_spec();
- return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED);
- }
-
- ResourceRequestInfoImpl* extra_info =
- CreateRequestInfo(child_id, route_id, true, context);
- extra_info->AssociateWithRequest(request.get()); // Request takes ownership.
-
- if (request->url().SchemeIs(chrome::kBlobScheme)) {
- ChromeBlobStorageContext* blob_context =
- GetChromeBlobStorageContextForResourceContext(context);
- webkit_blob::BlobProtocolHandler::SetRequestedBlobDataHandle(
- request.get(),
- blob_context->context()->GetBlobDataFromPublicURL(request->url()));
- }
-
- // From this point forward, the |DownloadResourceHandler| is responsible for
- // |started_callback|.
- scoped_ptr<ResourceHandler> handler(
- CreateResourceHandlerForDownload(request.get(), is_content_initiated,
- true, download_id, save_info.Pass(),
- started_callback));
-
- BeginRequestInternal(request.Pass(), handler.Pass());
-
- return net::OK;
-}
-
void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest(
net::URLRequest* request) {
ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
@@ -552,13 +421,8 @@ void ResourceDispatcherHostImpl::Shutdown() {
scoped_ptr<ResourceHandler>
ResourceDispatcherHostImpl::CreateResourceHandlerForDownload(
net::URLRequest* request,
- bool is_content_initiated,
- bool must_download,
- uint32 id,
- scoped_ptr<DownloadSaveInfo> save_info,
- const DownloadUrlParameters::OnStartedCallback& started_cb) {
- scoped_ptr<ResourceHandler> handler(
- new DownloadResourceHandler(id, request, started_cb, save_info.Pass()));
+ bool must_download) {
+ scoped_ptr<ResourceHandler> handler(new DownloadResourceHandler(request));
if (delegate_) {
const ResourceRequestInfo* request_info(
ResourceRequestInfo::ForRequest(request));
@@ -567,7 +431,7 @@ ResourceDispatcherHostImpl::CreateResourceHandlerForDownload(
delegate_->DownloadStarting(
request, request_info->GetContext(), request_info->GetChildID(),
request_info->GetRouteID(), request_info->GetRequestID(),
- is_content_initiated, must_download, &throttles);
+ true /* content_intiated */, must_download, &throttles);
if (!throttles.empty()) {
handler.reset(
new ThrottlingResourceHandler(
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/net/referrer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698