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

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

Issue 2441933002: [DevTools] Refactor connection-related classes. (Closed)
Patch Set: tests.js 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 fa21c11a7fd743fa2ec42b348751a84787512067..3a20f525f1035a0d4815fb7f5a8939adf5fc5d0d 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/WorkerManager.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/WorkerManager.js
@@ -78,7 +78,7 @@ WebInspector.WorkerManager.prototype = {
_reset: function()
{
for (var connection of this._connections.values())
- connection.close();
+ connection._onDisconnect.call(null, "reset");
this._connections.clear();
this._targetsByWorkerId.clear();
},
@@ -96,12 +96,10 @@ WebInspector.WorkerManager.prototype = {
*/
_workerCreated: function(workerId, url, waitingForDebugger)
{
- var connection = new WebInspector.WorkerConnection(this, workerId);
- this._connections.set(workerId, connection);
-
+ var capabilities = WebInspector.Target.Capability.JS | WebInspector.Target.Capability.Log;
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, capabilities, this._createConnection.bind(this, workerId), this.target());
this._targetsByWorkerId.set(workerId, target);
// Only pause new worker if debugging SW - we are going through the
@@ -114,12 +112,24 @@ WebInspector.WorkerManager.prototype = {
/**
* @param {string} workerId
+ * @param {!InspectorBackendClass.Connection.Params} params
+ * @return {!InspectorBackendClass.Connection}
+ */
+ _createConnection: function(workerId, params)
+ {
+ var connection = new WebInspector.WorkerConnection(this, workerId, params);
+ this._connections.set(workerId, connection);
+ return connection;
+ },
+
+ /**
+ * @param {string} workerId
*/
_workerTerminated: function(workerId)
{
var connection = this._connections.get(workerId);
if (connection)
- connection._reportClosed();
+ connection._onDisconnect.call(null, "worker terminated");
this._connections.delete(workerId);
this._targetsByWorkerId.delete(workerId);
},
@@ -132,7 +142,7 @@ WebInspector.WorkerManager.prototype = {
{
var connection = this._connections.get(workerId);
if (connection)
- connection.dispatch(message);
+ connection._onMessage.call(null, message);
},
/**
@@ -200,33 +210,35 @@ WebInspector.WorkerDispatcher.prototype = {
/**
* @constructor
- * @extends {InspectorBackendClass.Connection}
+ * @implements {InspectorBackendClass.Connection}
* @param {!WebInspector.WorkerManager} workerManager
* @param {string} workerId
+ * @param {!InspectorBackendClass.Connection.Params} params
*/
-WebInspector.WorkerConnection = function(workerManager, workerId)
+WebInspector.WorkerConnection = function(workerManager, workerId, params)
{
- InspectorBackendClass.Connection.call(this);
- // FIXME: remove resourceTreeModel and others from worker targets
- this.suppressErrorsForDomains(["Worker", "Page", "CSS", "DOM", "DOMStorage", "Database", "Network", "IndexedDB"]);
this._agent = workerManager.target().workerAgent();
this._workerId = workerId;
+ this._onMessage = params.onMessage;
+ this._onDisconnect = params.onDisconnect;
};
WebInspector.WorkerConnection.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
+ * @return {!Promise}
+ */
+ disconnect: function()
{
- this.connectionClosed("worker_terminated");
+ throw new Error("Not implemented");
},
-
- __proto__: InspectorBackendClass.Connection.prototype
};

Powered by Google App Engine
This is Rietveld 408576698