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

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

Issue 2121513002: Replace string::find(prefix) == 0 pattern with base::StartsWith(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typos Created 4 years, 5 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bits.h" 11 #include "base/bits.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "media/blink/active_loader.h" 19 #include "media/blink/active_loader.h"
19 #include "media/blink/cache_util.h" 20 #include "media/blink/cache_util.h"
20 #include "media/blink/media_blink_export.h" 21 #include "media/blink/media_blink_export.h"
21 #include "media/blink/url_index.h" 22 #include "media/blink/url_index.h"
22 #include "net/http/http_byte_range.h" 23 #include "net/http/http_byte_range.h"
23 #include "net/http/http_request_headers.h" 24 #include "net/http/http_request_headers.h"
24 #include "third_party/WebKit/public/platform/WebURLError.h" 25 #include "third_party/WebKit/public/platform/WebURLError.h"
25 #include "third_party/WebKit/public/platform/WebURLResponse.h" 26 #include "third_party/WebKit/public/platform/WebURLResponse.h"
26 27
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 // Note that calling Fail() will most likely delete this object. 455 // Note that calling Fail() will most likely delete this object.
455 url_data_->Fail(); 456 url_data_->Fail();
456 } 457 }
457 } 458 }
458 459
459 bool ResourceMultiBufferDataProvider::ParseContentRange( 460 bool ResourceMultiBufferDataProvider::ParseContentRange(
460 const std::string& content_range_str, 461 const std::string& content_range_str,
461 int64_t* first_byte_position, 462 int64_t* first_byte_position,
462 int64_t* last_byte_position, 463 int64_t* last_byte_position,
463 int64_t* instance_size) { 464 int64_t* instance_size) {
464 const std::string kUpThroughBytesUnit = "bytes "; 465 const char kUpThroughBytesUnit[] = "bytes ";
Lei Zhang 2016/07/07 22:33:49 Thanks
lazyboy 2016/07/07 23:44:50 Acknowledged.
465 if (content_range_str.find(kUpThroughBytesUnit) != 0) 466 if (!base::StartsWith(content_range_str, kUpThroughBytesUnit,
467 base::CompareCase::SENSITIVE)) {
466 return false; 468 return false;
469 }
467 std::string range_spec = 470 std::string range_spec =
468 content_range_str.substr(kUpThroughBytesUnit.length()); 471 content_range_str.substr(sizeof(kUpThroughBytesUnit) - 1);
469 size_t dash_offset = range_spec.find("-"); 472 size_t dash_offset = range_spec.find("-");
470 size_t slash_offset = range_spec.find("/"); 473 size_t slash_offset = range_spec.find("/");
471 474
472 if (dash_offset == std::string::npos || slash_offset == std::string::npos || 475 if (dash_offset == std::string::npos || slash_offset == std::string::npos ||
473 slash_offset < dash_offset || slash_offset + 1 == range_spec.length()) { 476 slash_offset < dash_offset || slash_offset + 1 == range_spec.length()) {
474 return false; 477 return false;
475 } 478 }
476 if (!base::StringToInt64(range_spec.substr(0, dash_offset), 479 if (!base::StringToInt64(range_spec.substr(0, dash_offset),
477 first_byte_position) || 480 first_byte_position) ||
478 !base::StringToInt64( 481 !base::StringToInt64(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 } 531 }
529 532
530 if (byte_pos() != first_byte_position) { 533 if (byte_pos() != first_byte_position) {
531 return false; 534 return false;
532 } 535 }
533 536
534 return true; 537 return true;
535 } 538 }
536 539
537 } // namespace media 540 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698