summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 22:07:50 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 22:07:50 +0000
commit3f82664f2b89927ff83883aa9a79f56fdf409ebe (patch)
treeaeb5a39dbf86e118841a2534517e8458b9767a19 /chromeos
parent07033bf42472bf19a7e246d5280f9229b84f7799 (diff)
downloadchromium_src-3f82664f2b89927ff83883aa9a79f56fdf409ebe.zip
chromium_src-3f82664f2b89927ff83883aa9a79f56fdf409ebe.tar.gz
chromium_src-3f82664f2b89927ff83883aa9a79f56fdf409ebe.tar.bz2
Disable some API calls in networkingPrivate for non-primary user
We will disable createNetwork, and getManagedProperties if this is called from the non-primary user because these methods currently require a user id hash. This does not address other methods (e.g. setProperties) which should probably also take a user id hash and enforce policy based on it. BUG=364922 R=pneubeck@chromium.org Review URL: https://codereview.chromium.org/242983004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277103 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/login/login_state.cc10
-rw-r--r--chromeos/login/login_state.h16
-rw-r--r--chromeos/login/login_state_unittest.cc26
3 files changed, 50 insertions, 2 deletions
diff --git a/chromeos/login/login_state.cc b/chromeos/login/login_state.cc
index d911548..8fb55f6 100644
--- a/chromeos/login/login_state.cc
+++ b/chromeos/login/login_state.cc
@@ -57,6 +57,16 @@ void LoginState::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
+void LoginState::SetLoggedInStateAndPrimaryUser(
+ LoggedInState state,
+ LoggedInUserType type,
+ const std::string& primary_user_hash) {
+ DCHECK(type != LOGGED_IN_USER_NONE);
+ primary_user_hash_ = primary_user_hash;
+ VLOG(1) << "LoggedInStateUser: " << primary_user_hash;
+ SetLoggedInState(state, type);
+}
+
void LoginState::SetLoggedInState(LoggedInState state,
LoggedInUserType type) {
if (state == logged_in_state_ && type == logged_in_user_type_)
diff --git a/chromeos/login/login_state.h b/chromeos/login/login_state.h
index 246bab9..f0ba4ba 100644
--- a/chromeos/login/login_state.h
+++ b/chromeos/login/login_state.h
@@ -51,10 +51,19 @@ class CHROMEOS_EXPORT LoginState {
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
- // Set the logged in state and user type.
+ // Sets the logged in state, user type, and primary user hash when the
+ // primary user initialy logs in. Also notifies observers.
+ void SetLoggedInStateAndPrimaryUser(
+ LoggedInState state,
+ LoggedInUserType type,
+ const std::string& primary_user_hash);
+
+ // Sets the logged in state and user type. Also notifies observers. Used
+ // in tests or situations where there is no primary user (e.g. from the
+ // login screen).
void SetLoggedInState(LoggedInState state, LoggedInUserType type);
- // Get the logged in user type.
+ // Gets the logged in user type.
LoggedInUserType GetLoggedInUserType() const;
// Returns true if a user is considered to be logged in.
@@ -84,6 +93,8 @@ class CHROMEOS_EXPORT LoginState {
always_logged_in_ = always_logged_in;
}
+ const std::string& primary_user_hash() const { return primary_user_hash_; }
+
private:
LoginState();
virtual ~LoginState();
@@ -92,6 +103,7 @@ class CHROMEOS_EXPORT LoginState {
LoggedInState logged_in_state_;
LoggedInUserType logged_in_user_type_;
+ std::string primary_user_hash_;
ObserverList<Observer> observer_list_;
// If true, it always thinks the current status as logged in. Set to true by
diff --git a/chromeos/login/login_state_unittest.cc b/chromeos/login/login_state_unittest.cc
index 431b419..50dfdb6 100644
--- a/chromeos/login/login_state_unittest.cc
+++ b/chromeos/login/login_state_unittest.cc
@@ -9,6 +9,10 @@
#include "chromeos/chromeos_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+const char kTestUserHash[] = "testuserhash";
+} // namespace
+
namespace chromeos {
class LoginStateTest : public testing::Test,
@@ -124,4 +128,26 @@ TEST_F(LoginStateTest, TestLoggedInStateChangedObserverOnUserTypeChange) {
LoginState::Get()->GetLoggedInUserType());
}
+TEST_F(LoginStateTest, TestPrimaryUser) {
+ EXPECT_FALSE(LoginState::Get()->IsUserLoggedIn());
+ EXPECT_FALSE(LoginState::Get()->IsInSafeMode());
+ EXPECT_EQ(LoginState::LOGGED_IN_USER_NONE, logged_in_user_type_);
+ EXPECT_EQ(LoginState::LOGGED_IN_USER_NONE,
+ LoginState::Get()->GetLoggedInUserType());
+
+ // Setting login state to ACTIVE and setting the primary user.
+ LoginState::Get()->SetLoggedInStateAndPrimaryUser(
+ LoginState::LOGGED_IN_ACTIVE,
+ LoginState::LOGGED_IN_USER_REGULAR,
+ kTestUserHash);
+ EXPECT_EQ(LoginState::LOGGED_IN_USER_REGULAR,
+ LoginState::Get()->GetLoggedInUserType());
+ EXPECT_TRUE(LoginState::Get()->IsUserLoggedIn());
+ EXPECT_FALSE(LoginState::Get()->IsInSafeMode());
+ EXPECT_EQ(kTestUserHash, LoginState::Get()->primary_user_hash());
+
+ EXPECT_EQ(1U, GetNewLoginStateChangesCount());
+ EXPECT_EQ(LoginState::LOGGED_IN_USER_REGULAR, logged_in_user_type_);
+}
+
} // namespace chromeos