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 "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_GUEST || | |
| 40 user_type_ == User::USER_TYPE_RETAIL_MODE || | |
| 41 user_type_ == User::USER_TYPE_KIOSK_APP) { | |
|
Nikita (slow)
2014/06/11 14:05:14
nit: I think SUPERVISED user should be here as wel
| |
| 42 user_id_ = user_id; | |
| 43 } else { | |
| 44 user_id_ = login::CanonicalizeUserID(user_id); | |
| 45 } | |
| 29 } | 46 } |
| 30 | 47 |
| 31 UserContext::~UserContext() { | 48 UserContext::~UserContext() { |
| 32 } | 49 } |
| 33 | 50 |
| 34 bool UserContext::operator==(const UserContext& context) const { | 51 bool UserContext::operator==(const UserContext& context) const { |
| 35 return context.user_id_ == user_id_ && | 52 return context.user_id_ == user_id_ && context.key_ == key_ && |
| 36 context.key_ == key_ && | |
| 37 context.auth_code_ == auth_code_ && | 53 context.auth_code_ == auth_code_ && |
| 38 context.user_id_hash_ == user_id_hash_ && | 54 context.user_id_hash_ == user_id_hash_ && |
| 39 context.is_using_oauth_ == is_using_oauth_ && | 55 context.is_using_oauth_ == is_using_oauth_ && |
| 40 context.auth_flow_ == auth_flow_; | 56 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_; |
| 41 } | 57 } |
| 42 | 58 |
| 43 bool UserContext::operator!=(const UserContext& context) const { | 59 bool UserContext::operator!=(const UserContext& context) const { |
| 44 return !(*this == context); | 60 return !(*this == context); |
| 45 } | 61 } |
| 46 | 62 |
| 47 const std::string& UserContext::GetUserID() const { | 63 const std::string& UserContext::GetUserID() const { |
| 48 return user_id_; | 64 return user_id_; |
| 49 } | 65 } |
| 50 | 66 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 65 } | 81 } |
| 66 | 82 |
| 67 bool UserContext::IsUsingOAuth() const { | 83 bool UserContext::IsUsingOAuth() const { |
| 68 return is_using_oauth_; | 84 return is_using_oauth_; |
| 69 } | 85 } |
| 70 | 86 |
| 71 UserContext::AuthFlow UserContext::GetAuthFlow() const { | 87 UserContext::AuthFlow UserContext::GetAuthFlow() const { |
| 72 return auth_flow_; | 88 return auth_flow_; |
| 73 } | 89 } |
| 74 | 90 |
| 91 User::UserType UserContext::GetUserType() const { | |
| 92 return user_type_; | |
| 93 } | |
| 94 | |
| 75 bool UserContext::HasCredentials() const { | 95 bool UserContext::HasCredentials() const { |
| 76 return (!user_id_.empty() && !key_.GetSecret().empty()) || | 96 return (!user_id_.empty() && !key_.GetSecret().empty()) || |
| 77 !auth_code_.empty(); | 97 !auth_code_.empty(); |
| 78 } | 98 } |
| 79 | 99 |
| 80 void UserContext::SetUserID(const std::string& user_id) { | 100 void UserContext::SetUserID(const std::string& user_id) { |
| 81 user_id_ = login::CanonicalizeUserID(user_id); | 101 user_id_ = login::CanonicalizeUserID(user_id); |
| 82 } | 102 } |
| 83 | 103 |
| 84 void UserContext::SetKey(const Key& key) { | 104 void UserContext::SetKey(const Key& key) { |
| 85 key_ = key; | 105 key_ = key; |
| 86 } | 106 } |
| 87 | 107 |
| 88 void UserContext::SetAuthCode(const std::string& auth_code) { | 108 void UserContext::SetAuthCode(const std::string& auth_code) { |
| 89 auth_code_ = auth_code; | 109 auth_code_ = auth_code; |
| 90 } | 110 } |
| 91 | 111 |
| 92 void UserContext::SetUserIDHash(const std::string& user_id_hash) { | 112 void UserContext::SetUserIDHash(const std::string& user_id_hash) { |
| 93 user_id_hash_ = user_id_hash; | 113 user_id_hash_ = user_id_hash; |
| 94 } | 114 } |
| 95 | 115 |
| 96 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { | 116 void UserContext::SetIsUsingOAuth(bool is_using_oauth) { |
| 97 is_using_oauth_ = is_using_oauth; | 117 is_using_oauth_ = is_using_oauth; |
| 98 } | 118 } |
| 99 | 119 |
| 100 void UserContext::SetAuthFlow(AuthFlow auth_flow) { | 120 void UserContext::SetAuthFlow(AuthFlow auth_flow) { |
| 101 auth_flow_ = auth_flow; | 121 auth_flow_ = auth_flow; |
| 102 } | 122 } |
| 103 | 123 |
| 124 void UserContext::SetUserType(User::UserType user_type) { | |
| 125 user_type_ = user_type; | |
| 126 } | |
| 127 | |
| 104 void UserContext::ClearSecrets() { | 128 void UserContext::ClearSecrets() { |
| 105 key_.ClearSecret(); | 129 key_.ClearSecret(); |
| 106 auth_code_.clear(); | 130 auth_code_.clear(); |
| 107 } | 131 } |
| 108 | 132 |
| 109 } // namespace chromeos | 133 } // namespace chromeos |
| OLD | NEW |