NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / resources / about_invalidations.js
blobdb58dc9bf91500a770065ce7a1faa02ee0240fe1
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() {
7 function quote(str) {
8 return '\"' + str + '\"';
11 function nowTimeString() {
12 return '[' + new Date().getTime() + '] ';
15 /**
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';
25 /**
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;
39 /**
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) +
52 ' version ' +
53 quote((inv.isUnknownVersion ? 'Unknown' : inv.version)) +
54 ' with payload ' +
55 quote(inv.payload);
57 appendToLog(logMessage);
62 /**
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');
70 return {
71 updateState: updateState,
72 logInvalidations: logInvalidations,
73 onLoadWork: onLoadWork
75 });
77 document.addEventListener('DOMContentLoaded', chrome.invalidations.onLoadWork);