diff options
author | sammc <sammc@chromium.org> | 2015-02-09 23:45:53 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-10 07:46:43 +0000 |
commit | d3d01eebe4aa13a42e3a3a14f08cbc219bbef945 (patch) | |
tree | 9f0b6c317aeea24d7a3c1bf21c190ef5165b87ab /extensions/renderer/resources/serial_service.js | |
parent | a5b3eb75b80954fdb346d194419cd47f2ad6b981 (diff) | |
download | chromium_src-d3d01eebe4aa13a42e3a3a14f08cbc219bbef945.zip chromium_src-d3d01eebe4aa13a42e3a3a14f08cbc219bbef945.tar.gz chromium_src-d3d01eebe4aa13a42e3a3a14f08cbc219bbef945.tar.bz2 |
Use the JS stash client from the JS serial service.
This allows persistent serial connections to be supported on the
mojo-service-backed serial implementation.
BUG=389016
Review URL: https://codereview.chromium.org/908153002
Cr-Commit-Position: refs/heads/master@{#315514}
Diffstat (limited to 'extensions/renderer/resources/serial_service.js')
-rw-r--r-- | extensions/renderer/resources/serial_service.js | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/extensions/renderer/resources/serial_service.js b/extensions/renderer/resources/serial_service.js index 21efb7b..e5d909d 100644 --- a/extensions/renderer/resources/serial_service.js +++ b/extensions/renderer/resources/serial_service.js @@ -10,13 +10,15 @@ define('serial_service', [ 'device/serial/serial_serialization.mojom', 'mojo/public/js/core', 'mojo/public/js/router', + 'stash_client', ], function(serviceProvider, dataReceiver, dataSender, serialMojom, serialization, core, - routerModule) { + routerModule, + stashClient) { /** * A Javascript client for the serial service and connection Mojo services. * @@ -132,6 +134,8 @@ define('serial_service', [ clientOptions.sendTimeout = options.sendTimeout; if ('bufferSize' in options) clientOptions.bufferSize = options.bufferSize; + if ('persistent' in options) + clientOptions.persistent = options.persistent; }; function Connection(connection, router, receivePipe, receiveClientPipe, @@ -446,7 +450,7 @@ define('serial_service', [ Connection.deserialize = function(serialized) { var serialConnection = $Object.create(Connection.prototype); var router = new routerModule.Router(serialized.connection); - var connection = new serialMojom.ConnectionProxy(router); + var connection = new serialMojom.Connection.proxyClass(router); var receiver = dataReceiver.DataReceiver.deserialize(serialized.receiver); var sender = dataSender.DataSender.deserialize(serialized.sender); @@ -480,9 +484,12 @@ define('serial_service', [ // All accesses to connections_ and nextConnectionId_ other than those // involved in deserialization should ensure that // connectionDeserializationComplete_ has resolved first. - // Note: this will not immediately resolve once serial connection stashing and - // restoring is implemented. - var connectionDeserializationComplete_ = Promise.resolve(); + var connectionDeserializationComplete_ = stashClient.retrieve( + 'serial', serialization.SerializedConnection).then(function(decoded) { + if (!decoded) + return; + return Promise.all($Array.map(decoded, Connection.deserialize)); + }); // The map of connection ID to connection object. var connections_ = new Map(); @@ -510,6 +517,27 @@ define('serial_service', [ }); } + stashClient.registerClient( + 'serial', serialization.SerializedConnection, function() { + return connectionDeserializationComplete_.then(function() { + var clientPromises = []; + for (var connection of connections_.values()) { + if (connection.state_.persistent) + clientPromises.push(connection.serialize()); + else + connection.close(); + } + return Promise.all($Array.map(clientPromises, function(promise) { + return promise.then(function(serialization) { + return { + serialization: serialization, + monitorHandles: !serialization.paused, + }; + }); + })); + }); + }); + return { getDevices: getDevices, createConnection: Connection.create, |