Index: components/offline_pages/core/downloads/download_ui_adapter.h |
diff --git a/components/offline_pages/core/downloads/download_ui_adapter.h b/components/offline_pages/core/downloads/download_ui_adapter.h |
index 7ab6ace92d198f4a6413b215be6d686a0b309bc3..ccf22793e9907ecea9118008c7d8f7f9be271f79 100644 |
--- a/components/offline_pages/core/downloads/download_ui_adapter.h |
+++ b/components/offline_pages/core/downloads/download_ui_adapter.h |
@@ -12,6 +12,7 @@ |
#include "base/observer_list.h" |
#include "base/supports_user_data.h" |
+#include "components/offline_pages/core/background/request_coordinator.h" |
#include "components/offline_pages/core/downloads/download_ui_item.h" |
#include "components/offline_pages/core/offline_page_model.h" |
#include "components/offline_pages/core/offline_page_types.h" |
@@ -25,8 +26,19 @@ namespace offline_pages { |
// initial load the UI components can synchronously pull the whoel list or any |
// item by its guid. |
class DownloadUIAdapter : public OfflinePageModel::Observer, |
+ public RequestCoordinator::Observer, |
public base::SupportsUserData::Data { |
public: |
+ // Delegate, used to customize behavior of this Adapter. |
+ class Delegate { |
+ public: |
+ virtual ~Delegate() = default; |
+ // Returns true if the page or request with the specified Client Id should |
+ // be visible in the collection of items exposed by this Adapter. This also |
+ // indicates if Observers will be notified about changes for the given page. |
+ virtual bool IsVisibleInUI(const ClientId& client_id) = 0; |
dewittj
2017/01/18 18:49:48
Eventually I will need a way to ask the DownloadUI
Dmitry Titov
2017/01/27 04:30:22
Done.
|
+ }; |
+ |
// Observer, normally implemented by UI or a Bridge. |
class Observer { |
public: |
@@ -50,17 +62,12 @@ class DownloadUIAdapter : public OfflinePageModel::Observer, |
virtual ~Observer() = default; |
}; |
- explicit DownloadUIAdapter(OfflinePageModel* model); |
+ explicit DownloadUIAdapter(OfflinePageModel* model, |
+ RequestCoordinator* coordinator, |
+ std::unique_ptr<Delegate> delegate); |
~DownloadUIAdapter() override; |
- static DownloadUIAdapter* FromOfflinePageModel( |
- OfflinePageModel* offline_page_model); |
- |
- // Checks a client ID for proper namespace and ID format to be shown in the |
- // Downloads Home UI. |
- bool IsVisibleInUI(const ClientId& page); |
- |
- // This adapter is potentially shared by UI elements, each of which adds |
+ // This adapter is potentially shared by UI elements, each of which adds |
// itself as an observer. |
// When the last observer si removed, cached list of items is destroyed and |
// next time the initial loading will take longer. |
@@ -85,15 +92,32 @@ class DownloadUIAdapter : public OfflinePageModel::Observer, |
void OfflinePageDeleted(int64_t offline_id, |
const ClientId& client_id) override; |
+ // RequestCoordinator::Observer |
+ void OnAdded(const SavePageRequest& request) override; |
+ void OnCompleted(const SavePageRequest& request, |
+ RequestNotifier::BackgroundSavePageResult status) override; |
+ void OnChanged(const SavePageRequest& request) override; |
+ |
private: |
- enum class State { NOT_LOADED, LOADING, LOADED }; |
+ enum class State { |
+ NOT_LOADED, |
+ LOADING_PAGES, |
+ LOADING_REQUESTS, |
+ LOADED |
+ }; |
struct ItemInfo { |
explicit ItemInfo(const OfflinePageItem& page); |
+ explicit ItemInfo(const SavePageRequest& request); |
~ItemInfo(); |
std::unique_ptr<DownloadUIItem> ui_item; |
+ |
// Additional cached data, not exposed to UI through DownloadUIItem. |
+ // Indicates if this item wraps the completed page or in-progress request. |
+ bool is_request; |
+ |
+ // These are shared between pages and requests. |
int64_t offline_id; |
private: |
@@ -107,12 +131,23 @@ class DownloadUIAdapter : public OfflinePageModel::Observer, |
// Task callbacks. |
void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages); |
+ void OnRequestsLoaded(std::vector<std::unique_ptr<SavePageRequest>> requests); |
+ |
void NotifyItemsLoaded(Observer* observer); |
void OnDeletePagesDone(DeletePageResult result); |
+ void addItemHelper(std::unique_ptr<ItemInfo> item_info); |
dewittj
2017/01/18 18:49:48
nit: capital A, also next line.
Dmitry Titov
2017/01/27 04:30:22
Done.
|
+ void deleteItemHelper(const std::string& guid); |
+ |
// Always valid, this class is a member of the model. |
OfflinePageModel* model_; |
+ // Always valid, a service. |
Pete Williamson
2017/01/17 18:27:34
Should we note that this pointer is unowned?
Dmitry Titov
2017/01/27 04:30:23
It is a raw pointer, so unowned... The comment say
|
+ RequestCoordinator* request_coordinator_; |
+ |
+ // A delegate, supplied at construction. |
+ std::unique_ptr<Delegate> delegate_; |
+ |
State state_; |
// The cache of UI items. The key is DownloadUIItem.guid. |