OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 MOJO_SHELL_IDENTITY_H_ | |
6 #define MOJO_SHELL_IDENTITY_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <map> | |
11 #include <set> | |
12 #include <string> | |
13 | |
14 namespace mojo { | |
15 namespace shell { | |
16 | |
17 // A set of names of interfaces that may be exposed to an application. | |
18 using AllowedInterfaces = std::set<std::string>; | |
19 // A map of allowed applications to allowed interface sets. See shell.mojom for | |
20 // more details. | |
21 using CapabilityFilter = std::map<std::string, AllowedInterfaces>; | |
22 | |
23 // Represents the identity of an application. | |
24 // |name| is the structured name of the application. | |
25 // |qualifier| is a string that allows to tie a specific instance of an | |
26 // application to another. A typical use case of qualifier is to control process | |
27 // grouping for a given application name. For example, the core services are | |
28 // grouped into "Core"/"Files"/"Network"/etc. using qualifier; content handler's | |
29 // qualifier is derived from the origin of the content. | |
30 class Identity { | |
31 public: | |
32 Identity(); | |
33 // Assumes user = mojom::kRootUserID. | |
34 // Used in tests or for shell-initiated connections. | |
35 explicit Identity(const std::string& in_name); | |
36 Identity(const std::string& in_name, | |
37 const std::string& in_qualifier, | |
38 const std::string& user_id); | |
39 Identity(const Identity& other); | |
40 ~Identity(); | |
41 | |
42 bool operator<(const Identity& other) const; | |
43 bool is_null() const { return name_.empty(); } | |
44 bool operator==(const Identity& other) const; | |
45 | |
46 const std::string& name() const { return name_; } | |
47 const std::string& user_id() const { return user_id_; } | |
48 void set_user_id(const std::string& user_id) { user_id_ = user_id; } | |
49 const std::string& qualifier() const { return qualifier_; } | |
50 void set_filter(const CapabilityFilter& filter) { filter_ = filter; } | |
51 const CapabilityFilter& filter() const { return filter_; } | |
52 | |
53 private: | |
54 std::string name_; | |
55 std::string qualifier_; | |
56 | |
57 std::string user_id_; | |
58 | |
59 // TODO(beng): CapabilityFilter is not currently included in equivalence | |
60 // checks for Identity since we're not currently clear on the | |
61 // policy for instance disambiguation. Need to figure this out. | |
62 // This field is supplied because it is logically part of the | |
63 // instance identity of an application. | |
64 CapabilityFilter filter_; | |
65 }; | |
66 | |
67 // Creates an identity for the Shell, used when the Shell connects to | |
68 // applications. | |
69 Identity CreateShellIdentity(); | |
70 | |
71 // Returns a capability filter that allows an application to connect to any | |
72 // other application and any service exposed by other applications. | |
73 CapabilityFilter GetPermissiveCapabilityFilter(); | |
74 | |
75 // Returns the set of interfaces that an application instance with |filter| is | |
76 // allowed to see from an instance with |identity|. | |
77 AllowedInterfaces GetAllowedInterfaces(const CapabilityFilter& filter, | |
78 const Identity& identity); | |
79 | |
80 } // namespace shell | |
81 } // namespace mojo | |
82 | |
83 #endif // MOJO_SHELL_IDENTITY_H_ | |
OLD | NEW |