0

focus_mode: Add focus mode delegate

This adds focus mode delegate for Chrome.

Bug: b/331643640
Test: N/A
Change-Id: Ifa052ceb3a725185b0919584562c6562fa9803e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5512507
Reviewed-by: Richard Chui <richui@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Yongshun Liu <yongshun@chromium.org>
Reviewed-by: Sean Kau <skau@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1297157}
This commit is contained in:
Yongshun Liu
2024-05-06 22:22:03 +00:00
committed by Chromium LUCI CQ
parent fb8b15aaf4
commit 20a847f9f9
16 changed files with 152 additions and 4 deletions

@ -1643,6 +1643,7 @@ component("ash") {
"system/focus_mode/focus_mode_controller.h",
"system/focus_mode/focus_mode_countdown_view.cc",
"system/focus_mode/focus_mode_countdown_view.h",
"system/focus_mode/focus_mode_delegate.h",
"system/focus_mode/focus_mode_detailed_view.cc",
"system/focus_mode/focus_mode_detailed_view.h",
"system/focus_mode/focus_mode_detailed_view_controller.cc",
@ -4791,6 +4792,8 @@ static_library("test_support") {
"system/diagnostics/fake_diagnostics_browser_delegate.h",
"system/diagnostics/log_test_helpers.cc",
"system/diagnostics/log_test_helpers.h",
"system/focus_mode/test/test_focus_mode_delegate.cc",
"system/focus_mode/test/test_focus_mode_delegate.h",
"system/geolocation/test_geolocation_url_loader_factory.cc",
"system/geolocation/test_geolocation_url_loader_factory.h",
"system/mahi/test/mock_mahi_manager.cc",

@ -1683,7 +1683,8 @@ void Shell::Init(
std::make_unique<SystemNotificationController>();
if (features::IsFocusModeEnabled()) {
focus_mode_controller_ = std::make_unique<FocusModeController>();
focus_mode_controller_ = std::make_unique<FocusModeController>(
shell_delegate_->CreateFocusModeDelegate());
}
// WmModeController should be created before initializing the window tree

@ -43,6 +43,7 @@ class BackGestureContextualNudgeDelegate;
class CaptureModeDelegate;
class ClipboardHistoryControllerDelegate;
class DeskProfilesDelegate;
class FocusModeDelegate;
class GameDashboardDelegate;
class MediaNotificationProvider;
class NearbyShareController;
@ -106,6 +107,10 @@ class ASH_EXPORT ShellDelegate {
virtual std::unique_ptr<api::TasksDelegate> CreateTasksDelegate() const = 0;
// Creates and returns the delegate for Focus Mode.
virtual std::unique_ptr<FocusModeDelegate> CreateFocusModeDelegate()
const = 0;
// Creates and returns the delegate of the System Sounds feature.
virtual std::unique_ptr<SystemSoundsDelegate> CreateSystemSoundsDelegate()
const = 0;

@ -12,6 +12,7 @@
#include "ash/public/cpp/system/anchored_nudge_data.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/do_not_disturb_notification_controller.h"
#include "ash/system/focus_mode/focus_mode_histogram_names.h"
@ -148,8 +149,10 @@ void RecordStartSessionSourceHistogram(
} // namespace
FocusModeController::FocusModeController()
: session_duration_(kDefaultSessionDuration) {
FocusModeController::FocusModeController(
std::unique_ptr<FocusModeDelegate> delegate)
: session_duration_(kDefaultSessionDuration),
delegate_(std::move(delegate)) {
CHECK_EQ(g_instance, nullptr);
g_instance = this;

@ -9,6 +9,7 @@
#include "ash/ash_export.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/system/focus_mode/focus_mode_delegate.h"
#include "ash/system/focus_mode/focus_mode_histogram_names.h"
#include "ash/system/focus_mode/focus_mode_session.h"
#include "ash/system/focus_mode/focus_mode_tasks_provider.h"
@ -54,7 +55,7 @@ class ASH_EXPORT FocusModeController : public SessionObserver {
const FocusModeSession::Snapshot& session_snapshot) {}
};
FocusModeController();
explicit FocusModeController(std::unique_ptr<FocusModeDelegate> delegate);
FocusModeController(const FocusModeController&) = delete;
FocusModeController& operator=(const FocusModeController&) = delete;
~FocusModeController() override;
@ -100,6 +101,7 @@ class ASH_EXPORT FocusModeController : public SessionObserver {
youtube_music::YoutubeMusicController* youtube_music_controller() const {
return youtube_music_controller_.get();
}
FocusModeDelegate* delegate() { return delegate_.get(); }
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
@ -228,6 +230,8 @@ class ASH_EXPORT FocusModeController : public SessionObserver {
std::unique_ptr<youtube_music::YoutubeMusicController>
youtube_music_controller_;
std::unique_ptr<FocusModeDelegate> delegate_;
base::ObserverList<Observer> observers_;
};

@ -0,0 +1,32 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_FOCUS_MODE_FOCUS_MODE_DELEGATE_H_
#define ASH_SYSTEM_FOCUS_MODE_FOCUS_MODE_DELEGATE_H_
#include <memory>
#include "ash/ash_export.h"
namespace ash {
namespace youtube_music {
class YoutubeMusicClient;
} // namespace youtube_music
// Interface for focus mode delegate.
// TODO(yongshun): Move this and the YouTube Music client interface to
// ash/public/cpp if they are going to be implemented in chrome.
class ASH_EXPORT FocusModeDelegate {
public:
virtual ~FocusModeDelegate() = default;
// Virtual function that is implemented in chrome to create the client.
virtual std::unique_ptr<youtube_music::YoutubeMusicClient>
CreateYoutubeMusicClient() = 0;
};
} // namespace ash
#endif // ASH_SYSTEM_FOCUS_MODE_FOCUS_MODE_DELEGATE_H_

@ -0,0 +1,19 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/focus_mode/test/test_focus_mode_delegate.h"
namespace ash {
TestFocusModeDelegate::TestFocusModeDelegate() = default;
TestFocusModeDelegate::~TestFocusModeDelegate() = default;
std::unique_ptr<youtube_music::YoutubeMusicClient>
TestFocusModeDelegate::CreateYoutubeMusicClient() {
// TODO(yongshun): Return the active fake client.
return nullptr;
}
} // namespace ash

@ -0,0 +1,26 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_FOCUS_MODE_TEST_TEST_FOCUS_MODE_DELEGATE_H_
#define ASH_SYSTEM_FOCUS_MODE_TEST_TEST_FOCUS_MODE_DELEGATE_H_
#include "ash/system/focus_mode/focus_mode_delegate.h"
namespace ash {
class TestFocusModeDelegate : public FocusModeDelegate {
public:
TestFocusModeDelegate();
TestFocusModeDelegate(const TestFocusModeDelegate&) = delete;
TestFocusModeDelegate& operator=(const TestFocusModeDelegate&) = delete;
~TestFocusModeDelegate() override;
// FocusModeDelegate:
std::unique_ptr<youtube_music::YoutubeMusicClient> CreateYoutubeMusicClient()
override;
};
} // namespace ash
#endif // ASH_SYSTEM_FOCUS_MODE_TEST_TEST_FOCUS_MODE_DELEGATE_H_

@ -18,6 +18,7 @@
#include "ash/public/cpp/test/test_desk_profiles_delegate.h"
#include "ash/public/cpp/test/test_nearby_share_delegate.h"
#include "ash/public/cpp/test/test_saved_desk_delegate.h"
#include "ash/system/focus_mode/test/test_focus_mode_delegate.h"
#include "ash/system/geolocation/test_geolocation_url_loader_factory.h"
#include "ash/system/test_system_sounds_delegate.h"
#include "ash/user_education/user_education_delegate.h"
@ -94,6 +95,11 @@ std::unique_ptr<api::TasksDelegate> TestShellDelegate::CreateTasksDelegate()
return std::make_unique<api::TestTasksDelegate>();
}
std::unique_ptr<FocusModeDelegate> TestShellDelegate::CreateFocusModeDelegate()
const {
return std::make_unique<TestFocusModeDelegate>();
}
std::unique_ptr<UserEducationDelegate>
TestShellDelegate::CreateUserEducationDelegate() const {
return user_education_delegate_factory_

@ -72,6 +72,7 @@ class TestShellDelegate : public ShellDelegate {
std::unique_ptr<SystemSoundsDelegate> CreateSystemSoundsDelegate()
const override;
std::unique_ptr<api::TasksDelegate> CreateTasksDelegate() const override;
std::unique_ptr<FocusModeDelegate> CreateFocusModeDelegate() const override;
std::unique_ptr<UserEducationDelegate> CreateUserEducationDelegate()
const override;
scoped_refptr<network::SharedURLLoaderFactory>

@ -2735,6 +2735,8 @@ static_library("ui") {
"ash/download_status/holding_space_display_client.h",
"ash/download_status/notification_display_client.cc",
"ash/download_status/notification_display_client.h",
"ash/focus_mode/chrome_focus_mode_delegate.cc",
"ash/focus_mode/chrome_focus_mode_delegate.h",
"ash/fwupd_download_client_impl.cc",
"ash/fwupd_download_client_impl.h",
"ash/game_dashboard/chrome_game_dashboard_delegate.cc",

@ -51,6 +51,7 @@
#include "chrome/browser/ui/ash/chrome_accessibility_delegate.h"
#include "chrome/browser/ui/ash/clipboard_history_controller_delegate_impl.h"
#include "chrome/browser/ui/ash/desks/chrome_saved_desk_delegate.h"
#include "chrome/browser/ui/ash/focus_mode/chrome_focus_mode_delegate.h"
#include "chrome/browser/ui/ash/game_dashboard/chrome_game_dashboard_delegate.h"
#include "chrome/browser/ui/ash/global_media_controls/media_notification_provider_impl.h"
#include "chrome/browser/ui/ash/keyboard/chrome_keyboard_ui.h"
@ -210,6 +211,11 @@ ChromeShellDelegate::CreateTasksDelegate() const {
return std::make_unique<ash::api::ChromeTasksDelegate>();
}
std::unique_ptr<ash::FocusModeDelegate>
ChromeShellDelegate::CreateFocusModeDelegate() const {
return std::make_unique<ChromeFocusModeDelegate>();
}
std::unique_ptr<ash::UserEducationDelegate>
ChromeShellDelegate::CreateUserEducationDelegate() const {
return std::make_unique<ChromeUserEducationDelegate>();

@ -49,6 +49,8 @@ class ChromeShellDelegate : public ash::ShellDelegate {
std::unique_ptr<ash::SystemSoundsDelegate> CreateSystemSoundsDelegate()
const override;
std::unique_ptr<ash::api::TasksDelegate> CreateTasksDelegate() const override;
std::unique_ptr<ash::FocusModeDelegate> CreateFocusModeDelegate()
const override;
std::unique_ptr<ash::UserEducationDelegate> CreateUserEducationDelegate()
const override;
scoped_refptr<network::SharedURLLoaderFactory>

@ -0,0 +1 @@
file://ash/system/focus_mode/OWNERS

@ -0,0 +1,15 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/focus_mode/chrome_focus_mode_delegate.h"
ChromeFocusModeDelegate::ChromeFocusModeDelegate() = default;
ChromeFocusModeDelegate::~ChromeFocusModeDelegate() = default;
std::unique_ptr<ash::youtube_music::YoutubeMusicClient>
ChromeFocusModeDelegate::CreateYoutubeMusicClient() {
// TODO(yongshun): Create and return the client.
return nullptr;
}

@ -0,0 +1,22 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_FOCUS_MODE_CHROME_FOCUS_MODE_DELEGATE_H_
#define CHROME_BROWSER_UI_ASH_FOCUS_MODE_CHROME_FOCUS_MODE_DELEGATE_H_
#include "ash/system/focus_mode/focus_mode_delegate.h"
class ChromeFocusModeDelegate : public ash::FocusModeDelegate {
public:
ChromeFocusModeDelegate();
ChromeFocusModeDelegate(const ChromeFocusModeDelegate&) = delete;
ChromeFocusModeDelegate& operator=(const ChromeFocusModeDelegate&) = delete;
~ChromeFocusModeDelegate() override;
// ash::FocusModeDelegate
std::unique_ptr<ash::youtube_music::YoutubeMusicClient>
CreateYoutubeMusicClient() override;
};
#endif // CHROME_BROWSER_UI_ASH_FOCUS_MODE_CHROME_FOCUS_MODE_DELEGATE_H_