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

Unified Diff: ios/chrome/browser/ui/ntp/google_landing_mediator.mm

Issue 2887383003: Refresh the Most Visited tiles only on user interaction (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/ntp/google_landing_mediator.mm
diff --git a/ios/chrome/browser/ui/ntp/google_landing_mediator.mm b/ios/chrome/browser/ui/ntp/google_landing_mediator.mm
index d93c60f241ac4b4d0f5bc1e1c2959463121e907a..996b1b3f92e0e296b674779d906a1057de9ab7d8 100644
--- a/ios/chrome/browser/ui/ntp/google_landing_mediator.mm
+++ b/ios/chrome/browser/ui/ntp/google_landing_mediator.mm
@@ -106,8 +106,7 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
std::unique_ptr<ntp_tiles::MostVisitedSites> _mostVisitedSites;
- // Most visited data from the MostVisitedSites service (copied upon receiving
- // the callback).
+ // Most visited data from the MostVisitedSites service currently in use.
ntp_tiles::NTPTilesVector _mostVisitedData;
// Observes the WebStateList so that this mediator can update the UI when the
@@ -127,9 +126,17 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
// The dispatcher for this mediator.
@property(nonatomic, assign) id<ChromeExecuteCommand, UrlLoader> dispatcher;
+// Most visited data from the MostVisitedSites service (copied upon receiving
+// the callback), not yet used.
+@property(nonatomic, assign) ntp_tiles::NTPTilesVector freshMostVisitedData;
+
// Perform initial setup.
- (void)setUp;
+// If there is some fresh most visited tiles, they become the current tiles and
+// the consumer gets notified.
+- (void)useFreshData;
+
@end
@implementation GoogleLandingMediator
@@ -137,6 +144,7 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
@synthesize consumer = _consumer;
@synthesize dispatcher = _dispatcher;
@synthesize webStateList = _webStateList;
+@synthesize freshMostVisitedData = _freshMostVisitedData;
- (instancetype)initWithConsumer:(id<GoogleLandingConsumer>)consumer
browserState:(ios::ChromeBrowserState*)browserState
@@ -240,6 +248,11 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
#pragma mark - MostVisitedSitesObserving
- (void)onMostVisitedURLsAvailable:(const ntp_tiles::NTPTilesVector&)data {
+ if (_mostVisitedData.size() > 0) {
fhorschig 2017/05/19 13:09:57 Could you please add a comment why the fresh data
gambard 2017/05/19 13:41:20 Done.
+ self.freshMostVisitedData = data;
+ return;
+ }
+
_mostVisitedData = data;
[self.consumer mostVisitedDataUpdated];
@@ -299,10 +312,12 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
- (void)addBlacklistedURL:(const GURL&)url {
_mostVisitedSites->AddOrRemoveBlacklistedUrl(url, true);
+ [self useFreshData];
}
- (void)removeBlacklistedURL:(const GURL&)url {
_mostVisitedSites->AddOrRemoveBlacklistedUrl(url, false);
+ [self useFreshData];
}
- (ntp_tiles::NTPTile)mostVisitedAtIndex:(NSUInteger)index {
@@ -363,4 +378,15 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
NOTREACHED();
}
+#pragma mark - Private
+
+- (void)useFreshData {
+ if (self.freshMostVisitedData.size() == 0) {
+ return;
+ }
+ _mostVisitedData = self.freshMostVisitedData;
+ self.freshMostVisitedData.clear();
+ [self.consumer mostVisitedDataUpdated];
+}
+
@end
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698