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() : account_id_(EmptyAccountId()) {} | 10 UserContext::UserContext() |
| 11 : is_using_oauth_(true), |
| 12 auth_flow_(AUTH_FLOW_OFFLINE), |
| 13 user_type_(user_manager::USER_TYPE_REGULAR) { |
| 14 } |
11 | 15 |
12 UserContext::UserContext(const UserContext& other) | 16 UserContext::UserContext(const UserContext& other) |
13 : account_id_(other.account_id_), | 17 : user_id_(other.user_id_), |
14 gaia_id_(other.gaia_id_), | 18 gaia_id_(other.gaia_id_), |
15 key_(other.key_), | 19 key_(other.key_), |
16 auth_code_(other.auth_code_), | 20 auth_code_(other.auth_code_), |
17 refresh_token_(other.refresh_token_), | 21 refresh_token_(other.refresh_token_), |
18 access_token_(other.access_token_), | 22 access_token_(other.access_token_), |
19 user_id_hash_(other.user_id_hash_), | 23 user_id_hash_(other.user_id_hash_), |
20 is_using_oauth_(other.is_using_oauth_), | 24 is_using_oauth_(other.is_using_oauth_), |
21 auth_flow_(other.auth_flow_), | 25 auth_flow_(other.auth_flow_), |
22 user_type_(other.user_type_), | 26 user_type_(other.user_type_), |
23 public_session_locale_(other.public_session_locale_), | 27 public_session_locale_(other.public_session_locale_), |
24 public_session_input_method_(other.public_session_input_method_), | 28 public_session_input_method_(other.public_session_input_method_), |
25 device_id_(other.device_id_), | 29 device_id_(other.device_id_), |
26 gaps_cookie_(other.gaps_cookie_) {} | 30 gaps_cookie_(other.gaps_cookie_) { |
| 31 } |
27 | 32 |
28 UserContext::UserContext(const AccountId& account_id) | 33 UserContext::UserContext(const std::string& user_id) |
29 : account_id_(account_id) { | 34 : user_id_(login::CanonicalizeUserID(user_id)), |
30 account_id_.SetUserEmail( | 35 is_using_oauth_(true), |
31 login::CanonicalizeUserID(account_id.GetUserEmail())); | 36 auth_flow_(AUTH_FLOW_OFFLINE), |
| 37 user_type_(user_manager::USER_TYPE_REGULAR) { |
32 } | 38 } |
33 | 39 |
34 UserContext::UserContext(user_manager::UserType user_type, | 40 UserContext::UserContext(user_manager::UserType user_type, |
35 const std::string& user_id) | 41 const std::string& user_id) |
36 : account_id_(EmptyAccountId()), user_type_(user_type) { | 42 : is_using_oauth_(true), |
| 43 auth_flow_(AUTH_FLOW_OFFLINE), |
| 44 user_type_(user_type) { |
37 if (user_type_ == user_manager::USER_TYPE_REGULAR) | 45 if (user_type_ == user_manager::USER_TYPE_REGULAR) |
38 account_id_ = AccountId::FromUserEmail(login::CanonicalizeUserID(user_id)); | 46 user_id_ = login::CanonicalizeUserID(user_id); |
39 else | 47 else |
40 account_id_ = AccountId::FromUserEmail(user_id); | 48 user_id_ = user_id; |
41 } | 49 } |
42 | 50 |
43 UserContext::~UserContext() { | 51 UserContext::~UserContext() { |
44 } | 52 } |
45 | 53 |
46 bool UserContext::operator==(const UserContext& context) const { | 54 bool UserContext::operator==(const UserContext& context) const { |
47 return context.account_id_ == account_id_ && context.gaia_id_ == gaia_id_ && | 55 return context.user_id_ == user_id_ && context.gaia_id_ == gaia_id_ && |
48 context.key_ == key_ && context.auth_code_ == auth_code_ && | 56 context.key_ == key_ && context.auth_code_ == auth_code_ && |
49 context.refresh_token_ == refresh_token_ && | 57 context.refresh_token_ == refresh_token_ && |
50 context.access_token_ == access_token_ && | 58 context.access_token_ == access_token_ && |
51 context.user_id_hash_ == user_id_hash_ && | 59 context.user_id_hash_ == user_id_hash_ && |
52 context.is_using_oauth_ == is_using_oauth_ && | 60 context.is_using_oauth_ == is_using_oauth_ && |
53 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_ && | 61 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_ && |
54 context.public_session_locale_ == public_session_locale_ && | 62 context.public_session_locale_ == public_session_locale_ && |
55 context.public_session_input_method_ == public_session_input_method_; | 63 context.public_session_input_method_ == public_session_input_method_; |
56 } | 64 } |
57 | 65 |
58 bool UserContext::operator!=(const UserContext& context) const { | 66 bool UserContext::operator!=(const UserContext& context) const { |
59 return !(*this == context); | 67 return !(*this == context); |
60 } | 68 } |
61 | 69 |
62 const AccountId& UserContext::GetAccountId() const { | 70 const std::string& UserContext::GetUserID() const { |
63 return account_id_; | 71 return user_id_; |
64 } | 72 } |
65 | 73 |
66 const std::string& UserContext::GetGaiaID() const { | 74 const std::string& UserContext::GetGaiaID() const { |
67 return gaia_id_; | 75 return gaia_id_; |
68 } | 76 } |
69 | 77 |
70 const Key* UserContext::GetKey() const { | 78 const Key* UserContext::GetKey() const { |
71 return &key_; | 79 return &key_; |
72 } | 80 } |
73 | 81 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 121 |
114 const std::string& UserContext::GetDeviceId() const { | 122 const std::string& UserContext::GetDeviceId() const { |
115 return device_id_; | 123 return device_id_; |
116 } | 124 } |
117 | 125 |
118 const std::string& UserContext::GetGAPSCookie() const { | 126 const std::string& UserContext::GetGAPSCookie() const { |
119 return gaps_cookie_; | 127 return gaps_cookie_; |
120 } | 128 } |
121 | 129 |
122 bool UserContext::HasCredentials() const { | 130 bool UserContext::HasCredentials() const { |
123 return (account_id_.is_valid() && !key_.GetSecret().empty()) || | 131 return (!user_id_.empty() && !key_.GetSecret().empty()) || |
124 !auth_code_.empty(); | 132 !auth_code_.empty(); |
125 } | 133 } |
126 | 134 |
127 void UserContext::SetUserID(const std::string& user_id) { | 135 void UserContext::SetUserID(const std::string& user_id) { |
128 account_id_ = AccountId::FromUserEmail(login::CanonicalizeUserID(user_id)); | 136 user_id_ = login::CanonicalizeUserID(user_id); |
129 } | 137 } |
130 | 138 |
131 void UserContext::SetGaiaID(const std::string& gaia_id) { | 139 void UserContext::SetGaiaID(const std::string& gaia_id) { |
132 gaia_id_ = gaia_id; | 140 gaia_id_ = gaia_id; |
133 } | 141 } |
134 | 142 |
135 void UserContext::SetKey(const Key& key) { | 143 void UserContext::SetKey(const Key& key) { |
136 key_ = key; | 144 key_ = key; |
137 } | 145 } |
138 | 146 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 gaps_cookie_ = gaps_cookie; | 188 gaps_cookie_ = gaps_cookie; |
181 } | 189 } |
182 | 190 |
183 void UserContext::ClearSecrets() { | 191 void UserContext::ClearSecrets() { |
184 key_.ClearSecret(); | 192 key_.ClearSecret(); |
185 auth_code_.clear(); | 193 auth_code_.clear(); |
186 refresh_token_.clear(); | 194 refresh_token_.clear(); |
187 } | 195 } |
188 | 196 |
189 } // namespace chromeos | 197 } // namespace chromeos |
OLD | NEW |