| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/auth/user_context.h" | |
| 6 | |
| 7 #include "chrome/browser/chromeos/login/helper.h" | |
| 8 | |
| 9 namespace chromeos { | |
| 10 | |
| 11 UserContext::UserContext() | |
| 12 : is_using_oauth_(true), | |
| 13 auth_flow_(AUTH_FLOW_OFFLINE), | |
| 14 user_type_(user_manager::USER_TYPE_REGULAR) { | |
| 15 } | |
| 16 | |
| 17 UserContext::UserContext(const UserContext& other) | |
| 18 : user_id_(other.user_id_), | |
| 19 key_(other.key_), | |
| 20 auth_code_(other.auth_code_), | |
| 21 user_id_hash_(other.user_id_hash_), | |
| 22 is_using_oauth_(other.is_using_oauth_), | |
| 23 auth_flow_(other.auth_flow_), | |
| 24 user_type_(other.user_type_) { | |
| 25 } | |
| 26 | |
| 27 UserContext::UserContext(const std::string& user_id) | |
| 28 : user_id_(login::CanonicalizeUserID(user_id)), | |
| 29 is_using_oauth_(true), | |
| 30 auth_flow_(AUTH_FLOW_OFFLINE), | |
| 31 user_type_(user_manager::USER_TYPE_REGULAR) { | |
| 32 } | |
| 33 | |
| 34 UserContext::UserContext(user_manager::UserType user_type, | |
| 35 const std::string& user_id) | |
| 36 : is_using_oauth_(true), | |
| 37 auth_flow_(AUTH_FLOW_OFFLINE), | |
| 38 user_type_(user_type) { | |
| 39 if (user_type_ == user_manager::USER_TYPE_REGULAR) | |
| 40 user_id_ = login::CanonicalizeUserID(user_id); | |
| 41 else | |
| 42 user_id_ = user_id; | |
| 43 } | |
| 44 | |
| 45 UserContext::~UserContext() { | |
| 46 } | |
| 47 | |
| 48 bool UserContext::operator==(const UserContext& context) const { | |
| 49 return context.user_id_ == user_id_ && context.key_ == key_ && | |
| 50 context.auth_code_ == auth_code_ && | |
| 51 context.user_id_hash_ == user_id_hash_ && | |
| 52 context.is_using_oauth_ == is_using_oauth_ && | |
| 53 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_; | |
| 54 } | |
| 55 | |
| 56 bool UserContext::operator!=(const UserContext& context) const { | |
| 57 return !(*this == context); | |
| 58 } | |
| 59 | |
| 60 const std::string& UserContext::GetUserID() const { | |
| 61 return user_id_; | |
| 62 } | |
| 63 | |
| 64 const Key* UserContext::GetKey() const { | |
| 65 return &key_; | |
| 66 } | |
| 67 | |
| 68 Key* UserContext::GetKey() { | |
| 69 return &key_; | |
| 70 } | |
| 71 | |
| 72 const std::string& UserContext::GetAuthCode() const { | |
| 73 return auth_code_; | |
| 74 } | |
| 75 | |
| 76 const std::string& UserContext::GetUserIDHash() const { | |
| 77 return user_id_hash_; | |
| 78 } | |
| 79 | |
| 80 bool UserContext::IsUsingOAuth() const { | |
| 81 return is_using_oauth_; | |
| 82 } | |
| 83 | |
| 84 UserContext::AuthFlow UserContext::GetAuthFlow() const { | |
| 85 return auth_flow_; | |
| 86 } | |
| 87 | |
| 88 user_manager::UserType UserContext::GetUserType() const { | |
| 89 return user_type_; | |
| 90 } | |
| 91 | |
| 92 bool UserContext::HasCredentials() const { | |
| 93 return (!user_id_.empty() && !key_.GetSecret().empty()) || | |
| 94 !auth_code_.empty(); | |
| 95 } | |
| 96 | |
| 97 void UserContext::SetUserID(const std::string& user_id) { | |
| 98 user_id_ = login::CanonicalizeUserID(user_id); | |
| 99 } | |
| 100 | |
| 101 void UserContext::SetKey(const Key& key) { | |
| 102 key_ = key; | |
| 103 } | |
| 104 | |
| 105 void UserContext::SetAuthCode(const std::string& auth_code) { | |
| 106 auth_code_ = auth_code; | |
| 107 } | |
| 108 | |
| 109 void UserContext::SetUserIDHash(const std::string& user_id_hash) { | |
| 110 user_id_hash_ = user_id_hash; | |
| 111 } | |
| 112 | |
| 113 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { | |
| 114 is_using_oauth_ = is_using_oauth; | |
| 115 } | |
| 116 | |
| 117 void UserContext::SetAuthFlow(AuthFlow auth_flow) { | |
| 118 auth_flow_ = auth_flow; | |
| 119 } | |
| 120 | |
| 121 void UserContext::SetUserType(user_manager::UserType user_type) { | |
| 122 user_type_ = user_type; | |
| 123 } | |
| 124 | |
| 125 void UserContext::ClearSecrets() { | |
| 126 key_.ClearSecret(); | |
| 127 auth_code_.clear(); | |
| 128 } | |
| 129 | |
| 130 } // namespace chromeos | |
| OLD | NEW |