Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: chrome/browser/resources/google_now/utility.js

Issue 217263005: Add Optin Retry Logic to Google Now (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * Most important entities here: 9 * Most important entities here:
10 * (1) 'wrapper' is a module used to add error handling and other services to 10 * (1) 'wrapper' is a module used to add error handling and other services to
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 * PromiseRejection.ALLOW, allow promise rejection on errors, otherwise the 641 * PromiseRejection.ALLOW, allow promise rejection on errors, otherwise the
642 * default storage object is resolved. 642 * default storage object is resolved.
643 * @return {Promise} A promise that fills the default storage object. On 643 * @return {Promise} A promise that fills the default storage object. On
644 * failure, if promise rejection is allowed, the promise is rejected, 644 * failure, if promise rejection is allowed, the promise is rejected,
645 * otherwise it is resolved to the default storage object. 645 * otherwise it is resolved to the default storage object.
646 */ 646 */
647 function fillFromChromeLocalStorage( 647 function fillFromChromeLocalStorage(
648 defaultStorageObject, 648 defaultStorageObject,
649 opt_allowPromiseRejection) { 649 opt_allowPromiseRejection) {
650 return new Promise(function(resolve, reject) { 650 return new Promise(function(resolve, reject) {
651 instrumented.storage.local.get(defaultStorageObject, function(items) { 651 // We have to create a keys array because keys with a default value
652 // of undefined will cause that key to not be looked up!
653 var keysToGet = [];
654 for (var key in defaultStorageObject) {
655 keysToGet.push(key);
656 }
657 instrumented.storage.local.get(keysToGet, function(items) {
652 if (items) { 658 if (items) {
653 resolve(items); 659 // Merge the result with the default storage object.
660 var result = {};
661 for (var key in defaultStorageObject) {
662 result[key] = (key in items) ? items[key] : defaultStorageObject[key];
663 }
664 resolve(result);
654 } else if (opt_allowPromiseRejection === PromiseRejection.ALLOW) { 665 } else if (opt_allowPromiseRejection === PromiseRejection.ALLOW) {
655 reject(); 666 reject();
656 } else { 667 } else {
657 resolve(defaultStorageObject); 668 resolve(defaultStorageObject);
658 } 669 }
659 }); 670 });
660 }); 671 });
661 } 672 }
662 673
663 /** 674 /**
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 // One hour is just an arbitrary amount of time chosen. 1038 // One hour is just an arbitrary amount of time chosen.
1028 chrome.alarms.create(alarmName, {periodInMinutes: 60}); 1039 chrome.alarms.create(alarmName, {periodInMinutes: 60});
1029 1040
1030 return { 1041 return {
1031 addListener: addListener, 1042 addListener: addListener,
1032 getAuthToken: getAuthToken, 1043 getAuthToken: getAuthToken,
1033 isSignedIn: isSignedIn, 1044 isSignedIn: isSignedIn,
1034 removeToken: removeToken 1045 removeToken: removeToken
1035 }; 1046 };
1036 } 1047 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698