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