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

Side by Side Diff: chrome/browser/resources/sync_internals/about.js

Issue 210233005: sync: Display protocol events on about:sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nit + unrelated bug Created 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 function highlightIfChanged(node, oldVal, newVal) { 5 cr.define('chrome.sync.about_tab', function() {
6 function clearHighlight() { 6 // Contains the latest snapshot of sync about info.
7 this.removeAttribute('highlighted'); 7 chrome.sync.aboutInfo = {};
8
9 function refreshAboutInfo(aboutInfo) {
10 chrome.sync.aboutInfo = aboutInfo;
11 var aboutInfoDiv = $('about-info');
12 jstProcess(new JsEvalContext(aboutInfo), aboutInfoDiv);
8 } 13 }
9 14
10 var oldStr = oldVal.toString(); 15 function onAboutInfoUpdatedEvent(e) {
11 var newStr = newVal.toString(); 16 refreshAboutInfo(e.details);
12 if (oldStr != '' && oldStr != newStr) {
13 // Note the addListener function does not end up creating duplicate
14 // listeners. There can be only one listener per event at a time.
15 // Reference: https://developer.mozilla.org/en/DOM/element.addEventListener
16 node.addEventListener('webkitAnimationEnd', clearHighlight, false);
17 node.setAttribute('highlighted', '');
18 } 17 }
19 }
20 18
21 (function() { 19 /** Container for accumulated sync protocol events. */
22 // Contains the latest snapshot of sync about info. 20 var protocolEvents = [];
23 chrome.sync.aboutInfo = {};
24 21
25 function refreshAboutInfo(aboutInfo) { 22 /**
26 chrome.sync.aboutInfo = aboutInfo; 23 * Callback for incoming protocol events.
27 var aboutInfoDiv = $('aboutInfo'); 24 * @param {Event} e The protocol event.
28 jstProcess(new JsEvalContext(aboutInfo), aboutInfoDiv); 25 */
29 } 26 function onReceivedProtocolEvent(e) {
27 var details = e.details;
28 protocolEvents.push(details);
30 29
31 function onAboutInfoUpdatedEvent(e) { 30 var context = new JsEvalContext({ events: protocolEvents });
32 refreshAboutInfo(e.details); 31 jstProcess(context, $('traffic-event-container'));
33 } 32 }
34 33
35 function onLoad() { 34 /**
36 $('status-data').hidden = true; 35 * Initializes state and callbacks for the protocol event log UI.
36 */
37 function initProtocolEventLog() {
38 chrome.sync.events.addEventListener(
39 'onProtocolEvent', onReceivedProtocolEvent);
37 40
38 chrome.sync.events.addEventListener( 41 // Make the prototype jscontent element disappear.
39 'onAboutInfoUpdated', 42 jstProcess({}, $('traffic-event-container'));
40 onAboutInfoUpdatedEvent); 43 }
41 chrome.sync.requestUpdatedAboutInfo();
42 44
43 var dumpStatusButton = $('dump-status'); 45 /**
44 dumpStatusButton.addEventListener('click', function(event) { 46 * Toggles the given traffic event entry div's "expanded" state.
45 var aboutInfo = chrome.sync.aboutInfo; 47 * @param {HTMLElement} element the element to toggle.
46 if (!$('include-ids').checked) { 48 */
47 aboutInfo.details = chrome.sync.aboutInfo.details.filter(function(el) { 49 function expandListener(element) {
48 return !el.is_sensitive; 50 element.target.classList.toggle('traffic-event-entry-expanded');
49 }); 51 }
50 }
51 var data = '';
52 data += new Date().toString() + '\n';
53 data += '======\n';
54 data += 'Status\n';
55 data += '======\n';
56 data += JSON.stringify(aboutInfo, null, 2) + '\n';
57 52
58 $('status-text').value = data; 53 /**
59 $('status-data').hidden = false; 54 * Attaches a listener to the given traffic event entry div.
60 }); 55 * @param {HTMLElement} element the element to attach the listener to.
56 */
57 function addExpandListener(element) {
58 element.addEventListener('click', expandListener, false);
59 }
61 60
62 var importStatusButton = $('import-status'); 61 function onLoad() {
63 importStatusButton.addEventListener('click', function(event) { 62 $('status-data').hidden = true;
64 $('status-data').hidden = false;
65 if ($('status-text').value.length == 0) {
66 $('status-text').value = 'Paste sync status dump here then click import.';
67 return;
68 }
69 63
70 // First remove any characters before the '{'. 64 chrome.sync.events.addEventListener(
71 var data = $('status-text').value;
72 var firstBrace = data.indexOf('{');
73 if (firstBrace < 0) {
74 $('status-text').value = 'Invalid sync status dump.';
75 return;
76 }
77 data = data.substr(firstBrace);
78
79 // Remove listeners to prevent sync events from overwriting imported data.
80 chrome.sync.events.removeEventListener(
81 'onAboutInfoUpdated', 65 'onAboutInfoUpdated',
82 onAboutInfoUpdatedEvent); 66 onAboutInfoUpdatedEvent);
67 chrome.sync.requestUpdatedAboutInfo();
83 68
84 var aboutInfo = JSON.parse(data); 69 var dumpStatusButton = $('dump-status');
85 refreshAboutInfo(aboutInfo); 70 dumpStatusButton.addEventListener('click', function(event) {
86 }); 71 var aboutInfo = chrome.sync.aboutInfo;
87 } 72 if (!$('include-ids').checked) {
73 aboutInfo.details = chrome.sync.aboutInfo.details.filter(function(el) {
74 return !el.is_sensitive;
75 });
76 }
77 var data = '';
78 data += new Date().toString() + '\n';
79 data += '======\n';
80 data += 'Status\n';
81 data += '======\n';
82 data += JSON.stringify(aboutInfo, null, 2) + '\n';
88 83
89 document.addEventListener('DOMContentLoaded', onLoad, false); 84 $('status-text').value = data;
90 })(); 85 $('status-data').hidden = false;
86 });
87
88 var importStatusButton = $('import-status');
89 importStatusButton.addEventListener('click', function(event) {
90 $('status-data').hidden = false;
91 if ($('status-text').value.length == 0) {
92 $('status-text').value =
93 'Paste sync status dump here then click import.';
94 return;
95 }
96
97 // First remove any characters before the '{'.
98 var data = $('status-text').value;
99 var firstBrace = data.indexOf('{');
100 if (firstBrace < 0) {
101 $('status-text').value = 'Invalid sync status dump.';
102 return;
103 }
104 data = data.substr(firstBrace);
105
106 // Remove listeners to prevent sync events from overwriting imported data.
107 chrome.sync.events.removeEventListener(
108 'onAboutInfoUpdated',
109 onAboutInfoUpdatedEvent);
110
111 var aboutInfo = JSON.parse(data);
112 refreshAboutInfo(aboutInfo);
113 });
114
115 initProtocolEventLog();
116 }
117
118 return {
119 onLoad: onLoad,
120 addExpandListener: addExpandListener
121 };
122 });
123
124 document.addEventListener(
125 'DOMContentLoaded', chrome.sync.about_tab.onLoad, false);
OLDNEW
« no previous file with comments | « chrome/browser/resources/sync_internals/about.html ('k') | chrome/browser/resources/sync_internals/sync_log.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698