| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/app/spotlight/topsites_spotlight_manager.h" | 5 #import "ios/chrome/app/spotlight/topsites_spotlight_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 (const suggestions::SuggestionsProfile&)suggestions_profile; | 86 (const suggestions::SuggestionsProfile&)suggestions_profile; |
| 87 | 87 |
| 88 @end | 88 @end |
| 89 | 89 |
| 90 class SpotlightTopSitesCallbackBridge | 90 class SpotlightTopSitesCallbackBridge |
| 91 : public base::SupportsWeakPtr<SpotlightTopSitesCallbackBridge> { | 91 : public base::SupportsWeakPtr<SpotlightTopSitesCallbackBridge> { |
| 92 public: | 92 public: |
| 93 explicit SpotlightTopSitesCallbackBridge(TopSitesSpotlightManager* owner) | 93 explicit SpotlightTopSitesCallbackBridge(TopSitesSpotlightManager* owner) |
| 94 : owner_(owner) {} | 94 : owner_(owner) {} |
| 95 | 95 |
| 96 SpotlightTopSitesCallbackBridge() {} | 96 ~SpotlightTopSitesCallbackBridge() {} |
| 97 | 97 |
| 98 void OnMostVisitedURLsAvailable(const history::MostVisitedURLList& data) { | 98 void OnMostVisitedURLsAvailable(const history::MostVisitedURLList& data) { |
| 99 [owner_ onMostVisitedURLsAvailable:data]; | 99 [owner_ onMostVisitedURLsAvailable:data]; |
| 100 } | 100 } |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 __weak TopSitesSpotlightManager* owner_; | 103 __weak TopSitesSpotlightManager* owner_; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 class SpotlightTopSitesBridge : public history::TopSitesObserver { | 106 class SpotlightTopSitesBridge : public history::TopSitesObserver { |
| 107 public: | 107 public: |
| 108 explicit SpotlightTopSitesBridge(TopSitesSpotlightManager* owner) | 108 SpotlightTopSitesBridge(TopSitesSpotlightManager* owner, |
| 109 : owner_(owner) { | 109 history::TopSites* top_sites) |
| 110 owner.topSites->AddObserver(this); | 110 : owner_(owner), top_sites_(top_sites) { |
| 111 top_sites->AddObserver(this); |
| 111 }; | 112 }; |
| 112 | 113 |
| 113 ~SpotlightTopSitesBridge() override { | 114 ~SpotlightTopSitesBridge() override { |
| 114 owner_.topSites->RemoveObserver(this); | 115 top_sites_->RemoveObserver(this); |
| 116 top_sites_ = nullptr; |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 void TopSitesLoaded(history::TopSites* top_sites) override {} | 119 void TopSitesLoaded(history::TopSites* top_sites) override {} |
| 118 | 120 |
| 119 void TopSitesChanged(history::TopSites* top_sites, | 121 void TopSitesChanged(history::TopSites* top_sites, |
| 120 ChangeReason change_reason) override { | 122 ChangeReason change_reason) override { |
| 121 [owner_ updateAllTopSitesSpotlightItems]; | 123 [owner_ updateAllTopSitesSpotlightItems]; |
| 122 } | 124 } |
| 123 | 125 |
| 124 private: | 126 private: |
| 125 __weak TopSitesSpotlightManager* owner_; | 127 __weak TopSitesSpotlightManager* owner_; |
| 128 history::TopSites* top_sites_; |
| 126 }; | 129 }; |
| 127 | 130 |
| 128 class SpotlightSuggestionsBridge | 131 class SpotlightSuggestionsBridge |
| 129 : public base::SupportsWeakPtr<SpotlightSuggestionsBridge> { | 132 : public base::SupportsWeakPtr<SpotlightSuggestionsBridge> { |
| 130 public: | 133 public: |
| 131 explicit SpotlightSuggestionsBridge(TopSitesSpotlightManager* owner) | 134 explicit SpotlightSuggestionsBridge(TopSitesSpotlightManager* owner) |
| 132 : owner_(owner) {} | 135 : owner_(owner) {} |
| 133 | 136 |
| 134 SpotlightSuggestionsBridge() {} | 137 ~SpotlightSuggestionsBridge() {} |
| 135 | 138 |
| 136 void OnSuggestionsProfileAvailable( | 139 void OnSuggestionsProfileAvailable( |
| 137 const suggestions::SuggestionsProfile& suggestions_profile) { | 140 const suggestions::SuggestionsProfile& suggestions_profile) { |
| 138 [owner_ onSuggestionsProfileAvailable:suggestions_profile]; | 141 [owner_ onSuggestionsProfileAvailable:suggestions_profile]; |
| 139 } | 142 } |
| 140 | 143 |
| 141 private: | 144 private: |
| 142 __weak TopSitesSpotlightManager* owner_; | 145 __weak TopSitesSpotlightManager* owner_; |
| 143 }; | 146 }; |
| 144 | 147 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 163 - (instancetype) | 166 - (instancetype) |
| 164 initWithLargeIconService:(favicon::LargeIconService*)largeIconService | 167 initWithLargeIconService:(favicon::LargeIconService*)largeIconService |
| 165 topSites:(scoped_refptr<history::TopSites>)topSites | 168 topSites:(scoped_refptr<history::TopSites>)topSites |
| 166 bookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel | 169 bookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel |
| 167 profileSyncService:(browser_sync::ProfileSyncService*)syncService | 170 profileSyncService:(browser_sync::ProfileSyncService*)syncService |
| 168 suggestionsService:(suggestions::SuggestionsService*)suggestionsService { | 171 suggestionsService:(suggestions::SuggestionsService*)suggestionsService { |
| 169 self = [super initWithLargeIconService:largeIconService | 172 self = [super initWithLargeIconService:largeIconService |
| 170 domain:spotlight::DOMAIN_TOPSITES]; | 173 domain:spotlight::DOMAIN_TOPSITES]; |
| 171 if (self) { | 174 if (self) { |
| 172 _topSites = topSites; | 175 _topSites = topSites; |
| 173 _topSitesBridge.reset(new SpotlightTopSitesBridge(self)); | 176 _topSitesBridge.reset(new SpotlightTopSitesBridge(self, _topSites.get())); |
| 174 _topSitesCallbackBridge.reset(new SpotlightTopSitesCallbackBridge(self)); | 177 _topSitesCallbackBridge.reset(new SpotlightTopSitesCallbackBridge(self)); |
| 175 _bookmarkModel = bookmarkModel; | 178 _bookmarkModel = bookmarkModel; |
| 176 _isReindexPending = false; | 179 _isReindexPending = false; |
| 177 if (syncService && suggestionsService) { | 180 if (syncService && suggestionsService) { |
| 178 _suggestionsBridge.reset(new SpotlightSuggestionsBridge(self)); | 181 _suggestionsBridge.reset(new SpotlightSuggestionsBridge(self)); |
| 179 _syncService = syncService; | 182 _syncService = syncService; |
| 180 _suggestionService = suggestionsService; | 183 _suggestionService = suggestionsService; |
| 181 _suggestionsServiceResponseSubscription = _suggestionService->AddCallback( | 184 _suggestionsServiceResponseSubscription = _suggestionService->AddCallback( |
| 182 base::Bind(&SpotlightSuggestionsBridge::OnSuggestionsProfileAvailable, | 185 base::Bind(&SpotlightSuggestionsBridge::OnSuggestionsProfileAvailable, |
| 183 _suggestionsBridge->AsWeakPtr())); | 186 _suggestionsBridge->AsWeakPtr())); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 287 } |
| 285 | 288 |
| 286 #pragma mark - | 289 #pragma mark - |
| 287 #pragma mark SyncObserverModelBridge | 290 #pragma mark SyncObserverModelBridge |
| 288 | 291 |
| 289 - (void)onSyncStateChanged { | 292 - (void)onSyncStateChanged { |
| 290 [self updateAllTopSitesSpotlightItems]; | 293 [self updateAllTopSitesSpotlightItems]; |
| 291 } | 294 } |
| 292 | 295 |
| 293 @end | 296 @end |
| OLD | NEW |