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
3 // found in the LICENSE file.
6 * Responsible for interfacing with the native component of the WebUI to make
7 * CryptAuth API requests and handling the responses.
11 * A list of observers of CryptAuth events.
18 addObserver: function(observer) {
19 CryptAuthInterface.observers_.push(observer);
23 * Removes an observer.
25 removeObserver: function(observer) {
26 CryptAuthInterface.observers_.remove(observer);
30 * Starts the findEligibleUnlockDevices API call.
31 * The onGotEligibleDevices() function will be called upon success.
33 findEligibleUnlockDevices: function() {
34 chrome.send('findEligibleUnlockDevices');
38 * Starts the flow to find reachable devices. Reachable devices are those that
39 * respond to a CryptAuth ping.
40 * The onGotReachableDevices() function will be called upon success.
42 findReachableDevices: function() {
43 chrome.send('findReachableDevices');
47 * Called by the browser when the API request fails.
49 onError: function(errorMessage) {
50 CryptAuthInterface.observers_.forEach(function(observer) {
51 if (observer.onCryptAuthError != null)
52 observer.onCryptAuthError(errorMessage);
57 * Called by the browser when a findEligibleUnlockDevices completes
59 * @param {Array<DeviceInfo>} eligibleDevices
60 * @param {Array<DeviceInfo>} ineligibleDevices
62 onGotEligibleDevices: function(eligibleDevices, ineligibleDevices) {
63 CryptAuthInterface.observers_.forEach(function(observer) {
64 if (observer.onGotEligibleDevices != null)
65 observer.onGotEligibleDevices(eligibleDevices, ineligibleDevices);
70 * Called by the browser when the reachable devices flow completes
72 * @param {Array<DeviceInfo>} reachableDevices
74 onGotReachableDevices: function(reachableDevices) {
75 CryptAuthInterface.observers_.forEach(function(observer) {
76 if (observer.onGotReachableDevices != null)
77 observer.onGotReachableDevices(reachableDevices);