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 /** | 6 /** |
7 * Whether a node contains another node. | 7 * Whether a node contains another node. |
8 * TODO(yosin): Once JavaScript style guide is updated and linter follows | 8 * TODO(yosin): Once JavaScript style guide is updated and linter follows |
9 * that, we'll remove useless documentations for |parent| and |descendant|. | 9 * that, we'll remove useless documentations for |parent| and |descendant|. |
10 * TODO(yosin): bmm.contains() should be method of BookmarkTreeNode. | 10 * TODO(yosin): bmm.contains() should be method of BookmarkTreeNode. |
(...skipping 18 matching lines...) Expand all Loading... |
29 function isFolder(node) { | 29 function isFolder(node) { |
30 return !('url' in node); | 30 return !('url' in node); |
31 } | 31 } |
32 | 32 |
33 var loadingPromises = {}; | 33 var loadingPromises = {}; |
34 | 34 |
35 /** | 35 /** |
36 * Promise version of chrome.bookmarkManagerPrivate.getSubtree. | 36 * Promise version of chrome.bookmarkManagerPrivate.getSubtree. |
37 * @param {string} id . | 37 * @param {string} id . |
38 * @param {boolean} foldersOnly . | 38 * @param {boolean} foldersOnly . |
39 * @return {!Promise.<!Array.<!BookmarkTreeNode>>} . | 39 * @return {!Promise<!Array<!BookmarkTreeNode>>} . |
40 */ | 40 */ |
41 function getSubtreePromise(id, foldersOnly) { | 41 function getSubtreePromise(id, foldersOnly) { |
42 return new Promise(function(resolve) { | 42 return new Promise(function(resolve) { |
43 chrome.bookmarkManagerPrivate.getSubtree(id, foldersOnly, resolve); | 43 chrome.bookmarkManagerPrivate.getSubtree(id, foldersOnly, resolve); |
44 }); | 44 }); |
45 } | 45 } |
46 | 46 |
47 /** | 47 /** |
48 * Loads a subtree of the bookmark tree and returns a {@code Promise} that | 48 * Loads a subtree of the bookmark tree and returns a {@code Promise} that |
49 * will be fulfilled when done. This reuses multiple loads so that we do not | 49 * will be fulfilled when done. This reuses multiple loads so that we do not |
50 * load the same subtree more than once at the same time. | 50 * load the same subtree more than once at the same time. |
51 * @return {!Promise.<!BookmarkTreeNode>} The future promise for the load. | 51 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load. |
52 */ | 52 */ |
53 function loadSubtree(id) { | 53 function loadSubtree(id) { |
54 if (!loadingPromises[id]) { | 54 if (!loadingPromises[id]) { |
55 loadingPromises[id] = getSubtreePromise(id, false).then(function(nodes) { | 55 loadingPromises[id] = getSubtreePromise(id, false).then(function(nodes) { |
56 delete loadingPromises[id]; | 56 delete loadingPromises[id]; |
57 return nodes && nodes[0]; | 57 return nodes && nodes[0]; |
58 }); | 58 }); |
59 } | 59 } |
60 return loadingPromises[id]; | 60 return loadingPromises[id]; |
61 } | 61 } |
62 | 62 |
63 /** | 63 /** |
64 * Loads the entire bookmark tree and returns a {@code Promise} that will | 64 * Loads the entire bookmark tree and returns a {@code Promise} that will |
65 * be fulfilled when done. This reuses multiple loads so that we do not load | 65 * be fulfilled when done. This reuses multiple loads so that we do not load |
66 * the same tree more than once at the same time. | 66 * the same tree more than once at the same time. |
67 * @return {!Promise.<!BookmarkTreeNode>} The future promise for the load. | 67 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load. |
68 */ | 68 */ |
69 function loadTree() { | 69 function loadTree() { |
70 return loadSubtree(''); | 70 return loadSubtree(''); |
71 } | 71 } |
72 | 72 |
73 var bookmarkCache = { | 73 var bookmarkCache = { |
74 /** | 74 /** |
75 * Removes the cached item from both the list and tree lookups. | 75 * Removes the cached item from both the list and tree lookups. |
76 */ | 76 */ |
77 remove: function(id) { | 77 remove: function(id) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 }; | 240 }; |
241 | 241 |
242 return { | 242 return { |
243 contains: contains, | 243 contains: contains, |
244 isFolder: isFolder, | 244 isFolder: isFolder, |
245 loadSubtree: loadSubtree, | 245 loadSubtree: loadSubtree, |
246 loadTree: loadTree, | 246 loadTree: loadTree, |
247 addBookmarkModelListeners: addBookmarkModelListeners | 247 addBookmarkModelListeners: addBookmarkModelListeners |
248 }; | 248 }; |
249 }); | 249 }); |
OLD | NEW |