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