Commit beeb83c9 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Chromium LUCI CQ

[CrOS PhoneHub] Clean up SilencePhoneQuickActionController

This CL removes an Observer interface and related functions which are no
longer used. They previously were used to facilitate the "Locate phone"
feature, whose implementation was changed to no longer need this
functionality.

Fixed: 1156382
Bug: 1106937
Change-Id: Ic3c7b4208388c6ac96e307a3a7364c4171edd378
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2605844
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarRegan Hsu <hsuregan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839623}
parent bd6ee41a
...@@ -36,14 +36,6 @@ SilencePhoneQuickActionController::~SilencePhoneQuickActionController() { ...@@ -36,14 +36,6 @@ SilencePhoneQuickActionController::~SilencePhoneQuickActionController() {
dnd_controller_->RemoveObserver(this); dnd_controller_->RemoveObserver(this);
} }
void SilencePhoneQuickActionController::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
void SilencePhoneQuickActionController::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
bool SilencePhoneQuickActionController::IsItemEnabled() { bool SilencePhoneQuickActionController::IsItemEnabled() {
return item_->IsToggled(); return item_->IsToggled();
} }
...@@ -133,8 +125,6 @@ void SilencePhoneQuickActionController::SetItemState(ActionState state) { ...@@ -133,8 +125,6 @@ void SilencePhoneQuickActionController::SetItemState(ActionState state) {
IDS_ASH_PHONE_HUB_QUICK_ACTIONS_TOGGLE_TOOLTIP, item_->GetItemLabel(), IDS_ASH_PHONE_HUB_QUICK_ACTIONS_TOGGLE_TOOLTIP, item_->GetItemLabel(),
tooltip_state)); tooltip_state));
} }
for (auto& observer : observer_list_)
observer.OnSilencePhoneItemStateChanged();
} }
void SilencePhoneQuickActionController::CheckRequestedState() { void SilencePhoneQuickActionController::CheckRequestedState() {
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
#define ASH_SYSTEM_PHONEHUB_SILENCE_PHONE_QUICK_ACTION_CONTROLLER_H_ #define ASH_SYSTEM_PHONEHUB_SILENCE_PHONE_QUICK_ACTION_CONTROLLER_H_
#include "ash/system/phonehub/quick_action_controller_base.h" #include "ash/system/phonehub/quick_action_controller_base.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "chromeos/components/phonehub/do_not_disturb_controller.h" #include "chromeos/components/phonehub/do_not_disturb_controller.h"
namespace base { namespace base {
...@@ -21,14 +19,6 @@ class ASH_EXPORT SilencePhoneQuickActionController ...@@ -21,14 +19,6 @@ class ASH_EXPORT SilencePhoneQuickActionController
: public QuickActionControllerBase, : public QuickActionControllerBase,
public chromeos::phonehub::DoNotDisturbController::Observer { public chromeos::phonehub::DoNotDisturbController::Observer {
public: public:
class Observer : public base::CheckedObserver {
public:
~Observer() override = default;
// Called when the state of the item has changed.
virtual void OnSilencePhoneItemStateChanged() = 0;
};
explicit SilencePhoneQuickActionController( explicit SilencePhoneQuickActionController(
chromeos::phonehub::DoNotDisturbController* dnd_controller); chromeos::phonehub::DoNotDisturbController* dnd_controller);
~SilencePhoneQuickActionController() override; ~SilencePhoneQuickActionController() override;
...@@ -37,9 +27,6 @@ class ASH_EXPORT SilencePhoneQuickActionController ...@@ -37,9 +27,6 @@ class ASH_EXPORT SilencePhoneQuickActionController
SilencePhoneQuickActionController operator=( SilencePhoneQuickActionController operator=(
SilencePhoneQuickActionController&) = delete; SilencePhoneQuickActionController&) = delete;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
// Return true if the item is enabled/toggled. // Return true if the item is enabled/toggled.
bool IsItemEnabled(); bool IsItemEnabled();
...@@ -80,9 +67,6 @@ class ASH_EXPORT SilencePhoneQuickActionController ...@@ -80,9 +67,6 @@ class ASH_EXPORT SilencePhoneQuickActionController
// if the requested state is similar to the current state after the button is // if the requested state is similar to the current state after the button is
// pressed for a certain time. // pressed for a certain time.
std::unique_ptr<base::OneShotTimer> check_requested_state_timer_; std::unique_ptr<base::OneShotTimer> check_requested_state_timer_;
// Registered observers.
base::ObserverList<Observer> observer_list_;
}; };
} // namespace ash } // namespace ash
......
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
namespace ash { namespace ash {
class SilencePhoneQuickActionControllerTest class SilencePhoneQuickActionControllerTest : public AshTestBase {
: public AshTestBase,
public SilencePhoneQuickActionController::Observer {
public: public:
SilencePhoneQuickActionControllerTest() = default; SilencePhoneQuickActionControllerTest() = default;
...@@ -26,21 +24,16 @@ class SilencePhoneQuickActionControllerTest ...@@ -26,21 +24,16 @@ class SilencePhoneQuickActionControllerTest
controller_ = std::make_unique<SilencePhoneQuickActionController>( controller_ = std::make_unique<SilencePhoneQuickActionController>(
dnd_controller_.get()); dnd_controller_.get());
controller_->AddObserver(this);
controller_->CreateItem(); controller_->CreateItem();
} }
void TearDown() override { void TearDown() override {
controller_->RemoveObserver(this);
controller_.reset(); controller_.reset();
dnd_controller_.reset(); dnd_controller_.reset();
AshTestBase::TearDown(); AshTestBase::TearDown();
} }
protected: protected:
// SilencePhoneQuickActionController::Observer:
void OnSilencePhoneItemStateChanged() override { ++num_calls_; }
SilencePhoneQuickActionController* controller() { return controller_.get(); } SilencePhoneQuickActionController* controller() { return controller_.get(); }
chromeos::phonehub::FakeDoNotDisturbController* dnd_controller() { chromeos::phonehub::FakeDoNotDisturbController* dnd_controller() {
...@@ -52,37 +45,28 @@ class SilencePhoneQuickActionControllerTest ...@@ -52,37 +45,28 @@ class SilencePhoneQuickActionControllerTest
controller_->GetItemState(); controller_->GetItemState();
} }
size_t GetNumObserverCalls() { return num_calls_; }
private: private:
std::unique_ptr<SilencePhoneQuickActionController> controller_; std::unique_ptr<SilencePhoneQuickActionController> controller_;
std::unique_ptr<chromeos::phonehub::FakeDoNotDisturbController> std::unique_ptr<chromeos::phonehub::FakeDoNotDisturbController>
dnd_controller_; dnd_controller_;
size_t num_calls_ = 0;
}; };
TEST_F(SilencePhoneQuickActionControllerTest, ItemStateChanged) { TEST_F(SilencePhoneQuickActionControllerTest, ItemStateChanged) {
// Set request to fail to avoid triggering state's changes by the model. // Set request to fail to avoid triggering state's changes by the model.
dnd_controller()->SetShouldRequestFail(true); dnd_controller()->SetShouldRequestFail(true);
// Initially, there's one observer call during initiation.
EXPECT_EQ(1u, GetNumObserverCalls());
// Allow the button to be enabled. // Allow the button to be enabled.
dnd_controller()->SetDoNotDisturbStateInternal( dnd_controller()->SetDoNotDisturbStateInternal(
/*is_dnd_enabled=*/false, /*can_request_new_dnd_state=*/true); /*is_dnd_enabled=*/false, /*can_request_new_dnd_state=*/true);
EXPECT_EQ(2u, GetNumObserverCalls());
// Press the button to enabled state will trigger observer. // Press the button to enabled state will trigger observer.
controller()->OnButtonPressed(false /* is_now_enabled */); controller()->OnButtonPressed(false /* is_now_enabled */);
EXPECT_EQ(3u, GetNumObserverCalls());
// Item state changed to enabled. // Item state changed to enabled.
EXPECT_TRUE(controller()->IsItemEnabled()); EXPECT_TRUE(controller()->IsItemEnabled());
// Press the button to disabled state will trigger observer. // Press the button to disabled state will trigger observer.
controller()->OnButtonPressed(true /* is_now_enabled */); controller()->OnButtonPressed(true /* is_now_enabled */);
EXPECT_EQ(4u, GetNumObserverCalls());
// Item state changed to disabled. // Item state changed to disabled.
EXPECT_FALSE(controller()->IsItemEnabled()); EXPECT_FALSE(controller()->IsItemEnabled());
...@@ -94,7 +78,7 @@ TEST_F(SilencePhoneQuickActionControllerTest, CanRequestNewDndState) { ...@@ -94,7 +78,7 @@ TEST_F(SilencePhoneQuickActionControllerTest, CanRequestNewDndState) {
// Set DoNotDisturbState to not allow any new request. // Set DoNotDisturbState to not allow any new request.
dnd_controller()->SetDoNotDisturbStateInternal( dnd_controller()->SetDoNotDisturbStateInternal(
/*is_dnd_enabled=*/false, /*can_request_new_dnd_state=*/false); /*is_dnd_enabled=*/false, /*can_request_new_dnd_state=*/false);
EXPECT_EQ(1u, GetNumObserverCalls());
// Since no new state requests are allowed, expect the button to be disabled. // Since no new state requests are allowed, expect the button to be disabled.
EXPECT_FALSE(controller()->IsItemEnabled()); EXPECT_FALSE(controller()->IsItemEnabled());
EXPECT_TRUE(IsButtonDisabled()); EXPECT_TRUE(IsButtonDisabled());
...@@ -103,7 +87,7 @@ TEST_F(SilencePhoneQuickActionControllerTest, CanRequestNewDndState) { ...@@ -103,7 +87,7 @@ TEST_F(SilencePhoneQuickActionControllerTest, CanRequestNewDndState) {
// work profile. // work profile.
dnd_controller()->SetDoNotDisturbStateInternal( dnd_controller()->SetDoNotDisturbStateInternal(
/*is_dnd_enabled=*/true, /*can_request_new_dnd_state=*/false); /*is_dnd_enabled=*/true, /*can_request_new_dnd_state=*/false);
EXPECT_EQ(2u, GetNumObserverCalls());
// The button should still be disabled despite the phone has DoNotDisturb mode // The button should still be disabled despite the phone has DoNotDisturb mode
// enabled. However, the underlying toggle has been flipped to enabled. // enabled. However, the underlying toggle has been flipped to enabled.
EXPECT_TRUE(controller()->IsItemEnabled()); EXPECT_TRUE(controller()->IsItemEnabled());
...@@ -112,7 +96,6 @@ TEST_F(SilencePhoneQuickActionControllerTest, CanRequestNewDndState) { ...@@ -112,7 +96,6 @@ TEST_F(SilencePhoneQuickActionControllerTest, CanRequestNewDndState) {
// Flip toggle state back to enabled, but still in a work profile. // Flip toggle state back to enabled, but still in a work profile.
dnd_controller()->SetDoNotDisturbStateInternal( dnd_controller()->SetDoNotDisturbStateInternal(
/*is_dnd_enabled=*/false, /*can_request_new_dnd_state=*/false); /*is_dnd_enabled=*/false, /*can_request_new_dnd_state=*/false);
EXPECT_EQ(3u, GetNumObserverCalls());
EXPECT_FALSE(controller()->IsItemEnabled()); EXPECT_FALSE(controller()->IsItemEnabled());
EXPECT_TRUE(IsButtonDisabled()); EXPECT_TRUE(IsButtonDisabled());
} }
......
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