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

Unified Diff: ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.mm

Issue 2589583003: Upstream Chrome on iOS source code [7/11]. (Closed)
Patch Set: Created 4 years 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/ui/reading_list/reading_list_menu_notifier.mm
diff --git a/ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.mm b/ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.mm
new file mode 100644
index 0000000000000000000000000000000000000000..47fb7a6eaf5fe1db25075d5bd81728d858ef273f
--- /dev/null
+++ b/ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.mm
@@ -0,0 +1,100 @@
+// Copyright 2016 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.
+
+#import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h"
+
+#include <memory>
+
+#include "components/reading_list/ios/reading_list_model.h"
+#import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_delegate.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+class ReadingListObserverBridge;
+
+@interface ReadingListMenuNotifier () {
+ // Observer for reading list changes.
+ std::unique_ptr<ReadingListObserverBridge> _readingListObserverBridge;
+
+ // Backing object for property of the same name.
+ __weak id<ReadingListMenuNotificationDelegate> _delegate;
+
+ // Keep a reference to detach before deallocing.
+ ReadingListModel* _readingListModel; // weak
+}
+
+// Detach the observer on the reading list.
+- (void)detachReadingListModel;
+
+// Handle callbacks from the reading list model observer.
+- (void)readingListModelCompletedBatchUpdates:(const ReadingListModel*)model;
+
+@end
+
+// TODO(crbug.com/590725): use the one-and-only protocol-based implementation of
+// ReadingListModelObserver
+class ReadingListObserverBridge : public ReadingListModelObserver {
+ public:
+ explicit ReadingListObserverBridge(ReadingListMenuNotifier* owner)
+ : owner_(owner) {}
+
+ ~ReadingListObserverBridge() override {}
+
+ void ReadingListModelLoaded(const ReadingListModel* model) override {}
+
+ void ReadingListModelBeganBatchUpdates(
+ const ReadingListModel* model) override {}
+
+ void ReadingListModelCompletedBatchUpdates(
+ const ReadingListModel* model) override {
+ [owner_ readingListModelCompletedBatchUpdates:model];
+ }
+
+ void ReadingListModelBeingDeleted(const ReadingListModel* model) override{};
+
+ void ReadingListDidApplyChanges(ReadingListModel* model) override {
+ [owner_ readingListModelCompletedBatchUpdates:model];
+ }
+
+ private:
+ ReadingListMenuNotifier* owner_; // weak, owns us
+};
+
+@implementation ReadingListMenuNotifier
+@synthesize delegate = _delegate;
+
+- (instancetype)initWithReadingList:(ReadingListModel*)readingListModel {
+ if (self = [super init]) {
+ _readingListObserverBridge.reset(new ReadingListObserverBridge(self));
+ _readingListModel = readingListModel;
+ _readingListModel->AddObserver(_readingListObserverBridge.get());
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [self detachReadingListModel];
+}
+
+- (void)detachReadingListModel {
+ _readingListModel->RemoveObserver(_readingListObserverBridge.get());
+ _readingListObserverBridge.reset();
+}
+
+- (void)readingListModelCompletedBatchUpdates:(const ReadingListModel*)model {
+ [_delegate unreadCountChanged:model->unread_size()];
+ [_delegate unseenStateChanged:model->HasUnseenEntries()];
+}
+
+- (NSInteger)readingListUnreadCount {
+ return _readingListModel->unread_size();
+}
+
+- (BOOL)readingListUnseenItemsExist {
+ return _readingListModel->HasUnseenEntries();
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698