OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 // TODO(vadimt): Remove alerts. | 7 // TODO(vadimt): Remove alerts. |
8 | 8 |
9 /** | 9 /** |
10 * @fileoverview Utility objects and functions for Google Now extension. | 10 * @fileoverview Utility objects and functions for Google Now extension. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 * Builds an object to manage retrying activities with exponential backoff. | 267 * Builds an object to manage retrying activities with exponential backoff. |
268 * @param {string} name Name of this attempt manager. | 268 * @param {string} name Name of this attempt manager. |
269 * @param {function()} attempt Activity that the manager retries until it | 269 * @param {function()} attempt Activity that the manager retries until it |
270 * calls 'stop' method. | 270 * calls 'stop' method. |
271 * @param {number} initialDelaySeconds Default first delay until first retry. | 271 * @param {number} initialDelaySeconds Default first delay until first retry. |
272 * @param {number} maximumDelaySeconds Maximum delay between retries. | 272 * @param {number} maximumDelaySeconds Maximum delay between retries. |
273 * @return {Object} Attempt manager interface. | 273 * @return {Object} Attempt manager interface. |
274 */ | 274 */ |
275 function buildAttemptManager( | 275 function buildAttemptManager( |
276 name, attempt, initialDelaySeconds, maximumDelaySeconds) { | 276 name, attempt, initialDelaySeconds, maximumDelaySeconds) { |
277 var alarmName = name + '-scheduler'; | 277 var alarmName = 'attempt-scheduler-' + name; |
278 var currentDelayStorageKey = name + '-current-delay'; | 278 var currentDelayStorageKey = 'current-delay-' + name; |
279 | 279 |
280 /** | 280 /** |
281 * Creates an alarm for the next attempt. The alarm is repeating for the case | 281 * Creates an alarm for the next attempt. The alarm is repeating for the case |
282 * when the next attempt crashes before registering next alarm. | 282 * when the next attempt crashes before registering next alarm. |
283 * @param {number} delaySeconds Delay until next retry. | 283 * @param {number} delaySeconds Delay until next retry. |
284 */ | 284 */ |
285 function createAlarm(delaySeconds) { | 285 function createAlarm(delaySeconds) { |
286 var alarmInfo = { | 286 var alarmInfo = { |
287 delayInMinutes: delaySeconds / 60, | 287 delayInMinutes: delaySeconds / 60, |
288 periodInMinutes: maximumDelaySeconds / 60 | 288 periodInMinutes: maximumDelaySeconds / 60 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 if (alarm.name == alarmName) | 350 if (alarm.name == alarmName) |
351 attempt(); | 351 attempt(); |
352 }); | 352 }); |
353 | 353 |
354 return { | 354 return { |
355 start: start, | 355 start: start, |
356 planForNext: planForNext, | 356 planForNext: planForNext, |
357 stop: stop | 357 stop: stop |
358 }; | 358 }; |
359 } | 359 } |
OLD | NEW |