OLD | NEW |
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/common/automation_messages.h" | 7 #include "chrome/common/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 27 matching lines...) Expand all Loading... |
38 handle_to_object_.insert(MapEntry(proxy->handle(), proxy)); | 38 handle_to_object_.insert(MapEntry(proxy->handle(), proxy)); |
39 } | 39 } |
40 | 40 |
41 void AutomationHandleTracker::Remove(AutomationResourceProxy* proxy) { | 41 void AutomationHandleTracker::Remove(AutomationResourceProxy* proxy) { |
42 AutoLock lock(map_lock_); | 42 AutoLock lock(map_lock_); |
43 HandleToObjectMap::iterator iter = handle_to_object_.find(proxy->handle()); | 43 HandleToObjectMap::iterator iter = handle_to_object_.find(proxy->handle()); |
44 if (iter != handle_to_object_.end()) { | 44 if (iter != handle_to_object_.end()) { |
45 AutomationHandle proxy_handle = proxy->handle(); | 45 AutomationHandle proxy_handle = proxy->handle(); |
46 handle_to_object_.erase(iter); | 46 handle_to_object_.erase(iter); |
47 if (channel_) | 47 if (channel_) |
48 channel_->Send(new AutomationMsg_HandleUnused(0, proxy_handle)); | 48 channel_->Send(new AutomationMsg_HandleUnused(proxy_handle)); |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 void AutomationHandleTracker::InvalidateHandle(AutomationHandle handle) { | 52 void AutomationHandleTracker::InvalidateHandle(AutomationHandle handle) { |
53 // Called in background thread. | 53 // Called in background thread. |
54 AutoLock lock(map_lock_); | 54 AutoLock lock(map_lock_); |
55 HandleToObjectMap::iterator iter = handle_to_object_.find(handle); | 55 HandleToObjectMap::iterator iter = handle_to_object_.find(handle); |
56 if (iter != handle_to_object_.end()) { | 56 if (iter != handle_to_object_.end()) { |
57 scoped_refptr<AutomationResourceProxy> proxy = iter->second; | 57 scoped_refptr<AutomationResourceProxy> proxy = iter->second; |
58 handle_to_object_.erase(iter); | 58 handle_to_object_.erase(iter); |
59 proxy->Invalidate(); | 59 proxy->Invalidate(); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 AutomationResourceProxy* AutomationHandleTracker::GetResource( | 63 AutomationResourceProxy* AutomationHandleTracker::GetResource( |
64 AutomationHandle handle) { | 64 AutomationHandle handle) { |
65 AutoLock lock(map_lock_); | 65 AutoLock lock(map_lock_); |
66 HandleToObjectMap::iterator iter = handle_to_object_.find(handle); | 66 HandleToObjectMap::iterator iter = handle_to_object_.find(handle); |
67 if (iter == handle_to_object_.end()) | 67 if (iter == handle_to_object_.end()) |
68 return NULL; | 68 return NULL; |
69 | 69 |
70 iter->second->AddRef(); | 70 iter->second->AddRef(); |
71 return iter->second; | 71 return iter->second; |
72 } | 72 } |
OLD | NEW |