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

Side by Side Diff: components/offline_pages/core/downloads/download_ui_adapter.h

Issue 2706343007: Only show Last N Pages in the UI when the corresponding tab is visible. (cont'd) (Closed)
Patch Set: Rebase. Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_
6 #define COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ 6 #define COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
(...skipping 29 matching lines...) Expand all
41 // Returns true if the page or request with the specified Client Id should 41 // Returns true if the page or request with the specified Client Id should
42 // be visible in the collection of items exposed by this Adapter. This also 42 // be visible in the collection of items exposed by this Adapter. This also
43 // indicates if Observers will be notified about changes for the given page. 43 // indicates if Observers will be notified about changes for the given page.
44 virtual bool IsVisibleInUI(const ClientId& client_id) = 0; 44 virtual bool IsVisibleInUI(const ClientId& client_id) = 0;
45 // Sometimes the item should be in the collection but not visible in the UI, 45 // Sometimes the item should be in the collection but not visible in the UI,
46 // temporarily. This is a relatively special case, for example for Last_N 46 // temporarily. This is a relatively special case, for example for Last_N
47 // snapshots that are only valid while their tab is alive. When the status 47 // snapshots that are only valid while their tab is alive. When the status
48 // of temporary visibility changes, the Delegate is supposed to call 48 // of temporary visibility changes, the Delegate is supposed to call
49 // DownloadUIAdapter::TemporarilyHiddenStatusChanged(). 49 // DownloadUIAdapter::TemporarilyHiddenStatusChanged().
50 virtual bool IsTemporarilyHiddenInUI(const ClientId& client_id) = 0; 50 virtual bool IsTemporarilyHiddenInUI(const ClientId& client_id) = 0;
51
52 // Delegates need a reference to the UI adapter in order to notify it about
53 // visibility changes.
54 virtual void SetUIAdapter(DownloadUIAdapter* ui_adapter) = 0;
51 }; 55 };
52 56
53 // Observer, normally implemented by UI or a Bridge. 57 // Observer, normally implemented by UI or a Bridge.
54 class Observer { 58 class Observer {
55 public: 59 public:
56 // Invoked when UI items are loaded. GetAllItems/GetItem can now be used. 60 // Invoked when UI items are loaded. GetAllItems/GetItem can now be used.
57 // Must be listened for in order to start getting the items. 61 // Must be listened for in order to start getting the items.
58 // If the items are already loaded by the time observer is added, this 62 // If the items are already loaded by the time observer is added, this
59 // callback will be posted right away. 63 // callback will be posted right away.
60 virtual void ItemsLoaded() = 0; 64 virtual void ItemsLoaded() = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // RequestCoordinator::Observer 115 // RequestCoordinator::Observer
112 void OnAdded(const SavePageRequest& request) override; 116 void OnAdded(const SavePageRequest& request) override;
113 void OnCompleted(const SavePageRequest& request, 117 void OnCompleted(const SavePageRequest& request,
114 RequestNotifier::BackgroundSavePageResult status) override; 118 RequestNotifier::BackgroundSavePageResult status) override;
115 void OnChanged(const SavePageRequest& request) override; 119 void OnChanged(const SavePageRequest& request) override;
116 120
117 // For the DownloadUIAdapter::Delegate, to report the temporary hidden status 121 // For the DownloadUIAdapter::Delegate, to report the temporary hidden status
118 // change. 122 // change.
119 void TemporaryHiddenStatusChanged(const ClientId& client_id); 123 void TemporaryHiddenStatusChanged(const ClientId& client_id);
120 124
125 Delegate* delegate() { return delegate_.get(); }
126
121 private: 127 private:
122 enum class State { NOT_LOADED, LOADING_PAGES, LOADING_REQUESTS, LOADED }; 128 enum class State { NOT_LOADED, LOADING_PAGES, LOADING_REQUESTS, LOADED };
123 129
124 struct ItemInfo { 130 struct ItemInfo {
125 explicit ItemInfo(const OfflinePageItem& page); 131 ItemInfo(const OfflinePageItem& page, bool temporarily_hidden);
126 explicit ItemInfo(const SavePageRequest& request); 132 ItemInfo(const SavePageRequest& request, bool temporarily_hidden);
127 ~ItemInfo(); 133 ~ItemInfo();
128 134
129 std::unique_ptr<DownloadUIItem> ui_item; 135 std::unique_ptr<DownloadUIItem> ui_item;
130 136
131 // Additional cached data, not exposed to UI through DownloadUIItem. 137 // Additional cached data, not exposed to UI through DownloadUIItem.
132 // Indicates if this item wraps the completed page or in-progress request. 138 // Indicates if this item wraps the completed page or in-progress request.
133 bool is_request; 139 bool is_request;
134 140
135 // These are shared between pages and requests. 141 // These are shared between pages and requests.
136 int64_t offline_id; 142 int64_t offline_id;
(...skipping 19 matching lines...) Expand all
156 void ClearCache(); 162 void ClearCache();
157 163
158 // Task callbacks. 164 // Task callbacks.
159 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages); 165 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages);
160 void OnRequestsLoaded(std::vector<std::unique_ptr<SavePageRequest>> requests); 166 void OnRequestsLoaded(std::vector<std::unique_ptr<SavePageRequest>> requests);
161 167
162 void NotifyItemsLoaded(Observer* observer); 168 void NotifyItemsLoaded(Observer* observer);
163 void OnDeletePagesDone(DeletePageResult result); 169 void OnDeletePagesDone(DeletePageResult result);
164 170
165 void AddItemHelper(std::unique_ptr<ItemInfo> item_info); 171 void AddItemHelper(std::unique_ptr<ItemInfo> item_info);
172 // This function is not re-entrant. It temporarily sets |deleting_item_|
173 // while it runs, so that functions such as |GetOfflineIdByGuid| will work
174 // during the |ItemDeleted| callback.
166 void DeleteItemHelper(const std::string& guid); 175 void DeleteItemHelper(const std::string& guid);
167 176
168 // Always valid, this class is a member of the model. 177 // Always valid, this class is a member of the model.
169 OfflinePageModel* model_; 178 OfflinePageModel* model_;
170 179
171 // Always valid, a service. 180 // Always valid, a service.
172 RequestCoordinator* request_coordinator_; 181 RequestCoordinator* request_coordinator_;
173 182
174 // A delegate, supplied at construction. 183 // A delegate, supplied at construction.
175 std::unique_ptr<Delegate> delegate_; 184 std::unique_ptr<Delegate> delegate_;
176 185
177 State state_; 186 State state_;
178 187
179 // The cache of UI items. The key is DownloadUIItem.guid. 188 // The cache of UI items. The key is DownloadUIItem.guid.
180 DownloadUIItems items_; 189 DownloadUIItems items_;
181 190
191 std::unique_ptr<ItemInfo> deleting_item_;
192
182 // The observers. 193 // The observers.
183 base::ObserverList<Observer> observers_; 194 base::ObserverList<Observer> observers_;
184 int observers_count_; 195 int observers_count_;
185 196
186 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_; 197 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_;
187 198
188 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter); 199 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter);
189 }; 200 };
190 201
191 } // namespace offline_pages 202 } // namespace offline_pages
192 203
193 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ 204 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_
OLDNEW
« no previous file with comments | « components/offline_pages/core/BUILD.gn ('k') | components/offline_pages/core/downloads/download_ui_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698