1 // Copyright 2016 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 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_IDENTITY_H_
6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_IDENTITY_H_
7 
8 #include <string>
9 
10 #include "base/component_export.h"
11 #include "base/token.h"
12 
13 namespace service_manager {
14 
15 // Represents the identity of a single service instance running in the system.
16 // Every service instance has an Identity assigned to it, either by the Service
17 // Manager or by a trusted client using the privileged
18 // |Connector.RegisterServiceInstance()| API. Each Identity is globally unique
19 // across space and time.
20 //
21 // |name| is the name of the service, as specified in the service's manifest.
22 //
23 // |instance_group| is a base::Token representing the identity of an isolated
24 // group of instances running in the system.
25 //
26 // |instance_id| identifies a more specific instance within the instance's
27 // group, or globally if the service's instances are shared across groups. Note
28 // that at any given time there is only a single running service instance with
29 // any given combination of |name|, |instance_group|, and |instance_id|.
30 //
31 // |globally_unique_id| is a randomly generated token whose sole purpose is to
32 // differentiate identities of instances over time where all three other fields
33 // are identical.
COMPONENT_EXPORT(SERVICE_MANAGER_CPP_TYPES)34 class COMPONENT_EXPORT(SERVICE_MANAGER_CPP_TYPES) Identity {
35  public:
36   Identity();
37   explicit Identity(const std::string& name,
38                     const base::Token& instance_group,
39                     const base::Token& instance_id,
40                     const base::Token& globally_unique_id);
41   Identity(const Identity& other);
42   ~Identity();
43 
44   Identity& operator=(const Identity& other);
45   bool operator<(const Identity& other) const;
46   bool operator==(const Identity& other) const;
47   bool operator!=(const Identity& other) const { return !(*this == other); }
48 
49   bool IsValid() const;
50 
51   std::string ToString() const;
52 
53   const std::string& name() const { return name_; }
54   const base::Token& instance_group() const { return instance_group_; }
55   const base::Token& instance_id() const { return instance_id_; }
56   const base::Token& globally_unique_id() const { return globally_unique_id_; }
57 
58  private:
59   std::string name_;
60   base::Token instance_group_;
61   base::Token instance_id_;
62   base::Token globally_unique_id_;
63 };
64 
65 }  // namespace service_manager
66 
67 #endif  // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_IDENTITY_H_
68