Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_OFFLINE_CONTENT_CORE_OFFLINE_CONTENT_PROVIDER_H_ | |
| 6 #define COMPONENTS_OFFLINE_CONTENT_CORE_OFFLINE_CONTENT_PROVIDER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "url/gurl.h" | |
| 13 | |
| 14 namespace offline_content { | |
| 15 | |
| 16 struct ContentId; | |
| 17 struct OfflineItem; | |
| 18 | |
| 19 // 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 | |
| 21 // underlying data set is initialized. Without that call it should not expect | |
| 22 // nor have to support any other calls to this provider. | |
| 23 class OfflineContentProvider { | |
| 24 public: | |
| 25 using OfflineItemList = std::vector<OfflineItem>; | |
| 26 | |
| 27 // An observer class that should be notified of relevant changes to the | |
| 28 // underlying data source. | |
| 29 class Observer { | |
| 30 public: | |
| 31 // Called when the underlying data source for the provider has been | |
| 32 // initialized and the contents are able to be queried and interacted with. | |
| 33 // |provider| should be a reference to this OfflineContentProvider that is | |
| 34 // initialized. | |
| 35 virtual void OnItemsAvailable(OfflineContentProvider* provider) = 0; | |
| 36 | |
| 37 // Called when one or more OfflineItems have been added and should be shown | |
| 38 // in the UI. | |
| 39 virtual void OnItemsAdded(const OfflineItemList& items) = 0; | |
| 40 | |
| 41 // Called when the OfflineItem represented by |id| should be removed from | |
| 42 // the UI. | |
| 43 virtual void OnItemRemoved(const ContentId& id) = 0; | |
| 44 | |
| 45 // Called when the contents of |item| have been updated and the UI should be | |
| 46 // refreshed for that item. | |
| 47 virtual void OnItemUpdated(const OfflineItem& item) = 0; | |
| 48 | |
| 49 protected: | |
| 50 virtual ~Observer() = default; | |
| 51 }; | |
| 52 | |
| 53 // Returns whether or not the underlying data source for this provider has | |
| 54 // been initialized and is ready to start returning content. This provider | |
| 55 // should not need to support handling the other data query/manipulation | |
| 56 // methods if this returns false. | |
| 57 virtual bool AreItemsAvailable() = 0; | |
| 58 | |
| 59 // Called to trigger opening an OfflineItem represented by |id|. | |
| 60 virtual void OpenItem(const ContentId& id) = 0; | |
| 61 | |
| 62 // Called to trigger removal of an OfflineItem represented by |id|. | |
| 63 virtual void RemoveItem(const ContentId& id) = 0; | |
| 64 | |
| 65 // Called to cancel a download of an OfflineItem represented by |id|. | |
| 66 virtual void CancelDownload(const ContentId& id) = 0; | |
| 67 | |
| 68 // Called to pause a download of an OfflineItem represented by |id|. | |
| 69 virtual void PauseDownload(const ContentId& id) = 0; | |
| 70 | |
| 71 // Called to resume a paused download of an OfflineItem represented by |id|. | |
| 72 virtual void ResumeDownload(const ContentId& id) = 0; | |
| 73 | |
| 74 // 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 | |
| 76 // of the function call. | |
|
fgorski
2017/02/14 22:17:55
should the caller be able to modify it?
once again
David Trainor- moved to gerrit
2017/02/22 01:23:12
Done. I think this will change as this thing gets
| |
| 77 virtual OfflineItem* GetItemById(const ContentId& id) = 0; | |
| 78 | |
| 79 // Returns all OfflineItems for this particular provider. | |
| 80 virtual OfflineItemList GetAllItems() = 0; | |
| 81 | |
| 82 // Adds an observer that should be notified of OfflineItem list modifications. | |
| 83 // If the provider is already initialized OnItemsAvailable should be called | |
| 84 // on this observer. | |
|
Dmitry Titov
2017/02/14 05:41:31
Maybe makes sense to say that in case of already i
David Trainor- moved to gerrit
2017/02/22 01:23:12
Agreed. I like that you did that in the DownloadU
| |
| 85 virtual void AddObserver(Observer* observer) = 0; | |
| 86 | |
| 87 // Removes an observer. No further notifications should be sent to it. | |
| 88 virtual void RemoveObserver(Observer* observer) = 0; | |
| 89 | |
| 90 protected: | |
| 91 virtual ~OfflineContentProvider() = default; | |
| 92 }; | |
| 93 | |
| 94 } // namespace offline_content | |
| 95 | |
| 96 #endif // COMPONENTS_OFFLINE_CONTENT_CORE_OFFLINE_CONTENT_PROVIDER_H_ | |
| OLD | NEW |