| 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 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. |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 chrome.metricsPrivate.recordValue(metricDescription, event); | 228 chrome.metricsPrivate.recordValue(metricDescription, event); |
| 229 } | 229 } |
| 230 | 230 |
| 231 /** | 231 /** |
| 232 * Adds authorization behavior to the request. | 232 * Adds authorization behavior to the request. |
| 233 * @param {XMLHttpRequest} request Server request. | 233 * @param {XMLHttpRequest} request Server request. |
| 234 * @param {function(boolean)} callbackBoolean Completion callback with 'success' | 234 * @param {function(boolean)} callbackBoolean Completion callback with 'success' |
| 235 * parameter. | 235 * parameter. |
| 236 */ | 236 */ |
| 237 function setAuthorization(request, callbackBoolean) { | 237 function setAuthorization(request, callbackBoolean) { |
| 238 authenticationManager.isSignedIn(function(token) { | 238 authenticationManager.getAuthToken(function(token) { |
| 239 if (!token) { | 239 if (!token) { |
| 240 callbackBoolean(false); | 240 callbackBoolean(false); |
| 241 return; | 241 return; |
| 242 } | 242 } |
| 243 | 243 |
| 244 request.setRequestHeader('Authorization', 'Bearer ' + token); | 244 request.setRequestHeader('Authorization', 'Bearer ' + token); |
| 245 | 245 |
| 246 // Instrument onloadend to remove stale auth tokens. | 246 // Instrument onloadend to remove stale auth tokens. |
| 247 var originalOnLoadEnd = request.onloadend; | 247 var originalOnLoadEnd = request.onloadend; |
| 248 request.onloadend = wrapper.wrapCallback(function(event) { | 248 request.onloadend = wrapper.wrapCallback(function(event) { |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 setBackgroundEnable(shouldSetBackground); | 974 setBackgroundEnable(shouldSetBackground); |
| 975 setShouldPollCards(shouldPollCards); | 975 setShouldPollCards(shouldPollCards); |
| 976 } | 976 } |
| 977 | 977 |
| 978 /** | 978 /** |
| 979 * Coordinates the behavior of Google Now for Chrome depending on | 979 * Coordinates the behavior of Google Now for Chrome depending on |
| 980 * Chrome and extension state. | 980 * Chrome and extension state. |
| 981 */ | 981 */ |
| 982 function onStateChange() { | 982 function onStateChange() { |
| 983 tasks.add(STATE_CHANGED_TASK_NAME, function() { | 983 tasks.add(STATE_CHANGED_TASK_NAME, function() { |
| 984 authenticationManager.isSignedIn(function(token) { | 984 authenticationManager.isSignedIn(function(signedIn) { |
| 985 var signedIn = !!token; | |
| 986 instrumented.metricsPrivate.getVariationParams( | 985 instrumented.metricsPrivate.getVariationParams( |
| 987 'GoogleNow', | 986 'GoogleNow', |
| 988 function(response) { | 987 function(response) { |
| 989 var enableBackground = | 988 var enableBackground = |
| 990 (!response || (response.enableBackground != 'false')); | 989 (!response || (response.enableBackground != 'false')); |
| 991 instrumented.notifications.getPermissionLevel(function(level) { | 990 instrumented.notifications.getPermissionLevel(function(level) { |
| 992 var notificationEnabled = (level == 'granted'); | 991 var notificationEnabled = (level == 'granted'); |
| 993 instrumented. | 992 instrumented. |
| 994 preferencesPrivate. | 993 preferencesPrivate. |
| 995 googleGeolocationAccessEnabled. | 994 googleGeolocationAccessEnabled. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 | 1093 |
| 1095 updateCardsAttempts.isRunning(function(running) { | 1094 updateCardsAttempts.isRunning(function(running) { |
| 1096 if (running) | 1095 if (running) |
| 1097 requestNotificationGroups([]); | 1096 requestNotificationGroups([]); |
| 1098 }); | 1097 }); |
| 1099 } | 1098 } |
| 1100 }); | 1099 }); |
| 1101 }); | 1100 }); |
| 1102 } | 1101 } |
| 1103 }); | 1102 }); |
| OLD | NEW |