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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 | 238 |
239 for (std::vector<const BookmarkNode*>::const_iterator it = | 239 for (std::vector<const BookmarkNode*>::const_iterator it = |
240 top_level_folders.begin(); it != top_level_folders.end(); ++it) { | 240 top_level_folders.begin(); it != top_level_folders.end(); ++it) { |
241 Java_BookmarksBridge_addToBookmarkIdList(env, | 241 Java_BookmarksBridge_addToBookmarkIdList(env, |
242 j_result_obj, | 242 j_result_obj, |
243 (*it)->id(), | 243 (*it)->id(), |
244 GetBookmarkType(*it)); | 244 GetBookmarkType(*it)); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 void BookmarksBridge::GetAllFoldersWithDepth(JNIEnv* env, | |
249 jobject obj, | |
250 jobject j_folder_obj, | |
251 jobject j_depth_obj) { | |
252 DCHECK(IsLoaded()); | |
253 | |
254 const BookmarkNode* desktop = bookmark_model_->bookmark_bar_node(); | |
255 const BookmarkNode* mobile = bookmark_model_->mobile_node(); | |
256 const BookmarkNode* other = bookmark_model_->other_node(); | |
257 | |
258 scoped_ptr<icu::Collator> collator = GetICUCollator(); | |
259 | |
260 std::vector<const BookmarkNode*> vct; | |
newt (away)
2014/09/04 21:49:55
Explain how these variables are used. This method
Ian Wen
2014/09/05 01:00:19
Done.
| |
261 std::stack<std::pair<const BookmarkNode*, int> > stk; | |
262 | |
263 for (int i = 0; i < mobile->child_count(); ++i) { | |
264 vct.push_back(mobile->GetChild(i)); | |
265 } | |
266 for (int i = 0; i < other->child_count(); ++i) { | |
267 vct.push_back(other->GetChild(i)); | |
268 } | |
269 vct.push_back(desktop); | |
270 std::sort(vct.begin(), vct.end(), BookmarkTitleComparer(collator.get())); | |
newt (away)
2014/09/04 21:49:55
I'd use stable_sort in case there are two folders
Ian Wen
2014/09/05 01:00:19
Done.
| |
271 | |
272 for (std::vector<const BookmarkNode*>::reverse_iterator it = vct.rbegin(); | |
newt (away)
2014/09/04 21:49:55
You can move lines 270-275 to the beginning of the
Ian Wen
2014/09/05 01:00:19
But this for loop is not completely the same as th
newt (away)
2014/09/05 02:10:20
Right. You'd need to initialize depth to -1, then
| |
273 it != vct.rend(); | |
274 ++it) { | |
275 stk.push(std::make_pair(*it, 0)); | |
276 } | |
277 | |
278 while (!stk.empty()) { | |
279 const BookmarkNode* node = stk.top().first; | |
280 int depth = stk.top().second; | |
281 stk.pop(); | |
282 if (!node->is_folder() || !client_->CanBeEditedByUser(node)) | |
283 continue; | |
284 Java_BookmarksBridge_addToBookmarkIdListWithDepth(env, | |
285 j_folder_obj, | |
286 node->id(), | |
287 GetBookmarkType(node), | |
288 j_depth_obj, | |
289 depth); | |
290 vct.clear(); | |
291 for (int i = 0; i < node->child_count(); ++i) { | |
292 vct.push_back(node->GetChild(i)); | |
293 } | |
294 std::sort(vct.begin(), vct.end(), BookmarkTitleComparer(collator.get())); | |
295 for (std::vector<const BookmarkNode*>::reverse_iterator it = vct.rbegin(); | |
296 it != vct.rend(); | |
297 ++it) { | |
298 stk.push(std::make_pair(*it, depth + 1)); | |
299 } | |
300 } | |
301 } | |
302 | |
303 ScopedJavaLocalRef<jobject> BookmarksBridge::GetMobileFolderId(JNIEnv* env, | |
304 jobject obj) { | |
305 const BookmarkNode* mobileNode = bookmark_model_->mobile_node(); | |
306 ScopedJavaLocalRef<jobject> folder_id_obj = | |
307 Java_BookmarksBridge_createBookmarkId( | |
308 env, mobileNode->id(), GetBookmarkType(mobileNode)); | |
309 return folder_id_obj; | |
310 } | |
311 | |
248 void BookmarksBridge::GetChildIDs(JNIEnv* env, | 312 void BookmarksBridge::GetChildIDs(JNIEnv* env, |
249 jobject obj, | 313 jobject obj, |
250 jlong id, | 314 jlong id, |
251 jint type, | 315 jint type, |
252 jboolean get_folders, | 316 jboolean get_folders, |
253 jboolean get_bookmarks, | 317 jboolean get_bookmarks, |
254 jobject j_result_obj) { | 318 jobject j_result_obj) { |
255 DCHECK(IsLoaded()); | 319 DCHECK(IsLoaded()); |
256 | 320 |
257 const BookmarkNode* parent = GetNodeByID(id, type); | 321 const BookmarkNode* parent = GetNodeByID(id, type); |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 BookmarkModelChanged(); | 817 BookmarkModelChanged(); |
754 } | 818 } |
755 | 819 |
756 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { | 820 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { |
757 NotifyIfDoneLoading(); | 821 NotifyIfDoneLoading(); |
758 } | 822 } |
759 | 823 |
760 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { | 824 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { |
761 partner_bookmarks_shim_ = NULL; | 825 partner_bookmarks_shim_ = NULL; |
762 } | 826 } |
OLD | NEW |