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

Side by Side Diff: media/blink/resource_multibuffer_data_provider.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "media/blink/resource_multibuffer_data_provider.h" 5 #include "media/blink/resource_multibuffer_data_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bits.h" 8 #include "base/bits.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 base::Time last_modified; 210 base::Time last_modified;
211 if (base::Time::FromString( 211 if (base::Time::FromString(
212 response.httpHeaderField("Last-Modified").utf8().data(), 212 response.httpHeaderField("Last-Modified").utf8().data(),
213 &last_modified)) { 213 &last_modified)) {
214 destination_url_data->set_last_modified(last_modified); 214 destination_url_data->set_last_modified(last_modified);
215 } 215 }
216 216
217 destination_url_data->set_valid_until(base::Time::Now() + 217 destination_url_data->set_valid_until(base::Time::Now() +
218 GetCacheValidUntil(response)); 218 GetCacheValidUntil(response));
219 219
220 uint32 reasons = GetReasonsForUncacheability(response); 220 uint32_t reasons = GetReasonsForUncacheability(response);
221 destination_url_data->set_cacheable(reasons == 0); 221 destination_url_data->set_cacheable(reasons == 0);
222 UMA_HISTOGRAM_BOOLEAN("Media.CacheUseful", reasons == 0); 222 UMA_HISTOGRAM_BOOLEAN("Media.CacheUseful", reasons == 0);
223 int shift = 0; 223 int shift = 0;
224 int max_enum = base::bits::Log2Ceiling(kMaxReason); 224 int max_enum = base::bits::Log2Ceiling(kMaxReason);
225 while (reasons) { 225 while (reasons) {
226 DCHECK_LT(shift, max_enum); // Sanity check. 226 DCHECK_LT(shift, max_enum); // Sanity check.
227 if (reasons & 0x1) { 227 if (reasons & 0x1) {
228 UMA_HISTOGRAM_ENUMERATION("Media.UncacheableReason", shift, 228 UMA_HISTOGRAM_ENUMERATION("Media.UncacheableReason", shift,
229 max_enum); // PRESUBMIT_IGNORE_UMA_MAX 229 max_enum); // PRESUBMIT_IGNORE_UMA_MAX
230 } 230 }
231 231
232 reasons >>= 1; 232 reasons >>= 1;
233 ++shift; 233 ++shift;
234 } 234 }
235 235
236 // Expected content length can be |kPositionNotSpecified|, in that case 236 // Expected content length can be |kPositionNotSpecified|, in that case
237 // |content_length_| is not specified and this is a streaming response. 237 // |content_length_| is not specified and this is a streaming response.
238 int64 content_length = response.expectedContentLength(); 238 int64_t content_length = response.expectedContentLength();
239 239
240 // We make a strong assumption that when we reach here we have either 240 // We make a strong assumption that when we reach here we have either
241 // received a response from HTTP/HTTPS protocol or the request was 241 // received a response from HTTP/HTTPS protocol or the request was
242 // successful (in particular range request). So we only verify the partial 242 // successful (in particular range request). So we only verify the partial
243 // response for HTTP and HTTPS protocol. 243 // response for HTTP and HTTPS protocol.
244 if (destination_url_data->url().SchemeIsHTTPOrHTTPS()) { 244 if (destination_url_data->url().SchemeIsHTTPOrHTTPS()) {
245 bool partial_response = (response.httpStatusCode() == kHttpPartialContent); 245 bool partial_response = (response.httpStatusCode() == kHttpPartialContent);
246 bool ok_response = (response.httpStatusCode() == kHttpOK); 246 bool ok_response = (response.httpStatusCode() == kHttpOK);
247 247
248 // Check to see whether the server supports byte ranges. 248 // Check to see whether the server supports byte ranges.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // We don't need to continue loading after failure. 413 // We don't need to continue loading after failure.
414 // 414 //
415 // Keep it alive until we exit this method so that |error| remains valid. 415 // Keep it alive until we exit this method so that |error| remains valid.
416 scoped_ptr<ActiveLoader> active_loader = active_loader_.Pass(); 416 scoped_ptr<ActiveLoader> active_loader = active_loader_.Pass();
417 url_data_->Fail(); 417 url_data_->Fail();
418 } 418 }
419 } 419 }
420 420
421 bool ResourceMultiBufferDataProvider::ParseContentRange( 421 bool ResourceMultiBufferDataProvider::ParseContentRange(
422 const std::string& content_range_str, 422 const std::string& content_range_str,
423 int64* first_byte_position, 423 int64_t* first_byte_position,
424 int64* last_byte_position, 424 int64_t* last_byte_position,
425 int64* instance_size) { 425 int64_t* instance_size) {
426 const std::string kUpThroughBytesUnit = "bytes "; 426 const std::string kUpThroughBytesUnit = "bytes ";
427 if (content_range_str.find(kUpThroughBytesUnit) != 0) 427 if (content_range_str.find(kUpThroughBytesUnit) != 0)
428 return false; 428 return false;
429 std::string range_spec = 429 std::string range_spec =
430 content_range_str.substr(kUpThroughBytesUnit.length()); 430 content_range_str.substr(kUpThroughBytesUnit.length());
431 size_t dash_offset = range_spec.find("-"); 431 size_t dash_offset = range_spec.find("-");
432 size_t slash_offset = range_spec.find("/"); 432 size_t slash_offset = range_spec.find("/");
433 433
434 if (dash_offset == std::string::npos || slash_offset == std::string::npos || 434 if (dash_offset == std::string::npos || slash_offset == std::string::npos ||
435 slash_offset < dash_offset || slash_offset + 1 == range_spec.length()) { 435 slash_offset < dash_offset || slash_offset + 1 == range_spec.length()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 return ret; 470 return ret;
471 } 471 }
472 472
473 int64_t ResourceMultiBufferDataProvider::block_size() const { 473 int64_t ResourceMultiBufferDataProvider::block_size() const {
474 int64_t ret = 1; 474 int64_t ret = 1;
475 return ret << url_data_->multibuffer()->block_size_shift(); 475 return ret << url_data_->multibuffer()->block_size_shift();
476 } 476 }
477 477
478 bool ResourceMultiBufferDataProvider::VerifyPartialResponse( 478 bool ResourceMultiBufferDataProvider::VerifyPartialResponse(
479 const WebURLResponse& response) { 479 const WebURLResponse& response) {
480 int64 first_byte_position, last_byte_position, instance_size; 480 int64_t first_byte_position, last_byte_position, instance_size;
481 if (!ParseContentRange(response.httpHeaderField("Content-Range").utf8(), 481 if (!ParseContentRange(response.httpHeaderField("Content-Range").utf8(),
482 &first_byte_position, &last_byte_position, 482 &first_byte_position, &last_byte_position,
483 &instance_size)) { 483 &instance_size)) {
484 return false; 484 return false;
485 } 485 }
486 486
487 if (url_data_->length() == kPositionNotSpecified) { 487 if (url_data_->length() == kPositionNotSpecified) {
488 url_data_->set_length(instance_size); 488 url_data_->set_length(instance_size);
489 } 489 }
490 490
491 if (byte_pos() != first_byte_position) { 491 if (byte_pos() != first_byte_position) {
492 return false; 492 return false;
493 } 493 }
494 494
495 return true; 495 return true;
496 } 496 }
497 497
498 } // namespace media 498 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698