Commit 350211de authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

Use ContainsValue() instead of std::find() at components/payments

replace std::find() with base::containsValue()
at components/payments

Bug: 561800
Change-Id: Id11c844383e792b608eaa2e0bec6a389821e927c
Reviewed-on: https://chromium-review.googlesource.com/1102283Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Commit-Queue: Hwanseung Lee <hs1217.lee@samsung.com>
Cr-Commit-Position: refs/heads/master@{#567860}
parent 8536944f
......@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "components/payments/content/payment_manifest_web_data_service.h"
#include "components/payments/content/utility/payment_manifest_parser.h"
......@@ -40,10 +41,8 @@ void EnableMethodManifestUrlForSupportedApps(
for (auto& app : *apps) {
if (app_origin.IsSameOriginWith(
url::Origin::Create(app.second->scope.GetOrigin()))) {
app.second->has_explicitly_verified_methods =
std::find(supported_origin_strings.begin(),
supported_origin_strings.end(),
app_origin.Serialize()) != supported_origin_strings.end();
app.second->has_explicitly_verified_methods = base::ContainsValue(
supported_origin_strings, app_origin.Serialize());
if (all_origins_supported ||
app.second->has_explicitly_verified_methods) {
app.second->enabled_methods.emplace_back(method_manifest_url.spec());
......
......@@ -8,6 +8,7 @@
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/stl_util.h"
#include "components/webdata/common/web_database.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -70,12 +71,8 @@ TEST_F(PaymentMethodManifestTableTest, AddAndGetSingleManifest) {
retrieved_web_app_ids =
payment_method_manifest_table->GetManifest("https://bobpay.com");
ASSERT_EQ(web_app_ids.size(), retrieved_web_app_ids.size());
ASSERT_TRUE(std::find(retrieved_web_app_ids.begin(),
retrieved_web_app_ids.end(),
web_app_ids[0]) != retrieved_web_app_ids.end());
ASSERT_TRUE(std::find(retrieved_web_app_ids.begin(),
retrieved_web_app_ids.end(),
web_app_ids[1]) != retrieved_web_app_ids.end());
ASSERT_TRUE(base::ContainsValue(retrieved_web_app_ids, web_app_ids[0]));
ASSERT_TRUE(base::ContainsValue(retrieved_web_app_ids, web_app_ids[1]));
}
TEST_F(PaymentMethodManifestTableTest, AddAndGetMultipleManifest) {
......@@ -109,20 +106,14 @@ TEST_F(PaymentMethodManifestTableTest, AddAndGetMultipleManifest) {
bobpay_web_app_ids =
payment_method_manifest_table->GetManifest(method_name_1);
ASSERT_EQ(web_app_ids.size(), bobpay_web_app_ids.size());
ASSERT_TRUE(std::find(bobpay_web_app_ids.begin(), bobpay_web_app_ids.end(),
web_app_ids[0]) != bobpay_web_app_ids.end());
ASSERT_TRUE(std::find(bobpay_web_app_ids.begin(), bobpay_web_app_ids.end(),
web_app_ids[1]) != bobpay_web_app_ids.end());
ASSERT_TRUE(base::ContainsValue(bobpay_web_app_ids, web_app_ids[0]));
ASSERT_TRUE(base::ContainsValue(bobpay_web_app_ids, web_app_ids[1]));
alicepay_web_app_ids =
payment_method_manifest_table->GetManifest(method_name_1);
ASSERT_EQ(web_app_ids.size(), alicepay_web_app_ids.size());
ASSERT_TRUE(std::find(alicepay_web_app_ids.begin(),
alicepay_web_app_ids.end(),
web_app_ids[0]) != alicepay_web_app_ids.end());
ASSERT_TRUE(std::find(alicepay_web_app_ids.begin(),
alicepay_web_app_ids.end(),
web_app_ids[1]) != alicepay_web_app_ids.end());
ASSERT_TRUE(base::ContainsValue(alicepay_web_app_ids, web_app_ids[0]));
ASSERT_TRUE(base::ContainsValue(alicepay_web_app_ids, web_app_ids[1]));
}
} // namespace
......
......@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "base/stl_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/payments/content/installable_payment_app_crawler.h"
#include "components/payments/content/manifest_verifier.h"
......@@ -65,9 +66,7 @@ bool AppSupportsAtLeastOneRequestedMethodData(
const std::vector<mojom::PaymentMethodDataPtr>& requests) {
for (const auto& enabled_method : app.enabled_methods) {
for (const auto& request : requests) {
auto it = std::find(request->supported_methods.begin(),
request->supported_methods.end(), enabled_method);
if (it != request->supported_methods.end()) {
if (base::ContainsValue(request->supported_methods, enabled_method)) {
if (enabled_method != "basic-card" ||
BasicCardCapabilitiesMatch(app.capabilities, request)) {
return true;
......
......@@ -346,8 +346,7 @@ bool ServiceWorkerPaymentInstrument::IsValidForModifier(
// Payment app that needs installation only supports url based payment
// methods.
if (needs_installation_) {
return std::find(methods.begin(), methods.end(),
installable_enabled_method_) != methods.end();
return base::ContainsValue(methods, installable_enabled_method_);
}
std::vector<std::string> matched_methods;
......
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/json/json_writer.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "components/autofill/core/browser/autofill_country.h"
......@@ -126,7 +127,7 @@ bool AutofillPaymentInstrument::IsValidForModifier(
bool supported_types_specified,
const std::set<autofill::CreditCard::CardType>& supported_types) const {
// This instrument only matches basic-card.
if (std::find(methods.begin(), methods.end(), "basic-card") == methods.end())
if (!base::ContainsValue(methods, "basic-card"))
return false;
// If supported_types is not specified and this instrument matches the method,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment