Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 var BookmarksStore = Polymer({ | 5 var BookmarksStore = Polymer({ |
| 6 is: 'bookmarks-store', | 6 is: 'bookmarks-store', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 /** @type {BookmarkTreeNode} */ | 9 /** @type {BookmarkTreeNode} */ |
| 10 rootNode: { | 10 rootNode: { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 * Initializes the store with data from the bookmarks API. | 72 * Initializes the store with data from the bookmarks API. |
| 73 * Called by app on attached. | 73 * Called by app on attached. |
| 74 */ | 74 */ |
| 75 initializeStore: function() { | 75 initializeStore: function() { |
| 76 chrome.bookmarks.getTree(function(results) { | 76 chrome.bookmarks.getTree(function(results) { |
| 77 this.setupStore_(results[0]); | 77 this.setupStore_(results[0]); |
| 78 }.bind(this)); | 78 }.bind(this)); |
| 79 // Attach bookmarks API listeners. | 79 // Attach bookmarks API listeners. |
| 80 chrome.bookmarks.onRemoved.addListener(this.onBookmarkRemoved_.bind(this)); | 80 chrome.bookmarks.onRemoved.addListener(this.onBookmarkRemoved_.bind(this)); |
| 81 chrome.bookmarks.onChanged.addListener(this.onBookmarkChanged_.bind(this)); | 81 chrome.bookmarks.onChanged.addListener(this.onBookmarkChanged_.bind(this)); |
| 82 chrome.bookmarks.onImportBegan.addListener(this.onImportBegan_.bind(this)); | |
| 83 chrome.bookmarks.onImportEnded.addListener(this.onImportEnded_.bind(this)); | |
| 82 }, | 84 }, |
| 83 | 85 |
| 84 ////////////////////////////////////////////////////////////////////////////// | 86 ////////////////////////////////////////////////////////////////////////////// |
| 85 // bookmarks-store, private: | 87 // bookmarks-store, private: |
| 86 | 88 |
| 87 /** | 89 /** |
| 88 * @param {BookmarkTreeNode} rootNode | 90 * @param {BookmarkTreeNode} rootNode |
| 89 * @private | 91 * @private |
| 90 */ | 92 */ |
| 91 setupStore_: function(rootNode) { | 93 setupStore_: function(rootNode) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 onBookmarkChanged_: function(id, changeInfo) { | 321 onBookmarkChanged_: function(id, changeInfo) { |
| 320 if (changeInfo.title) | 322 if (changeInfo.title) |
| 321 this.set(this.idToNodeMap_[id].path + '.title', changeInfo.title); | 323 this.set(this.idToNodeMap_[id].path + '.title', changeInfo.title); |
| 322 if (changeInfo.url) | 324 if (changeInfo.url) |
| 323 this.set(this.idToNodeMap_[id].path + '.url', changeInfo.url); | 325 this.set(this.idToNodeMap_[id].path + '.url', changeInfo.url); |
| 324 | 326 |
| 325 if (this.searchTerm) | 327 if (this.searchTerm) |
| 326 this.updateSearchDisplay_(); | 328 this.updateSearchDisplay_(); |
| 327 }, | 329 }, |
| 328 | 330 |
| 331 /** | |
| 332 * Called when importing bookmark is started. | |
| 333 */ | |
| 334 onImportBegan_: function() { | |
| 335 chrome.bookmarks.onRemoved.removeListener(this.onBookmarkRemoved_.bind(this) ); | |
|
tsergeant
2017/02/24 00:03:18
The docs for importBegan say:
"Expensive observer
rongjie
2017/02/24 00:20:46
Done.
| |
| 336 chrome.bookmarks.onChanged.removeListener(this.onBookmarkChanged_.bind(this) ); | |
| 337 }, | |
| 338 | |
| 339 /** | |
| 340 * Called when importing bookmark node is finished. | |
| 341 */ | |
| 342 onImportEnded_: function() { | |
| 343 chrome.bookmarks.getTree(function(results) { | |
| 344 this.setupStore_(results[0]); | |
|
tsergeant
2017/02/24 00:03:18
I think you need to call
this.updateSelectedDispl
rongjie
2017/02/24 00:20:46
Done.
| |
| 345 }.bind(this)); | |
| 346 | |
| 347 chrome.bookmarks.onRemoved.addListener(this.onBookmarkRemoved_.bind(this)); | |
| 348 chrome.bookmarks.onChanged.addListener(this.onBookmarkChanged_.bind(this)); | |
| 349 }, | |
| 350 | |
| 329 ////////////////////////////////////////////////////////////////////////////// | 351 ////////////////////////////////////////////////////////////////////////////// |
| 330 // bookmarks-store, bookmarks app event listeners: | 352 // bookmarks-store, bookmarks app event listeners: |
| 331 | 353 |
| 332 /** | 354 /** |
| 333 * @param {Event} e | 355 * @param {Event} e |
| 334 * @private | 356 * @private |
| 335 */ | 357 */ |
| 336 onSearchTermChanged_: function(e) { | 358 onSearchTermChanged_: function(e) { |
| 337 this.searchTerm = /** @type {string} */ (e.detail); | 359 this.searchTerm = /** @type {string} */ (e.detail); |
| 338 }, | 360 }, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 idToNodeMap[bookmarkNode.id] = bookmarkNode; | 459 idToNodeMap[bookmarkNode.id] = bookmarkNode; |
| 438 | 460 |
| 439 if (bookmarkNode.url) | 461 if (bookmarkNode.url) |
| 440 return; | 462 return; |
| 441 | 463 |
| 442 bookmarkNode.isSelectedFolder = false; | 464 bookmarkNode.isSelectedFolder = false; |
| 443 bookmarkNode.isOpen = true; | 465 bookmarkNode.isOpen = true; |
| 444 for (var i = 0; i < bookmarkNode.children.length; i++) | 466 for (var i = 0; i < bookmarkNode.children.length; i++) |
| 445 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap); | 467 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap); |
| 446 }; | 468 }; |
| OLD | NEW |