summaryrefslogtreecommitdiff
path: root/chromium/components/offline_items_collection/core/offline_content_provider.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/offline_items_collection/core/offline_content_provider.h')
-rw-r--r--chromium/components/offline_items_collection/core/offline_content_provider.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/chromium/components/offline_items_collection/core/offline_content_provider.h b/chromium/components/offline_items_collection/core/offline_content_provider.h
new file mode 100644
index 00000000000..353a7bc2520
--- /dev/null
+++ b/chromium/components/offline_items_collection/core/offline_content_provider.h
@@ -0,0 +1,97 @@
+// 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_ITEMS_COLLETION_CORE_OFFLINE_CONTENT_PROVIDER_H_
+#define COMPONENTS_OFFLINE_ITEMS_COLLETION_CORE_OFFLINE_CONTENT_PROVIDER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "url/gurl.h"
+
+namespace offline_items_collection {
+
+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.
+ virtual const 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 scheduled
+ // on this observer (suggested over calling the method directly to avoid
+ // reentrancy).
+ 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_items_collection
+
+#endif // COMPONENTS_OFFLINE_ITEMS_COLLETION_CORE_OFFLINE_CONTENT_PROVIDER_H_