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

Side by Side Diff: chrome/browser/automation/automation_resource_tracker.h

Issue 10553010: Rename IPC::Channel and IPC::Sender in src/chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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) 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/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/notification_source.h" 14 #include "content/public/browser/notification_source.h"
15 #include "content/public/browser/notification_types.h" 15 #include "content/public/browser/notification_types.h"
16 #include "ipc/ipc_message.h" 16 #include "ipc/ipc_sender.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>
26 struct AutomationResourceTraits<T*> { 26 struct AutomationResourceTraits<T*> {
27 typedef T ValueType; 27 typedef T ValueType;
28 }; 28 };
29 29
30 // This class exists for the sole purpose of allowing some of the implementation 30 // This class exists for the sole purpose of allowing some of the implementation
31 // of AutomationResourceTracker to live in a .cc file. 31 // of AutomationResourceTracker to live in a .cc file.
32 class AutomationResourceTrackerImpl { 32 class AutomationResourceTrackerImpl {
33 public: 33 public:
34 explicit AutomationResourceTrackerImpl(IPC::Message::Sender* sender); 34 explicit AutomationResourceTrackerImpl(IPC::Sender* sender);
35 virtual ~AutomationResourceTrackerImpl(); 35 virtual ~AutomationResourceTrackerImpl();
36 36
37 protected: 37 protected:
38 // These need to be implemented in AutomationResourceTracker, 38 // These need to be implemented in AutomationResourceTracker,
39 // since it needs to call the subclass's type-specific notification 39 // since it needs to call the subclass's type-specific notification
40 // registration functions. 40 // registration functions.
41 virtual void AddObserverTypeProxy(const void* resource) = 0; 41 virtual void AddObserverTypeProxy(const void* resource) = 0;
42 virtual void RemoveObserverTypeProxy(const void* resource) = 0; 42 virtual void RemoveObserverTypeProxy(const void* resource) = 0;
43 43
44 int AddImpl(const void* resource); 44 int AddImpl(const void* resource);
45 void RemoveImpl(const void* resource); 45 void RemoveImpl(const void* resource);
46 int GenerateHandle(); 46 int GenerateHandle();
47 bool ContainsResourceImpl(const void* resource); 47 bool ContainsResourceImpl(const void* resource);
48 bool ContainsHandleImpl(int handle); 48 bool ContainsHandleImpl(int handle);
49 const void* GetResourceImpl(int handle); 49 const void* GetResourceImpl(int handle);
50 int GetHandleImpl(const void* resource); 50 int GetHandleImpl(const void* resource);
51 void HandleCloseNotification(const void* resource); 51 void HandleCloseNotification(const void* resource);
52 52
53 private: 53 private:
54 typedef std::map<const void*, int> ResourceToHandleMap; 54 typedef std::map<const void*, int> ResourceToHandleMap;
55 typedef std::map<int, const void*> HandleToResourceMap; 55 typedef std::map<int, const void*> HandleToResourceMap;
56 56
57 ResourceToHandleMap resource_to_handle_; 57 ResourceToHandleMap resource_to_handle_;
58 HandleToResourceMap handle_to_resource_; 58 HandleToResourceMap handle_to_resource_;
59 59
60 IPC::Message::Sender* sender_; 60 IPC::Sender* sender_;
61 61
62 DISALLOW_COPY_AND_ASSIGN(AutomationResourceTrackerImpl); 62 DISALLOW_COPY_AND_ASSIGN(AutomationResourceTrackerImpl);
63 }; 63 };
64 64
65 // This template defines a superclass for an object that wants to track 65 // This template defines a superclass for an object that wants to track
66 // a particular kind of application resource (like windows or tabs) for 66 // a particular kind of application resource (like windows or tabs) for
67 // automation purposes. The only things that a subclass should need to 67 // automation purposes. The only things that a subclass should need to
68 // define are AddObserver and RemoveObserver for the given resource's 68 // define are AddObserver and RemoveObserver for the given resource's
69 // close notifications. 69 // close notifications.
70 template <class T> 70 template <class T>
71 class AutomationResourceTracker : public AutomationResourceTrackerImpl, 71 class AutomationResourceTracker : public AutomationResourceTrackerImpl,
72 public content::NotificationObserver { 72 public content::NotificationObserver {
73 public: 73 public:
74 explicit AutomationResourceTracker(IPC::Message::Sender* automation) 74 explicit AutomationResourceTracker(IPC::Sender* automation)
75 : AutomationResourceTrackerImpl(automation) {} 75 : AutomationResourceTrackerImpl(automation) {}
76 76
77 // The implementations for these should call the NotificationService 77 // The implementations for these should call the NotificationService
78 // to add and remove this object as an observer for the appropriate 78 // to add and remove this object as an observer for the appropriate
79 // resource closing notification. 79 // resource closing notification.
80 virtual void AddObserver(T resource) = 0; 80 virtual void AddObserver(T resource) = 0;
81 virtual void RemoveObserver(T resource) = 0; 81 virtual void RemoveObserver(T resource) = 0;
82 82
83 // Adds the given resource to this tracker, and returns a handle that 83 // Adds the given resource to this tracker, and returns a handle that
84 // can be used to refer to that resource. If the resource is already 84 // can be used to refer to that resource. If the resource is already
85 // being tracked, the handle may be the same as one returned previously. 85 // being tracked, the handle may be the same as one returned previously.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 RemoveObserver(static_cast<T>(const_cast<void*>(resource))); 147 RemoveObserver(static_cast<T>(const_cast<void*>(resource)));
148 } 148 }
149 149
150 content::NotificationRegistrar registrar_; 150 content::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__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698