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

Side by Side Diff: Source/core/inspector/InspectorWorkerAgent.cpp

Issue 1253293002: Oilpan: Remove raw pointer to ExecutionContext from WorkerInspectorProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
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 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 32
33 #include "core/inspector/InspectorWorkerAgent.h" 33 #include "core/inspector/InspectorWorkerAgent.h"
34 34
35 #include "core/InspectorFrontend.h" 35 #include "core/InspectorFrontend.h"
36 #include "core/inspector/IdentifiersFactory.h" 36 #include "core/inspector/IdentifiersFactory.h"
37 #include "core/inspector/InspectorState.h" 37 #include "core/inspector/InspectorState.h"
38 #include "core/inspector/InstrumentingAgents.h" 38 #include "core/inspector/InstrumentingAgents.h"
39 #include "core/inspector/PageConsoleAgent.h" 39 #include "core/inspector/PageConsoleAgent.h"
40 #include "core/workers/WorkerInspectorProxy.h"
41 #include "platform/weborigin/KURL.h" 40 #include "platform/weborigin/KURL.h"
42 #include "wtf/PassOwnPtr.h" 41 #include "wtf/PassOwnPtr.h"
43 #include "wtf/RefPtr.h" 42 #include "wtf/RefPtr.h"
44 #include "wtf/text/WTFString.h" 43 #include "wtf/text/WTFString.h"
45 44
46 namespace blink { 45 namespace blink {
47 46
48 namespace WorkerAgentState { 47 namespace WorkerAgentState {
49 static const char workerInspectionEnabled[] = "workerInspectionEnabled"; 48 static const char workerInspectionEnabled[] = "workerInspectionEnabled";
50 static const char autoconnectToWorkers[] = "autoconnectToWorkers"; 49 static const char autoconnectToWorkers[] = "autoconnectToWorkers";
51 }; 50 };
52 51
53 class InspectorWorkerAgent::WorkerAgentClient final : public WorkerInspectorProx y::PageInspector {
54 WTF_MAKE_FAST_ALLOCATED(InspectorWorkerAgent::WorkerAgentClient);
55 public:
56 WorkerAgentClient(InspectorFrontend::Worker* frontend, WorkerInspectorProxy* proxy, const String& id, PageConsoleAgent* consoleAgent)
57 : m_frontend(frontend)
58 , m_proxy(proxy)
59 , m_id(id)
60 , m_connected(false)
61 , m_consoleAgent(consoleAgent)
62 {
63 ASSERT(!proxy->pageInspector());
64 }
65 ~WorkerAgentClient() override
66 {
67 disconnectFromWorker();
68 }
69
70 String id() const { return m_id; }
71 WorkerInspectorProxy* proxy() const { return m_proxy; }
72
73 void connectToWorker()
74 {
75 if (m_connected)
76 return;
77 m_connected = true;
78 m_proxy->connectToInspector(this);
79 }
80
81 void disconnectFromWorker()
82 {
83 if (!m_connected)
84 return;
85 m_connected = false;
86 m_proxy->disconnectFromInspector();
87 }
88
89 private:
90 // WorkerInspectorProxy::PageInspector implementation
91 void dispatchMessageFromWorker(const String& message) override
92 {
93 m_frontend->dispatchMessageFromWorker(m_id, message);
94 }
95 // WorkerInspectorProxy::PageInspector implementation
96 void workerConsoleAgentEnabled(WorkerGlobalScopeProxy* proxy) override
97 {
98 m_consoleAgent->workerConsoleAgentEnabled(proxy);
99 }
100
101 InspectorFrontend::Worker* m_frontend;
102 WorkerInspectorProxy* m_proxy;
103 String m_id;
104 bool m_connected;
105 PageConsoleAgent* m_consoleAgent;
106 };
107
108 PassOwnPtrWillBeRawPtr<InspectorWorkerAgent> InspectorWorkerAgent::create(PageCo nsoleAgent* consoleAgent) 52 PassOwnPtrWillBeRawPtr<InspectorWorkerAgent> InspectorWorkerAgent::create(PageCo nsoleAgent* consoleAgent)
109 { 53 {
110 return adoptPtrWillBeNoop(new InspectorWorkerAgent(consoleAgent)); 54 return adoptPtrWillBeNoop(new InspectorWorkerAgent(consoleAgent));
111 } 55 }
112 56
113 InspectorWorkerAgent::InspectorWorkerAgent(PageConsoleAgent* consoleAgent) 57 InspectorWorkerAgent::InspectorWorkerAgent(PageConsoleAgent* consoleAgent)
114 : InspectorBaseAgent<InspectorWorkerAgent, InspectorFrontend::Worker>("Worke r") 58 : InspectorBaseAgent<InspectorWorkerAgent, InspectorFrontend::Worker>("Worke r")
115 , m_consoleAgent(consoleAgent) 59 , m_consoleAgent(consoleAgent)
116 { 60 {
117 } 61 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 if (client) 97 if (client)
154 client->connectToWorker(); 98 client->connectToWorker();
155 else 99 else
156 *error = "Worker is gone"; 100 *error = "Worker is gone";
157 } 101 }
158 102
159 void InspectorWorkerAgent::disconnectFromWorker(ErrorString* error, const String & workerId) 103 void InspectorWorkerAgent::disconnectFromWorker(ErrorString* error, const String & workerId)
160 { 104 {
161 WorkerAgentClient* client = m_idToClient.get(workerId); 105 WorkerAgentClient* client = m_idToClient.get(workerId);
162 if (client) 106 if (client)
163 client->disconnectFromWorker(); 107 client->dispose();
164 else 108 else
165 *error = "Worker is gone"; 109 *error = "Worker is gone";
166 } 110 }
167 111
168 void InspectorWorkerAgent::sendMessageToWorker(ErrorString* error, const String& workerId, const String& message) 112 void InspectorWorkerAgent::sendMessageToWorker(ErrorString* error, const String& workerId, const String& message)
169 { 113 {
170 WorkerAgentClient* client = m_idToClient.get(workerId); 114 WorkerAgentClient* client = m_idToClient.get(workerId);
171 if (client) 115 if (client)
172 client->proxy()->sendMessageToInspector(message); 116 client->proxy()->sendMessageToInspector(message);
173 else 117 else
(...skipping 28 matching lines...) Expand all
202 if (!m_tracingSessionId.isEmpty()) 146 if (!m_tracingSessionId.isEmpty())
203 workerInspectorProxy->writeTimelineStartedEvent(m_tracingSessionId, id); 147 workerInspectorProxy->writeTimelineStartedEvent(m_tracingSessionId, id);
204 } 148 }
205 149
206 void InspectorWorkerAgent::workerTerminated(WorkerInspectorProxy* proxy) 150 void InspectorWorkerAgent::workerTerminated(WorkerInspectorProxy* proxy)
207 { 151 {
208 m_workerInfos.remove(proxy); 152 m_workerInfos.remove(proxy);
209 for (WorkerClients::iterator it = m_idToClient.begin(); it != m_idToClient.e nd(); ++it) { 153 for (WorkerClients::iterator it = m_idToClient.begin(); it != m_idToClient.e nd(); ++it) {
210 if (proxy == it->value->proxy()) { 154 if (proxy == it->value->proxy()) {
211 frontend()->workerTerminated(it->key); 155 frontend()->workerTerminated(it->key);
212 delete it->value; 156 it->value->dispose();
213 m_idToClient.remove(it); 157 m_idToClient.remove(it);
214 return; 158 return;
215 } 159 }
216 } 160 }
217 } 161 }
218 162
219 void InspectorWorkerAgent::createWorkerAgentClientsForExistingWorkers() 163 void InspectorWorkerAgent::createWorkerAgentClientsForExistingWorkers()
220 { 164 {
221 for (auto& info : m_workerInfos) 165 for (auto& info : m_workerInfos)
222 createWorkerAgentClient(info.key, info.value.url, info.value.id); 166 createWorkerAgentClient(info.key, info.value.url, info.value.id);
223 } 167 }
224 168
225 void InspectorWorkerAgent::destroyWorkerAgentClients() 169 void InspectorWorkerAgent::destroyWorkerAgentClients()
226 { 170 {
227 for (auto& client : m_idToClient) { 171 for (auto& client : m_idToClient)
228 client.value->disconnectFromWorker(); 172 client.value->dispose();
229 delete client.value;
230 }
231 m_idToClient.clear(); 173 m_idToClient.clear();
232 } 174 }
233 175
234 void InspectorWorkerAgent::createWorkerAgentClient(WorkerInspectorProxy* workerI nspectorProxy, const String& url, const String& id) 176 void InspectorWorkerAgent::createWorkerAgentClient(WorkerInspectorProxy* workerI nspectorProxy, const String& url, const String& id)
235 { 177 {
236 WorkerAgentClient* client = new WorkerAgentClient(frontend(), workerInspecto rProxy, id, m_consoleAgent); 178 OwnPtrWillBeRawPtr<WorkerAgentClient> client = WorkerAgentClient::create(fro ntend(), workerInspectorProxy, id, m_consoleAgent);
237 m_idToClient.set(id, client); 179 WorkerAgentClient* rawClient = client.get();
180 m_idToClient.set(id, client.release());
238 181
239 ASSERT(frontend()); 182 ASSERT(frontend());
240 bool autoconnectToWorkers = m_state->getBoolean(WorkerAgentState::autoconnec tToWorkers); 183 bool autoconnectToWorkers = m_state->getBoolean(WorkerAgentState::autoconnec tToWorkers);
241 if (autoconnectToWorkers) 184 if (autoconnectToWorkers)
242 client->connectToWorker(); 185 rawClient->connectToWorker();
243 frontend()->workerCreated(id, url, autoconnectToWorkers); 186 frontend()->workerCreated(id, url, autoconnectToWorkers);
244 } 187 }
245 188
246 DEFINE_TRACE(InspectorWorkerAgent) 189 DEFINE_TRACE(InspectorWorkerAgent)
247 { 190 {
191 #if ENABLE(OILPAN)
192 visitor->trace(m_idToClient);
248 visitor->trace(m_consoleAgent); 193 visitor->trace(m_consoleAgent);
194 #endif
249 InspectorBaseAgent<InspectorWorkerAgent, InspectorFrontend::Worker>::trace(v isitor); 195 InspectorBaseAgent<InspectorWorkerAgent, InspectorFrontend::Worker>::trace(v isitor);
250 } 196 }
251 197
198 PassOwnPtrWillBeRawPtr<InspectorWorkerAgent::WorkerAgentClient> InspectorWorkerA gent::WorkerAgentClient::create(InspectorFrontend::Worker* frontend, WorkerInspe ctorProxy* proxy, const String& id, PageConsoleAgent* consoleAgent)
199 {
200 return adoptPtrWillBeNoop(new InspectorWorkerAgent::WorkerAgentClient(fronte nd, proxy, id, consoleAgent));
201 }
202
203 InspectorWorkerAgent::WorkerAgentClient::WorkerAgentClient(InspectorFrontend::Wo rker* frontend, WorkerInspectorProxy* proxy, const String& id, PageConsoleAgent* consoleAgent)
204 : m_frontend(frontend)
205 , m_proxy(proxy)
206 , m_id(id)
207 , m_connected(false)
208 , m_consoleAgent(consoleAgent)
209 {
210 ASSERT(!proxy->pageInspector());
211 }
212 InspectorWorkerAgent::WorkerAgentClient::~WorkerAgentClient()
213 {
214 ASSERT(!m_frontend);
215 ASSERT(!m_proxy);
216 ASSERT(!m_consoleAgent);
217 }
218
219 void InspectorWorkerAgent::WorkerAgentClient::connectToWorker()
220 {
221 if (m_connected)
222 return;
223 m_connected = true;
224 m_proxy->connectToInspector(this);
225 }
226
227 void InspectorWorkerAgent::WorkerAgentClient::dispose()
228 {
229 if (m_connected) {
230 m_connected = false;
231 m_proxy->disconnectFromInspector();
232 }
233 m_frontend = nullptr;
234 m_proxy = nullptr;
235 m_consoleAgent = nullptr;
236 }
237
238 void InspectorWorkerAgent::WorkerAgentClient::dispatchMessageFromWorker(const St ring& message)
239 {
240 m_frontend->dispatchMessageFromWorker(m_id, message);
241 }
242 void InspectorWorkerAgent::WorkerAgentClient::workerConsoleAgentEnabled(WorkerGl obalScopeProxy* proxy)
243 {
244 m_consoleAgent->workerConsoleAgentEnabled(proxy);
245 }
246
247 DEFINE_TRACE(InspectorWorkerAgent::WorkerAgentClient)
248 {
249 visitor->trace(m_proxy);
250 visitor->trace(m_consoleAgent);
251 WorkerInspectorProxy::PageInspector::trace(visitor);
252 }
253
252 } // namespace blink 254 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorWorkerAgent.h ('k') | Source/core/workers/WorkerInspectorProxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698