Skip to content

Commit

Permalink
[freezing] Add HID and serial port connections as freezing opt-outs.
Browse files Browse the repository at this point in the history
In accordance with go/tab-freezing-on-energy-saver-prd

Bug: 325954772
Change-Id: I77ff0bf48ce892ed644ef96715f09844127d45a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5847609
Reviewed-by: Patrick Monette <[email protected]>
Commit-Queue: Francois Pierre Doray <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1356469}
  • Loading branch information
fdoray authored and Chromium LUCI CQ committed Sep 17, 2024
1 parent e753bf9 commit 5146877
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ class PageLiveStateDataImpl
void SetIsConnectedToBluetoothDeviceForTesting(bool value) override {
set_is_connected_to_bluetooth_device(value);
}
void SetIsConnectedToHidDeviceForTesting(bool value) override {
set_is_connected_to_hid_device(value);
}
void SetIsConnectedToSerialPortForTesting(bool value) override {
set_is_connected_to_serial_port(value);
}
void SetIsCapturingVideoForTesting(bool value) override {
set_is_capturing_video(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const char* CannotFreezeReasonToString(CannotFreezeReason reason) {
return "connected to USB device";
case CannotFreezeReason::kConnectedToBluetoothDevice:
return "connected to Bluetooth device";
case CannotFreezeReason::kConnectedToHidDevice:
return "connected to HID device";
case CannotFreezeReason::kConnectedToSerialPort:
return "connected to serial port";
case CannotFreezeReason::kCapturingVideo:
return "capturing video";
case CannotFreezeReason::kCapturingAudio:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum class CannotFreezeReason {
kHoldingIndexedDBLock,
kConnectedToUsbDevice,
kConnectedToBluetoothDevice,
kConnectedToHidDevice,
kConnectedToSerialPort,
kCapturingVideo,
kCapturingAudio,
kBeingMirrored,
Expand Down
24 changes: 24 additions & 0 deletions components/performance_manager/freezing/freezing_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ bool IsPageConnectedToBluetoothDevice(const PageNode* page_node) {
->IsConnectedToBluetoothDevice();
}

bool IsPageConnectedToHidDevice(const PageNode* page_node) {
return PageLiveStateDecorator::Data::FromPageNode(page_node)
->IsConnectedToHidDevice();
}

bool IsPageConnectedToSerialPort(const PageNode* page_node) {
return PageLiveStateDecorator::Data::FromPageNode(page_node)
->IsConnectedToSerialPort();
}

bool IsPageCapturingVideo(const PageNode* page_node) {
return PageLiveStateDecorator::Data::FromPageNode(page_node)
->IsCapturingVideo();
Expand Down Expand Up @@ -479,6 +489,20 @@ void FreezingPolicy::OnIsConnectedToBluetoothDeviceChanged(
CannotFreezeReason::kConnectedToBluetoothDevice);
}

void FreezingPolicy::OnIsConnectedToHidDeviceChanged(
const PageNode* page_node) {
OnCannotFreezeReasonChange(page_node,
/*add=*/IsPageConnectedToHidDevice(page_node),
CannotFreezeReason::kConnectedToHidDevice);
}

void FreezingPolicy::OnIsConnectedToSerialPortChanged(
const PageNode* page_node) {
OnCannotFreezeReasonChange(page_node,
/*add=*/IsPageConnectedToSerialPort(page_node),
CannotFreezeReason::kConnectedToSerialPort);
}

void FreezingPolicy::OnIsCapturingVideoChanged(const PageNode* page_node) {
OnCannotFreezeReasonChange(page_node, /*add=*/IsPageCapturingVideo(page_node),
CannotFreezeReason::kCapturingVideo);
Expand Down
2 changes: 2 additions & 0 deletions components/performance_manager/freezing/freezing_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class FreezingPolicy : public PageNode::ObserverDefaultImpl,
void OnIsConnectedToUSBDeviceChanged(const PageNode* page_node) override;
void OnIsConnectedToBluetoothDeviceChanged(
const PageNode* page_node) override;
void OnIsConnectedToHidDeviceChanged(const PageNode* page_node) override;
void OnIsConnectedToSerialPortChanged(const PageNode* page_node) override;
void OnIsCapturingVideoChanged(const PageNode* page_node) override;
void OnIsCapturingAudioChanged(const PageNode* page_node) override;
void OnIsBeingMirroredChanged(const PageNode* page_node) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,56 @@ TEST_F(FreezingPolicyTest, ConnectedToBluetoothDeviceWhenFrozen) {
VerifyFreezerExpectations();
}

TEST_F(FreezingPolicyTest, FreezeVoteWhenConnectedToHidDevice) {
PageLiveStateDecorator::Data::GetOrCreateForPageNode(page_node())
->SetIsConnectedToHidDeviceForTesting(true);

// Don't expect freezing.
policy()->AddFreezeVote(page_node());

// Expect freezing after disconnecting from HID device.
EXPECT_CALL(*freezer(), MaybeFreezePageNode(page_node()));
PageLiveStateDecorator::Data::GetOrCreateForPageNode(page_node())
->SetIsConnectedToHidDeviceForTesting(false);
VerifyFreezerExpectations();
}

TEST_F(FreezingPolicyTest, ConnectedToHidDeviceWhenFrozen) {
EXPECT_CALL(*freezer(), MaybeFreezePageNode(page_node()));
policy()->AddFreezeVote(page_node());
VerifyFreezerExpectations();

EXPECT_CALL(*freezer(), UnfreezePageNode(page_node()));
PageLiveStateDecorator::Data::GetOrCreateForPageNode(page_node())
->SetIsConnectedToHidDeviceForTesting(true);
VerifyFreezerExpectations();
}

TEST_F(FreezingPolicyTest, FreezeVoteWhenConnectedToSerialPort) {
PageLiveStateDecorator::Data::GetOrCreateForPageNode(page_node())
->SetIsConnectedToSerialPortForTesting(true);

// Don't expect freezing.
policy()->AddFreezeVote(page_node());

// Expect freezing after disconnecting from HID device.
EXPECT_CALL(*freezer(), MaybeFreezePageNode(page_node()));
PageLiveStateDecorator::Data::GetOrCreateForPageNode(page_node())
->SetIsConnectedToSerialPortForTesting(false);
VerifyFreezerExpectations();
}

TEST_F(FreezingPolicyTest, ConnectedToSerialPortWhenFrozen) {
EXPECT_CALL(*freezer(), MaybeFreezePageNode(page_node()));
policy()->AddFreezeVote(page_node());
VerifyFreezerExpectations();

EXPECT_CALL(*freezer(), UnfreezePageNode(page_node()));
PageLiveStateDecorator::Data::GetOrCreateForPageNode(page_node())
->SetIsConnectedToSerialPortForTesting(true);
VerifyFreezerExpectations();
}

TEST_F(FreezingPolicyTest, FreezeVoteWhenCapturingVideo) {
PageLiveStateDecorator::Data::GetOrCreateForPageNode(page_node())
->SetIsCapturingVideoForTesting(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class PageLiveStateDecorator::Data {

virtual void SetIsConnectedToUSBDeviceForTesting(bool value) = 0;
virtual void SetIsConnectedToBluetoothDeviceForTesting(bool value) = 0;
virtual void SetIsConnectedToHidDeviceForTesting(bool value) = 0;
virtual void SetIsConnectedToSerialPortForTesting(bool value) = 0;
virtual void SetIsCapturingVideoForTesting(bool value) = 0;
virtual void SetIsCapturingAudioForTesting(bool value) = 0;
virtual void SetIsBeingMirroredForTesting(bool value) = 0;
Expand Down

0 comments on commit 5146877

Please sign in to comment.