Commit 51f3aacf authored by rvargas's avatar rvargas Committed by Commit bot

Add an explicit ObjectWatcher::IsWatching() method

This removes the need to compare a raw handle against
a predefined value from the caller's code.

BUG=none
TEST=base_unittests

Review URL: https://codereview.chromium.org/868143004

Cr-Commit-Position: refs/heads/master@{#314687}
parent 50b79dc6
......@@ -77,7 +77,11 @@ bool ObjectWatcher::StopWatching() {
return true;
}
HANDLE ObjectWatcher::GetWatchedObject() {
bool ObjectWatcher::IsWatching() const {
return object_ != NULL;
}
HANDLE ObjectWatcher::GetWatchedObject() const {
return object_;
}
......
......@@ -74,9 +74,11 @@ class BASE_EXPORT ObjectWatcher : public MessageLoop::DestructionObserver {
//
bool StopWatching();
// Returns the handle of the object being watched, or NULL if the object
// watcher is stopped.
HANDLE GetWatchedObject();
// Returns true if currently watching an object.
bool IsWatching() const;
// Returns the handle of the object being watched.
HANDLE GetWatchedObject() const;
private:
// Called on a background thread when done waiting.
......
......@@ -37,7 +37,7 @@ void RunTest_BasicSignal(MessageLoop::Type message_loop_type) {
MessageLoop message_loop(message_loop_type);
ObjectWatcher watcher;
EXPECT_EQ(NULL, watcher.GetWatchedObject());
EXPECT_FALSE(watcher.IsWatching());
// A manual-reset event that is not yet signaled.
HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL);
......@@ -45,13 +45,14 @@ void RunTest_BasicSignal(MessageLoop::Type message_loop_type) {
QuitDelegate delegate;
bool ok = watcher.StartWatching(event, &delegate);
EXPECT_TRUE(ok);
EXPECT_TRUE(watcher.IsWatching());
EXPECT_EQ(event, watcher.GetWatchedObject());
SetEvent(event);
MessageLoop::current()->Run();
EXPECT_EQ(NULL, watcher.GetWatchedObject());
EXPECT_FALSE(watcher.IsWatching());
CloseHandle(event);
}
......@@ -115,7 +116,7 @@ void RunTest_SignalBeforeWatch(MessageLoop::Type message_loop_type) {
MessageLoop::current()->Run();
EXPECT_EQ(NULL, watcher.GetWatchedObject());
EXPECT_FALSE(watcher.IsWatching());
CloseHandle(event);
}
......
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