| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 namespace WorkerAgentState { | 48 namespace WorkerAgentState { |
| 49 static const char workerInspectionEnabled[] = "workerInspectionEnabled"; | 49 static const char workerInspectionEnabled[] = "workerInspectionEnabled"; |
| 50 static const char autoconnectToWorkers[] = "autoconnectToWorkers"; | 50 static const char autoconnectToWorkers[] = "autoconnectToWorkers"; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 class InspectorWorkerAgent::WorkerFrontendChannel final : public WorkerInspector
Proxy::PageInspector { | 53 class InspectorWorkerAgent::WorkerFrontendChannel final : public WorkerInspector
Proxy::PageInspector { |
| 54 WTF_MAKE_FAST_ALLOCATED; | 54 WTF_MAKE_FAST_ALLOCATED; |
| 55 public: | 55 public: |
| 56 explicit WorkerFrontendChannel(InspectorFrontend::Worker* frontend, WorkerIn
spectorProxy* proxy) | 56 WorkerFrontendChannel(InspectorFrontend::Worker* frontend, WorkerInspectorPr
oxy* proxy, int id) |
| 57 : m_frontend(frontend) | 57 : m_frontend(frontend) |
| 58 , m_proxy(proxy) | 58 , m_proxy(proxy) |
| 59 , m_id(s_nextId++) | 59 , m_id(id) |
| 60 , m_connected(false) | 60 , m_connected(false) |
| 61 { | 61 { |
| 62 ASSERT(!proxy->pageInspector()); | 62 ASSERT(!proxy->pageInspector()); |
| 63 } | 63 } |
| 64 virtual ~WorkerFrontendChannel() | 64 virtual ~WorkerFrontendChannel() |
| 65 { | 65 { |
| 66 disconnectFromWorker(); | 66 disconnectFromWorker(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 int id() const { return m_id; } | 69 int id() const { return m_id; } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 95 RefPtr<JSONObject> messageObject = value->asObject(); | 95 RefPtr<JSONObject> messageObject = value->asObject(); |
| 96 if (!messageObject) | 96 if (!messageObject) |
| 97 return; | 97 return; |
| 98 m_frontend->dispatchMessageFromWorker(m_id, messageObject); | 98 m_frontend->dispatchMessageFromWorker(m_id, messageObject); |
| 99 } | 99 } |
| 100 | 100 |
| 101 InspectorFrontend::Worker* m_frontend; | 101 InspectorFrontend::Worker* m_frontend; |
| 102 WorkerInspectorProxy* m_proxy; | 102 WorkerInspectorProxy* m_proxy; |
| 103 int m_id; | 103 int m_id; |
| 104 bool m_connected; | 104 bool m_connected; |
| 105 static int s_nextId; | |
| 106 }; | 105 }; |
| 107 | 106 |
| 108 int InspectorWorkerAgent::WorkerFrontendChannel::s_nextId = 1; | |
| 109 | |
| 110 PassOwnPtrWillBeRawPtr<InspectorWorkerAgent> InspectorWorkerAgent::create() | 107 PassOwnPtrWillBeRawPtr<InspectorWorkerAgent> InspectorWorkerAgent::create() |
| 111 { | 108 { |
| 112 return adoptPtrWillBeNoop(new InspectorWorkerAgent()); | 109 return adoptPtrWillBeNoop(new InspectorWorkerAgent()); |
| 113 } | 110 } |
| 114 | 111 |
| 115 InspectorWorkerAgent::InspectorWorkerAgent() | 112 InspectorWorkerAgent::InspectorWorkerAgent() |
| 116 : InspectorBaseAgent<InspectorWorkerAgent>("Worker") | 113 : InspectorBaseAgent<InspectorWorkerAgent>("Worker") |
| 117 , m_frontend(0) | 114 , m_frontend(0) |
| 115 , m_nextId(1) |
| 118 { | 116 { |
| 119 } | 117 } |
| 120 | 118 |
| 121 InspectorWorkerAgent::~InspectorWorkerAgent() | 119 InspectorWorkerAgent::~InspectorWorkerAgent() |
| 122 { | 120 { |
| 123 #if !ENABLE(OILPAN) | 121 #if !ENABLE(OILPAN) |
| 124 m_instrumentingAgents->setInspectorWorkerAgent(0); | 122 m_instrumentingAgents->setInspectorWorkerAgent(0); |
| 125 #endif | 123 #endif |
| 126 } | 124 } |
| 127 | 125 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 void InspectorWorkerAgent::setAutoconnectToWorkers(ErrorString*, bool value) | 197 void InspectorWorkerAgent::setAutoconnectToWorkers(ErrorString*, bool value) |
| 200 { | 198 { |
| 201 m_state->setBoolean(WorkerAgentState::autoconnectToWorkers, value); | 199 m_state->setBoolean(WorkerAgentState::autoconnectToWorkers, value); |
| 202 } | 200 } |
| 203 | 201 |
| 204 void InspectorWorkerAgent::setTracingSessionId(const String& sessionId) | 202 void InspectorWorkerAgent::setTracingSessionId(const String& sessionId) |
| 205 { | 203 { |
| 206 m_tracingSessionId = sessionId; | 204 m_tracingSessionId = sessionId; |
| 207 if (sessionId.isEmpty()) | 205 if (sessionId.isEmpty()) |
| 208 return; | 206 return; |
| 209 for (WorkerIds::iterator it = m_workerIds.begin(); it != m_workerIds.end();
++it) | 207 for (WorkerInfos::iterator it = m_workerInfos.begin(); it != m_workerInfos.e
nd(); ++it) |
| 210 it->key->writeTimelineStartedEvent(sessionId); | 208 it->key->writeTimelineStartedEvent(sessionId, it->value.id); |
| 211 } | 209 } |
| 212 | 210 |
| 213 bool InspectorWorkerAgent::shouldPauseDedicatedWorkerOnStart() | 211 bool InspectorWorkerAgent::shouldPauseDedicatedWorkerOnStart() |
| 214 { | 212 { |
| 215 return m_state->getBoolean(WorkerAgentState::autoconnectToWorkers); | 213 return m_state->getBoolean(WorkerAgentState::autoconnectToWorkers); |
| 216 } | 214 } |
| 217 | 215 |
| 218 void InspectorWorkerAgent::didStartWorker(WorkerInspectorProxy* workerInspectorP
roxy, const KURL& url) | 216 void InspectorWorkerAgent::didStartWorker(WorkerInspectorProxy* workerInspectorP
roxy, const KURL& url) |
| 219 { | 217 { |
| 220 m_workerIds.set(workerInspectorProxy, url.string()); | 218 int id = m_nextId++; |
| 219 m_workerInfos.set(workerInspectorProxy, WorkerInfo(url.string(), id)); |
| 221 if (m_frontend && m_state->getBoolean(WorkerAgentState::workerInspectionEnab
led)) | 220 if (m_frontend && m_state->getBoolean(WorkerAgentState::workerInspectionEnab
led)) |
| 222 createWorkerFrontendChannel(workerInspectorProxy, url.string()); | 221 createWorkerFrontendChannel(workerInspectorProxy, url.string(), id); |
| 223 if (!m_tracingSessionId.isEmpty()) | 222 if (!m_tracingSessionId.isEmpty()) |
| 224 workerInspectorProxy->writeTimelineStartedEvent(m_tracingSessionId); | 223 workerInspectorProxy->writeTimelineStartedEvent(m_tracingSessionId, id); |
| 225 } | 224 } |
| 226 | 225 |
| 227 void InspectorWorkerAgent::workerTerminated(WorkerInspectorProxy* proxy) | 226 void InspectorWorkerAgent::workerTerminated(WorkerInspectorProxy* proxy) |
| 228 { | 227 { |
| 229 m_workerIds.remove(proxy); | 228 m_workerInfos.remove(proxy); |
| 230 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { | 229 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { |
| 231 if (proxy == it->value->proxy()) { | 230 if (proxy == it->value->proxy()) { |
| 232 m_frontend->workerTerminated(it->key); | 231 m_frontend->workerTerminated(it->key); |
| 233 delete it->value; | 232 delete it->value; |
| 234 m_idToChannel.remove(it); | 233 m_idToChannel.remove(it); |
| 235 return; | 234 return; |
| 236 } | 235 } |
| 237 } | 236 } |
| 238 } | 237 } |
| 239 | 238 |
| 240 void InspectorWorkerAgent::createWorkerFrontendChannelsForExistingWorkers() | 239 void InspectorWorkerAgent::createWorkerFrontendChannelsForExistingWorkers() |
| 241 { | 240 { |
| 242 for (WorkerIds::iterator it = m_workerIds.begin(); it != m_workerIds.end();
++it) | 241 for (WorkerInfos::iterator it = m_workerInfos.begin(); it != m_workerInfos.e
nd(); ++it) |
| 243 createWorkerFrontendChannel(it->key, it->value); | 242 createWorkerFrontendChannel(it->key, it->value.url, it->value.id); |
| 244 } | 243 } |
| 245 | 244 |
| 246 void InspectorWorkerAgent::destroyWorkerFrontendChannels() | 245 void InspectorWorkerAgent::destroyWorkerFrontendChannels() |
| 247 { | 246 { |
| 248 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { | 247 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { |
| 249 it->value->disconnectFromWorker(); | 248 it->value->disconnectFromWorker(); |
| 250 delete it->value; | 249 delete it->value; |
| 251 } | 250 } |
| 252 m_idToChannel.clear(); | 251 m_idToChannel.clear(); |
| 253 } | 252 } |
| 254 | 253 |
| 255 void InspectorWorkerAgent::createWorkerFrontendChannel(WorkerInspectorProxy* wor
kerInspectorProxy, const String& url) | 254 void InspectorWorkerAgent::createWorkerFrontendChannel(WorkerInspectorProxy* wor
kerInspectorProxy, const String& url, int id) |
| 256 { | 255 { |
| 257 WorkerFrontendChannel* channel = new WorkerFrontendChannel(m_frontend, worke
rInspectorProxy); | 256 WorkerFrontendChannel* channel = new WorkerFrontendChannel(m_frontend, worke
rInspectorProxy, id); |
| 258 m_idToChannel.set(channel->id(), channel); | 257 m_idToChannel.set(id, channel); |
| 259 | 258 |
| 260 ASSERT(m_frontend); | 259 ASSERT(m_frontend); |
| 261 bool autoconnectToWorkers = m_state->getBoolean(WorkerAgentState::autoconnec
tToWorkers); | 260 bool autoconnectToWorkers = m_state->getBoolean(WorkerAgentState::autoconnec
tToWorkers); |
| 262 if (autoconnectToWorkers) | 261 if (autoconnectToWorkers) |
| 263 channel->connectToWorker(); | 262 channel->connectToWorker(); |
| 264 m_frontend->workerCreated(channel->id(), url, autoconnectToWorkers); | 263 m_frontend->workerCreated(id, url, autoconnectToWorkers); |
| 265 } | 264 } |
| 266 | 265 |
| 267 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |