| 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() | 12 UserContext::UserContext() : is_using_oauth_(true), |
| 13 : is_using_oauth_(true), | 13 auth_flow_(AUTH_FLOW_OFFLINE) { |
| 14 auth_flow_(AUTH_FLOW_OFFLINE), | |
| 15 user_type_(User::USER_TYPE_REGULAR) { | |
| 16 } | 14 } |
| 17 | 15 |
| 18 UserContext::UserContext(const UserContext& other) | 16 UserContext::UserContext(const UserContext& other) |
| 19 : user_id_(other.user_id_), | 17 : user_id_(other.user_id_), |
| 20 key_(other.key_), | 18 key_(other.key_), |
| 21 auth_code_(other.auth_code_), | 19 auth_code_(other.auth_code_), |
| 22 user_id_hash_(other.user_id_hash_), | 20 user_id_hash_(other.user_id_hash_), |
| 23 is_using_oauth_(other.is_using_oauth_), | 21 is_using_oauth_(other.is_using_oauth_), |
| 24 auth_flow_(other.auth_flow_), | 22 auth_flow_(other.auth_flow_) { |
| 25 user_type_(other.user_type_) { | |
| 26 } | 23 } |
| 27 | 24 |
| 28 UserContext::UserContext(const std::string& user_id) | 25 UserContext::UserContext(const std::string& user_id) |
| 29 : user_id_(login::CanonicalizeUserID(user_id)), | 26 : user_id_(login::CanonicalizeUserID(user_id)), |
| 30 is_using_oauth_(true), | 27 is_using_oauth_(true), |
| 31 auth_flow_(AUTH_FLOW_OFFLINE), | 28 auth_flow_(AUTH_FLOW_OFFLINE) { |
| 32 user_type_(User::USER_TYPE_REGULAR) { | |
| 33 } | 29 } |
| 34 | 30 |
| 35 UserContext::~UserContext() { | 31 UserContext::~UserContext() { |
| 36 } | 32 } |
| 37 | 33 |
| 38 bool UserContext::operator==(const UserContext& context) const { | 34 bool UserContext::operator==(const UserContext& context) const { |
| 39 return context.user_id_ == user_id_ && context.key_ == key_ && | 35 return context.user_id_ == user_id_ && |
| 36 context.key_ == key_ && |
| 40 context.auth_code_ == auth_code_ && | 37 context.auth_code_ == auth_code_ && |
| 41 context.user_id_hash_ == user_id_hash_ && | 38 context.user_id_hash_ == user_id_hash_ && |
| 42 context.is_using_oauth_ == is_using_oauth_ && | 39 context.is_using_oauth_ == is_using_oauth_ && |
| 43 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_; | 40 context.auth_flow_ == auth_flow_; |
| 44 } | 41 } |
| 45 | 42 |
| 46 bool UserContext::operator!=(const UserContext& context) const { | 43 bool UserContext::operator!=(const UserContext& context) const { |
| 47 return !(*this == context); | 44 return !(*this == context); |
| 48 } | 45 } |
| 49 | 46 |
| 50 const std::string& UserContext::GetUserID() const { | 47 const std::string& UserContext::GetUserID() const { |
| 51 return user_id_; | 48 return user_id_; |
| 52 } | 49 } |
| 53 | 50 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 68 } | 65 } |
| 69 | 66 |
| 70 bool UserContext::IsUsingOAuth() const { | 67 bool UserContext::IsUsingOAuth() const { |
| 71 return is_using_oauth_; | 68 return is_using_oauth_; |
| 72 } | 69 } |
| 73 | 70 |
| 74 UserContext::AuthFlow UserContext::GetAuthFlow() const { | 71 UserContext::AuthFlow UserContext::GetAuthFlow() const { |
| 75 return auth_flow_; | 72 return auth_flow_; |
| 76 } | 73 } |
| 77 | 74 |
| 78 User::UserType UserContext::GetUserType() const { | |
| 79 return user_type_; | |
| 80 } | |
| 81 | |
| 82 bool UserContext::HasCredentials() const { | 75 bool UserContext::HasCredentials() const { |
| 83 return (!user_id_.empty() && !key_.GetSecret().empty()) || | 76 return (!user_id_.empty() && !key_.GetSecret().empty()) || |
| 84 !auth_code_.empty(); | 77 !auth_code_.empty(); |
| 85 } | 78 } |
| 86 | 79 |
| 87 void UserContext::SetUserID(const std::string& user_id) { | 80 void UserContext::SetUserID(const std::string& user_id) { |
| 88 user_id_ = login::CanonicalizeUserID(user_id); | 81 user_id_ = login::CanonicalizeUserID(user_id); |
| 89 } | 82 } |
| 90 | 83 |
| 91 void UserContext::SetKey(const Key& key) { | 84 void UserContext::SetKey(const Key& key) { |
| 92 key_ = key; | 85 key_ = key; |
| 93 } | 86 } |
| 94 | 87 |
| 95 void UserContext::SetAuthCode(const std::string& auth_code) { | 88 void UserContext::SetAuthCode(const std::string& auth_code) { |
| 96 auth_code_ = auth_code; | 89 auth_code_ = auth_code; |
| 97 } | 90 } |
| 98 | 91 |
| 99 void UserContext::SetUserIDHash(const std::string& user_id_hash) { | 92 void UserContext::SetUserIDHash(const std::string& user_id_hash) { |
| 100 user_id_hash_ = user_id_hash; | 93 user_id_hash_ = user_id_hash; |
| 101 } | 94 } |
| 102 | 95 |
| 103 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { | 96 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { |
| 104 is_using_oauth_ = is_using_oauth; | 97 is_using_oauth_ = is_using_oauth; |
| 105 } | 98 } |
| 106 | 99 |
| 107 void UserContext::SetAuthFlow(AuthFlow auth_flow) { | 100 void UserContext::SetAuthFlow(AuthFlow auth_flow) { |
| 108 auth_flow_ = auth_flow; | 101 auth_flow_ = auth_flow; |
| 109 } | 102 } |
| 110 | 103 |
| 111 void UserContext::SetUserType(User::UserType user_type) { | |
| 112 user_type_ = user_type; | |
| 113 } | |
| 114 | |
| 115 void UserContext::ClearSecrets() { | 104 void UserContext::ClearSecrets() { |
| 116 key_.ClearSecret(); | 105 key_.ClearSecret(); |
| 117 auth_code_.clear(); | 106 auth_code_.clear(); |
| 118 } | 107 } |
| 119 | 108 |
| 120 } // namespace chromeos | 109 } // namespace chromeos |
| OLD | NEW |