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

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

Issue 2476163003: Refactor ResourceHandler API. (Closed)
Patch Set: Minor cleanups, one real fix Created 4 years, 1 month 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #include "content/browser/loader/navigation_resource_handler.h" 5 #include "content/browser/loader/navigation_resource_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/browser/loader/navigation_url_loader_impl_core.h" 10 #include "content/browser/loader/navigation_url_loader_impl_core.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // StreamHandle sent in OnResponseStarted. 66 // StreamHandle sent in OnResponseStarted.
67 DetachFromCore(); 67 DetachFromCore();
68 controller()->Resume(); 68 controller()->Resume();
69 } 69 }
70 70
71 void NavigationResourceHandler::SetController(ResourceController* controller) { 71 void NavigationResourceHandler::SetController(ResourceController* controller) {
72 writer_.set_controller(controller); 72 writer_.set_controller(controller);
73 ResourceHandler::SetController(controller); 73 ResourceHandler::SetController(controller);
74 } 74 }
75 75
76 bool NavigationResourceHandler::OnRequestRedirected( 76 void NavigationResourceHandler::OnRequestRedirected(
77 const net::RedirectInfo& redirect_info, 77 const net::RedirectInfo& redirect_info,
78 ResourceResponse* response, 78 ResourceResponse* response,
79 bool* defer) { 79 bool* defer_or_cancel) {
80 DCHECK(core_); 80 DCHECK(core_);
81 81
82 // TODO(davidben): Perform a CSP check here, and anything else that would have 82 // TODO(davidben): Perform a CSP check here, and anything else that would have
83 // been done renderer-side. 83 // been done renderer-side.
84 NetLogObserver::PopulateResponseInfo(request(), response); 84 NetLogObserver::PopulateResponseInfo(request(), response);
85 response->head.encoded_data_length = request()->GetTotalReceivedBytes(); 85 response->head.encoded_data_length = request()->GetTotalReceivedBytes();
86 core_->NotifyRequestRedirected(redirect_info, response); 86 core_->NotifyRequestRedirected(redirect_info, response);
87 *defer = true; 87 *defer_or_cancel = true;
88 return true;
89 } 88 }
90 89
91 bool NavigationResourceHandler::OnResponseStarted(ResourceResponse* response, 90 void NavigationResourceHandler::OnResponseStarted(ResourceResponse* response,
92 bool* defer) { 91 bool* defer_or_cancel) {
93 DCHECK(core_); 92 DCHECK(core_);
94 93
95 ResourceRequestInfoImpl* info = GetRequestInfo(); 94 ResourceRequestInfoImpl* info = GetRequestInfo();
96 95
97 // If the MimeTypeResourceHandler intercepted this request and converted it 96 // If the MimeTypeResourceHandler intercepted this request and converted it
98 // into a download, it will still call OnResponseStarted and immediately 97 // into a download, it will still call OnResponseStarted and immediately
99 // cancel. Ignore the call; OnReadCompleted will happen shortly. 98 // cancel. Ignore the call; OnReadCompleted will happen shortly.
100 // 99 //
101 // TODO(davidben): Move the dispatch out of MimeTypeResourceHandler. Perhaps 100 // TODO(davidben): Move the dispatch out of MimeTypeResourceHandler. Perhaps
102 // all the way to the UI thread. Downloads, user certificates, etc., should be 101 // all the way to the UI thread. Downloads, user certificates, etc., should be
103 // dispatched at the navigation layer. 102 // dispatched at the navigation layer.
104 if (info->IsDownload()) 103 if (info->IsDownload())
105 return true; 104 return;
106 105
107 StreamContext* stream_context = 106 StreamContext* stream_context =
108 GetStreamContextForResourceContext(info->GetContext()); 107 GetStreamContextForResourceContext(info->GetContext());
109 writer_.InitializeStream(stream_context->registry(), 108 writer_.InitializeStream(stream_context->registry(),
110 request()->url().GetOrigin()); 109 request()->url().GetOrigin());
111 110
112 NetLogObserver::PopulateResponseInfo(request(), response); 111 NetLogObserver::PopulateResponseInfo(request(), response);
113 112
114 std::unique_ptr<NavigationData> cloned_data; 113 std::unique_ptr<NavigationData> cloned_data;
115 if (resource_dispatcher_host_delegate_) { 114 if (resource_dispatcher_host_delegate_) {
(...skipping 14 matching lines...) Expand all
130 129
131 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle(), 130 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle(),
132 ssl_status, std::move(cloned_data)); 131 ssl_status, std::move(cloned_data));
133 // Don't defer stream based requests. This includes requests initiated via 132 // Don't defer stream based requests. This includes requests initiated via
134 // mime type sniffing, etc. 133 // mime type sniffing, etc.
135 // TODO(ananta) 134 // TODO(ananta)
136 // Make sure that the requests go through the throttle checks. Currently this 135 // Make sure that the requests go through the throttle checks. Currently this
137 // does not work as the InterceptingResourceHandler is above us and hence it 136 // does not work as the InterceptingResourceHandler is above us and hence it
138 // does not expect the old handler to defer the request. 137 // does not expect the old handler to defer the request.
139 if (!info->is_stream()) 138 if (!info->is_stream())
140 *defer = true; 139 *defer_or_cancel = true;
141 return true;
142 } 140 }
143 141
144 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { 142 void NavigationResourceHandler::OnWillStart(const GURL& url,
145 return true; 143 bool* defer_or_cancel) {}
146 }
147 144
148 bool NavigationResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, 145 bool NavigationResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
149 int* buf_size, 146 int* buf_size,
150 int min_size) { 147 int min_size) {
151 writer_.OnWillRead(buf, buf_size, min_size); 148 writer_.OnWillRead(buf, buf_size, min_size);
152 return true; 149 return true;
153 } 150 }
154 151
155 bool NavigationResourceHandler::OnReadCompleted(int bytes_read, bool* defer) { 152 void NavigationResourceHandler::OnReadCompleted(int bytes_read,
156 writer_.OnReadCompleted(bytes_read, defer); 153 bool* defer_or_cancel) {
157 return true; 154 writer_.OnReadCompleted(bytes_read, defer_or_cancel);
158 } 155 }
159 156
160 void NavigationResourceHandler::OnResponseCompleted( 157 void NavigationResourceHandler::OnResponseCompleted(
161 const net::URLRequestStatus& status, 158 const net::URLRequestStatus& status,
162 bool* defer) { 159 bool* defer) {
163 // If the request has already committed, close the stream and leave it as-is. 160 // If the request has already committed, close the stream and leave it as-is.
164 if (writer_.stream()) { 161 if (writer_.stream()) {
165 writer_.Finalize(status.error()); 162 writer_.Finalize(status.error());
166 return; 163 return;
167 } 164 }
(...skipping 10 matching lines...) Expand all
178 NOTREACHED(); 175 NOTREACHED();
179 } 176 }
180 177
181 void NavigationResourceHandler::DetachFromCore() { 178 void NavigationResourceHandler::DetachFromCore() {
182 DCHECK(core_); 179 DCHECK(core_);
183 core_->set_resource_handler(nullptr); 180 core_->set_resource_handler(nullptr);
184 core_ = nullptr; 181 core_ = nullptr;
185 } 182 }
186 183
187 } // namespace content 184 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/navigation_resource_handler.h ('k') | content/browser/loader/redirect_to_file_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698