Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / loader / navigation_url_loader_impl_core.cc
blob48845e8aa0c26976ecb6eee07461a88ef7ea4a1a
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/loader/navigation_url_loader_impl_core.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "content/browser/frame_host/navigation_request_info.h"
10 #include "content/browser/loader/navigation_resource_handler.h"
11 #include "content/browser/loader/resource_dispatcher_host_impl.h"
12 #include "content/common/navigation_params.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/stream_handle.h"
15 #include "content/public/common/resource_response.h"
16 #include "net/base/net_errors.h"
17 #include "net/url_request/redirect_info.h"
19 namespace content {
21 NavigationURLLoaderImplCore::NavigationURLLoaderImplCore(
22 const base::WeakPtr<NavigationURLLoaderImpl>& loader)
23 : loader_(loader),
24 resource_handler_(nullptr) {
25 // This object is created on the UI thread but otherwise is accessed and
26 // deleted on the IO thread.
27 DCHECK_CURRENTLY_ON(BrowserThread::UI);
30 NavigationURLLoaderImplCore::~NavigationURLLoaderImplCore() {
31 DCHECK_CURRENTLY_ON(BrowserThread::IO);
33 if (resource_handler_)
34 resource_handler_->Cancel();
37 void NavigationURLLoaderImplCore::Start(
38 ResourceContext* resource_context,
39 int64 frame_tree_node_id,
40 const CommonNavigationParams& common_params,
41 scoped_ptr<NavigationRequestInfo> request_info,
42 ResourceRequestBody* request_body) {
43 DCHECK_CURRENTLY_ON(BrowserThread::IO);
45 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest(
46 resource_context, frame_tree_node_id,
47 common_params, *request_info, request_body,
48 this);
51 void NavigationURLLoaderImplCore::FollowRedirect() {
52 DCHECK_CURRENTLY_ON(BrowserThread::IO);
54 if (resource_handler_)
55 resource_handler_->FollowRedirect();
59 void NavigationURLLoaderImplCore::NotifyRequestRedirected(
60 const net::RedirectInfo& redirect_info,
61 ResourceResponse* response) {
62 DCHECK_CURRENTLY_ON(BrowserThread::IO);
64 // Make a copy of the ResourceResponse before it is passed to another thread.
66 // TODO(davidben): This copy could be avoided if ResourceResponse weren't
67 // reference counted and the loader stack passed unique ownership of the
68 // response. https://crbug.com/416050
69 BrowserThread::PostTask(
70 BrowserThread::UI, FROM_HERE,
71 base::Bind(&NavigationURLLoaderImpl::NotifyRequestRedirected, loader_,
72 redirect_info, response->DeepCopy()));
75 void NavigationURLLoaderImplCore::NotifyResponseStarted(
76 ResourceResponse* response,
77 scoped_ptr<StreamHandle> body) {
78 DCHECK_CURRENTLY_ON(BrowserThread::IO);
80 // If, by the time the task reaches the UI thread, |loader_| has already been
81 // destroyed, NotifyResponseStarted will not run. |body| will be destructed
82 // and the request released at that point.
84 // Make a copy of the ResourceResponse before it is passed to another thread.
86 // TODO(davidben): This copy could be avoided if ResourceResponse weren't
87 // reference counted and the loader stack passed unique ownership of the
88 // response. https://crbug.com/416050
89 BrowserThread::PostTask(
90 BrowserThread::UI, FROM_HERE,
91 base::Bind(&NavigationURLLoaderImpl::NotifyResponseStarted, loader_,
92 response->DeepCopy(), base::Passed(&body)));
95 void NavigationURLLoaderImplCore::NotifyRequestFailed(int net_error) {
96 DCHECK_CURRENTLY_ON(BrowserThread::IO);
98 BrowserThread::PostTask(
99 BrowserThread::UI, FROM_HERE,
100 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_,
101 net_error));
104 } // namespace content