OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 define('stash_client', [ | 5 define('stash_client', [ |
6 'async_waiter', | 6 'async_waiter', |
7 'content/public/renderer/service_provider', | 7 'content/public/renderer/service_provider', |
8 'extensions/common/mojo/stash.mojom', | 8 'extensions/common/mojo/stash.mojom', |
9 'mojo/public/js/buffer', | 9 'mojo/public/js/buffer', |
10 'mojo/public/js/codec', | 10 'mojo/public/js/codec', |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 data: new Uint8Array(encoded.buffer.arrayBuffer), | 80 data: new Uint8Array(encoded.buffer.arrayBuffer), |
81 stashed_handles: encoded.handles, | 81 stashed_handles: encoded.handles, |
82 monitor_handles: stashed.monitorHandles, | 82 monitor_handles: stashed.monitorHandles, |
83 }); | 83 }); |
84 }, this); | 84 }, this); |
85 }, this)).catch(function(e) { return []; }); | 85 }, this)).catch(function(e) { return []; }); |
86 }; | 86 }; |
87 | 87 |
88 /** | 88 /** |
89 * The registered stash clients. | 89 * The registered stash clients. |
90 * @type {!Array.<!Registration>} | 90 * @type {!Array<!Registration>} |
91 */ | 91 */ |
92 var clients = []; | 92 var clients = []; |
93 | 93 |
94 /** | 94 /** |
95 * Registers a client to provide objects to stash during shut-down. | 95 * Registers a client to provide objects to stash during shut-down. |
96 * | 96 * |
97 * @param {string} id The id of the client. This can be passed to retrieve to | 97 * @param {string} id The id of the client. This can be passed to retrieve to |
98 * retrieve the stashed objects. | 98 * retrieve the stashed objects. |
99 * @param {!Object} type The type of the objects that callback will return. | 99 * @param {!Object} type The type of the objects that callback will return. |
100 * @param {module:stash_client.StashCallback} callback The callback that | 100 * @param {module:stash_client.StashCallback} callback The callback that |
(...skipping 20 matching lines...) Expand all Loading... |
121 }); | 121 }); |
122 | 122 |
123 /** | 123 /** |
124 * Retrieves the objects that were stashed with the given |id|, deserializing | 124 * Retrieves the objects that were stashed with the given |id|, deserializing |
125 * them into structs with type |type|. | 125 * them into structs with type |type|. |
126 * | 126 * |
127 * @param {string} id The id of the client. This should be unique to this | 127 * @param {string} id The id of the client. This should be unique to this |
128 * client and should be passed as the id to registerClient(). | 128 * client and should be passed as the id to registerClient(). |
129 * @param {!Object} type The mojo struct type that was serialized into the | 129 * @param {!Object} type The mojo struct type that was serialized into the |
130 * each stashed object. | 130 * each stashed object. |
131 * @return {!Promise.<!Array<!Object>>} The stashed objects. The exact type of | 131 * @return {!Promise<!Array<!Object>>} The stashed objects. The exact type of |
132 * each object is that of the |type| parameter. | 132 * each object is that of the |type| parameter. |
133 * @alias module:stash_client.retrieve | 133 * @alias module:stash_client.retrieve |
134 */ | 134 */ |
135 function retrieve(id, type) { | 135 function retrieve(id, type) { |
136 return retrievedStash.then(function(stash) { | 136 return retrievedStash.then(function(stash) { |
137 var stashedObjects = stash[id]; | 137 var stashedObjects = stash[id]; |
138 if (!stashedObjects) | 138 if (!stashedObjects) |
139 return Promise.resolve([]); | 139 return Promise.resolve([]); |
140 | 140 |
141 return Promise.all($Array.map(stashedObjects, function(stashed) { | 141 return Promise.all($Array.map(stashedObjects, function(stashed) { |
(...skipping 18 matching lines...) Expand all Loading... |
160 }); | 160 }); |
161 service.addToStash(flattenedObjectsToStash); | 161 service.addToStash(flattenedObjectsToStash); |
162 }); | 162 }); |
163 }); | 163 }); |
164 | 164 |
165 return { | 165 return { |
166 registerClient: registerClient, | 166 registerClient: registerClient, |
167 retrieve: retrieve, | 167 retrieve: retrieve, |
168 }; | 168 }; |
169 }); | 169 }); |
OLD | NEW |