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/query_util.h" | |
8 | |
9 namespace mojo { | 7 namespace mojo { |
10 namespace shell { | 8 namespace shell { |
11 namespace { | 9 namespace { |
12 | 10 |
13 // It's valid to specify mojo: URLs in the filter either as mojo:foo or | 11 // It's valid to specify mojo: URLs in the filter either as mojo:foo or |
14 // mojo://foo/ - but we store the filter in the latter form. | 12 // mojo://foo/ - but we store the filter in the latter form. |
15 CapabilityFilter CanonicalizeFilter(const CapabilityFilter& filter) { | 13 CapabilityFilter CanonicalizeFilter(const CapabilityFilter& filter) { |
16 CapabilityFilter canonicalized; | 14 CapabilityFilter canonicalized; |
17 for (CapabilityFilter::const_iterator it = filter.begin(); | 15 for (CapabilityFilter::const_iterator it = filter.begin(); |
18 it != filter.end(); | 16 it != filter.end(); |
19 ++it) { | 17 ++it) { |
20 if (it->first == "*") | 18 if (it->first == "*") |
21 canonicalized[it->first] = it->second; | 19 canonicalized[it->first] = it->second; |
22 else | 20 else |
23 canonicalized[GURL(it->first).spec()] = it->second; | 21 canonicalized[GURL(it->first).spec()] = it->second; |
24 } | 22 } |
25 return canonicalized; | 23 return canonicalized; |
26 } | 24 } |
27 | 25 |
28 } // namespace | 26 } // namespace |
29 | 27 |
30 Identity::Identity() {} | 28 Identity::Identity() {} |
31 | 29 |
32 Identity::Identity(const GURL& url) | 30 Identity::Identity(const GURL& url) |
33 : url_(GetBaseURLAndQuery(url, nullptr)), | 31 : url_(url), |
34 qualifier_(url_.spec()) {} | 32 qualifier_(url_.spec()) {} |
35 | 33 |
36 Identity::Identity(const GURL& url, const std::string& qualifier) | 34 Identity::Identity(const GURL& url, const std::string& qualifier) |
37 : url_(GetBaseURLAndQuery(url, nullptr)), | 35 : url_(url), |
38 qualifier_(qualifier.empty() ? url_.spec() : qualifier) {} | 36 qualifier_(qualifier.empty() ? url_.spec() : qualifier) {} |
39 | 37 |
40 Identity::Identity(const GURL& url, | 38 Identity::Identity(const GURL& url, |
41 const std::string& qualifier, | 39 const std::string& qualifier, |
42 CapabilityFilter filter) | 40 CapabilityFilter filter) |
43 : url_(GetBaseURLAndQuery(url, nullptr)), | 41 : url_(url), |
44 qualifier_(qualifier.empty() ? url_.spec() : qualifier), | 42 qualifier_(qualifier.empty() ? url_.spec() : qualifier), |
45 filter_(CanonicalizeFilter(filter)) {} | 43 filter_(CanonicalizeFilter(filter)) {} |
46 | 44 |
47 Identity::~Identity() {} | 45 Identity::~Identity() {} |
48 | 46 |
49 bool Identity::operator<(const Identity& other) const { | 47 bool Identity::operator<(const Identity& other) const { |
50 // We specifically don't include filter in the equivalence check because we | 48 // We specifically don't include filter in the equivalence check because we |
51 // don't quite know how this should work yet. | 49 // don't quite know how this should work yet. |
52 // TODO(beng): figure out how it should work. | 50 // TODO(beng): figure out how it should work. |
53 if (url_ != other.url_) | 51 if (url_ != other.url_) |
54 return url_ < other.url_; | 52 return url_ < other.url_; |
55 return qualifier_ < other.qualifier_; | 53 return qualifier_ < other.qualifier_; |
56 } | 54 } |
57 | 55 |
58 } // namespace shell | 56 } // namespace shell |
59 } // namespace mojo | 57 } // namespace mojo |
OLD | NEW |