Commit c665963d authored by Curt Clemens's avatar Curt Clemens Committed by Commit Bot

[NearbyShare] Stub out delegate for system tray pod button

The Nearby Share pod button will need to make calls against code in
//chrome/browser, but it lives in //ash, which cannot depend on
//chrome. This delegate will provide the functionality needed for
the pod button.

Bug: 154866703
Test: unit_tests
Change-Id: Id0a04e56f48590e1770389ad2433fccedae105e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2405640
Commit-Queue: Curt Clemens <cclem@google.com>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#807580}
parent e12d11db
......@@ -1016,6 +1016,8 @@ component("ash") {
"system/model/update_model.h",
"system/model/virtual_keyboard_model.cc",
"system/model/virtual_keyboard_model.h",
"system/nearby_share/nearby_share_controller_impl.cc",
"system/nearby_share/nearby_share_controller_impl.h",
"system/network/active_network_icon.cc",
"system/network/active_network_icon.h",
"system/network/auto_connect_notifier.cc",
......
......@@ -206,6 +206,8 @@ component("cpp") {
"message_center/arc_notifications_host_initializer.h",
"metrics_util.cc",
"metrics_util.h",
"nearby_share_controller.h",
"nearby_share_delegate.h",
"network_config_service.cc",
"network_config_service.h",
"network_icon_image_source.cc",
......@@ -401,6 +403,8 @@ source_set("test_support") {
"test/test_image_downloader.h",
"test/test_keyboard_controller_observer.cc",
"test/test_keyboard_controller_observer.h",
"test/test_nearby_share_delegate.cc",
"test/test_nearby_share_delegate.h",
"test/test_new_window_delegate.cc",
"test/test_new_window_delegate.h",
"test/test_system_tray_client.cc",
......
// 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_NEARBY_SHARE_CONTROLLER_H_
#define ASH_PUBLIC_CPP_NEARBY_SHARE_CONTROLLER_H_
#include "ash/public/cpp/ash_public_export.h"
namespace base {
class TimeDelta;
} // namespace base
namespace ash {
// Relays events from //chrome to //ash for Nearby Share.
class ASH_PUBLIC_EXPORT NearbyShareController {
public:
virtual ~NearbyShareController() = default;
// To be called whenever Nearby Share's High Visibility state changes.
virtual void HighVisibilityEnabledChanged(bool enabled) = 0;
// Called periodically while high visibility is on in order to update the
// Nearby Share pod button's countdown display.
virtual void HighVisibilityCountdownUpdate(
base::TimeDelta remaining_time) = 0;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_NEARBY_SHARE_CONTROLLER_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.
#ifndef ASH_PUBLIC_CPP_NEARBY_SHARE_DELEGATE_H_
#define ASH_PUBLIC_CPP_NEARBY_SHARE_DELEGATE_H_
#include "ash/public/cpp/ash_public_export.h"
#include "base/observer_list_types.h"
#include "base/optional.h"
namespace base {
class TimeDelta;
} // namespace base
namespace ash {
// This delegate is a singleton used by the
// NearbyShareVisibilityFeaturePodButton in //ash to communicate with the
// NearbySharingService KeyedService in //chrome.
class ASH_PUBLIC_EXPORT NearbyShareDelegate {
public:
virtual ~NearbyShareDelegate() = default;
// Used by the pod button to determine whether it should be visible.
virtual bool IsPodButtonVisible() const = 0;
// Gets the current high visibility state from the NearbySharingService.
virtual bool IsHighVisibilityOn() const = 0;
// If high visibility is on, returns the remaining duration until the delegate
// will turn it off, or nullopt if high visibility is off.
virtual base::Optional<base::TimeDelta> RemainingHighVisibilityTime()
const = 0;
// Request high visibility be turned on. If Nearby Share is disabled in prefs,
// this will instead redirect the user to onboarding.
virtual void EnableHighVisibility() = 0;
// Request high visibility be turned off.
virtual void DisableHighVisibility() = 0;
// Open the settings page for Nearby Share, Used when the user clicks on the
// label under the pod button.
virtual void ShowNearbyShareSettings() const = 0;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_NEARBY_SHARE_DELEGATE_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/test/test_nearby_share_delegate.h"
namespace ash {
TestNearbyShareDelegate::TestNearbyShareDelegate() = default;
TestNearbyShareDelegate::~TestNearbyShareDelegate() = default;
bool TestNearbyShareDelegate::IsPodButtonVisible() const {
return false;
}
bool TestNearbyShareDelegate::IsHighVisibilityOn() const {
return false;
}
base::Optional<base::TimeDelta>
TestNearbyShareDelegate::RemainingHighVisibilityTime() const {
return base::nullopt;
}
void TestNearbyShareDelegate::EnableHighVisibility() {}
void TestNearbyShareDelegate::DisableHighVisibility() {}
void TestNearbyShareDelegate::ShowNearbyShareSettings() const {}
} // 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_TEST_TEST_NEARBY_SHARE_DELEGATE_H_
#define ASH_PUBLIC_CPP_TEST_TEST_NEARBY_SHARE_DELEGATE_H_
#include "ash/public/cpp/ash_public_export.h"
#include "ash/public/cpp/nearby_share_delegate.h"
namespace ash {
// A NearbyShareDelegate that does nothing. Used by TestShellDelegate.
class ASH_PUBLIC_EXPORT TestNearbyShareDelegate : public NearbyShareDelegate {
public:
TestNearbyShareDelegate();
~TestNearbyShareDelegate() override;
TestNearbyShareDelegate(TestNearbyShareDelegate&) = delete;
TestNearbyShareDelegate& operator=(TestNearbyShareDelegate&) = delete;
// NearbyShareDelegate
bool IsPodButtonVisible() const override;
bool IsHighVisibilityOn() const override;
base::Optional<base::TimeDelta> RemainingHighVisibilityTime() const override;
void EnableHighVisibility() override;
void DisableHighVisibility() override;
void ShowNearbyShareSettings() const override;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_TEST_TEST_NEARBY_SHARE_DELEGATE_H_
......@@ -80,6 +80,7 @@
#include "ash/public/cpp/ash_prefs.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/holding_space/holding_space_controller.h"
#include "ash/public/cpp/nearby_share_delegate.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/shell_window_ids.h"
......@@ -112,6 +113,7 @@
#include "ash/system/message_center/message_center_controller.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/model/virtual_keyboard_model.h"
#include "ash/system/nearby_share/nearby_share_controller_impl.h"
#include "ash/system/network/sms_observer.h"
#include "ash/system/night_light/night_light_controller_impl.h"
#include "ash/system/power/backlights_forced_off_setter.h"
......@@ -1155,6 +1157,9 @@ void Shell::Init(
// to initialize itself.
shelf_config_->Init();
nearby_share_delegate_ = shell_delegate_->CreateNearbyShareDelegate();
nearby_share_controller_ = std::make_unique<NearbyShareControllerImpl>();
system_notification_controller_ =
std::make_unique<SystemNotificationController>();
......
......@@ -139,6 +139,8 @@ class MessageCenterController;
class MouseCursorEventFilter;
class MruWindowTracker;
class MultiDeviceNotificationPresenter;
class NearbyShareController;
class NearbyShareDelegate;
class NightLightControllerImpl;
class OverlayEventFilter;
class OverviewController;
......@@ -428,6 +430,12 @@ class ASH_EXPORT Shell : public SessionObserver,
return mouse_cursor_filter_.get();
}
MruWindowTracker* mru_window_tracker() { return mru_window_tracker_.get(); }
NearbyShareController* nearby_share_controller() {
return nearby_share_controller_.get();
}
NearbyShareDelegate* nearby_share_delegate() {
return nearby_share_delegate_.get();
}
NightLightControllerImpl* night_light_controller() {
return night_light_controller_.get();
}
......@@ -694,6 +702,8 @@ class ASH_EXPORT Shell : public SessionObserver,
std::unique_ptr<MruWindowTracker> mru_window_tracker_;
std::unique_ptr<MultiDeviceNotificationPresenter>
multidevice_notification_presenter_;
std::unique_ptr<NearbyShareController> nearby_share_controller_;
std::unique_ptr<NearbyShareDelegate> nearby_share_delegate_;
std::unique_ptr<ParentAccessController> parent_access_controller_;
std::unique_ptr<QuickAnswersController> quick_answers_controller_;
std::unique_ptr<ResizeShadowController> resize_shadow_controller_;
......
......@@ -34,6 +34,7 @@ class CaptureModeDelegate;
class ScreenshotDelegate;
class BackGestureContextualNudgeDelegate;
class BackGestureContextualNudgeController;
class NearbyShareDelegate;
// Delegate of the Shell.
class ASH_EXPORT ShellDelegate {
......@@ -60,6 +61,9 @@ class ASH_EXPORT ShellDelegate {
CreateBackGestureContextualNudgeDelegate(
BackGestureContextualNudgeController* controller) = 0;
virtual std::unique_ptr<ash::NearbyShareDelegate> CreateNearbyShareDelegate()
const = 0;
// Check whether the current tab of the browser window can go back.
virtual bool CanGoBack(gfx::NativeWindow window) const = 0;
......
// 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/system/nearby_share/nearby_share_controller_impl.h"
namespace ash {
NearbyShareControllerImpl::NearbyShareControllerImpl() = default;
NearbyShareControllerImpl::~NearbyShareControllerImpl() = default;
void NearbyShareControllerImpl::HighVisibilityCountdownUpdate(
base::TimeDelta remaining_time) {
for (auto& observer : observers_) {
observer.OnHighVisibilityCountdownUpdate(remaining_time);
}
}
void NearbyShareControllerImpl::HighVisibilityEnabledChanged(bool enabled) {
for (auto& observer : observers_) {
observer.OnHighVisibilityEnabledChanged(enabled);
}
}
void NearbyShareControllerImpl::AddObserver(Observer* obs) {
observers_.AddObserver(obs);
}
void NearbyShareControllerImpl::RemoveObserver(Observer* obs) {
observers_.RemoveObserver(obs);
}
} // 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_SYSTEM_NEARBY_SHARE_NEARBY_SHARE_CONTROLLER_IMPL_H_
#define ASH_SYSTEM_NEARBY_SHARE_NEARBY_SHARE_CONTROLLER_IMPL_H_
#include "ash/public/cpp/nearby_share_controller.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
namespace ash {
// Handles Nearby Share events from //chrome, providing an observer interface
// within //ash. Singleton, lives on UI thread.
class NearbyShareControllerImpl : public NearbyShareController {
public:
class Observer : public base::CheckedObserver {
public:
// The delegate implementation maintains a timer and shuts off high
// visibility after a timeout. During that timeout, this event fires
// periodically to update the remaining time on the pod button UI.
virtual void OnHighVisibilityCountdownUpdate(
base::TimeDelta remaining_time) = 0;
// Relays high visibility state changes from the service to the pod button.
virtual void OnHighVisibilityEnabledChanged(bool enabled) = 0;
};
NearbyShareControllerImpl();
NearbyShareControllerImpl(NearbyShareControllerImpl&) = delete;
NearbyShareControllerImpl& operator=(NearbyShareControllerImpl&) = delete;
~NearbyShareControllerImpl() override;
// NearbyShareController
void HighVisibilityCountdownUpdate(base::TimeDelta remaining_time) override;
void HighVisibilityEnabledChanged(bool enabled) override;
void AddObserver(Observer* obs);
void RemoveObserver(Observer* obs);
private:
base::ObserverList<Observer> observers_;
};
} // namespace ash
#endif // ASH_SYSTEM_NEARBY_SHARE_NEARBY_SHARE_CONTROLLER_IMPL_H_
......@@ -8,6 +8,7 @@
#include "ash/accessibility/default_accessibility_delegate.h"
#include "ash/capture_mode/test_capture_mode_delegate.h"
#include "ash/public/cpp/test/test_nearby_share_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/test_screenshot_delegate.h"
#include "ash/wm/gestures/back_gesture/test_back_gesture_contextual_nudge_delegate.h"
......@@ -70,4 +71,9 @@ void TestShellDelegate::SetShouldWaitForTouchAck(
should_wait_for_touch_ack_ = should_wait_for_touch_ack;
}
std::unique_ptr<NearbyShareDelegate>
TestShellDelegate::CreateNearbyShareDelegate() const {
return std::make_unique<TestNearbyShareDelegate>();
}
} // namespace ash
......@@ -47,6 +47,8 @@ class TestShellDelegate : public ShellDelegate {
mojo::PendingReceiver<
chromeos::multidevice_setup::mojom::MultiDeviceSetup> receiver)
override;
std::unique_ptr<NearbyShareDelegate> CreateNearbyShareDelegate()
const override;
void SetCanGoBack(bool can_go_back);
void SetShouldWaitForTouchAck(bool should_wait_for_touch_ack);
......
......@@ -4188,6 +4188,8 @@ static_library("browser") {
"metrics/perf/random_selector.h",
"metrics/perf/windowed_incognito_observer.cc",
"metrics/perf/windowed_incognito_observer.h",
"nearby_sharing/nearby_share_delegate_impl.cc",
"nearby_sharing/nearby_share_delegate_impl.h",
"nearby_sharing/sharesheet/nearby_share_action.cc",
"nearby_sharing/sharesheet/nearby_share_action.h",
"notifications/arc_application_notifier_controller.cc",
......
// 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 "chrome/browser/nearby_sharing/nearby_share_delegate_impl.h"
#include "base/time/time.h"
#include "chrome/browser/nearby_sharing/logging/logging.h"
#include "chrome/browser/nearby_sharing/nearby_sharing_service.h"
#include "chrome/browser/nearby_sharing/nearby_sharing_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h"
#include "chrome/browser/ui/webui/settings/chromeos/constants/routes.mojom.h"
NearbyShareDelegateImpl::NearbyShareDelegateImpl() = default;
NearbyShareDelegateImpl::~NearbyShareDelegateImpl() = default;
bool NearbyShareDelegateImpl::IsPodButtonVisible() const {
return GetService() != nullptr;
}
bool NearbyShareDelegateImpl::IsHighVisibilityOn() const {
NearbySharingService* service = GetService();
return service && service->IsInHighVisibility();
}
base::Optional<base::TimeDelta>
NearbyShareDelegateImpl::RemainingHighVisibilityTime() const {
if (!IsHighVisibilityOn())
return base::nullopt;
return shutoff_time_ - base::TimeTicks::Now();
}
void NearbyShareDelegateImpl::EnableHighVisibility() {
NOTIMPLEMENTED();
}
void NearbyShareDelegateImpl::DisableHighVisibility() {
NOTIMPLEMENTED();
}
NearbySharingService* NearbyShareDelegateImpl::GetService() const {
return NearbySharingServiceFactory::GetForBrowserContext(
ProfileManager::GetPrimaryUserProfile());
}
void NearbyShareDelegateImpl::ShowNearbyShareSettings() const {
settings_opener_->ShowSettingsPage(
chromeos::settings::mojom::kNearbyShareSubpagePath);
}
void NearbyShareDelegateImpl::SettingsOpener::ShowSettingsPage(
const std::string& sub_page) {
chrome::SettingsWindowManager::GetInstance()->ShowOSSettings(
ProfileManager::GetActiveUserProfile(), sub_page);
}
// 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 CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARE_DELEGATE_IMPL_H_
#define CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARE_DELEGATE_IMPL_H_
#include <memory>
#include <string>
#include "ash/public/cpp/nearby_share_delegate.h"
class NearbySharingService;
namespace base {
class TimeDelta;
class TimeTicks;
} // namespace base
// Delegate injected into |ash::Shell| to provide a communication channel
// between the system tray and the |NearbyShareService|. Singleton owned by the
// Shell, lives on the UI thread.
class NearbyShareDelegateImpl : public ash::NearbyShareDelegate {
public:
// For testing. Allows overriding |ShowSettingsPage|.
class SettingsOpener {
public:
SettingsOpener() = default;
SettingsOpener(SettingsOpener&) = delete;
SettingsOpener& operator=(SettingsOpener&) = delete;
virtual ~SettingsOpener() = default;
// Open the chromeos settings page at the given uri, using
// |chrome::SettingsWindowManager| by default.
virtual void ShowSettingsPage(const std::string& sub_page);
};
NearbyShareDelegateImpl();
NearbyShareDelegateImpl(NearbyShareDelegateImpl&) = delete;
NearbyShareDelegateImpl& operator=(NearbyShareDelegateImpl&) = delete;
~NearbyShareDelegateImpl() override;
// ash::NearbyShareDelegate
bool IsPodButtonVisible() const override;
bool IsHighVisibilityOn() const override;
base::Optional<base::TimeDelta> RemainingHighVisibilityTime() const override;
void EnableHighVisibility() override;
void DisableHighVisibility() override;
void ShowNearbyShareSettings() const override;
private:
NearbySharingService* GetService() const;
std::unique_ptr<SettingsOpener> settings_opener_;
// The time when high visibility is scheduled to be shut off.
base::TimeTicks shutoff_time_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARE_DELEGATE_IMPL_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 "chrome/browser/nearby_sharing/nearby_share_delegate_impl.h"
#include "ash/public/cpp/nearby_share_controller.h"
#include "ash/public/cpp/session/session_controller.h"
#include "base/time/clock.h"
#include "chrome/browser/nearby_sharing/common/nearby_share_prefs.h"
#include "chrome/browser/nearby_sharing/mock_nearby_sharing_service.h"
#include "chrome/browser/nearby_sharing/nearby_share_settings.h"
#include "chrome/browser/ui/ash/test_session_controller.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
class MockSettingsOpener : public NearbyShareDelegateImpl::SettingsOpener {
public:
MOCK_METHOD(void, ShowSettingsPage, (const std::string&), (override));
};
class MockNearbyShareController : public ash::NearbyShareController {
public:
MOCK_METHOD(void,
HighVisibilityCountdownUpdate,
(base::TimeDelta),
(override));
MOCK_METHOD(void, HighVisibilityEnabledChanged, (bool), (override));
};
// TODO(crbug.com/1127940): Refactor these tests to avoid use of GMock.
class NearbyShareDelegateImplTest : public ::testing::Test {
public:
NearbyShareDelegateImplTest()
: task_environment_(base::test::TaskEnvironment::TimeSource::MOCK_TIME) {}
~NearbyShareDelegateImplTest() override = default;
base::Time Now() const { return task_environment_.GetMockClock()->Now(); }
// Fast-forwards mock time by |delta| and fires relevant timers.
void FastForward(base::TimeDelta delta) {
task_environment_.FastForwardBy(delta);
}
protected:
content::BrowserTaskEnvironment task_environment_;
MockNearbySharingService nearby_share_service_;
MockSettingsOpener* settings_opener_;
MockNearbyShareController controller_;
NearbyShareDelegateImpl delegate_;
};
TEST_F(NearbyShareDelegateImplTest, StartHighVisibilityAndTimeout) {
// TODO(cclem)
}
TEST_F(NearbyShareDelegateImplTest, StartStopHighVisibility) {
// TODO(cclem)
}
TEST_F(NearbyShareDelegateImplTest, ShowOnboardingAndTurnOnHighVisibility) {
// TODO(cclem)
}
TEST_F(NearbyShareDelegateImplTest, ShowOnboardingAndTimeout) {
// TODO(cclem)
}
TEST_F(NearbyShareDelegateImplTest, StopHighVisibilityOnScreenLock) {
// TODO(cclem)
}
TEST_F(NearbyShareDelegateImplTest, ShowNearbyShareSettings) {
// TODO(cclem)
}
......@@ -13,6 +13,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/chromeos/multidevice_setup/multidevice_setup_service_factory.h"
#include "chrome/browser/nearby_sharing/nearby_share_delegate_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/back_gesture_contextual_nudge_delegate.h"
......@@ -199,3 +200,8 @@ ChromeShellDelegate::CreateBackGestureContextualNudgeDelegate(
ash::BackGestureContextualNudgeController* controller) {
return std::make_unique<BackGestureContextualNudgeDelegate>(controller);
}
std::unique_ptr<ash::NearbyShareDelegate>
ChromeShellDelegate::CreateNearbyShareDelegate() const {
return std::make_unique<NearbyShareDelegateImpl>();
}
......@@ -45,6 +45,8 @@ class ChromeShellDelegate : public ash::ShellDelegate {
chromeos::multidevice_setup::mojom::MultiDeviceSetup> receiver)
override;
media_session::mojom::MediaSessionService* GetMediaSessionService() override;
std::unique_ptr<ash::NearbyShareDelegate> CreateNearbyShareDelegate()
const override;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeShellDelegate);
......
......@@ -3895,6 +3895,7 @@ test("unit_tests") {
sources += [
"../../chromeos/memory/userspace_swap/userspace_swap.cc",
"../browser/device_identity/chromeos/device_oauth2_token_store_chromeos_unittest.cc",
"../browser/nearby_sharing/nearby_share_delegate_impl_unittest.cc",
"../browser/ui/webui/certificate_provisioning_ui_handler_unittest.cc",
"../browser/ui/webui/chromeos/add_supervision/add_supervision_handler_utils_unittest.cc",
"../browser/ui/webui/chromeos/edu_account_login_handler_unittest.cc",
......
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