| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_OBSERVER_H_ | 5 #ifndef COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_OBSERVER_H_ |
| 6 #define COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_OBSERVER_H_ | 6 #define COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 class GURL; |
| 11 class ReadingListModel; | 12 class ReadingListModel; |
| 12 class ReadingListEntry; | 13 class ReadingListEntry; |
| 13 | 14 |
| 14 // Observer for the Reading List model. In the observer methods care should be | 15 // Observer for the Reading List model. In the observer methods care should be |
| 15 // taken to not modify the model. | 16 // taken to not modify the model. |
| 16 class ReadingListModelObserver { | 17 class ReadingListModelObserver { |
| 17 public: | 18 public: |
| 18 // Invoked when the model has finished loading. Until this method is called it | 19 // Invoked when the model has finished loading. Until this method is called it |
| 19 // is unsafe to use the model. | 20 // is unsafe to use the model. |
| 20 virtual void ReadingListModelLoaded(const ReadingListModel* model) = 0; | 21 virtual void ReadingListModelLoaded(const ReadingListModel* model) = 0; |
| 21 | 22 |
| 22 // Invoked when the batch updates are about to start. It will only be called | 23 // Invoked when the batch updates are about to start. It will only be called |
| 23 // once before ReadingListModelCompletedBatchUpdates, even if several updates | 24 // once before ReadingListModelCompletedBatchUpdates, even if several updates |
| 24 // are taking place at the same time. | 25 // are taking place at the same time. |
| 25 virtual void ReadingListModelBeganBatchUpdates( | 26 virtual void ReadingListModelBeganBatchUpdates( |
| 26 const ReadingListModel* model) {} | 27 const ReadingListModel* model) {} |
| 27 | 28 |
| 28 // Invoked when the batch updates have completed. This is called once all | 29 // Invoked when the batch updates have completed. This is called once all |
| 29 // batch updates are completed. | 30 // batch updates are completed. |
| 30 virtual void ReadingListModelCompletedBatchUpdates( | 31 virtual void ReadingListModelCompletedBatchUpdates( |
| 31 const ReadingListModel* model) {} | 32 const ReadingListModel* model) {} |
| 32 | 33 |
| 33 // Invoked from the destructor of the model. The model is no longer valid | 34 // Invoked from the destructor of the model. The model is no longer valid |
| 34 // after this call. There is no need to call RemoveObserver on the model from | 35 // after this call. There is no need to call RemoveObserver on the model from |
| 35 // here, as the observers are automatically deleted. | 36 // here, as the observers are automatically deleted. |
| 36 virtual void ReadingListModelBeingDeleted(const ReadingListModel* model) {} | 37 virtual void ReadingListModelBeingDeleted(const ReadingListModel* model) {} |
| 37 | 38 |
| 38 // Invoked when elements are about to be removed from the read or unread list. | 39 // Invoked when elements are about to be removed from the read or unread list. |
| 40 virtual void ReadingListWillRemoveEntry(const ReadingListModel* model, |
| 41 const GURL& url) {} |
| 42 // Invoked when elements |MarkEntryUpdated| is called on an entry. This means |
| 43 // that the order of the entry may change and read/unread list may change |
| 44 // too. |
| 45 virtual void ReadingListWillMoveEntry(const ReadingListModel* model, |
| 46 const GURL& url) {} |
| 47 |
| 48 // Invoked when elements are added. |
| 49 virtual void ReadingListWillAddEntry(const ReadingListModel* model, |
| 50 const ReadingListEntry& entry) {} |
| 51 |
| 52 // Invoked when elements have been added. This method is called after the |
| 53 // the entry has been added to the model and the entry can now be retrieved |
| 54 // from the model. |
| 55 virtual void ReadingListDidAddEntry(const ReadingListModel* model, |
| 56 const GURL& url) {} |
| 57 |
| 58 // Invoked when an entry is about to change. |
| 59 virtual void ReadingListWillUpdateEntry(const ReadingListModel* model, |
| 60 const GURL& url) {} |
| 61 |
| 62 // Called after all the changes signaled by calls to the "Will" methods are |
| 63 // done. All the "Will" methods are called as necessary, then the changes |
| 64 // are applied and then this method is called. |
| 65 virtual void ReadingListDidApplyChanges(ReadingListModel* model) {} |
| 66 |
| 67 // TODO(crbug.com/664924): Remove temporary methods |
| 39 virtual void ReadingListWillRemoveUnreadEntry(const ReadingListModel* model, | 68 virtual void ReadingListWillRemoveUnreadEntry(const ReadingListModel* model, |
| 40 size_t index) {} | 69 size_t index) {} |
| 70 |
| 41 virtual void ReadingListWillRemoveReadEntry(const ReadingListModel* model, | 71 virtual void ReadingListWillRemoveReadEntry(const ReadingListModel* model, |
| 42 size_t index) {} | 72 size_t index) {} |
| 43 // Invoked when elements are moved from unread to read or from read to unread. | |
| 44 // |index| is the original position and |read| the origin status. The element | |
| 45 // will change list and/or index but will not be deleted. | |
| 46 virtual void ReadingListWillMoveEntry(const ReadingListModel* model, | |
| 47 size_t index, | |
| 48 bool read) {} | |
| 49 | 73 |
| 50 // Invoked when elements are added to the read or the unread list. The new | |
| 51 // entries are always added at the beginning. these methods may be called | |
| 52 // multiple time (to process changes coming from a synchronization for | |
| 53 // example) and they will be executed in call order, the last call will end up | |
| 54 // in first position. | |
| 55 virtual void ReadingListWillAddUnreadEntry(const ReadingListModel* model, | 74 virtual void ReadingListWillAddUnreadEntry(const ReadingListModel* model, |
| 56 const ReadingListEntry& entry) {} | 75 const ReadingListEntry& entry) {} |
| 57 | 76 |
| 58 virtual void ReadingListWillAddReadEntry(const ReadingListModel* model, | 77 virtual void ReadingListWillAddReadEntry(const ReadingListModel* model, |
| 59 const ReadingListEntry& entry) {} | 78 const ReadingListEntry& entry) {} |
| 60 | 79 |
| 61 // Invoked when an entry is about to change. | |
| 62 virtual void ReadingListWillUpdateUnreadEntry(const ReadingListModel* model, | |
| 63 size_t index) {} | |
| 64 virtual void ReadingListWillUpdateReadEntry(const ReadingListModel* model, | |
| 65 size_t index) {} | |
| 66 | |
| 67 // Called after all the changes signaled by calls to the "Will" methods are | |
| 68 // done. All the "Will" methods are called as necessary, then the changes | |
| 69 // are applied and then this method is called. | |
| 70 virtual void ReadingListDidApplyChanges(ReadingListModel* model) {} | |
| 71 | |
| 72 protected: | 80 protected: |
| 73 ReadingListModelObserver() {} | 81 ReadingListModelObserver() {} |
| 74 virtual ~ReadingListModelObserver() {} | 82 virtual ~ReadingListModelObserver() {} |
| 75 | 83 |
| 76 DISALLOW_COPY_AND_ASSIGN(ReadingListModelObserver); | 84 DISALLOW_COPY_AND_ASSIGN(ReadingListModelObserver); |
| 77 }; | 85 }; |
| 78 | 86 |
| 79 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_OBSERVER_H_ | 87 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_OBSERVER_H_ |
| OLD | NEW |