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

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/WorkerManager.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/WorkerManager.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/WorkerManager.js b/third_party/WebKit/Source/devtools/front_end/sdk/WorkerManager.js
index 1969ff6a6a113ef228e14284c834b3f6a973c87d..c9215de204ed76c1e4f881ba5ba2eb0ea2ca3228 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/WorkerManager.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/WorkerManager.js
@@ -38,8 +38,8 @@ WebInspector.WorkerManager = function(target)
WebInspector.SDKObject.call(this, target);
target.registerWorkerDispatcher(new WebInspector.WorkerDispatcher(this));
this._lastAnonymousTargetId = 0;
- /** @type {!Map.<string, !WebInspector.WorkerConnection>} */
- this._connections = new Map();
+ /** @type {!Map.<string, !WebInspector.WorkerChannel>} */
+ this._channels = new Map();
/** @type {!Map.<string, !WebInspector.Target>} */
this._targetsByWorkerId = new Map();
@@ -77,9 +77,9 @@ WebInspector.WorkerManager.prototype = {
_reset: function()
{
- for (var connection of this._connections.values())
- connection.close();
- this._connections.clear();
+ for (var channel of this._channels.values())
+ channel.dispatchEventToListeners(InspectorBackendClass.Channel.Events.ChannelClosed, "worker terminated");
+ this._channels.clear();
this._targetsByWorkerId.clear();
},
@@ -96,12 +96,12 @@ WebInspector.WorkerManager.prototype = {
*/
_workerCreated: function(workerId, url, waitingForDebugger)
{
- var connection = new WebInspector.WorkerConnection(this, workerId);
- this._connections.set(workerId, connection);
+ var channel = new WebInspector.WorkerChannel(this, workerId);
+ this._channels.set(workerId, channel);
var parsedURL = url.asParsedURL();
var workerName = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++this._lastAnonymousTargetId);
- var target = WebInspector.targetManager.createTarget(workerName, WebInspector.Target.Capability.JS | WebInspector.Target.Capability.Log, connection, this.target());
+ var target = WebInspector.targetManager.createTarget(workerName, WebInspector.Target.Capability.JS | WebInspector.Target.Capability.Log, channel, this.target());
this._targetsByWorkerId.set(workerId, target);
// Only pause new worker if debugging SW - we are going through the
@@ -117,10 +117,10 @@ WebInspector.WorkerManager.prototype = {
*/
_workerTerminated: function(workerId)
{
- var connection = this._connections.get(workerId);
- if (connection)
- connection._reportClosed();
- this._connections.delete(workerId);
+ var channel = this._channels.get(workerId);
+ if (channel)
+ channel.dispatchEventToListeners(InspectorBackendClass.Channel.Events.ChannelClosed, "worker terminated");
+ this._channels.delete(workerId);
this._targetsByWorkerId.delete(workerId);
},
@@ -130,9 +130,9 @@ WebInspector.WorkerManager.prototype = {
*/
_dispatchMessageFromWorker: function(workerId, message)
{
- var connection = this._connections.get(workerId);
- if (connection)
- connection.dispatch(message);
+ var channel = this._channels.get(workerId);
+ if (channel)
+ channel.dispatchEventToListeners(InspectorBackendClass.Channel.Events.MessageReceived, message);
},
/**
@@ -200,33 +200,36 @@ WebInspector.WorkerDispatcher.prototype = {
/**
* @constructor
- * @extends {InspectorBackendClass.Connection}
+ * @extends {WebInspector.Object}
+ * @implements {InspectorBackendClass.Channel}
* @param {!WebInspector.WorkerManager} workerManager
* @param {string} workerId
*/
-WebInspector.WorkerConnection = function(workerManager, workerId)
+WebInspector.WorkerChannel = function(workerManager, workerId)
{
- InspectorBackendClass.Connection.call(this);
- // FIXME: remove resourceTreeModel and others from worker targets
- this.suppressErrorsForDomains(["Worker", "Page", "CSS", "DOM", "DOMStorage", "Database", "Network", "IndexedDB"]);
+ WebInspector.Object.call(this);
this._agent = workerManager.target().workerAgent();
this._workerId = workerId;
}
-WebInspector.WorkerConnection.prototype = {
+WebInspector.WorkerChannel.prototype = {
/**
* @override
- * @param {!Object} messageObject
+ * @param {string} message
*/
- sendMessage: function(messageObject)
+ sendMessage: function(message)
{
- this._agent.sendMessageToWorker(this._workerId, JSON.stringify(messageObject));
+ this._agent.sendMessageToWorker(this._workerId, message);
},
- _reportClosed: function()
+ /**
+ * @override
+ * @param {function()} callback
+ */
+ reconnect: function(callback)
{
- this.connectionClosed("worker_terminated");
+ throw new Error("Not implemented");
},
- __proto__: InspectorBackendClass.Connection.prototype
+ __proto__: WebInspector.Object.prototype
}

Powered by Google App Engine
This is Rietveld 408576698