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

Unified Diff: ios/chrome/browser/content_suggestions/content_suggestions_service_bridge_observer.h

Issue 2638413006: Add ContentSuggestionsMediator (Closed)
Patch Set: Format Created 3 years, 11 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
Index: ios/chrome/browser/content_suggestions/content_suggestions_service_bridge_observer.h
diff --git a/ios/chrome/browser/content_suggestions/content_suggestions_service_bridge_observer.h b/ios/chrome/browser/content_suggestions/content_suggestions_service_bridge_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..50ed859095eff85ba623760201ab6aa410c5d541
--- /dev/null
+++ b/ios/chrome/browser/content_suggestions/content_suggestions_service_bridge_observer.h
@@ -0,0 +1,69 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IOS_CHROME_BROWSER_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_SERVICE_BRIDGE_OBSERVER_H_
+#define IOS_CHROME_BROWSER_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_SERVICE_BRIDGE_OBSERVER_H_
+
+#include "components/ntp_snippets/content_suggestions_service.h"
+
+// Observes ContentSuggestionsService events from Objective-C. To use as a
+// ntp_snippets::ContentSuggestionsService::Observer, wrap in a
+// ContentSuggestionsServiceBridge.
+@protocol ContentSuggestionsServiceObserver
+
+// Invoked by ntp_snippets::ContentSuggestionsService::OnNewSuggestions.
+- (void)contentSuggestionsService:
+ (ntp_snippets::ContentSuggestionsService*)suggestionsService
+ newSuggestionsInCategory:(ntp_snippets::Category)category;
+
+// Invoked by ntp_snippets::ContentSuggestionsService::OnCategoryStatusChanged.
+- (void)contentSuggestionsService:
+ (ntp_snippets::ContentSuggestionsService*)suggestionsService
+ category:(ntp_snippets::Category)category
+ statusChangedTo:(ntp_snippets::CategoryStatus)status;
+
+// Invoked by ntp_snippets::ContentSuggestionsService::OnSuggestionInvalidated.
+- (void)contentSuggestionsService:
+ (ntp_snippets::ContentSuggestionsService*)suggestionsService
+ SuggestionInvalidated:
+ (const ntp_snippets::ContentSuggestion::ID&)suggestion_id;
+
+// Invoked by ntp_snippets::ContentSuggestionsService::OnFullRefreshRequired.
+- (void)contentSuggestionsServiceFullRefreshRequired:
+ (ntp_snippets::ContentSuggestionsService*)suggestionsService;
+
+// Invoked by
+// ntp_snippets::ContentSuggestionsService::ContentSuggestionsServiceShutdown.
+- (void)contentSuggestionsServiceShutdown:
+ (ntp_snippets::ContentSuggestionsService*)suggestionsService;
+
+@end
+
+// Observer for the ContentSuggestionsService that translates all the callbacks
+// to Objective-C calls.
+class ContentSuggestionsServiceBridge
+ : public ntp_snippets::ContentSuggestionsService::Observer {
+ public:
+ ContentSuggestionsServiceBridge(
+ id<ContentSuggestionsServiceObserver> observer,
+ ntp_snippets::ContentSuggestionsService* service);
+ ~ContentSuggestionsServiceBridge() override;
+
+ private:
+ void OnNewSuggestions(ntp_snippets::Category category) override;
+ void OnCategoryStatusChanged(
+ ntp_snippets::Category category,
+ ntp_snippets::CategoryStatus new_status) override;
+ void OnSuggestionInvalidated(
+ const ntp_snippets::ContentSuggestion::ID& suggestion_id) override;
+ void OnFullRefreshRequired() override;
+ void ContentSuggestionsServiceShutdown() override;
+
+ __unsafe_unretained id<ContentSuggestionsServiceObserver> observer_;
+ ntp_snippets::ContentSuggestionsService* service_; // weak
+
+ DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsServiceBridge);
+};
+
+#endif // IOS_CHROME_BROWSER_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_SERVICE_BRIDGE_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698