Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.mm

Issue 2662473003: Removing "All Bookmarks" (Closed)
Patch Set: feedback Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 #pragma mark - Cache position in collection view. 619 #pragma mark - Cache position in collection view.
620 620
621 void CachePosition(CGFloat position, BookmarkMenuItem* item) { 621 void CachePosition(CGFloat position, BookmarkMenuItem* item) {
622 BookmarkPositionCache* cache = nil; 622 BookmarkPositionCache* cache = nil;
623 switch (item.type) { 623 switch (item.type) {
624 case bookmarks::MenuItemFolder: 624 case bookmarks::MenuItemFolder:
625 cache = [BookmarkPositionCache 625 cache = [BookmarkPositionCache
626 cacheForMenuItemFolderWithPosition:position 626 cacheForMenuItemFolderWithPosition:position
627 folderId:item.folder->id()]; 627 folderId:item.folder->id()];
628 break; 628 break;
629 case bookmarks::MenuItemAll:
630 cache = [BookmarkPositionCache cacheForMenuItemAllWithPosition:position];
631 break;
632 case bookmarks::MenuItemDivider: 629 case bookmarks::MenuItemDivider:
633 case bookmarks::MenuItemSectionHeader: 630 case bookmarks::MenuItemSectionHeader:
634 NOTREACHED(); 631 NOTREACHED();
635 break; 632 break;
636 } 633 }
637 634
638 // TODO(crbug.com/388789): remove the use of NSUserDefaults. 635 // TODO(crbug.com/388789): remove the use of NSUserDefaults.
639 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:cache]; 636 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:cache];
640 [[NSUserDefaults standardUserDefaults] setObject:data 637 [[NSUserDefaults standardUserDefaults] setObject:data
641 forKey:kPositionCacheKey]; 638 forKey:kPositionCacheKey];
(...skipping 10 matching lines...) Expand all
652 NSData* data = 649 NSData* data =
653 [[NSUserDefaults standardUserDefaults] objectForKey:kPositionCacheKey]; 650 [[NSUserDefaults standardUserDefaults] objectForKey:kPositionCacheKey];
654 if (!data || ![data isKindOfClass:[NSData class]]) 651 if (!data || ![data isKindOfClass:[NSData class]])
655 return NO; 652 return NO;
656 BookmarkPositionCache* cache = 653 BookmarkPositionCache* cache =
657 [NSKeyedUnarchiver unarchiveObjectWithData:data]; 654 [NSKeyedUnarchiver unarchiveObjectWithData:data];
658 if (!cache) 655 if (!cache)
659 return NO; 656 return NO;
660 657
661 switch (cache.type) { 658 switch (cache.type) {
662 case bookmarks::MenuItemAll:
663 if (!experimental_flags::IsAllBookmarksEnabled())
664 return NO;
665 *item = [BookmarkMenuItem allMenuItem];
666 break;
667 case bookmarks::MenuItemFolder: { 659 case bookmarks::MenuItemFolder: {
668 const BookmarkNode* bookmark = FindFolderById(model, cache.folderId); 660 const BookmarkNode* bookmark = FindFolderById(model, cache.folderId);
669 if (!bookmark) 661 if (!bookmark)
670 return NO; 662 return NO;
671 const BookmarkNode* parent = RootLevelFolderForNode(bookmark, model); 663 const BookmarkNode* parent = RootLevelFolderForNode(bookmark, model);
672 if (!parent) 664 if (!parent)
673 parent = bookmark; 665 parent = bookmark;
674 *item = 666 *item =
675 [BookmarkMenuItem folderMenuItemForNode:bookmark rootAncestor:parent]; 667 [BookmarkMenuItem folderMenuItemForNode:bookmark rootAncestor:parent];
676 break; 668 break;
677 } 669 }
678 case bookmarks::MenuItemDivider: 670 case bookmarks::MenuItemDivider:
679 case bookmarks::MenuItemSectionHeader: 671 case bookmarks::MenuItemSectionHeader:
680 NOTREACHED(); 672 NOTREACHED();
681 return NO; 673 return NO;
682 } 674 }
683 675
684 *position = cache.position; 676 *position = cache.position;
685 return YES; 677 return YES;
686 } 678 }
687 679
688 void ClearPositionCache() { 680 void ClearPositionCache() {
689 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kPositionCacheKey]; 681 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kPositionCacheKey];
690 } 682 }
691 683
692 } // namespace bookmark_utils_ios 684 } // namespace bookmark_utils_ios
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698