Commit 7e22905c authored by Maxim Kolosovskiy's avatar Maxim Kolosovskiy Committed by Commit Bot

Revert "ambient: container logic refactoring [part 1]."

This reverts commit 7eab011b.

Reason for revert: AmbientControllerTest failures
https://ci.chromium.org/p/chromium/builders/ci/linux-chromeos-dbg?limit=200

https://ci.chromium.org/p/chromium/builders/ci/linux-chromeos-dbg/19204?blamelist=1#blamelist-tab

Original change's description:
> ambient: container logic refactoring [part 1].
> 
> This CL is splitted from the original CL:
> https://chromium-review.googlesource.com/c/chromium/src/+/2199870
> with all files changed on ambient/. side.
> 
> Bug: b/156531168
> Test: unittests.
> Change-Id: I4f84277c74c95419ac96e6cfaaa48081c407b243
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2248878
> Commit-Queue: Meilin Wang <meilinw@chromium.org>
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#779664}

TBR=xiyuan@chromium.org,xiaohuic@chromium.org,wutao@chromium.org,meilinw@chromium.org

Change-Id: Ia9eaa3e0d856c7dabf2526c3566fa35cf415e17c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: b/156531168
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2250602Reviewed-by: default avatarMaxim Kolosovskiy <kolos@chromium.org>
Commit-Queue: Maxim Kolosovskiy <kolos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779737}
parent 6aed45f6
...@@ -996,7 +996,7 @@ bool CanHandleStartAmbientMode() { ...@@ -996,7 +996,7 @@ bool CanHandleStartAmbientMode() {
} }
void HandleToggleAmbientMode(const ui::Accelerator& accelerator) { void HandleToggleAmbientMode(const ui::Accelerator& accelerator) {
Shell::Get()->ambient_controller()->ToggleInSessionUI(); Shell::Get()->ambient_controller()->Toggle();
} }
void HandleToggleAssistant(const ui::Accelerator& accelerator) { void HandleToggleAssistant(const ui::Accelerator& accelerator) {
......
This diff is collapsed.
...@@ -11,9 +11,8 @@ ...@@ -11,9 +11,8 @@
#include "ash/ambient/ambient_photo_controller.h" #include "ash/ambient/ambient_photo_controller.h"
#include "ash/ambient/ambient_view_delegate_impl.h" #include "ash/ambient/ambient_view_delegate_impl.h"
#include "ash/ambient/model/ambient_backend_model.h" #include "ash/ambient/model/ambient_backend_model.h"
#include "ash/ambient/ui/ambient_view_delegate.h"
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/public/cpp/ambient/ambient_ui_model.h" #include "ash/public/cpp/ambient/ambient_mode_state.h"
#include "ash/session/session_observer.h" #include "ash/session/session_observer.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -29,7 +28,8 @@ class AmbientPhotoController; ...@@ -29,7 +28,8 @@ class AmbientPhotoController;
class AmbientViewDelegateObserver; class AmbientViewDelegateObserver;
// Class to handle all ambient mode functionalities. // Class to handle all ambient mode functionalities.
class ASH_EXPORT AmbientController : public AmbientUiModelObserver, class ASH_EXPORT AmbientController : public views::WidgetObserver,
public AmbientModeStateObserver,
public SessionObserver { public SessionObserver {
public: public:
static void RegisterProfilePrefs(PrefRegistrySimple* registry); static void RegisterProfilePrefs(PrefRegistrySimple* registry);
...@@ -37,62 +37,49 @@ class ASH_EXPORT AmbientController : public AmbientUiModelObserver, ...@@ -37,62 +37,49 @@ class ASH_EXPORT AmbientController : public AmbientUiModelObserver,
AmbientController(); AmbientController();
~AmbientController() override; ~AmbientController() override;
// AmbientUiModelObserver: // views::WidgetObserver:
void OnAmbientUiVisibilityChanged(AmbientUiVisibility visibility) override; void OnWidgetDestroying(views::Widget* widget) override;
// AmbientModeStateObserver:
void OnAmbientModeEnabled(bool enabled) override;
// SessionObserver: // SessionObserver:
void OnLockStateChanged(bool locked) override; void OnLockStateChanged(bool locked) override;
void AddAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer); // Creates and displays the ambient mode screen on top of the lock screen.
void RemoveAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer); void Show();
// Destroys the ambient mode screen widget.
void Destroy();
// Toggle between show and destroy the ambient mode screen.
// Should be removed once we delete the shortcut entry point.
void Toggle();
// Initializes the |container_view_|. Called in |CreateWidget()| as the void RequestAccessToken(
// contents view. AmbientAccessTokenController::AccessTokenCallback callback);
std::unique_ptr<AmbientContainerView> CreateContainerView();
// Hides the |container_view_|. Called in |OnBackgroundPhotoEvents()| when void AddAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer);
// user interacts with the lock-screen UI. void RemoveAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer);
void HideContainerView();
// Handles the in-session ambient UI, which is displayed in its own widget. AmbientBackendModel* ambient_backend_model();
void ShowInSessionUI();
void CloseInSessionUI();
void ToggleInSessionUI();
// Returns true if the |container_view_| is currently visible. bool is_showing() const { return !!container_view_; }
bool IsShown() const;
// Handles events on the background photo. // Handles user interactions on the background photo. For now the behavior
// is showing lock screen contents (login pod and media control view) on top
// while fading-out the current shown image.
void OnBackgroundPhotoEvents(); void OnBackgroundPhotoEvents();
void UpdateUiMode(AmbientUiMode ui_mode);
void RequestAccessToken(
AmbientAccessTokenController::AccessTokenCallback callback);
AmbientBackendModel* GetAmbientBackendModel();
AmbientBackendController* ambient_backend_controller() { AmbientBackendController* ambient_backend_controller() {
return ambient_backend_controller_.get(); return ambient_backend_controller_.get();
} }
AmbientUiModel* ambient_ui_model() { return &ambient_ui_model_; }
private: private:
friend class AmbientAshTestBase; friend class AmbientAshTestBase;
// TODO(meilinw): reuses the lock-screen widget: b/156531168, b/157175030. void CreateContainerView();
// Creates and shows a full-screen widget responsible for showing void DestroyContainerView();
// the ambient UI.
void CreateWidget();
void StartRefreshingImages();
void StopRefreshingImages();
void CleanUpOnClosed();
void set_backend_controller_for_testing( void StartFadeOutAnimation();
std::unique_ptr<AmbientBackendController> photo_client);
AmbientPhotoController* get_ambient_photo_controller_for_testing() { AmbientPhotoController* get_ambient_photo_controller_for_testing() {
return &ambient_photo_controller_; return &ambient_photo_controller_;
...@@ -102,14 +89,19 @@ class ASH_EXPORT AmbientController : public AmbientUiModelObserver, ...@@ -102,14 +89,19 @@ class ASH_EXPORT AmbientController : public AmbientUiModelObserver,
return container_view_; return container_view_;
} }
// Owned by |RootView| of its parent widget. void set_backend_controller_for_testing(
AmbientContainerView* container_view_ = nullptr; std::unique_ptr<AmbientBackendController> photo_client);
AmbientViewDelegateImpl delegate_{this}; AmbientViewDelegateImpl delegate_{this};
AmbientUiModel ambient_ui_model_;
AmbientContainerView* container_view_ = nullptr; // Owned by view hierarchy.
AmbientModeState ambient_state_;
AmbientAccessTokenController access_token_controller_; AmbientAccessTokenController access_token_controller_;
std::unique_ptr<AmbientBackendController> ambient_backend_controller_; std::unique_ptr<AmbientBackendController> ambient_backend_controller_;
AmbientPhotoController ambient_photo_controller_; AmbientPhotoController ambient_photo_controller_;
DISALLOW_COPY_AND_ASSIGN(AmbientController); DISALLOW_COPY_AND_ASSIGN(AmbientController);
......
...@@ -4,13 +4,10 @@ ...@@ -4,13 +4,10 @@
#include "ash/ambient/ambient_controller.h" #include "ash/ambient/ambient_controller.h"
#include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
#include "ash/ambient/test/ambient_ash_test_base.h" #include "ash/ambient/test/ambient_ash_test_base.h"
#include "ash/ambient/ui/ambient_container_view.h"
#include "ash/public/cpp/ambient/ambient_ui_model.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
...@@ -25,44 +22,11 @@ constexpr base::TimeDelta kDefaultTokenExpirationDelay = ...@@ -25,44 +22,11 @@ constexpr base::TimeDelta kDefaultTokenExpirationDelay =
using AmbientControllerTest = AmbientAshTestBase; using AmbientControllerTest = AmbientAshTestBase;
TEST_F(AmbientControllerTest, ShowAmbientScreenUponLock) { TEST_F(AmbientControllerTest, ShowAmbientContainerViewOnLockScreen) {
LockScreen(); EXPECT_FALSE(ambient_controller()->is_showing());
EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown());
}
TEST_F(AmbientControllerTest, HideAmbientScreen) {
LockScreen(); LockScreen();
EXPECT_TRUE(container_view()); EXPECT_TRUE(ambient_controller()->is_showing());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown());
HideAmbientScreen();
EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kHidden);
EXPECT_FALSE(container_view()->GetWidget()->IsVisible());
}
TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlock) {
LockScreen();
EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown());
UnlockScreen();
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget.
EXPECT_FALSE(container_view());
} }
TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) { TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) {
...@@ -76,6 +40,7 @@ TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) { ...@@ -76,6 +40,7 @@ TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) {
EXPECT_FALSE(IsAccessTokenRequestPending()); EXPECT_FALSE(IsAccessTokenRequestPending());
// Should close ambient widget already when unlocking screen. // Should close ambient widget already when unlocking screen.
ambient_controller()->Toggle();
UnlockScreen(); UnlockScreen();
EXPECT_FALSE(IsAccessTokenRequestPending()); EXPECT_FALSE(IsAccessTokenRequestPending());
} }
......
...@@ -28,7 +28,7 @@ void AmbientViewDelegateImpl::RemoveObserver( ...@@ -28,7 +28,7 @@ void AmbientViewDelegateImpl::RemoveObserver(
} }
AmbientBackendModel* AmbientViewDelegateImpl::GetAmbientBackendModel() { AmbientBackendModel* AmbientViewDelegateImpl::GetAmbientBackendModel() {
return ambient_controller_->GetAmbientBackendModel(); return ambient_controller_->ambient_backend_model();
} }
void AmbientViewDelegateImpl::OnBackgroundPhotoEvents() { void AmbientViewDelegateImpl::OnBackgroundPhotoEvents() {
......
...@@ -16,10 +16,8 @@ TEST_F(AutotestAmbientApiTest, ...@@ -16,10 +16,8 @@ TEST_F(AutotestAmbientApiTest,
ShouldSuccessfullyWaitForPhotoTransitionAnimation) { ShouldSuccessfullyWaitForPhotoTransitionAnimation) {
AutotestAmbientApi test_api; AutotestAmbientApi test_api;
ShowAmbientScreen(); // Start ambient mode.
ambient_controller()->Toggle();
// Simulates locking screen to trigger the image refreshing.
LockScreen();
// Wait for 10 photo transition animation to complete. // Wait for 10 photo transition animation to complete.
base::RunLoop run_loop; base::RunLoop run_loop;
......
...@@ -200,7 +200,7 @@ void AmbientBackendControllerImpl::SetPhotoRefreshInterval( ...@@ -200,7 +200,7 @@ void AmbientBackendControllerImpl::SetPhotoRefreshInterval(
base::TimeDelta interval) { base::TimeDelta interval) {
Shell::Get() Shell::Get()
->ambient_controller() ->ambient_controller()
->GetAmbientBackendModel() ->ambient_backend_model()
->SetPhotoRefreshInterval(interval); ->SetPhotoRefreshInterval(interval);
} }
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "ash/ambient/test/ambient_ash_test_base.h" #include "ash/ambient/test/ambient_ash_test_base.h"
#include <memory>
#include "ash/ambient/ambient_photo_controller.h" #include "ash/ambient/ambient_photo_controller.h"
#include "ash/ambient/fake_ambient_backend_controller_impl.h" #include "ash/ambient/fake_ambient_backend_controller_impl.h"
#include "ash/ambient/ui/ambient_container_view.h" #include "ash/ambient/ui/ambient_container_view.h"
...@@ -38,19 +36,18 @@ void AmbientAshTestBase::SetUp() { ...@@ -38,19 +36,18 @@ void AmbientAshTestBase::SetUp() {
} }
void AmbientAshTestBase::TearDown() { void AmbientAshTestBase::TearDown() {
AshTestBase::TearDown();
ambient_client_.reset(); ambient_client_.reset();
image_downloader_.reset(); image_downloader_.reset();
AshTestBase::TearDown();
} }
void AmbientAshTestBase::ShowAmbientScreen() { AmbientController* AmbientAshTestBase::ambient_controller() const {
// The widget will be destroyed in |AshTestBase::TearDown()|. return Shell::Get()->ambient_controller();
ambient_controller()->CreateWidget();
} }
void AmbientAshTestBase::HideAmbientScreen() { AmbientPhotoController* AmbientAshTestBase::photo_controller() {
ambient_controller()->HideContainerView(); return ambient_controller()->get_ambient_photo_controller_for_testing();
} }
void AmbientAshTestBase::LockScreen() { void AmbientAshTestBase::LockScreen() {
...@@ -61,10 +58,16 @@ void AmbientAshTestBase::UnlockScreen() { ...@@ -61,10 +58,16 @@ void AmbientAshTestBase::UnlockScreen() {
GetSessionControllerClient()->UnlockScreen(); GetSessionControllerClient()->UnlockScreen();
} }
void AmbientAshTestBase::Toggle() {
ambient_controller()->Toggle();
}
AmbientContainerView* AmbientAshTestBase::GetView() {
return ambient_controller()->get_container_view_for_testing();
}
const gfx::ImageSkia& AmbientAshTestBase::GetImageInPhotoView() { const gfx::ImageSkia& AmbientAshTestBase::GetImageInPhotoView() {
return container_view() return GetView()->photo_view_for_testing()->GetCurrentImagesForTesting();
->photo_view_for_testing()
->GetCurrentImagesForTesting();
} }
void AmbientAshTestBase::IssueAccessToken(const std::string& token, void AmbientAshTestBase::IssueAccessToken(const std::string& token,
...@@ -76,16 +79,4 @@ bool AmbientAshTestBase::IsAccessTokenRequestPending() const { ...@@ -76,16 +79,4 @@ bool AmbientAshTestBase::IsAccessTokenRequestPending() const {
return ambient_client_->IsAccessTokenRequestPending(); return ambient_client_->IsAccessTokenRequestPending();
} }
AmbientController* AmbientAshTestBase::ambient_controller() {
return Shell::Get()->ambient_controller();
}
AmbientPhotoController* AmbientAshTestBase::photo_controller() {
return ambient_controller()->get_ambient_photo_controller_for_testing();
}
AmbientContainerView* AmbientAshTestBase::container_view() {
return ambient_controller()->get_container_view_for_testing();
}
} // namespace ash } // namespace ash
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "ash/public/cpp/test/test_image_downloader.h" #include "ash/public/cpp/test/test_image_downloader.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "ui/views/widget/widget.h"
namespace gfx { namespace gfx {
class ImageSkia; class ImageSkia;
...@@ -24,7 +23,7 @@ namespace ash { ...@@ -24,7 +23,7 @@ namespace ash {
class AmbientContainerView; class AmbientContainerView;
class AmbientPhotoController; class AmbientPhotoController;
// The base class to test the Ambient Mode in Ash. // The base class to test the ambient mode in Ash.
class AmbientAshTestBase : public AshTestBase { class AmbientAshTestBase : public AshTestBase {
public: public:
AmbientAshTestBase(); AmbientAshTestBase();
...@@ -34,18 +33,18 @@ class AmbientAshTestBase : public AshTestBase { ...@@ -34,18 +33,18 @@ class AmbientAshTestBase : public AshTestBase {
void SetUp() override; void SetUp() override;
void TearDown() override; void TearDown() override;
// Creates ambient screen in its own widget. AmbientController* ambient_controller() const;
void ShowAmbientScreen();
// Hides ambient screen. Can only be called after |ShowAmbientScreen| has been AmbientPhotoController* photo_controller();
// called.
void HideAmbientScreen();
// Simulates user locks/unlocks screen which will result in ambient widget
// shown/closed.
void LockScreen(); void LockScreen();
void UnlockScreen(); void UnlockScreen();
// Toggle ambient mode.
void Toggle();
AmbientContainerView* GetView();
const gfx::ImageSkia& GetImageInPhotoView(); const gfx::ImageSkia& GetImageInPhotoView();
// Simulate to issue an |access_token|. // Simulate to issue an |access_token|.
...@@ -54,18 +53,10 @@ class AmbientAshTestBase : public AshTestBase { ...@@ -54,18 +53,10 @@ class AmbientAshTestBase : public AshTestBase {
bool IsAccessTokenRequestPending() const; bool IsAccessTokenRequestPending() const;
AmbientController* ambient_controller();
AmbientPhotoController* photo_controller();
// Returns the top-level view which contains all the ambient components.
AmbientContainerView* container_view();
private: private:
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<TestImageDownloader> image_downloader_; std::unique_ptr<TestImageDownloader> image_downloader_;
std::unique_ptr<TestAmbientClient> ambient_client_; std::unique_ptr<TestAmbientClient> ambient_client_;
std::unique_ptr<views::Widget> widget_;
}; };
} // namespace ash } // namespace ash
......
...@@ -34,7 +34,6 @@ constexpr int kAvatarImageSizeDip = 32; ...@@ -34,7 +34,6 @@ constexpr int kAvatarImageSizeDip = 32;
// Greeting message. // Greeting message.
base::string16 GetGreetingMessage(const UserSession* user_session) { base::string16 GetGreetingMessage(const UserSession* user_session) {
DCHECK(user_session);
const std::string& username = user_session->user_info.display_name; const std::string& username = user_session->user_info.display_name;
return l10n_util::GetStringFUTF16(IDS_ASSISTANT_AMBIENT_GREETING_MESSAGE, return l10n_util::GetStringFUTF16(IDS_ASSISTANT_AMBIENT_GREETING_MESSAGE,
base::UTF8ToUTF16(username)); base::UTF8ToUTF16(username));
...@@ -104,19 +103,15 @@ void AmbientAssistantContainerView::InitLayout() { ...@@ -104,19 +103,15 @@ void AmbientAssistantContainerView::InitLayout() {
// Greeting label. // Greeting label.
const UserSession* active_user_session = const UserSession* active_user_session =
Shell::Get()->session_controller()->GetUserSession(0); Shell::Get()->session_controller()->GetUserSession(0);
// TODO(meilinw): uses login user info instead as no active user session is greeting_label_ = AddChildView(
// available on lock screen. std::make_unique<views::Label>(GetGreetingMessage(active_user_session)));
if (active_user_session) { greeting_label_->SetEnabledColor(kTextColorSecondary);
greeting_label_ = AddChildView(std::make_unique<views::Label>( greeting_label_->SetFontList(
GetGreetingMessage(active_user_session))); assistant::ui::GetDefaultFontList()
greeting_label_->SetEnabledColor(kTextColorSecondary); .DeriveWithSizeDelta(8)
greeting_label_->SetFontList( .DeriveWithWeight(gfx::Font::Weight::NORMAL));
assistant::ui::GetDefaultFontList() greeting_label_->SetHorizontalAlignment(
.DeriveWithSizeDelta(8) gfx::HorizontalAlignment::ALIGN_CENTER);
.DeriveWithWeight(gfx::Font::Weight::NORMAL));
greeting_label_->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_CENTER);
}
// Spacer. // Spacer.
views::View* spacer = AddChildView(std::make_unique<views::View>()); views::View* spacer = AddChildView(std::make_unique<views::View>());
...@@ -129,13 +124,9 @@ void AmbientAssistantContainerView::InitLayout() { ...@@ -129,13 +124,9 @@ void AmbientAssistantContainerView::InitLayout() {
gfx::Size(kAvatarImageSizeDip, kAvatarImageSizeDip)); gfx::Size(kAvatarImageSizeDip, kAvatarImageSizeDip));
avatar_view_->SetPreferredSize( avatar_view_->SetPreferredSize(
gfx::Size(kAvatarImageSizeDip, kAvatarImageSizeDip)); gfx::Size(kAvatarImageSizeDip, kAvatarImageSizeDip));
// TODO(meilinw): uses login user info instead as no active user session is gfx::ImageSkia avatar = active_user_session->user_info.avatar.image;
// available on lock screen. if (!avatar.isNull())
if (active_user_session) { avatar_view_->SetImage(avatar);
gfx::ImageSkia avatar = active_user_session->user_info.avatar.image;
if (!avatar.isNull())
avatar_view_->SetImage(avatar);
}
SkPath circular_mask; SkPath circular_mask;
constexpr int kClipCircleRadius = kAvatarImageSizeDip / 2; constexpr int kClipCircleRadius = kAvatarImageSizeDip / 2;
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "ash/ambient/util/ambient_util.h" #include "ash/ambient/util/ambient_util.h"
#include "ash/assistant/util/animation_util.h" #include "ash/assistant/util/animation_util.h"
#include "ash/login/ui/lock_screen.h" #include "ash/login/ui/lock_screen.h"
#include "ash/public/cpp/ambient/ambient_ui_model.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -30,7 +29,34 @@ namespace { ...@@ -30,7 +29,34 @@ namespace {
// Appearance. // Appearance.
constexpr int kHorizontalMarginDip = 16; constexpr int kHorizontalMarginDip = 16;
constexpr int kVerticalMarginDip = 64; constexpr int kVerticalMarginDip = 64;
constexpr int kAssistantPreferredHeightDip = 128; constexpr int kAssistantContainerViewPreferredHeightDip = 128;
// TODO(meilinw): temporary values for dev purpose, need to be updated with the
// final spec.
constexpr float kBackgroundPhotoOpacity = 0.5f;
constexpr base::TimeDelta kBackgroundPhotoFadeOutAnimationDuration =
base::TimeDelta::FromMilliseconds(500);
aura::Window* GetContainer() {
aura::Window* container = nullptr;
if (ambient::util::IsShowing(LockScreen::ScreenType::kLock))
container = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
kShellWindowId_LockScreenContainer);
return container;
}
void CreateWidget(AmbientContainerView* view) {
views::Widget::InitParams params;
params.parent = GetContainer();
params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
params.delegate = view;
params.name = "AmbientModeContainer";
views::Widget* widget = new views::Widget;
widget->Init(std::move(params));
widget->SetFullscreen(true);
}
} // namespace } // namespace
...@@ -51,12 +77,28 @@ gfx::Size AmbientContainerView::CalculatePreferredSize() const { ...@@ -51,12 +77,28 @@ gfx::Size AmbientContainerView::CalculatePreferredSize() const {
} }
void AmbientContainerView::Layout() { void AmbientContainerView::Layout() {
// Layout child views first to have proper bounds set for children. if (photo_view_)
LayoutPhotoView(); photo_view_->SetBoundsRect(GetLocalBounds());
LayoutAssistantView();
LayoutGlanceableInfoView(); if (ambient_assistant_container_view_) {
// The view has the same width as the container view and the widget.
int width = GetLocalBounds().width();
ambient_assistant_container_view_->SetBounds(
0, 0, width, kAssistantContainerViewPreferredHeightDip);
}
if (glanceable_info_view_)
LayoutGlanceableInfoView();
}
void AmbientContainerView::FadeOutPhotoView() {
DCHECK(photo_view_);
View::Layout(); photo_view_->layer()->GetAnimator()->StartAnimation(
assistant::util::CreateLayerAnimationSequence(
assistant::util::CreateOpacityElement(
kBackgroundPhotoOpacity,
kBackgroundPhotoFadeOutAnimationDuration)));
} }
void AmbientContainerView::Init() { void AmbientContainerView::Init() {
...@@ -71,11 +113,8 @@ void AmbientContainerView::Init() { ...@@ -71,11 +113,8 @@ void AmbientContainerView::Init() {
glanceable_info_view_ = glanceable_info_view_ =
AddChildView(std::make_unique<GlanceableInfoView>(delegate_)); AddChildView(std::make_unique<GlanceableInfoView>(delegate_));
}
void AmbientContainerView::LayoutPhotoView() { CreateWidget(this);
// |photo_view_| should have the same size as the widget.
photo_view_->SetBoundsRect(GetLocalBounds());
} }
void AmbientContainerView::LayoutGlanceableInfoView() { void AmbientContainerView::LayoutGlanceableInfoView() {
...@@ -91,11 +130,4 @@ void AmbientContainerView::LayoutGlanceableInfoView() { ...@@ -91,11 +130,4 @@ void AmbientContainerView::LayoutGlanceableInfoView() {
gfx::Rect(x, y, preferred_size.width(), preferred_size.height())); gfx::Rect(x, y, preferred_size.width(), preferred_size.height()));
} }
void AmbientContainerView::LayoutAssistantView() {
int preferred_width = GetPreferredSize().width();
int preferred_height = kAssistantPreferredHeightDip;
ambient_assistant_container_view_->SetBoundsRect(
gfx::Rect(0, 0, preferred_width, preferred_height));
}
} // namespace ash } // namespace ash
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/view.h" #include "ui/views/widget/widget_delegate.h"
namespace ash { namespace ash {
...@@ -16,9 +16,8 @@ class AmbientViewDelegate; ...@@ -16,9 +16,8 @@ class AmbientViewDelegate;
class GlanceableInfoView; class GlanceableInfoView;
class PhotoView; class PhotoView;
// Container view to display all Ambient Mode related views, i.e. photo frame, // Container view for ambient mode.
// weather info. class ASH_EXPORT AmbientContainerView : public views::WidgetDelegateView {
class ASH_EXPORT AmbientContainerView : public views::View {
public: public:
explicit AmbientContainerView(AmbientViewDelegate* delegate); explicit AmbientContainerView(AmbientViewDelegate* delegate);
~AmbientContainerView() override; ~AmbientContainerView() override;
...@@ -28,15 +27,15 @@ class ASH_EXPORT AmbientContainerView : public views::View { ...@@ -28,15 +27,15 @@ class ASH_EXPORT AmbientContainerView : public views::View {
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void Layout() override; void Layout() override;
// Fade out the background photo.
void FadeOutPhotoView();
private: private:
friend class AmbientAshTestBase; friend class AmbientAshTestBase;
void Init(); void Init();
// Layouts its child views.
void LayoutPhotoView();
void LayoutGlanceableInfoView(); void LayoutGlanceableInfoView();
void LayoutAssistantView();
PhotoView* photo_view_for_testing() { return photo_view_; } PhotoView* photo_view_for_testing() { return photo_view_; }
......
...@@ -15,10 +15,33 @@ namespace ash { ...@@ -15,10 +15,33 @@ namespace ash {
using AmbientContainerViewTest = AmbientAshTestBase; using AmbientContainerViewTest = AmbientAshTestBase;
// Shows the widget for AmbientContainerView.
TEST_F(AmbientContainerViewTest, Show) {
// Show the widget.
ambient_controller()->Toggle();
AmbientContainerView* ambient_container_view = GetView();
EXPECT_TRUE(ambient_container_view);
views::Widget* widget = ambient_container_view->GetWidget();
EXPECT_TRUE(widget);
}
// Tests that the window can be shown or closed by toggling.
TEST_F(AmbientContainerViewTest, ToggleWindow) {
// Show the widget.
ambient_controller()->Toggle();
EXPECT_TRUE(GetView());
// Call |Toggle()| to close the widget.
ambient_controller()->Toggle();
EXPECT_FALSE(GetView());
}
// Tests that AmbientContainerView window should be fullscreen. // Tests that AmbientContainerView window should be fullscreen.
TEST_F(AmbientContainerViewTest, WindowFullscreenSize) { TEST_F(AmbientContainerViewTest, WindowFullscreenSize) {
ShowAmbientScreen(); // Show the widget.
views::Widget* widget = container_view()->GetWidget(); ambient_controller()->Toggle();
views::Widget* widget = GetView()->GetWidget();
gfx::Rect root_window_bounds = gfx::Rect root_window_bounds =
display::Screen::GetScreen() display::Screen::GetScreen()
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/ambient/model/ambient_backend_model.h" #include "ash/ambient/model/ambient_backend_model.h"
#include "ash/ambient/ui/ambient_view_delegate.h" #include "ash/ambient/ui/ambient_view_delegate.h"
#include "ash/ambient/util/ambient_util.h" #include "ash/ambient/util/ambient_util.h"
#include "ash/public/cpp/ambient/ambient_mode_state.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/clock_model.h" #include "ash/system/model/clock_model.h"
......
...@@ -78,6 +78,10 @@ class AmbientBackgroundImageView : public views::ImageView { ...@@ -78,6 +78,10 @@ class AmbientBackgroundImageView : public views::ImageView {
return true; return true;
} }
void OnMouseMoved(const ui::MouseEvent& event) override {
delegate_->OnBackgroundPhotoEvents();
}
void OnGestureEvent(ui::GestureEvent* event) override { void OnGestureEvent(ui::GestureEvent* event) override {
if (event->type() == ui::ET_GESTURE_TAP) { if (event->type() == ui::ET_GESTURE_TAP) {
delegate_->OnBackgroundPhotoEvents(); delegate_->OnBackgroundPhotoEvents();
......
...@@ -17,7 +17,7 @@ using AmbientPhotoViewTest = AmbientAshTestBase; ...@@ -17,7 +17,7 @@ using AmbientPhotoViewTest = AmbientAshTestBase;
// the same orientation. // the same orientation.
TEST_F(AmbientPhotoViewTest, DISABLED_ShouldResizeImageToFillFullScreen) { TEST_F(AmbientPhotoViewTest, DISABLED_ShouldResizeImageToFillFullScreen) {
// Start Ambient mode. // Start Ambient mode.
ShowAmbientScreen(); ambient_controller()->Show();
// Fastforward enough time to update the photo. // Fastforward enough time to update the photo.
task_environment()->FastForwardBy(1.2 * kPhotoRefreshInterval); task_environment()->FastForwardBy(1.2 * kPhotoRefreshInterval);
...@@ -28,6 +28,9 @@ TEST_F(AmbientPhotoViewTest, DISABLED_ShouldResizeImageToFillFullScreen) { ...@@ -28,6 +28,9 @@ TEST_F(AmbientPhotoViewTest, DISABLED_ShouldResizeImageToFillFullScreen) {
// The expected size is "600x1200". // The expected size is "600x1200".
EXPECT_EQ(image.size().width(), 600); EXPECT_EQ(image.size().width(), 600);
EXPECT_EQ(image.size().height(), 1200); EXPECT_EQ(image.size().height(), 1200);
// Stop Ambient mode.
ambient_controller()->Destroy();
} }
// TODO(b/158617675): test is flaky. // TODO(b/158617675): test is flaky.
...@@ -36,7 +39,7 @@ TEST_F(AmbientPhotoViewTest, DISABLED_ShouldResizeImageToFillFullScreen) { ...@@ -36,7 +39,7 @@ TEST_F(AmbientPhotoViewTest, DISABLED_ShouldResizeImageToFillFullScreen) {
TEST_F(AmbientPhotoViewTest, TEST_F(AmbientPhotoViewTest,
DISABLED_ShouldResizeImageToFillOneDirectionOfScreen) { DISABLED_ShouldResizeImageToFillOneDirectionOfScreen) {
// Start Ambient mode. // Start Ambient mode.
ShowAmbientScreen(); ambient_controller()->Show();
// Fastforward enough time to update the photo. // Fastforward enough time to update the photo.
task_environment()->FastForwardBy(1.2 * kPhotoRefreshInterval); task_environment()->FastForwardBy(1.2 * kPhotoRefreshInterval);
...@@ -47,6 +50,9 @@ TEST_F(AmbientPhotoViewTest, ...@@ -47,6 +50,9 @@ TEST_F(AmbientPhotoViewTest,
// The expected size is "300x600". // The expected size is "300x600".
EXPECT_EQ(image.size().width(), 300); EXPECT_EQ(image.size().width(), 300);
EXPECT_EQ(image.size().height(), 600); EXPECT_EQ(image.size().height(), 600);
// Stop Ambient mode.
ambient_controller()->Destroy();
} }
} // namespace ash } // namespace ash
...@@ -4,19 +4,12 @@ ...@@ -4,19 +4,12 @@
#include "ash/ambient/util/ambient_util.h" #include "ash/ambient/util/ambient_util.h"
#include "ash/public/cpp/ambient/ambient_client.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "chromeos/constants/chromeos_features.h"
namespace ash { namespace ash {
namespace ambient { namespace ambient {
namespace util { namespace util {
bool IsAmbientModeAllowed() {
return chromeos::features::IsAmbientModeEnabled() &&
ash::AmbientClient::Get()->IsAmbientModeAllowedForActiveUser();
}
bool IsShowing(LockScreen::ScreenType type) { bool IsShowing(LockScreen::ScreenType type) {
return LockScreen::HasInstance() && LockScreen::Get()->screen_type() == type; return LockScreen::HasInstance() && LockScreen::Get()->screen_type() == type;
} }
......
...@@ -14,10 +14,6 @@ namespace ash { ...@@ -14,10 +14,6 @@ namespace ash {
namespace ambient { namespace ambient {
namespace util { namespace util {
// Returns true if Ambient Mode feature is enabled and also allowed for the
// current active user session.
ASH_EXPORT bool IsAmbientModeAllowed();
// Returns true if Ash is showing lock screen. // Returns true if Ash is showing lock screen.
ASH_EXPORT bool IsShowing(LockScreen::ScreenType type); ASH_EXPORT bool IsShowing(LockScreen::ScreenType type);
......
...@@ -92,7 +92,7 @@ void AssistantUiControllerImpl::ShowUi(AssistantEntryPoint entry_point) { ...@@ -92,7 +92,7 @@ void AssistantUiControllerImpl::ShowUi(AssistantEntryPoint entry_point) {
} }
if (chromeos::features::IsAmbientModeEnabled() && if (chromeos::features::IsAmbientModeEnabled() &&
Shell::Get()->ambient_controller()->IsShown()) { Shell::Get()->ambient_controller()->is_showing()) {
model_.SetUiMode(AssistantUiMode::kAmbientUi); model_.SetUiMode(AssistantUiMode::kAmbientUi);
model_.SetVisible(entry_point); model_.SetVisible(entry_point);
return; return;
......
...@@ -21,10 +21,10 @@ component("cpp") { ...@@ -21,10 +21,10 @@ component("cpp") {
"ambient/ambient_backend_controller.h", "ambient/ambient_backend_controller.h",
"ambient/ambient_client.cc", "ambient/ambient_client.cc",
"ambient/ambient_client.h", "ambient/ambient_client.h",
"ambient/ambient_mode_state.cc",
"ambient/ambient_mode_state.h",
"ambient/ambient_prefs.cc", "ambient/ambient_prefs.cc",
"ambient/ambient_prefs.h", "ambient/ambient_prefs.h",
"ambient/ambient_ui_model.cc",
"ambient/ambient_ui_model.h",
"android_intent_helper.cc", "android_intent_helper.cc",
"android_intent_helper.h", "android_intent_helper.h",
"app_list/app_list_client.h", "app_list/app_list_client.h",
......
// Copyright 2019 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/public/cpp/ambient/ambient_mode_state.h"
namespace ash {
namespace {
AmbientModeState* g_ambient_mode_state = nullptr;
} // namespace
// static
AmbientModeState* AmbientModeState::Get() {
return g_ambient_mode_state;
}
AmbientModeState::AmbientModeState() {
DCHECK(!g_ambient_mode_state);
g_ambient_mode_state = this;
}
AmbientModeState::~AmbientModeState() {
DCHECK_EQ(g_ambient_mode_state, this);
g_ambient_mode_state = nullptr;
}
void AmbientModeState::AddObserver(AmbientModeStateObserver* observer) {
observers_.AddObserver(observer);
}
void AmbientModeState::RemoveObserver(AmbientModeStateObserver* observer) {
observers_.RemoveObserver(observer);
}
void AmbientModeState::SetAmbientModeEnabled(bool enabled) {
if (enabled_ == enabled)
return;
enabled_ = enabled;
NotifyAmbientModeEnabled();
}
void AmbientModeState::NotifyAmbientModeEnabled() {
for (auto& observer : observers_)
observer.OnAmbientModeEnabled(enabled_);
}
} // namespace ash
// Copyright 2019 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.
#ifndef ASH_PUBLIC_CPP_AMBIENT_AMBIENT_MODE_STATE_H_
#define ASH_PUBLIC_CPP_AMBIENT_AMBIENT_MODE_STATE_H_
#include "ash/public/cpp/ash_public_export.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
namespace ash {
// An interface implemented by classes who want to be notified about ambient
// state change event.
class ASH_PUBLIC_EXPORT AmbientModeStateObserver
: public base::CheckedObserver {
public:
// Invoked when the Ambient Mode has been enabled/disabled by user
// entering/exiting this mode.
virtual void OnAmbientModeEnabled(bool enabled) = 0;
};
// A class that stores Ambient Mode related states.
class ASH_PUBLIC_EXPORT AmbientModeState {
public:
static AmbientModeState* Get();
AmbientModeState();
AmbientModeState(const AmbientModeState&) = delete;
AmbientModeState& operator=(AmbientModeState&) = delete;
~AmbientModeState();
void AddObserver(AmbientModeStateObserver* observer);
void RemoveObserver(AmbientModeStateObserver* observer);
// Sets the enabled/disabled state for Ambient Mode.
void SetAmbientModeEnabled(bool enabled);
// Returns the enabled/disabled state for Ambient Mode.
bool enabled() const { return enabled_; }
private:
void NotifyAmbientModeEnabled();
// Whether Ambient Mode is enabled.
bool enabled_ = false;
base::ObserverList<AmbientModeStateObserver> observers_;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_MODE_STATE_H_
// 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/public/cpp/ambient/ambient_ui_model.h"
namespace ash {
namespace {
AmbientUiModel* g_ambient_ui_model = nullptr;
} // namespace
// static
// TODO(b/158039112): return a const* instead.
AmbientUiModel* AmbientUiModel::Get() {
return g_ambient_ui_model;
}
AmbientUiModel::AmbientUiModel() {
DCHECK(!g_ambient_ui_model);
g_ambient_ui_model = this;
}
AmbientUiModel::~AmbientUiModel() {
DCHECK_EQ(g_ambient_ui_model, this);
g_ambient_ui_model = nullptr;
}
void AmbientUiModel::AddObserver(AmbientUiModelObserver* observer) {
observers_.AddObserver(observer);
}
void AmbientUiModel::RemoveObserver(AmbientUiModelObserver* observer) {
observers_.RemoveObserver(observer);
}
void AmbientUiModel::SetUiVisibility(AmbientUiVisibility visibility) {
if (ui_visibility_ == visibility)
return;
ui_visibility_ = visibility;
NotifyAmbientUiVisibilityChanged();
}
void AmbientUiModel::SetUiMode(AmbientUiMode ui_mode) {
if (ui_mode_ == ui_mode)
return;
ui_mode_ = ui_mode;
}
void AmbientUiModel::NotifyAmbientUiVisibilityChanged() {
for (auto& observer : observers_)
observer.OnAmbientUiVisibilityChanged(ui_visibility_);
}
} // namespace ash
// 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.
#ifndef ASH_PUBLIC_CPP_AMBIENT_AMBIENT_UI_MODEL_H_
#define ASH_PUBLIC_CPP_AMBIENT_AMBIENT_UI_MODEL_H_
#include "ash/public/cpp/ash_public_export.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
namespace ash {
// Enumeration of UI visibility states.
enum class AmbientUiVisibility {
kShown,
kHidden,
kClosed,
};
// Enumeration of ambient UI modes.
enum class AmbientUiMode {
kLockScreenUi,
kInSessionUi,
};
// A checked observer which receives notification of changes to the Ambient Mode
// UI model.
class ASH_PUBLIC_EXPORT AmbientUiModelObserver : public base::CheckedObserver {
public:
// Invoked when the Ambient Mode UI visibility changed.
virtual void OnAmbientUiVisibilityChanged(AmbientUiVisibility visibility) = 0;
};
// Models the Ambient Mode UI.
class ASH_PUBLIC_EXPORT AmbientUiModel {
public:
static AmbientUiModel* Get();
AmbientUiModel();
AmbientUiModel(const AmbientUiModel&) = delete;
AmbientUiModel& operator=(AmbientUiModel&) = delete;
~AmbientUiModel();
void AddObserver(AmbientUiModelObserver* observer);
void RemoveObserver(AmbientUiModelObserver* observer);
// Updates current UI visibility and notifies all subscribers.
void SetUiVisibility(AmbientUiVisibility visibility);
// Updates current UI mode.
void SetUiMode(AmbientUiMode ui_mode);
AmbientUiVisibility ui_visibility() const { return ui_visibility_; }
AmbientUiMode ui_mode() const { return ui_mode_; }
private:
void NotifyAmbientUiVisibilityChanged();
AmbientUiVisibility ui_visibility_ = AmbientUiVisibility::kClosed;
AmbientUiMode ui_mode_ = AmbientUiMode::kLockScreenUi;
base::ObserverList<AmbientUiModelObserver> observers_;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_UI_MODEL_H_
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "ash/public/cpp/accelerators.h" #include "ash/public/cpp/accelerators.h"
#include "ash/public/cpp/accessibility_controller.h" #include "ash/public/cpp/accessibility_controller.h"
#include "ash/public/cpp/ambient/ambient_ui_model.h" #include "ash/public/cpp/ambient/ambient_mode_state.h"
#include "ash/public/cpp/app_list/app_list_types.h" #include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/public/cpp/app_types.h" #include "ash/public/cpp/app_types.h"
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "ash/public/cpp/ambient/ambient_ui_model.h" #include "ash/public/cpp/ambient/ambient_mode_state.h"
#include "ash/public/cpp/assistant/assistant_state_base.h" #include "ash/public/cpp/assistant/assistant_state_base.h"
#include "ash/public/cpp/assistant/controller/assistant_alarm_timer_controller.h" #include "ash/public/cpp/assistant/controller/assistant_alarm_timer_controller.h"
#include "base/barrier_closure.h" #include "base/barrier_closure.h"
...@@ -218,11 +218,10 @@ void AssistantManagerServiceImpl::Start(const base::Optional<UserInfo>& user, ...@@ -218,11 +218,10 @@ void AssistantManagerServiceImpl::Start(const base::Optional<UserInfo>& user,
// Check the AmbientModeState to keep us synced on |ambient_state|. // Check the AmbientModeState to keep us synced on |ambient_state|.
if (chromeos::features::IsAmbientModeEnabled()) { if (chromeos::features::IsAmbientModeEnabled()) {
auto* model = ash::AmbientUiModel::Get(); auto* ambient_state = ash::AmbientModeState::Get();
DCHECK(model); DCHECK(ambient_state);
EnableAmbientMode(model->ui_visibility() != EnableAmbientMode(ambient_state->enabled());
ash::AmbientUiVisibility::kClosed);
} }
// LibAssistant creation will make file IO and sync wait. Post the creation to // LibAssistant creation will make file IO and sync wait. Post the creation to
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "ash/public/cpp/ambient/ambient_ui_model.h"
#include "ash/public/cpp/assistant/assistant_state.h" #include "ash/public/cpp/assistant/assistant_state.h"
#include "ash/public/cpp/assistant/controller/assistant_alarm_timer_controller.h" #include "ash/public/cpp/assistant/controller/assistant_alarm_timer_controller.h"
#include "ash/public/cpp/assistant/controller/assistant_controller.h" #include "ash/public/cpp/assistant/controller/assistant_controller.h"
...@@ -96,21 +95,14 @@ base::Optional<std::string> GetS3ServerUriOverride() { ...@@ -96,21 +95,14 @@ base::Optional<std::string> GetS3ServerUriOverride() {
} }
#endif #endif
// Returns true if the system is currently in Ambient Mode (with ambient screen
// shown or hidden, but not closed).
bool InAmbientMode() {
DCHECK(chromeos::features::IsAmbientModeEnabled());
return ash::AmbientUiModel::Get()->ui_visibility() !=
ash::AmbientUiVisibility::kClosed;
}
// In the signed-out mode, we are going to run Assistant service without // In the signed-out mode, we are going to run Assistant service without
// using user's signed in account information. // using user's signed in account information.
bool IsSignedOutMode() { bool IsSignedOutMode() {
// We will switch the Libassitsant mode to signed-out/signed-in when user // We will switch the Libassitsant mode to signed-out/signed-in when user
// enters/exits the ambient mode. // enters/exits the ambient mode.
const bool entered_ambient_mode = const bool entered_ambient_mode =
chromeos::features::IsAmbientModeEnabled() && InAmbientMode(); chromeos::features::IsAmbientModeEnabled() &&
ash::AmbientModeState::Get()->enabled();
// Note that we shouldn't toggle the flag to true when exiting ambient // Note that we shouldn't toggle the flag to true when exiting ambient
// mode if we have been using fake gaia login, e.g. in the Tast test. // mode if we have been using fake gaia login, e.g. in the Tast test.
...@@ -219,6 +211,12 @@ Service::Service(std::unique_ptr<network::PendingSharedURLLoaderFactory> ...@@ -219,6 +211,12 @@ Service::Service(std::unique_ptr<network::PendingSharedURLLoaderFactory>
Service::~Service() { Service::~Service() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Add null check for |AmbientModeState| in case that |Service| is released
// after ash has gone.
auto* const ambient_mode_state = ash::AmbientModeState::Get();
if (chromeos::features::IsAmbientModeEnabled() && ambient_mode_state)
ambient_mode_state->RemoveObserver(this);
ash::AssistantState::Get()->RemoveObserver(this); ash::AssistantState::Get()->RemoveObserver(this);
} }
...@@ -238,11 +236,11 @@ void Service::Init() { ...@@ -238,11 +236,11 @@ void Service::Init() {
ash::AssistantState::Get()->AddObserver(this); ash::AssistantState::Get()->AddObserver(this);
if (chromeos::features::IsAmbientModeEnabled())
ambient_ui_model_observer_.Add(ash::AmbientUiModel::Get());
DCHECK(!assistant_manager_service_); DCHECK(!assistant_manager_service_);
if (chromeos::features::IsAmbientModeEnabled())
ash::AmbientModeState::Get()->AddObserver(this);
RequestAccessToken(); RequestAccessToken();
} }
...@@ -358,8 +356,7 @@ void Service::OnStateChanged(AssistantManagerService::State new_state) { ...@@ -358,8 +356,7 @@ void Service::OnStateChanged(AssistantManagerService::State new_state) {
UpdateListeningState(); UpdateListeningState();
} }
void Service::OnAmbientUiVisibilityChanged( void Service::OnAmbientModeEnabled(bool enabled) {
ash::AmbientUiVisibility visibility) {
if (IsSignedOutMode()) { if (IsSignedOutMode()) {
UpdateAssistantManagerState(); UpdateAssistantManagerState();
} else { } else {
...@@ -421,8 +418,10 @@ void Service::UpdateAssistantManagerState() { ...@@ -421,8 +418,10 @@ void Service::UpdateAssistantManagerState() {
case AssistantManagerService::State::RUNNING: case AssistantManagerService::State::RUNNING:
if (assistant_state->settings_enabled().value()) { if (assistant_state->settings_enabled().value()) {
assistant_manager_service_->SetUser(GetUserInfo()); assistant_manager_service_->SetUser(GetUserInfo());
if (chromeos::features::IsAmbientModeEnabled()) if (chromeos::features::IsAmbientModeEnabled()) {
assistant_manager_service_->EnableAmbientMode(InAmbientMode()); assistant_manager_service_->EnableAmbientMode(
ash::AmbientModeState::Get()->enabled());
}
assistant_manager_service_->EnableHotword(ShouldEnableHotword()); assistant_manager_service_->EnableHotword(ShouldEnableHotword());
assistant_manager_service_->SetArcPlayStoreEnabled( assistant_manager_service_->SetArcPlayStoreEnabled(
assistant_state->arc_play_store_enabled().value()); assistant_state->arc_play_store_enabled().value());
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "ash/public/cpp/ambient/ambient_ui_model.h" #include "ash/public/cpp/ambient/ambient_mode_state.h"
#include "ash/public/cpp/assistant/assistant_state.h" #include "ash/public/cpp/assistant/assistant_state.h"
#include "ash/public/cpp/session/session_activation_observer.h" #include "ash/public/cpp/session/session_activation_observer.h"
#include "ash/public/mojom/assistant_controller.mojom.h" #include "ash/public/mojom/assistant_controller.mojom.h"
...@@ -71,7 +71,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service ...@@ -71,7 +71,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service
public ash::AssistantStateObserver, public ash::AssistantStateObserver,
public AssistantManagerService::CommunicationErrorObserver, public AssistantManagerService::CommunicationErrorObserver,
public AssistantManagerService::StateObserver, public AssistantManagerService::StateObserver,
public ash::AmbientUiModelObserver { public ash::AmbientModeStateObserver {
public: public:
Service(std::unique_ptr<network::PendingSharedURLLoaderFactory> Service(std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory, pending_url_loader_factory,
...@@ -126,9 +126,8 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service ...@@ -126,9 +126,8 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service
// AssistantManagerService::StateObserver overrides: // AssistantManagerService::StateObserver overrides:
void OnStateChanged(AssistantManagerService::State new_state) override; void OnStateChanged(AssistantManagerService::State new_state) override;
// ash::AmbientUiModelObserver overrides: // ash::AmbientModeStateObserver overrides:
void OnAmbientUiVisibilityChanged( void OnAmbientModeEnabled(bool enabled) override;
ash::AmbientUiVisibility visibility) override;
void UpdateAssistantManagerState(); void UpdateAssistantManagerState();
...@@ -163,8 +162,6 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service ...@@ -163,8 +162,6 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service
signin::IdentityManager* const identity_manager_; signin::IdentityManager* const identity_manager_;
std::unique_ptr<ScopedAshSessionObserver> scoped_ash_session_observer_; std::unique_ptr<ScopedAshSessionObserver> scoped_ash_session_observer_;
ScopedObserver<ash::AmbientUiModel, ash::AmbientUiModelObserver>
ambient_ui_model_observer_{this};
std::unique_ptr<AssistantManagerService> assistant_manager_service_; std::unique_ptr<AssistantManagerService> assistant_manager_service_;
std::unique_ptr<base::OneShotTimer> token_refresh_timer_; std::unique_ptr<base::OneShotTimer> token_refresh_timer_;
int token_refresh_error_backoff_factor = 1; int token_refresh_error_backoff_factor = 1;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "ash/public/cpp/ambient/ambient_ui_model.h"
#include "ash/public/cpp/assistant/test_support/mock_assistant_controller.h" #include "ash/public/cpp/assistant/test_support/mock_assistant_controller.h"
#include "base/check.h" #include "base/check.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -156,7 +155,7 @@ class AssistantServiceTest : public testing::Test { ...@@ -156,7 +155,7 @@ class AssistantServiceTest : public testing::Test {
base::test::TaskEnvironment* task_environment() { return &task_environment_; } base::test::TaskEnvironment* task_environment() { return &task_environment_; }
ash::AmbientUiModel* ambient_ui_model() { return &ambient_ui_model_; } ash::AmbientModeState* ambient_mode_state() { return &ambient_mode_state_; }
private: private:
base::test::TaskEnvironment task_environment_{ base::test::TaskEnvironment task_environment_{
...@@ -176,7 +175,7 @@ class AssistantServiceTest : public testing::Test { ...@@ -176,7 +175,7 @@ class AssistantServiceTest : public testing::Test {
network::TestURLLoaderFactory url_loader_factory_; network::TestURLLoaderFactory url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory_; scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory_;
ash::AmbientUiModel ambient_ui_model_; ash::AmbientModeState ambient_mode_state_;
DISALLOW_COPY_AND_ASSIGN(AssistantServiceTest); DISALLOW_COPY_AND_ASSIGN(AssistantServiceTest);
}; };
...@@ -328,13 +327,13 @@ TEST_F(AssistantServiceTest, ...@@ -328,13 +327,13 @@ TEST_F(AssistantServiceTest,
ASSERT_TRUE(assistant_manager()->access_token().has_value()); ASSERT_TRUE(assistant_manager()->access_token().has_value());
ASSERT_EQ(assistant_manager()->access_token().value(), kAccessToken); ASSERT_EQ(assistant_manager()->access_token().value(), kAccessToken);
ambient_ui_model()->SetUiVisibility(ash::AmbientUiVisibility::kShown); ambient_mode_state()->SetAmbientModeEnabled(true);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(identity_test_env()->IsAccessTokenRequestPending()); EXPECT_FALSE(identity_test_env()->IsAccessTokenRequestPending());
ASSERT_FALSE(assistant_manager()->access_token().has_value()); ASSERT_FALSE(assistant_manager()->access_token().has_value());
// Disabling ambient mode requests a new token. // Disabling ambient mode requests a new token.
ambient_ui_model()->SetUiVisibility(ash::AmbientUiVisibility::kClosed); ambient_mode_state()->SetAmbientModeEnabled(false);
EXPECT_TRUE(identity_test_env()->IsAccessTokenRequestPending()); EXPECT_TRUE(identity_test_env()->IsAccessTokenRequestPending());
// Assistant manager receives the new token. // Assistant manager receives the new token.
......
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