From 802376eb9aacca5284b76da93face73a9488bdb6 Mon Sep 17 00:00:00 2001 From: "stoyan@chromium.org" Date: Thu, 28 May 2009 19:12:46 +0000 Subject: Make automation proxy objects to ref_counted. That allows to process async notifications directly in channel background thread. Add support for listener-less ChannelProxy. BUG=none TEST=none Review URL: http://codereview.chromium.org/113722 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17093 0039d316-1c4b-4281-b951-d872f2087c98 --- .../test/automation/automation_handle_tracker.cc | 46 ++++++++++------------ 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'chrome/test/automation/automation_handle_tracker.cc') diff --git a/chrome/test/automation/automation_handle_tracker.cc b/chrome/test/automation/automation_handle_tracker.cc index b843218..db688cc 100644 --- a/chrome/test/automation/automation_handle_tracker.cc +++ b/chrome/test/automation/automation_handle_tracker.cc @@ -33,40 +33,36 @@ AutomationHandleTracker::~AutomationHandleTracker() { } void AutomationHandleTracker::Add(AutomationResourceProxy* proxy) { + AutoLock lock(map_lock_); handle_to_object_.insert(MapEntry(proxy->handle(), proxy)); } void AutomationHandleTracker::Remove(AutomationResourceProxy* proxy) { + AutoLock lock(map_lock_); HandleToObjectMap::iterator iter = handle_to_object_.find(proxy->handle()); - if (iter == handle_to_object_.end()) - return; - - HandleToObjectMap::iterator end_of_matching_objects = - handle_to_object_.upper_bound(proxy->handle()); - - while(iter != end_of_matching_objects) { - if (iter->second == proxy) { - handle_to_object_.erase(iter); - - // If we have no more proxy objects using this handle, tell the - // app that it can clean up that handle. If the proxy isn't valid, - // that means that the app has already discarded this handle, and - // thus doesn't need to be notified that the handle is unused. - if (proxy->is_valid() && handle_to_object_.count(proxy->handle()) == 0) { - sender_->Send(new AutomationMsg_HandleUnused(0, proxy->handle())); - } - return; - } - ++iter; + if (iter != handle_to_object_.end()) { + handle_to_object_.erase(iter); + sender_->Send(new AutomationMsg_HandleUnused(0, proxy->handle())); } } void AutomationHandleTracker::InvalidateHandle(AutomationHandle handle) { - HandleToObjectMap::iterator iter = handle_to_object_.lower_bound(handle); - HandleToObjectMap::const_iterator end_of_matching_objects = - handle_to_object_.upper_bound(handle); - - for (; iter != end_of_matching_objects; ++iter) { + // Called in background thread. + AutoLock lock(map_lock_); + HandleToObjectMap::iterator iter = handle_to_object_.find(handle); + if (iter != handle_to_object_.end()) { iter->second->Invalidate(); } } + +AutomationResourceProxy* AutomationHandleTracker::GetResource( + AutomationHandle handle) { + DCHECK(handle); + AutoLock lock(map_lock_); + HandleToObjectMap::iterator iter = handle_to_object_.find(handle); + if (iter == handle_to_object_.end()) + return NULL; + + iter->second->AddRef(); + return iter->second; +} -- cgit v1.1