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

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

Issue 648813002: PlzNavigate: Add first version of NavigationURLLoader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plz-navigate-prepare
Patch Set: rebase, OVERRIDE -> override, NULL -> nullptr Created 6 years, 2 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
OLDNEW
(Empty)
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.
4
5 #include "content/browser/loader/navigation_url_loader_core.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "content/browser/frame_host/frame_tree_node.h"
10 #include "content/browser/frame_host/navigation_request_info.h"
11 #include "content/browser/loader/navigation_resource_handler.h"
12 #include "content/browser/loader/resource_dispatcher_host_impl.h"
13 #include "content/common/navigation_params.h"
14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/stream_handle.h"
17 #include "content/public/common/resource_response.h"
18 #include "net/base/net_errors.h"
19 #include "net/url_request/redirect_info.h"
20
21 namespace content {
22
23 NavigationURLLoaderCore::NavigationURLLoaderCore()
24 : delegate_(nullptr),
25 resource_handler_(nullptr) {
26 }
27
28 void NavigationURLLoaderCore::StartRequest(
29 BrowserContext* browser_context,
30 int64 frame_tree_node_id,
31 const CommonNavigationParams& common_params,
32 scoped_ptr<NavigationRequestInfo> request_info,
33 ResourceRequestBody* request_body) {
34 DCHECK_CURRENTLY_ON(BrowserThread::UI);
35
36 BrowserThread::PostTask(
37 BrowserThread::IO, FROM_HERE,
38 base::Bind(&NavigationURLLoaderCore::StartRequestOnIOThread, this,
39 browser_context->GetResourceContext(),
40 frame_tree_node_id, common_params, base::Passed(&request_info),
41 make_scoped_refptr(request_body)));
42 }
43
44 void NavigationURLLoaderCore::FollowRedirect() {
45 DCHECK_CURRENTLY_ON(BrowserThread::UI);
46
47 BrowserThread::PostTask(
48 BrowserThread::IO, FROM_HERE,
49 base::Bind(&NavigationURLLoaderCore::FollowRedirectOnIOThread, this));
50 }
51
52 void NavigationURLLoaderCore::Cancel() {
53 DCHECK_CURRENTLY_ON(BrowserThread::UI);
54
55 BrowserThread::PostTask(
56 BrowserThread::IO, FROM_HERE,
57 base::Bind(&NavigationURLLoaderCore::CancelOnIOThread, this));
58 }
59
60 void NavigationURLLoaderCore::RequestRedirectedOnIOThread(
61 const net::RedirectInfo& redirect_info,
62 ResourceResponse* response) {
63 DCHECK_CURRENTLY_ON(BrowserThread::IO);
64
65 // Make a copy of the ResourceResponse before it is passed to another thread.
66 //
67 // TODO(davidben): This copy could be avoided if ResourceResponse weren't
68 // reference counted and the loader stack passed unique ownership of the
69 // response. https://crbug.com/416050
70 BrowserThread::PostTask(
71 BrowserThread::UI, FROM_HERE,
72 base::Bind(&NavigationURLLoaderCore::CallOnRequestRedirected,
73 this, redirect_info, response->DeepCopy()));
74 }
75
76 void NavigationURLLoaderCore::ResponseStartedOnIOThread(
77 ResourceResponse* response,
78 scoped_ptr<StreamHandle> body) {
79 DCHECK_CURRENTLY_ON(BrowserThread::IO);
80
81 // Make a copy of the ResourceResponse before it is passed to another thread.
82 //
83 // TODO(davidben): This copy could be avoided if ResourceResponse weren't
84 // reference counted and the loader stack passed unique ownership of the
85 // response. https://crbug.com/416050
86 BrowserThread::PostTask(
87 BrowserThread::UI, FROM_HERE,
88 base::Bind(&NavigationURLLoaderCore::CallOnResponseStarted,
89 this, response->DeepCopy(), base::Passed(&body)));
90 }
91
92 void NavigationURLLoaderCore::RequestFailedOnIOThread(int net_error) {
93 DCHECK_CURRENTLY_ON(BrowserThread::IO);
94
95 BrowserThread::PostTask(
96 BrowserThread::UI, FROM_HERE,
97 base::Bind(&NavigationURLLoaderCore::CallOnRequestFailed,
98 this, net_error));
99 }
100
101 NavigationURLLoaderCore::~NavigationURLLoaderCore() {
102 // When the core is released by either the delegate or the resource handler,
103 // the corresponding pointers are nulled. At this point, both should be
104 // nullptr.
105 DCHECK(!delegate_);
106 DCHECK(!resource_handler_);
107 }
108
109 void NavigationURLLoaderCore::StartRequestOnIOThread(
110 ResourceContext* resource_context,
111 int64 frame_tree_node_id,
112 const CommonNavigationParams& common_params,
113 scoped_ptr<NavigationRequestInfo> request_info,
114 ResourceRequestBody* request_body) {
115 DCHECK_CURRENTLY_ON(BrowserThread::IO);
116
117 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest(
118 resource_context, frame_tree_node_id,
119 common_params, *request_info, request_body,
120 this);
121 }
122
123 void NavigationURLLoaderCore::FollowRedirectOnIOThread() {
124 DCHECK_CURRENTLY_ON(BrowserThread::IO);
125
126 if (resource_handler_)
127 resource_handler_->FollowRedirect();
128 }
129
130 void NavigationURLLoaderCore::CancelOnIOThread() {
131 DCHECK_CURRENTLY_ON(BrowserThread::IO);
132
133 if (resource_handler_)
134 resource_handler_->Cancel();
135 }
136
137 void NavigationURLLoaderCore::CallOnRequestRedirected(
138 const net::RedirectInfo& redirect_info,
139 ResourceResponse* response) {
140 DCHECK_CURRENTLY_ON(BrowserThread::UI);
141
142 if (delegate_)
143 delegate_->OnRequestRedirected(redirect_info, response);
144 }
145
146 void NavigationURLLoaderCore::CallOnResponseStarted(
147 ResourceResponse* response,
148 scoped_ptr<StreamHandle> body) {
149 DCHECK_CURRENTLY_ON(BrowserThread::UI);
150
151 // If |delegate_| is nullptr, OnResponseStarted on the IO thread raced with
152 // Cancel on the UI thread. |body| will be destructed and the request released
153 // at that point.
154 if (delegate_)
155 delegate_->OnResponseStarted(response, body.Pass());
156 }
157
158 void NavigationURLLoaderCore::CallOnRequestFailed(int net_error) {
159 DCHECK_CURRENTLY_ON(BrowserThread::UI);
160
161 if (delegate_)
162 delegate_->OnRequestFailed(net_error);
163 }
164
165 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698