Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: chromeos/login/login_state.cc

Issue 13495003: Add LoginState class to src/chromeos/login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« chromeos/chromeos.gyp ('K') | « chromeos/login/login_state.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromeos/login/login_state.h"
6
7 #include "chromeos/dbus/dbus_thread_manager.h"
8
9 namespace chromeos {
10
11 static LoginState* g_login_state = NULL;
12
13 // static
14 void LoginState::Initialize() {
15 CHECK(!g_login_state);
bartfab (slow) 2013/04/03 08:21:36 #include "base/logging.h"
stevenjb 2013/04/03 17:21:42 Done.
16 g_login_state = new LoginState();
17 }
18
19 // static
20 void LoginState::Shutdown() {
21 CHECK(g_login_state);
22 delete g_login_state;
23 g_login_state = NULL;
24 }
25
26 // static
27 LoginState* LoginState::Get() {
28 CHECK(g_login_state) << "LoginState::Get() called before Initialize()";
29 return g_login_state;
30 }
31
32 void LoginState::AddObserver(Observer* observer) {
33 observer_list_.AddObserver(observer);
34 }
35
36 void LoginState::RemoveObserver(Observer* observer) {
37 observer_list_.RemoveObserver(observer);
38 }
39
40 void LoginState::SetLoginState(LoginState::State state) {
41 if (state == state_)
42 return;
43 VLOG(1) << "Login State: " << state;
44 state_ = state;
45 NotifyObservers();
46 }
47
48 LoginState::State LoginState::GetLoginState() const {
49 if (screen_locked_)
50 return LOGGED_IN_LOCKED;
51 return state_;
52 }
53
54 bool LoginState::IsLoggedIn() {
55 if (state_ == LOGGED_IN_OOBE ||
56 state_ == LOGGED_IN_NONE) {
57 return false;
58 }
59 return true;
60 }
61
62 // Private methods
63
64 LoginState::LoginState() : state_(LOGGED_IN_OOBE),
65 screen_locked_(false) {
66 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
67 }
68
69 LoginState::~LoginState() {
70 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
71 }
72
73 void LoginState::LockScreen() {
74 screen_locked_ = true;
75 NotifyObservers();
76 }
77
78 void LoginState::UnlockScreen() {
79 screen_locked_ = false;
80 NotifyObservers();
81 }
82
83 void LoginState::NotifyObservers() {
84 FOR_EACH_OBSERVER(LoginState::Observer, observer_list_,
85 LoginStateChanged(GetLoginState()));
86 }
87
88 } // namespace chromeos
OLDNEW
« chromeos/chromeos.gyp ('K') | « chromeos/login/login_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698