Move action_runner.py out of actions folder prior to moving actions to internal.
[chromium-blink-merge.git] / chromeos / login / auth / user_context.cc
blobff21fa64dd8ca2edd577afdb5a33d873345ed21d
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 user_id_hash_(other.user_id_hash_),
23 is_using_oauth_(other.is_using_oauth_),
24 auth_flow_(other.auth_flow_),
25 user_type_(other.user_type_),
26 public_session_locale_(other.public_session_locale_),
27 public_session_input_method_(other.public_session_input_method_) {
30 UserContext::UserContext(const std::string& user_id)
31 : user_id_(login::CanonicalizeUserID(user_id)),
32 is_using_oauth_(true),
33 auth_flow_(AUTH_FLOW_OFFLINE),
34 user_type_(user_manager::USER_TYPE_REGULAR) {
37 UserContext::UserContext(user_manager::UserType user_type,
38 const std::string& user_id)
39 : is_using_oauth_(true),
40 auth_flow_(AUTH_FLOW_OFFLINE),
41 user_type_(user_type) {
42 if (user_type_ == user_manager::USER_TYPE_REGULAR)
43 user_id_ = login::CanonicalizeUserID(user_id);
44 else
45 user_id_ = user_id;
48 UserContext::~UserContext() {
51 bool UserContext::operator==(const UserContext& context) const {
52 return context.user_id_ == user_id_ &&
53 context.gaia_id_ == gaia_id_ &&
54 context.key_ == key_ &&
55 context.auth_code_ == auth_code_ &&
56 context.user_id_hash_ == user_id_hash_ &&
57 context.is_using_oauth_ == is_using_oauth_ &&
58 context.auth_flow_ == auth_flow_ &&
59 context.user_type_ == user_type_ &&
60 context.public_session_locale_ == public_session_locale_ &&
61 context.public_session_input_method_ == public_session_input_method_;
64 bool UserContext::operator!=(const UserContext& context) const {
65 return !(*this == context);
68 const std::string& UserContext::GetUserID() const {
69 return user_id_;
72 const std::string& UserContext::GetGaiaID() const {
73 return gaia_id_;
76 const Key* UserContext::GetKey() const {
77 return &key_;
80 Key* UserContext::GetKey() {
81 return &key_;
84 const std::string& UserContext::GetAuthCode() const {
85 return auth_code_;
88 const std::string& UserContext::GetRefreshToken() const {
89 return refresh_token_;
92 const std::string& UserContext::GetUserIDHash() const {
93 return user_id_hash_;
96 bool UserContext::IsUsingOAuth() const {
97 return is_using_oauth_;
100 UserContext::AuthFlow UserContext::GetAuthFlow() const {
101 return auth_flow_;
104 user_manager::UserType UserContext::GetUserType() const {
105 return user_type_;
108 const std::string& UserContext::GetPublicSessionLocale() const {
109 return public_session_locale_;
112 const std::string& UserContext::GetPublicSessionInputMethod() const {
113 return public_session_input_method_;
116 bool UserContext::HasCredentials() const {
117 return (!user_id_.empty() && !key_.GetSecret().empty()) ||
118 !auth_code_.empty();
121 void UserContext::SetUserID(const std::string& user_id) {
122 user_id_ = login::CanonicalizeUserID(user_id);
125 void UserContext::SetGaiaID(const std::string& gaia_id) {
126 gaia_id_ = gaia_id;
129 void UserContext::SetKey(const Key& key) {
130 key_ = key;
133 void UserContext::SetAuthCode(const std::string& auth_code) {
134 auth_code_ = auth_code;
137 void UserContext::SetRefreshToken(const std::string& refresh_token) {
138 refresh_token_ = refresh_token;
141 void UserContext::SetUserIDHash(const std::string& user_id_hash) {
142 user_id_hash_ = user_id_hash;
145 void UserContext::SetIsUsingOAuth(bool is_using_oauth) {
146 is_using_oauth_ = is_using_oauth;
149 void UserContext::SetAuthFlow(AuthFlow auth_flow) {
150 auth_flow_ = auth_flow;
153 void UserContext::SetUserType(user_manager::UserType user_type) {
154 user_type_ = user_type;
157 void UserContext::SetPublicSessionLocale(const std::string& locale) {
158 public_session_locale_ = locale;
161 void UserContext::SetPublicSessionInputMethod(const std::string& input_method) {
162 public_session_input_method_ = input_method;
165 void UserContext::ClearSecrets() {
166 key_.ClearSecret();
167 auth_code_.clear();
168 refresh_token_.clear();
171 } // namespace chromeos