Chromium Code Reviews| 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 #import "ios/chrome/browser/ui/ntp/google_landing_controller.h" | 5 #import "ios/chrome/browser/ui/ntp/google_landing_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 - (void)onIconMadeAvailable:(const GURL&)siteUrl; | 114 - (void)onIconMadeAvailable:(const GURL&)siteUrl; |
| 115 @end | 115 @end |
| 116 | 116 |
| 117 namespace google_landing { | 117 namespace google_landing { |
| 118 | 118 |
| 119 // MostVisitedSitesObserverBridge allow registration as a | 119 // MostVisitedSitesObserverBridge allow registration as a |
| 120 // MostVisitedSites::Observer. | 120 // MostVisitedSites::Observer. |
| 121 class MostVisitedSitesObserverBridge | 121 class MostVisitedSitesObserverBridge |
| 122 : public ntp_tiles::MostVisitedSites::Observer { | 122 : public ntp_tiles::MostVisitedSites::Observer { |
| 123 public: | 123 public: |
| 124 MostVisitedSitesObserverBridge(GoogleLandingController* owner); | 124 MostVisitedSitesObserverBridge( |
| 125 GoogleLandingController* owner, | |
| 126 ntp_tiles::MostVisitedSites* most_visited_sites); | |
| 125 ~MostVisitedSitesObserverBridge() override; | 127 ~MostVisitedSitesObserverBridge() override; |
| 126 | 128 |
| 127 // MostVisitedSites::Observer implementation. | 129 // MostVisitedSites::Observer implementation. |
| 128 void OnMostVisitedURLsAvailable( | 130 void OnMostVisitedURLsAvailable( |
| 129 const ntp_tiles::NTPTilesVector& most_visited) override; | 131 const ntp_tiles::NTPTilesVector& most_visited) override; |
| 130 void OnIconMadeAvailable(const GURL& site_url) override; | 132 void OnIconMadeAvailable(const GURL& site_url) override; |
| 131 | 133 |
| 132 private: | 134 private: |
| 133 GoogleLandingController* _owner; | 135 GoogleLandingController* _owner; |
| 136 ntp_tiles::MostVisitedSites* _most_visited_sites; // weak | |
| 134 }; | 137 }; |
| 135 | 138 |
| 136 MostVisitedSitesObserverBridge::MostVisitedSitesObserverBridge( | 139 MostVisitedSitesObserverBridge::MostVisitedSitesObserverBridge( |
| 137 GoogleLandingController* owner) | 140 GoogleLandingController* owner, |
| 138 : _owner(owner) {} | 141 ntp_tiles::MostVisitedSites* most_visited_sites) |
| 142 : _owner(owner), _most_visited_sites(most_visited_sites) { | |
| 143 _most_visited_sites->AddObserver(this); | |
| 144 } | |
| 139 | 145 |
| 140 MostVisitedSitesObserverBridge::~MostVisitedSitesObserverBridge() {} | 146 MostVisitedSitesObserverBridge::~MostVisitedSitesObserverBridge() { |
| 147 _most_visited_sites->RemoveObserver(this); | |
| 148 } | |
| 141 | 149 |
| 142 void MostVisitedSitesObserverBridge::OnMostVisitedURLsAvailable( | 150 void MostVisitedSitesObserverBridge::OnMostVisitedURLsAvailable( |
| 143 const ntp_tiles::NTPTilesVector& tiles) { | 151 const ntp_tiles::NTPTilesVector& tiles) { |
| 144 [_owner onMostVisitedURLsAvailable:tiles]; | 152 [_owner onMostVisitedURLsAvailable:tiles]; |
| 145 } | 153 } |
| 146 | 154 |
| 147 void MostVisitedSitesObserverBridge::OnIconMadeAvailable(const GURL& site_url) { | 155 void MostVisitedSitesObserverBridge::OnIconMadeAvailable(const GURL& site_url) { |
| 148 [_owner onIconMadeAvailable:site_url]; | 156 [_owner onIconMadeAvailable:site_url]; |
| 149 } | 157 } |
| 150 | 158 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 // Tap and swipe gesture recognizers when the omnibox is focused. | 267 // Tap and swipe gesture recognizers when the omnibox is focused. |
| 260 base::scoped_nsobject<UITapGestureRecognizer> _tapGestureRecognizer; | 268 base::scoped_nsobject<UITapGestureRecognizer> _tapGestureRecognizer; |
| 261 base::scoped_nsobject<UISwipeGestureRecognizer> _swipeGestureRecognizer; | 269 base::scoped_nsobject<UISwipeGestureRecognizer> _swipeGestureRecognizer; |
| 262 | 270 |
| 263 // Handles displaying the context menu for all form factors. | 271 // Handles displaying the context menu for all form factors. |
| 264 base::scoped_nsobject<ContextMenuCoordinator> _contextMenuCoordinator; | 272 base::scoped_nsobject<ContextMenuCoordinator> _contextMenuCoordinator; |
| 265 | 273 |
| 266 // What's new promo. | 274 // What's new promo. |
| 267 std::unique_ptr<NotificationPromoWhatsNew> _notification_promo; | 275 std::unique_ptr<NotificationPromoWhatsNew> _notification_promo; |
| 268 | 276 |
| 277 std::unique_ptr<ntp_tiles::MostVisitedSites> _most_visited_sites; | |
| 278 | |
| 269 // A MostVisitedSites::Observer bridge object to get notified of most visited | 279 // A MostVisitedSites::Observer bridge object to get notified of most visited |
| 270 // sites changes. | 280 // sites changes. |
| 271 std::unique_ptr<google_landing::MostVisitedSitesObserverBridge> | 281 std::unique_ptr<google_landing::MostVisitedSitesObserverBridge> |
| 272 _most_visited_observer_bridge; | 282 _most_visited_observer_bridge; |
| 273 | 283 |
| 274 std::unique_ptr<ntp_tiles::MostVisitedSites> _most_visited_sites; | |
| 275 | |
| 276 // URL of the last deleted most viewed entry. If present the UI to restore it | 284 // URL of the last deleted most viewed entry. If present the UI to restore it |
| 277 // is shown. | 285 // is shown. |
| 278 base::scoped_nsobject<NSURL> _deletedUrl; | 286 base::scoped_nsobject<NSURL> _deletedUrl; |
| 279 | 287 |
| 280 // Listen for default search engine changes. | 288 // Listen for default search engine changes. |
| 281 std::unique_ptr<google_landing::SearchEngineObserver> _observer; | 289 std::unique_ptr<google_landing::SearchEngineObserver> _observer; |
| 282 TemplateURLService* _templateURLService; // weak | 290 TemplateURLService* _templateURLService; // weak |
| 283 | 291 |
| 284 // |YES| if the view has finished its first layout. This is useful when | 292 // |YES| if the view has finished its first layout. This is useful when |
| 285 // determining if the view has sized itself for tablet. | 293 // determining if the view has sized itself for tablet. |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 withReuseIdentifier:@"whatsNew"]; | 932 withReuseIdentifier:@"whatsNew"]; |
| 925 [_mostVisitedView registerClass:[NewTabPageHeaderView class] | 933 [_mostVisitedView registerClass:[NewTabPageHeaderView class] |
| 926 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader | 934 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
| 927 withReuseIdentifier:@"header"]; | 935 withReuseIdentifier:@"header"]; |
| 928 [_mostVisitedView setAccessibilityIdentifier:@"Google Landing"]; | 936 [_mostVisitedView setAccessibilityIdentifier:@"Google Landing"]; |
| 929 | 937 |
| 930 [_view addSubview:_mostVisitedView]; | 938 [_view addSubview:_mostVisitedView]; |
| 931 _most_visited_sites = | 939 _most_visited_sites = |
| 932 IOSMostVisitedSitesFactory::NewForBrowserState(_browserState); | 940 IOSMostVisitedSitesFactory::NewForBrowserState(_browserState); |
| 933 _most_visited_observer_bridge.reset( | 941 _most_visited_observer_bridge.reset( |
| 934 new google_landing::MostVisitedSitesObserverBridge(self)); | 942 new google_landing::MostVisitedSitesObserverBridge( |
| 935 _most_visited_sites->SetMostVisitedURLsObserver( | 943 self, _most_visited_sites.get())); |
| 936 _most_visited_observer_bridge.get(), kMaxNumMostVisitedFavicons); | 944 _most_visited_sites->Refresh(); |
| 937 } | 945 } |
| 938 | 946 |
| 939 - (void)updateSearchField { | 947 - (void)updateSearchField { |
| 940 NSArray* constraints = | 948 NSArray* constraints = |
| 941 @[ _hintLabelLeadingConstraint, _voiceTapTrailingConstraint ]; | 949 @[ _hintLabelLeadingConstraint, _voiceTapTrailingConstraint ]; |
| 942 [_headerView updateSearchField:_searchTapTarget | 950 [_headerView updateSearchField:_searchTapTarget |
| 943 withInitialFrame:[self searchFieldFrame] | 951 withInitialFrame:[self searchFieldFrame] |
| 944 subviewConstraints:constraints | 952 subviewConstraints:constraints |
| 945 forOffset:[_mostVisitedView contentOffset].y]; | 953 forOffset:[_mostVisitedView contentOffset].y]; |
| 946 } | 954 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 tileType:(ntp_tiles::metrics::MostVisitedTileType)tileType { | 1100 tileType:(ntp_tiles::metrics::MostVisitedTileType)tileType { |
| 1093 new_tab_page_uma::RecordAction( | 1101 new_tab_page_uma::RecordAction( |
| 1094 _browserState, new_tab_page_uma::ACTION_OPENED_MOST_VISITED_ENTRY); | 1102 _browserState, new_tab_page_uma::ACTION_OPENED_MOST_VISITED_ENTRY); |
| 1095 base::RecordAction(UserMetricsAction("MobileNTPMostVisited")); | 1103 base::RecordAction(UserMetricsAction("MobileNTPMostVisited")); |
| 1096 const ntp_tiles::NTPTile& tile = _mostVisitedData[visitedIndex]; | 1104 const ntp_tiles::NTPTile& tile = _mostVisitedData[visitedIndex]; |
| 1097 ntp_tiles::metrics::RecordTileClick(visitedIndex, tile.source, tileType); | 1105 ntp_tiles::metrics::RecordTileClick(visitedIndex, tile.source, tileType); |
| 1098 } | 1106 } |
| 1099 | 1107 |
| 1100 - (void)onMostVisitedURLsAvailable:(const ntp_tiles::NTPTilesVector&)data { | 1108 - (void)onMostVisitedURLsAvailable:(const ntp_tiles::NTPTilesVector&)data { |
| 1101 _mostVisitedData = data; | 1109 _mostVisitedData = data; |
| 1110 if (_mostVisitedData.size() > kMaxNumMostVisitedFavicons) | |
|
sfiera
2017/01/18 09:58:33
We're resizing to save memory, but it's not relate
| |
| 1111 _mostVisitedData.resize(kMaxNumMostVisitedFavicons); | |
| 1112 | |
| 1102 [self reloadData]; | 1113 [self reloadData]; |
| 1103 | 1114 |
| 1104 if (data.size() && !_recordedPageImpression) { | 1115 if (_mostVisitedData.size() && !_recordedPageImpression) { |
| 1105 _recordedPageImpression = YES; | 1116 _recordedPageImpression = YES; |
| 1106 std::vector<ntp_tiles::metrics::TileImpression> tiles; | 1117 std::vector<ntp_tiles::metrics::TileImpression> tiles; |
| 1107 for (const ntp_tiles::NTPTile& ntpTile : data) { | 1118 for (const ntp_tiles::NTPTile& ntpTile : _mostVisitedData) { |
| 1108 tiles.emplace_back(ntpTile.source, ntp_tiles::metrics::UNKNOWN_TILE_TYPE, | 1119 tiles.emplace_back(ntpTile.source, ntp_tiles::metrics::UNKNOWN_TILE_TYPE, |
| 1109 ntpTile.url); | 1120 ntpTile.url); |
| 1110 } | 1121 } |
| 1111 ntp_tiles::metrics::RecordPageImpression( | 1122 ntp_tiles::metrics::RecordPageImpression( |
| 1112 tiles, GetApplicationContext()->GetRapporServiceImpl()); | 1123 tiles, GetApplicationContext()->GetRapporServiceImpl()); |
| 1113 } | 1124 } |
| 1114 } | 1125 } |
| 1115 | 1126 |
| 1116 - (void)onIconMadeAvailable:(const GURL&)siteUrl { | 1127 - (void)onIconMadeAvailable:(const GURL&)siteUrl { |
| 1117 for (size_t i = 0; i < [self numberOfItems]; ++i) { | 1128 for (size_t i = 0; i < [self numberOfItems]; ++i) { |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1740 if (!view) { | 1751 if (!view) { |
| 1741 return nil; | 1752 return nil; |
| 1742 } | 1753 } |
| 1743 if ([view isKindOfClass:aClass]) { | 1754 if ([view isKindOfClass:aClass]) { |
| 1744 return view; | 1755 return view; |
| 1745 } | 1756 } |
| 1746 return [self nearestAncestorOfView:[view superview] withClass:aClass]; | 1757 return [self nearestAncestorOfView:[view superview] withClass:aClass]; |
| 1747 } | 1758 } |
| 1748 | 1759 |
| 1749 @end | 1760 @end |
| OLD | NEW |