| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 * @param {string} message Diagnostic message for the case when the condition is | 51 * @param {string} message Diagnostic message for the case when the condition is |
| 52 * false. | 52 * false. |
| 53 */ | 53 */ |
| 54 function verify(condition, message) { | 54 function verify(condition, message) { |
| 55 if (!condition) | 55 if (!condition) |
| 56 throw buildErrorWithMessageForServer('ASSERT: ' + message); | 56 throw buildErrorWithMessageForServer('ASSERT: ' + message); |
| 57 } | 57 } |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Builds a request to the notification server. | 60 * Builds a request to the notification server. |
| 61 * @param {string} method Request method. |
| 61 * @param {string} handlerName Server handler to send the request to. | 62 * @param {string} handlerName Server handler to send the request to. |
| 62 * @param {string} contentType Value for the Content-type header. | 63 * @param {string=} contentType Value for the Content-type header. |
| 63 * @return {XMLHttpRequest} Server request. | 64 * @return {XMLHttpRequest} Server request. |
| 64 */ | 65 */ |
| 65 function buildServerRequest(handlerName, contentType) { | 66 function buildServerRequest(method, handlerName, contentType) { |
| 66 var request = new XMLHttpRequest(); | 67 var request = new XMLHttpRequest(); |
| 67 | 68 |
| 68 request.responseType = 'text'; | 69 request.responseType = 'text'; |
| 69 request.open('POST', NOTIFICATION_CARDS_URL + '/' + handlerName, true); | 70 request.open(method, NOTIFICATION_CARDS_URL + '/' + handlerName, true); |
| 70 request.setRequestHeader('Content-type', contentType); | 71 if (contentType) |
| 72 request.setRequestHeader('Content-type', contentType); |
| 71 | 73 |
| 72 return request; | 74 return request; |
| 73 } | 75 } |
| 74 | 76 |
| 75 /** | 77 /** |
| 76 * Sends an error report to the server. | 78 * Sends an error report to the server. |
| 77 * @param {Error} error Error to send. | 79 * @param {Error} error Error to send. |
| 78 */ | 80 */ |
| 79 function sendErrorReport(error) { | 81 function sendErrorReport(error) { |
| 80 // Don't remove 'error.stack.replace' below! | 82 // Don't remove 'error.stack.replace' below! |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 if (error.canSendMessageToServer) | 120 if (error.canSendMessageToServer) |
| 119 errorText = errorText + ': ' + error.message; | 121 errorText = errorText + ': ' + error.message; |
| 120 | 122 |
| 121 var errorObject = { | 123 var errorObject = { |
| 122 message: errorText, | 124 message: errorText, |
| 123 file: file, | 125 file: file, |
| 124 line: line, | 126 line: line, |
| 125 trace: filteredStack | 127 trace: filteredStack |
| 126 }; | 128 }; |
| 127 | 129 |
| 128 var request = buildServerRequest('jserrors', 'application/json'); | 130 var request = buildServerRequest('POST', 'jserrors', 'application/json'); |
| 129 request.onloadend = function(event) { | 131 request.onloadend = function(event) { |
| 130 console.log('sendErrorReport status: ' + request.status); | 132 console.log('sendErrorReport status: ' + request.status); |
| 131 }; | 133 }; |
| 132 request.send(JSON.stringify(errorObject)); | 134 request.send(JSON.stringify(errorObject)); |
| 133 } | 135 } |
| 134 | 136 |
| 135 // Limiting 1 error report per background page load. | 137 // Limiting 1 error report per background page load. |
| 136 var errorReported = false; | 138 var errorReported = false; |
| 137 | 139 |
| 138 /** | 140 /** |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 // Poll for the sign in state every hour. | 734 // Poll for the sign in state every hour. |
| 733 // One hour is just an arbitrary amount of time chosen. | 735 // One hour is just an arbitrary amount of time chosen. |
| 734 chrome.alarms.create(alarmName, {periodInMinutes: 60}); | 736 chrome.alarms.create(alarmName, {periodInMinutes: 60}); |
| 735 | 737 |
| 736 return { | 738 return { |
| 737 addListener: addListener, | 739 addListener: addListener, |
| 738 isSignedIn: isSignedIn, | 740 isSignedIn: isSignedIn, |
| 739 removeToken: removeToken | 741 removeToken: removeToken |
| 740 }; | 742 }; |
| 741 } | 743 } |
| OLD | NEW |