1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 cr
.define('chrome.invalidations', function() {
8 return '\"' + str
+ '\"';
11 function nowTimeString() {
12 return '[' + new Date().getTime() + '] ';
16 * Appends a string to a textarea log.
18 * @param {string} logMessage The string to be appended.
20 function appendToLog(logMessage
) {
21 var invalidationsLog
= $('invalidations-log');
22 invalidationsLog
.value
+= logMessage
+ '\n';
26 * Shows the current state of the InvalidatorService
28 * @param {string} newState The string to be displayed and logged.
30 function updateState(newState
) {
31 var logMessage
= nowTimeString() +
32 'Invalidations service state changed to ' + quote(newState
);
34 appendToLog(logMessage
);
35 $('invalidations-state').textContent
= newState
;
36 currentInvalidationState
= newState
;
40 * Adds to the log the latest invalidations received
42 * @param {Array of Object} allInvalidations The array of ObjectId
43 * that contains the invalidations received by the InvalidatorService
45 function logInvalidations(allInvalidations
) {
46 for (var i
= 0; i
< allInvalidations
.length
; i
++) {
47 var inv
= allInvalidations
[i
];
48 if (inv
.hasOwnProperty('objectId')) {
49 var logMessage
= nowTimeString() +
50 'Received Invalidation with type ' +
51 quote(inv
.objectId
.name
) +
53 quote((inv
.isUnknownVersion
? 'Unknown' : inv
.version
)) +
57 appendToLog(logMessage
);
63 * Function that notifies the Invalidator Logger that the UI is
64 * ready to receive real-time notifications.
66 function onLoadWork() {
67 chrome
.send('doneLoading');
71 updateState
: updateState
,
72 logInvalidations
: logInvalidations
,
73 onLoadWork
: onLoadWork
77 document
.addEventListener('DOMContentLoaded', chrome
.invalidations
.onLoadWork
);