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