| 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 * 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 * was instrumented by wrapper.wrapCallback() call. | 259 * was instrumented by wrapper.wrapCallback() call. |
| 260 * @type {boolean} | 260 * @type {boolean} |
| 261 */ | 261 */ |
| 262 var isInWrappedCallback = false; | 262 var isInWrappedCallback = false; |
| 263 | 263 |
| 264 /** | 264 /** |
| 265 * Required callbacks that are not yet called. Includes both task and non-task | 265 * Required callbacks that are not yet called. Includes both task and non-task |
| 266 * callbacks. This is a map from unique callback id to the stack at the moment | 266 * callbacks. This is a map from unique callback id to the stack at the moment |
| 267 * when the callback was wrapped. This stack identifies the callback. | 267 * when the callback was wrapped. This stack identifies the callback. |
| 268 * Used only for diagnostics. | 268 * Used only for diagnostics. |
| 269 * @type {Object.<number, string>} | 269 * @type {Object<number, string>} |
| 270 */ | 270 */ |
| 271 var pendingCallbacks = {}; | 271 var pendingCallbacks = {}; |
| 272 | 272 |
| 273 /** | 273 /** |
| 274 * Unique ID of the next callback. | 274 * Unique ID of the next callback. |
| 275 * @type {number} | 275 * @type {number} |
| 276 */ | 276 */ |
| 277 var nextCallbackId = 0; | 277 var nextCallbackId = 0; |
| 278 | 278 |
| 279 /** | 279 /** |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 338 |
| 339 return returnValue; | 339 return returnValue; |
| 340 } catch (error) { | 340 } catch (error) { |
| 341 reportError(error); | 341 reportError(error); |
| 342 } | 342 } |
| 343 }; | 343 }; |
| 344 } | 344 } |
| 345 | 345 |
| 346 /** | 346 /** |
| 347 * Returns an instrumented function. | 347 * Returns an instrumented function. |
| 348 * @param {!Array.<string>} functionIdentifierParts Path to the chrome.* | 348 * @param {!Array<string>} functionIdentifierParts Path to the chrome.* |
| 349 * function. | 349 * function. |
| 350 * @param {string} functionName Name of the chrome API function. | 350 * @param {string} functionName Name of the chrome API function. |
| 351 * @param {number} callbackParameter Index of the callback parameter to this | 351 * @param {number} callbackParameter Index of the callback parameter to this |
| 352 * API function. | 352 * API function. |
| 353 * @return {Function} An instrumented function. | 353 * @return {Function} An instrumented function. |
| 354 */ | 354 */ |
| 355 function createInstrumentedFunction( | 355 function createInstrumentedFunction( |
| 356 functionIdentifierParts, | 356 functionIdentifierParts, |
| 357 functionName, | 357 functionName, |
| 358 callbackParameter) { | 358 callbackParameter) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 * is nothing left to do. | 508 * is nothing left to do. |
| 509 * @param {object} promise Promise being tracked. | 509 * @param {object} promise Promise being tracked. |
| 510 * @return {object} A promise callback tracker. | 510 * @return {object} A promise callback tracker. |
| 511 */ | 511 */ |
| 512 function createPromiseCallbackTracker(promise) { | 512 function createPromiseCallbackTracker(promise) { |
| 513 /** | 513 /** |
| 514 * Callback Tracker. Holds an array of callbacks created for this promise. | 514 * Callback Tracker. Holds an array of callbacks created for this promise. |
| 515 * The indirection allows quick checks against the array and clearing the | 515 * The indirection allows quick checks against the array and clearing the |
| 516 * array without ugly splicing and copying. | 516 * array without ugly splicing and copying. |
| 517 * @typedef {{ | 517 * @typedef {{ |
| 518 * callback: array.<Function>= | 518 * callback: array<Function>= |
| 519 * }} | 519 * }} |
| 520 */ | 520 */ |
| 521 var CallbackTracker; | 521 var CallbackTracker; |
| 522 | 522 |
| 523 /** @type {CallbackTracker} */ | 523 /** @type {CallbackTracker} */ |
| 524 var thenTracker = {callbacks: []}; | 524 var thenTracker = {callbacks: []}; |
| 525 /** @type {CallbackTracker} */ | 525 /** @type {CallbackTracker} */ |
| 526 var catchTracker = {callbacks: []}; | 526 var catchTracker = {callbacks: []}; |
| 527 | 527 |
| 528 /** | 528 /** |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 * Builds the object to manage tasks (mutually exclusive chains of events). | 689 * Builds the object to manage tasks (mutually exclusive chains of events). |
| 690 * @param {function(string, string): boolean} areConflicting Function that | 690 * @param {function(string, string): boolean} areConflicting Function that |
| 691 * checks if a new task can't be added to a task queue that contains an | 691 * checks if a new task can't be added to a task queue that contains an |
| 692 * existing task. | 692 * existing task. |
| 693 * @return {Object} Task manager interface. | 693 * @return {Object} Task manager interface. |
| 694 */ | 694 */ |
| 695 function buildTaskManager(areConflicting) { | 695 function buildTaskManager(areConflicting) { |
| 696 /** | 696 /** |
| 697 * Queue of scheduled tasks. The first element, if present, corresponds to the | 697 * Queue of scheduled tasks. The first element, if present, corresponds to the |
| 698 * currently running task. | 698 * currently running task. |
| 699 * @type {Array.<Object.<string, function()>>} | 699 * @type {Array<Object<string, function()>>} |
| 700 */ | 700 */ |
| 701 var queue = []; | 701 var queue = []; |
| 702 | 702 |
| 703 /** | 703 /** |
| 704 * Count of unfinished callbacks of the current task. | 704 * Count of unfinished callbacks of the current task. |
| 705 * @type {number} | 705 * @type {number} |
| 706 */ | 706 */ |
| 707 var taskPendingCallbackCount = 0; | 707 var taskPendingCallbackCount = 0; |
| 708 | 708 |
| 709 /** | 709 /** |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 // One hour is just an arbitrary amount of time chosen. | 1052 // One hour is just an arbitrary amount of time chosen. |
| 1053 chrome.alarms.create(alarmName, {periodInMinutes: 60}); | 1053 chrome.alarms.create(alarmName, {periodInMinutes: 60}); |
| 1054 | 1054 |
| 1055 return { | 1055 return { |
| 1056 addListener: addListener, | 1056 addListener: addListener, |
| 1057 getAuthToken: getAuthToken, | 1057 getAuthToken: getAuthToken, |
| 1058 isSignedIn: isSignedIn, | 1058 isSignedIn: isSignedIn, |
| 1059 removeToken: removeToken | 1059 removeToken: removeToken |
| 1060 }; | 1060 }; |
| 1061 } | 1061 } |
| OLD | NEW |