Commit 8680d31c authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

Extensions: Clean up some < operator definitions to use std::tie.

Bug: None
Change-Id: I36623aa2bbb0a3fd1aeebbf3a9f44f94fc7164b5
Reviewed-on: https://chromium-review.googlesource.com/c/1460193
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630473}
parent 40ebd8b0
......@@ -4,6 +4,7 @@
#include "chrome/common/extensions/permissions/chrome_permission_message_provider.h"
#include <tuple>
#include <vector>
#include "base/metrics/field_trial.h"
......@@ -27,11 +28,8 @@ class ComparablePermission {
explicit ComparablePermission(const PermissionMessage& msg) : msg_(&msg) {}
bool operator<(const ComparablePermission& rhs) const {
if (msg_->message() < rhs.msg_->message())
return true;
if (msg_->message() > rhs.msg_->message())
return false;
return msg_->submessages() < rhs.msg_->submessages();
return std::tie(msg_->message(), msg_->submessages()) <
std::tie(rhs.msg_->message(), rhs.msg_->submessages());
}
bool operator==(const ComparablePermission& rhs) const {
......
......@@ -459,11 +459,10 @@ operator=(ExtensionRulesetData&& other) = default;
bool RulesetManager::ExtensionRulesetData::operator<(
const ExtensionRulesetData& other) const {
// Sort based on descending installation time, using extension id to break
// Sort based on *descending* installation time, using extension id to break
// ties.
return (extension_install_time != other.extension_install_time)
? (extension_install_time > other.extension_install_time)
: (extension_id < other.extension_id);
return std::tie(extension_install_time, extension_id) >
std::tie(other.extension_install_time, other.extension_id);
}
bool RulesetManager::ShouldEvaluateRequest(
......
......@@ -6,6 +6,8 @@
#include <stddef.h>
#include <tuple>
#include "base/files/file_path.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
......@@ -126,6 +128,11 @@ Warning Warning::CreateRulesetFailedToLoadWarning(
{} /*message_parameters*/);
}
bool Warning::operator<(const Warning& other) const {
return std::tie(extension_id_, type_) <
std::tie(other.extension_id_, other.type_);
}
std::string Warning::GetLocalizedMessage(const ExtensionSet* extensions) const {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......@@ -166,10 +173,4 @@ std::string Warning::GetLocalizedMessage(const ExtensionSet* extensions) const {
}
}
bool operator<(const Warning& a, const Warning& b) {
if (a.extension_id() != b.extension_id())
return a.extension_id() < b.extension_id();
return a.warning_type() < b.warning_type();
}
} // namespace extensions
......@@ -63,6 +63,11 @@ class Warning {
static Warning CreateRulesetFailedToLoadWarning(
const ExtensionId& extension_id);
// Compare Warnings based on the tuple of (extension_id, type).
// The message associated with Warnings is purely informational
// and does not contribute to distinguishing extensions.
bool operator<(const Warning& other) const;
// Returns the specific warning type.
WarningType warning_type() const { return type_; }
......@@ -90,11 +95,6 @@ class Warning {
std::vector<std::string> message_parameters_;
};
// Compare Warnings based on the tuple of (extension_id, type).
// The message associated with Warnings is purely informational
// and does not contribute to distinguishing extensions.
bool operator<(const Warning& a, const Warning& b);
typedef std::set<Warning> WarningSet;
} // namespace extensions
......
......@@ -4,6 +4,8 @@
#include "extensions/common/host_id.h"
#include <tuple>
HostID::HostID()
: type_(HostType::EXTENSIONS) {
}
......@@ -21,13 +23,9 @@ HostID::~HostID() {
}
bool HostID::operator<(const HostID& host_id) const {
if (type_ != host_id.type())
return type_ < host_id.type();
else if (id_ != host_id.id())
return id_ < host_id.id();
return false;
return std::tie(type_, id_) < std::tie(host_id.type_, host_id.id_);
}
bool HostID::operator==(const HostID& host_id) const {
return type_ == host_id.type() && id_ == host_id.id();
return type_ == host_id.type_ && id_ == host_id.id_;
}
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