Commit bc3ddd68 authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

Implement the entry point for ambient mode.

This CL implements an entry point for ambient mode where it will show
when user switches to the lock screen, e.g. by pressing the icon, with
feature flag turned on. This CL also adds the first unit test case for
the ambient controller.

Bug: b/149245177
Test: run unittest.
Change-Id: I8cf4424d861b1eac707db2d1dd978af6b7e0efce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065614Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744427}
parent 1367d740
......@@ -1718,6 +1718,7 @@ test("ash_unittests") {
"accessibility/touch_accessibility_enabler_unittest.cc",
"accessibility/touch_exploration_controller_unittest.cc",
"accessibility/touch_exploration_manager_unittest.cc",
"ambient/ambient_controller_unittest.cc",
"ambient/model/photo_model_unittest.cc",
"ambient/ui/ambient_container_view_unittest.cc",
"app_list/app_list_controller_impl_unittest.cc",
......
......@@ -13,6 +13,8 @@
#include "ash/public/cpp/ambient/ambient_mode_state.h"
#include "ash/public/cpp/ambient/ambient_prefs.h"
#include "ash/public/cpp/ambient/photo_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/prefs/pref_registry_simple.h"
#include "ui/views/widget/widget.h"
......@@ -39,9 +41,13 @@ void AmbientController::RegisterProfilePrefs(PrefRegistrySimple* registry) {
AmbientController::AmbientController(AssistantController* assistant_controller)
: assistant_controller_(assistant_controller) {
ambient_state_.AddObserver(this);
// |SessionController| is initialized before |this| in Shell.
Shell::Get()->session_controller()->AddObserver(this);
}
AmbientController::~AmbientController() {
// |SessionController| is destroyed after |this| in Shell.
Shell::Get()->session_controller()->RemoveObserver(this);
ambient_state_.RemoveObserver(this);
DestroyContainerView();
......@@ -73,6 +79,20 @@ void AmbientController::OnAmbientModeEnabled(bool enabled) {
}
}
void AmbientController::OnLockStateChanged(bool locked) {
if (!locked) {
// We should already exit ambient mode at this time, as the ambient
// container needs to be closed to uncover the login port for
// re-authentication.
DCHECK(!container_view_);
return;
}
// Show the ambient container on top of the lock screen.
DCHECK(!container_view_);
Start();
}
void AmbientController::Toggle() {
if (container_view_)
Stop();
......
......@@ -8,6 +8,7 @@
#include "ash/ambient/model/photo_model.h"
#include "ash/ash_export.h"
#include "ash/public/cpp/ambient/ambient_mode_state.h"
#include "ash/session/session_observer.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
......@@ -27,7 +28,8 @@ class PhotoModelObserver;
// Class to handle all ambient mode functionalities.
class ASH_EXPORT AmbientController : public views::WidgetObserver,
public AmbientModeStateObserver {
public AmbientModeStateObserver,
public SessionObserver {
public:
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
......@@ -40,6 +42,9 @@ class ASH_EXPORT AmbientController : public views::WidgetObserver,
// AmbientModeStateObserver:
void OnAmbientModeEnabled(bool enabled) override;
// SessionObserver:
void OnLockStateChanged(bool locked) override;
void Toggle();
void AddPhotoModelObserver(PhotoModelObserver* observer);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/ambient/ambient_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/constants/chromeos_features.h"
namespace ash {
class AmbientControllerTest : public AshTestBase {
public:
AmbientControllerTest() = default;
AmbientControllerTest(const AmbientControllerTest&) = delete;
AmbientControllerTest& operator=(AmbientControllerTest&) = delete;
~AmbientControllerTest() override = default;
// AshTestBase:
void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(
chromeos::features::kAmbientModeFeature);
AshTestBase::SetUp();
}
AmbientController* ambient_controller() {
return Shell::Get()->ambient_controller();
}
void LockScreen() { GetSessionControllerClient()->LockScreen(); }
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(AmbientControllerTest, ShowAmbientContainerViewOnLockScreen) {
EXPECT_FALSE(ambient_controller()->is_showing());
LockScreen();
EXPECT_TRUE(ambient_controller()->is_showing());
}
} // namespace ash
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