• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "chrome/browser/chromeos/login/auth/user_context.h"
6 
7 #include "chrome/browser/chromeos/login/helper.h"
8 #include "chrome/browser/chromeos/login/users/user_manager.h"
9 
10 namespace chromeos {
11 
UserContext()12 UserContext::UserContext() : is_using_oauth_(true),
13                              auth_flow_(AUTH_FLOW_OFFLINE) {
14 }
15 
UserContext(const UserContext & other)16 UserContext::UserContext(const UserContext& other)
17     : user_id_(other.user_id_),
18       key_(other.key_),
19       auth_code_(other.auth_code_),
20       user_id_hash_(other.user_id_hash_),
21       is_using_oauth_(other.is_using_oauth_),
22       auth_flow_(other.auth_flow_) {
23 }
24 
UserContext(const std::string & user_id)25 UserContext::UserContext(const std::string& user_id)
26     : user_id_(login::CanonicalizeUserID(user_id)),
27       is_using_oauth_(true),
28       auth_flow_(AUTH_FLOW_OFFLINE) {
29 }
30 
~UserContext()31 UserContext::~UserContext() {
32 }
33 
operator ==(const UserContext & context) const34 bool UserContext::operator==(const UserContext& context) const {
35   return context.user_id_ == user_id_ &&
36          context.key_ == key_ &&
37          context.auth_code_ == auth_code_ &&
38          context.user_id_hash_ == user_id_hash_ &&
39          context.is_using_oauth_ == is_using_oauth_ &&
40          context.auth_flow_ == auth_flow_;
41 }
42 
operator !=(const UserContext & context) const43 bool UserContext::operator!=(const UserContext& context) const {
44   return !(*this == context);
45 }
46 
GetUserID() const47 const std::string& UserContext::GetUserID() const {
48   return user_id_;
49 }
50 
GetKey() const51 const Key* UserContext::GetKey() const {
52   return &key_;
53 }
54 
GetKey()55 Key* UserContext::GetKey() {
56   return &key_;
57 }
58 
GetAuthCode() const59 const std::string& UserContext::GetAuthCode() const {
60   return auth_code_;
61 }
62 
GetUserIDHash() const63 const std::string& UserContext::GetUserIDHash() const {
64   return user_id_hash_;
65 }
66 
IsUsingOAuth() const67 bool UserContext::IsUsingOAuth() const {
68   return is_using_oauth_;
69 }
70 
GetAuthFlow() const71 UserContext::AuthFlow UserContext::GetAuthFlow() const {
72   return auth_flow_;
73 }
74 
HasCredentials() const75 bool UserContext::HasCredentials() const {
76   return (!user_id_.empty() && !key_.GetSecret().empty()) ||
77          !auth_code_.empty();
78 }
79 
SetUserID(const std::string & user_id)80 void UserContext::SetUserID(const std::string& user_id) {
81   user_id_ = login::CanonicalizeUserID(user_id);
82 }
83 
SetKey(const Key & key)84 void UserContext::SetKey(const Key& key) {
85   key_ = key;
86 }
87 
SetAuthCode(const std::string & auth_code)88 void UserContext::SetAuthCode(const std::string& auth_code) {
89   auth_code_ = auth_code;
90 }
91 
SetUserIDHash(const std::string & user_id_hash)92 void UserContext::SetUserIDHash(const std::string& user_id_hash) {
93   user_id_hash_ = user_id_hash;
94 }
95 
SetIsUsingOAuth(bool is_using_oauth)96 void UserContext::SetIsUsingOAuth(bool is_using_oauth) {
97   is_using_oauth_ = is_using_oauth;
98 }
99 
SetAuthFlow(AuthFlow auth_flow)100 void UserContext::SetAuthFlow(AuthFlow auth_flow) {
101   auth_flow_ = auth_flow;
102 }
103 
ClearSecrets()104 void UserContext::ClearSecrets() {
105   key_.ClearSecret();
106   auth_code_.clear();
107 }
108 
109 }  // namespace chromeos
110