Skip to content

Commit

Permalink
Extensions: Clean up some < operator definitions to use std::tie.
Browse files Browse the repository at this point in the history
Bug: None
Change-Id: I36623aa2bbb0a3fd1aeebbf3a9f44f94fc7164b5
Reviewed-on: https://chromium-review.googlesource.com/c/1460193
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: Karan Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630473}
  • Loading branch information
Istiaque Ahmed authored and Commit Bot committed Feb 8, 2019
1 parent 40ebd8b commit 8680d31
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chrome/common/extensions/permissions/chrome_permission_message_provider.h"

#include <tuple>
#include <vector>

#include "base/metrics/field_trial.h"
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 7 additions & 6 deletions extensions/browser/warning_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
10 changes: 5 additions & 5 deletions extensions/browser/warning_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions extensions/common/host_id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "extensions/common/host_id.h"

#include <tuple>

HostID::HostID()
: type_(HostType::EXTENSIONS) {
}
Expand All @@ -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_;
}

0 comments on commit 8680d31

Please sign in to comment.