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

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

Issue 166033010: Convert Google Now's use of chrome.local.storage.get to use Promises (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR Feedback 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 * Show/hide trigger in a card. 8 * Show/hide trigger in a card.
9 * 9 *
10 * @typedef {{ 10 * @typedef {{
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 320 }
321 } 321 }
322 322
323 instrumented.alarms.onAlarm.addListener(function(alarm) { 323 instrumented.alarms.onAlarm.addListener(function(alarm) {
324 console.log('cardManager.onAlarm ' + JSON.stringify(alarm)); 324 console.log('cardManager.onAlarm ' + JSON.stringify(alarm));
325 325
326 if (alarm.name.indexOf(alarmPrefix) == 0) { 326 if (alarm.name.indexOf(alarmPrefix) == 0) {
327 // Alarm to show the card. 327 // Alarm to show the card.
328 tasks.add(UPDATE_CARD_TASK_NAME, function() { 328 tasks.add(UPDATE_CARD_TASK_NAME, function() {
329 var cardId = alarm.name.substring(alarmPrefix.length); 329 var cardId = alarm.name.substring(alarmPrefix.length);
330 instrumented.storage.local.get( 330 fillFromChromeLocalStorage({
331 ['notificationsData', 'notificationGroups'], 331 /** @type {Object.<string, NotificationDataEntry>} */
332 function(items) { 332 notificationsData: {},
333 console.log('cardManager.onAlarm.get ' + JSON.stringify(items)); 333 /** @type {Object.<string, StoredNotificationGroup>} */
334 items = items || {}; 334 notificationGroups: {}
335 /** @type {Object.<string, NotificationDataEntry>} */ 335 }).then(function(items) {
336 items.notificationsData = items.notificationsData || {}; 336 console.log('cardManager.onAlarm.get ' + JSON.stringify(items));
337 /** @type {Object.<string, StoredNotificationGroup>} */
338 items.notificationGroups = items.notificationGroups || {};
339 337
340 var combinedCard = 338 var combinedCard =
341 (items.notificationsData[cardId] && 339 (items.notificationsData[cardId] &&
342 items.notificationsData[cardId].combinedCard) || []; 340 items.notificationsData[cardId].combinedCard) || [];
343 341
344 var cardShownCallback = undefined; 342 var cardShownCallback = undefined;
345 if (localStorage['explanatoryCardsShown'] < 343 if (localStorage['explanatoryCardsShown'] <
346 EXPLANATORY_CARDS_LINK_THRESHOLD) { 344 EXPLANATORY_CARDS_LINK_THRESHOLD) {
347 cardShownCallback = countExplanatoryCard; 345 cardShownCallback = countExplanatoryCard;
348 } 346 }
349 347
350 items.notificationsData[cardId] = 348 items.notificationsData[cardId] =
351 update( 349 update(
352 cardId, 350 cardId,
353 combinedCard, 351 combinedCard,
354 items.notificationGroups, 352 items.notificationGroups,
355 cardShownCallback); 353 cardShownCallback);
356 354
357 chrome.storage.local.set(items); 355 chrome.storage.local.set(items);
358 }); 356 });
359 }); 357 });
360 } 358 }
361 }); 359 });
362 360
363 return { 361 return {
364 update: update, 362 update: update,
365 onDismissal: onDismissal 363 onDismissal: onDismissal
366 }; 364 };
367 } 365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698