Roll src/third_party/skia 726cf90:183b57f
[chromium-blink-merge.git] / chromeos / login / auth / user_context.cc
blobe5b3fe0951949df8a3a14685971a20c757e66721
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
3 // found in the LICENSE file.
5 #include "chromeos/login/auth/user_context.h"
6 #include "chromeos/login/user_names.h"
8 namespace chromeos {
10 UserContext::UserContext()
11 : is_using_oauth_(true),
12 auth_flow_(AUTH_FLOW_OFFLINE),
13 user_type_(user_manager::USER_TYPE_REGULAR) {
16 UserContext::UserContext(const UserContext& other)
17 : user_id_(other.user_id_),
18 gaia_id_(other.gaia_id_),
19 key_(other.key_),
20 auth_code_(other.auth_code_),
21 refresh_token_(other.refresh_token_),
22 access_token_(other.access_token_),
23 user_id_hash_(other.user_id_hash_),
24 is_using_oauth_(other.is_using_oauth_),
25 auth_flow_(other.auth_flow_),
26 user_type_(other.user_type_),
27 public_session_locale_(other.public_session_locale_),
28 public_session_input_method_(other.public_session_input_method_),
29 device_id_(other.device_id_) {
32 UserContext::UserContext(const std::string& user_id)
33 : user_id_(login::CanonicalizeUserID(user_id)),
34 is_using_oauth_(true),
35 auth_flow_(AUTH_FLOW_OFFLINE),
36 user_type_(user_manager::USER_TYPE_REGULAR) {
39 UserContext::UserContext(user_manager::UserType user_type,
40 const std::string& user_id)
41 : is_using_oauth_(true),
42 auth_flow_(AUTH_FLOW_OFFLINE),
43 user_type_(user_type) {
44 if (user_type_ == user_manager::USER_TYPE_REGULAR)
45 user_id_ = login::CanonicalizeUserID(user_id);
46 else
47 user_id_ = user_id;
50 UserContext::~UserContext() {
53 bool UserContext::operator==(const UserContext& context) const {
54 return context.user_id_ == user_id_ && context.gaia_id_ == gaia_id_ &&
55 context.key_ == key_ && context.auth_code_ == auth_code_ &&
56 context.refresh_token_ == refresh_token_ &&
57 context.access_token_ == access_token_ &&
58 context.user_id_hash_ == user_id_hash_ &&
59 context.is_using_oauth_ == is_using_oauth_ &&
60 context.auth_flow_ == auth_flow_ && context.user_type_ == user_type_ &&
61 context.public_session_locale_ == public_session_locale_ &&
62 context.public_session_input_method_ == public_session_input_method_;
65 bool UserContext::operator!=(const UserContext& context) const {
66 return !(*this == context);
69 const std::string& UserContext::GetUserID() const {
70 return user_id_;
73 const std::string& UserContext::GetGaiaID() const {
74 return gaia_id_;
77 const Key* UserContext::GetKey() const {
78 return &key_;
81 Key* UserContext::GetKey() {
82 return &key_;
85 const std::string& UserContext::GetAuthCode() const {
86 return auth_code_;
89 const std::string& UserContext::GetRefreshToken() const {
90 return refresh_token_;
93 const std::string& UserContext::GetAccessToken() const {
94 return access_token_;
97 const std::string& UserContext::GetUserIDHash() const {
98 return user_id_hash_;
101 bool UserContext::IsUsingOAuth() const {
102 return is_using_oauth_;
105 UserContext::AuthFlow UserContext::GetAuthFlow() const {
106 return auth_flow_;
109 user_manager::UserType UserContext::GetUserType() const {
110 return user_type_;
113 const std::string& UserContext::GetPublicSessionLocale() const {
114 return public_session_locale_;
117 const std::string& UserContext::GetPublicSessionInputMethod() const {
118 return public_session_input_method_;
121 const std::string& UserContext::GetDeviceId() const {
122 return device_id_;
125 bool UserContext::HasCredentials() const {
126 return (!user_id_.empty() && !key_.GetSecret().empty()) ||
127 !auth_code_.empty();
130 void UserContext::SetUserID(const std::string& user_id) {
131 user_id_ = login::CanonicalizeUserID(user_id);
134 void UserContext::SetGaiaID(const std::string& gaia_id) {
135 gaia_id_ = gaia_id;
138 void UserContext::SetKey(const Key& key) {
139 key_ = key;
142 void UserContext::SetAuthCode(const std::string& auth_code) {
143 auth_code_ = auth_code;
146 void UserContext::SetRefreshToken(const std::string& refresh_token) {
147 refresh_token_ = refresh_token;
150 void UserContext::SetAccessToken(const std::string& access_token) {
151 access_token_ = access_token;
154 void UserContext::SetUserIDHash(const std::string& user_id_hash) {
155 user_id_hash_ = user_id_hash;
158 void UserContext::SetIsUsingOAuth(bool is_using_oauth) {
159 is_using_oauth_ = is_using_oauth;
162 void UserContext::SetAuthFlow(AuthFlow auth_flow) {
163 auth_flow_ = auth_flow;
166 void UserContext::SetUserType(user_manager::UserType user_type) {
167 user_type_ = user_type;
170 void UserContext::SetPublicSessionLocale(const std::string& locale) {
171 public_session_locale_ = locale;
174 void UserContext::SetPublicSessionInputMethod(const std::string& input_method) {
175 public_session_input_method_ = input_method;
178 void UserContext::SetDeviceId(const std::string& device_id) {
179 device_id_ = device_id;
182 void UserContext::ClearSecrets() {
183 key_.ClearSecret();
184 auth_code_.clear();
185 refresh_token_.clear();
188 } // namespace chromeos