| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/service_manager/public/cpp/identity.h" | 5 #include "services/service_manager/public/cpp/identity.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "services/service_manager/public/cpp/names.h" | 8 #include "services/service_manager/public/cpp/names.h" |
| 9 | 9 |
| 10 namespace service_manager { | 10 namespace service_manager { |
| 11 | 11 |
| 12 Identity::Identity() {} | 12 Identity::Identity() {} |
| 13 | 13 |
| 14 Identity::Identity(const std::string& name, const std::string& user_id) | 14 Identity::Identity(const std::string& name, const std::string& user_id) |
| 15 : Identity(name, user_id, "") {} | 15 : Identity(name, user_id, "") {} |
| 16 | 16 |
| 17 Identity::Identity(const std::string& name, const std::string& user_id, | 17 Identity::Identity(const std::string& name, const std::string& user_id, |
| 18 const std::string& instance) | 18 const std::string& instance) |
| 19 : name_(name), | 19 : name_(name), |
| 20 user_id_(user_id), | 20 user_id_(user_id), |
| 21 instance_(instance.empty() ? GetNamePath(name_) : instance) { | 21 instance_(instance) { |
| 22 CHECK(!user_id.empty()); | 22 CHECK(!user_id.empty()); |
| 23 CHECK(base::IsValidGUID(user_id)); | 23 CHECK(base::IsValidGUID(user_id)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 Identity::Identity(const Identity& other) = default; | 26 Identity::Identity(const Identity& other) = default; |
| 27 | 27 |
| 28 Identity::~Identity() {} | 28 Identity::~Identity() {} |
| 29 | 29 |
| 30 bool Identity::operator<(const Identity& other) const { | 30 bool Identity::operator<(const Identity& other) const { |
| 31 if (name_ != other.name_) | 31 if (name_ != other.name_) |
| 32 return name_ < other.name_; | 32 return name_ < other.name_; |
| 33 if (instance_ != other.instance_) | 33 if (instance_ != other.instance_) |
| 34 return instance_ < other.instance_; | 34 return instance_ < other.instance_; |
| 35 return user_id_ < other.user_id_; | 35 return user_id_ < other.user_id_; |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool Identity::operator==(const Identity& other) const { | 38 bool Identity::operator==(const Identity& other) const { |
| 39 return other.name_ == name_ && other.instance_ == instance_ && | 39 return other.name_ == name_ && other.instance_ == instance_ && |
| 40 other.user_id_ == user_id_; | 40 other.user_id_ == user_id_; |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool Identity::IsValid() const { | 43 bool Identity::IsValid() const { |
| 44 return IsValidName(name_) && base::IsValidGUID(user_id_); | 44 return IsValidName(name_) && base::IsValidGUID(user_id_); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace service_manager | 47 } // namespace service_manager |
| OLD | NEW |