Commit ab7f2d46 authored by Monica Basta's avatar Monica Basta Committed by Commit Bot

[ProfilePicker]: Add observer on the profile attributes storage.

This CL ensures the profile picker main view is updated if any of the
profiles's state changes.

Bug: 1063856
Change-Id: Ic93292b9f094b7202ceb1a25831310b25c77c997
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2279894
Commit-Queue: Monica Basta <msalama@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785880}
parent 09be9935
......@@ -24,7 +24,9 @@ const size_t kAvatarIconSize = 74;
ProfilePickerHandler::ProfilePickerHandler() = default;
ProfilePickerHandler::~ProfilePickerHandler() = default;
ProfilePickerHandler::~ProfilePickerHandler() {
OnJavascriptDisallowed();
}
void ProfilePickerHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
......@@ -37,6 +39,17 @@ void ProfilePickerHandler::RegisterMessages() {
base::Unretained(this)));
}
void ProfilePickerHandler::OnJavascriptAllowed() {
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.AddObserver(this);
}
void ProfilePickerHandler::OnJavascriptDisallowed() {
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.RemoveObserver(this);
}
void ProfilePickerHandler::HandleMainViewInitialize(
const base::ListValue* args) {
AllowJavascript();
......@@ -85,6 +98,7 @@ void ProfilePickerHandler::OnSwitchToProfileComplete(
}
void ProfilePickerHandler::PushProfilesList() {
DCHECK(IsJavascriptAllowed());
FireWebUIListener("profiles-list-changed", GetProfilesList());
}
......@@ -109,3 +123,29 @@ base::Value ProfilePickerHandler::GetProfilesList() {
}
return std::move(profiles_list);
}
void ProfilePickerHandler::OnProfileAdded(const base::FilePath& profile_path) {
PushProfilesList();
}
void ProfilePickerHandler::OnProfileWasRemoved(
const base::FilePath& profile_path,
const base::string16& profile_name) {
PushProfilesList();
}
void ProfilePickerHandler::OnProfileAvatarChanged(
const base::FilePath& profile_path) {
PushProfilesList();
}
void ProfilePickerHandler::OnProfileHighResAvatarLoaded(
const base::FilePath& profile_path) {
PushProfilesList();
}
void ProfilePickerHandler::OnProfileNameChanged(
const base::FilePath& profile_path,
const base::string16& old_profile_name) {
PushProfilesList();
}
......@@ -8,16 +8,20 @@
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "content/public/browser/web_ui_message_handler.h"
// The handler for Javascript messages related to the profile picker main view.
class ProfilePickerHandler : public content::WebUIMessageHandler {
class ProfilePickerHandler : public content::WebUIMessageHandler,
public ProfileAttributesStorage::Observer {
public:
ProfilePickerHandler();
~ProfilePickerHandler() override;
// content::WebUIMessageHandler:
void RegisterMessages() override;
void OnJavascriptAllowed() override;
void OnJavascriptDisallowed() override;
private:
void HandleMainViewInitialize(const base::ListValue* args);
......@@ -28,6 +32,16 @@ class ProfilePickerHandler : public content::WebUIMessageHandler {
void PushProfilesList();
base::Value GetProfilesList();
// ProfileAttributesStorage::Observer:
void OnProfileAdded(const base::FilePath& profile_path) override;
void OnProfileWasRemoved(const base::FilePath& profile_path,
const base::string16& profile_name) override;
void OnProfileAvatarChanged(const base::FilePath& profile_path) override;
void OnProfileHighResAvatarLoaded(
const base::FilePath& profile_path) override;
void OnProfileNameChanged(const base::FilePath& profile_path,
const base::string16& old_profile_name) override;
base::WeakPtrFactory<ProfilePickerHandler> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ProfilePickerHandler);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment