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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/automation/automation_handle_tracker.h" 5 #include "chrome/test/automation/automation_handle_tracker.h"
6 6
7 #include "chrome/test/automation/automation_messages.h" 7 #include "chrome/test/automation/automation_messages.h"
8 #include "chrome/test/automation/automation_proxy.h" 8 #include "chrome/test/automation/automation_proxy.h"
9 9
10 AutomationResourceProxy::AutomationResourceProxy( 10 AutomationResourceProxy::AutomationResourceProxy(
(...skipping 15 matching lines...) Expand all
26 // Tell any live objects that the tracker is going away so they don't try to 26 // Tell any live objects that the tracker is going away so they don't try to
27 // call us when they are being destroyed. 27 // call us when they are being destroyed.
28 for (HandleToObjectMap::iterator iter = handle_to_object_.begin(); 28 for (HandleToObjectMap::iterator iter = handle_to_object_.begin();
29 iter != handle_to_object_.end(); ++iter) { 29 iter != handle_to_object_.end(); ++iter) {
30 iter->second->Invalidate(); 30 iter->second->Invalidate();
31 iter->second->TrackerGone(); 31 iter->second->TrackerGone();
32 } 32 }
33 } 33 }
34 34
35 void AutomationHandleTracker::Add(AutomationResourceProxy* proxy) { 35 void AutomationHandleTracker::Add(AutomationResourceProxy* proxy) {
36 AutoLock lock(map_lock_);
36 handle_to_object_.insert(MapEntry(proxy->handle(), proxy)); 37 handle_to_object_.insert(MapEntry(proxy->handle(), proxy));
37 } 38 }
38 39
39 void AutomationHandleTracker::Remove(AutomationResourceProxy* proxy) { 40 void AutomationHandleTracker::Remove(AutomationResourceProxy* proxy) {
41 AutoLock lock(map_lock_);
40 HandleToObjectMap::iterator iter = handle_to_object_.find(proxy->handle()); 42 HandleToObjectMap::iterator iter = handle_to_object_.find(proxy->handle());
41 if (iter == handle_to_object_.end()) 43 if (iter != handle_to_object_.end()) {
42 return; 44 handle_to_object_.erase(iter);
43 45 sender_->Send(new AutomationMsg_HandleUnused(0, proxy->handle()));
44 HandleToObjectMap::iterator end_of_matching_objects =
45 handle_to_object_.upper_bound(proxy->handle());
46
47 while(iter != end_of_matching_objects) {
48 if (iter->second == proxy) {
49 handle_to_object_.erase(iter);
50
51 // If we have no more proxy objects using this handle, tell the
52 // app that it can clean up that handle. If the proxy isn't valid,
53 // that means that the app has already discarded this handle, and
54 // thus doesn't need to be notified that the handle is unused.
55 if (proxy->is_valid() && handle_to_object_.count(proxy->handle()) == 0) {
56 sender_->Send(new AutomationMsg_HandleUnused(0, proxy->handle()));
57 }
58 return;
59 }
60 ++iter;
61 } 46 }
62 } 47 }
63 48
64 void AutomationHandleTracker::InvalidateHandle(AutomationHandle handle) { 49 void AutomationHandleTracker::InvalidateHandle(AutomationHandle handle) {
65 HandleToObjectMap::iterator iter = handle_to_object_.lower_bound(handle); 50 // Called in background thread.
66 HandleToObjectMap::const_iterator end_of_matching_objects = 51 AutoLock lock(map_lock_);
67 handle_to_object_.upper_bound(handle); 52 HandleToObjectMap::iterator iter = handle_to_object_.find(handle);
68 53 if (iter != handle_to_object_.end()) {
69 for (; iter != end_of_matching_objects; ++iter) {
70 iter->second->Invalidate(); 54 iter->second->Invalidate();
71 } 55 }
72 } 56 }
57
58 AutomationResourceProxy* AutomationHandleTracker::GetResource(
59 AutomationHandle handle) {
60 DCHECK(handle);
61 AutoLock lock(map_lock_);
62 HandleToObjectMap::iterator iter = handle_to_object_.find(handle);
63 if (iter == handle_to_object_.end())
64 return NULL;
65
66 iter->second->AddRef();
67 return iter->second;
68 }
OLDNEW
« 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