| Index: chrome/browser/chromeos/lock_screen_apps/state_controller.cc
|
| diff --git a/chrome/browser/chromeos/lock_screen_apps/state_controller.cc b/chrome/browser/chromeos/lock_screen_apps/state_controller.cc
|
| index d2d49799940ed4bf424af2f51bb493ad2501555d..40ec80fb717cf4489f78ecd28c87966a90cef586 100644
|
| --- a/chrome/browser/chromeos/lock_screen_apps/state_controller.cc
|
| +++ b/chrome/browser/chromeos/lock_screen_apps/state_controller.cc
|
| @@ -7,8 +7,14 @@
|
| #include <utility>
|
|
|
| #include "ash/public/interfaces/constants.mojom.h"
|
| +#include "base/bind.h"
|
| #include "base/command_line.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "chrome/browser/chromeos/lock_screen_apps/app_manager_impl.h"
|
| +#include "chrome/browser/chromeos/profiles/profile_helper.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| #include "chromeos/chromeos_switches.h"
|
| +#include "components/session_manager/core/session_manager.h"
|
| #include "content/public/common/service_manager_connection.h"
|
| #include "services/service_manager/public/cpp/connector.h"
|
|
|
| @@ -34,7 +40,7 @@ StateController* StateController::Get() {
|
| return g_instance;
|
| }
|
|
|
| -StateController::StateController() : binding_(this) {
|
| +StateController::StateController() : binding_(this), session_observer_(this) {
|
| DCHECK(!g_instance);
|
| DCHECK(IsEnabled());
|
|
|
| @@ -55,6 +61,11 @@ void StateController::FlushTrayActionForTesting() {
|
| tray_action_ptr_.FlushForTesting();
|
| }
|
|
|
| +void StateController::SetAppManagerForTesting(
|
| + std::unique_ptr<AppManager> app_manager) {
|
| + app_manager_ = std::move(app_manager);
|
| +}
|
| +
|
| void StateController::Initialize() {
|
| // The tray action ptr might be set previously if the client was being created
|
| // for testing.
|
| @@ -67,6 +78,17 @@ void StateController::Initialize() {
|
| lock_screen_note_state_);
|
| }
|
|
|
| +void StateController::SetPrimaryProfile(Profile* profile) {
|
| + // App manager might have been set previously by a test.
|
| + if (!app_manager_)
|
| + app_manager_ = base::MakeUnique<AppManagerImpl>();
|
| + app_manager_->Initialize(profile,
|
| + chromeos::ProfileHelper::GetSigninProfile());
|
| +
|
| + session_observer_.Add(session_manager::SessionManager::Get());
|
| + OnSessionStateChanged();
|
| +}
|
| +
|
| void StateController::AddObserver(StateObserver* observer) {
|
| observers_.AddObserver(observer);
|
| }
|
| @@ -80,16 +102,42 @@ TrayActionState StateController::GetLockScreenNoteState() const {
|
| }
|
|
|
| void StateController::RequestNewLockScreenNote() {
|
| - if (lock_screen_note_state_ != TrayActionState::kAvailable) {
|
| + if (lock_screen_note_state_ != TrayActionState::kAvailable)
|
| + return;
|
| +
|
| + DCHECK(app_manager_->IsNoteTakingAppAvailable());
|
| +
|
| + // Update state to launching even if app fails to launch - this is to notify
|
| + // listeners that a lock screen note request was handled.
|
| + UpdateLockScreenNoteState(TrayActionState::kLaunching);
|
| + if (!app_manager_->LaunchNoteTaking())
|
| + UpdateLockScreenNoteState(TrayActionState::kAvailable);
|
| +}
|
| +
|
| +void StateController::OnSessionStateChanged() {
|
| + if (!session_manager::SessionManager::Get()->IsScreenLocked()) {
|
| + app_manager_->Stop();
|
| + UpdateLockScreenNoteState(TrayActionState::kNotAvailable);
|
| return;
|
| }
|
|
|
| - // TODO(tbarzic): Implement this properly.
|
| - UpdateLockScreenNoteState(TrayActionState::kActive);
|
| + app_manager_->Start(this);
|
| + OnNoteTakingAvailabilityChanged();
|
| +}
|
| +
|
| +void StateController::OnNoteTakingAvailabilityChanged() {
|
| + if (!app_manager_->IsNoteTakingAppAvailable()) {
|
| + UpdateLockScreenNoteState(TrayActionState::kNotAvailable);
|
| + return;
|
| + }
|
| +
|
| + if (GetLockScreenNoteState() == TrayActionState::kNotAvailable)
|
| + UpdateLockScreenNoteState(TrayActionState::kAvailable);
|
| }
|
|
|
| void StateController::MoveToBackground() {
|
| - if (GetLockScreenNoteState() != TrayActionState::kActive)
|
| + TrayActionState state = GetLockScreenNoteState();
|
| + if (state != TrayActionState::kActive && state != TrayActionState::kLaunching)
|
| return;
|
| UpdateLockScreenNoteState(TrayActionState::kBackground);
|
| }
|
|
|