| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_RESOURCE_TRACKER_H__ | 5 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_RESOURCE_TRACKER_H__ |
| 6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_RESOURCE_TRACKER_H__ | 6 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_RESOURCE_TRACKER_H__ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "content/common/content_notification_types.h" |
| 12 #include "content/common/notification_observer.h" | 13 #include "content/common/notification_observer.h" |
| 13 #include "content/common/notification_registrar.h" | 14 #include "content/common/notification_registrar.h" |
| 14 #include "content/common/notification_source.h" | 15 #include "content/common/notification_source.h" |
| 15 #include "content/common/notification_type.h" | |
| 16 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
| 17 | 17 |
| 18 // Template trick so that AutomationResourceTracker can be used with non-pointer | 18 // Template trick so that AutomationResourceTracker can be used with non-pointer |
| 19 // types. | 19 // types. |
| 20 template <class T> | 20 template <class T> |
| 21 struct AutomationResourceTraits { | 21 struct AutomationResourceTraits { |
| 22 typedef T ValueType; | 22 typedef T ValueType; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 template <class T> | 25 template <class T> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 // Returns the handle associated with a given resource pointer, or 0 if | 114 // Returns the handle associated with a given resource pointer, or 0 if |
| 115 // the resource is not currently in the mapping. | 115 // the resource is not currently in the mapping. |
| 116 int GetHandle(T resource) { | 116 int GetHandle(T resource) { |
| 117 return GetHandleImpl(resource); | 117 return GetHandleImpl(resource); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // NotificationObserver implementation--the only thing that this tracker | 120 // NotificationObserver implementation--the only thing that this tracker |
| 121 // does in response to notifications is to tell the AutomationProxy | 121 // does in response to notifications is to tell the AutomationProxy |
| 122 // that the associated handle is now invalid. | 122 // that the associated handle is now invalid. |
| 123 virtual void Observe(NotificationType type, | 123 virtual void Observe(int type, |
| 124 const NotificationSource& source, | 124 const NotificationSource& source, |
| 125 const NotificationDetails& details) { | 125 const NotificationDetails& details) { |
| 126 T resource = | 126 T resource = |
| 127 Source<typename AutomationResourceTraits<T>::ValueType>(source).ptr(); | 127 Source<typename AutomationResourceTraits<T>::ValueType>(source).ptr(); |
| 128 | 128 |
| 129 CloseResource(resource); | 129 CloseResource(resource); |
| 130 } | 130 } |
| 131 | 131 |
| 132 protected: | 132 protected: |
| 133 // Removes |resource| from the tracker, and handles sending the close | 133 // Removes |resource| from the tracker, and handles sending the close |
| (...skipping 13 matching lines...) Expand all Loading... |
| 147 RemoveObserver(static_cast<T>(const_cast<void*>(resource))); | 147 RemoveObserver(static_cast<T>(const_cast<void*>(resource))); |
| 148 } | 148 } |
| 149 | 149 |
| 150 NotificationRegistrar registrar_; | 150 NotificationRegistrar registrar_; |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 DISALLOW_COPY_AND_ASSIGN(AutomationResourceTracker); | 153 DISALLOW_COPY_AND_ASSIGN(AutomationResourceTracker); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_RESOURCE_TRACKER_H__ | 156 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_RESOURCE_TRACKER_H__ |
| OLD | NEW |