author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 15 Feb 2010 15:24:16 -0800 | |
changeset 151 | 1b175992ea1c |
parent 52 | f577ea64429e |
permissions | -rw-r--r-- |
2 | 1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 |
// Use of this source code is governed by a BSD-style license that can be |
|
3 |
// found in the LICENSE file. |
|
4 |
||
5 |
package org.chromium.debug.ui.launcher; |
|
6 |
||
7 |
import java.util.concurrent.atomic.AtomicBoolean; |
|
8 |
||
9 |
import org.chromium.debug.core.model.ConnectionLoggerImpl; |
|
10 |
import org.chromium.debug.core.model.ConsolePseudoProcess; |
|
11 |
import org.chromium.debug.core.model.DebugTargetImpl; |
|
12 |
import org.chromium.debug.core.model.Destructable; |
|
13 |
import org.chromium.debug.core.model.DestructingGuard; |
|
14 |
import org.chromium.debug.core.model.JavascriptVmEmbedder; |
|
15 |
import org.chromium.debug.core.model.NamedConnectionLoggerFactory; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
16 |
import org.chromium.debug.core.model.VProjectWorkspaceBridge; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
17 |
import org.chromium.debug.core.model.WorkspaceBridge; |
2 | 18 |
import org.chromium.debug.ui.PluginUtil; |
19 |
import org.chromium.sdk.ConnectionLogger; |
|
20 |
import org.eclipse.core.runtime.CoreException; |
|
21 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
22 |
import org.eclipse.debug.core.DebugPlugin; |
|
23 |
import org.eclipse.debug.core.ILaunch; |
|
24 |
import org.eclipse.debug.core.ILaunchConfiguration; |
|
25 |
import org.eclipse.debug.core.ILaunchManager; |
|
26 |
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; |
|
27 |
||
28 |
/** |
|
29 |
* A launch configuration delegate for the JavaScript debugging. |
|
30 |
*/ |
|
31 |
public abstract class LaunchTypeBase implements ILaunchConfigurationDelegate { |
|
32 |
||
33 |
/** Launch configuration attribute (debug port). */ |
|
34 |
public static final String CHROMIUM_DEBUG_PORT = "debug_port"; //$NON-NLS-1$ |
|
35 |
||
36 |
public static final String ADD_NETWORK_CONSOLE = "add_network_console"; //$NON-NLS-1$ |
|
37 |
||
38 |
public void launch(ILaunchConfiguration config, String mode, final ILaunch launch, |
|
39 |
IProgressMonitor monitor) throws CoreException { |
|
40 |
if (!mode.equals(ILaunchManager.DEBUG_MODE)) { |
|
41 |
// Chromium JavaScript launch is only supported for debugging. |
|
42 |
return; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
43 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
44 |
|
2 | 45 |
int port = |
46 |
config.getAttribute(LaunchTypeBase.CHROMIUM_DEBUG_PORT, |
|
47 |
PluginVariablesUtil.getValueAsInt(PluginVariablesUtil.DEFAULT_PORT)); |
|
48 |
||
49 |
boolean addNetworkConsole = config.getAttribute(LaunchTypeBase.ADD_NETWORK_CONSOLE, false); |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
50 |
|
2 | 51 |
JavascriptVmEmbedder.ConnectionToRemote remoteServer = |
52 |
createConnectionToRemote(port, launch, addNetworkConsole); |
|
53 |
try { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
54 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
55 |
final String projectNameBase = config.getName(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
56 |
|
2 | 57 |
DestructingGuard destructingGuard = new DestructingGuard(); |
58 |
try { |
|
59 |
Destructable lauchDestructor = new Destructable() { |
|
60 |
public void destruct() { |
|
61 |
if (!launch.hasChildren()) { |
|
62 |
DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); |
|
63 |
} |
|
64 |
} |
|
65 |
}; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
66 |
|
2 | 67 |
destructingGuard.addValue(lauchDestructor); |
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
68 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
69 |
WorkspaceBridge.Factory bridgeFactory = |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
70 |
new VProjectWorkspaceBridge.FactoryImpl(projectNameBase); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
71 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
72 |
final DebugTargetImpl target = new DebugTargetImpl(launch, bridgeFactory); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
73 |
|
2 | 74 |
Destructable targetDestructor = new Destructable() { |
75 |
public void destruct() { |
|
76 |
terminateTarget(target); |
|
77 |
} |
|
78 |
}; |
|
79 |
destructingGuard.addValue(targetDestructor); |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
80 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
81 |
boolean attached = target.attach(remoteServer, destructingGuard, |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
82 |
OPENING_VIEW_ATTACH_CALLBACK, monitor); |
2 | 83 |
if (!attached) { |
84 |
// Error |
|
85 |
return; |
|
86 |
} |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
87 |
|
2 | 88 |
launch.addDebugTarget(target); |
89 |
monitor.done(); |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
90 |
|
2 | 91 |
// All OK |
92 |
destructingGuard.discharge(); |
|
93 |
} finally { |
|
94 |
destructingGuard.doFinally(); |
|
95 |
} |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
96 |
|
2 | 97 |
} finally { |
98 |
remoteServer.disposeConnection(); |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
protected abstract JavascriptVmEmbedder.ConnectionToRemote createConnectionToRemote(int port, |
|
103 |
ILaunch launch, boolean addConsoleLogger) throws CoreException; |
|
104 |
||
105 |
private static void terminateTarget(DebugTargetImpl target) { |
|
106 |
target.setDisconnected(true); |
|
107 |
target.fireTerminateEvent(); |
|
108 |
} |
|
109 |
||
110 |
static ConnectionLogger createConsoleAndLogger(final ILaunch launch, |
|
111 |
final boolean addLaunchToManager, final String title) { |
|
112 |
final ConsolePseudoProcess.Retransmitter consoleRetransmitter = |
|
113 |
new ConsolePseudoProcess.Retransmitter(); |
|
114 |
||
115 |
// This controller is responsible for creating ConsolePseudoProcess only on |
|
116 |
// logStarted call. Before this ConnectionLoggerImpl with all it fields should stay |
|
117 |
// garbage-collectible, because connection may not even start. |
|
118 |
ConnectionLoggerImpl.LogLifecycleListener consoleController = |
|
119 |
new ConnectionLoggerImpl.LogLifecycleListener() { |
|
120 |
private final AtomicBoolean alreadyStarted = new AtomicBoolean(false); |
|
121 |
||
122 |
public void logClosed() { |
|
123 |
consoleRetransmitter.processClosed(); |
|
124 |
} |
|
125 |
||
126 |
public void logStarted(ConnectionLoggerImpl connectionLogger) { |
|
127 |
boolean res = alreadyStarted.compareAndSet(false, true); |
|
128 |
if (!res) { |
|
129 |
throw new IllegalStateException(); |
|
130 |
} |
|
131 |
ConsolePseudoProcess consolePseudoProcess = new ConsolePseudoProcess(launch, title, |
|
132 |
consoleRetransmitter, connectionLogger.getConnectionTerminate()); |
|
133 |
consoleRetransmitter.startFlushing(); |
|
134 |
if (addLaunchToManager) { |
|
135 |
// Active the launch (again if it has already been removed) |
|
136 |
DebugPlugin.getDefault().getLaunchManager().addLaunch(launch); |
|
137 |
} |
|
138 |
} |
|
139 |
}; |
|
140 |
||
141 |
return new ConnectionLoggerImpl(consoleRetransmitter, consoleController); |
|
142 |
} |
|
143 |
||
144 |
static final NamedConnectionLoggerFactory NO_CONNECTION_LOGGER_FACTORY = |
|
145 |
new NamedConnectionLoggerFactory() { |
|
146 |
public ConnectionLogger createLogger(String title) { |
|
147 |
return null; |
|
148 |
} |
|
149 |
}; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
150 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
151 |
private static final Runnable OPENING_VIEW_ATTACH_CALLBACK = new Runnable() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
152 |
public void run() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
153 |
PluginUtil.openProjectExplorerView(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
154 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
155 |
}; |
2 | 156 |
} |