Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / chrome / browser / resources / cryptotoken / requesthelper.js
blob2c8052f1b99ea4225d1b44f46859796dc76e2c7f
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @fileoverview Provides a "bottom half" helper to assist with raw requests.
7 * This fills the same role as the Authenticator-Specific Module component of
8 * U2F documents, although the API is different.
9 */
10 'use strict';
12 /**
13 * @typedef {{
14 * type: string,
15 * timeout: number
16 * }}
18 var HelperRequest;
20 /**
21 * @typedef {{
22 * type: string,
23 * code: (number|undefined)
24 * }}
26 var HelperReply;
28 /**
29 * A helper to process requests.
30 * @interface
32 function RequestHelper() {}
34 /**
35 * Gets a handler for a request.
36 * @param {HelperRequest} request The request to handle.
37 * @return {RequestHandler} A handler for the request.
39 RequestHelper.prototype.getHandler = function(request) {};
41 /**
42 * A handler to track an outstanding request.
43 * @extends {Closeable}
44 * @interface
46 function RequestHandler() {}
48 /** @typedef {function(HelperReply, string=)} */
49 var RequestHandlerCallback;
51 /**
52 * @param {RequestHandlerCallback} cb Called with the result of the request,
53 * and an optional source for the result.
54 * @return {boolean} Whether this handler could be run.
56 RequestHandler.prototype.run = function(cb) {};
58 /** Closes this handler. */
59 RequestHandler.prototype.close = function() {};
61 /**
62 * Makes a response to a helper request with an error code.
63 * @param {HelperRequest} request The request to make a response to.
64 * @param {DeviceStatusCodes} code The error code to return.
65 * @param {string=} opt_defaultType The default response type, if none is
66 * present in the request.
67 * @return {HelperReply} The helper error response.
69 function makeHelperErrorResponse(request, code, opt_defaultType) {
70 var type;
71 if (request && request.type) {
72 type = request.type.replace(/_request$/, '_reply');
73 } else {
74 type = opt_defaultType || 'unknown_type_reply';
76 var reply = {
77 'type': type,
78 'code': /** @type {number} */ (code)
80 return reply;