update_engine: Get rid of WatchFileDescriptor.
The API is removed in the next libchrome uprev to r576297.
This CL replaces the use by new API base::FileDescriptorWatcher.
BUG=chromium:909719
TEST=Build locally. Ran cros_run_unit_tests.
Change-Id: I318b35b2d00742955f6877c4e36624e4c672827b
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/1924097
Tested-by: Qijiang Fan <fqj@google.com>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Commit-Queue: Qijiang Fan <fqj@google.com>
diff --git a/common/subprocess_unittest.cc b/common/subprocess_unittest.cc
index 8dbaa0b..19b24f4 100644
--- a/common/subprocess_unittest.cc
+++ b/common/subprocess_unittest.cc
@@ -45,6 +45,7 @@
using base::TimeDelta;
using brillo::MessageLoop;
using std::string;
+using std::unique_ptr;
using std::vector;
namespace {
@@ -73,6 +74,7 @@
brillo::BaseMessageLoop loop_{&base_loop_};
brillo::AsynchronousSignalHandler async_signal_handler_;
Subprocess subprocess_;
+ unique_ptr<base::FileDescriptorWatcher::Controller> watcher_;
};
namespace {
@@ -256,21 +258,23 @@
int fifo_fd = HANDLE_EINTR(open(fifo_path.c_str(), O_RDONLY));
EXPECT_GE(fifo_fd, 0);
- loop_.WatchFileDescriptor(FROM_HERE,
- fifo_fd,
- MessageLoop::WatchMode::kWatchRead,
- false,
- base::Bind(
- [](int fifo_fd, uint32_t tag) {
- char c;
- EXPECT_EQ(1,
- HANDLE_EINTR(read(fifo_fd, &c, 1)));
- EXPECT_EQ('X', c);
- LOG(INFO) << "Killing tag " << tag;
- Subprocess::Get().KillExec(tag);
- },
- fifo_fd,
- tag));
+ watcher_ = base::FileDescriptorWatcher::WatchReadable(
+ fifo_fd,
+ base::Bind(
+ [](unique_ptr<base::FileDescriptorWatcher::Controller>* watcher,
+ int fifo_fd,
+ uint32_t tag) {
+ char c;
+ EXPECT_EQ(1, HANDLE_EINTR(read(fifo_fd, &c, 1)));
+ EXPECT_EQ('X', c);
+ LOG(INFO) << "Killing tag " << tag;
+ Subprocess::Get().KillExec(tag);
+ *watcher = nullptr;
+ },
+ // watcher_ is no longer used outside the clousure.
+ base::Unretained(&watcher_),
+ fifo_fd,
+ tag));
// This test would leak a callback that runs when the child process exits
// unless we wait for it to run.