Chromium Code Reviews| Index: chrome/browser/managed_mode/managed_user_registration_utility.cc |
| diff --git a/chrome/browser/managed_mode/managed_user_registration_utility.cc b/chrome/browser/managed_mode/managed_user_registration_utility.cc |
| index 0b9104d45eb96777aa8ced04e8c182b12a78b0bc..0118e7add0829789c3da2dd5c539decffca6cf60 100644 |
| --- a/chrome/browser/managed_mode/managed_user_registration_utility.cc |
| +++ b/chrome/browser/managed_mode/managed_user_registration_utility.cc |
| @@ -50,11 +50,15 @@ class ManagedUserRegistrationUtilityImpl |
| // Registers a new managed user with the server. |managed_user_id| is a new |
| // unique ID for the new managed user. If its value is the same as that of |
| // of one of the existing managed users, then the same user will be created |
| - // on this machine. |info| contains necessary information like the display |
| - // name of the the user. |callback| is called with the result of the |
| - // registration. We use the info here and not the profile, because on |
| - // Chrome OS the profile of the managed user does not yet exist. |
| + // on this machine. |update_avatar| can only be true when a managed user |
| + // is being imported, in this case the managed user's avatar will also |
| + // be updated on the sync server. |info| contains necessary information like |
| + // the display name of the user and his avatar. |callback| is called |
| + // with the result of the registration. We use the info here and not the |
| + // profile, because on Chrome OS the profile of the managed user does not |
| + // yet exist. |
| virtual void Register(const std::string& managed_user_id, |
| + bool update_avatar, |
| const ManagedUserRegistrationInfo& info, |
| const RegistrationCallback& callback) OVERRIDE; |
| @@ -100,6 +104,7 @@ class ManagedUserRegistrationUtilityImpl |
| std::string pending_managed_user_token_; |
| bool pending_managed_user_acknowledged_; |
| bool is_existing_managed_user_; |
| + bool update_avatar_; |
| RegistrationCallback callback_; |
| DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationUtilityImpl); |
| @@ -182,7 +187,8 @@ ManagedUserRegistrationUtilityImpl::ManagedUserRegistrationUtilityImpl( |
| token_fetcher_(token_fetcher.Pass()), |
| managed_user_sync_service_(service), |
| pending_managed_user_acknowledged_(false), |
| - is_existing_managed_user_(false) { |
| + is_existing_managed_user_(false), |
| + update_avatar_(false) { |
| managed_user_sync_service_->AddObserver(this); |
| } |
| @@ -193,6 +199,7 @@ ManagedUserRegistrationUtilityImpl::~ManagedUserRegistrationUtilityImpl() { |
| void ManagedUserRegistrationUtilityImpl::Register( |
| const std::string& managed_user_id, |
| + bool update_avatar, |
| const ManagedUserRegistrationInfo& info, |
| const RegistrationCallback& callback) { |
| DCHECK(pending_managed_user_id_.empty()); |
| @@ -202,11 +209,18 @@ void ManagedUserRegistrationUtilityImpl::Register( |
| const DictionaryValue* dict = prefs_->GetDictionary(prefs::kManagedUsers); |
| is_existing_managed_user_ = dict->HasKey(managed_user_id); |
| if (!is_existing_managed_user_) { |
| + DCHECK(!update_avatar); |
| managed_user_sync_service_->AddManagedUser(pending_managed_user_id_, |
| base::UTF16ToUTF8(info.name), |
| info.master_key, |
| info.avatar_index); |
| } else { |
| + if (update_avatar) { |
|
Bernhard Bauer
2013/09/13 11:24:20
Couldn't we infer this from the information we alr
ibra
2013/09/13 14:16:50
Done.
|
| + update_avatar_ = true; |
| + managed_user_sync_service_->UpdateManagedUserAvatar(managed_user_id, |
| + info.avatar_index); |
| + } |
| + |
| // User already exists, don't wait for acknowledgment. |
| OnManagedUserAcknowledged(managed_user_id); |
| } |
| @@ -282,17 +296,21 @@ void ManagedUserRegistrationUtilityImpl::CompleteRegistration( |
| if (callback_.is_null()) |
| return; |
| - // We check that the user being registered is not an existing managed |
| - // user before deleting it from sync to avoid accidental deletion of |
| - // existing managed users by just canceling the registration for example. |
| - if (pending_managed_user_token_.empty() && !is_existing_managed_user_) { |
| + if (pending_managed_user_token_.empty()) { |
| DCHECK(!pending_managed_user_id_.empty()); |
| - // Remove the pending managed user if we weren't successful. |
| - DictionaryPrefUpdate update(prefs_, prefs::kManagedUsers); |
| - bool success = |
| - update->RemoveWithoutPathExpansion(pending_managed_user_id_, NULL); |
| - DCHECK(success); |
| - managed_user_sync_service_->DeleteManagedUser(pending_managed_user_id_); |
| + |
| + if (!is_existing_managed_user_) { |
| + // Remove the pending managed user if we weren't successful. |
| + // However, check that we are not importing a managed user |
| + // before deleting it from sync to avoid accidental deletion of |
| + // existing managed users by just canceling the registration for example. |
| + managed_user_sync_service_->DeleteManagedUser(pending_managed_user_id_); |
| + } else if (update_avatar_) { |
| + // Canceling (or failing) a managed user import that did set the avatar |
| + // should undo this change. |
| + managed_user_sync_service_->ClearManagedUserAvatar( |
| + pending_managed_user_id_); |
| + } |
| } |
| if (run_callback) |