Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: components/offline_pages/downloads/download_ui_adapter.h

Issue 2221293002: Implement deleteItem and openItem on OfflinePageDownloadBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/downloads/download_ui_adapter.h
diff --git a/components/offline_pages/downloads/download_ui_adapter.h b/components/offline_pages/downloads/download_ui_adapter.h
index d96f11d7da757836ac0aee7a2cfc360b2a58b5e3..124ab4bb6d615c3c465403ebe25bdbe37cbb381a 100644
--- a/components/offline_pages/downloads/download_ui_adapter.h
+++ b/components/offline_pages/downloads/download_ui_adapter.h
@@ -14,13 +14,9 @@
#include "components/offline_pages/downloads/download_ui_item.h"
#include "components/offline_pages/offline_page_model.h"
#include "components/offline_pages/offline_page_types.h"
+#include "url/gurl.h"
namespace offline_pages {
-
-// Key is DownloadUIItem.guid.
-typedef
- std::map<std::string, std::unique_ptr<DownloadUIItem>> DownloadUIItemsMap;
-
// C++ side of the UI Adapter. Mimics DownloadManager/Item/History (since we
// share UI with Downloads).
// An instance of this class is owned by OfflinePageModel and is shared between
@@ -66,10 +62,17 @@ class DownloadUIAdapter : public OfflinePageModel::Observer,
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
- const DownloadUIItemsMap& GetAllItems() const;
- // May return nullptr.
+ // Returns all UI items. The list contains references to items in the cache
+ // and has to be used synchronously.
+ std::vector<const DownloadUIItem*> GetAllItems() const;
+ // May return nullptr if item with specified guid does not exist.
const DownloadUIItem* GetItem(const std::string& guid) const;
+ // Commands from UI. Start async operations, result is observable
+ // via Observer or directly by the user (as in 'open').
+ void DeleteItem(const std::string& guid);
+ std::string GetOfflineUrlByGuid(const std::string& guid) const;
+
// OfflinePageModel::Observer
void OfflinePageModelLoaded(OfflinePageModel* model) override;
void OfflinePageModelChanged(OfflinePageModel* model) override;
@@ -77,6 +80,18 @@ class DownloadUIAdapter : public OfflinePageModel::Observer,
const ClientId& client_id) override;
private:
+ struct ItemInfo {
+ ItemInfo(const OfflinePageItem& page);
+ ~ItemInfo();
fgorski 2016/08/12 15:43:52 = default; would probably do here.
Dmitry Titov 2016/08/12 19:43:37 Apparently, the 'complex types must have non-inlin
+
+ std::unique_ptr<DownloadUIItem> ui_item;
fgorski 2016/08/12 15:43:52 do we need to do anything about copying of these o
Dmitry Titov 2016/08/12 19:43:37 Done.
+ // Additional cached data, not exposed to UI through DownloadUIItem.
+ int64_t offline_id;
+ GURL offline_url;
+ };
+
+ typedef std::map<std::string, std::unique_ptr<ItemInfo>> DownloadUIItems;
+
void LoadCache();
void ClearCache();
@@ -84,6 +99,8 @@ class DownloadUIAdapter : public OfflinePageModel::Observer,
void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages);
void NotifyItemsLoaded(Observer* observer);
void OnOfflinePagesChanged(const MultipleOfflinePageItemResult& pages);
+ void OnDeletePagesDone(DeletePageResult result);
+
bool IsVisibleInUI(const OfflinePageItem& page);
// Always valid, this class is a member of the model.
@@ -91,8 +108,8 @@ class DownloadUIAdapter : public OfflinePageModel::Observer,
bool is_loaded_;
- // The cache of UI items.
- DownloadUIItemsMap items_;
+ // The cache of UI items. The key is DownloadUIItem.guid.
+ DownloadUIItems items_;
// The observers.
base::ObserverList<Observer> observers_;

Powered by Google App Engine
This is Rietveld 408576698