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

Side by Side Diff: chrome/browser/resources/bookmark_manager/js/bmm.js

Issue 1059413005: Checking node object before checking its property. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 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
« no previous file with comments | « no previous file | chrome/browser/resources/bookmark_manager/js/main.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'use strict'; 5 'use strict';
6 6
7 cr.define('bmm', function() { 7 cr.define('bmm', function() {
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 23 matching lines...) Expand all
34 34
35 var loadingPromises = {}; 35 var loadingPromises = {};
36 36
37 /** 37 /**
38 * Promise version of chrome.bookmarkManagerPrivate.getSubtree. 38 * Promise version of chrome.bookmarkManagerPrivate.getSubtree.
39 * @param {string} id . 39 * @param {string} id .
40 * @param {boolean} foldersOnly . 40 * @param {boolean} foldersOnly .
41 * @return {!Promise<!Array<!BookmarkTreeNode>>} . 41 * @return {!Promise<!Array<!BookmarkTreeNode>>} .
42 */ 42 */
43 function getSubtreePromise(id, foldersOnly) { 43 function getSubtreePromise(id, foldersOnly) {
44 return new Promise(function(resolve) { 44 return new Promise(function(resolve, reject) {
45 chrome.bookmarkManagerPrivate.getSubtree(id, foldersOnly, resolve); 45 chrome.bookmarkManagerPrivate.getSubtree(id, foldersOnly, function(node) {
46 if (chrome.runtime.lastError) {
47 reject(new Error(chrome.runtime.lastError.message));
48 return;
49 }
50 resolve(node);
51 });
46 }); 52 });
47 } 53 }
48 54
49 /** 55 /**
50 * 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
51 * 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
52 * load the same subtree more than once at the same time. 58 * load the same subtree more than once at the same time.
53 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load. 59 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load.
54 */ 60 */
55 function loadSubtree(id) { 61 function loadSubtree(id) {
56 if (!loadingPromises[id]) { 62 if (!loadingPromises[id]) {
57 loadingPromises[id] = getSubtreePromise(id, false).then(function(nodes) { 63 loadingPromises[id] = getSubtreePromise(id, false).then(function(nodes) {
64 return nodes && nodes[0];
65 }, function(error) {
66 console.error(error.message);
67 });
68 loadingPromises[id].then(function() {
58 delete loadingPromises[id]; 69 delete loadingPromises[id];
59 return nodes && nodes[0];
60 }); 70 });
61 } 71 }
62 return loadingPromises[id]; 72 return loadingPromises[id];
63 } 73 }
64 74
65 /** 75 /**
66 * Loads the entire bookmark tree and returns a {@code Promise} that will 76 * Loads the entire bookmark tree and returns a {@code Promise} that will
67 * be fulfilled when done. This reuses multiple loads so that we do not load 77 * be fulfilled when done. This reuses multiple loads so that we do not load
68 * the same tree more than once at the same time. 78 * the same tree more than once at the same time.
69 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load. 79 * @return {!Promise<!BookmarkTreeNode>} The future promise for the load.
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 }; 252 };
243 253
244 return { 254 return {
245 contains: contains, 255 contains: contains,
246 isFolder: isFolder, 256 isFolder: isFolder,
247 loadSubtree: loadSubtree, 257 loadSubtree: loadSubtree,
248 loadTree: loadTree, 258 loadTree: loadTree,
249 addBookmarkModelListeners: addBookmarkModelListeners 259 addBookmarkModelListeners: addBookmarkModelListeners
250 }; 260 };
251 }); 261 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/bookmark_manager/js/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698