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

Unified Diff: mojo/shell/public/cpp/lib/identity.cc

Issue 1769163002: Add a instance groups to Connect(), and introduce an Identity struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/shell/public/cpp/lib/connector_impl.cc ('k') | mojo/shell/public/cpp/lib/interface_registry.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/public/cpp/lib/identity.cc
diff --git a/mojo/shell/public/cpp/lib/identity.cc b/mojo/shell/public/cpp/lib/identity.cc
new file mode 100644
index 0000000000000000000000000000000000000000..85860a0c3a75898d805b26e78027330420a03625
--- /dev/null
+++ b/mojo/shell/public/cpp/lib/identity.cc
@@ -0,0 +1,60 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/shell/public/cpp/identity.h"
+
+#include "base/guid.h"
+#include "mojo/shell/public/cpp/names.h"
+
+namespace mojo {
+
+Identity::Identity() {}
+
+Identity::Identity(const std::string& name, const std::string& user_id)
+ : Identity(name, user_id, "") {}
+
+Identity::Identity(const std::string& name, const std::string& user_id,
+ const std::string& instance)
+ : name_(name),
+ user_id_(user_id),
+ instance_(instance.empty() ? GetNamePath(name_) : instance) {
+ CHECK(!user_id.empty());
+ CHECK(base::IsValidGUID(user_id));
+}
+
+Identity::Identity(const Identity& other) = default;
+
+Identity::~Identity() {}
+
+bool Identity::operator<(const Identity& other) const {
+ if (name_ != other.name_)
+ return name_ < other.name_;
+ if (instance_ != other.instance_)
+ return instance_ < other.instance_;
+ return user_id_ < other.user_id_;
+}
+
+bool Identity::operator==(const Identity& other) const {
+ return other.name_ == name_ && other.instance_ == instance_ &&
+ other.user_id_ == user_id_;
+}
+
+// static
+shell::mojom::IdentityPtr
+ TypeConverter<shell::mojom::IdentityPtr, Identity>::Convert(
+ const Identity& input) {
+ shell::mojom::IdentityPtr identity(shell::mojom::Identity::New());
+ identity->name = input.name();
+ identity->user_id = input.user_id();
+ identity->instance = input.instance();
+ return identity;
+}
+
+// static
+Identity TypeConverter<Identity, shell::mojom::IdentityPtr>::Convert(
+ const shell::mojom::IdentityPtr& input) {
+ return Identity(input->name, input->user_id, input->instance);
+}
+
+} // namespace mojo
« no previous file with comments | « mojo/shell/public/cpp/lib/connector_impl.cc ('k') | mojo/shell/public/cpp/lib/interface_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698