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

[ProfilePicker]: Launch selected profile from the profile picker.

This CL handles launching selected profile from the profile picker and
then closing the picker.

Bug: 1063856
Change-Id: I5bfd15a115503dad2749f21f159cb8df25ed0a05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2279890
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@{#785772}
parent 3101c190
......@@ -23,10 +23,10 @@ export class ManageProfilesBrowserProxy {
initializeMainView() {}
/**
* Opens picked profile and closes the profile picker.
* Launches picked profile and closes the profile picker.
* @param {string} profilePath
*/
openSelectedProfile(profilePath) {}
launchSelectedProfile(profilePath) {}
}
/** @implements {ManageProfilesBrowserProxy} */
......@@ -37,8 +37,8 @@ export class ManageProfilesBrowserProxyImpl {
}
/** @override */
openSelectedProfile(profilePath) {
// TODO(msalama): Implement open selected profile.
launchSelectedProfile(profilePath) {
chrome.send('launchSelectedProfile', [profilePath]);
}
}
......
......@@ -30,7 +30,7 @@ Polymer({
/** @private */
onProfileClick_() {
this.manageProfilesBrowserProxy_.openSelectedProfile(
this.manageProfilesBrowserProxy_.launchSelectedProfile(
this.profileState.profilePath);
},
......
......@@ -110,7 +110,7 @@ void ProfilePickerView::Init(Profile* system_profile) {
views::HWNDForWidget(GetWidget()));
#endif
web_view_->LoadInitialURL(GURL(chrome::kChromeUIMdUserManagerUrl));
web_view_->LoadInitialURL(GURL(chrome::kChromeUIProfilePickerUrl));
GetWidget()->Show();
web_view_->RequestFocus();
initialized_ = InitState::kDone;
......
......@@ -12,6 +12,9 @@
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/profile_picker.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/gfx/image/image.h"
......@@ -28,6 +31,10 @@ void ProfilePickerHandler::RegisterMessages() {
"mainViewInitialize",
base::BindRepeating(&ProfilePickerHandler::HandleMainViewInitialize,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"launchSelectedProfile",
base::BindRepeating(&ProfilePickerHandler::HandleLaunchSelectedProfile,
base::Unretained(this)));
}
void ProfilePickerHandler::HandleMainViewInitialize(
......@@ -36,6 +43,47 @@ void ProfilePickerHandler::HandleMainViewInitialize(
PushProfilesList();
}
void ProfilePickerHandler::HandleLaunchSelectedProfile(
const base::ListValue* args) {
const base::Value* profile_path_value = nullptr;
if (!args->Get(0, &profile_path_value))
return;
base::Optional<base::FilePath> profile_path =
util::ValueToFilePath(*profile_path_value);
if (!profile_path)
return;
ProfileAttributesEntry* entry;
if (!g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(*profile_path, &entry)) {
NOTREACHED();
return;
}
if (entry->IsSigninRequired()) {
// The new profile picker does not yet support force signin policy and
// should not be accessible for devices with this policy.
NOTREACHED();
return;
}
profiles::SwitchToProfile(
*profile_path, /*always_create=*/false,
base::Bind(&ProfilePickerHandler::OnSwitchToProfileComplete,
weak_factory_.GetWeakPtr()));
}
void ProfilePickerHandler::OnSwitchToProfileComplete(
Profile* profile,
Profile::CreateStatus profile_create_status) {
Browser* browser = chrome::FindAnyBrowser(profile, false);
DCHECK(browser);
DCHECK(browser->window());
ProfilePicker::Hide();
}
void ProfilePickerHandler::PushProfilesList() {
FireWebUIListener("profiles-list-changed", GetProfilesList());
}
......@@ -47,11 +95,6 @@ base::Value ProfilePickerHandler::GetProfilesList() {
->GetProfileAttributesStorage()
.GetAllProfilesAttributesSortedByName();
for (const ProfileAttributesEntry* entry : entries) {
// Don't show profiles still in the middle of being set up as new legacy
// supervised users.
if (entry->IsOmitted())
continue;
auto profile_entry = std::make_unique<base::DictionaryValue>();
profile_entry->SetKey("profilePath",
util::FilePathToValue(entry->GetPath()));
......
......@@ -7,6 +7,7 @@
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_ui_message_handler.h"
// The handler for Javascript messages related to the profile picker main view.
......@@ -20,6 +21,10 @@ class ProfilePickerHandler : public content::WebUIMessageHandler {
private:
void HandleMainViewInitialize(const base::ListValue* args);
void HandleLaunchSelectedProfile(const base::ListValue* args);
void OnSwitchToProfileComplete(Profile* profile,
Profile::CreateStatus profile_create_status);
void PushProfilesList();
base::Value GetProfilesList();
......
......@@ -326,6 +326,7 @@ const char kChromeUIDiscardsURL[] = "chrome://discards/";
const char kChromeUIHatsHost[] = "hats";
const char kChromeUIHatsURL[] = "chrome://hats/";
const char kChromeUIProfilePickerHost[] = "profile-picker";
const char kChromeUIProfilePickerUrl[] = "chrome://profile-picker/";
#endif
#if !defined(OS_ANDROID)
......
......@@ -284,6 +284,7 @@ extern const char kChromeUIDiscardsURL[];
extern const char kChromeUIHatsHost[];
extern const char kChromeUIHatsURL[];
extern const char kChromeUIProfilePickerHost[];
extern const char kChromeUIProfilePickerUrl[];
#endif
#if !defined(OS_ANDROID)
......
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