Chromium Code Reviews| Index: components/offline_content/core/offline_content_provider.h |
| diff --git a/components/offline_content/core/offline_content_provider.h b/components/offline_content/core/offline_content_provider.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7a485cd0b197658a57110e16bf3341e0bd129a6b |
| --- /dev/null |
| +++ b/components/offline_content/core/offline_content_provider.h |
| @@ -0,0 +1,96 @@ |
| +// 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 COMPONENTS_OFFLINE_CONTENT_CORE_OFFLINE_CONTENT_PROVIDER_H_ |
| +#define COMPONENTS_OFFLINE_CONTENT_CORE_OFFLINE_CONTENT_PROVIDER_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "url/gurl.h" |
| + |
| +namespace offline_content { |
| + |
| +struct ContentId; |
| +struct OfflineItem; |
| + |
| +// A provider of a set of OfflineItems that are meant to be exposed to the UI. |
| +// The provider is required to notify all observers of OnItemsAvailable when the |
| +// underlying data set is initialized. Without that call it should not expect |
| +// nor have to support any other calls to this provider. |
| +class OfflineContentProvider { |
| + public: |
| + using OfflineItemList = std::vector<OfflineItem>; |
| + |
| + // An observer class that should be notified of relevant changes to the |
| + // underlying data source. |
| + class Observer { |
| + public: |
| + // Called when the underlying data source for the provider has been |
| + // initialized and the contents are able to be queried and interacted with. |
| + // |provider| should be a reference to this OfflineContentProvider that is |
| + // initialized. |
| + virtual void OnItemsAvailable(OfflineContentProvider* provider) = 0; |
| + |
| + // Called when one or more OfflineItems have been added and should be shown |
| + // in the UI. |
| + virtual void OnItemsAdded(const OfflineItemList& items) = 0; |
| + |
| + // Called when the OfflineItem represented by |id| should be removed from |
| + // the UI. |
| + virtual void OnItemRemoved(const ContentId& id) = 0; |
| + |
| + // Called when the contents of |item| have been updated and the UI should be |
| + // refreshed for that item. |
| + virtual void OnItemUpdated(const OfflineItem& item) = 0; |
| + |
| + protected: |
| + virtual ~Observer() = default; |
| + }; |
| + |
| + // Returns whether or not the underlying data source for this provider has |
| + // been initialized and is ready to start returning content. This provider |
| + // should not need to support handling the other data query/manipulation |
| + // methods if this returns false. |
| + virtual bool AreItemsAvailable() = 0; |
| + |
| + // Called to trigger opening an OfflineItem represented by |id|. |
| + virtual void OpenItem(const ContentId& id) = 0; |
| + |
| + // Called to trigger removal of an OfflineItem represented by |id|. |
| + virtual void RemoveItem(const ContentId& id) = 0; |
| + |
| + // Called to cancel a download of an OfflineItem represented by |id|. |
| + virtual void CancelDownload(const ContentId& id) = 0; |
| + |
| + // Called to pause a download of an OfflineItem represented by |id|. |
| + virtual void PauseDownload(const ContentId& id) = 0; |
| + |
| + // Called to resume a paused download of an OfflineItem represented by |id|. |
| + virtual void ResumeDownload(const ContentId& id) = 0; |
| + |
| + // Returns an OfflineItem represented by |id| or |nullptr| if none exists. |
| + // The caller should not hold ownership of the returned item beyond the scope |
| + // 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
|
| + virtual OfflineItem* GetItemById(const ContentId& id) = 0; |
| + |
| + // Returns all OfflineItems for this particular provider. |
| + virtual OfflineItemList GetAllItems() = 0; |
| + |
| + // Adds an observer that should be notified of OfflineItem list modifications. |
| + // If the provider is already initialized OnItemsAvailable should be called |
| + // 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
|
| + virtual void AddObserver(Observer* observer) = 0; |
| + |
| + // Removes an observer. No further notifications should be sent to it. |
| + virtual void RemoveObserver(Observer* observer) = 0; |
| + |
| + protected: |
| + virtual ~OfflineContentProvider() = default; |
| +}; |
| + |
| +} // namespace offline_content |
| + |
| +#endif // COMPONENTS_OFFLINE_CONTENT_CORE_OFFLINE_CONTENT_PROVIDER_H_ |