OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ppapi/proxy/url_loader_resource.h" | 5 #include "ppapi/proxy/url_loader_resource.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/numerics/safe_conversions.h" |
8 #include "ppapi/c/pp_completion_callback.h" | 9 #include "ppapi/c/pp_completion_callback.h" |
9 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/ppb_url_loader.h" | 11 #include "ppapi/c/ppb_url_loader.h" |
11 #include "ppapi/proxy/dispatch_reply_message.h" | 12 #include "ppapi/proxy/dispatch_reply_message.h" |
12 #include "ppapi/proxy/file_ref_resource.h" | 13 #include "ppapi/proxy/file_ref_resource.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
14 #include "ppapi/proxy/url_request_info_resource.h" | 15 #include "ppapi/proxy/url_request_info_resource.h" |
15 #include "ppapi/proxy/url_response_info_resource.h" | 16 #include "ppapi/proxy/url_response_info_resource.h" |
16 #include "ppapi/shared_impl/ppapi_globals.h" | 17 #include "ppapi/shared_impl/ppapi_globals.h" |
17 #include "ppapi/shared_impl/url_response_info_data.h" | 18 #include "ppapi/shared_impl/url_response_info_data.h" |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 PP_Resource body_as_file_ref = 0; | 368 PP_Resource body_as_file_ref = 0; |
368 if (data.body_as_file_ref.IsValid()) { | 369 if (data.body_as_file_ref.IsValid()) { |
369 body_as_file_ref = FileRefResource::CreateFileRef(connection(), | 370 body_as_file_ref = FileRefResource::CreateFileRef(connection(), |
370 pp_instance(), | 371 pp_instance(), |
371 data.body_as_file_ref); | 372 data.body_as_file_ref); |
372 } | 373 } |
373 response_info_ = new URLResponseInfoResource( | 374 response_info_ = new URLResponseInfoResource( |
374 connection(), pp_instance(), data, body_as_file_ref); | 375 connection(), pp_instance(), data, body_as_file_ref); |
375 } | 376 } |
376 | 377 |
377 size_t URLLoaderResource::FillUserBuffer() { | 378 int32_t URLLoaderResource::FillUserBuffer() { |
378 DCHECK(user_buffer_); | 379 DCHECK(user_buffer_); |
379 DCHECK(user_buffer_size_); | 380 DCHECK(user_buffer_size_); |
380 | 381 |
381 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_); | 382 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_); |
382 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_); | 383 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_); |
383 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy); | 384 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy); |
384 | 385 |
385 // If the buffer is getting too empty, resume asynchronous loading. | 386 // If the buffer is getting too empty, resume asynchronous loading. |
386 if (is_asynchronous_load_suspended_ && | 387 if (is_asynchronous_load_suspended_ && |
387 buffer_.size() <= static_cast<size_t>( | 388 buffer_.size() <= static_cast<size_t>( |
388 request_data_.prefetch_buffer_lower_threshold)) { | 389 request_data_.prefetch_buffer_lower_threshold)) { |
389 DVLOG(1) << "Resuming async load - buffer size: " << buffer_.size(); | 390 DVLOG(1) << "Resuming async load - buffer size: " << buffer_.size(); |
390 SetDefersLoading(false); | 391 SetDefersLoading(false); |
391 } | 392 } |
392 | 393 |
393 // Reset for next time. | 394 // Reset for next time. |
394 user_buffer_ = NULL; | 395 user_buffer_ = NULL; |
395 user_buffer_size_ = 0; | 396 user_buffer_size_ = 0; |
396 return bytes_to_copy; | 397 return base::checked_cast<int32_t>(bytes_to_copy); |
397 } | 398 } |
398 | 399 |
399 } // namespace proxy | 400 } // namespace proxy |
400 } // namespace ppapi | 401 } // namespace ppapi |
OLD | NEW |