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 #include "mojo/shell/identity.h" | 5 #include "mojo/shell/identity.h" |
6 | 6 |
7 #include "mojo/shell/public/interfaces/shell.mojom.h" | 7 #include "mojo/shell/public/interfaces/shell.mojom.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 namespace shell { | 10 namespace shell { |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 Identity::Identity() {} | 30 Identity::Identity() {} |
31 | 31 |
32 Identity::Identity(const GURL& url) | 32 Identity::Identity(const GURL& url) |
33 : Identity(url, url.spec(), mojom::Connector::kUserRoot) {} | 33 : Identity(url, url.spec(), mojom::Connector::kUserRoot) {} |
34 | 34 |
35 Identity::Identity(const GURL& url, const std::string& qualifier, | 35 Identity::Identity(const GURL& url, const std::string& qualifier, |
36 uint32_t user_id) | 36 uint32_t user_id) |
37 : Identity(url, qualifier, user_id, CapabilityFilter()) {} | |
38 | |
39 Identity::Identity(const GURL& url, const std::string& qualifier, | |
40 uint32_t user_id, CapabilityFilter filter) | |
41 : url_(url), | 37 : url_(url), |
42 qualifier_(qualifier.empty() ? url_.spec() : qualifier), | 38 qualifier_(qualifier.empty() ? url_.spec() : qualifier), |
43 user_id_(user_id), | 39 user_id_(user_id) {} |
44 filter_(CanonicalizeFilter(filter)) {} | |
45 | 40 |
46 Identity::~Identity() {} | 41 Identity::~Identity() {} |
47 | 42 |
48 bool Identity::operator<(const Identity& other) const { | 43 bool Identity::operator<(const Identity& other) const { |
49 // We specifically don't include filter in the equivalence check because we | 44 // We specifically don't include filter in the equivalence check because we |
50 // don't quite know how this should work yet. | 45 // don't quite know how this should work yet. |
51 // TODO(beng): figure out how it should work. | 46 // TODO(beng): figure out how it should work. |
52 if (url_ != other.url_) | 47 if (url_ != other.url_) |
53 return url_ < other.url_; | 48 return url_ < other.url_; |
54 if (qualifier_ != other.qualifier_) | 49 if (qualifier_ != other.qualifier_) |
55 return qualifier_ < other.qualifier_; | 50 return qualifier_ < other.qualifier_; |
56 return user_id_ < other.user_id_; | 51 return user_id_ < other.user_id_; |
57 } | 52 } |
58 | 53 |
59 bool Identity::operator==(const Identity& other) const { | 54 bool Identity::operator==(const Identity& other) const { |
| 55 // We specifically don't include filter in the equivalence check because we |
| 56 // don't quite know how this should work yet. |
| 57 // TODO(beng): figure out how it should work. |
60 return other.url_ == url_ && other.qualifier_ == qualifier_ && | 58 return other.url_ == url_ && other.qualifier_ == qualifier_ && |
61 other.filter_ == filter_ && other.user_id_ == user_id_; | 59 other.user_id_ == user_id_; |
| 60 } |
| 61 |
| 62 void Identity::SetFilter(const CapabilityFilter& filter) { |
| 63 filter_ = CanonicalizeFilter(filter); |
62 } | 64 } |
63 | 65 |
64 Identity CreateShellIdentity() { | 66 Identity CreateShellIdentity() { |
65 return Identity(GURL("mojo://shell/"), std::string(), | 67 Identity id = |
66 mojom::Connector::kUserRoot, GetPermissiveCapabilityFilter()); | 68 Identity(GURL("mojo://shell/"), "", mojom::Connector::kUserRoot); |
| 69 id.SetFilter(GetPermissiveCapabilityFilter()); |
| 70 return id; |
67 } | 71 } |
68 | 72 |
69 } // namespace shell | 73 } // namespace shell |
70 } // namespace mojo | 74 } // namespace mojo |
OLD | NEW |