| OLD | NEW |
| 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 Loading... |
| 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; |
| 629 case bookmarks::MenuItemDivider: | 632 case bookmarks::MenuItemDivider: |
| 630 case bookmarks::MenuItemSectionHeader: | 633 case bookmarks::MenuItemSectionHeader: |
| 631 NOTREACHED(); | 634 NOTREACHED(); |
| 632 break; | 635 break; |
| 633 } | 636 } |
| 634 | 637 |
| 635 // TODO(crbug.com/388789): remove the use of NSUserDefaults. | 638 // TODO(crbug.com/388789): remove the use of NSUserDefaults. |
| 636 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:cache]; | 639 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:cache]; |
| 637 [[NSUserDefaults standardUserDefaults] setObject:data | 640 [[NSUserDefaults standardUserDefaults] setObject:data |
| 638 forKey:kPositionCacheKey]; | 641 forKey:kPositionCacheKey]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 649 NSData* data = | 652 NSData* data = |
| 650 [[NSUserDefaults standardUserDefaults] objectForKey:kPositionCacheKey]; | 653 [[NSUserDefaults standardUserDefaults] objectForKey:kPositionCacheKey]; |
| 651 if (!data || ![data isKindOfClass:[NSData class]]) | 654 if (!data || ![data isKindOfClass:[NSData class]]) |
| 652 return NO; | 655 return NO; |
| 653 BookmarkPositionCache* cache = | 656 BookmarkPositionCache* cache = |
| 654 [NSKeyedUnarchiver unarchiveObjectWithData:data]; | 657 [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
| 655 if (!cache) | 658 if (!cache) |
| 656 return NO; | 659 return NO; |
| 657 | 660 |
| 658 switch (cache.type) { | 661 switch (cache.type) { |
| 662 case bookmarks::MenuItemAll: |
| 663 if (!experimental_flags::IsAllBookmarksEnabled()) |
| 664 return NO; |
| 665 *item = [BookmarkMenuItem allMenuItem]; |
| 666 break; |
| 659 case bookmarks::MenuItemFolder: { | 667 case bookmarks::MenuItemFolder: { |
| 660 const BookmarkNode* bookmark = FindFolderById(model, cache.folderId); | 668 const BookmarkNode* bookmark = FindFolderById(model, cache.folderId); |
| 661 if (!bookmark) | 669 if (!bookmark) |
| 662 return NO; | 670 return NO; |
| 663 const BookmarkNode* parent = RootLevelFolderForNode(bookmark, model); | 671 const BookmarkNode* parent = RootLevelFolderForNode(bookmark, model); |
| 664 if (!parent) | 672 if (!parent) |
| 665 parent = bookmark; | 673 parent = bookmark; |
| 666 *item = | 674 *item = |
| 667 [BookmarkMenuItem folderMenuItemForNode:bookmark rootAncestor:parent]; | 675 [BookmarkMenuItem folderMenuItemForNode:bookmark rootAncestor:parent]; |
| 668 break; | 676 break; |
| 669 } | 677 } |
| 670 case bookmarks::MenuItemDivider: | 678 case bookmarks::MenuItemDivider: |
| 671 case bookmarks::MenuItemSectionHeader: | 679 case bookmarks::MenuItemSectionHeader: |
| 672 NOTREACHED(); | 680 NOTREACHED(); |
| 673 return NO; | 681 return NO; |
| 674 } | 682 } |
| 675 | 683 |
| 676 *position = cache.position; | 684 *position = cache.position; |
| 677 return YES; | 685 return YES; |
| 678 } | 686 } |
| 679 | 687 |
| 680 void ClearPositionCache() { | 688 void ClearPositionCache() { |
| 681 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kPositionCacheKey]; | 689 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kPositionCacheKey]; |
| 682 } | 690 } |
| 683 | 691 |
| 684 } // namespace bookmark_utils_ios | 692 } // namespace bookmark_utils_ios |
| OLD | NEW |