OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/login/login_state.h" | 5 #include "chromeos/login/login_state.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
10 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 void LoginState::SetLoggedInStateAndPrimaryUser( | 60 void LoginState::SetLoggedInStateAndPrimaryUser( |
61 LoggedInState state, | 61 LoggedInState state, |
62 LoggedInUserType type, | 62 LoggedInUserType type, |
63 const std::string& primary_user_hash) { | 63 const std::string& primary_user_hash) { |
64 DCHECK(type != LOGGED_IN_USER_NONE); | 64 DCHECK(type != LOGGED_IN_USER_NONE); |
65 primary_user_hash_ = primary_user_hash; | 65 primary_user_hash_ = primary_user_hash; |
66 VLOG(1) << "LoggedInStateUser: " << primary_user_hash; | 66 VLOG(1) << "LoggedInStateUser: " << primary_user_hash; |
67 SetLoggedInState(state, type); | 67 SetLoggedInState(state, type); |
68 } | 68 } |
69 | 69 |
70 void LoginState::SetLoggedInState(LoggedInState state, | 70 void LoginState::SetLoggedInState(LoggedInState state, LoggedInUserType type) { |
71 LoggedInUserType type) { | 71 CHECK_NE(LOGGED_IN_USER_RETAIL_MODE, type); |
72 if (state == logged_in_state_ && type == logged_in_user_type_) | 72 if (state == logged_in_state_ && type == logged_in_user_type_) |
73 return; | 73 return; |
74 VLOG(1) << "LoggedInState: " << state << " UserType: " << type; | 74 VLOG(1) << "LoggedInState: " << state << " UserType: " << type; |
75 logged_in_state_ = state; | 75 logged_in_state_ = state; |
76 logged_in_user_type_ = type; | 76 logged_in_user_type_ = type; |
77 NotifyObservers(); | 77 NotifyObservers(); |
78 } | 78 } |
79 | 79 |
80 LoginState::LoggedInUserType LoginState::GetLoggedInUserType() const { | 80 LoginState::LoggedInUserType LoginState::GetLoggedInUserType() const { |
81 return logged_in_user_type_; | 81 return logged_in_user_type_; |
82 } | 82 } |
83 | 83 |
84 bool LoginState::IsUserLoggedIn() const { | 84 bool LoginState::IsUserLoggedIn() const { |
85 if (always_logged_in_) | 85 if (always_logged_in_) |
86 return true; | 86 return true; |
87 return logged_in_state_ == LOGGED_IN_ACTIVE; | 87 return logged_in_state_ == LOGGED_IN_ACTIVE; |
88 } | 88 } |
89 | 89 |
90 bool LoginState::IsInSafeMode() const { | 90 bool LoginState::IsInSafeMode() const { |
91 DCHECK(!always_logged_in_ || logged_in_state_ != LOGGED_IN_SAFE_MODE); | 91 DCHECK(!always_logged_in_ || logged_in_state_ != LOGGED_IN_SAFE_MODE); |
92 return logged_in_state_ == LOGGED_IN_SAFE_MODE; | 92 return logged_in_state_ == LOGGED_IN_SAFE_MODE; |
93 } | 93 } |
94 | 94 |
95 bool LoginState::IsGuestUser() const { | 95 bool LoginState::IsGuestSessionUser() const { |
96 if (!IsUserLoggedIn()) | 96 return logged_in_user_type_ == LOGGED_IN_USER_GUEST; |
97 return false; | 97 } |
98 switch (logged_in_user_type_) { | 98 |
99 case LOGGED_IN_USER_NONE: | 99 bool LoginState::IsPublicSessionUser() const { |
100 case LOGGED_IN_USER_REGULAR: | 100 return logged_in_user_type_ == LOGGED_IN_USER_PUBLIC_ACCOUNT; |
101 case LOGGED_IN_USER_OWNER: | |
102 case LOGGED_IN_USER_SUPERVISED: | |
103 case LOGGED_IN_USER_KIOSK_APP: | |
104 return false; | |
105 case LOGGED_IN_USER_GUEST: | |
106 case LOGGED_IN_USER_RETAIL_MODE: | |
107 case LOGGED_IN_USER_PUBLIC_ACCOUNT: | |
108 return true; | |
109 } | |
110 NOTREACHED(); | |
111 return false; | |
112 } | 101 } |
113 | 102 |
114 bool LoginState::IsKioskApp() const { | 103 bool LoginState::IsKioskApp() const { |
115 return logged_in_user_type_ == LoginState::LOGGED_IN_USER_KIOSK_APP; | 104 return logged_in_user_type_ == LOGGED_IN_USER_KIOSK_APP; |
116 } | 105 } |
117 | 106 |
118 bool LoginState::UserHasNetworkProfile() const { | 107 bool LoginState::UserHasNetworkProfile() const { |
119 if (!IsUserLoggedIn()) | 108 if (!IsUserLoggedIn()) |
120 return false; | 109 return false; |
121 return logged_in_user_type_ != LOGGED_IN_USER_RETAIL_MODE && | 110 return logged_in_user_type_ != LOGGED_IN_USER_PUBLIC_ACCOUNT; |
122 logged_in_user_type_ != LOGGED_IN_USER_PUBLIC_ACCOUNT; | |
123 } | 111 } |
124 | 112 |
125 bool LoginState::IsUserAuthenticated() const { | 113 bool LoginState::IsUserAuthenticated() const { |
126 return logged_in_user_type_ == LOGGED_IN_USER_REGULAR || | 114 return logged_in_user_type_ == LOGGED_IN_USER_REGULAR || |
127 logged_in_user_type_ == LOGGED_IN_USER_OWNER || | 115 logged_in_user_type_ == LOGGED_IN_USER_OWNER || |
128 logged_in_user_type_ == LOGGED_IN_USER_SUPERVISED; | 116 logged_in_user_type_ == LOGGED_IN_USER_SUPERVISED; |
129 } | 117 } |
130 | 118 |
131 bool LoginState::IsUserGaiaAuthenticated() const { | 119 bool LoginState::IsUserGaiaAuthenticated() const { |
132 return logged_in_user_type_ == LOGGED_IN_USER_REGULAR || | 120 return logged_in_user_type_ == LOGGED_IN_USER_REGULAR || |
133 logged_in_user_type_ == LOGGED_IN_USER_OWNER; | 121 logged_in_user_type_ == LOGGED_IN_USER_OWNER; |
134 } | 122 } |
135 | 123 |
136 // Private methods | 124 // Private methods |
137 | 125 |
138 LoginState::LoginState() : logged_in_state_(LOGGED_IN_NONE), | 126 LoginState::LoginState() : logged_in_state_(LOGGED_IN_NONE), |
139 logged_in_user_type_(LOGGED_IN_USER_NONE), | 127 logged_in_user_type_(LOGGED_IN_USER_NONE), |
140 always_logged_in_(AlwaysLoggedInByDefault()) { | 128 always_logged_in_(AlwaysLoggedInByDefault()) { |
141 } | 129 } |
142 | 130 |
143 LoginState::~LoginState() { | 131 LoginState::~LoginState() { |
144 } | 132 } |
145 | 133 |
146 void LoginState::NotifyObservers() { | 134 void LoginState::NotifyObservers() { |
147 FOR_EACH_OBSERVER(LoginState::Observer, observer_list_, | 135 FOR_EACH_OBSERVER(LoginState::Observer, observer_list_, |
148 LoggedInStateChanged()); | 136 LoggedInStateChanged()); |
149 } | 137 } |
150 | 138 |
151 } // namespace chromeos | 139 } // namespace chromeos |
OLD | NEW |