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

Unified Diff: chromeos/login/scoped_test_public_session_login_state.cc

Issue 2856053004: [Refactor] Use ScopedTestPublicSessionLoginState in code (Closed)
Patch Set: Rebase Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/login/scoped_test_public_session_login_state.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/login/scoped_test_public_session_login_state.cc
diff --git a/chromeos/login/scoped_test_public_session_login_state.cc b/chromeos/login/scoped_test_public_session_login_state.cc
index 0067ebcf7a724b30118e79f44946296f093c587c..2e8be46e77d6ce28880ce7fb90941f82cbfee4b9 100644
--- a/chromeos/login/scoped_test_public_session_login_state.cc
+++ b/chromeos/login/scoped_test_public_session_login_state.cc
@@ -8,17 +8,36 @@
namespace chromeos {
+namespace {
+
+bool g_instance_exists = false;
+
+} // namespace
+
ScopedTestPublicSessionLoginState::ScopedTestPublicSessionLoginState() {
+ // Allow only one instance of this class.
+ CHECK(!g_instance_exists);
+ g_instance_exists = true;
+
// Set Public Session state.
- chromeos::LoginState::Initialize();
- chromeos::LoginState::Get()->SetLoggedInState(
- chromeos::LoginState::LOGGED_IN_ACTIVE,
- chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT);
+ if (!LoginState::IsInitialized()) {
+ LoginState::Initialize();
+ needs_shutdown_ = true;
+ }
+ LoginState::Get()->SetLoggedInState(
+ LoginState::LOGGED_IN_ACTIVE,
+ LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT);
}
ScopedTestPublicSessionLoginState::~ScopedTestPublicSessionLoginState() {
// Reset state at the end of test.
- chromeos::LoginState::Shutdown();
+ LoginState::Get()->SetLoggedInState(
+ LoginState::LOGGED_IN_NONE,
+ LoginState::LOGGED_IN_USER_NONE);
+ if (needs_shutdown_)
+ LoginState::Shutdown();
+
+ g_instance_exists = false;
}
} // namespace chromeos
« no previous file with comments | « chromeos/login/scoped_test_public_session_login_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698