OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/android/bookmarks/bookmarks_bridge.h" | 5 #include "chrome/browser/android/bookmarks/bookmarks_bridge.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "base/containers/stack_container.h" | 8 #include "base/containers/stack_container.h" |
9 #include "base/i18n/string_compare.h" | 9 #include "base/i18n/string_compare.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 const BookmarkNode* node = other_node->GetChild(i); | 272 const BookmarkNode* node = other_node->GetChild(i); |
273 if (!node->is_folder()) { | 273 if (!node->is_folder()) { |
274 Java_BookmarksBridge_addToBookmarkIdList(env, | 274 Java_BookmarksBridge_addToBookmarkIdList(env, |
275 j_result_obj, | 275 j_result_obj, |
276 node->id(), | 276 node->id(), |
277 GetBookmarkType(node)); | 277 GetBookmarkType(node)); |
278 } | 278 } |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 void BookmarksBridge::GetAllFoldersWithDepths(JNIEnv* env, | |
283 jobject obj, | |
284 jobject j_folders_obj, | |
285 jobject j_depths_obj) { | |
286 DCHECK(IsLoaded()); | |
287 | |
288 const BookmarkNode* desktop = bookmark_model_->bookmark_bar_node(); | |
289 const BookmarkNode* mobile = bookmark_model_->mobile_node(); | |
290 const BookmarkNode* other = bookmark_model_->other_node(); | |
291 | |
292 scoped_ptr<icu::Collator> collator = GetICUCollator(); | |
293 | |
294 // Vector to temporarily contain all child bookmarks at same level for sorting | |
295 std::vector<const BookmarkNode*> bookmarkList; | |
296 // Stack for Depth-First Search of bookmark model. It stores nodes and their | |
297 // heights. | |
298 std::stack<std::pair<const BookmarkNode*, int> > stk; | |
299 | |
300 for (int i = 0; i < mobile->child_count(); ++i) { | |
301 const BookmarkNode* child = mobile->GetChild(i); | |
302 if (child->is_folder() && client_->CanBeEditedByUser(child)) | |
303 bookmarkList.push_back(child); | |
304 } | |
305 for (int i = 0; i < other->child_count(); ++i) { | |
306 const BookmarkNode* child = other->GetChild(i); | |
307 if (child->is_folder() && client_->CanBeEditedByUser(child)) | |
308 bookmarkList.push_back(child); | |
309 } | |
310 bookmarkList.push_back(desktop); | |
311 std::stable_sort(bookmarkList.begin(), | |
312 bookmarkList.end(), | |
313 BookmarkTitleComparer(collator.get())); | |
314 | |
315 // Push all sorted top folders in stack and give them depth of 0. | |
316 // Note the order to push folders to stack should be opposite to the order in | |
317 // output. | |
318 for (std::vector<const BookmarkNode*>::reverse_iterator it = | |
Ian Wen
2014/09/05 22:35:21
const_reverse_iterator cannot be applied here as i
Kibeom Kim (inactive)
2014/09/08 09:41:09
fyi workaround:
std::vector<const BookmarkNode*
| |
319 bookmarkList.rbegin(); | |
320 it != bookmarkList.rend(); | |
321 ++it) { | |
322 stk.push(std::make_pair(*it, 0)); | |
323 } | |
324 | |
325 while (!stk.empty()) { | |
326 const BookmarkNode* node = stk.top().first; | |
327 int depth = stk.top().second; | |
328 stk.pop(); | |
329 Java_BookmarksBridge_addToBookmarkIdListWithDepth(env, | |
330 j_folders_obj, | |
331 node->id(), | |
332 GetBookmarkType(node), | |
333 j_depths_obj, | |
334 depth); | |
335 bookmarkList.clear(); | |
336 for (int i = 0; i < node->child_count(); ++i) { | |
337 const BookmarkNode* child = node->GetChild(i); | |
338 if (child->is_folder() && client_->CanBeEditedByUser(child)) | |
339 bookmarkList.push_back(node->GetChild(i)); | |
340 } | |
341 std::stable_sort(bookmarkList.begin(), | |
342 bookmarkList.end(), | |
343 BookmarkTitleComparer(collator.get())); | |
344 for (std::vector<const BookmarkNode*>::reverse_iterator it = | |
345 bookmarkList.rbegin(); | |
346 it != bookmarkList.rend(); | |
347 ++it) { | |
348 stk.push(std::make_pair(*it, depth + 1)); | |
349 } | |
350 } | |
351 } | |
352 | |
353 ScopedJavaLocalRef<jobject> BookmarksBridge::GetMobileFolderId(JNIEnv* env, | |
354 jobject obj) { | |
355 const BookmarkNode* mobileNode = bookmark_model_->mobile_node(); | |
356 ScopedJavaLocalRef<jobject> folder_id_obj = | |
357 Java_BookmarksBridge_createBookmarkId( | |
358 env, mobileNode->id(), GetBookmarkType(mobileNode)); | |
359 return folder_id_obj; | |
360 } | |
361 | |
282 void BookmarksBridge::GetChildIDs(JNIEnv* env, | 362 void BookmarksBridge::GetChildIDs(JNIEnv* env, |
283 jobject obj, | 363 jobject obj, |
284 jlong id, | 364 jlong id, |
285 jint type, | 365 jint type, |
286 jboolean get_folders, | 366 jboolean get_folders, |
287 jboolean get_bookmarks, | 367 jboolean get_bookmarks, |
288 jobject j_result_obj) { | 368 jobject j_result_obj) { |
289 DCHECK(IsLoaded()); | 369 DCHECK(IsLoaded()); |
290 | 370 |
291 const BookmarkNode* parent = GetNodeByID(id, type); | 371 const BookmarkNode* parent = GetNodeByID(id, type); |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 BookmarkModelChanged(); | 867 BookmarkModelChanged(); |
788 } | 868 } |
789 | 869 |
790 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { | 870 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { |
791 NotifyIfDoneLoading(); | 871 NotifyIfDoneLoading(); |
792 } | 872 } |
793 | 873 |
794 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { | 874 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { |
795 partner_bookmarks_shim_ = NULL; | 875 partner_bookmarks_shim_ = NULL; |
796 } | 876 } |
OLD | NEW |