| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/scoped_test_public_session_login_state.h" | 5 #include "chromeos/login/scoped_test_public_session_login_state.h" |
| 6 | 6 |
| 7 #include "chromeos/login/login_state.h" | 7 #include "chromeos/login/login_state.h" |
| 8 | 8 |
| 9 namespace chromeos { | 9 namespace chromeos { |
| 10 | 10 |
| 11 namespace { |
| 12 |
| 13 bool g_instance_exists = false; |
| 14 |
| 15 } // namespace |
| 16 |
| 11 ScopedTestPublicSessionLoginState::ScopedTestPublicSessionLoginState() { | 17 ScopedTestPublicSessionLoginState::ScopedTestPublicSessionLoginState() { |
| 18 // Allow only one instance of this class. |
| 19 CHECK(!g_instance_exists); |
| 20 g_instance_exists = true; |
| 21 |
| 12 // Set Public Session state. | 22 // Set Public Session state. |
| 13 chromeos::LoginState::Initialize(); | 23 if (!LoginState::IsInitialized()) { |
| 14 chromeos::LoginState::Get()->SetLoggedInState( | 24 LoginState::Initialize(); |
| 15 chromeos::LoginState::LOGGED_IN_ACTIVE, | 25 needs_shutdown_ = true; |
| 16 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT); | 26 } |
| 27 LoginState::Get()->SetLoggedInState( |
| 28 LoginState::LOGGED_IN_ACTIVE, |
| 29 LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT); |
| 17 } | 30 } |
| 18 | 31 |
| 19 ScopedTestPublicSessionLoginState::~ScopedTestPublicSessionLoginState() { | 32 ScopedTestPublicSessionLoginState::~ScopedTestPublicSessionLoginState() { |
| 20 // Reset state at the end of test. | 33 // Reset state at the end of test. |
| 21 chromeos::LoginState::Shutdown(); | 34 LoginState::Get()->SetLoggedInState( |
| 35 LoginState::LOGGED_IN_NONE, |
| 36 LoginState::LOGGED_IN_USER_NONE); |
| 37 if (needs_shutdown_) |
| 38 LoginState::Shutdown(); |
| 39 |
| 40 g_instance_exists = false; |
| 22 } | 41 } |
| 23 | 42 |
| 24 } // namespace chromeos | 43 } // namespace chromeos |
| OLD | NEW |