OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 var localStrings; | |
6 | |
7 // Timer that will check and update the countdown every second. | |
8 var countdownTimer; | |
9 // Time at which we should logout the user unless we've been closed. | |
10 var logoutTime; // ms | |
11 | |
12 /** | |
13 * Gets time since epoch in miliseconds. | |
14 */ | |
15 function getMillisecondsSinceEpoch() { | |
16 var time = new Date(); | |
17 return time.getTime(); | |
18 } | |
19 | |
20 /** | |
21 * Decrements the countdown timer and updates the display on the dialog. | |
22 */ | |
23 function decrementTimer() { | |
24 var currentTime = getMillisecondsSinceEpoch(); | |
arv (Not doing code reviews)
2012/03/02 02:26:20
replace with Date.now()
rkc
2012/03/02 03:03:21
Done.
| |
25 if (logoutTime > currentTime) { | |
26 secondsToRestart = Math.round((logoutTime - currentTime) / 1000); | |
27 $('warning').innerHTML = localStrings.getStringF('warning', | |
28 secondsToRestart); | |
29 } else { | |
30 clearInterval(countdownTimer); | |
31 chrome.send('requestLogout'); | |
32 } | |
33 } | |
34 | |
35 /** | |
36 * Starts the countdown to logout. | |
37 */ | |
38 function startCountdown(seconds) { | |
39 logoutTime = getMillisecondsSinceEpoch() + (seconds * 1000); | |
40 $('warning').innerHTML = localStrings.getStringF('warning', | |
41 seconds); | |
42 countdownTimer = setInterval(decrementTimer, 1000); | |
43 } | |
44 | |
45 /** | |
46 * Inserts translated strings on loading. | |
47 */ | |
48 function initialize() { | |
49 localStrings = new LocalStrings(); | |
50 | |
51 i18nTemplate.process(document, templateData); | |
52 chrome.send('requestCountdown'); | |
53 } | |
54 | |
55 document.addEventListener('DOMContentLoaded', initialize); | |
OLD | NEW |