Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / resources / sync_internals / sync_log.js
blob296a04a7a4f0382cdd219ac83f5d6595e8515416
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.
5 // require: cr.js
6 // require: cr/event_target.js
8 /**
9 * @fileoverview This creates a log object which listens to and
10 * records all sync events.
13 cr.define('chrome.sync', function() {
14 'use strict';
16 var eventsByCategory = {
17 notifier: [
18 'onIncomingNotification',
19 'onNotificationStateChange',
22 manager: [
23 'onActionableError',
24 'onChangesApplied',
25 'onChangesComplete',
26 'onClearServerDataFailed',
27 'onClearServerDataSucceeded',
28 'onConnectionStatusChange',
29 'onEncryptedTypesChanged',
30 'onEncryptionComplete',
31 'onInitializationComplete',
32 'onPassphraseAccepted',
33 'onPassphraseRequired',
34 'onStopSyncingPermanently',
35 'onSyncCycleCompleted',
38 transaction: [
39 'onTransactionWrite',
42 protocol: [
43 'onProtocolEvent',
47 /**
48 * Creates a new log object which then immediately starts recording
49 * sync events. Recorded entries are available in the 'entries'
50 * property and there is an 'append' event which can be listened to.
51 * @constructor
52 * @extends {cr.EventTarget}
54 var Log = function() {
55 var self = this;
57 /**
58 * Creates a callback function to be invoked when an event arrives.
60 var makeCallback = function(categoryName, eventName) {
61 return function(e) {
62 self.log_(categoryName, eventName, e.details);
66 for (var categoryName in eventsByCategory) {
67 for (var i = 0; i < eventsByCategory[categoryName].length; ++i) {
68 var eventName = eventsByCategory[categoryName][i];
69 chrome.sync.events.addEventListener(
70 eventName,
71 makeCallback(categoryName, eventName));
76 Log.prototype = {
77 __proto__: cr.EventTarget.prototype,
79 /**
80 * The recorded log entries.
81 * @type {array}
83 entries: [],
85 /**
86 * Records a single event with the given parameters and fires the
87 * 'append' event with the newly-created event as the 'detail'
88 * field of a custom event.
89 * @param {string} submodule The sync submodule for the event.
90 * @param {string} event The name of the event.
91 * @param {dictionary} details A dictionary of event-specific details.
93 log_: function(submodule, event, details) {
94 var entry = {
95 submodule: submodule,
96 event: event,
97 date: new Date(),
98 details: details,
99 textDetails: ''
101 entry.textDetails = JSON.stringify(entry.details, null, 2);
102 this.entries.push(entry);
103 // Fire append event.
104 var e = cr.doc.createEvent('CustomEvent');
105 e.initCustomEvent('append', false, false, entry);
106 this.dispatchEvent(e);
110 return {
111 log: new Log()