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

Side by Side Diff: components/html_viewer/web_url_loader_impl.cc

Issue 1096243004: Perform a sizet->int checked_cast in WebURLLoaderImpl::OnReceiveWebBlobData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment typo. Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/html_viewer/web_url_loader_impl.h" 5 #include "components/html_viewer/web_url_loader_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/numerics/safe_conversions.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
11 #include "components/html_viewer/blink_url_request_type_converters.h" 12 #include "components/html_viewer/blink_url_request_type_converters.h"
12 #include "mojo/common/common_type_converters.h" 13 #include "mojo/common/common_type_converters.h"
13 #include "mojo/common/url_type_converters.h" 14 #include "mojo/common/url_type_converters.h"
14 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 15 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
15 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
16 #include "third_party/WebKit/public/platform/WebURLError.h" 17 #include "third_party/WebKit/public/platform/WebURLError.h"
17 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" 18 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h"
18 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" 19 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 244
244 base::WeakPtr<WebURLLoaderImpl> self(weak_factory_.GetWeakPtr()); 245 base::WeakPtr<WebURLLoaderImpl> self(weak_factory_.GetWeakPtr());
245 client_->didReceiveResponse(this, result); 246 client_->didReceiveResponse(this, result);
246 247
247 // We may have been deleted during didReceiveResponse. 248 // We may have been deleted during didReceiveResponse.
248 if (!self) 249 if (!self)
249 return; 250 return;
250 251
251 // Send a receive data for each blob item. 252 // Send a receive data for each blob item.
252 for (size_t i = 0; i < items.size(); ++i) { 253 for (size_t i = 0; i < items.size(); ++i) {
253 client_->didReceiveData(this, items[i]->data.data(), items[i]->data.size(), 254 const int data_size = base::checked_cast<int>(items[i]->data.size());
254 -1); 255 client_->didReceiveData(this, items[i]->data.data(), data_size, -1);
255 } 256 }
256 257
257 // Send a closing finish. 258 // Send a closing finish.
258 double finish_time = base::Time::Now().ToDoubleT(); 259 double finish_time = base::Time::Now().ToDoubleT();
259 client_->didFinishLoading( 260 client_->didFinishLoading(
260 this, finish_time, blink::WebURLLoaderClient::kUnknownEncodedDataLength); 261 this, finish_time, blink::WebURLLoaderClient::kUnknownEncodedDataLength);
261 } 262 }
262 263
263 void WebURLLoaderImpl::ReadMore() { 264 void WebURLLoaderImpl::ReadMore() {
264 const void* buf; 265 const void* buf;
265 uint32_t buf_size; 266 uint32_t buf_size;
266 MojoResult rv = BeginReadDataRaw(response_body_stream_.get(), 267 MojoResult rv = BeginReadDataRaw(response_body_stream_.get(),
267 &buf, 268 &buf,
268 &buf_size, 269 &buf_size,
269 MOJO_READ_DATA_FLAG_NONE); 270 MOJO_READ_DATA_FLAG_NONE);
270 if (rv == MOJO_RESULT_OK) { 271 if (rv == MOJO_RESULT_OK) {
271 base::WeakPtr<WebURLLoaderImpl> self(weak_factory_.GetWeakPtr()); 272 base::WeakPtr<WebURLLoaderImpl> self(weak_factory_.GetWeakPtr());
272 client_->didReceiveData(this, static_cast<const char*>(buf), buf_size, -1); 273 client_->didReceiveData(this, static_cast<const char*>(buf), buf_size, -1);
273 // We may have been deleted durining didReceiveData. 274 // We may have been deleted during didReceiveData.
274 if (!self) 275 if (!self)
275 return; 276 return;
276 EndReadDataRaw(response_body_stream_.get(), buf_size); 277 EndReadDataRaw(response_body_stream_.get(), buf_size);
277 WaitToReadMore(); 278 WaitToReadMore();
278 } else if (rv == MOJO_RESULT_SHOULD_WAIT) { 279 } else if (rv == MOJO_RESULT_SHOULD_WAIT) {
279 WaitToReadMore(); 280 WaitToReadMore();
280 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) { 281 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) {
281 // We reached end-of-file. 282 // We reached end-of-file.
282 double finish_time = base::Time::Now().ToDoubleT(); 283 double finish_time = base::Time::Now().ToDoubleT();
283 client_->didFinishLoading( 284 client_->didFinishLoading(
(...skipping 12 matching lines...) Expand all
296 MOJO_DEADLINE_INDEFINITE, 297 MOJO_DEADLINE_INDEFINITE,
297 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady, 298 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady,
298 weak_factory_.GetWeakPtr())); 299 weak_factory_.GetWeakPtr()));
299 } 300 }
300 301
301 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) { 302 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) {
302 ReadMore(); 303 ReadMore();
303 } 304 }
304 305
305 } // namespace html_viewer 306 } // namespace html_viewer
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698