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 /** | 7 /** |
8 * @fileoverview Utility objects and functions for Google Now extension. | 8 * @fileoverview Utility objects and functions for Google Now extension. |
9 */ | 9 */ |
10 | 10 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 chrome.storage.local.remove(currentDelayStorageKey); | 497 chrome.storage.local.remove(currentDelayStorageKey); |
498 } | 498 } |
499 | 499 |
500 /** | 500 /** |
501 * Plans for the next attempt. | 501 * Plans for the next attempt. |
502 * @param {function()} callback Completion callback. It will be invoked after | 502 * @param {function()} callback Completion callback. It will be invoked after |
503 * the planning is done. | 503 * the planning is done. |
504 */ | 504 */ |
505 function planForNext(callback) { | 505 function planForNext(callback) { |
506 instrumented.storage.local.get(currentDelayStorageKey, function(items) { | 506 instrumented.storage.local.get(currentDelayStorageKey, function(items) { |
507 if (!items) { | |
508 items = {}; | |
rgustafson
2013/08/22 00:46:14
why not items.currentDelayStorageKey like everythi
rgustafson
2013/08/22 00:49:53
I just answered that for myself right after asking
| |
509 items[currentDelayStorageKey] = maximumDelaySeconds; | |
510 } | |
507 console.log('planForNext-get-storage ' + JSON.stringify(items)); | 511 console.log('planForNext-get-storage ' + JSON.stringify(items)); |
508 scheduleNextAttempt(items[currentDelayStorageKey]); | 512 scheduleNextAttempt(items[currentDelayStorageKey]); |
509 callback(); | 513 callback(); |
510 }); | 514 }); |
511 } | 515 } |
512 | 516 |
513 instrumented.alarms.onAlarm.addListener(function(alarm) { | 517 instrumented.alarms.onAlarm.addListener(function(alarm) { |
514 if (alarm.name == alarmName) | 518 if (alarm.name == alarmName) |
515 isRunning(function(running) { | 519 isRunning(function(running) { |
516 if (running) | 520 if (running) |
(...skipping 30 matching lines...) Expand all Loading... | |
547 instrumented.identity.getAuthToken({interactive: false}, function(token) { | 551 instrumented.identity.getAuthToken({interactive: false}, function(token) { |
548 token = chrome.runtime.lastError ? undefined : token; | 552 token = chrome.runtime.lastError ? undefined : token; |
549 callback(token); | 553 callback(token); |
550 checkAndNotifyListeners(!!token); | 554 checkAndNotifyListeners(!!token); |
551 }); | 555 }); |
552 } | 556 } |
553 | 557 |
554 /** | 558 /** |
555 * Removes the specified cached token. | 559 * Removes the specified cached token. |
556 * @param {string} token Authentication Token to remove from the cache. | 560 * @param {string} token Authentication Token to remove from the cache. |
557 * @param {function} onSuccess Called on completion. | 561 * @param {function} callback Called on completion. |
558 */ | 562 */ |
559 function removeToken(token, onSuccess) { | 563 function removeToken(token, callback) { |
560 instrumented.identity.removeCachedAuthToken({token: token}, function() { | 564 instrumented.identity.removeCachedAuthToken({token: token}, function() { |
561 // Removing the token from the cache will change the sign in state. | 565 // Removing the token from the cache will change the sign in state. |
562 // Repoll now to check the state and notify listeners. | 566 // Repoll now to check the state and notify listeners. |
563 // This also lets Chrome now about a possible problem with the token. | 567 // This also lets Chrome now about a possible problem with the token. |
564 isSignedIn(function() {}); | 568 isSignedIn(function() {}); |
565 onSuccess(); | 569 callback(); |
566 }); | 570 }); |
567 } | 571 } |
568 | 572 |
569 var listeners = []; | 573 var listeners = []; |
570 | 574 |
571 /** | 575 /** |
572 * Registers a listener that gets called back when the signed in state | 576 * Registers a listener that gets called back when the signed in state |
573 * is found to be changed. | 577 * is found to be changed. |
574 * @param {function} callback Called when the answer to isSignedIn changes. | 578 * @param {function} callback Called when the answer to isSignedIn changes. |
575 */ | 579 */ |
(...skipping 24 matching lines...) Expand all Loading... | |
600 // Poll for the sign in state every hour. | 604 // Poll for the sign in state every hour. |
601 // One hour is just an arbitrary amount of time chosen. | 605 // One hour is just an arbitrary amount of time chosen. |
602 chrome.alarms.create(alarmName, {periodInMinutes: 60}); | 606 chrome.alarms.create(alarmName, {periodInMinutes: 60}); |
603 | 607 |
604 return { | 608 return { |
605 addListener: addListener, | 609 addListener: addListener, |
606 isSignedIn: isSignedIn, | 610 isSignedIn: isSignedIn, |
607 removeToken: removeToken | 611 removeToken: removeToken |
608 }; | 612 }; |
609 } | 613 } |
OLD | NEW |