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('bmm', function() { | 5 cr.define('bmm', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Whether a node contains another node. | 9 * Whether a node contains another node. |
10 * TODO(yosin): Once JavaScript style guide is updated and linter follows | 10 * TODO(yosin): Once JavaScript style guide is updated and linter follows |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 /** | 55 /** |
56 * Loads a subtree of the bookmark tree and returns a {@code Promise} that | 56 * Loads a subtree of the bookmark tree and returns a {@code Promise} that |
57 * will be fulfilled when done. This reuses multiple loads so that we do not | 57 * will be fulfilled when done. This reuses multiple loads so that we do not |
58 * load the same subtree more than once at the same time. | 58 * load the same subtree more than once at the same time. |
59 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load. | 59 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load. |
60 */ | 60 */ |
61 function loadSubtree(id) { | 61 function loadSubtree(id) { |
62 if (!loadingPromises[id]) { | 62 if (!loadingPromises[id]) { |
63 loadingPromises[id] = getSubtreePromise(id, false).then(function(nodes) { | 63 loadingPromises[id] = getSubtreePromise(id, false).then( |
64 return nodes && nodes[0]; | 64 function(nodes) { |
65 }, function(error) { | 65 return nodes && nodes[0]; |
66 console.error(error.message); | 66 }, |
67 }); | 67 function(error) { |
| 68 console.error(error.message); |
| 69 }); |
68 loadingPromises[id].then(function() { | 70 loadingPromises[id].then(function() { |
69 delete loadingPromises[id]; | 71 delete loadingPromises[id]; |
70 }); | 72 }); |
71 } | 73 } |
72 return loadingPromises[id]; | 74 return loadingPromises[id]; |
73 } | 75 } |
74 | 76 |
75 /** | 77 /** |
76 * Loads the entire bookmark tree and returns a {@code Promise} that will | 78 * Loads the entire bookmark tree and returns a {@code Promise} that will |
77 * be fulfilled when done. This reuses multiple loads so that we do not load | 79 * be fulfilled when done. This reuses multiple loads so that we do not load |
78 * the same tree more than once at the same time. | 80 * the same tree more than once at the same time. |
79 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load. | 81 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load. |
80 */ | 82 */ |
81 function loadTree() { | 83 function loadTree() { |
82 return loadSubtree(''); | 84 return loadSubtree(''); |
83 } | 85 } |
84 | 86 |
85 var bookmarkCache = { | 87 var bookmarkCache = { |
86 /** | 88 /** |
87 * Removes the cached item from both the list and tree lookups. | 89 * Removes the cached item from both the list and tree lookups. |
88 */ | 90 */ |
89 remove: function(id) { | 91 remove: function(id) { |
90 var treeItem = bmm.treeLookup[id]; | 92 var treeItem = bmm.treeLookup[id]; |
91 if (treeItem) { | 93 if (treeItem) { |
92 var items = treeItem.items; // is an HTMLCollection | 94 var items = treeItem.items; // is an HTMLCollection |
93 for (var i = 0; i < items.length; ++i) { | 95 for (var i = 0; i < items.length; ++i) { |
94 var item = items[i]; | 96 var item = items[i]; |
95 var bookmarkNode = item.bookmarkNode; | 97 var bookmarkNode = item.bookmarkNode; |
96 delete bmm.treeLookup[bookmarkNode.id]; | 98 delete bmm.treeLookup[bookmarkNode.id]; |
97 } | 99 } |
98 delete bmm.treeLookup[id]; | 100 delete bmm.treeLookup[id]; |
99 } | 101 } |
100 }, | 102 }, |
101 | 103 |
102 /** | 104 /** |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 254 } |
253 | 255 |
254 return { | 256 return { |
255 contains: contains, | 257 contains: contains, |
256 isFolder: isFolder, | 258 isFolder: isFolder, |
257 loadSubtree: loadSubtree, | 259 loadSubtree: loadSubtree, |
258 loadTree: loadTree, | 260 loadTree: loadTree, |
259 addBookmarkModelListeners: addBookmarkModelListeners | 261 addBookmarkModelListeners: addBookmarkModelListeners |
260 }; | 262 }; |
261 }); | 263 }); |
OLD | NEW |