Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: mojo/shell/identity.cc

Issue 1719193003: Add a user id parameter to connections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
8
7 namespace mojo { 9 namespace mojo {
8 namespace shell { 10 namespace shell {
9 namespace { 11 namespace {
10 12
11 // It's valid to specify mojo: URLs in the filter either as mojo:foo or 13 // It's valid to specify mojo: URLs in the filter either as mojo:foo or
12 // mojo://foo/ - but we store the filter in the latter form. 14 // mojo://foo/ - but we store the filter in the latter form.
13 CapabilityFilter CanonicalizeFilter(const CapabilityFilter& filter) { 15 CapabilityFilter CanonicalizeFilter(const CapabilityFilter& filter) {
14 CapabilityFilter canonicalized; 16 CapabilityFilter canonicalized;
15 for (CapabilityFilter::const_iterator it = filter.begin(); 17 for (CapabilityFilter::const_iterator it = filter.begin();
16 it != filter.end(); 18 it != filter.end();
17 ++it) { 19 ++it) {
18 if (it->first == "*") 20 if (it->first == "*")
19 canonicalized[it->first] = it->second; 21 canonicalized[it->first] = it->second;
20 else 22 else
21 canonicalized[GURL(it->first).spec()] = it->second; 23 canonicalized[GURL(it->first).spec()] = it->second;
22 } 24 }
23 return canonicalized; 25 return canonicalized;
24 } 26 }
25 27
26 } // namespace 28 } // namespace
27 29
28 Identity::Identity() {} 30 Identity::Identity() {}
29 31
30 Identity::Identity(const GURL& url) 32 Identity::Identity(const GURL& url)
31 : url_(url), 33 : Identity(url, url.spec(), mojom::Shell::kUserRoot) {}
32 qualifier_(url_.spec()) {}
33 34
34 Identity::Identity(const GURL& url, const std::string& qualifier) 35 Identity::Identity(const GURL& url, const std::string& qualifier,
35 : url_(url), 36 uint32_t user_id)
36 qualifier_(qualifier.empty() ? url_.spec() : qualifier) {} 37 : Identity(url, qualifier, user_id, CapabilityFilter()) {}
37 38
38 Identity::Identity(const GURL& url, 39 Identity::Identity(const GURL& url, const std::string& qualifier,
39 const std::string& qualifier, 40 uint32_t user_id, CapabilityFilter filter)
40 CapabilityFilter filter)
41 : url_(url), 41 : url_(url),
42 qualifier_(qualifier.empty() ? url_.spec() : qualifier), 42 qualifier_(qualifier.empty() ? url_.spec() : qualifier),
43 user_id_(user_id),
43 filter_(CanonicalizeFilter(filter)) {} 44 filter_(CanonicalizeFilter(filter)) {}
44 45
45 Identity::~Identity() {} 46 Identity::~Identity() {}
46 47
47 bool Identity::operator<(const Identity& other) const { 48 bool Identity::operator<(const Identity& other) const {
48 // We specifically don't include filter in the equivalence check because we 49 // We specifically don't include filter in the equivalence check because we
49 // don't quite know how this should work yet. 50 // don't quite know how this should work yet.
50 // TODO(beng): figure out how it should work. 51 // TODO(beng): figure out how it should work.
51 if (url_ != other.url_) 52 if (url_ != other.url_)
52 return url_ < other.url_; 53 return url_ < other.url_;
53 return qualifier_ < other.qualifier_; 54 if (qualifier_ != other.qualifier_)
55 return qualifier_ < other.qualifier_;
56 return user_id_ != other.user_id_;
sky 2016/02/23 21:15:13 return user_id_ < other.user_id_;
54 } 57 }
55 58
56 bool Identity::operator==(const Identity& other) const { 59 bool Identity::operator==(const Identity& other) const {
57 return other.url_ == url_ && other.qualifier_ == qualifier_ && 60 return other.url_ == url_ && other.qualifier_ == qualifier_ &&
58 other.filter_ == filter_; 61 other.filter_ == filter_ && other.user_id_ == user_id_;
59 } 62 }
60 63
61 Identity CreateShellIdentity() { 64 Identity CreateShellIdentity() {
62 return Identity(GURL("mojo://shell/"), std::string(), 65 return Identity(GURL("mojo://shell/"), std::string(),
63 GetPermissiveCapabilityFilter()); 66 mojom::Shell::kUserRoot, GetPermissiveCapabilityFilter());
64 } 67 }
65 68
66 } // namespace shell 69 } // namespace shell
67 } // namespace mojo 70 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698