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.
6 * @fileoverview Contains a simple factory for creating and opening Gnubby
12 * @param {Gnubbies} gnubbies Gnubbies singleton instance
14 * @implements {GnubbyFactory}
16 function UsbGnubbyFactory(gnubbies
) {
17 /** @private {Gnubbies} */
18 this.gnubbies_
= gnubbies
;
19 Gnubby
.setGnubbies(gnubbies
);
23 * Creates a new gnubby object, and opens the gnubby with the given index.
24 * @param {GnubbyDeviceId} which The device to open.
25 * @param {boolean} forEnroll Whether this gnubby is being opened for enrolling.
26 * @param {FactoryOpenCallback} cb Called with result of opening the gnubby.
27 * @param {string=} opt_appIdHash The base64-encoded hash of the app id for
28 * which the gnubby being opened.
29 * @param {string=} opt_logMsgUrl The url to post log messages to.
32 UsbGnubbyFactory
.prototype.openGnubby
=
33 function(which
, forEnroll
, cb
, opt_appIdHash
, opt_logMsgUrl
) {
34 var gnubby
= new Gnubby();
35 gnubby
.open(which
, function(rc
) {
40 gnubby
.sync(function(rc
) {
47 * Enumerates gnubbies.
48 * @param {function(number, Array<GnubbyDeviceId>)} cb Enumerate callback
50 UsbGnubbyFactory
.prototype.enumerate = function(cb
) {
51 this.gnubbies_
.enumerate(cb
);
55 * No-op prerequisite check.
56 * @param {Gnubby} gnubby The not-enrolled gnubby.
57 * @param {string} appIdHash The base64-encoded hash of the app id for which
58 * the gnubby being enrolled.
59 * @param {FactoryOpenCallback} cb Called with the result of the prerequisite
60 * check. (A non-zero status indicates failure.)
62 UsbGnubbyFactory
.prototype.notEnrolledPrerequisiteCheck
=
63 function(gnubby
, appIdHash
, cb
) {
64 cb(DeviceStatusCodes
.OK_STATUS
, gnubby
);