| OLD | NEW |
| 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 Loading... |
| 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 } |
| OLD | NEW |