diff options
7 files changed, 111 insertions, 7 deletions
diff --git a/chrome/browser/chromeos/cros_settings_provider_user.cc b/chrome/browser/chromeos/cros_settings_provider_user.cc index 67dae8e..a22915c 100644 --- a/chrome/browser/chromeos/cros_settings_provider_user.cc +++ b/chrome/browser/chromeos/cros_settings_provider_user.cc @@ -4,17 +4,33 @@ #include "chrome/browser/chromeos/cros_settings_provider_user.h" +#include "base/logging.h" #include "base/string_util.h" #include "base/values.h" #include "chrome/browser/chromeos/cros_settings_names.h" +#include "chrome/browser/chromeos/login/user_manager.h" + +namespace { + +Value* CreateSettingsBooleanValue(bool value, bool managed) { + DictionaryValue* dict = new DictionaryValue; + dict->Set("value", Value::CreateBooleanValue(value)); + dict->Set("managed", Value::CreateBooleanValue(managed)); + return dict; +} + +} // namespace namespace chromeos { UserCrosSettingsProvider::UserCrosSettingsProvider() : dict_(new DictionaryValue) { - Set(kAccountsPrefAllowBWSI, Value::CreateBooleanValue(true)); - Set(kAccountsPrefAllowGuest, Value::CreateBooleanValue(true)); - Set(kAccountsPrefShowUserNamesOnSignIn, Value::CreateBooleanValue(true)); + bool is_owner = UserManager::Get()->current_user_is_owner(); + + Set(kAccountsPrefAllowBWSI, CreateSettingsBooleanValue(true, !is_owner)); + Set(kAccountsPrefAllowGuest, CreateSettingsBooleanValue(true, !is_owner)); + Set(kAccountsPrefShowUserNamesOnSignIn, + CreateSettingsBooleanValue(true, !is_owner)); ListValue* user_list = new ListValue; diff --git a/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc b/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc index ae18b2b..ec19473 100644 --- a/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc +++ b/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc @@ -7,8 +7,10 @@ #include "app/l10n_util.h" #include "base/json/json_reader.h" #include "base/scoped_ptr.h" +#include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/chromeos/cros_settings_provider_user.h" +#include "chrome/browser/chromeos/login/user_manager.h" #include "grit/generated_resources.h" namespace chromeos { @@ -38,6 +40,10 @@ void AccountsOptionsHandler::GetLocalizedValues( IDS_OPTIONS_ACCOUNTS_USERNAME_FORMAT)); localized_strings->SetString("add_users",l10n_util::GetStringUTF16( IDS_OPTIONS_ACCOUNTS_ADD_USERS)); + + localized_strings->SetString("current_user_is_owner", + UserManager::Get()->current_user_is_owner() ? + ASCIIToUTF16("true") : ASCIIToUTF16("false")); } } // namespace chromeos diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc index 5b7bd34..381297a 100644 --- a/chrome/browser/chromeos/login/user_manager.cc +++ b/chrome/browser/chromeos/login/user_manager.cc @@ -18,10 +18,12 @@ #include "chrome/browser/chrome_thread.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/input_method_library.h" +#include "chrome/browser/chromeos/login/ownership_service.h" #include "chrome/browser/chromeos/wm_ipc.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" #include "gfx/codec/png_codec.h" #include "grit/theme_resources.h" @@ -79,6 +81,14 @@ void save_image_to_file(const SkBitmap& image, username, image_path.value())); } +// Checks current user's ownership on file thread. +void CheckOwnership() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); + + UserManager::Get()->set_current_user_is_owner( + OwnershipService::GetSharedInstance()->CurrentUserIsOwner()); +} + } // namespace UserManager::User::User() { @@ -242,7 +252,12 @@ void UserManager::OnImageLoaded(const std::string& username, // Private constructor and destructor. Do nothing. UserManager::UserManager() - : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader(this))) { + : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader(this))), + current_user_is_owner_(false) { + registrar_.Add(this, NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, + NotificationService::AllSources()); } UserManager::~UserManager() { @@ -262,6 +277,20 @@ void UserManager::NotifyOnLogin() { StopInputMethodProcesses(); // Let the window manager know that we're logged in now. WmIpc::instance()->SetLoggedInProperty(true); + + // Schedules current user ownership check on file thread. + ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, + NewRunnableFunction(&CheckOwnership)); +} + +void UserManager::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED || + type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED) { + ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, + NewRunnableFunction(&CheckOwnership)); + } } } // namespace chromeos diff --git a/chrome/browser/chromeos/login/user_manager.h b/chrome/browser/chromeos/login/user_manager.h index 1d712cd..6763069 100644 --- a/chrome/browser/chromeos/login/user_manager.h +++ b/chrome/browser/chromeos/login/user_manager.h @@ -13,6 +13,8 @@ #include "base/hash_tables.h" #include "base/ref_counted.h" #include "chrome/browser/chromeos/login/user_image_loader.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "third_party/skia/include/core/SkBitmap.h" class PrefService; @@ -21,7 +23,8 @@ namespace chromeos { // This class provides a mechanism for discovering users who have logged // into this chromium os device before and updating that list. -class UserManager : public UserImageLoader::Delegate { +class UserManager : public UserImageLoader::Delegate, + public NotificationObserver { public: // A class representing information about a previously logged in user. class User { @@ -83,6 +86,19 @@ class UserManager : public UserImageLoader::Delegate { virtual void OnImageLoaded(const std::string& username, const SkBitmap& image); + // NotificationObserver implementation. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Accessor for current_user_is_owner_ + bool current_user_is_owner() const { + return current_user_is_owner_; + } + void set_current_user_is_owner(bool current_user_is_owner) { + current_user_is_owner_ = current_user_is_owner; + } + private: UserManager(); ~UserManager(); @@ -100,6 +116,11 @@ class UserManager : public UserImageLoader::Delegate { // The logged-in user. User logged_in_user_; + // Cached flag of whether currently logged-in user is owner or not. + bool current_user_is_owner_; + + NotificationRegistrar registrar_; + DISALLOW_COPY_AND_ASSIGN(UserManager); }; diff --git a/chrome/browser/resources/options/chromeos_accounts_options.js b/chrome/browser/resources/options/chromeos_accounts_options.js index 3adb4b7..72e63e1 100644 --- a/chrome/browser/resources/options/chromeos_accounts_options.js +++ b/chrome/browser/resources/options/chromeos_accounts_options.js @@ -32,12 +32,16 @@ cr.define('options', function() { OptionsPage.prototype.initializePage.call(this); // Set up accounts page. - options.accounts.UserList.decorate($('userList')); + var userList = $('userList'); + options.accounts.UserList.decorate(userList); var userNameEdit = $('userNameEdit'); options.accounts.UserNameEdit.decorate(userNameEdit); userNameEdit.addEventListener('add', this.handleAddUser_); + userList.disabled = + userNameEdit.disabled = !AccountsOptions.currentUserIsOwner(); + this.addEventListener('visibleChange', this.handleVisibleChange_); }, @@ -51,7 +55,7 @@ cr.define('options', function() { handleVisibleChange_: function(e) { if (!this.userListInitalized_ && this.visible) { this.userListInitalized_ = true; - userList.redraw(); + $('userList').redraw(); } }, @@ -65,6 +69,13 @@ cr.define('options', function() { } }; + /** + * Returns whether the current user is owner or not. + */ + AccountsOptions.currentUserIsOwner = function() { + return localStrings.getString('current_user_is_owner') == 'true'; + }; + // Export return { AccountsOptions: AccountsOptions diff --git a/chrome/browser/resources/options/chromeos_accounts_options_page.css b/chrome/browser/resources/options/chromeos_accounts_options_page.css index ceb4a9e..f92132f 100644 --- a/chrome/browser/resources/options/chromeos_accounts_options_page.css +++ b/chrome/browser/resources/options/chromeos_accounts_options_page.css @@ -58,6 +58,21 @@ html[dir=rtl] .remove-user-button { height: 166px; } +#userList[disabled], +#userList[disabled] > [selected], +#userList[disabled] > :hover { + border-color: hsl(0, 0%, 85%); +} + +#userList[disabled] > [selected], +#userList[disabled] > :hover { + background-color: hsl(0,0%,90%); +} + +#userList[disabled] .remove-user-button { + visibility: hidden; +} + #userNameEdit { border: 1px solid lightgrey; width: 366px; diff --git a/chrome/browser/resources/options/chromeos_accounts_user_list.js b/chrome/browser/resources/options/chromeos_accounts_user_list.js index c57f290..1f37f61 100644 --- a/chrome/browser/resources/options/chromeos_accounts_user_list.js +++ b/chrome/browser/resources/options/chromeos_accounts_user_list.js @@ -119,6 +119,12 @@ cr.define('options.accounts', function() { }; /** + * Whether the user list is disabled. Only used for display purpose. + * @type {boolean} + */ + cr.defineProperty(UserList, 'disabled', cr.PropertyKind.BOOL_ATTR); + + /** * Creates a new user list item. * @param user The user account this represents. * @constructor |