1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "services/service_manager/public/cpp/service_filter.h"
6 
7 namespace service_manager {
8 
9 ServiceFilter::ServiceFilter() = default;
10 
11 ServiceFilter::ServiceFilter(const ServiceFilter&) = default;
12 
13 ServiceFilter::ServiceFilter(ServiceFilter&&) = default;
14 
ServiceFilter(const Identity & identity)15 ServiceFilter::ServiceFilter(const Identity& identity)
16     : service_name_(identity.name()),
17       instance_group_(identity.instance_group()),
18       instance_id_(identity.instance_id()),
19       globally_unique_id_(identity.globally_unique_id()) {}
20 
21 ServiceFilter::~ServiceFilter() = default;
22 
23 ServiceFilter& ServiceFilter::operator=(const ServiceFilter& other) = default;
24 
25 // static
ByName(const std::string & service_name)26 ServiceFilter ServiceFilter::ByName(const std::string& service_name) {
27   return ServiceFilter(service_name, base::nullopt /* instance_group */,
28                        base::nullopt /* instance_id */,
29                        base::nullopt /* globally_unique_id */);
30 }
31 
32 // static
ByNameWithId(const std::string & service_name,const base::Token & instance_id)33 ServiceFilter ServiceFilter::ByNameWithId(const std::string& service_name,
34                                           const base::Token& instance_id) {
35   return ServiceFilter(service_name, base::nullopt /* instance_group */,
36                        instance_id, base::nullopt /* globally_unique_id */);
37 }
38 
39 // static
ByNameInGroup(const std::string & service_name,const base::Token & instance_group)40 ServiceFilter ServiceFilter::ByNameInGroup(const std::string& service_name,
41                                            const base::Token& instance_group) {
42   return ServiceFilter(service_name, instance_group,
43                        base::nullopt /* instance_id */,
44                        base::nullopt /* globally_unique_id */);
45 }
46 
47 // static
ByNameWithIdInGroup(const std::string & service_name,const base::Token & instance_id,const base::Token & instance_group)48 ServiceFilter ServiceFilter::ByNameWithIdInGroup(
49     const std::string& service_name,
50     const base::Token& instance_id,
51     const base::Token& instance_group) {
52   return ServiceFilter(service_name, instance_group, instance_id,
53                        base::nullopt /* globally_unique_id */);
54 }
55 
56 // static
ForExactIdentity(const Identity & identity)57 ServiceFilter ServiceFilter::ForExactIdentity(const Identity& identity) {
58   DCHECK(identity.IsValid());
59   return ServiceFilter(identity.name(), identity.instance_group(),
60                        identity.instance_id(), identity.globally_unique_id());
61 }
62 
operator <(const ServiceFilter & other) const63 bool ServiceFilter::operator<(const ServiceFilter& other) const {
64   return std::tie(service_name_, instance_group_, instance_id_,
65                   globally_unique_id_) <
66          std::tie(other.service_name_, other.instance_group_,
67                   other.instance_id_, other.globally_unique_id_);
68 }
69 
ServiceFilter(const std::string & service_name,const base::Optional<base::Token> & instance_group,const base::Optional<base::Token> & instance_id,const base::Optional<base::Token> & globally_unique_id)70 ServiceFilter::ServiceFilter(
71     const std::string& service_name,
72     const base::Optional<base::Token>& instance_group,
73     const base::Optional<base::Token>& instance_id,
74     const base::Optional<base::Token>& globally_unique_id)
75     : service_name_(service_name),
76       instance_group_(instance_group),
77       instance_id_(instance_id),
78       globally_unique_id_(globally_unique_id) {}
79 
80 }  // namespace service_manager
81