Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / chromeos / login / auth / user_context.cc
blob4f51b34ef7ceec7bbdf9eabb3549ba85b2293025
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_) {
31 UserContext::UserContext(const std::string& user_id)
32 : user_id_(login::CanonicalizeUserID(user_id)),
33 is_using_oauth_(true),
34 auth_flow_(AUTH_FLOW_OFFLINE),
35 user_type_(user_manager::USER_TYPE_REGULAR) {
38 UserContext::UserContext(user_manager::UserType user_type,
39 const std::string& user_id)
40 : is_using_oauth_(true),
41 auth_flow_(AUTH_FLOW_OFFLINE),
42 user_type_(user_type) {
43 if (user_type_ == user_manager::USER_TYPE_REGULAR)
44 user_id_ = login::CanonicalizeUserID(user_id);
45 else
46 user_id_ = user_id;
49 UserContext::~UserContext() {
52 bool UserContext::operator==(const UserContext& context) const {
53 return context.user_id_ == user_id_ && context.gaia_id_ == gaia_id_ &&
54 context.key_ == key_ && context.auth_code_ == auth_code_ &&
55 context.refresh_token_ == refresh_token_ &&
56 context.access_token_ == access_token_ &&
57 context.user_id_hash_ == user_id_hash_ &&
58 context.is_using_oauth_ == is_using_oauth_ &&
59 context.auth_flow_ == auth_flow_ && 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::GetAccessToken() const {
93 return access_token_;
96 const std::string& UserContext::GetUserIDHash() const {
97 return user_id_hash_;
100 bool UserContext::IsUsingOAuth() const {
101 return is_using_oauth_;
104 UserContext::AuthFlow UserContext::GetAuthFlow() const {
105 return auth_flow_;
108 user_manager::UserType UserContext::GetUserType() const {
109 return user_type_;
112 const std::string& UserContext::GetPublicSessionLocale() const {
113 return public_session_locale_;
116 const std::string& UserContext::GetPublicSessionInputMethod() const {
117 return public_session_input_method_;
120 const std::string& UserContext::GetDeviceId() const {
121 return device_id_;
124 bool UserContext::HasCredentials() const {
125 return (!user_id_.empty() && !key_.GetSecret().empty()) ||
126 !auth_code_.empty();
129 void UserContext::SetUserID(const std::string& user_id) {
130 user_id_ = login::CanonicalizeUserID(user_id);
133 void UserContext::SetGaiaID(const std::string& gaia_id) {
134 gaia_id_ = gaia_id;
137 void UserContext::SetKey(const Key& key) {
138 key_ = key;
141 void UserContext::SetAuthCode(const std::string& auth_code) {
142 auth_code_ = auth_code;
145 void UserContext::SetRefreshToken(const std::string& refresh_token) {
146 refresh_token_ = refresh_token;
149 void UserContext::SetAccessToken(const std::string& access_token) {
150 access_token_ = access_token;
153 void UserContext::SetUserIDHash(const std::string& user_id_hash) {
154 user_id_hash_ = user_id_hash;
157 void UserContext::SetIsUsingOAuth(bool is_using_oauth) {
158 is_using_oauth_ = is_using_oauth;
161 void UserContext::SetAuthFlow(AuthFlow auth_flow) {
162 auth_flow_ = auth_flow;
165 void UserContext::SetUserType(user_manager::UserType user_type) {
166 user_type_ = user_type;
169 void UserContext::SetPublicSessionLocale(const std::string& locale) {
170 public_session_locale_ = locale;
173 void UserContext::SetPublicSessionInputMethod(const std::string& input_method) {
174 public_session_input_method_ = input_method;
177 void UserContext::SetDeviceId(const std::string& device_id) {
178 device_id_ = device_id;
181 void UserContext::ClearSecrets() {
182 key_.ClearSecret();
183 auth_code_.clear();
184 refresh_token_.clear();
187 } // namespace chromeos