Commit da04be72 authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

Smart Lock: Delay showing the 'Chromebook added' notification.

Delay showing the 'Chromebook added' notification until the
MultiDeviceSetupDialog has been closed.

R=jhawkins@chromium.org, khorimoto@chromium.org

Bug: 883069
Change-Id: If8ae079f77de89cede94ea840e5335445fb7a0ad
Reviewed-on: https://chromium-review.googlesource.com/c/1260304Reviewed-by: default avatarJames Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597213}
parent 47ed9b80
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.h"
#include "chrome/common/apps/platform_apps/api/easy_unlock_private.h" #include "chrome/common/apps/platform_apps/api/easy_unlock_private.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
...@@ -706,6 +707,18 @@ void EasyUnlockServiceRegular::OnFeatureStatesChanged( ...@@ -706,6 +707,18 @@ void EasyUnlockServiceRegular::OnFeatureStatesChanged(
LoadRemoteDevices(); LoadRemoteDevices();
} }
void EasyUnlockServiceRegular::ShowChromebookAddedNotification() {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) &&
base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup));
// The user may have decided to disable Smart Lock or the whole multidevice
// suite immediately after completing setup, so ensure that Smart Lock is
// enabled.
if (feature_state_ == multidevice_setup::mojom::FeatureState::kEnabledByUser)
notification_controller_->ShowChromebookAddedNotification();
}
void EasyUnlockServiceRegular::ShowNotificationIfNewDevicePresent( void EasyUnlockServiceRegular::ShowNotificationIfNewDevicePresent(
const std::set<std::string>& public_keys_before_sync, const std::set<std::string>& public_keys_before_sync,
const std::set<std::string>& public_keys_after_sync) { const std::set<std::string>& public_keys_after_sync) {
...@@ -724,6 +737,21 @@ void EasyUnlockServiceRegular::ShowNotificationIfNewDevicePresent( ...@@ -724,6 +737,21 @@ void EasyUnlockServiceRegular::ShowNotificationIfNewDevicePresent(
if (!public_keys_after_sync.empty() && !is_setup_fresh) { if (!public_keys_after_sync.empty() && !is_setup_fresh) {
if (public_keys_before_sync.empty()) { if (public_keys_before_sync.empty()) {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) &&
base::FeatureList::IsEnabled(
chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
multidevice_setup::MultiDeviceSetupDialog* multidevice_setup_dialog =
multidevice_setup::MultiDeviceSetupDialog::Get();
if (multidevice_setup_dialog) {
// Delay showing the "Chromebook added" notification until the
// MultiDeviceSetupDialog is closed.
multidevice_setup_dialog->AddOnCloseCallback(base::BindOnce(
&EasyUnlockServiceRegular::ShowChromebookAddedNotification,
weak_ptr_factory_.GetWeakPtr()));
return;
}
}
notification_controller_->ShowChromebookAddedNotification(); notification_controller_->ShowChromebookAddedNotification();
} else { } else {
shown_pairing_changed_notification_ = true; shown_pairing_changed_notification_ = true;
......
...@@ -129,6 +129,8 @@ class EasyUnlockServiceRegular ...@@ -129,6 +129,8 @@ class EasyUnlockServiceRegular
const multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap& const multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap&
feature_states_map) override; feature_states_map) override;
void ShowChromebookAddedNotification();
void ShowNotificationIfNewDevicePresent( void ShowNotificationIfNewDevicePresent(
const std::set<std::string>& public_keys_before_sync, const std::set<std::string>& public_keys_before_sync,
const std::set<std::string>& public_keys_after_sync); const std::set<std::string>& public_keys_after_sync);
......
...@@ -58,11 +58,23 @@ void MultiDeviceSetupDialog::Show() { ...@@ -58,11 +58,23 @@ void MultiDeviceSetupDialog::Show() {
false /* is_minimal_style */); false /* is_minimal_style */);
} }
// static
MultiDeviceSetupDialog* MultiDeviceSetupDialog::Get() {
return current_instance_;
}
void MultiDeviceSetupDialog::AddOnCloseCallback(base::OnceClosure callback) {
on_close_callbacks_.push_back(std::move(callback));
}
MultiDeviceSetupDialog::MultiDeviceSetupDialog() MultiDeviceSetupDialog::MultiDeviceSetupDialog()
: SystemWebDialogDelegate(GURL(chrome::kChromeUIMultiDeviceSetupUrl), : SystemWebDialogDelegate(GURL(chrome::kChromeUIMultiDeviceSetupUrl),
base::string16()) {} base::string16()) {}
MultiDeviceSetupDialog::~MultiDeviceSetupDialog() = default; MultiDeviceSetupDialog::~MultiDeviceSetupDialog() {
for (auto& callback : on_close_callbacks_)
std::move(callback).Run();
}
void MultiDeviceSetupDialog::GetDialogSize(gfx::Size* size) const { void MultiDeviceSetupDialog::GetDialogSize(gfx::Size* size) const {
size->SetSize(kDialogWidthPx, kDialogHeightPx); size->SetSize(kDialogWidthPx, kDialogHeightPx);
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_MULTIDEVICE_SETUP_MULTIDEVICE_SETUP_DIALOG_H_ #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_MULTIDEVICE_SETUP_MULTIDEVICE_SETUP_DIALOG_H_
#include <string> #include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h" #include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h"
#include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h" #include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
...@@ -25,6 +27,13 @@ class MultiDeviceSetupDialog : public SystemWebDialogDelegate { ...@@ -25,6 +27,13 @@ class MultiDeviceSetupDialog : public SystemWebDialogDelegate {
// no-op. // no-op.
static void Show(); static void Show();
// Returns the currently displayed dialog. If no dialog exists, returns
// nullptr.
static MultiDeviceSetupDialog* Get();
// Registers a callback which will be called when the dialog is closed.
void AddOnCloseCallback(base::OnceClosure callback);
protected: protected:
MultiDeviceSetupDialog(); MultiDeviceSetupDialog();
~MultiDeviceSetupDialog() override; ~MultiDeviceSetupDialog() override;
...@@ -36,6 +45,10 @@ class MultiDeviceSetupDialog : public SystemWebDialogDelegate { ...@@ -36,6 +45,10 @@ class MultiDeviceSetupDialog : public SystemWebDialogDelegate {
private: private:
static MultiDeviceSetupDialog* current_instance_; static MultiDeviceSetupDialog* current_instance_;
// List of callbacks that have registered themselves to be invoked once this
// dialog is closed.
std::vector<base::OnceClosure> on_close_callbacks_;
DISALLOW_COPY_AND_ASSIGN(MultiDeviceSetupDialog); DISALLOW_COPY_AND_ASSIGN(MultiDeviceSetupDialog);
}; };
......
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