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

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

Issue 7049028: [Sync] Speed up Javascript node operations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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/ui.js 6 // require: cr/ui.js
7 // require: cr/ui/tree.js 7 // require: cr/ui/tree.js
8 8
9 cr.define('chrome.sync', function() { 9 cr.define('chrome.sync', function() {
10 // Allow platform specific CSS rules. 10 // Allow platform specific CSS rules.
11 // 11 //
12 // TODO(akalin): BMM and options page does something similar, too. 12 // TODO(akalin): BMM and options page does something similar, too.
13 // Move this to util.js. 13 // Move this to util.js.
14 if (cr.isWindows) 14 if (cr.isWindows)
15 document.documentElement.setAttribute('os', 'win'); 15 document.documentElement.setAttribute('os', 'win');
16 16
17 // TODO(akalin): Create SyncNodeTree/SyncNodeTreeItem classes that 17 // TODO(akalin): Create SyncNodeTree/SyncNodeTreeItem classes that
18 // hide all these details. 18 // hide all these details.
19 19
20 /** 20 /**
21 * Returns an object which measures elapsed time.
22 */
23 var makeTimer = function() {
24 var start = new Date();
25
26 return {
27 /**
28 * @return {number} The number of seconds since the timer was
29 * created.
30 */
31 get elapsedSeconds() {
32 return ((new Date()).getTime() - start.getTime()) / 1000.0;
33 }
34 };
35 };
36
37 /**
21 * Gets all children of the given node and passes it to the given 38 * Gets all children of the given node and passes it to the given
22 * callback. 39 * callback.
23 * @param {Object} nodeInfo The info for the node whose children we 40 * @param {Object} nodeInfo The info for the node whose children we
24 * want. 41 * want.
25 * @param {Function} callback The callback to call with the list of 42 * @param {Function} callback The callback to call with the list of
26 * children. 43 * children.
27 */ 44 */
28 function getSyncNodeChildren(nodeInfo, callback) { 45 function getSyncNodeChildren(nodeInfo, callback) {
29 var children = []; 46 var timer = makeTimer();
30 function processChildInfo(childNodeInfo) { 47 chrome.sync.getChildNodeIds(nodeInfo.id, function(childNodeIds) {
31 if (!childNodeInfo) { 48 console.debug('getChildNodeIds took ' +
49 timer.elapsedSeconds + 's to retrieve ' +
50 childNodeIds.length + ' ids');
51 timer = makeTimer();
52 chrome.sync.getNodesById(childNodeIds, function(children) {
53 console.debug('getNodesById took ' +
54 timer.elapsedSeconds + 's to retrieve ' +
55 children.length + ' nodes');
32 callback(children); 56 callback(children);
33 return; 57 });
34 } 58 });
35 children.push(childNodeInfo);
36 chrome.sync.getNodeById(childNodeInfo.successorId, processChildInfo);
37 };
38 chrome.sync.getNodeById(nodeInfo.firstChildId, processChildInfo);
39 } 59 }
40 60
41 /** 61 /**
42 * Makes a tree item from the given node info. 62 * Makes a tree item from the given node info.
43 * @param {dictionary} nodeInfo The node info to create the tree 63 * @param {dictionary} nodeInfo The node info to create the tree
44 * item from. 64 * item from.
45 * @return {cr.ui.TreeItem} The created tree item. 65 * @return {cr.ui.TreeItem} The created tree item.
46 */ 66 */
47 function makeNodeTreeItem(nodeInfo) { 67 function makeNodeTreeItem(nodeInfo) {
48 var treeItem = new cr.ui.TreeItem({ 68 var treeItem = new cr.ui.TreeItem({
49 label: nodeInfo.title, 69 label: nodeInfo.title,
50 detail: nodeInfo 70 detail: nodeInfo
51 }); 71 });
52 72
53 if (nodeInfo.isFolder) { 73 if (nodeInfo.isFolder) {
54 treeItem.mayHaveChildren_ = true; 74 treeItem.mayHaveChildren_ = true;
55 75
56 // Load children asynchronously on expand. 76 // Load children asynchronously on expand.
57 // TODO(akalin): Add a throbber while loading? 77 // TODO(akalin): Add a throbber while loading?
58 treeItem.triggeredLoad_ = false; 78 treeItem.triggeredLoad_ = false;
59 treeItem.addEventListener('expand', function(event) { 79 treeItem.addEventListener('expand', function(event) {
60 if (!treeItem.triggeredLoad_) { 80 if (!treeItem.triggeredLoad_) {
61 getSyncNodeChildren(nodeInfo, function(children) { 81 getSyncNodeChildren(nodeInfo, function(children) {
82 var timer = makeTimer();
62 for (var i = 0; i < children.length; ++i) { 83 for (var i = 0; i < children.length; ++i) {
63 var childTreeItem = makeNodeTreeItem(children[i]); 84 var childTreeItem = makeNodeTreeItem(children[i]);
64 treeItem.add(childTreeItem); 85 treeItem.add(childTreeItem);
65 } 86 }
87 console.debug('adding ' + children.length + ' children took ' +
88 timer.elapsedSeconds + 's');
66 }); 89 });
67 treeItem.triggeredLoad_ = true; 90 treeItem.triggeredLoad_ = true;
68 } 91 }
69 }); 92 });
70 } else { 93 } else {
71 treeItem.classList.add('leaf'); 94 treeItem.classList.add('leaf');
72 } 95 }
73 return treeItem; 96 return treeItem;
74 } 97 }
75 98
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 for (var i = 0; i < pendingSyncNodeBrowsers.length; ++i) { 145 for (var i = 0; i < pendingSyncNodeBrowsers.length; ++i) {
123 decorateSyncNodeBrowser(pendingSyncNodeBrowsers[i]); 146 decorateSyncNodeBrowser(pendingSyncNodeBrowsers[i]);
124 } 147 }
125 domLoaded = true; 148 domLoaded = true;
126 }); 149 });
127 150
128 return { 151 return {
129 decorateSyncNodeBrowser: decorateSyncNodeBrowserAfterDOMLoad 152 decorateSyncNodeBrowser: decorateSyncNodeBrowserAfterDOMLoad
130 }; 153 };
131 }); 154 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/sync_internals/chrome_sync.js ('k') | chrome/browser/sync/engine/syncapi.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698