Chromium Code Reviews| 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_(EmptyAccountId()), |
|
achuithb
2015/10/23 00:08:51
in class member initialization, also remove initia
Alexander Alekseev
2015/10/23 09:11:24
This is dangerous, as EmptyAccountId fits only def
| |
| 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 UserContext::UserContext(const UserContext& other) | 16 UserContext::UserContext(const UserContext& other) |
| 17 : user_id_(other.user_id_), | 17 : user_id_(other.user_id_), |
| 18 gaia_id_(other.gaia_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 gaps_cookie_(other.gaps_cookie_) { | 30 gaps_cookie_(other.gaps_cookie_) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 UserContext::UserContext(const std::string& user_id) | 33 UserContext::UserContext(const AccountId& user_id) |
| 34 : user_id_(login::CanonicalizeUserID(user_id)), | 34 : user_id_(user_id), |
| 35 is_using_oauth_(true), | 35 is_using_oauth_(true), |
| 36 auth_flow_(AUTH_FLOW_OFFLINE), | 36 auth_flow_(AUTH_FLOW_OFFLINE), |
| 37 user_type_(user_manager::USER_TYPE_REGULAR) { | 37 user_type_(user_manager::USER_TYPE_REGULAR) { |
| 38 user_id_.SetUserEmail(login::CanonicalizeUserID(user_id.GetUserEmail())); | |
| 38 } | 39 } |
| 39 | 40 |
| 40 UserContext::UserContext(user_manager::UserType user_type, | 41 UserContext::UserContext(user_manager::UserType user_type, |
| 41 const std::string& user_id) | 42 const std::string& user_id) |
| 42 : is_using_oauth_(true), | 43 : user_id_(EmptyAccountId()), |
| 44 is_using_oauth_(true), | |
| 43 auth_flow_(AUTH_FLOW_OFFLINE), | 45 auth_flow_(AUTH_FLOW_OFFLINE), |
| 44 user_type_(user_type) { | 46 user_type_(user_type) { |
| 45 if (user_type_ == user_manager::USER_TYPE_REGULAR) | 47 if (user_type_ == user_manager::USER_TYPE_REGULAR) |
| 46 user_id_ = login::CanonicalizeUserID(user_id); | 48 user_id_ = AccountId::FromUserEmail(login::CanonicalizeUserID(user_id)); |
| 47 else | 49 else |
| 48 user_id_ = user_id; | 50 user_id_ = AccountId::FromUserEmail(user_id); |
| 49 } | 51 } |
| 50 | 52 |
| 51 UserContext::~UserContext() { | 53 UserContext::~UserContext() { |
| 52 } | 54 } |
| 53 | 55 |
| 54 bool UserContext::operator==(const UserContext& context) const { | 56 bool UserContext::operator==(const UserContext& context) const { |
| 55 return context.user_id_ == user_id_ && context.gaia_id_ == gaia_id_ && | 57 return context.user_id_ == user_id_ && context.gaia_id_ == gaia_id_ && |
| 56 context.key_ == key_ && context.auth_code_ == auth_code_ && | 58 context.key_ == key_ && context.auth_code_ == auth_code_ && |
| 57 context.refresh_token_ == refresh_token_ && | 59 context.refresh_token_ == refresh_token_ && |
| 58 context.access_token_ == access_token_ && | 60 context.access_token_ == access_token_ && |
| 59 context.user_id_hash_ == user_id_hash_ && | 61 context.user_id_hash_ == user_id_hash_ && |
| 60 context.is_using_oauth_ == is_using_oauth_ && | 62 context.is_using_oauth_ == is_using_oauth_ && |
| 61 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_ && | 63 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_ && |
| 62 context.public_session_locale_ == public_session_locale_ && | 64 context.public_session_locale_ == public_session_locale_ && |
| 63 context.public_session_input_method_ == public_session_input_method_; | 65 context.public_session_input_method_ == public_session_input_method_; |
| 64 } | 66 } |
| 65 | 67 |
| 66 bool UserContext::operator!=(const UserContext& context) const { | 68 bool UserContext::operator!=(const UserContext& context) const { |
| 67 return !(*this == context); | 69 return !(*this == context); |
| 68 } | 70 } |
| 69 | 71 |
| 70 const std::string& UserContext::GetUserID() const { | 72 const AccountId& UserContext::GetUserID() const { |
| 71 return user_id_; | 73 return user_id_; |
| 72 } | 74 } |
| 73 | 75 |
| 74 const std::string& UserContext::GetGaiaID() const { | 76 const std::string& UserContext::GetGaiaID() const { |
| 75 return gaia_id_; | 77 return gaia_id_; |
| 76 } | 78 } |
| 77 | 79 |
| 78 const Key* UserContext::GetKey() const { | 80 const Key* UserContext::GetKey() const { |
| 79 return &key_; | 81 return &key_; |
| 80 } | 82 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 const std::string& UserContext::GetGAPSCookie() const { | 128 const std::string& UserContext::GetGAPSCookie() const { |
| 127 return gaps_cookie_; | 129 return gaps_cookie_; |
| 128 } | 130 } |
| 129 | 131 |
| 130 bool UserContext::HasCredentials() const { | 132 bool UserContext::HasCredentials() const { |
| 131 return (!user_id_.empty() && !key_.GetSecret().empty()) || | 133 return (!user_id_.empty() && !key_.GetSecret().empty()) || |
| 132 !auth_code_.empty(); | 134 !auth_code_.empty(); |
| 133 } | 135 } |
| 134 | 136 |
| 135 void UserContext::SetUserID(const std::string& user_id) { | 137 void UserContext::SetUserID(const std::string& user_id) { |
| 136 user_id_ = login::CanonicalizeUserID(user_id); | 138 user_id_ = AccountId::FromUserEmail(login::CanonicalizeUserID(user_id)); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void UserContext::SetGaiaID(const std::string& gaia_id) { | 141 void UserContext::SetGaiaID(const std::string& gaia_id) { |
| 140 gaia_id_ = gaia_id; | 142 gaia_id_ = gaia_id; |
| 141 } | 143 } |
| 142 | 144 |
| 143 void UserContext::SetKey(const Key& key) { | 145 void UserContext::SetKey(const Key& key) { |
| 144 key_ = key; | 146 key_ = key; |
| 145 } | 147 } |
| 146 | 148 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 gaps_cookie_ = gaps_cookie; | 190 gaps_cookie_ = gaps_cookie; |
| 189 } | 191 } |
| 190 | 192 |
| 191 void UserContext::ClearSecrets() { | 193 void UserContext::ClearSecrets() { |
| 192 key_.ClearSecret(); | 194 key_.ClearSecret(); |
| 193 auth_code_.clear(); | 195 auth_code_.clear(); |
| 194 refresh_token_.clear(); | 196 refresh_token_.clear(); |
| 195 } | 197 } |
| 196 | 198 |
| 197 } // namespace chromeos | 199 } // namespace chromeos |
| OLD | NEW |