OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef InspectorBaseAgent_h | 31 #ifndef InspectorBaseAgent_h |
32 #define InspectorBaseAgent_h | 32 #define InspectorBaseAgent_h |
33 | 33 |
34 #include "InspectorBackendDispatcher.h" | 34 #include "InspectorBackendDispatcher.h" |
35 #include <wtf/Forward.h> | 35 #include "wtf/Forward.h" |
36 #include <wtf/Vector.h> | 36 #include "wtf/PassOwnPtr.h" |
37 #include <wtf/text/WTFString.h> | 37 #include "wtf/RefCounted.h" |
| 38 #include "wtf/Vector.h" |
| 39 #include "wtf/text/WTFString.h" |
38 | 40 |
39 namespace WebCore { | 41 namespace WebCore { |
40 | 42 |
41 class InspectorFrontend; | 43 class InspectorFrontend; |
42 class InspectorCompositeState; | 44 class InspectorCompositeState; |
43 class InspectorState; | 45 class InspectorState; |
44 class InstrumentingAgents; | 46 class InstrumentingAgents; |
45 | 47 |
46 class InspectorBaseAgentInterface { | 48 class InspectorBaseAgent : public RefCounted<InspectorBaseAgent> { |
47 public: | 49 public: |
48 InspectorBaseAgentInterface(const String&, InstrumentingAgents*, InspectorCo
mpositeState*); | 50 InspectorBaseAgent(InstrumentingAgents*, InspectorState*); |
49 virtual ~InspectorBaseAgentInterface(); | 51 virtual ~InspectorBaseAgent(); |
50 | 52 |
| 53 // FIXME(kaznacheev) Remove the below 4 methods once all agent instances are
created on enable (see crbug.com/248092) |
51 virtual void setFrontend(InspectorFrontend*) { } | 54 virtual void setFrontend(InspectorFrontend*) { } |
52 virtual void clearFrontend() { } | 55 virtual void clearFrontend() { } |
53 virtual void restore() { } | 56 virtual void restore() { } |
54 virtual void registerInDispatcher(InspectorBackendDispatcher*) = 0; | |
55 virtual void discardAgent() { } | 57 virtual void discardAgent() { } |
56 | 58 |
57 String name() { return m_name; } | |
58 | |
59 virtual void reportMemoryUsage(MemoryObjectInfo*) const; | 59 virtual void reportMemoryUsage(MemoryObjectInfo*) const; |
60 | 60 |
| 61 protected: |
| 62 InstrumentingAgents* m_instrumentingAgents; |
| 63 InspectorState* m_state; |
| 64 }; |
| 65 |
| 66 class InspectorBaseFactoryInterface { |
| 67 public: |
| 68 |
| 69 InspectorBaseFactoryInterface(const String& name, InstrumentingAgents*, Insp
ectorCompositeState*); |
| 70 virtual ~InspectorBaseFactoryInterface(); |
| 71 |
| 72 void setAgent(PassRefPtr<InspectorBaseAgent>); |
| 73 |
| 74 virtual void setFrontend(InspectorFrontend*); |
| 75 virtual void clearFrontend(); |
| 76 virtual void restore(); |
| 77 virtual void registerInDispatcher(InspectorBackendDispatcher*) = 0; |
| 78 virtual void discardDependencies(); |
| 79 |
| 80 virtual void reportMemoryUsage(MemoryObjectInfo*) const; |
| 81 |
61 protected: | 82 protected: |
62 InstrumentingAgents* m_instrumentingAgents; | 83 InstrumentingAgents* m_instrumentingAgents; |
63 InspectorState* m_state; | 84 InspectorState* m_state; |
64 | 85 |
| 86 RefPtr<InspectorBaseAgent> m_agent; |
| 87 |
65 private: | 88 private: |
66 String m_name; | 89 InspectorFrontend* m_frontend; |
67 }; | 90 }; |
68 | 91 |
69 class InspectorAgentRegistry { | 92 class InspectorFactoryRegistry { |
70 public: | 93 public: |
71 void append(PassOwnPtr<InspectorBaseAgentInterface>); | 94 void append(PassOwnPtr<InspectorBaseFactoryInterface>); |
72 | 95 |
73 void setFrontend(InspectorFrontend*); | 96 void setFrontend(InspectorFrontend*); |
74 void clearFrontend(); | 97 void clearFrontend(); |
75 void restore(); | 98 void restore(); |
76 void registerInDispatcher(InspectorBackendDispatcher*); | 99 void registerInDispatcher(InspectorBackendDispatcher*); |
77 void discardAgents(); | 100 void discardDependencies(); |
78 | 101 |
79 virtual void reportMemoryUsage(MemoryObjectInfo*) const; | 102 virtual void reportMemoryUsage(MemoryObjectInfo*) const; |
80 | 103 |
81 private: | 104 private: |
82 Vector<OwnPtr<InspectorBaseAgentInterface> > m_agents; | 105 Vector<OwnPtr<InspectorBaseFactoryInterface> > m_controllers; |
83 }; | 106 }; |
84 | 107 |
85 template<typename T> | 108 template<typename T, typename Agent> |
86 class InspectorBaseAgent : public InspectorBaseAgentInterface { | 109 class InspectorBaseFactory : public InspectorBaseFactoryInterface, public Agent:
:Factory { |
87 public: | 110 public: |
88 virtual ~InspectorBaseAgent() { } | 111 // InspectorBaseFactoryInterface implementation |
89 | |
90 virtual void registerInDispatcher(InspectorBackendDispatcher* dispatcher) | 112 virtual void registerInDispatcher(InspectorBackendDispatcher* dispatcher) |
91 { | 113 { |
92 dispatcher->registerAgent(static_cast<T*>(this)); | 114 dispatcher->registerAgent(static_cast<T*>(this)); |
93 } | 115 } |
94 | 116 |
| 117 Agent* agent() { return static_cast<Agent*>(m_agent.get()); } |
| 118 |
| 119 // Agent::Factory implementation |
| 120 virtual Agent* commandHandler() { return agent(); } |
| 121 |
95 protected: | 122 protected: |
96 InspectorBaseAgent(const String& name, InstrumentingAgents* instrumentingAge
nts, InspectorCompositeState* inspectorState) | 123 InspectorBaseFactory(const String& name, InstrumentingAgents* instrumentingA
gents, InspectorCompositeState* compositeState) |
97 : InspectorBaseAgentInterface(name, instrumentingAgents, inspectorState) | 124 : InspectorBaseFactoryInterface(name, instrumentingAgents, compositeStat
e) |
98 { | 125 { |
99 } | 126 } |
100 }; | 127 }; |
101 | 128 |
102 } // namespace WebCore | 129 } // namespace WebCore |
103 | 130 |
104 #endif // !defined(InspectorBaseAgent_h) | 131 #endif // !defined(InspectorBaseAgent_h) |
OLD | NEW |