• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5/**
6 * @fileoverview Contains a simple factory for creating and opening usbGnubby
7 * instances.
8 */
9'use strict';
10
11/**
12 * @param {Gnubbies} gnubbies Gnubbies singleton instance
13 * @constructor
14 * @implements {GnubbyFactory}
15 */
16function UsbGnubbyFactory(gnubbies) {
17  /** @private {Gnubbies} */
18  this.gnubbies_ = gnubbies;
19  usbGnubby.setGnubbies(gnubbies);
20}
21
22/**
23 * Creates a new gnubby object, and opens the gnubby with the given index.
24 * @param {llGnubbyDeviceId} which The device to open.
25 * @param {boolean} forEnroll Whether this gnubby is being opened for enrolling.
26 * @param {function(number, usbGnubby=)} cb Called with result of opening the
27 *     gnubby.
28 * @param {string=} logMsgUrl the url to post log messages to
29 * @override
30 */
31UsbGnubbyFactory.prototype.openGnubby =
32    function(which, forEnroll, cb, logMsgUrl) {
33  var gnubby = new usbGnubby();
34  gnubby.open(which, function(rc) {
35    cb(rc, gnubby);
36  });
37};
38
39/**
40 * Enumerates gnubbies.
41 * @param {function(number, Array.<llGnubbyDeviceId>)} cb Enumerate callback
42 */
43UsbGnubbyFactory.prototype.enumerate = function(cb) {
44  this.gnubbies_.enumerate(cb);
45};
46