Commit dd4945c9 authored by Karan Bhatia's avatar Karan Bhatia Committed by Commit Bot

Revert "[hid] Replicate self-destruct logic in connection fake"

This reverts commit 1b26f574.

Reason for revert: Causes HidServiceTest.OpenAndNavigateCrossOrigin
to fail.

Original change's description:
> [hid] Replicate self-destruct logic in connection fake
>
> HidConnectionImpl is self-owned and will self-destruct on
> disconnection of the HidConnection or HidConnectionWatcher.
> This CL modifies the FakeHidConnection used in tests so it
> behaves the same way.
>
> BUG=1126689
>
> Change-Id: I8bbdcca7c77699749c6022f01b8a456c4891cdb8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441151
> Commit-Queue: Reilly Grant <reillyg@chromium.org>
> Auto-Submit: Matt Reynolds <mattreynolds@chromium.org>
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#812858}

TBR=reillyg@chromium.org,mattreynolds@chromium.org,andypaicu@chromium.org

Change-Id: Ibd1de02feee8d39e071a3291f3dce2062eff3270
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
TBR: mattreynolds@chromium.org
Bug: 1126689, 1134346
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2443760
Commit-Queue: Karan Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812941}
parent 4aaf38d5
...@@ -370,18 +370,17 @@ TEST_F(HidServiceTest, RevokeDevicePermission) { ...@@ -370,18 +370,17 @@ TEST_F(HidServiceTest, RevokeDevicePermission) {
EXPECT_TRUE(contents()->IsConnectedToHidDevice()); EXPECT_TRUE(contents()->IsConnectedToHidDevice());
EXPECT_TRUE(connection); EXPECT_TRUE(connection);
base::RunLoop disconnect_loop;
connection.set_disconnect_handler(
base::BindLambdaForTesting([&] { disconnect_loop.Quit(); }));
// Simulate user revoking permission. // Simulate user revoking permission.
EXPECT_CALL(hid_delegate(), HasDevicePermission).WillOnce(Return(false)); EXPECT_CALL(hid_delegate(), HasDevicePermission).WillOnce(Return(false));
url::Origin origin = url::Origin::Create(GURL(kTestUrl)); url::Origin origin = url::Origin::Create(GURL(kTestUrl));
hid_delegate().OnPermissionRevoked(origin, origin); hid_delegate().OnPermissionRevoked(origin, origin);
disconnect_loop.Run(); // TODO(mattreynolds): Use a disconnect handler with a run loop instead of the
// potentially flaky `RunUntilIdle`. This depends on fixing
// `FakeHidConnection` to monitor the watcher just as `HidConnectionImpl`
// does.
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(contents()->IsConnectedToHidDevice()); EXPECT_FALSE(contents()->IsConnectedToHidDevice());
EXPECT_FALSE(connection.is_connected());
} }
} // namespace content } // namespace content
...@@ -13,23 +13,8 @@ ...@@ -13,23 +13,8 @@
namespace device { namespace device {
FakeHidConnection::FakeHidConnection( FakeHidConnection::FakeHidConnection(mojom::HidDeviceInfoPtr device)
mojom::HidDeviceInfoPtr device, : device_(std::move(device)) {}
mojo::PendingReceiver<mojom::HidConnection> receiver,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
mojo::PendingRemote<mojom::HidConnectionWatcher> watcher)
: receiver_(this, std::move(receiver)),
device_(std::move(device)),
watcher_(std::move(watcher)) {
receiver_.set_disconnect_handler(base::BindOnce(
[](FakeHidConnection* self) { delete self; }, base::Unretained(this)));
if (watcher_) {
watcher_.set_disconnect_handler(base::BindOnce(
[](FakeHidConnection* self) { delete self; }, base::Unretained(this)));
}
if (connection_client)
client_.Bind(std::move(connection_client));
}
FakeHidConnection::~FakeHidConnection() = default; FakeHidConnection::~FakeHidConnection() = default;
...@@ -150,10 +135,9 @@ void FakeHidManager::Connect( ...@@ -150,10 +135,9 @@ void FakeHidManager::Connect(
} }
mojo::PendingRemote<mojom::HidConnection> connection; mojo::PendingRemote<mojom::HidConnection> connection;
// FakeHidConnection is self-owned. mojo::MakeSelfOwnedReceiver(
new FakeHidConnection(devices_[device_guid]->Clone(), std::make_unique<FakeHidConnection>(devices_[device_guid]->Clone()),
connection.InitWithNewPipeAndPassReceiver(), connection.InitWithNewPipeAndPassReceiver());
std::move(connection_client), std::move(watcher));
std::move(callback).Run(std::move(connection)); std::move(callback).Run(std::move(connection));
} }
......
...@@ -19,11 +19,7 @@ namespace device { ...@@ -19,11 +19,7 @@ namespace device {
class FakeHidConnection : public mojom::HidConnection { class FakeHidConnection : public mojom::HidConnection {
public: public:
FakeHidConnection( explicit FakeHidConnection(mojom::HidDeviceInfoPtr device);
mojom::HidDeviceInfoPtr device,
mojo::PendingReceiver<mojom::HidConnection> receiver,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
mojo::PendingRemote<mojom::HidConnectionWatcher> watcher);
FakeHidConnection(FakeHidConnection&) = delete; FakeHidConnection(FakeHidConnection&) = delete;
FakeHidConnection& operator=(FakeHidConnection&) = delete; FakeHidConnection& operator=(FakeHidConnection&) = delete;
~FakeHidConnection() override; ~FakeHidConnection() override;
...@@ -41,10 +37,7 @@ class FakeHidConnection : public mojom::HidConnection { ...@@ -41,10 +37,7 @@ class FakeHidConnection : public mojom::HidConnection {
SendFeatureReportCallback callback) override; SendFeatureReportCallback callback) override;
private: private:
mojo::Receiver<mojom::HidConnection> receiver_;
mojom::HidDeviceInfoPtr device_; mojom::HidDeviceInfoPtr device_;
mojo::Remote<mojom::HidConnectionClient> client_;
mojo::Remote<mojom::HidConnectionWatcher> watcher_;
}; };
class FakeHidManager : public mojom::HidManager { class FakeHidManager : public mojom::HidManager {
......
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