Commit a01c664c authored by kkimlabs's avatar kkimlabs Committed by Commit bot

[Android] Change enhanced bookmark folder structure.

- 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}
parent fc420e93
......@@ -225,7 +225,7 @@ public class BookmarksBridge {
}
/**
* @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;
......@@ -238,9 +238,7 @@ public class BookmarksBridge {
* @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;
......@@ -249,17 +247,6 @@ public class BookmarksBridge {
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
......@@ -702,8 +689,6 @@ public class BookmarksBridge {
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);
......
......@@ -103,14 +103,16 @@ public class BookmarksBridgeTest extends ChromeShellTestBase {
// 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>();
......@@ -141,44 +143,54 @@ public class BookmarksBridgeTest extends ChromeShellTestBase {
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);
}
......
......@@ -210,12 +210,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,
......@@ -241,8 +235,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);
......@@ -251,6 +243,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);
......@@ -274,64 +275,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
......
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment