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

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js

Issue 2441933002: [DevTools] Refactor connection-related classes. (Closed)
Patch Set: test fixes Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js b/third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js
index 7589cdcaf44295bf4a550cc6454ff4da5288c882..e3eb97e2870b214e68c2a3c1debd4c16eab155b4 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js
@@ -16,8 +16,8 @@ WebInspector.SubTargetsManager = function(target)
/** @type {!Map<string, !WebInspector.Target>} */
this._attachedTargets = new Map();
- /** @type {!Map<string, !WebInspector.SubTargetConnection>} */
- this._connections = new Map();
+ /** @type {!Map<string, !WebInspector.SubTargetChannel>} */
+ this._channels = new Map();
this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebuggerOnStart */);
this._agent.setAttachToFrames(Runtime.experiments.isEnabled("autoAttachToCrossProcessSubframes"));
@@ -67,9 +67,9 @@ WebInspector.SubTargetsManager.prototype = {
*/
dispose: function()
{
- for (var connection of this._connections.values())
- connection.close();
- this._connections.clear();
+ for (var channel of this._channels.values())
+ channel._detach();
+ this._channels.clear();
this._attachedTargets.clear();
},
@@ -149,8 +149,8 @@ WebInspector.SubTargetsManager.prototype = {
*/
_attachedToTarget: function(targetInfo, waitingForDebugger)
{
- var connection = new WebInspector.SubTargetConnection(this._agent, targetInfo.id);
- this._connections.set(targetInfo.id, connection);
+ var channel = new WebInspector.SubTargetChannel(this._agent, targetInfo.id);
+ this._channels.set(targetInfo.id, channel);
var targetName = "";
if (targetInfo.type === "node") {
@@ -159,7 +159,7 @@ WebInspector.SubTargetsManager.prototype = {
var parsedURL = targetInfo.url.asParsedURL();
targetName = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++this._lastAnonymousTargetId);
}
- var target = WebInspector.targetManager.createTarget(targetName, this._capabilitiesForType(targetInfo.type), connection, this.target());
+ var target = WebInspector.targetManager.createTarget(targetName, this._capabilitiesForType(targetInfo.type), channel, this.target());
target[WebInspector.SubTargetsManager._InfoSymbol] = targetInfo;
this._attachedTargets.set(targetInfo.id, target);
@@ -177,13 +177,13 @@ WebInspector.SubTargetsManager.prototype = {
*/
_detachedFromTarget: function(targetId)
{
- var connection = this._connections.get(targetId);
- if (connection)
- connection._reportClosed();
- this._connections.delete(targetId);
var target = this._attachedTargets.get(targetId);
this._attachedTargets.delete(targetId);
this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubTargetRemoved, target);
+ var channel = this._channels.get(targetId);
+ if (channel)
+ channel._channelClosed();
+ this._channels.delete(targetId);
},
/**
@@ -192,9 +192,9 @@ WebInspector.SubTargetsManager.prototype = {
*/
_receivedMessageFromTarget: function(targetId, message)
{
- var connection = this._connections.get(targetId);
- if (connection)
- connection.dispatch(message);
+ var channel = this._channels.get(targetId);
+ if (channel)
+ channel.dispatchEventToListeners(InspectorBackendClass.Channel.Events.MessageReceived, message);
},
/**
@@ -279,41 +279,49 @@ WebInspector.SubTargetsDispatcher.prototype = {
/**
* @constructor
- * @extends {InspectorBackendClass.Connection}
+ * @extends {WebInspector.Object}
+ * @implements {InspectorBackendClass.Channel}
* @param {!Protocol.TargetAgent} agent
* @param {string} targetId
*/
-WebInspector.SubTargetConnection = function(agent, targetId)
+WebInspector.SubTargetChannel = function(agent, targetId)
{
- InspectorBackendClass.Connection.call(this);
+ WebInspector.Object.call(this);
this._agent = agent;
this._targetId = targetId;
}
-WebInspector.SubTargetConnection.prototype = {
+WebInspector.SubTargetChannel.prototype = {
/**
* @override
- * @param {!Object} messageObject
+ * @param {string} message
*/
- sendMessage: function(messageObject)
+ sendMessage: function(message)
{
- this._agent.sendMessageToTarget(this._targetId, JSON.stringify(messageObject));
+ this._agent.sendMessageToTarget(this._targetId, message);
},
/**
* @override
+ * @param {function()} callback
*/
- forceClose: function()
+ reconnect: function(callback)
+ {
+ throw new Error("Not implemented");
+ },
+
+ _detach: function()
{
this._agent.detachFromTarget(this._targetId);
+ this._channelClosed();
},
- _reportClosed: function()
+ _channelClosed: function()
{
- this.connectionClosed("target_terminated");
+ this.dispatchEventToListeners(InspectorBackendClass.Channel.Events.ChannelClosed, "target terminated");
},
- __proto__: InspectorBackendClass.Connection.prototype
+ __proto__: WebInspector.Object.prototype
}
/**

Powered by Google App Engine
This is Rietveld 408576698