| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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_collection_view.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h" |
| 6 | 6 |
| 7 #import <UIKit/UIGestureRecognizerSubclass.h> | 7 #import <UIKit/UIGestureRecognizerSubclass.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/ios/weak_nsobject.h" | 12 #include "base/ios/weak_nsobject.h" |
| 13 #include "base/mac/bind_objc_block.h" | 13 #include "base/mac/bind_objc_block.h" |
| 14 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
| 15 #include "base/mac/objc_property_releaser.h" | 15 #include "base/mac/objc_release_properties.h" |
| 16 #include "base/mac/scoped_nsobject.h" | 16 #include "base/mac/scoped_nsobject.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "components/bookmarks/browser/bookmark_model.h" | 18 #include "components/bookmarks/browser/bookmark_model.h" |
| 19 #include "components/bookmarks/browser/bookmark_model_observer.h" | 19 #include "components/bookmarks/browser/bookmark_model_observer.h" |
| 20 #include "components/favicon/core/fallback_url_util.h" | 20 #include "components/favicon/core/fallback_url_util.h" |
| 21 #include "components/favicon/core/large_icon_service.h" | 21 #include "components/favicon/core/large_icon_service.h" |
| 22 #include "components/favicon_base/fallback_icon_style.h" | 22 #include "components/favicon_base/fallback_icon_style.h" |
| 23 #include "components/favicon_base/favicon_types.h" | 23 #include "components/favicon_base/favicon_types.h" |
| 24 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 24 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
| 25 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" | 25 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 53 // This delay should not be too small to let enough time to load bookmarks | 53 // This delay should not be too small to let enough time to load bookmarks |
| 54 // from network. | 54 // from network. |
| 55 const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; | 55 const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 @interface BookmarkCollectionView ()<UICollectionViewDataSource, | 59 @interface BookmarkCollectionView ()<UICollectionViewDataSource, |
| 60 UICollectionViewDelegateFlowLayout, | 60 UICollectionViewDelegateFlowLayout, |
| 61 UIGestureRecognizerDelegate> { | 61 UIGestureRecognizerDelegate> { |
| 62 std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; | 62 std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; |
| 63 ios::ChromeBrowserState* _browserState; | |
| 64 | |
| 65 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkCollectionView; | |
| 66 | 63 |
| 67 // Map of favicon load tasks for each index path. Used to keep track of | 64 // Map of favicon load tasks for each index path. Used to keep track of |
| 68 // pending favicon load operations so that they can be cancelled upon cell | 65 // pending favicon load operations so that they can be cancelled upon cell |
| 69 // reuse. Keys are (section, item) pairs of cell index paths. | 66 // reuse. Keys are (section, item) pairs of cell index paths. |
| 70 std::map<IntegerPair, base::CancelableTaskTracker::TaskId> _faviconLoadTasks; | 67 std::map<IntegerPair, base::CancelableTaskTracker::TaskId> _faviconLoadTasks; |
| 71 // Task tracker used for async favicon loads. | 68 // Task tracker used for async favicon loads. |
| 72 base::CancelableTaskTracker _faviconTaskTracker; | 69 base::CancelableTaskTracker _faviconTaskTracker; |
| 73 } | 70 } |
| 74 | 71 |
| 75 // Redefined to be readwrite. | 72 // Redefined to be readwrite. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 127 |
| 131 - (id)initWithFrame:(CGRect)frame { | 128 - (id)initWithFrame:(CGRect)frame { |
| 132 NOTREACHED(); | 129 NOTREACHED(); |
| 133 return nil; | 130 return nil; |
| 134 } | 131 } |
| 135 | 132 |
| 136 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 133 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
| 137 frame:(CGRect)frame { | 134 frame:(CGRect)frame { |
| 138 self = [super initWithFrame:frame]; | 135 self = [super initWithFrame:frame]; |
| 139 if (self) { | 136 if (self) { |
| 140 _propertyReleaser_BookmarkCollectionView.Init( | |
| 141 self, [BookmarkCollectionView class]); | |
| 142 | |
| 143 _browserState = browserState; | 137 _browserState = browserState; |
| 144 | 138 |
| 145 // Set up connection to the BookmarkModel. | 139 // Set up connection to the BookmarkModel. |
| 146 _bookmarkModel = | 140 _bookmarkModel = |
| 147 ios::BookmarkModelFactory::GetForBrowserState(browserState); | 141 ios::BookmarkModelFactory::GetForBrowserState(browserState); |
| 148 | 142 |
| 149 // Set up observers. | 143 // Set up observers. |
| 150 _modelBridge.reset( | 144 _modelBridge.reset( |
| 151 new bookmarks::BookmarkModelBridge(self, _bookmarkModel)); | 145 new bookmarks::BookmarkModelBridge(self, _bookmarkModel)); |
| 152 | 146 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 163 // A collection view with a layout that uses a dynamic animator (aka | 157 // A collection view with a layout that uses a dynamic animator (aka |
| 164 // something that changes the layout over time) will crash if it is | 158 // something that changes the layout over time) will crash if it is |
| 165 // deallocated while the animation is currently playing. | 159 // deallocated while the animation is currently playing. |
| 166 // Apparently if a tick has been dispatched it will execute, invoking a | 160 // Apparently if a tick has been dispatched it will execute, invoking a |
| 167 // method on the deallocated collection. | 161 // method on the deallocated collection. |
| 168 // The only purpose of this block is to retain the collection view for a | 162 // The only purpose of this block is to retain the collection view for a |
| 169 // while, giving the layout a chance to perform its last tick. | 163 // while, giving the layout a chance to perform its last tick. |
| 170 [moi self]; | 164 [moi self]; |
| 171 }); | 165 }); |
| 172 _faviconTaskTracker.TryCancelAll(); | 166 _faviconTaskTracker.TryCancelAll(); |
| 167 base::mac::ReleaseProperties(self); |
| 173 [super dealloc]; | 168 [super dealloc]; |
| 174 } | 169 } |
| 175 | 170 |
| 176 - (void)setupViews { | 171 - (void)setupViews { |
| 177 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); | 172 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); |
| 178 base::scoped_nsobject<UICollectionViewFlowLayout> layout( | 173 base::scoped_nsobject<UICollectionViewFlowLayout> layout( |
| 179 [[UICollectionViewFlowLayout alloc] init]); | 174 [[UICollectionViewFlowLayout alloc] init]); |
| 180 | 175 |
| 181 base::scoped_nsobject<UICollectionView> collectionView( | 176 base::scoped_nsobject<UICollectionView> collectionView( |
| 182 [[UICollectionView alloc] initWithFrame:self.bounds | 177 [[UICollectionView alloc] initWithFrame:self.bounds |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 | 845 |
| 851 - (BOOL)shouldShowPromoCell { | 846 - (BOOL)shouldShowPromoCell { |
| 852 return NO; | 847 return NO; |
| 853 } | 848 } |
| 854 | 849 |
| 855 - (BOOL)isPromoActive { | 850 - (BOOL)isPromoActive { |
| 856 return NO; | 851 return NO; |
| 857 } | 852 } |
| 858 | 853 |
| 859 @end | 854 @end |
| OLD | NEW |