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

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

Issue 12508004: Enabling testing Google Now component extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rgustafson's notes Created 7 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 (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 The event page for Google Now for Chrome implementation. 8 * @fileoverview The event page for Google Now for Chrome implementation.
9 * The Google Now event page gets Google Now cards from the server and shows 9 * The Google Now event page gets Google Now cards from the server and shows
10 * them as Chrome notifications. 10 * them as Chrome notifications.
11 * The service performs periodic updating of Google Now cards. 11 * The service performs periodic updating of Google Now cards.
12 * Each updating of the cards includes 3 steps: 12 * Each updating of the cards includes 3 steps:
13 * 1. Obtaining the location of the machine; 13 * 1. Obtaining the location of the machine;
14 * 2. Making a server request based on that location; 14 * 2. Making a server request based on that location;
15 * 3. Showing the received cards as notifications. 15 * 3. Showing the received cards as notifications.
16 */ 16 */
17 17
18 // TODO(vadimt): Use background permission to show notifications even when all 18 // TODO(vadimt): Use background permission to show notifications even when all
19 // browser windows are closed. 19 // browser windows are closed.
20 // TODO(vadimt): Remove the C++ implementation. 20 // TODO(vadimt): Remove the C++ implementation.
21 // TODO(vadimt): Decide what to do in incognito mode. 21 // TODO(vadimt): Decide what to do in incognito mode.
22 // TODO(vadimt): Gather UMAs. 22 // TODO(vadimt): Gather UMAs.
23 // TODO(vadimt): Honor the flag the enables Google Now integration. 23 // TODO(vadimt): Honor the flag the enables Google Now integration.
24 // TODO(vadimt): Figure out the final values of the constants. 24 // TODO(vadimt): Figure out the final values of the constants.
25 // TODO(vadimt): Report internal and server errors. Collect UMAs on errors where 25 // TODO(vadimt): Report internal and server errors. Collect UMAs on errors where
26 // appropriate. Also consider logging errors or throwing exceptions. 26 // appropriate. Also consider logging errors or throwing exceptions.
27 27
28 // TODO(vadimt): Consider processing errors for all storage.set calls.
skare_ 2013/03/06 22:08:01 has this edit already been done in another review
vadimt 2013/03/06 22:37:12 "Yes" to both :) The Races review (next in the que
skare_ 2013/03/07 00:56:39 ok, great, thanks On 2013/03/06 22:37:12, vadimt w
28 // TODO(vadimt): Figure out the server name. Use it in the manifest and for 29 // TODO(vadimt): Figure out the server name. Use it in the manifest and for
29 // TODO(vadimt): Consider processing errors for all storage.set calls.
30 // NOTIFICATION_CARDS_URL. Meanwhile, to use the feature, you need to manually 30 // NOTIFICATION_CARDS_URL. Meanwhile, to use the feature, you need to manually
31 // edit NOTIFICATION_CARDS_URL before building Chrome. 31 // set the server name via local storage.
32 /** 32 /**
33 * URL to retrieve notification cards. 33 * URL to retrieve notification cards.
34 */ 34 */
35 var NOTIFICATION_CARDS_URL = ''; 35 var NOTIFICATION_CARDS_URL = localStorage['server_url'];
36 36
37 /** 37 /**
38 * Standard response code for successful HTTP requests. This is the only success 38 * Standard response code for successful HTTP requests. This is the only success
39 * code the server will send. 39 * code the server will send.
40 */ 40 */
41 var HTTP_OK = 200; 41 var HTTP_OK = 200;
42 42
43 /** 43 /**
44 * Initial period for polling for Google Now Notifications cards to use when the 44 * Initial period for polling for Google Now Notifications cards to use when the
45 * period from the server is not available. 45 * period from the server is not available.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Mark existing notifications that received an update in this server 101 // Mark existing notifications that received an update in this server
102 // response. 102 // response.
103 for (var i = 0; i < cards.length; ++i) { 103 for (var i = 0; i < cards.length; ++i) {
104 var notificationId = cards[i].notificationId; 104 var notificationId = cards[i].notificationId;
105 if (notificationId in items.activeNotifications) 105 if (notificationId in items.activeNotifications)
106 items.activeNotifications[notificationId].hasUpdate = true; 106 items.activeNotifications[notificationId].hasUpdate = true;
107 } 107 }
108 108
109 // Delete notifications that didn't receive an update. 109 // Delete notifications that didn't receive an update.
110 for (var notificationId in items.activeNotifications) 110 for (var notificationId in items.activeNotifications)
111 if (!items.activeNotifications[notificationId].hasUpdate) { 111 if (items.activeNotifications.hasOwnProperty(notificationId) &&
112 !items.activeNotifications[notificationId].hasUpdate) {
112 chrome.experimental.notification.clear( 113 chrome.experimental.notification.clear(
113 notificationId, 114 notificationId,
114 function(wasDeleted) {}); 115 function(wasDeleted) {});
115 } 116 }
116 117
117 // Create/update notifications and store their new properties. 118 // Create/update notifications and store their new properties.
118 var notificationsUrlInfo = {}; 119 var notificationsUrlInfo = {};
119 120
120 for (var i = 0; i < cards.length; ++i) { 121 for (var i = 0; i < cards.length; ++i) {
121 try { 122 try {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 function(notificationId, buttonIndex) { 301 function(notificationId, buttonIndex) {
301 onNotificationClicked(notificationId, function(actionUrls) { 302 onNotificationClicked(notificationId, function(actionUrls) {
302 if (!Array.isArray(actionUrls.buttonUrls)) 303 if (!Array.isArray(actionUrls.buttonUrls))
303 return undefined; 304 return undefined;
304 305
305 return actionUrls.buttonUrls[buttonIndex]; 306 return actionUrls.buttonUrls[buttonIndex];
306 }); 307 });
307 }); 308 });
308 309
309 chrome.experimental.notification.onClosed.addListener(onNotificationClosed); 310 chrome.experimental.notification.onClosed.addListener(onNotificationClosed);
OLDNEW
« chrome/browser/chrome_browser_main.cc ('K') | « chrome/browser/chrome_browser_main.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698