Skip to content

Commit

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

Review-Url: https://codereview.chromium.org/2117233002
Cr-Commit-Position: refs/heads/master@{#404289}
  • Loading branch information
leizleiz authored and Commit bot committed Jul 8, 2016
1 parent bb47aac commit ee1440b
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 108 deletions.
8 changes: 3 additions & 5 deletions components/autofill/content/renderer/autofill_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ void GetDataListSuggestions(const WebInputElement& element,
std::vector<base::string16> parts = base::SplitString(
prefix, base::ASCIIToUTF16(","), base::TRIM_WHITESPACE,
base::SPLIT_WANT_ALL);
if (!parts.empty()) {
base::TrimWhitespace(parts[parts.size() - 1], base::TRIM_LEADING,
&prefix);
}
if (!parts.empty())
base::TrimWhitespace(parts.back(), base::TRIM_LEADING, &prefix);
}

// Prefix filtering.
Expand Down Expand Up @@ -500,7 +498,7 @@ void AutofillAgent::AcceptDataListSuggestion(
}
}
last_part.append(suggested_value);
parts[parts.size() - 1] = last_part;
parts.back() = last_part;

new_value = base::JoinString(parts, base::ASCIIToUTF16(","));
}
Expand Down
5 changes: 1 addition & 4 deletions components/autofill/core/browser/form_structure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,7 @@ bool FormStructure::EncodeQueryRequest(
encoded_signatures->push_back(signature);
}

if (!encoded_signatures->size())
return false;

return true;
return !encoded_signatures->empty();
}

// static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool StartsWithActionPrefix(base::StringPiece header_value,
base::StringPiece action_prefix) {
DCHECK(!action_prefix.empty());
// A valid action does not include a trailing '='.
DCHECK(action_prefix[action_prefix.size() - 1] != kActionValueDelimiter);
DCHECK(action_prefix.back() != kActionValueDelimiter);

return header_value.size() > action_prefix.size() + 1 &&
header_value[action_prefix.size()] == kActionValueDelimiter &&
Expand Down
6 changes: 2 additions & 4 deletions components/display_compositor/gl_helper_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,8 @@ class GLHelperTest : public testing::Test {
}

// Check the output size matches the destination of the last stage
EXPECT_EQ(scaler_stages[scaler_stages.size() - 1].dst_size.width(),
dst_size.width());
EXPECT_EQ(scaler_stages[scaler_stages.size() - 1].dst_size.height(),
dst_size.height());
EXPECT_EQ(scaler_stages.back().dst_size.width(), dst_size.width());
EXPECT_EQ(scaler_stages.back().dst_size.height(), dst_size.height());

// Used to verify that up-scales are not attempted after some
// other scale.
Expand Down
2 changes: 1 addition & 1 deletion components/gcm_driver/crypto/gcm_encryption_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const base::FilePath::CharType kEncryptionDirectoryName[] =

std::string GCMEncryptionProvider::ToDecryptionResultDetailsString(
DecryptionResult result) {
switch(result) {
switch (result) {
case DECRYPTION_RESULT_UNENCRYPTED:
return "Message was not encrypted";
case DECRYPTION_RESULT_DECRYPTED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@ bool AndroidURLsSQLHandler::Insert(HistoryAndBookmarkRow* row) {

bool AndroidURLsSQLHandler::Delete(const TableIDRows& ids_set) {
std::vector<URLID> ids;
for (TableIDRows::const_iterator id = ids_set.begin();
id != ids_set.end(); ++id)
ids.push_back(id->url_id);

if (!ids.size())
return true;

return android_urls_db_->DeleteAndroidURLRows(ids);
for (const auto& id : ids_set)
ids.push_back(id.url_id);
return ids.empty() || android_urls_db_->DeleteAndroidURLRows(ids);
}

} // namespace history.
2 changes: 1 addition & 1 deletion components/history/core/browser/history_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data,
mv.redirects.push_back(mv.url);
} else {
mv.redirects = redirects;
if (mv.redirects[mv.redirects.size() - 1] != mv.url) {
if (mv.redirects.back() != mv.url) {
// The last url must be the target url.
mv.redirects.push_back(mv.url);
}
Expand Down
3 changes: 1 addition & 2 deletions components/history/core/browser/url_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,7 @@ void URLDatabase::GetMostRecentKeywordSearchTerms(
base::string16 lower_prefix = base::i18n::ToLower(prefix);
// This magic gives us a prefix search.
base::string16 next_prefix = lower_prefix;
next_prefix[next_prefix.size() - 1] =
next_prefix[next_prefix.size() - 1] + 1;
next_prefix.back() = next_prefix.back() + 1;
statement.BindInt64(0, keyword_id);
statement.BindString16(1, lower_prefix);
statement.BindString16(2, next_prefix);
Expand Down
2 changes: 1 addition & 1 deletion components/proximity_auth/remote_device_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void RemoteDeviceLoader::OnPSKDerived(
user_id_, unlock_key.friendly_device_name(), unlock_key.public_key(),
bluetooth_type, bluetooth_address, psk, std::string()));

if (!remaining_unlock_keys_.size())
if (remaining_unlock_keys_.empty())
callback_.Run(remote_devices_);
}

Expand Down
3 changes: 1 addition & 2 deletions components/safe_browsing_db/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,7 @@ void UrlToFullHashes(const GURL& url,
// We may have /foo as path-prefix in the whitelist which should
// also match with /foo/bar and /foo?bar. Hence, for every path
// that ends in '/' we also add the path without the slash.
if (include_whitelist_hashes && path.size() > 1 &&
path[path.size() - 1] == '/') {
if (include_whitelist_hashes && path.size() > 1 && path.back() == '/') {
full_hashes->push_back(SBFullHashForString(
host + path.substr(0, path.size() - 1)));
}
Expand Down
59 changes: 29 additions & 30 deletions components/sessions/core/tab_restore_service_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,21 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreMostRecentEntry(
LiveTabContext* context) {
if (entries_.empty())
return std::vector<LiveTab*>();

return RestoreEntryById(context, entries_.front()->id, UNKNOWN);
}

TabRestoreService::Tab* TabRestoreServiceHelper::RemoveTabEntryById(
SessionID::id_type id) {
Entries::iterator i = GetEntryIteratorById(id);
if (i == entries_.end())
return NULL;
Entries::iterator it = GetEntryIteratorById(id);
if (it == entries_.end())
return nullptr;

Entry* entry = *i;
Entry* entry = *it;
if (entry->type != TabRestoreService::TAB)
return NULL;
return nullptr;

Tab* tab = static_cast<Tab*>(entry);
entries_.erase(i);
entries_.erase(it);
return tab;
}

Expand All @@ -162,9 +161,10 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
SessionID::id_type id,
WindowOpenDisposition disposition) {
Entries::iterator entry_iterator = GetEntryIteratorById(id);
if (entry_iterator == entries_.end())
if (entry_iterator == entries_.end()) {
// Don't hoark here, we allow an invalid id.
return std::vector<LiveTab*>();
}

if (observer_)
observer_->OnRestoreEntryById(id, entry_iterator);
Expand All @@ -186,7 +186,7 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
std::vector<LiveTab*> live_tabs;
if (entry->type == TabRestoreService::TAB) {
Tab* tab = static_cast<Tab*>(entry);
LiveTab* restored_tab = NULL;
LiveTab* restored_tab = nullptr;
context = RestoreTab(*tab, context, disposition, &restored_tab);
live_tabs.push_back(restored_tab);
context->ShowBrowserWindow();
Expand Down Expand Up @@ -225,28 +225,27 @@ std::vector<LiveTab*> TabRestoreServiceHelper::RestoreEntryById(
for (std::vector<Tab>::iterator tab_i = window->tabs.begin();
tab_i != window->tabs.end(); ++tab_i) {
const Tab& tab = *tab_i;
if (tab.id == id) {
LiveTab* restored_tab = NULL;
context = RestoreTab(tab, context, disposition, &restored_tab);
live_tabs.push_back(restored_tab);
window->tabs.erase(tab_i);
// If restoring the tab leaves the window with nothing else, delete it
// as well.
if (!window->tabs.size()) {
entries_.erase(entry_iterator);
delete entry;
} else {
// Update the browser ID of the rest of the tabs in the window so if
// any one is restored, it goes into the same window as the tab
// being restored now.
UpdateTabBrowserIDs(tab.browser_id, context->GetSessionID().id());
for (std::vector<Tab>::iterator tab_j = window->tabs.begin();
tab_j != window->tabs.end(); ++tab_j) {
(*tab_j).browser_id = context->GetSessionID().id();
}
}
break;
if (tab.id != id)
continue;

LiveTab* restored_tab = nullptr;
context = RestoreTab(tab, context, disposition, &restored_tab);
live_tabs.push_back(restored_tab);
window->tabs.erase(tab_i);
// If restoring the tab leaves the window with nothing else, delete it
// as well.
if (window->tabs.empty()) {
entries_.erase(entry_iterator);
delete entry;
} else {
// Update the browser ID of the rest of the tabs in the window so if
// any one is restored, it goes into the same window as the tab
// being restored now.
UpdateTabBrowserIDs(tab.browser_id, context->GetSessionID().id());
for (Tab& tab_j : window->tabs)
tab_j.browser_id = context->GetSessionID().id();
}
break;
}
}
context->ShowBrowserWindow();
Expand Down
58 changes: 26 additions & 32 deletions components/sync_sessions/synced_session_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,39 +215,36 @@ void SyncedSessionTracker::DeleteForeignTab(const std::string& session_tag,

bool SyncedSessionTracker::DeleteOldSessionWindowIfNecessary(
const SessionWindowWrapper& window_wrapper) {
if (!window_wrapper.owned) {
DVLOG(1) << "Deleting closed window "
<< window_wrapper.window_ptr->window_id.id();
// Clear the tabs first, since we don't want the destructor to destroy
// them. Their deletion will be handled by DeleteOldSessionTabIfNecessary.
window_wrapper.window_ptr->tabs.clear();
delete window_wrapper.window_ptr;
return true;
}
return false;
if (window_wrapper.owned)
return false;

DVLOG(1) << "Deleting closed window "
<< window_wrapper.window_ptr->window_id.id();
// Clear the tabs first, since we don't want the destructor to destroy
// them. Their deletion will be handled by DeleteOldSessionTabIfNecessary.
window_wrapper.window_ptr->tabs.clear();
delete window_wrapper.window_ptr;
return true;
}

bool SyncedSessionTracker::DeleteOldSessionTabIfNecessary(
const SessionTabWrapper& tab_wrapper) {
if (!tab_wrapper.owned) {
if (VLOG_IS_ON(1)) {
sessions::SessionTab* tab_ptr = tab_wrapper.tab_ptr;
std::string title;
if (tab_ptr->navigations.size() > 0) {
title =
" (" +
base::UTF16ToUTF8(
tab_ptr->navigations[tab_ptr->navigations.size() - 1].title()) +
")";
}
DVLOG(1) << "Deleting closed tab " << tab_ptr->tab_id.id() << title
<< " from window " << tab_ptr->window_id.id();
if (tab_wrapper.owned)
return false;

if (VLOG_IS_ON(1)) {
sessions::SessionTab* tab_ptr = tab_wrapper.tab_ptr;
std::string title;
if (!tab_ptr->navigations.empty()) {
title =
" (" + base::UTF16ToUTF8(tab_ptr->navigations.back().title()) + ")";
}
unmapped_tabs_.erase(tab_wrapper.tab_ptr);
delete tab_wrapper.tab_ptr;
return true;
DVLOG(1) << "Deleting closed tab " << tab_ptr->tab_id.id() << title
<< " from window " << tab_ptr->window_id.id();
}
return false;
unmapped_tabs_.erase(tab_wrapper.tab_ptr);
delete tab_wrapper.tab_ptr;
return true;
}

void SyncedSessionTracker::CleanupSession(const std::string& session_tag) {
Expand Down Expand Up @@ -400,15 +397,12 @@ sessions::SessionTab* SyncedSessionTracker::GetTabImpl(
std::string title;
if (tab_ptr->navigations.size() > 0) {
title =
" (" +
base::UTF16ToUTF8(
tab_ptr->navigations[tab_ptr->navigations.size() - 1].title()) +
")";
" (" + base::UTF16ToUTF8(tab_ptr->navigations.back().title()) + ")";
}
DVLOG(1) << "Getting "
<< (session_tag == local_session_tag_ ? "local session"
: session_tag)
<< "'s seen tab " << tab_id << " at " << tab_ptr << title;
<< "'s seen tab " << tab_id << " at " << tab_ptr << " " << title;
}
} else {
tab_ptr = new sessions::SessionTab();
Expand Down
26 changes: 11 additions & 15 deletions components/url_matcher/url_matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,30 +513,26 @@ URLMatcherCondition URLMatcherConditionFactory::CreateCondition(
PatternSingletons::const_iterator iter =
pattern_singletons->find(&search_pattern);

if (iter != pattern_singletons->end()) {
if (iter != pattern_singletons->end())
return URLMatcherCondition(criterion, *iter);
} else {
StringPattern* new_pattern =
new StringPattern(pattern, id_counter_++);
pattern_singletons->insert(new_pattern);
return URLMatcherCondition(criterion, new_pattern);
}

StringPattern* new_pattern = new StringPattern(pattern, id_counter_++);
pattern_singletons->insert(new_pattern);
return URLMatcherCondition(criterion, new_pattern);
}

std::string URLMatcherConditionFactory::CanonicalizeHostSuffix(
const std::string& suffix) const {
if (!suffix.empty() && suffix[suffix.size() - 1] == '.')
return suffix;
else
return suffix + ".";
if (suffix.empty())
return ".";
return suffix.back() == '.' ? suffix : suffix + ".";
}

std::string URLMatcherConditionFactory::CanonicalizeHostPrefix(
const std::string& prefix) const {
if (!prefix.empty() && prefix[0] == '.')
return prefix;
else
return "." + prefix;
if (prefix.empty())
return ".";
return prefix[0] == '.' ? prefix : "." + prefix;
}

std::string URLMatcherConditionFactory::CanonicalizeHostname(
Expand Down
2 changes: 1 addition & 1 deletion components/webcrypto/algorithms/ecdh_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ TEST_F(WebCryptoEcdhTest, DeriveKeyHmac19Bits) {
ExportKey(blink::WebCryptoKeyFormatRaw, derived_key, &raw_key));
EXPECT_EQ(3u, raw_key.size());
// The last 7 bits of the key should be zero.
EXPECT_EQ(0, raw_key[raw_key.size() - 1] & 0x1f);
EXPECT_EQ(0, raw_key.back() & 0x1f);
}

// Derive an HMAC key with no specified length (just the hash of SHA-256).
Expand Down
2 changes: 1 addition & 1 deletion components/webcrypto/algorithms/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void TruncateToBitLength(size_t length_bits, std::vector<uint8_t>* bytes) {

// Zero any "unused bits" in the final byte.
if (remainder_bits)
(*bytes)[bytes->size() - 1] &= ~((0xFF) >> remainder_bits);
bytes->back() &= ~((0xFF) >> remainder_bits);
}

Status CheckKeyCreationUsages(blink::WebCryptoKeyUsageMask all_possible_usages,
Expand Down

0 comments on commit ee1440b

Please sign in to comment.