Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[Android] Change enhanced bookmark folder structure.
Browse files Browse the repository at this point in the history
- Top level folders are now all the sub folders of
  Bookmark Bar, Mobile, and Others nodes.
- We no longer use Uncategorized.

BUG=453024

Review URL: https://codereview.chromium.org/869193008

Cr-Commit-Position: refs/heads/master@{#314013}
(cherry picked from commit a01c664)

TBR=newt@chromium.org

Review URL: https://codereview.chromium.org/894853002

Cr-Commit-Position: refs/branch-heads/2272@{#188}
Cr-Branched-From: 827a380-refs/heads/master@{#310958}
  • Loading branch information
kkimdev committed Feb 2, 2015
1 parent b6fb515 commit dc6f13b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public List<BookmarkId> getPermanentNodeIDs() {
}

/**
* @return The top level folder's parents, which are root node, mobile node, and other node.
* @return The top level folder's parents.
*/
public List<BookmarkId> getTopLevelFolderParentIDs() {
assert mIsNativeBookmarkModelLoaded;
Expand All @@ -238,9 +238,7 @@ public List<BookmarkId> getTopLevelFolderParentIDs() {
* @param getSpecial Whether special top folders should be returned.
* @param getNormal Whether normal top folders should be returned.
* @return The top level folders. Note that special folders come first and normal top folders
* will be in the alphabetical order. Special top folders are managed bookmark and
* partner bookmark. Normal top folders are desktop permanent folder, and the
* sub-folders of mobile permanent folder and others permanent folder.
* will be in the alphabetical order.
*/
public List<BookmarkId> getTopLevelFolderIDs(boolean getSpecial, boolean getNormal) {
assert mIsNativeBookmarkModelLoaded;
Expand All @@ -249,17 +247,6 @@ public List<BookmarkId> getTopLevelFolderIDs(boolean getSpecial, boolean getNorm
return result;
}

/**
* @return The uncategorized bookmark IDs. They are direct descendant bookmarks of mobile and
* other folders.
*/
public List<BookmarkId> getUncategorizedBookmarkIDs() {
assert mIsNativeBookmarkModelLoaded;
List<BookmarkId> result = new ArrayList<BookmarkId>();
nativeGetUncategorizedBookmarkIDs(mNativeBookmarksBridge, result);
return result;
}

/**
* Populates folderList with BookmarkIds of folders users can move bookmarks
* to and all folders have corresponding depth value in depthList. Folders
Expand Down Expand Up @@ -702,8 +689,6 @@ private native void nativeGetTopLevelFolderParentIDs(long nativeBookmarksBridge,
List<BookmarkId> bookmarksList);
private native void nativeGetTopLevelFolderIDs(long nativeBookmarksBridge, boolean getSpecial,
boolean getNormal, List<BookmarkId> bookmarksList);
private native void nativeGetUncategorizedBookmarkIDs(long nativeBookmarksBridge,
List<BookmarkId> bookmarksList);
private native void nativeGetAllFoldersWithDepths(long nativeBookmarksBridge,
List<BookmarkId> folderList, List<Integer> depthList);
private native BookmarkId nativeGetMobileFolderId(long nativeBookmarksBridge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ public void testGetAllFoldersWithDepths() {

// Map folders to depths as expected results
HashMap<BookmarkId, Integer> idToDepth = new HashMap<BookmarkId, Integer>();
idToDepth.put(folderA, 0);
idToDepth.put(folderAA, 1);
idToDepth.put(folderAAA, 2);
idToDepth.put(folderAAAA, 3);
idToDepth.put(mMobileNode, 0);
idToDepth.put(folderA, 1);
idToDepth.put(folderAA, 2);
idToDepth.put(folderAAA, 3);
idToDepth.put(folderAAAA, 4);
idToDepth.put(mDesktopNode, 0);
idToDepth.put(folderB, 1);
idToDepth.put(folderBA, 2);
idToDepth.put(folderC, 0);
idToDepth.put(mOtherNode, 0);
idToDepth.put(folderC, 1);

List<BookmarkId> folderList = new ArrayList<BookmarkId>();
List<Integer> depthList = new ArrayList<Integer>();
Expand Down Expand Up @@ -141,44 +143,54 @@ public void testGetMoveDestinations() {
List<Integer> depthList = new ArrayList<Integer>();

mBookmarksBridge.getMoveDestinations(folderList, depthList, Arrays.asList(folderA));
idToDepth.put(mMobileNode, 0);
idToDepth.put(mDesktopNode, 0);
idToDepth.put(folderB, 1);
idToDepth.put(folderBA, 2);
idToDepth.put(folderC, 0);
idToDepth.put(mOtherNode, 0);
idToDepth.put(folderC, 1);
verifyFolderDepths(folderList, depthList, idToDepth);

mBookmarksBridge.getMoveDestinations(folderList, depthList, Arrays.asList(folderB));
idToDepth.put(folderA, 0);
idToDepth.put(folderAA, 1);
idToDepth.put(folderAAA, 2);
idToDepth.put(mMobileNode, 0);
idToDepth.put(folderA, 1);
idToDepth.put(folderAA, 2);
idToDepth.put(folderAAA, 3);
idToDepth.put(mDesktopNode, 0);
idToDepth.put(folderC, 0);
idToDepth.put(mOtherNode, 0);
idToDepth.put(folderC, 1);
verifyFolderDepths(folderList, depthList, idToDepth);

mBookmarksBridge.getMoveDestinations(folderList, depthList, Arrays.asList(folderC));
idToDepth.put(folderA, 0);
idToDepth.put(folderAA, 1);
idToDepth.put(folderAAA, 2);
idToDepth.put(mMobileNode, 0);
idToDepth.put(folderA, 1);
idToDepth.put(folderAA, 2);
idToDepth.put(folderAAA, 3);
idToDepth.put(mDesktopNode, 0);
idToDepth.put(folderB, 1);
idToDepth.put(folderBA, 2);
idToDepth.put(mOtherNode, 0);
verifyFolderDepths(folderList, depthList, idToDepth);

mBookmarksBridge.getMoveDestinations(folderList, depthList, Arrays.asList(folderBA));
idToDepth.put(folderA, 0);
idToDepth.put(folderAA, 1);
idToDepth.put(folderAAA, 2);
idToDepth.put(mMobileNode, 0);
idToDepth.put(folderA, 1);
idToDepth.put(folderAA, 2);
idToDepth.put(folderAAA, 3);
idToDepth.put(mDesktopNode, 0);
idToDepth.put(folderB, 1);
idToDepth.put(folderC, 0);
idToDepth.put(mOtherNode, 0);
idToDepth.put(folderC, 1);
verifyFolderDepths(folderList, depthList, idToDepth);

mBookmarksBridge.getMoveDestinations(folderList, depthList,
Arrays.asList(folderAA, folderC));
idToDepth.put(folderA, 0);
idToDepth.put(mMobileNode, 0);
idToDepth.put(folderA, 1);
idToDepth.put(mDesktopNode, 0);
idToDepth.put(folderB, 1);
idToDepth.put(folderBA, 2);
idToDepth.put(mOtherNode, 0);
verifyFolderDepths(folderList, depthList, idToDepth);
}

Expand Down
65 changes: 13 additions & 52 deletions chrome/browser/android/bookmarks/bookmarks_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,6 @@ void BookmarksBridge::GetTopLevelFolderParentIDs(JNIEnv* env,
Java_BookmarksBridge_addToBookmarkIdList(
env, j_result_obj, bookmark_model_->root_node()->id(),
GetBookmarkType(bookmark_model_->root_node()));
Java_BookmarksBridge_addToBookmarkIdList(
env, j_result_obj, bookmark_model_->mobile_node()->id(),
GetBookmarkType(bookmark_model_->mobile_node()));
Java_BookmarksBridge_addToBookmarkIdList(
env, j_result_obj, bookmark_model_->other_node()->id(),
GetBookmarkType(bookmark_model_->other_node()));
}

void BookmarksBridge::GetTopLevelFolderIDs(JNIEnv* env,
Expand All @@ -240,8 +234,6 @@ void BookmarksBridge::GetTopLevelFolderIDs(JNIEnv* env,
if (get_normal) {
DCHECK_EQ(bookmark_model_->root_node()->child_count(), 4);

top_level_folders.push_back(bookmark_model_->bookmark_bar_node());

const BookmarkNode* mobile_node = bookmark_model_->mobile_node();
for (int i = 0; i < mobile_node->child_count(); ++i) {
const BookmarkNode* node = mobile_node->GetChild(i);
Expand All @@ -250,6 +242,15 @@ void BookmarksBridge::GetTopLevelFolderIDs(JNIEnv* env,
}
}

const BookmarkNode* bookmark_bar_node =
bookmark_model_->bookmark_bar_node();
for (int i = 0; i < bookmark_bar_node->child_count(); ++i) {
const BookmarkNode* node = bookmark_bar_node->GetChild(i);
if (node->is_folder()) {
top_level_folders.push_back(node);
}
}

const BookmarkNode* other_node = bookmark_model_->other_node();
for (int i = 0; i < other_node->child_count(); ++i) {
const BookmarkNode* node = other_node->GetChild(i);
Expand All @@ -273,64 +274,24 @@ void BookmarksBridge::GetTopLevelFolderIDs(JNIEnv* env,
}
}

void BookmarksBridge::GetUncategorizedBookmarkIDs(JNIEnv* env,
jobject obj,
jobject j_result_obj) {
const BookmarkNode* mobile_node = bookmark_model_->mobile_node();
for (int i = 0; i < mobile_node->child_count(); ++i) {
const BookmarkNode* node = mobile_node->GetChild(i);
if (!node->is_folder()) {
Java_BookmarksBridge_addToBookmarkIdList(env,
j_result_obj,
node->id(),
GetBookmarkType(node));
}
}

const BookmarkNode* other_node = bookmark_model_->other_node();
for (int i = 0; i < other_node->child_count(); ++i) {
const BookmarkNode* node = other_node->GetChild(i);
if (!node->is_folder()) {
Java_BookmarksBridge_addToBookmarkIdList(env,
j_result_obj,
node->id(),
GetBookmarkType(node));
}
}
}

void BookmarksBridge::GetAllFoldersWithDepths(JNIEnv* env,
jobject obj,
jobject j_folders_obj,
jobject j_depths_obj) {
DCHECK(IsLoaded());

const BookmarkNode* desktop = bookmark_model_->bookmark_bar_node();
const BookmarkNode* mobile = bookmark_model_->mobile_node();
const BookmarkNode* other = bookmark_model_->other_node();

scoped_ptr<icu::Collator> collator = GetICUCollator();

// Vector to temporarily contain all child bookmarks at same level for sorting
std::vector<const BookmarkNode*> bookmarkList;

// Stack for Depth-First Search of bookmark model. It stores nodes and their
// heights.
std::stack<std::pair<const BookmarkNode*, int> > stk;

for (int i = 0; i < mobile->child_count(); ++i) {
const BookmarkNode* child = mobile->GetChild(i);
if (child->is_folder() && client_->CanBeEditedByUser(child))
bookmarkList.push_back(child);
}
for (int i = 0; i < other->child_count(); ++i) {
const BookmarkNode* child = other->GetChild(i);
if (child->is_folder() && client_->CanBeEditedByUser(child))
bookmarkList.push_back(child);
}
bookmarkList.push_back(desktop);
std::stable_sort(bookmarkList.begin(),
bookmarkList.end(),
BookmarkTitleComparer(this, collator.get()));
bookmarkList.push_back(bookmark_model_->mobile_node());
bookmarkList.push_back(bookmark_model_->bookmark_bar_node());
bookmarkList.push_back(bookmark_model_->other_node());

// Push all sorted top folders in stack and give them depth of 0.
// Note the order to push folders to stack should be opposite to the order in
Expand Down
3 changes: 0 additions & 3 deletions chrome/browser/android/bookmarks/bookmarks_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class BookmarksBridge : public bookmarks::BaseBookmarkModelObserver,
jboolean get_normal,
jobject j_result_obj);

void GetUncategorizedBookmarkIDs(JNIEnv* env,
jobject obj,
jobject j_result_obj);
void GetAllFoldersWithDepths(JNIEnv* env,
jobject obj,
jobject j_folders_obj,
Expand Down

0 comments on commit dc6f13b

Please sign in to comment.