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

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

Issue 160083002: Refactor about:sync's events framework (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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) 2011 The Chromium Authors. All rights reserved. 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 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 // require: cr.js 5 // require: cr.js
6 // require: cr/event_target.js 6 // require: cr/event_target.js
7 7
8 /** 8 /**
9 * @fileoverview This creates a log object which listens to and 9 * @fileoverview This creates a log object which listens to and
10 * records all sync events. 10 * records all sync events.
11 */ 11 */
12 12
13 cr.define('chrome.sync', function() { 13 cr.define('chrome.sync', function() {
14 'use strict';
15
16 var eventsByCategory = {
17 notifier: [
18 'onNotificationStateChange',
19 'onIncomingNotification',
20 ],
21
22 manager: [
23 'onChangesApplied',
24 'onChangesComplete',
25 'onSyncCycleCompleted',
26 'onConnectionStatusChange',
27 'onPassphraseRequired',
28 'onPassphraseAccepted',
29 'onInitializationComplete',
30 'onStopSyncingPermanently',
31 'onClearServerDataSucceeded',
32 'onClearServerDataFailed',
33 'onEncryptedTypesChanged',
34 'onEncryptionComplete',
35 'onActionableError',
Dan Beam 2014/02/11 23:21:48 sort
rlarocque 2014/02/12 00:39:55 Done.
36 ],
37
38 transaction: [
39 'onTransactionWrite',
40 ]
Dan Beam 2014/02/11 23:21:48 nit: ],
rlarocque 2014/02/12 00:39:55 Done.
41 };
42
14 /** 43 /**
15 * Creates a new log object which then immediately starts recording 44 * Creates a new log object which then immediately starts recording
16 * sync events. Recorded entries are available in the 'entries' 45 * sync events. Recorded entries are available in the 'entries'
17 * property and there is an 'append' event which can be listened to. 46 * property and there is an 'append' event which can be listened to.
18 * @constructor 47 * @constructor
19 * @extends {cr.EventTarget} 48 * @extends {cr.EventTarget}
20 */ 49 */
21 var Log = function() { 50 var Log = function() {
22 var self = this; 51 var self = this;
23 52
24 var makeListener = function(service, event) { 53 /**
25 return function(details) { 54 * Creates a callback function to be invoked when an event arrives.
26 self.log_(service, event, details); 55 */
27 }; 56 var makeCallback = function(categoryName, eventName) {
28 }; 57 return function(e) {
29 58 self.log_(categoryName, eventName, e.details);
30 for (var eventType in chrome.sync.events) {
31 var events = chrome.sync.events[eventType];
32 for (var i = 0; i < events.length; ++i) {
33 var eventName = events[i];
34 var event = chrome.sync[eventName];
35 event.addListener(makeListener(eventType, eventName));
36 } 59 }
Dan Beam 2014/02/11 23:21:48 };
rlarocque 2014/02/12 00:39:55 Done.
37 } 60 }
38 }; 61
62 for (var categoryName in eventsByCategory) {
63 eventsByCategory[categoryName].forEach(function(eventName) {
Dan Beam 2014/02/11 23:21:48 nit: because this doesn't need to make a new scope
rlarocque 2014/02/12 00:39:55 Fixed.
64 chrome.sync.events.addEventListener(
65 eventName,
66 makeCallback(categoryName, eventName));
67 });
68 }
69 }
39 70
40 Log.prototype = { 71 Log.prototype = {
41 __proto__: cr.EventTarget.prototype, 72 __proto__: cr.EventTarget.prototype,
42 73
43 /** 74 /**
44 * The recorded log entries. 75 * The recorded log entries.
45 * @type {array} 76 * @type {array}
46 */ 77 */
47 entries: [], 78 entries: [],
48 79
(...skipping 19 matching lines...) Expand all
68 var e = cr.doc.createEvent('CustomEvent'); 99 var e = cr.doc.createEvent('CustomEvent');
69 e.initCustomEvent('append', false, false, entry); 100 e.initCustomEvent('append', false, false, entry);
70 this.dispatchEvent(e); 101 this.dispatchEvent(e);
71 } 102 }
72 }; 103 };
73 104
74 return { 105 return {
75 log: new Log() 106 log: new Log()
76 }; 107 };
77 }); 108 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698