File: local-state.js

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (214 lines) | stat: -rw-r--r-- 6,137 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Polymer({
  is: 'local-state',
  properties: {
    /**
     * The current CryptAuth enrollment status.
     * @type {{
     *   lastSuccessTime: ?number,
     *   nextRefreshTime: ?number,
     *   recoveringFromFailure: boolean,
     *   operationInProgress: boolean,
     * }} SyncState
     */
    enrollmentState_: {
      type: Object,
      value: {
        lastSuccessTime: null,
        nextRefreshTime: null,
        recoveringFromFailure: true,
        operationInProgress: false,
      },
    },

    /**
     * The current CryptAuth device sync status.
     * @type {SyncState}
     */
    deviceSyncState_: {
      type: Object,
      value: {
        lastSuccessTime: null,
        nextRefreshTime: null,
        recoveringFromFailure: true,
        operationInProgress: false,
      },
    },

    /**
     * List of unlock keys that can unlock the local device.
     * @type {Array<DeviceInfo>}
     */
    unlockKeys_: {
      type: Array,
      value: [
        {
         publicKey: 'CAESRQogOlH8DgPMQu7eAt-b6yoTXcazG8mAl6SPC5Ds-LTULIcSIQDZ' +
                    'DMqsoYRO4tNMej1FBEl1sTiTiVDqrcGq-CkYCzDThw==',
         friendlyDeviceName: 'LGE Nexus 4',
         bluetoothAddress: 'C4:43:8F:12:07:07',
         unlockKey: true,
         unlockable: false,
         connectionStatus: 'connected',
         remoteState: {
           userPresent: true,
           secureScreenLock: true,
           trustAgent: true
         },
        },
      ],
    },
  },

  /**
   * Called when the page is about to be shown.
   */
  activate: function() {
    LocalStateInterface = this;
    chrome.send('getLocalState');
  },

  /**
   * Immediately forces an enrollment attempt.
   */
  forceEnrollment_: function() {
    chrome.send('forceEnrollment');
  },

  /**
   * Immediately forces an device sync attempt.
   */
  forceDeviceSync_: function() {
    chrome.send('forceDeviceSync');
  },

  /**
   * Called when the enrollment state changes.
   * @param {SyncState} enrollmentState
   */
  onEnrollmentStateChanged: function(enrollmentState) {
    this.enrollmentState_ = enrollmentState;
  },

  /**
   * Called when the device sync state changes.
   * @param {SyncState} deviceSyncState
   */
  onDeviceSyncStateChanged: function(deviceSyncState) {
    this.deviceSyncState_ = deviceSyncState;
  },

  /**
   * Called when the locally stored unlock keys change.
   * @param {Array<DeviceInfo>} unlockKeys
   */
  onUnlockKeysChanged: function(unlockKeys) {
    this.unlockKeys_ = unlockKeys;
  },

  /**
   * Called for the chrome.send('getSyncStates') response.
   * @param {SyncState} enrollmentState
   * @param {SyncState} deviceSyncState
   * @param {Array<DeviceInfo>} unlockKeys
   */
  onGotLocalState: function(enrollmentState, deviceSyncState, unlockKeys) {
    this.enrollmentState_ = enrollmentState;
    this.deviceSyncState_ = deviceSyncState;
    this.unlockKeys_ = unlockKeys;
  },

  /**
   * @param {SyncState} syncState The enrollment or device sync state.
   * @param {string} neverSyncedString String returned if there has never been a
   *     last successful sync.
   * @return {string} The formatted string of the last successful sync time.
   */
  getLastSyncTimeString_: function(syncState, neverSyncedString) {
    if (syncState.lastSuccessTime == 0)
      return neverSyncedString;
    var date = new Date(syncState.lastSuccessTime);
    return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
  },

  /**
   * @param {SyncState} syncState The enrollment or device sync state.
   * @return {string} The formatted string to be displayed.
   */
  getNextEnrollmentString_: function(syncState) {
    var deltaMillis = syncState.nextRefreshTime;
    if (deltaMillis == null)
      return 'unknown';
    if (deltaMillis == 0)
      return 'sync in progress...';

    var seconds = deltaMillis / 1000;
    if (seconds < 60)
      return Math.round(seconds) + ' seconds to refresh';

    var minutes = seconds / 60;
    if (minutes < 60)
      return Math.round(minutes) + ' minutes to refresh';

    var hours = minutes / 60;
    if (hours < 24)
      return Math.round(hours) + ' hours to refresh';

    var days = hours / 24;
    return Math.round(days) + ' days to refresh';
  },

  /**
   * @param {SyncState} syncState The enrollment or device sync state.
   * @return {string} The icon to show for the current state.
   */
  getNextSyncIcon_: function(syncState) {
    return syncState.operationInProgress ? 'icons:refresh' : 'icons:schedule';
 },

  /**
   * @param {SyncState} syncState The enrollment or device sync state.
   * @return {string} The icon id representing whether the last sync is
   *     successful.
   */
  getIconForSuccess_: function(syncState) {
    return syncState.recoveringFromFailure ?
        'icons:error' : 'icons:cloud-done';
  },
});

// Interface with the native WebUI component for getting the local state and
// being notified when the local state changes.
// The local state refers to state stored on the device rather than online in
// CryptAuth. This state includes the enrollment and device sync states, as well
// as the list of unlock keys.
LocalStateInterface = {
  /**
   * Called when the enrollment state changes. For example, when a new
   * enrollment is initiated.
   * @type {function(SyncState)}
   */
  onEnrollmentStateChanged: function(enrollmentState) {},

  /**
   * Called when the device state changes. For example, when a new device sync
   * is initiated.
   * @type {function(DeviceSyncState)}
   */
  onDeviceSyncStateChanged: function(deviceSyncState) {},

  /**
   * Called when the locally stored unlock keys changes.
   * @type {function(Array<DeviceInfo>)}
   */
  onUnlockKeysChanged: function(unlockKeys) {},

  /**
   * Called in response to chrome.send('getLocalState') with the local state.
   * @type {function(SyncState, SyncState, Array<DeviceInfo>)}
   */
  onGotLocalState: function(enrollmentState, deviceSyncState, unlockKeys) {},
};