Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chromeos / login / auth / user_context.cc
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.
4
5 #include "chromeos/login/auth/user_context.h"
6 #include "chromeos/login/user_names.h"
7
8 namespace chromeos {
9
10 UserContext::UserContext()
11     : is_using_oauth_(true),
12       auth_flow_(AUTH_FLOW_OFFLINE),
13       user_type_(user_manager::USER_TYPE_REGULAR) {
14 }
15
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_) {
27 }
28
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) {
34 }
35
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;
45 }
46
47 UserContext::~UserContext() {
48 }
49
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_;
61 }
62
63 bool UserContext::operator!=(const UserContext& context) const {
64   return !(*this == context);
65 }
66
67 const std::string& UserContext::GetUserID() const {
68   return user_id_;
69 }
70
71 const std::string& UserContext::GetGaiaID() const {
72   return gaia_id_;
73 }
74
75 const Key* UserContext::GetKey() const {
76   return &key_;
77 }
78
79 Key* UserContext::GetKey() {
80   return &key_;
81 }
82
83 const std::string& UserContext::GetAuthCode() const {
84   return auth_code_;
85 }
86
87 const std::string& UserContext::GetUserIDHash() const {
88   return user_id_hash_;
89 }
90
91 bool UserContext::IsUsingOAuth() const {
92   return is_using_oauth_;
93 }
94
95 UserContext::AuthFlow UserContext::GetAuthFlow() const {
96   return auth_flow_;
97 }
98
99 user_manager::UserType UserContext::GetUserType() const {
100   return user_type_;
101 }
102
103 const std::string& UserContext::GetPublicSessionLocale() const {
104   return public_session_locale_;
105 }
106
107 const std::string& UserContext::GetPublicSessionInputMethod() const {
108   return public_session_input_method_;
109 }
110
111 bool UserContext::HasCredentials() const {
112   return (!user_id_.empty() && !key_.GetSecret().empty()) ||
113          !auth_code_.empty();
114 }
115
116 void UserContext::SetUserID(const std::string& user_id) {
117   user_id_ = login::CanonicalizeUserID(user_id);
118 }
119
120 void UserContext::SetGaiaID(const std::string& gaia_id) {
121   gaia_id_ = gaia_id;
122 }
123
124 void UserContext::SetKey(const Key& key) {
125   key_ = key;
126 }
127
128 void UserContext::SetAuthCode(const std::string& auth_code) {
129   auth_code_ = auth_code;
130 }
131
132 void UserContext::SetUserIDHash(const std::string& user_id_hash) {
133   user_id_hash_ = user_id_hash;
134 }
135
136 void UserContext::SetIsUsingOAuth(bool is_using_oauth) {
137   is_using_oauth_ = is_using_oauth;
138 }
139
140 void UserContext::SetAuthFlow(AuthFlow auth_flow) {
141   auth_flow_ = auth_flow;
142 }
143
144 void UserContext::SetUserType(user_manager::UserType user_type) {
145   user_type_ = user_type;
146 }
147
148 void UserContext::SetPublicSessionLocale(const std::string& locale) {
149   public_session_locale_ = locale;
150 }
151
152 void UserContext::SetPublicSessionInputMethod(const std::string& input_method) {
153   public_session_input_method_ = input_method;
154 }
155
156 void UserContext::ClearSecrets() {
157   key_.ClearSecret();
158   auth_code_.clear();
159 }
160
161 }  // namespace chromeos