Index: chrome/browser/resources/google_now/utility.js |
diff --git a/chrome/browser/resources/google_now/utility.js b/chrome/browser/resources/google_now/utility.js |
index f2236209fc498ffa15c0b2cc10c89d254e5a8c84..2946dc0dfa8e3809b2b57c2879ce0b66b9eb016f 100644 |
--- a/chrome/browser/resources/google_now/utility.js |
+++ b/chrome/browser/resources/google_now/utility.js |
@@ -323,7 +323,7 @@ var wrapper = (function() { |
wrapperPluginInstance.prologue(); |
// Call the original callback. |
- callback.apply(null, arguments); |
+ var returnValue = callback.apply(null, arguments); |
if (wrapperPluginInstance) |
wrapperPluginInstance.epilogue(); |
@@ -331,6 +331,8 @@ var wrapper = (function() { |
verify(isInWrappedCallback, |
'Instrumented callback is not instrumented upon exit'); |
isInWrappedCallback = false; |
+ |
+ return returnValue; |
} catch (error) { |
reportError(error); |
} |
@@ -434,6 +436,7 @@ wrapper.instrumentChromeApiFunction('alarms.onAlarm.addListener', 0); |
wrapper.instrumentChromeApiFunction('identity.getAuthToken', 1); |
wrapper.instrumentChromeApiFunction('identity.onSignInChanged.addListener', 0); |
wrapper.instrumentChromeApiFunction('identity.removeCachedAuthToken', 1); |
+wrapper.instrumentChromeApiFunction('storage.local.get', 1); |
wrapper.instrumentChromeApiFunction('webstorePrivate.getBrowserLogin', 0); |
/** |
@@ -458,6 +461,47 @@ Promise.prototype.catch = function() { |
} |
}(); |
+ |
+/* |
skare_
2014/02/20 00:17:12
nit: /* -> /** and in :472
(sorry!)
robliao
2014/02/21 21:25:45
Done.
|
+ * Disallow promise rejection. |
+ * @type {boolean} |
+ * @const |
+ */ |
+var NO_PROMISE_REJECTION = false; |
skare_
2014/02/20 00:17:12
(no action required)
this works; could make an @en
robliao
2014/02/21 21:25:45
Done.
|
+ |
+/* |
+ * Allow promise rejection. |
+ * @type {boolean} |
+ * @const |
+ */ |
+var ALLOW_PROMISE_REJECTION = true; |
+ |
+/** |
+ * Provides the promise equivalent of instrumented.chrome.local.get. |
skare_
2014/02/20 00:17:12
instrumented.chrome.storage.local?
robliao
2014/02/21 21:25:45
Done.
|
+ * @param {Object} defaultStorageObject Default storage object to fill. |
+ * @param {boolean} opt_allowPromiseRejection If ALLOW_PROMISE_REJECTION, |
+ * allows promise rejection on errors, otherwise the default storage |
+ * object is resolved. |
+ * @return {Promise} A promise that fills the default storage object. On |
skare_
2014/02/20 00:17:12
just as a first-read opinion, "fills" is slightly
robliao
2014/02/21 21:25:45
I'm open to other suggestions.
I chose fill becau
|
+ * failure, if promise rejection is a allowed, the promise is rejected, |
skare_
2014/02/20 00:17:12
nit: is a allowed -> is allowed
robliao
2014/02/21 21:25:45
Done.
|
+ * otherwise it is resolved to the default storage object. |
+ */ |
+function fillFromChromeLocalStorage( |
+ defaultStorageObject, |
+ opt_allowPromiseRejection) { |
+ return new Promise(function(resolve, reject) { |
+ instrumented.storage.local.get(defaultStorageObject, function(items) { |
+ if (items) { |
+ resolve(items); |
+ } else if (opt_allowPromiseRejection === ALLOW_PROMISE_REJECTION) { |
+ reject(); |
+ } else { |
+ resolve(defaultStorageObject); |
+ } |
+ }); |
+ }); |
+} |
+ |
/** |
* Builds the object to manage tasks (mutually exclusive chains of events). |
* @param {function(string, string): boolean} areConflicting Function that |
@@ -699,11 +743,9 @@ function buildAttemptManager( |
* the planning is done. |
*/ |
function planForNext(callback) { |
- instrumented.storage.local.get(currentDelayStorageKey, function(items) { |
- if (!items) { |
- items = {}; |
- items[currentDelayStorageKey] = maximumDelaySeconds; |
- } |
+ var request = {}; |
+ request[currentDelayStorageKey] = maximumDelaySeconds; |
+ fillFromChromeLocalStorage(request).then(function(items) { |
console.log('planForNext-get-storage ' + JSON.stringify(items)); |
scheduleNextAttempt(items[currentDelayStorageKey]); |
callback(); |
@@ -797,17 +839,17 @@ function buildAuthenticationManager() { |
*/ |
function checkAndNotifyListeners() { |
isSignedIn().then(function(signedIn) { |
- instrumented.storage.local.get('lastSignedInState', function(items) { |
- items = items || {}; |
- if (items.lastSignedInState != signedIn) { |
- chrome.storage.local.set( |
- {lastSignedInState: signedIn}); |
- listeners.forEach(function(callback) { |
- callback(); |
- }); |
- } |
+ fillFromChromeLocalStorage({lastSignedInState: undefined}) |
+ .then(function(items) { |
+ if (items.lastSignedInState != signedIn) { |
+ chrome.storage.local.set( |
+ {lastSignedInState: signedIn}); |
+ listeners.forEach(function(callback) { |
+ callback(); |
+ }); |
+ } |
+ }); |
}); |
- }); |
} |
instrumented.identity.onSignInChanged.addListener(function() { |