Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9006)

Unified Diff: chrome/test/automation/automation_handle_tracker.cc

Issue 113722: Make automation proxy objects to ref_counted. That allows to process async no... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/automation/automation_handle_tracker.h ('k') | chrome/test/automation/automation_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/automation/automation_handle_tracker.cc
===================================================================
--- chrome/test/automation/automation_handle_tracker.cc (revision 17078)
+++ chrome/test/automation/automation_handle_tracker.cc (working copy)
@@ -33,40 +33,36 @@
}
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;
+}
« no previous file with comments | « chrome/test/automation/automation_handle_tracker.h ('k') | chrome/test/automation/automation_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698