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

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: Word change Created 6 years, 8 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
« no previous file with comments | « chrome/browser/resources/google_now/background.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 to ensure all keys
660 // requested have either the default value or the retrieved storage
661 // value.
662 var result = {};
663 for (var key in defaultStorageObject) {
664 result[key] = (key in items) ? items[key] : defaultStorageObject[key];
665 }
666 resolve(result);
654 } else if (opt_allowPromiseRejection === PromiseRejection.ALLOW) { 667 } else if (opt_allowPromiseRejection === PromiseRejection.ALLOW) {
655 reject(); 668 reject();
656 } else { 669 } else {
657 resolve(defaultStorageObject); 670 resolve(defaultStorageObject);
658 } 671 }
659 }); 672 });
660 }); 673 });
661 } 674 }
662 675
663 /** 676 /**
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 // One hour is just an arbitrary amount of time chosen. 1040 // One hour is just an arbitrary amount of time chosen.
1028 chrome.alarms.create(alarmName, {periodInMinutes: 60}); 1041 chrome.alarms.create(alarmName, {periodInMinutes: 60});
1029 1042
1030 return { 1043 return {
1031 addListener: addListener, 1044 addListener: addListener,
1032 getAuthToken: getAuthToken, 1045 getAuthToken: getAuthToken,
1033 isSignedIn: isSignedIn, 1046 isSignedIn: isSignedIn,
1034 removeToken: removeToken 1047 removeToken: removeToken
1035 }; 1048 };
1036 } 1049 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/google_now/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698