| OLD | NEW | 
|    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 cr.define('chrome.sync.about_tab', function() { |    5 cr.define('chrome.sync.about_tab', function() { | 
|    6   // Contains the latest snapshot of sync about info. |    6   // Contains the latest snapshot of sync about info. | 
|    7   chrome.sync.aboutInfo = {}; |    7   chrome.sync.aboutInfo = {}; | 
|    8  |    8  | 
|    9   function refreshAboutInfo(aboutInfo) { |    9   function refreshAboutInfo(aboutInfo) { | 
|   10     chrome.sync.aboutInfo = aboutInfo; |   10     chrome.sync.aboutInfo = aboutInfo; | 
|   11     var aboutInfoDiv = $('about-info'); |   11     var aboutInfoDiv = $('about-info'); | 
|   12     jstProcess(new JsEvalContext(aboutInfo), aboutInfoDiv); |   12     jstProcess(new JsEvalContext(aboutInfo), aboutInfoDiv); | 
|   13   } |   13   } | 
|   14  |   14  | 
|   15   function onAboutInfoUpdatedEvent(e) { |   15   function onAboutInfoUpdatedEvent(e) { | 
|   16     refreshAboutInfo(e.details); |   16     refreshAboutInfo(e.details); | 
|   17   } |   17   } | 
|   18  |   18  | 
|   19   /** Container for accumulated sync protocol events. */ |   19   /** Container for accumulated sync protocol events. */ | 
|   20   var protocolEvents = []; |   20   var protocolEvents = []; | 
|   21  |   21  | 
 |   22   /** We may receive re-delivered events.  Keep a record of ones we've seen. */ | 
 |   23   var knownEventTimestamps = {}; | 
 |   24  | 
|   22   /** |   25   /** | 
|   23    * Callback for incoming protocol events. |   26    * Callback for incoming protocol events. | 
|   24    * @param {Event} e The protocol event. |   27    * @param {Event} e The protocol event. | 
|   25    */ |   28    */ | 
|   26   function onReceivedProtocolEvent(e) { |   29   function onReceivedProtocolEvent(e) { | 
|   27     var details = e.details; |   30     var details = e.details; | 
 |   31  | 
 |   32     // Return early if we've seen this event before.  Assumes that timestamps | 
 |   33     // are sufficiently high resolution to uniquely identify an event. | 
 |   34     if (knownEventTimestamps.hasOwnProperty(details.time)) { | 
 |   35       return; | 
 |   36     } | 
 |   37  | 
 |   38     knownEventTimestamps[details.time] = true; | 
|   28     protocolEvents.push(details); |   39     protocolEvents.push(details); | 
|   29  |   40  | 
|   30     var context = new JsEvalContext({ events: protocolEvents }); |   41     var context = new JsEvalContext({ events: protocolEvents }); | 
|   31     jstProcess(context, $('traffic-event-container')); |   42     jstProcess(context, $('traffic-event-container')); | 
|   32   } |   43   } | 
|   33  |   44  | 
|   34   /** |   45   /** | 
|   35    * Initializes state and callbacks for the protocol event log UI. |   46    * Initializes state and callbacks for the protocol event log UI. | 
|   36    */ |   47    */ | 
|   37   function initProtocolEventLog() { |   48   function initProtocolEventLog() { | 
|   38     chrome.sync.events.addEventListener( |   49     chrome.sync.events.addEventListener( | 
|   39         'onProtocolEvent', onReceivedProtocolEvent); |   50         'onProtocolEvent', onReceivedProtocolEvent); | 
|   40  |   51  | 
|   41     // Make the prototype jscontent element disappear. |   52     // Make the prototype jscontent element disappear. | 
|   42     jstProcess({}, $('traffic-event-container')); |   53     jstProcess({}, $('traffic-event-container')); | 
|   43   } |   54   } | 
|   44  |   55  | 
|   45   /** |   56   /** | 
|   46    * Toggles the given traffic event entry div's "expanded" state. |   57    * Initializes listeners for status dump and import UI. | 
|   47    * @param {HTMLElement} element the element to toggle. |  | 
|   48    */ |   58    */ | 
|   49   function expandListener(element) { |   59   function initStatusDumpButton() { | 
|   50     element.target.classList.toggle('traffic-event-entry-expanded'); |  | 
|   51   } |  | 
|   52  |  | 
|   53   /** |  | 
|   54    * Attaches a listener to the given traffic event entry div. |  | 
|   55    * @param {HTMLElement} element the element to attach the listener to. |  | 
|   56    */ |  | 
|   57   function addExpandListener(element) { |  | 
|   58     element.addEventListener('click', expandListener, false); |  | 
|   59   } |  | 
|   60  |  | 
|   61   function onLoad() { |  | 
|   62     $('status-data').hidden = true; |   60     $('status-data').hidden = true; | 
|   63  |   61  | 
|   64     chrome.sync.events.addEventListener( |  | 
|   65         'onAboutInfoUpdated', |  | 
|   66         onAboutInfoUpdatedEvent); |  | 
|   67     chrome.sync.requestUpdatedAboutInfo(); |  | 
|   68  |  | 
|   69     var dumpStatusButton = $('dump-status'); |   62     var dumpStatusButton = $('dump-status'); | 
|   70     dumpStatusButton.addEventListener('click', function(event) { |   63     dumpStatusButton.addEventListener('click', function(event) { | 
|   71       var aboutInfo = chrome.sync.aboutInfo; |   64       var aboutInfo = chrome.sync.aboutInfo; | 
|   72       if (!$('include-ids').checked) { |   65       if (!$('include-ids').checked) { | 
|   73         aboutInfo.details = chrome.sync.aboutInfo.details.filter(function(el) { |   66         aboutInfo.details = chrome.sync.aboutInfo.details.filter(function(el) { | 
|   74           return !el.is_sensitive; |   67           return !el.is_sensitive; | 
|   75         }); |   68         }); | 
|   76       } |   69       } | 
|   77       var data = ''; |   70       var data = ''; | 
|   78       data += new Date().toString() + '\n'; |   71       data += new Date().toString() + '\n'; | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  104       data = data.substr(firstBrace); |   97       data = data.substr(firstBrace); | 
|  105  |   98  | 
|  106       // Remove listeners to prevent sync events from overwriting imported data. |   99       // Remove listeners to prevent sync events from overwriting imported data. | 
|  107       chrome.sync.events.removeEventListener( |  100       chrome.sync.events.removeEventListener( | 
|  108           'onAboutInfoUpdated', |  101           'onAboutInfoUpdated', | 
|  109           onAboutInfoUpdatedEvent); |  102           onAboutInfoUpdatedEvent); | 
|  110  |  103  | 
|  111       var aboutInfo = JSON.parse(data); |  104       var aboutInfo = JSON.parse(data); | 
|  112       refreshAboutInfo(aboutInfo); |  105       refreshAboutInfo(aboutInfo); | 
|  113     }); |  106     }); | 
 |  107   } | 
|  114  |  108  | 
 |  109   /** | 
 |  110    * Toggles the given traffic event entry div's "expanded" state. | 
 |  111    * @param {HTMLElement} element the element to toggle. | 
 |  112    */ | 
 |  113   function expandListener(element) { | 
 |  114     element.target.classList.toggle('traffic-event-entry-expanded'); | 
 |  115   } | 
 |  116  | 
 |  117   /** | 
 |  118    * Attaches a listener to the given traffic event entry div. | 
 |  119    * @param {HTMLElement} element the element to attach the listener to. | 
 |  120    */ | 
 |  121   function addExpandListener(element) { | 
 |  122     element.addEventListener('click', expandListener, false); | 
 |  123   } | 
 |  124  | 
 |  125   function onLoad() { | 
 |  126     initStatusDumpButton(); | 
|  115     initProtocolEventLog(); |  127     initProtocolEventLog(); | 
 |  128  | 
 |  129     chrome.sync.events.addEventListener( | 
 |  130         'onAboutInfoUpdated', | 
 |  131         onAboutInfoUpdatedEvent); | 
 |  132  | 
 |  133     // Register to receive a stream of event notifications. | 
 |  134     chrome.sync.registerForEvents(); | 
 |  135  | 
 |  136     // Request an about info update event to initialize the page. | 
 |  137     chrome.sync.requestUpdatedAboutInfo(); | 
|  116   } |  138   } | 
|  117  |  139  | 
|  118   return { |  140   return { | 
|  119     onLoad: onLoad, |  141     onLoad: onLoad, | 
|  120     addExpandListener: addExpandListener |  142     addExpandListener: addExpandListener | 
|  121   }; |  143   }; | 
|  122 }); |  144 }); | 
|  123  |  145  | 
|  124 document.addEventListener( |  146 document.addEventListener( | 
|  125     'DOMContentLoaded', chrome.sync.about_tab.onLoad, false); |  147     'DOMContentLoaded', chrome.sync.about_tab.onLoad, false); | 
| OLD | NEW |