From 6aa53a1c4b11f4f28b96ded6b49ce0dfc1839cc6 Mon Sep 17 00:00:00 2001 From: "darin@google.com" Date: Mon, 11 Aug 2008 15:40:59 +0000 Subject: Made portable by use of WaitableEvent. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@652 0039d316-1c4b-4281-b951-d872f2087c98 --- .../test_shell/simple_resource_loader_bridge.cc | 35 ++++++++-------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'webkit') diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index e8dcbf2..f842db7 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -60,6 +60,7 @@ #include "base/message_loop.h" #include "base/ref_counted.h" #include "base/thread.h" +#include "base/waitable_event.h" #include "net/base/cookie_monster.h" #include "net/base/net_util.h" #include "net/base/upload_data.h" @@ -330,16 +331,12 @@ class RequestProxy : public URLRequest::Delegate, class SyncRequestProxy : public RequestProxy { public: explicit SyncRequestProxy(ResourceLoaderBridge::SyncLoadResponse* result) - : event_(::CreateEvent(NULL, TRUE, FALSE, NULL)), - result_(result) { + : event_(true, false), result_(result) { } - virtual ~SyncRequestProxy() { - CloseHandle(event_); - } - - HANDLE event() const { - return event_; + void WaitForCompletion() { + if (!event_.Wait()) + NOTREACHED(); } // -------------------------------------------------------------------------- @@ -361,12 +358,12 @@ class SyncRequestProxy : public RequestProxy { virtual void OnCompletedRequest(const URLRequestStatus& status) { result_->status = status; - ::SetEvent(event_); + event_.Signal(); } private: ResourceLoaderBridge::SyncLoadResponse* result_; - HANDLE event_; + base::WaitableEvent event_; }; //----------------------------------------------------------------------------- @@ -452,10 +449,7 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge { proxy_->Start(NULL, params_.release()); - HANDLE event = static_cast(proxy_)->event(); - - if (WaitForSingleObject(event, INFINITE) != WAIT_OBJECT_0) - NOTREACHED(); + static_cast(proxy_)->WaitForCompletion(); } private: @@ -479,27 +473,22 @@ class CookieSetter : public base::RefCountedThreadSafe { class CookieGetter : public base::RefCountedThreadSafe { public: - CookieGetter() - : event_(::CreateEvent(NULL, FALSE, FALSE, NULL)) { - } - - ~CookieGetter() { - CloseHandle(event_); + CookieGetter() : event_(false, false) { } void Get(const GURL& url) { result_ = request_context->cookie_store()->GetCookies(url); - SetEvent(event_); + event_.Signal(); } std::string GetResult() { - if (WaitForSingleObject(event_, INFINITE) != WAIT_OBJECT_0) + if (!event_.Wait()) NOTREACHED(); return result_; } private: - HANDLE event_; + base::WaitableEvent event_; std::string result_; }; -- cgit v1.1