Skip to content

Commit

Permalink
Use container::back() and container::pop_back() in media, net, ppapi.
Browse files Browse the repository at this point in the history
Also convert !container.size() to container.empty().

Review-Url: https://codereview.chromium.org/2119293002
Cr-Commit-Position: refs/heads/master@{#404728}
  • Loading branch information
leizleiz authored and Commit bot committed Jul 11, 2016
1 parent 0fbe211 commit a74ad2b
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 76 deletions.
2 changes: 1 addition & 1 deletion media/base/android/media_codec_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bool MediaCodecUtil::IsKnownUnaccelerated(const std::string& android_mime_type,
GetDefaultCodecName(android_mime_type, direction, false);
DVLOG(1) << __FUNCTION__ << "Default codec for " << android_mime_type << " : "
<< codec_name << ", direction: " << direction;
if (!codec_name.size())
if (codec_name.empty())
return true;

// MediaTek hardware vp8 is known slower than the software implementation.
Expand Down
2 changes: 1 addition & 1 deletion media/base/audio_renderer_mixer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class AudioRendererMixerTest

// Stop the last input in case the number of inputs is odd
if (mixer_inputs_.size() % 2)
mixer_inputs_[mixer_inputs_.size() - 1]->Stop();
mixer_inputs_.back()->Stop();

ASSERT_TRUE(RenderAndValidateAudioData(
std::max(1.f, static_cast<float>(floor(mixer_inputs_.size() / 2.f)))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@

VideoCaptureDevice::Names names;
video_capture_device_factory.GetDeviceNames(&names);
if (!names.size()) {
if (names.empty()) {
DVLOG(1) << "No camera available. Exiting test.";
return;
}
std::string device_vid;
for (VideoCaptureDevice::Names::const_iterator it = names.begin();
it != names.end(); ++it) {
EXPECT_EQ(it->capture_api_type(), VideoCaptureDevice::Name::AVFOUNDATION);
}
for (const auto& name : names)
EXPECT_EQ(VideoCaptureDevice::Name::AVFOUNDATION, name.capture_api_type());
}

}; // namespace media
20 changes: 9 additions & 11 deletions media/filters/media_source_state.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -28,7 +28,7 @@ static TimeDelta EndTimestamp(const StreamParser::BufferQueue& queue) {
// List of time ranges for each SourceBuffer.
// static
Ranges<TimeDelta> MediaSourceState::ComputeRangesIntersection(
const RangesList& activeRanges,
const RangesList& active_ranges,
bool ended) {
// TODO(servolk): Perhaps this can be removed in favor of blink implementation
// (MediaSource::buffered)? Currently this is only used on Android and for
Expand All @@ -39,20 +39,19 @@ Ranges<TimeDelta> MediaSourceState::ComputeRangesIntersection(

// Step 1: If activeSourceBuffers.length equals 0 then return an empty
// TimeRanges object and abort these steps.
if (activeRanges.empty())
if (active_ranges.empty())
return Ranges<TimeDelta>();

// Step 2: Let active ranges be the ranges returned by buffered for each
// SourceBuffer object in activeSourceBuffers.
// Step 3: Let highest end time be the largest range end time in the active
// ranges.
TimeDelta highest_end_time;
for (RangesList::const_iterator itr = activeRanges.begin();
itr != activeRanges.end(); ++itr) {
if (!itr->size())
for (const auto& range : active_ranges) {
if (!range.size())
continue;

highest_end_time = std::max(highest_end_time, itr->end(itr->size() - 1));
highest_end_time = std::max(highest_end_time, range.end(range.size() - 1));
}

// Step 4: Let intersection ranges equal a TimeRange object containing a
Expand All @@ -62,15 +61,14 @@ Ranges<TimeDelta> MediaSourceState::ComputeRangesIntersection(

// Step 5: For each SourceBuffer object in activeSourceBuffers run the
// following steps:
for (RangesList::const_iterator itr = activeRanges.begin();
itr != activeRanges.end(); ++itr) {
for (const auto& range : active_ranges) {
// Step 5.1: Let source ranges equal the ranges returned by the buffered
// attribute on the current SourceBuffer.
Ranges<TimeDelta> source_ranges = *itr;
Ranges<TimeDelta> source_ranges = range;

// Step 5.2: If readyState is "ended", then set the end time on the last
// range in source ranges to highest end time.
if (ended && source_ranges.size() > 0u) {
if (ended && source_ranges.size()) {
source_ranges.Add(source_ranges.start(source_ranges.size() - 1),
highest_end_time);
}
Expand Down
4 changes: 2 additions & 2 deletions media/filters/media_source_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class MEDIA_EXPORT MediaSourceState {
void SetMemoryLimits(DemuxerStream::Type type, size_t memory_limit);
bool IsSeekWaitingForData() const;

typedef std::list<Ranges<TimeDelta>> RangesList;
using RangesList = std::vector<Ranges<TimeDelta>>;
static Ranges<TimeDelta> ComputeRangesIntersection(
const RangesList& activeRanges,
const RangesList& active_ranges,
bool ended);

void SetTracksWatcher(const Demuxer::MediaTracksUpdatedCB& tracks_updated_cb);
Expand Down
5 changes: 2 additions & 3 deletions media/gpu/dxva_video_decode_accelerator_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static const DWORD g_IntelLegacyGPUList[] = {
// instance.
class MediaBufferScopedPointer {
public:
MediaBufferScopedPointer(IMFMediaBuffer* media_buffer)
explicit MediaBufferScopedPointer(IMFMediaBuffer* media_buffer)
: media_buffer_(media_buffer),
buffer_(nullptr),
max_length_(0),
Expand Down Expand Up @@ -1779,7 +1779,7 @@ void DXVAVideoDecodeAccelerator::ProcessPendingSamples() {
TRACE_EVENT0("media", "DXVAVideoDecodeAccelerator::ProcessPendingSamples");
DCHECK(main_thread_task_runner_->BelongsToCurrentThread());

if (!output_picture_buffers_.size())
if (output_picture_buffers_.empty())
return;

RETURN_AND_NOTIFY_ON_FAILURE(make_context_current_cb_.Run(),
Expand Down Expand Up @@ -1859,7 +1859,6 @@ void DXVAVideoDecodeAccelerator::ProcessPendingSamples() {
this, surface.get(), d3d11_texture.get(),
pending_sample->input_buffer_id),
"Failed to copy output sample", PLATFORM_FAILURE, );

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion net/base/ip_pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool IPPattern::ParsePattern(const std::string& ip_pattern) {
component_values_.push_back(value);
continue;
}
if (component[component.size() - 1] != ']') {
if (component.back() != ']') {
DVLOG(1) << "Missing close bracket: " << ip_pattern;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion net/cookies/cookie_monster_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
base::SPLIT_WANT_ALL)) {
DCHECK(!token.empty());

bool is_secure = token[token.size() - 1] == 'S';
bool is_secure = token.back() == 'S';

// The second-to-last character is the priority. Grab and discard it.
CookiePriority priority = CharToPriority(token[token.size() - 2]);
Expand Down
10 changes: 4 additions & 6 deletions net/disk_cache/blockfile/backend_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1421,9 +1421,7 @@ void BackendImpl::AdjustMaxCacheSize(int table_len) {
return;

// If we already have a table, adjust the size to it.
int current_max_size = MaxStorageSizeForTable(table_len);
if (max_size_ > current_max_size)
max_size_= current_max_size;
max_size_ = std::min(max_size_, MaxStorageSizeForTable(table_len));
}

bool BackendImpl::InitStats() {
Expand Down Expand Up @@ -1493,17 +1491,17 @@ void BackendImpl::RestartCache(bool failure) {
PrepareForRestart();
if (failure) {
DCHECK(!num_refs_);
DCHECK(!open_entries_.size());
DCHECK(open_entries_.empty());
DelayedCacheCleanup(path_);
} else {
DeleteCache(path_, false);
}

// Don't call Init() if directed by the unit test: we are simulating a failure
// trying to re-enable the cache.
if (unit_test_)
if (unit_test_) {
init_ = true; // Let the destructor do proper cleanup.
else if (SyncInit() == net::OK) {
} else if (SyncInit() == net::OK) {
stats_.SetCounter(Stats::FATAL_ERROR, errors);
stats_.SetCounter(Stats::DOOM_CACHE, full_dooms);
stats_.SetCounter(Stats::DOOM_RECENT, partial_dooms);
Expand Down
4 changes: 2 additions & 2 deletions net/dns/dns_transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ std::unique_ptr<base::Value> NetLogStartCallback(
dict->SetString("hostname", *hostname);
dict->SetInteger("query_type", qtype);
return std::move(dict);
};
}

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -634,7 +634,7 @@ class DnsTransactionImpl : public DnsTransaction,
if (!DNSDomainFromDot(hostname_, &labeled_hostname))
return ERR_INVALID_ARGUMENT;

if (hostname_[hostname_.size() - 1] == '.') {
if (hostname_.back() == '.') {
// It's a fully-qualified name, no suffix search.
qnames_.push_back(labeled_hostname);
return OK;
Expand Down
19 changes: 8 additions & 11 deletions net/dns/host_resolver_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

#include "net/dns/host_resolver_impl.h"

#include <memory>
#include <utility>

#include "base/memory/ptr_util.h"

#if defined(OS_WIN)
#include <Winsock2.h>
#elif defined(OS_POSIX)
#include <netdb.h>
#endif

#include <cmath>
#include <memory>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -195,7 +191,7 @@ bool ResemblesMulticastDNSName(const std::string& hostname) {
const char kSuffix[] = ".local.";
const size_t kSuffixLen = sizeof(kSuffix) - 1;
const size_t kSuffixLenTrimmed = kSuffixLen - 1;
if (hostname[hostname.size() - 1] == '.') {
if (hostname.back() == '.') {
return hostname.size() > kSuffixLen &&
!hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix);
}
Expand Down Expand Up @@ -367,7 +363,7 @@ std::unique_ptr<base::Value> NetLogDnsTaskFailedCallback(
if (dns_error)
dict->SetInteger("dns_error", dns_error);
return std::move(dict);
};
}

// Creates NetLog parameters containing the information in a RequestInfo object,
// along with the associated NetLog::Source.
Expand Down Expand Up @@ -480,7 +476,8 @@ class PriorityTracker {
--total_count_;
--counts_[req_priority];
size_t i;
for (i = highest_priority_; i > MINIMUM_PRIORITY && !counts_[i]; --i);
for (i = highest_priority_; i > MINIMUM_PRIORITY && !counts_[i]; --i) {
}
highest_priority_ = static_cast<RequestPriority>(i);

// In absence of requests, default to MINIMUM_PRIORITY.
Expand Down Expand Up @@ -859,7 +856,7 @@ class HostResolverImpl::ProcTask

// Log DNS lookups based on |address_family|. This will help us determine
// if IPv4 or IPv4/6 lookups are faster or slower.
switch(key_.address_family) {
switch (key_.address_family) {
case ADDRESS_FAMILY_IPV4:
DNS_HISTOGRAM("DNS.ResolveSuccess_FAMILY_IPV4", duration);
break;
Expand All @@ -880,7 +877,7 @@ class HostResolverImpl::ProcTask
}
// Log DNS lookups based on |address_family|. This will help us determine
// if IPv4 or IPv4/6 lookups are faster or slower.
switch(key_.address_family) {
switch (key_.address_family) {
case ADDRESS_FAMILY_IPV4:
DNS_HISTOGRAM("DNS.ResolveFail_FAMILY_IPV4", duration);
break;
Expand Down Expand Up @@ -1686,7 +1683,7 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
}
DNS_HISTOGRAM("AsyncDNS.ResolveSuccess", duration);
// Log DNS lookups based on |address_family|.
switch(key_.address_family) {
switch (key_.address_family) {
case ADDRESS_FAMILY_IPV4:
DNS_HISTOGRAM("AsyncDNS.ResolveSuccess_FAMILY_IPV4", duration);
break;
Expand Down
6 changes: 3 additions & 3 deletions net/ftp/ftp_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ std::string FtpUtil::UnixFilePathToVMS(const std::string& unix_path) {
for (size_t i = 2; i < tokens.size() - 1; i++)
result.append("." + tokens[i]);
}
result.append("]" + tokens[tokens.size() - 1]);
result.append("]" + tokens.back());
return result;
}

Expand All @@ -71,7 +71,7 @@ std::string FtpUtil::UnixFilePathToVMS(const std::string& unix_path) {
std::string result("[");
for (size_t i = 0; i < tokens.size() - 1; i++)
result.append("." + tokens[i]);
result.append("]" + tokens[tokens.size() - 1]);
result.append("]" + tokens.back());
return result;
}

Expand Down Expand Up @@ -373,4 +373,4 @@ base::string16 FtpUtil::GetStringPartAfterColumns(const base::string16& text,
return result;
}

} // namespace
} // namespace net
2 changes: 1 addition & 1 deletion net/http/http_network_transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ bool HttpNetworkTransaction::GetLoadTimingInfo(
}

bool HttpNetworkTransaction::GetRemoteEndpoint(IPEndPoint* endpoint) const {
if (!remote_endpoint_.address().size())
if (remote_endpoint_.address().empty())
return false;

*endpoint = remote_endpoint_;
Expand Down
2 changes: 1 addition & 1 deletion net/quic/crypto/proof_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ TEST_P(ProofTest, VerifyECDSAKnownAnswerTest) {
// An ECDSA signature is DER-encoded. Corrupt the last byte so that the
// signature can still be DER-decoded correctly.
string corrupt_signature = signature;
corrupt_signature[corrupt_signature.size() - 1] += 1;
corrupt_signature.back()++;
RunVerification(verifier.get(), hostname, port, server_config, quic_version,
chlo_hash, certs, corrupt_signature, false);

Expand Down
22 changes: 12 additions & 10 deletions net/tools/flip_server/flip_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ FlipAcceptor::FlipAcceptor(enum FlipHandlerType flip_handler_type,
idle_socket_timeout_s_(300) {
VLOG(1) << "Attempting to listen on " << listen_ip_.c_str() << ":"
<< listen_port_.c_str();
if (!https_server_ip_.size())
if (https_server_ip_.empty())
https_server_ip_ = http_server_ip_;
if (!https_server_port_.size())
if (https_server_port_.empty())
https_server_port_ = http_server_port_;

while (1) {
Expand All @@ -61,17 +61,19 @@ FlipAcceptor::FlipAcceptor(enum FlipHandlerType flip_handler_type,
wait_for_iface,
disable_nagle_,
&listen_fd_);
if (ret == 0) {
if (ret == 0)
break;
} else if (ret == -3 && wait_for_iface) {
// Binding error EADDRNOTAVAIL was encounted. We need
// to wait for the interfaces to raised. try again.

if (ret == -3 && !wait_for_iface) {
// -3 means binding error EADDRNOTAVAIL was encountered. We need to wait
// for the interfaces to come up and then try again.
usleep(200000);
} else {
LOG(ERROR) << "Unable to create listening socket for: ret = " << ret
<< ": " << listen_ip_.c_str() << ":" << listen_port_.c_str();
return;
continue;
}

LOG(ERROR) << "Unable to create listening socket for: ret = " << ret << ": "
<< listen_ip_.c_str() << ":" << listen_port_.c_str();
return;
}

if (!base::SetNonBlocking(listen_fd_)) {
Expand Down
4 changes: 2 additions & 2 deletions ppapi/proxy/serialized_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ ReceiveSerializedVarVectorOutParam::ReceiveSerializedVarVectorOutParam(

ReceiveSerializedVarVectorOutParam::~ReceiveSerializedVarVectorOutParam() {
*output_count_ = static_cast<uint32_t>(vector_.size());
if (!vector_.size()) {
*output_ = NULL;
if (vector_.empty()) {
*output_ = nullptr;
return;
}

Expand Down
10 changes: 4 additions & 6 deletions ppapi/tests/test_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ std::string TestView::TestPageHideShow() {

// Wait until we get a hide event, being careful to handle spurious
// notifications of ViewChanged.
while (WaitUntilViewChanged() &&
page_visibility_log_[page_visibility_log_.size() - 1]) {
while (WaitUntilViewChanged() && page_visibility_log_.back()) {
}
if (page_visibility_log_[page_visibility_log_.size() - 1]) {
if (page_visibility_log_.back()) {
// Didn't get a view changed event that changed visibility (though there
// may have been some that didn't change visibility).
// Add more error message since this test has some extra requirements.
Expand All @@ -108,10 +107,9 @@ std::string TestView::TestPageHideShow() {
instance_->ReportProgress("TestPageHideShow:Hidden");

// Wait until we get a show event.
while (WaitUntilViewChanged() &&
!page_visibility_log_[page_visibility_log_.size() - 1]) {
while (WaitUntilViewChanged() && !page_visibility_log_.back()) {
}
ASSERT_TRUE(page_visibility_log_[page_visibility_log_.size() - 1]);
ASSERT_TRUE(page_visibility_log_.back());

PASS();
}
Expand Down
Loading

0 comments on commit a74ad2b

Please sign in to comment.