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

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

Issue 519533002: Initial PlzNavigate RDH-side logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 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 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 "content/browser/frame_host/frame_tree_node.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/public/browser/browser_context.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"
18
19 namespace content {
20
21 NavigationURLLoaderCore::NavigationURLLoaderCore()
22 : delegate_(NULL),
23 resource_handler_(NULL) {
24 }
25
26 void NavigationURLLoaderCore::StartRequest(
27 BrowserContext* browser_context,
28 int64 frame_tree_node_id,
29 const NavigationRequestInfo& request_info,
30 ResourceRequestBody* request_body) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
32
33 BrowserThread::PostTask(
34 BrowserThread::IO, FROM_HERE,
mmenke 2014/09/23 17:22:45 Should include "base/location.h" for FROM_HERE
davidben 2014/10/03 16:27:52 Done.
35 base::Bind(&NavigationURLLoaderCore::StartRequestOnIOThread, this,
36 browser_context->GetResourceContext(),
37 frame_tree_node_id, request_info,
38 make_scoped_refptr(request_body)));
39 }
40
41 void NavigationURLLoaderCore::FollowRedirect() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
43
44 BrowserThread::PostTask(
45 BrowserThread::IO, FROM_HERE,
46 base::Bind(&NavigationURLLoaderCore::FollowRedirectOnIOThread, this));
47 }
48
49 void NavigationURLLoaderCore::Cancel() {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
51
52 BrowserThread::PostTask(
53 BrowserThread::IO, FROM_HERE,
54 base::Bind(&NavigationURLLoaderCore::CancelOnIOThread, this));
55 }
56
57 void NavigationURLLoaderCore::RequestRedirectedOnIOThread(
58 const net::RedirectInfo& redirect_info,
59 ResourceResponse* response) {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
61
62 BrowserThread::PostTask(
63 BrowserThread::UI, FROM_HERE,
64 base::Bind(&NavigationURLLoaderCore::CallOnRequestRedirected,
65 this, redirect_info, make_scoped_refptr(response)));
66 }
67
68 void NavigationURLLoaderCore::ResponseStartedOnIOThread(
69 ResourceResponse* response,
70 scoped_ptr<StreamHandle> body) {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
72
73 // Make a copy of the ResourceResponse before it is passed to another thread.
74 //
75 // TODO(davidben): This copy could be avoided if ResourceResponse weren't
76 // reference counted and the loader stack passed unique ownership of the
77 // response. https://crbug.com/416050
78 scoped_refptr<ResourceResponse> response_copy = new ResourceResponse;
79 response_copy->head = response->head;
mmenke 2014/09/23 17:22:45 Copying ResourceResponse is allowed, right? So we
davidben 2014/10/03 16:27:52 It doesn't actually have a copy constructor, sadly
80
81 BrowserThread::PostTask(
82 BrowserThread::UI, FROM_HERE,
83 base::Bind(&NavigationURLLoaderCore::CallOnResponseStarted,
84 this, response_copy, base::Passed(&body)));
85 }
86
87 void NavigationURLLoaderCore::RequestFailedOnIOThread(int net_error) {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
89
90 BrowserThread::PostTask(
91 BrowserThread::UI, FROM_HERE,
92 base::Bind(&NavigationURLLoaderCore::CallOnRequestFailed,
93 this, net_error));
94 }
95
96 NavigationURLLoaderCore::~NavigationURLLoaderCore() {
nasko 2014/09/24 21:15:34 Which thread should this object be destroyed on? C
davidben 2014/10/03 16:27:52 It actually could be either, which is kinda weird.
97 // The core may outlive either the delegate or the resource handler, so each
nasko 2014/09/24 21:15:34 "may" or "should"? If it is "may", then there is a
davidben 2014/10/03 16:27:52 Rephrased to be slightly less confusing hopefully.
98 // should NULL references on detach. At this point, both should be NULL.
99 DCHECK(!delegate_);
100 DCHECK(!resource_handler_);
101 }
102
103 void NavigationURLLoaderCore::StartRequestOnIOThread(
104 ResourceContext* resource_context,
105 int64 frame_tree_node_id,
106 const NavigationRequestInfo& request_info,
107 ResourceRequestBody* request_body) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
109
110 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest(
111 resource_context, frame_tree_node_id, request_info, request_body,
112 this);
113 }
114
115 void NavigationURLLoaderCore::FollowRedirectOnIOThread() {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
117
118 if (resource_handler_)
119 resource_handler_->FollowRedirect();
120 }
121
122 void NavigationURLLoaderCore::CancelOnIOThread() {
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
124
125 if (resource_handler_)
126 resource_handler_->Cancel();
127 }
128
129 void NavigationURLLoaderCore::CallOnRequestRedirected(
130 const net::RedirectInfo& redirect_info,
131 ResourceResponse* response) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
133
134 if (delegate_)
135 delegate_->OnRequestRedirected(redirect_info, response);
136 }
137
138 void NavigationURLLoaderCore::CallOnResponseStarted(
139 ResourceResponse* response,
140 scoped_ptr<StreamHandle> body) {
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
142
143 // If |delegate_| is NULL, OnResponseStarted on the IO thread raced with
144 // Cancel on the UI thread. |body| will be destructed and the request released
145 // at that point.
146 if (delegate_)
147 delegate_->OnResponseStarted(response, body.Pass());
148 }
149
150 void NavigationURLLoaderCore::CallOnRequestFailed(int net_error) {
151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
152
153 if (delegate_)
154 delegate_->OnRequestFailed(net_error);
155 }
156
157 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698