summaryrefslogtreecommitdiffstats
path: root/chrome/test/automation/automation_handle_tracker.cc
diff options
context:
space:
mode:
authorstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 19:12:46 +0000
committerstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 19:12:46 +0000
commit802376eb9aacca5284b76da93face73a9488bdb6 (patch)
tree705226a6750fed9a1429aaf07fe9c0a03303c759 /chrome/test/automation/automation_handle_tracker.cc
parent319d4ae6c8b2236fa7e0acf218c533a5a93af5a6 (diff)
downloadchromium_src-802376eb9aacca5284b76da93face73a9488bdb6.zip
chromium_src-802376eb9aacca5284b76da93face73a9488bdb6.tar.gz
chromium_src-802376eb9aacca5284b76da93face73a9488bdb6.tar.bz2
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
Diffstat (limited to 'chrome/test/automation/automation_handle_tracker.cc')
-rw-r--r--chrome/test/automation/automation_handle_tracker.cc46
1 files changed, 21 insertions, 25 deletions
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;
+}