| 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 "chromeos/login/auth/user_context.h" | 5 #include "chromeos/login/auth/user_context.h" |
| 6 #include "chromeos/login/user_names.h" | 6 #include "chromeos/login/user_names.h" |
| 7 | 7 |
| 8 namespace chromeos { | 8 namespace chromeos { |
| 9 | 9 |
| 10 UserContext::UserContext() | 10 UserContext::UserContext() |
| 11 : is_using_oauth_(true), | 11 : user_id_(std::string() /* gaia_id */, std::string() /* user_email */), |
| 12 is_using_oauth_(true), |
| 12 auth_flow_(AUTH_FLOW_OFFLINE), | 13 auth_flow_(AUTH_FLOW_OFFLINE), |
| 13 user_type_(user_manager::USER_TYPE_REGULAR) { | 14 user_type_(user_manager::USER_TYPE_REGULAR) { |
| 14 } | 15 } |
| 15 | 16 |
| 16 UserContext::UserContext(const UserContext& other) | 17 UserContext::UserContext(const UserContext& other) |
| 17 : user_id_(other.user_id_), | 18 : user_id_(other.user_id_), |
| 18 gaia_id_(other.gaia_id_), | |
| 19 key_(other.key_), | 19 key_(other.key_), |
| 20 auth_code_(other.auth_code_), | 20 auth_code_(other.auth_code_), |
| 21 refresh_token_(other.refresh_token_), | 21 refresh_token_(other.refresh_token_), |
| 22 access_token_(other.access_token_), | 22 access_token_(other.access_token_), |
| 23 user_id_hash_(other.user_id_hash_), | 23 user_id_hash_(other.user_id_hash_), |
| 24 is_using_oauth_(other.is_using_oauth_), | 24 is_using_oauth_(other.is_using_oauth_), |
| 25 auth_flow_(other.auth_flow_), | 25 auth_flow_(other.auth_flow_), |
| 26 user_type_(other.user_type_), | 26 user_type_(other.user_type_), |
| 27 public_session_locale_(other.public_session_locale_), | 27 public_session_locale_(other.public_session_locale_), |
| 28 public_session_input_method_(other.public_session_input_method_), | 28 public_session_input_method_(other.public_session_input_method_), |
| 29 device_id_(other.device_id_) { | 29 device_id_(other.device_id_) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 UserContext::UserContext(const std::string& user_id) | 32 UserContext::UserContext(const user_manager::UserID& user_id) |
| 33 : user_id_(login::CanonicalizeUserID(user_id)), | 33 : user_id_(user_id), |
| 34 is_using_oauth_(true), | 34 is_using_oauth_(true), |
| 35 auth_flow_(AUTH_FLOW_OFFLINE), | 35 auth_flow_(AUTH_FLOW_OFFLINE), |
| 36 user_type_(user_manager::USER_TYPE_REGULAR) { | 36 user_type_(user_manager::USER_TYPE_REGULAR) { |
| 37 user_id_.SetUserEmail(login::CanonicalizeUserID(user_id.GetUserEmail())); |
| 37 } | 38 } |
| 38 | 39 |
| 39 UserContext::UserContext(user_manager::UserType user_type, | 40 UserContext::UserContext(user_manager::UserType user_type, |
| 40 const std::string& user_id) | 41 const user_manager::UserID& user_id) |
| 41 : is_using_oauth_(true), | 42 : user_id_(user_id), |
| 43 is_using_oauth_(true), |
| 42 auth_flow_(AUTH_FLOW_OFFLINE), | 44 auth_flow_(AUTH_FLOW_OFFLINE), |
| 43 user_type_(user_type) { | 45 user_type_(user_type) { |
| 44 if (user_type_ == user_manager::USER_TYPE_REGULAR) | 46 if (user_type_ == user_manager::USER_TYPE_REGULAR) |
| 45 user_id_ = login::CanonicalizeUserID(user_id); | 47 user_id_.SetUserEmail(login::CanonicalizeUserID(user_id.GetUserEmail())); |
| 46 else | 48 else |
| 47 user_id_ = user_id; | 49 user_id_ = user_id; |
| 48 } | 50 } |
| 49 | 51 |
| 50 UserContext::~UserContext() { | 52 UserContext::~UserContext() { |
| 51 } | 53 } |
| 52 | 54 |
| 53 bool UserContext::operator==(const UserContext& context) const { | 55 bool UserContext::operator==(const UserContext& context) const { |
| 54 return context.user_id_ == user_id_ && context.gaia_id_ == gaia_id_ && | 56 return context.user_id_ == user_id_ && |
| 55 context.key_ == key_ && context.auth_code_ == auth_code_ && | 57 context.key_ == key_ && context.auth_code_ == auth_code_ && |
| 56 context.refresh_token_ == refresh_token_ && | 58 context.refresh_token_ == refresh_token_ && |
| 57 context.access_token_ == access_token_ && | 59 context.access_token_ == access_token_ && |
| 58 context.user_id_hash_ == user_id_hash_ && | 60 context.user_id_hash_ == user_id_hash_ && |
| 59 context.is_using_oauth_ == is_using_oauth_ && | 61 context.is_using_oauth_ == is_using_oauth_ && |
| 60 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_ && | 62 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_ && |
| 61 context.public_session_locale_ == public_session_locale_ && | 63 context.public_session_locale_ == public_session_locale_ && |
| 62 context.public_session_input_method_ == public_session_input_method_; | 64 context.public_session_input_method_ == public_session_input_method_; |
| 63 } | 65 } |
| 64 | 66 |
| 65 bool UserContext::operator!=(const UserContext& context) const { | 67 bool UserContext::operator!=(const UserContext& context) const { |
| 66 return !(*this == context); | 68 return !(*this == context); |
| 67 } | 69 } |
| 68 | 70 |
| 69 const std::string& UserContext::GetUserID() const { | 71 const user_manager::UserID& UserContext::GetUserID() const { |
| 70 return user_id_; | 72 return user_id_; |
| 71 } | 73 } |
| 72 | 74 |
| 73 const std::string& UserContext::GetGaiaID() const { | |
| 74 return gaia_id_; | |
| 75 } | |
| 76 | |
| 77 const Key* UserContext::GetKey() const { | 75 const Key* UserContext::GetKey() const { |
| 78 return &key_; | 76 return &key_; |
| 79 } | 77 } |
| 80 | 78 |
| 81 Key* UserContext::GetKey() { | 79 Key* UserContext::GetKey() { |
| 82 return &key_; | 80 return &key_; |
| 83 } | 81 } |
| 84 | 82 |
| 85 const std::string& UserContext::GetAuthCode() const { | 83 const std::string& UserContext::GetAuthCode() const { |
| 86 return auth_code_; | 84 return auth_code_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 118 |
| 121 const std::string& UserContext::GetDeviceId() const { | 119 const std::string& UserContext::GetDeviceId() const { |
| 122 return device_id_; | 120 return device_id_; |
| 123 } | 121 } |
| 124 | 122 |
| 125 bool UserContext::HasCredentials() const { | 123 bool UserContext::HasCredentials() const { |
| 126 return (!user_id_.empty() && !key_.GetSecret().empty()) || | 124 return (!user_id_.empty() && !key_.GetSecret().empty()) || |
| 127 !auth_code_.empty(); | 125 !auth_code_.empty(); |
| 128 } | 126 } |
| 129 | 127 |
| 130 void UserContext::SetUserID(const std::string& user_id) { | 128 void UserContext::SetUserID(const user_manager::UserID& user_id) { |
| 131 user_id_ = login::CanonicalizeUserID(user_id); | 129 user_id_.SetUserEmail(login::CanonicalizeUserID(user_id.GetUserEmail())); |
| 132 } | |
| 133 | |
| 134 void UserContext::SetGaiaID(const std::string& gaia_id) { | |
| 135 gaia_id_ = gaia_id; | |
| 136 } | 130 } |
| 137 | 131 |
| 138 void UserContext::SetKey(const Key& key) { | 132 void UserContext::SetKey(const Key& key) { |
| 139 key_ = key; | 133 key_ = key; |
| 140 } | 134 } |
| 141 | 135 |
| 142 void UserContext::SetAuthCode(const std::string& auth_code) { | 136 void UserContext::SetAuthCode(const std::string& auth_code) { |
| 143 auth_code_ = auth_code; | 137 auth_code_ = auth_code; |
| 144 } | 138 } |
| 145 | 139 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 device_id_ = device_id; | 173 device_id_ = device_id; |
| 180 } | 174 } |
| 181 | 175 |
| 182 void UserContext::ClearSecrets() { | 176 void UserContext::ClearSecrets() { |
| 183 key_.ClearSecret(); | 177 key_.ClearSecret(); |
| 184 auth_code_.clear(); | 178 auth_code_.clear(); |
| 185 refresh_token_.clear(); | 179 refresh_token_.clear(); |
| 186 } | 180 } |
| 187 | 181 |
| 188 } // namespace chromeos | 182 } // namespace chromeos |
| OLD | NEW |