Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_OFFLINE_ITEMS_COLLETION_CORE_OFFLINE_CONTENT_PROVIDER_H_ | 5 #ifndef COMPONENTS_OFFLINE_ITEMS_COLLETION_CORE_OFFLINE_CONTENT_PROVIDER_H_ |
| 6 #define COMPONENTS_OFFLINE_ITEMS_COLLETION_CORE_OFFLINE_CONTENT_PROVIDER_H_ | 6 #define COMPONENTS_OFFLINE_ITEMS_COLLETION_CORE_OFFLINE_CONTENT_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 namespace offline_items_collection { | 15 namespace offline_items_collection { |
| 15 | 16 |
| 16 struct ContentId; | 17 struct ContentId; |
| 17 struct OfflineItem; | 18 struct OfflineItem; |
| 19 struct OfflineItemVisuals; | |
| 18 | 20 |
| 19 // A provider of a set of OfflineItems that are meant to be exposed to the UI. | 21 // A provider of a set of OfflineItems that are meant to be exposed to the UI. |
| 20 // The provider is required to notify all observers of OnItemsAvailable when the | 22 // The provider is required to notify all observers of OnItemsAvailable when the |
| 21 // underlying data set is initialized. Without that call it should not expect | 23 // underlying data set is initialized. Without that call it should not expect |
| 22 // nor have to support any other calls to this provider. | 24 // nor have to support any other calls to this provider. |
| 23 class OfflineContentProvider { | 25 class OfflineContentProvider { |
| 24 public: | 26 public: |
| 25 using OfflineItemList = std::vector<OfflineItem>; | 27 using OfflineItemList = std::vector<OfflineItem>; |
| 28 using VisualsCallback = | |
| 29 base::Callback<void(const ContentId&, const OfflineItemVisuals*)>; | |
| 26 | 30 |
| 27 // An observer class that should be notified of relevant changes to the | 31 // An observer class that should be notified of relevant changes to the |
| 28 // underlying data source. | 32 // underlying data source. |
| 29 class Observer { | 33 class Observer { |
| 30 public: | 34 public: |
| 31 // Called when the underlying data source for the provider has been | 35 // Called when the underlying data source for the provider has been |
| 32 // initialized and the contents are able to be queried and interacted with. | 36 // initialized and the contents are able to be queried and interacted with. |
| 33 // |provider| should be a reference to this OfflineContentProvider that is | 37 // |provider| should be a reference to this OfflineContentProvider that is |
| 34 // initialized. | 38 // initialized. |
| 35 virtual void OnItemsAvailable(OfflineContentProvider* provider) = 0; | 39 virtual void OnItemsAvailable(OfflineContentProvider* provider) = 0; |
| 36 | 40 |
| 37 // Called when one or more OfflineItems have been added and should be shown | 41 // Called when one or more OfflineItems have been added and should be shown |
| 38 // in the UI. | 42 // in the UI. |
| 39 virtual void OnItemsAdded(const OfflineItemList& items) = 0; | 43 virtual void OnItemsAdded(const OfflineItemList& items) = 0; |
| 40 | 44 |
| 41 // Called when the OfflineItem represented by |id| should be removed from | 45 // Called when the OfflineItem represented by |id| should be removed from |
| 42 // the UI. | 46 // the UI. |
| 43 virtual void OnItemRemoved(const ContentId& id) = 0; | 47 virtual void OnItemRemoved(const ContentId& id) = 0; |
| 44 | 48 |
| 45 // Called when the contents of |item| have been updated and the UI should be | 49 // Called when the contents of |item| have been updated and the UI should be |
| 46 // refreshed for that item. | 50 // refreshed for that item. |
| 51 // TODO(dtrainor): Make this take a list of OfflineItems. | |
| 47 virtual void OnItemUpdated(const OfflineItem& item) = 0; | 52 virtual void OnItemUpdated(const OfflineItem& item) = 0; |
| 48 | 53 |
| 49 protected: | 54 protected: |
| 50 virtual ~Observer() = default; | 55 virtual ~Observer() = default; |
| 51 }; | 56 }; |
| 52 | 57 |
| 53 // Returns whether or not the underlying data source for this provider has | 58 // Returns whether or not the underlying data source for this provider has |
| 54 // been initialized and is ready to start returning content. This provider | 59 // been initialized and is ready to start returning content. This provider |
| 55 // should not need to support handling the other data query/manipulation | 60 // should not need to support handling the other data query/manipulation |
| 56 // methods if this returns false. | 61 // methods if this returns false. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 72 virtual void ResumeDownload(const ContentId& id) = 0; | 77 virtual void ResumeDownload(const ContentId& id) = 0; |
| 73 | 78 |
| 74 // Returns an OfflineItem represented by |id| or |nullptr| if none exists. | 79 // Returns an OfflineItem represented by |id| or |nullptr| if none exists. |
| 75 // The caller should not hold ownership of the returned item beyond the scope | 80 // The caller should not hold ownership of the returned item beyond the scope |
| 76 // of the function call. | 81 // of the function call. |
| 77 virtual const OfflineItem* GetItemById(const ContentId& id) = 0; | 82 virtual const OfflineItem* GetItemById(const ContentId& id) = 0; |
| 78 | 83 |
| 79 // Returns all OfflineItems for this particular provider. | 84 // Returns all OfflineItems for this particular provider. |
| 80 virtual OfflineItemList GetAllItems() = 0; | 85 virtual OfflineItemList GetAllItems() = 0; |
| 81 | 86 |
| 87 // Asks for an OfflineItemVisuals struct for an OfflineItem represented by | |
| 88 // |id| or |nullptr| if one doesn't exist. The caller should post any | |
|
nyquist
2017/04/13 05:08:25
The "caller"? Do you mean the implementor of the i
David Trainor- moved to gerrit
2017/04/13 07:20:23
Ah yeah sorry thanks!
| |
| 89 // replies even if the results are available immediately to prevent reentrancy | |
| 90 // and for consistent behavior. | |
| 91 virtual void GetVisualsForItem(const ContentId& id, | |
| 92 const VisualsCallback& callback) = 0; | |
| 93 | |
| 82 // Adds an observer that should be notified of OfflineItem list modifications. | 94 // Adds an observer that should be notified of OfflineItem list modifications. |
| 83 // If the provider is already initialized OnItemsAvailable should be scheduled | 95 // If the provider is already initialized OnItemsAvailable should be scheduled |
| 84 // on this observer (suggested over calling the method directly to avoid | 96 // on this observer (suggested over calling the method directly to avoid |
| 85 // reentrancy). | 97 // reentrancy). |
| 86 virtual void AddObserver(Observer* observer) = 0; | 98 virtual void AddObserver(Observer* observer) = 0; |
| 87 | 99 |
| 88 // Removes an observer. No further notifications should be sent to it. | 100 // Removes an observer. No further notifications should be sent to it. |
| 89 virtual void RemoveObserver(Observer* observer) = 0; | 101 virtual void RemoveObserver(Observer* observer) = 0; |
| 90 | 102 |
| 91 protected: | 103 protected: |
| 92 virtual ~OfflineContentProvider() = default; | 104 virtual ~OfflineContentProvider() = default; |
| 93 }; | 105 }; |
| 94 | 106 |
| 95 } // namespace offline_items_collection | 107 } // namespace offline_items_collection |
| 96 | 108 |
| 97 #endif // COMPONENTS_OFFLINE_ITEMS_COLLETION_CORE_OFFLINE_CONTENT_PROVIDER_H_ | 109 #endif // COMPONENTS_OFFLINE_ITEMS_COLLETION_CORE_OFFLINE_CONTENT_PROVIDER_H_ |
| OLD | NEW |