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 @@ ...@@ -4,6 +4,7 @@
#include "chrome/common/extensions/permissions/chrome_permission_message_provider.h" #include "chrome/common/extensions/permissions/chrome_permission_message_provider.h"
#include <tuple>
#include <vector> #include <vector>
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
...@@ -27,11 +28,8 @@ class ComparablePermission { ...@@ -27,11 +28,8 @@ class ComparablePermission {
explicit ComparablePermission(const PermissionMessage& msg) : msg_(&msg) {} explicit ComparablePermission(const PermissionMessage& msg) : msg_(&msg) {}
bool operator<(const ComparablePermission& rhs) const { bool operator<(const ComparablePermission& rhs) const {
if (msg_->message() < rhs.msg_->message()) return std::tie(msg_->message(), msg_->submessages()) <
return true; std::tie(rhs.msg_->message(), rhs.msg_->submessages());
if (msg_->message() > rhs.msg_->message())
return false;
return msg_->submessages() < rhs.msg_->submessages();
} }
bool operator==(const ComparablePermission& rhs) const { bool operator==(const ComparablePermission& rhs) const {
......
...@@ -459,11 +459,10 @@ operator=(ExtensionRulesetData&& other) = default; ...@@ -459,11 +459,10 @@ operator=(ExtensionRulesetData&& other) = default;
bool RulesetManager::ExtensionRulesetData::operator<( bool RulesetManager::ExtensionRulesetData::operator<(
const ExtensionRulesetData& other) const { 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. // ties.
return (extension_install_time != other.extension_install_time) return std::tie(extension_install_time, extension_id) >
? (extension_install_time > other.extension_install_time) std::tie(other.extension_install_time, other.extension_id);
: (extension_id < other.extension_id);
} }
bool RulesetManager::ShouldEvaluateRequest( bool RulesetManager::ShouldEvaluateRequest(
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <stddef.h> #include <stddef.h>
#include <tuple>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -126,6 +128,11 @@ Warning Warning::CreateRulesetFailedToLoadWarning( ...@@ -126,6 +128,11 @@ Warning Warning::CreateRulesetFailedToLoadWarning(
{} /*message_parameters*/); {} /*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 { std::string Warning::GetLocalizedMessage(const ExtensionSet* extensions) const {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -166,10 +173,4 @@ std::string Warning::GetLocalizedMessage(const ExtensionSet* extensions) const { ...@@ -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 } // namespace extensions
...@@ -63,6 +63,11 @@ class Warning { ...@@ -63,6 +63,11 @@ class Warning {
static Warning CreateRulesetFailedToLoadWarning( static Warning CreateRulesetFailedToLoadWarning(
const ExtensionId& extension_id); 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. // Returns the specific warning type.
WarningType warning_type() const { return type_; } WarningType warning_type() const { return type_; }
...@@ -90,11 +95,6 @@ class Warning { ...@@ -90,11 +95,6 @@ class Warning {
std::vector<std::string> message_parameters_; 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; typedef std::set<Warning> WarningSet;
} // namespace extensions } // namespace extensions
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "extensions/common/host_id.h" #include "extensions/common/host_id.h"
#include <tuple>
HostID::HostID() HostID::HostID()
: type_(HostType::EXTENSIONS) { : type_(HostType::EXTENSIONS) {
} }
...@@ -21,13 +23,9 @@ HostID::~HostID() { ...@@ -21,13 +23,9 @@ HostID::~HostID() {
} }
bool HostID::operator<(const HostID& host_id) const { bool HostID::operator<(const HostID& host_id) const {
if (type_ != host_id.type()) return std::tie(type_, id_) < std::tie(host_id.type_, host_id.id_);
return type_ < host_id.type();
else if (id_ != host_id.id())
return id_ < host_id.id();
return false;
} }
bool HostID::operator==(const HostID& host_id) const { 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