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 // This file defines a mapping between Automation Proxy objects and | 5 // This file defines a mapping between Automation Proxy objects and |
6 // their associated app-side handles. | 6 // their associated app-side handles. |
7 | 7 |
8 #ifndef CHROME_TEST_AUTOMATION_AUTOMATION_HANDLE_TRACKER_H__ | 8 #ifndef CHROME_TEST_AUTOMATION_AUTOMATION_HANDLE_TRACKER_H__ |
9 #define CHROME_TEST_AUTOMATION_AUTOMATION_HANDLE_TRACKER_H__ | 9 #define CHROME_TEST_AUTOMATION_AUTOMATION_HANDLE_TRACKER_H__ |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/lock.h" |
| 15 #include "base/ref_counted.h" |
14 | 16 |
15 // This represents a value that the app's AutomationProvider returns | 17 // This represents a value that the app's AutomationProvider returns |
16 // when asked for a resource (like a window or tab). | 18 // when asked for a resource (like a window or tab). |
17 typedef int AutomationHandle; | 19 typedef int AutomationHandle; |
18 | 20 |
19 class AutomationHandleTracker; | 21 class AutomationHandleTracker; |
20 class AutomationMessageSender; | 22 class AutomationMessageSender; |
21 | 23 |
22 class AutomationResourceProxy { | 24 class AutomationResourceProxy |
| 25 : public base::RefCountedThreadSafe<AutomationResourceProxy> { |
23 public: | 26 public: |
24 AutomationResourceProxy(AutomationHandleTracker* tracker, | 27 AutomationResourceProxy(AutomationHandleTracker* tracker, |
25 AutomationMessageSender* sender, | 28 AutomationMessageSender* sender, |
26 AutomationHandle handle); | 29 AutomationHandle handle); |
27 virtual ~AutomationResourceProxy(); | 30 virtual ~AutomationResourceProxy(); |
28 | 31 |
29 // Marks this proxy object as no longer valid; this generally means | 32 // Marks this proxy object as no longer valid; this generally means |
30 // that the corresponding resource on the app side is gone. | 33 // that the corresponding resource on the app side is gone. |
31 void Invalidate() { is_valid_ = false; } | 34 void Invalidate() { is_valid_ = false; } |
32 bool is_valid() const { return is_valid_; } | 35 bool is_valid() const { return is_valid_; } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // that handle. This is a no-op if the proxy object is not currently | 84 // that handle. This is a no-op if the proxy object is not currently |
82 // in the tracker. | 85 // in the tracker. |
83 void Remove(AutomationResourceProxy* proxy); | 86 void Remove(AutomationResourceProxy* proxy); |
84 | 87 |
85 // Marks all proxy objects related to a given handle invalid. This is | 88 // Marks all proxy objects related to a given handle invalid. This is |
86 // used when a resource (like a window) on the app side is closed, meaning | 89 // used when a resource (like a window) on the app side is closed, meaning |
87 // that no further operations can be completed using the handle that | 90 // that no further operations can be completed using the handle that |
88 // identified that resource. | 91 // identified that resource. |
89 void InvalidateHandle(AutomationHandle handle); | 92 void InvalidateHandle(AutomationHandle handle); |
90 | 93 |
| 94 AutomationResourceProxy* GetResource(AutomationHandle handle); |
91 private: | 95 private: |
92 typedef | 96 typedef |
93 std::multimap<AutomationHandle, AutomationResourceProxy*> HandleToObjectMap; | 97 std::map<AutomationHandle, AutomationResourceProxy*> HandleToObjectMap; |
94 typedef std::pair<AutomationHandle, AutomationResourceProxy*> MapEntry; | 98 typedef std::pair<AutomationHandle, AutomationResourceProxy*> MapEntry; |
95 | 99 |
96 HandleToObjectMap handle_to_object_; | 100 HandleToObjectMap handle_to_object_; |
97 | 101 |
98 AutomationMessageSender* sender_; | 102 AutomationMessageSender* sender_; |
99 | 103 Lock map_lock_; |
100 DISALLOW_EVIL_CONSTRUCTORS(AutomationHandleTracker); | 104 DISALLOW_EVIL_CONSTRUCTORS(AutomationHandleTracker); |
101 }; | 105 }; |
102 | 106 |
103 #endif // CHROME_TEST_AUTOMATION_AUTOMATION_HANDLE_TRACKER_H__ | 107 #endif // CHROME_TEST_AUTOMATION_AUTOMATION_HANDLE_TRACKER_H__ |
OLD | NEW |