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 28 matching lines...) Expand all Loading... |
39 namespace WebCore { | 39 namespace WebCore { |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 Mutex& workerDebuggerAgentsMutex() | 43 Mutex& workerDebuggerAgentsMutex() |
44 { | 44 { |
45 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); | 45 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); |
46 return mutex; | 46 return mutex; |
47 } | 47 } |
48 | 48 |
49 typedef HashMap<WorkerThread*, WorkerDebuggerAgent*> WorkerDebuggerAgents; | 49 typedef CrossThreadPersistent<HeapHashMap<WorkerThread*, Member<WorkerDebuggerAg
ent> > > WorkerDebuggerAgents; |
50 | 50 |
51 WorkerDebuggerAgents& workerDebuggerAgents() | 51 WorkerDebuggerAgents& workerDebuggerAgents() |
52 { | 52 { |
53 DEFINE_STATIC_LOCAL(WorkerDebuggerAgents, agents, ()); | 53 DEFINE_STATIC_LOCAL(WorkerDebuggerAgents, agents, (new HeapHashMap<WorkerThr
ead*, Member<WorkerDebuggerAgent> >())); |
54 return agents; | 54 return agents; |
55 } | 55 } |
56 | 56 |
| 57 #if ENABLE(OILPAN) |
| 58 class WorkerDebuggerAgentRemover { |
| 59 public: |
| 60 WorkerDebuggerAgentRemover(WorkerThread* thread) |
| 61 {printf("WorkerDebuggerAgentRemover %p\n", this); |
| 62 m_thread = thread; |
| 63 } |
| 64 ~WorkerDebuggerAgentRemover() |
| 65 {printf("~WorkerDebuggerAgentRemover %p\n", this); |
| 66 MutexLocker lock(workerDebuggerAgentsMutex()); |
| 67 ASSERT(workerDebuggerAgents()->contains(m_thread)); |
| 68 workerDebuggerAgents()->remove(m_thread); |
| 69 } |
| 70 |
| 71 private: |
| 72 WorkerThread* m_thread; |
| 73 }; |
| 74 |
| 75 typedef CrossThreadPersistent<HeapHashMap<WeakMember<WorkerDebuggerAgent>, OwnPt
r<WorkerDebuggerAgentRemover> > > WorkerDebuggerAgentRemovers; |
| 76 |
| 77 WorkerDebuggerAgentRemovers& workerDebuggerAgentRemovers() |
| 78 { |
| 79 DEFINE_STATIC_LOCAL(WorkerDebuggerAgentRemovers, removers, (new HeapHashMap<
WeakMember<WorkerDebuggerAgent>, OwnPtr<WorkerDebuggerAgentRemover> >())); |
| 80 return removers; |
| 81 } |
| 82 #endif |
57 | 83 |
58 class RunInspectorCommandsTask FINAL : public ScriptDebugServer::Task { | 84 class RunInspectorCommandsTask FINAL : public ScriptDebugServer::Task { |
59 public: | 85 public: |
60 explicit RunInspectorCommandsTask(WorkerThread* thread) | 86 explicit RunInspectorCommandsTask(WorkerThread* thread) |
61 : m_thread(thread) { } | 87 : m_thread(thread) { } |
62 virtual ~RunInspectorCommandsTask() { } | 88 virtual ~RunInspectorCommandsTask() { } |
63 virtual void run() OVERRIDE | 89 virtual void run() OVERRIDE |
64 { | 90 { |
65 // Process all queued debugger commands. WorkerThread is certainly | 91 // Process all queued debugger commands. WorkerThread is certainly |
66 // alive if this task is being executed. | 92 // alive if this task is being executed. |
67 while (MessageQueueMessageReceived == m_thread->runLoop().runDebuggerTas
k(WorkerRunLoop::DontWaitForMessage)) { } | 93 while (MessageQueueMessageReceived == m_thread->runLoop().runDebuggerTas
k(WorkerRunLoop::DontWaitForMessage)) { } |
68 } | 94 } |
69 | 95 |
70 private: | 96 private: |
71 WorkerThread* m_thread; | 97 WorkerThread* m_thread; |
72 }; | 98 }; |
73 | 99 |
74 } // namespace | 100 } // namespace |
75 | 101 |
76 PassOwnPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(WorkerScriptDebugSer
ver* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedS
criptManager* injectedScriptManager) | 102 PassOwnPtrWillBeRawPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(WorkerSc
riptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScop
e, InjectedScriptManager* injectedScriptManager) |
77 { | 103 { |
78 return adoptPtr(new WorkerDebuggerAgent(scriptDebugServer, inspectedWorkerGl
obalScope, injectedScriptManager)); | 104 return adoptPtrWillBeNoop(new WorkerDebuggerAgent(scriptDebugServer, inspect
edWorkerGlobalScope, injectedScriptManager)); |
79 } | 105 } |
80 | 106 |
81 WorkerDebuggerAgent::WorkerDebuggerAgent(WorkerScriptDebugServer* scriptDebugSer
ver, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injec
tedScriptManager) | 107 WorkerDebuggerAgent::WorkerDebuggerAgent(WorkerScriptDebugServer* scriptDebugSer
ver, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injec
tedScriptManager) |
82 : InspectorDebuggerAgent(injectedScriptManager) | 108 : InspectorDebuggerAgent(injectedScriptManager) |
83 , m_scriptDebugServer(scriptDebugServer) | 109 , m_scriptDebugServer(scriptDebugServer) |
84 , m_inspectedWorkerGlobalScope(inspectedWorkerGlobalScope) | 110 , m_inspectedWorkerGlobalScope(inspectedWorkerGlobalScope) |
85 { | 111 {printf("WorkerDebuggerAgent::WorkerDebuggerAgent %p\n", this); |
86 MutexLocker lock(workerDebuggerAgentsMutex()); | 112 MutexLocker lock(workerDebuggerAgentsMutex()); |
87 workerDebuggerAgents().set(inspectedWorkerGlobalScope->thread(), this); | 113 WorkerThread* thread = inspectedWorkerGlobalScope->thread(); |
| 114 ASSERT(!workerDebuggerAgents()->contains(thread)); |
| 115 ASSERT(!workerDebuggerAgentRemovers()->contains(this)); |
| 116 workerDebuggerAgents()->add(thread, this); |
| 117 // workerDebuggerAgentRemovers()->add(this, adoptPtr(new WorkerDebuggerAgent
Remover(thread))); |
88 } | 118 } |
89 | 119 |
90 WorkerDebuggerAgent::~WorkerDebuggerAgent() | 120 WorkerDebuggerAgent::~WorkerDebuggerAgent() |
| 121 {printf("WorkerDebuggerAgent::~WorkerDebuggerAgent %p\n", this); |
| 122 #if !ENABLE(OILPAN) |
| 123 MutexLocker lock(workerDebuggerAgentsMutex()); |
| 124 ASSERT(workerDebuggerAgents()->contains(m_inspectedWorkerGlobalScope->thread
())); |
| 125 workerDebuggerAgents()->remove(m_inspectedWorkerGlobalScope->thread()); |
| 126 #endif |
| 127 } |
| 128 |
| 129 void WorkerDebuggerAgent::trace(Visitor* visitor) |
91 { | 130 { |
92 MutexLocker lock(workerDebuggerAgentsMutex()); | 131 visitor->trace(m_inspectedWorkerGlobalScope); |
93 ASSERT(workerDebuggerAgents().contains(m_inspectedWorkerGlobalScope->thread(
))); | 132 InspectorDebuggerAgent::trace(visitor); |
94 workerDebuggerAgents().remove(m_inspectedWorkerGlobalScope->thread()); | |
95 } | 133 } |
96 | 134 |
97 void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(WorkerThread* th
read) | 135 void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(WorkerThread* th
read) |
98 { | 136 { |
99 MutexLocker lock(workerDebuggerAgentsMutex()); | 137 MutexLocker lock(workerDebuggerAgentsMutex()); |
100 WorkerDebuggerAgent* agent = workerDebuggerAgents().get(thread); | 138 WorkerDebuggerAgent* agent = workerDebuggerAgents()->get(thread); |
101 if (agent) | 139 if (agent) |
102 agent->m_scriptDebugServer->interruptAndRunTask(adoptPtr(new RunInspecto
rCommandsTask(thread))); | 140 agent->m_scriptDebugServer->interruptAndRunTask(adoptPtr(new RunInspecto
rCommandsTask(thread))); |
103 } | 141 } |
104 | 142 |
105 void WorkerDebuggerAgent::startListeningScriptDebugServer() | 143 void WorkerDebuggerAgent::startListeningScriptDebugServer() |
106 { | 144 { |
107 scriptDebugServer().addListener(this); | 145 scriptDebugServer().addListener(this); |
108 } | 146 } |
109 | 147 |
110 void WorkerDebuggerAgent::stopListeningScriptDebugServer() | 148 void WorkerDebuggerAgent::stopListeningScriptDebugServer() |
(...skipping 19 matching lines...) Expand all Loading... |
130 { | 168 { |
131 // We don't need to mute console for workers. | 169 // We don't need to mute console for workers. |
132 } | 170 } |
133 | 171 |
134 void WorkerDebuggerAgent::unmuteConsole() | 172 void WorkerDebuggerAgent::unmuteConsole() |
135 { | 173 { |
136 // We don't need to mute console for workers. | 174 // We don't need to mute console for workers. |
137 } | 175 } |
138 | 176 |
139 } // namespace WebCore | 177 } // namespace WebCore |
OLD | NEW |