private BookmarkNode getBookmarkForPosition(int position) {
      if (mCurrentFolder == null) return null;

      // The position 0 is saved for an entry of the current folder used to go up.
      // This is not the case when the current node has no parent (it's the root node).
      return (mCurrentFolder.parent() == null)
          ? mCurrentFolder.children().get(position)
          : (position == 0 ? mCurrentFolder : mCurrentFolder.children().get(position - 1));
    }
 private static boolean isSameHierarchyDownwards(BookmarkNode n1, BookmarkNode n2) {
   if (n1 == null && n2 == null) return true;
   if (n1 == null || n2 == null) return false;
   if (!n1.equalContents(n2)) return false;
   for (int i = 0; i < n1.children().size(); ++i) {
     if (!isSameHierarchyDownwards(n1.children().get(i), n2.children().get(i))) return false;
   }
   return true;
 }
  private BookmarkNode addImagesRecursive(BookmarkNode node) {
    node.setFavicon(mGenerator.nextBoolean() ? getRandomImageBlob() : null);
    node.setThumbnail(mGenerator.nextBoolean() ? getRandomImageBlob() : null);

    for (BookmarkNode child : node.children()) {
      addImagesRecursive(child);
    }

    return node;
  }
  // Tests parceling and comparing each of the nodes in the provided hierarchy.
  private boolean internalTestNodeHierarchyParceling(BookmarkNode node) {
    if (node == null) return false;

    BookmarkNode parceled = parcelNode(node);
    if (!isSameHierarchy(node, parceled)) return false;

    for (BookmarkNode child : node.children()) {
      if (!internalTestNodeHierarchyParceling(child)) return false;
    }

    return true;
  }
    @Override
    public void onThumbnailUpdated(String url) {
      synchronized (mLock) {
        if (mCurrentFolder == null) return;

        for (BookmarkNode child : mCurrentFolder.children()) {
          if (child.isUrl() && url.equals(child.url())) {
            refreshWidget();
            break;
          }
        }
      }
    }
 @Override
 public int getCount() {
   if (mCurrentFolder == null) return 0;
   return mCurrentFolder.children().size() + (mCurrentFolder.parent() != null ? 1 : 0);
 }