OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 Polymer({ | 5 Polymer({ |
6 is: 'local-state', | 6 is: 'local-state', |
7 properties: { | 7 properties: { |
8 /** | 8 /** |
9 * The current CryptAuth enrollment status. | 9 * The current CryptAuth enrollment status. |
10 * @type {{ | 10 * @type {{ |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 }, | 60 }, |
61 }, | 61 }, |
62 ], | 62 ], |
63 }, | 63 }, |
64 }, | 64 }, |
65 | 65 |
66 /** | 66 /** |
67 * Called when the page is about to be shown. | 67 * Called when the page is about to be shown. |
68 */ | 68 */ |
69 activate: function() { | 69 activate: function() { |
70 SyncStateInterface = this; | 70 LocalStateInterface = this; |
71 chrome.send('getSyncStates'); | 71 chrome.send('getLocalState'); |
72 }, | 72 }, |
73 | 73 |
74 /** | 74 /** |
75 * Immediately forces an enrollment attempt. | 75 * Immediately forces an enrollment attempt. |
76 */ | 76 */ |
77 forceEnrollment_: function() { | 77 forceEnrollment_: function() { |
78 chrome.send('forceEnrollment'); | 78 chrome.send('forceEnrollment'); |
79 }, | 79 }, |
80 | 80 |
81 /** | 81 /** |
(...skipping 13 matching lines...) Expand all Loading... |
95 | 95 |
96 /** | 96 /** |
97 * Called when the device sync state changes. | 97 * Called when the device sync state changes. |
98 * @param {SyncState} deviceSyncState | 98 * @param {SyncState} deviceSyncState |
99 */ | 99 */ |
100 onDeviceSyncStateChanged: function(deviceSyncState) { | 100 onDeviceSyncStateChanged: function(deviceSyncState) { |
101 this.deviceSyncState_ = deviceSyncState; | 101 this.deviceSyncState_ = deviceSyncState; |
102 }, | 102 }, |
103 | 103 |
104 /** | 104 /** |
| 105 * Called when the locally stored unlock keys change. |
| 106 * @param {Array<DeviceInfo>} unlockKeys |
| 107 */ |
| 108 onUnlockKeysChanged: function(unlockKeys) { |
| 109 this.unlockKeys_ = unlockKeys; |
| 110 }, |
| 111 |
| 112 /** |
105 * Called for the chrome.send('getSyncStates') response. | 113 * Called for the chrome.send('getSyncStates') response. |
106 * @param {SyncState} enrollmentState | 114 * @param {SyncState} enrollmentState |
107 * @param {SyncState} deviceSyncState | 115 * @param {SyncState} deviceSyncState |
| 116 * @param {Array<DeviceInfo>} unlockKeys |
108 */ | 117 */ |
109 onGotSyncStates: function(enrollmentState, deviceSyncState) { | 118 onGotLocalState: function(enrollmentState, deviceSyncState, unlockKeys) { |
110 this.enrollmentState_ = enrollmentState; | 119 this.enrollmentState_ = enrollmentState; |
111 this.deviceSyncState_ = deviceSyncState; | 120 this.deviceSyncState_ = deviceSyncState; |
| 121 this.unlockKeys_ = unlockKeys; |
112 }, | 122 }, |
113 | 123 |
114 /** | 124 /** |
115 * @param {SyncState} syncState The enrollment or device sync state. | 125 * @param {SyncState} syncState The enrollment or device sync state. |
116 * @param {string} neverSyncedString String returned if there has never been a | 126 * @param {string} neverSyncedString String returned if there has never been a |
117 * last successful sync. | 127 * last successful sync. |
118 * @return {string} The formatted string of the last successful sync time. | 128 * @return {string} The formatted string of the last successful sync time. |
119 */ | 129 */ |
120 getLastSyncTimeString_: function(syncState, neverSyncedString) { | 130 getLastSyncTimeString_: function(syncState, neverSyncedString) { |
121 if (syncState.lastSuccessTime == 0) | 131 if (syncState.lastSuccessTime == 0) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 * @param {SyncState} syncState The enrollment or device sync state. | 173 * @param {SyncState} syncState The enrollment or device sync state. |
164 * @return {string} The icon id representing whether the last sync is | 174 * @return {string} The icon id representing whether the last sync is |
165 * successful. | 175 * successful. |
166 */ | 176 */ |
167 getIconForSuccess_: function(syncState) { | 177 getIconForSuccess_: function(syncState) { |
168 return syncState.recoveringFromFailure ? | 178 return syncState.recoveringFromFailure ? |
169 'icons:error' : 'icons:cloud-done'; | 179 'icons:error' : 'icons:cloud-done'; |
170 }, | 180 }, |
171 }); | 181 }); |
172 | 182 |
173 // Interface with the native WebUI component for the CryptAuthSync state (i.e. | 183 // Interface with the native WebUI component for getting the local state and |
174 // enrollment and device sync). | 184 // being notified when the local state changes. |
175 SyncStateInterface = { | 185 // The local state refers to state stored on the device rather than online in |
| 186 // CryptAuth. This state includes the enrollment and device sync states, as well |
| 187 // as the list of unlock keys. |
| 188 LocalStateInterface = { |
176 /** | 189 /** |
177 * Called when the enrollment state changes. For example, when a new | 190 * Called when the enrollment state changes. For example, when a new |
178 * enrollment is initiated. | 191 * enrollment is initiated. |
179 * @type {function(SyncState)} | 192 * @type {function(SyncState)} |
180 */ | 193 */ |
181 onEnrollmentStateChanged: function(enrollmentState) {}, | 194 onEnrollmentStateChanged: function(enrollmentState) {}, |
182 | 195 |
183 /** | 196 /** |
184 * Called when the device state changes. For example, when a new device sync | 197 * Called when the device state changes. For example, when a new device sync |
185 * is initiated. | 198 * is initiated. |
186 * @type {function(DeviceSyncState)} | 199 * @type {function(DeviceSyncState)} |
187 */ | 200 */ |
188 onDeviceSyncStateChanged: function(deviceSyncState) {}, | 201 onDeviceSyncStateChanged: function(deviceSyncState) {}, |
189 | 202 |
190 /** | 203 /** |
191 * Called in response to chrome.send('getSyncStates') with the current | 204 * Called when the locally stored unlock keys changes. |
192 * enrollment and device sync states of the user and device. | 205 * @type {function(Array<DeviceInfo>)} |
193 * @type {function(SyncState, SyncState)} | |
194 */ | 206 */ |
195 onGotSyncStates: function(enrollmentState, deviceSyncState) {}, | 207 onUnlockKeysChanged: function(unlockKeys) {}, |
| 208 |
| 209 /** |
| 210 * Called in response to chrome.send('getLocalState') with the local state. |
| 211 * @type {function(SyncState, SyncState, Array<DeviceInfo>)} |
| 212 */ |
| 213 onGotLocalState: function(enrollmentState, deviceSyncState, unlockKeys) {}, |
196 }; | 214 }; |
OLD | NEW |