summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraltimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-20 08:42:22 +0000
committeraltimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-20 08:42:22 +0000
commitc4fcdca3cfec4ca060d29d10cdc06dc83aed1bf2 (patch)
tree2ddf1952e1e89ac5f0b1ee753e278238aff01805
parentf037221bfecf15eba8fc3353f2bb87f795db3ade (diff)
downloadchromium_src-c4fcdca3cfec4ca060d29d10cdc06dc83aed1bf2.zip
chromium_src-c4fcdca3cfec4ca060d29d10cdc06dc83aed1bf2.tar.gz
chromium_src-c4fcdca3cfec4ca060d29d10cdc06dc83aed1bf2.tar.bz2
Disallow owner user removing.
BUG=chromium-os:7448 TEST=No remove button for the user who is owner of the device (on login screen). Review URL: http://codereview.chromium.org/3684002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63190 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros_settings_names.cc2
-rw-r--r--chrome/browser/chromeos/cros_settings_names.h2
-rw-r--r--chrome/browser/chromeos/cros_settings_provider_user.cc46
-rw-r--r--chrome/browser/chromeos/cros_settings_provider_user.h10
-rw-r--r--chrome/browser/chromeos/login/user_controller.cc10
-rw-r--r--chrome/browser/chromeos/login/user_controller.h3
-rw-r--r--chrome/browser/chromeos/login/user_manager.cc24
7 files changed, 91 insertions, 6 deletions
diff --git a/chrome/browser/chromeos/cros_settings_names.cc b/chrome/browser/chromeos/cros_settings_names.cc
index a386847..556eb68 100644
--- a/chrome/browser/chromeos/cros_settings_names.cc
+++ b/chrome/browser/chromeos/cros_settings_names.cc
@@ -16,6 +16,8 @@ const char kAccountsPrefUsers[] = "cros.accounts.users";
const char kSystemTimezone[] = "cros.system.timezone";
+const char kDeviceOwner[] = "cros.device.owner";
+
const char kStatsReportingPref[] = "cros.metrics.reportingEnabled";
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros_settings_names.h b/chrome/browser/chromeos/cros_settings_names.h
index 7fda3fe..213370e 100644
--- a/chrome/browser/chromeos/cros_settings_names.h
+++ b/chrome/browser/chromeos/cros_settings_names.h
@@ -17,6 +17,8 @@ extern const char kAccountsPrefUsers[];
extern const char kSystemTimezone[];
+extern const char kDeviceOwner[];
+
extern const char kStatsReportingPref[];
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros_settings_provider_user.cc b/chrome/browser/chromeos/cros_settings_provider_user.cc
index f30e11b..3094d14 100644
--- a/chrome/browser/chromeos/cros_settings_provider_user.cc
+++ b/chrome/browser/chromeos/cros_settings_provider_user.cc
@@ -26,12 +26,19 @@ Value* CreateSettingsBooleanValue(bool value, bool managed) {
return dict;
}
-void UpdateCache(const char* name, bool value) {
+// static
+void UpdateCacheBool(const char* name, bool value) {
PrefService* prefs = g_browser_process->local_state();
prefs->SetBoolean(name, value);
prefs->ScheduleSavePersistentPrefs();
}
+void UpdateCacheString(const char* name, const std::string& value) {
+ PrefService* prefs = g_browser_process->local_state();
+ prefs->SetString(name, value);
+ prefs->ScheduleSavePersistentPrefs();
+}
+
bool GetUserWhitelist(ListValue* user_list) {
std::vector<std::string> whitelist;
if (!CrosLibrary::Get()->EnsureLoaded() ||
@@ -73,6 +80,7 @@ UserCrosSettingsProvider::UserCrosSettingsProvider() {
StartFetchingBoolSetting(kAccountsPrefAllowGuest);
StartFetchingBoolSetting(kAccountsPrefAllowNewUser);
StartFetchingBoolSetting(kAccountsPrefShowUserNamesOnSignIn);
+ StartFetchingStringSetting(kDeviceOwner);
}
UserCrosSettingsProvider::~UserCrosSettingsProvider() {
@@ -86,6 +94,7 @@ void UserCrosSettingsProvider::RegisterPrefs(PrefService* local_state) {
local_state->RegisterBooleanPref(kAccountsPrefAllowNewUser, true);
local_state->RegisterBooleanPref(kAccountsPrefShowUserNamesOnSignIn, true);
local_state->RegisterListPref(kAccountsPrefUsers);
+ local_state->RegisterStringPref(kDeviceOwner, "");
}
bool UserCrosSettingsProvider::cached_allow_guest() {
@@ -116,6 +125,10 @@ const ListValue* UserCrosSettingsProvider::cached_whitelist() {
return cached_users;
}
+std::string UserCrosSettingsProvider::cached_owner() {
+ return g_browser_process->local_state()->GetString(kDeviceOwner);
+}
+
void UserCrosSettingsProvider::Set(const std::string& path, Value* in_value) {
if (!UserManager::Get()->current_user_is_owner()) {
LOG(WARNING) << "Changing settings from non-owner, setting=" << path;
@@ -132,10 +145,13 @@ void UserCrosSettingsProvider::Set(const std::string& path, Value* in_value) {
if (in_value->GetAsBoolean(&bool_value)) {
std::string value = bool_value ? "true" : "false";
SignedSettingsHelper::Get()->StartStorePropertyOp(path, value, this);
- UpdateCache(path.c_str(), bool_value);
+ UpdateCacheBool(path.c_str(), bool_value);
LOG(INFO) << "Set cros setting " << path << "=" << value;
}
+ } else if (path == kDeviceOwner) {
+ LOG(INFO) << "Setting owner is not supported. "
+ << "Please use 'UpdateCachedOwner' instead.";
} else if (path == kAccountsPrefUsers) {
LOG(INFO) << "Setting user whitelist is not implemented."
<< "Please use whitelist/unwhitelist instead.";
@@ -204,7 +220,14 @@ void UserCrosSettingsProvider::OnRetrievePropertyCompleted(
LOG(INFO) << "Retrieved cros setting " << name << "=" << value;
- UpdateCache(name.c_str(), value == "true" ? true : false);
+ if (bool_settings_.count(name)) {
+ UpdateCacheBool(name.c_str(), value == "true" ? true : false);
+ }
+
+ if (string_settings_.count(name)) {
+ UpdateCacheString(name.c_str(), value);
+ }
+
CrosSettings::Get()->FireObservers(name.c_str());
}
@@ -227,8 +250,25 @@ void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) {
prefs->ScheduleSavePersistentPrefs();
}
+// static
+void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) {
+ UpdateCacheString(kDeviceOwner, email);
+}
+
void UserCrosSettingsProvider::StartFetchingBoolSetting(
const std::string& name) {
+ bool_settings_.insert(name);
+ StartFetchingSetting(name);
+}
+
+void UserCrosSettingsProvider::StartFetchingStringSetting(
+ const std::string& name) {
+ string_settings_.insert(name);
+ StartFetchingSetting(name);
+}
+
+void UserCrosSettingsProvider::StartFetchingSetting(
+ const std::string& name) {
if (CrosLibrary::Get()->EnsureLoaded())
SignedSettingsHelper::Get()->StartRetrieveProperty(name, this);
}
diff --git a/chrome/browser/chromeos/cros_settings_provider_user.h b/chrome/browser/chromeos/cros_settings_provider_user.h
index 215964a..f0c5509 100644
--- a/chrome/browser/chromeos/cros_settings_provider_user.h
+++ b/chrome/browser/chromeos/cros_settings_provider_user.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/hash_tables.h"
#include "chrome/browser/chromeos/cros_settings_provider.h"
#include "chrome/browser/chromeos/login/signed_settings_helper.h"
@@ -31,6 +32,7 @@ class UserCrosSettingsProvider : public CrosSettingsProvider,
static bool cached_allow_new_user();
static bool cached_show_users_on_signin();
static const ListValue* cached_whitelist();
+ static std::string cached_owner();
// CrosSettingsProvider implementation.
virtual void Set(const std::string& path, Value* in_value);
@@ -48,8 +50,16 @@ class UserCrosSettingsProvider : public CrosSettingsProvider,
void WhitelistUser(const std::string& email);
void UnwhitelistUser(const std::string& email);
+ // Updates cached value of the owner.
+ static void UpdateCachedOwner(const std::string& email);
+
private:
void StartFetchingBoolSetting(const std::string& name);
+ void StartFetchingStringSetting(const std::string& name);
+ void StartFetchingSetting(const std::string& name);
+
+ base::hash_set<std::string> bool_settings_;
+ base::hash_set<std::string> string_settings_;
DISALLOW_COPY_AND_ASSIGN(UserCrosSettingsProvider);
};
diff --git a/chrome/browser/chromeos/login/user_controller.cc b/chrome/browser/chromeos/login/user_controller.cc
index ed542f4..d7c97c6 100644
--- a/chrome/browser/chromeos/login/user_controller.cc
+++ b/chrome/browser/chromeos/login/user_controller.cc
@@ -11,6 +11,7 @@
#include "app/resource_bundle.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/chromeos/cros_settings_provider_user.h"
#include "chrome/browser/chromeos/login/existing_user_view.h"
#include "chrome/browser/chromeos/login/guest_user_view.h"
#include "chrome/browser/chromeos/login/helper.h"
@@ -138,6 +139,7 @@ UserController::UserController(Delegate* delegate, bool is_guest)
is_user_selected_(false),
is_new_user_(!is_guest),
is_guest_(is_guest),
+ is_owner_(false),
show_name_tooltip_(false),
delegate_(delegate),
controls_window_(NULL),
@@ -163,6 +165,11 @@ UserController::UserController(Delegate* delegate,
is_user_selected_(false),
is_new_user_(false),
is_guest_(false),
+ // Empty 'cached_owner()' means that owner hasn't been cached yet, not
+ // that owner has an empty email.
+ is_owner_(
+ !user.email().empty() &&
+ UserCrosSettingsProvider::cached_owner() == user.email()),
show_name_tooltip_(false),
user_(user),
delegate_(delegate),
@@ -332,7 +339,8 @@ void UserController::IsActiveChanged(bool active) {
is_user_selected_ = active;
if (active) {
delegate_->OnUserSelected(this);
- user_view_->SetRemoveButtonVisible(!is_new_user_ && !is_guest_);
+ user_view_->SetRemoveButtonVisible(
+ !is_new_user_ && !is_guest_ && !is_owner_);
// Background is NULL for inactive new user pod to make it transparent.
if (is_new_user_ && !border_window_->GetRootView()->background()) {
views::Painter* painter = CreateWizardPainter(
diff --git a/chrome/browser/chromeos/login/user_controller.h b/chrome/browser/chromeos/login/user_controller.h
index e73f701..d864808 100644
--- a/chrome/browser/chromeos/login/user_controller.h
+++ b/chrome/browser/chromeos/login/user_controller.h
@@ -184,6 +184,9 @@ class UserController : public views::ButtonListener,
// Is this the guest pod?
const bool is_guest_;
+ // Is this user the owner?
+ const bool is_owner_;
+
// Should we show tooltips above user image and label to help distinguish
// users with the same display name.
bool show_name_tooltip_;
diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc
index c1f7598..5095c0a 100644
--- a/chrome/browser/chromeos/login/user_manager.cc
+++ b/chrome/browser/chromeos/login/user_manager.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/input_method_library.h"
+#include "chrome/browser/chromeos/cros_settings_provider_user.h"
#include "chrome/browser/chromeos/login/ownership_service.h"
#include "chrome/browser/chromeos/wm_ipc.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -112,12 +113,31 @@ bool IsDefaultImagePath(const std::string& path, size_t* image_id) {
return false;
}
+// Updates current user ownership on UI thread.
+void UpdateOwnership(bool is_owner) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ UserManager* user_manager = UserManager::Get();
+ user_manager->set_current_user_is_owner(is_owner);
+
+ if (is_owner) {
+ // Also update cached value.
+ UserCrosSettingsProvider::UpdateCachedOwner(
+ user_manager->logged_in_user().email());
+ }
+}
+
// Checks current user's ownership on file thread.
void CheckOwnership() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- UserManager::Get()->set_current_user_is_owner(
- OwnershipService::GetSharedInstance()->CurrentUserIsOwner());
+ bool is_owner = OwnershipService::GetSharedInstance()->CurrentUserIsOwner();
+
+ // UserManager should be accessed only on UI thread.
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ NewRunnableFunction(&UpdateOwnership, is_owner));
}
} // namespace