1 // Copyright (c) 2011 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.
6 var dumpToTextButton = $('dump-to-text');
7 var dataDump = $('data-dump');
8 dumpToTextButton.addEventListener('click', function(event) {
9 // TODO(akalin): Add info like Chrome version, OS, date dumped, etc.
15 data += JSON.stringify(chrome.sync.aboutInfo, null, 2);
19 data += '=============\n';
20 data += 'Notifications\n';
21 data += '=============\n';
22 data += JSON.stringify(chrome.sync.notifications, null, 2);
29 data += JSON.stringify(chrome.sync.log.entries, null, 2);
32 dataDump.textContent = data;
38 'IS_UNAPPLIED_UPDATE',
42 'SERVER_VERSION_TIME',
52 function versionToDateString(version) {
53 // TODO(mmontgomery): ugly? Hacky? Is there a better way?
54 var epochLength = Date.now().toString().length;
55 var epochTime = parseInt(version.slice(0, epochLength));
56 var date = new Date(epochTime);
57 return date.toString();
60 function getFields(node) {
61 return allFields.map(function(field) {
63 if (field == 'SERVER_VERSION_TIME') {
64 var version = node['SERVER_VERSION'];
65 fieldVal = versionToDateString(version);
66 } if (field == 'BASE_VERSION_TIME') {
67 var version = node['BASE_VERSION'];
68 fieldVal = versionToDateString(version);
69 } else if ((field == 'SERVER_SPECIFICS' || field == 'SPECIFICS') &&
70 (!$('include-specifics').checked)) {
71 fieldVal = 'REDACTED';
72 } else if ((field == 'SERVER_SPECIFICS' || field == 'SPECIFICS') &&
73 $('include-specifics').checked) {
74 fieldVal = JSON.stringify(node[field]);
76 fieldVal = node[field];
82 function isSelectedDatatype(node) {
83 var type = node.serverModelType;
84 var typeCheckbox = $(type);
85 // Some types, such as 'Top level folder', appear in the list of nodes
86 // but not in the list of selectable items.
87 if (typeCheckbox == null) {
90 return typeCheckbox.checked;
93 function makeBlobUrl(data) {
94 var textBlob = new Blob([data], {type: 'octet/stream'});
95 var blobUrl = window.URL.createObjectURL(textBlob);
99 function makeDownloadName() {
100 // Format is sync-data-dump-$epoch-$year-$month-$day-$OS.csv.
101 var now = new Date();
102 var friendlyDate = [now.getFullYear(),
104 now.getDate()].join('-');
105 var name = ['sync-data-dump',
108 navigator.platform].join('-');
109 return [name, 'csv'].join('.');
112 function makeDateUserAgentHeader() {
113 var now = new Date();
114 var userAgent = window.navigator.userAgent;
115 var dateUaHeader = [now.toISOString(), userAgent].join(',');
119 function triggerDataDownload(data) {
120 // Prepend a header with ISO date and useragent.
121 var output = [makeDateUserAgentHeader()];
122 output.push('=====');
124 var aboutInfo = JSON.stringify(chrome.sync.aboutInfo, null, 2);
125 output.push(aboutInfo);
127 if (data != null && data.length > 0) {
128 output.push('=====');
129 var fieldLabels = allFields.join(',');
130 output.push(fieldLabels);
132 var data = data.filter(isSelectedDatatype);
133 data = data.map(getFields);
134 var dataAsString = data.join('\n');
135 output.push(dataAsString);
137 output = output.join('\n');
139 var anchor = $('dump-to-file-anchor');
140 anchor.href = makeBlobUrl(output);
141 anchor.download = makeDownloadName();
145 function createTypesCheckboxes(types) {
146 var containerElt = $('node-type-checkboxes');
148 types.map(function(type) {
149 var div = document.createElement('div');
151 var checkbox = document.createElement('input');
153 checkbox.type = 'checkbox';
154 checkbox.checked = 'yes';
155 div.appendChild(checkbox);
157 var label = document.createElement('label');
158 // Assigning to label.for doesn't work.
159 label.setAttribute('for', type);
160 label.innerText = type;
161 div.appendChild(label);
163 containerElt.appendChild(div);
167 document.addEventListener('DOMContentLoaded', function() {
168 chrome.sync.getListOfTypes(function(types) {
170 createTypesCheckboxes(types);
174 var dumpToFileLink = $('dump-to-file');
175 dumpToFileLink.addEventListener('click', function(event) {
176 chrome.sync.getAllNodes(triggerDataDownload);