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