Skip to content

Commit

Permalink
libstdc++: fix ostream operator<< for apps::AppUpdate
Browse files Browse the repository at this point in the history
std::unique_ptr has no operator<< in libstdc++. Even it would
exist, it would just return the pointer value and not the content.
Implement the necessary ToString() methods.

Bug: 957519
Change-Id: I6c4cf0005078a5d2fe6b7ee279f7af4e6ce1f9d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3536661
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Commit-Queue: Stephan Hartmann <stha09@googlemail.com>
Cr-Commit-Position: refs/heads/main@{#986374}
  • Loading branch information
stha09 authored and Chromium LUCI CQ committed Mar 29, 2022
1 parent 2316f83 commit 30523fd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/services/app_service/public/cpp/app_update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ std::ostream& operator<<(std::ostream& out, const AppUpdate& app) {

out << "IntentFilters: " << std::endl;
for (const auto& filter : app.IntentFilters()) {
out << filter << std::endl;
out << filter->ToString() << std::endl;
}

out << "ResizeLocked: " << PRINT_OPTIONAL_VALUE(ResizeLocked) << std::endl;
Expand Down
46 changes: 46 additions & 0 deletions components/services/app_service/public/cpp/intent_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

namespace apps {

APP_ENUM_TO_STRING(ConditionType,
kScheme,
kHost,
kPattern,
kAction,
kMimeType,
kFile)

ConditionValue::ConditionValue(const std::string& value,
PatternMatchType match_type)
: value(value), match_type(match_type) {}
Expand All @@ -20,6 +28,18 @@ bool ConditionValue::operator!=(const ConditionValue& other) const {
return !(*this == other);
}

std::string ConditionValue::ToString() const {
std::stringstream out;
if (match_type == PatternMatchType::kSuffix) {
out << "*";
}
out << value;
if (match_type == PatternMatchType::kPrefix) {
out << "*";
}
return out.str();
}

Condition::Condition(ConditionType condition_type,
ConditionValues condition_values)
: condition_type(condition_type),
Expand Down Expand Up @@ -55,6 +75,15 @@ ConditionPtr Condition::Clone() const {
return std::make_unique<Condition>(condition_type, std::move(values));
}

std::string Condition::ToString() const {
std::stringstream out;
out << " - " << EnumToString(condition_type) << ":";
for (const auto& condition_value : condition_values) {
out << " " << condition_value->ToString();
}
return out.str();
}

IntentFilter::IntentFilter() = default;
IntentFilter::~IntentFilter() = default;

Expand Down Expand Up @@ -186,6 +215,23 @@ bool IntentFilter::IsFileExtensionsFilter() {
return true;
}

std::string IntentFilter::ToString() const {
std::stringstream out;
if (activity_name.has_value()) {
out << " activity_name: " << activity_name.value() << std::endl;
}
if (activity_label.has_value()) {
out << " activity_label: " << activity_label.value() << std::endl;
}
if (!conditions.empty()) {
out << " conditions:" << std::endl;
for (const auto& condition : conditions) {
out << condition->ToString() << std::endl;
}
}
return out.str();
}

IntentFilters CloneIntentFilters(const IntentFilters& intent_filters) {
IntentFilters ret;
for (const auto& intent_filter : intent_filters) {
Expand Down
22 changes: 14 additions & 8 deletions components/services/app_service/public/cpp/intent_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "base/component_export.h"
#include "base/containers/flat_map.h"
#include "components/services/app_service/public/cpp/macros.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

Expand All @@ -31,14 +32,13 @@ enum class IntentFilterMatchLevel {
};

// The intent filter matching condition types.
enum class ConditionType {
kScheme, // Matches the URL scheme (e.g. https, tel).
kHost, // Matches the URL host (e.g. www.google.com).
kPattern, // Matches the URL pattern (e.g. /abc/*).
kAction, // Matches the action type (e.g. view, send).
kMimeType, // Matches the top-level mime type (e.g. text/plain).
kFile, // Matches against all files.
};
ENUM(ConditionType,
kScheme, // Matches the URL scheme (e.g. https, tel).
kHost, // Matches the URL host (e.g. www.google.com).
kPattern, // Matches the URL pattern (e.g. /abc/*).
kAction, // Matches the action type (e.g. view, send).
kMimeType, // Matches the top-level mime type (e.g. text/plain).
kFile) // Matches against all files.

// The pattern match type for intent filter pattern condition.
enum class PatternMatchType {
Expand All @@ -64,6 +64,8 @@ struct COMPONENT_EXPORT(APP_TYPES) ConditionValue {
bool operator==(const ConditionValue& other) const;
bool operator!=(const ConditionValue& other) const;

std::string ToString() const;

std::string value;
PatternMatchType match_type; // This will be None for non pattern conditions.
};
Expand All @@ -85,6 +87,8 @@ struct COMPONENT_EXPORT(APP_TYPES) Condition {

std::unique_ptr<Condition> Clone() const;

std::string ToString() const;

ConditionType condition_type;
ConditionValues condition_values;
};
Expand Down Expand Up @@ -129,6 +133,8 @@ struct COMPONENT_EXPORT(APP_TYPES) IntentFilter {
// Returns true if the filter only contains file extension pattern matches.
bool IsFileExtensionsFilter();

std::string ToString() const;

Conditions conditions;

// Activity which registered this filter. We only fill this field for ARC
Expand Down

0 comments on commit 30523fd

Please sign in to comment.