Fix initial hiding and centering cursor on ChromeOS
[chromium-blink-merge.git] / chromeos / login / auth / user_context.cc
blobedeb24ea7924345a44656b4f294543c5094580be
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 user_id_hash_(other.user_id_hash_),
22 is_using_oauth_(other.is_using_oauth_),
23 auth_flow_(other.auth_flow_),
24 user_type_(other.user_type_),
25 public_session_locale_(other.public_session_locale_),
26 public_session_input_method_(other.public_session_input_method_) {
29 UserContext::UserContext(const std::string& user_id)
30 : user_id_(login::CanonicalizeUserID(user_id)),
31 is_using_oauth_(true),
32 auth_flow_(AUTH_FLOW_OFFLINE),
33 user_type_(user_manager::USER_TYPE_REGULAR) {
36 UserContext::UserContext(user_manager::UserType user_type,
37 const std::string& user_id)
38 : is_using_oauth_(true),
39 auth_flow_(AUTH_FLOW_OFFLINE),
40 user_type_(user_type) {
41 if (user_type_ == user_manager::USER_TYPE_REGULAR)
42 user_id_ = login::CanonicalizeUserID(user_id);
43 else
44 user_id_ = user_id;
47 UserContext::~UserContext() {
50 bool UserContext::operator==(const UserContext& context) const {
51 return context.user_id_ == user_id_ &&
52 context.gaia_id_ == gaia_id_ &&
53 context.key_ == key_ &&
54 context.auth_code_ == auth_code_ &&
55 context.user_id_hash_ == user_id_hash_ &&
56 context.is_using_oauth_ == is_using_oauth_ &&
57 context.auth_flow_ == auth_flow_ &&
58 context.user_type_ == user_type_ &&
59 context.public_session_locale_ == public_session_locale_ &&
60 context.public_session_input_method_ == public_session_input_method_;
63 bool UserContext::operator!=(const UserContext& context) const {
64 return !(*this == context);
67 const std::string& UserContext::GetUserID() const {
68 return user_id_;
71 const std::string& UserContext::GetGaiaID() const {
72 return gaia_id_;
75 const Key* UserContext::GetKey() const {
76 return &key_;
79 Key* UserContext::GetKey() {
80 return &key_;
83 const std::string& UserContext::GetAuthCode() const {
84 return auth_code_;
87 const std::string& UserContext::GetUserIDHash() const {
88 return user_id_hash_;
91 bool UserContext::IsUsingOAuth() const {
92 return is_using_oauth_;
95 UserContext::AuthFlow UserContext::GetAuthFlow() const {
96 return auth_flow_;
99 user_manager::UserType UserContext::GetUserType() const {
100 return user_type_;
103 const std::string& UserContext::GetPublicSessionLocale() const {
104 return public_session_locale_;
107 const std::string& UserContext::GetPublicSessionInputMethod() const {
108 return public_session_input_method_;
111 bool UserContext::HasCredentials() const {
112 return (!user_id_.empty() && !key_.GetSecret().empty()) ||
113 !auth_code_.empty();
116 void UserContext::SetUserID(const std::string& user_id) {
117 user_id_ = login::CanonicalizeUserID(user_id);
120 void UserContext::SetGaiaID(const std::string& gaia_id) {
121 gaia_id_ = gaia_id;
124 void UserContext::SetKey(const Key& key) {
125 key_ = key;
128 void UserContext::SetAuthCode(const std::string& auth_code) {
129 auth_code_ = auth_code;
132 void UserContext::SetUserIDHash(const std::string& user_id_hash) {
133 user_id_hash_ = user_id_hash;
136 void UserContext::SetIsUsingOAuth(bool is_using_oauth) {
137 is_using_oauth_ = is_using_oauth;
140 void UserContext::SetAuthFlow(AuthFlow auth_flow) {
141 auth_flow_ = auth_flow;
144 void UserContext::SetUserType(user_manager::UserType user_type) {
145 user_type_ = user_type;
148 void UserContext::SetPublicSessionLocale(const std::string& locale) {
149 public_session_locale_ = locale;
152 void UserContext::SetPublicSessionInputMethod(const std::string& input_method) {
153 public_session_input_method_ = input_method;
156 void UserContext::ClearSecrets() {
157 key_.ClearSecret();
158 auth_code_.clear();
161 } // namespace chromeos