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