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

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

Issue 2684973014: Only show Last N Pages in the UI when the corresponding tab is visible. (Closed)
Patch Set: Move impl out Created 3 years, 10 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // RequestCoordinator::Observer 110 // RequestCoordinator::Observer
107 void OnAdded(const SavePageRequest& request) override; 111 void OnAdded(const SavePageRequest& request) override;
108 void OnCompleted(const SavePageRequest& request, 112 void OnCompleted(const SavePageRequest& request,
109 RequestNotifier::BackgroundSavePageResult status) override; 113 RequestNotifier::BackgroundSavePageResult status) override;
110 void OnChanged(const SavePageRequest& request) override; 114 void OnChanged(const SavePageRequest& request) override;
111 115
112 // For the DownloadUIAdapter::Delegate, to report the temporary hidden status 116 // For the DownloadUIAdapter::Delegate, to report the temporary hidden status
113 // change. 117 // change.
114 void TemporaryHiddenStatusChanged(const ClientId& client_id); 118 void TemporaryHiddenStatusChanged(const ClientId& client_id);
115 119
120 Delegate* delegate() { return delegate_.get(); }
121
116 private: 122 private:
117 enum class State { NOT_LOADED, LOADING_PAGES, LOADING_REQUESTS, LOADED }; 123 enum class State { NOT_LOADED, LOADING_PAGES, LOADING_REQUESTS, LOADED };
118 124
119 struct ItemInfo { 125 struct ItemInfo {
120 explicit ItemInfo(const OfflinePageItem& page); 126 ItemInfo(const OfflinePageItem& page, bool temporarily_hidden);
121 explicit ItemInfo(const SavePageRequest& request); 127 ItemInfo(const SavePageRequest& request, bool temporarily_hidden);
122 ~ItemInfo(); 128 ~ItemInfo();
123 129
124 std::unique_ptr<DownloadUIItem> ui_item; 130 std::unique_ptr<DownloadUIItem> ui_item;
125 131
126 // Additional cached data, not exposed to UI through DownloadUIItem. 132 // Additional cached data, not exposed to UI through DownloadUIItem.
127 // Indicates if this item wraps the completed page or in-progress request. 133 // Indicates if this item wraps the completed page or in-progress request.
128 bool is_request; 134 bool is_request;
129 135
130 // These are shared between pages and requests. 136 // These are shared between pages and requests.
131 int64_t offline_id; 137 int64_t offline_id;
(...skipping 19 matching lines...) Expand all
151 void ClearCache(); 157 void ClearCache();
152 158
153 // Task callbacks. 159 // Task callbacks.
154 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages); 160 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages);
155 void OnRequestsLoaded(std::vector<std::unique_ptr<SavePageRequest>> requests); 161 void OnRequestsLoaded(std::vector<std::unique_ptr<SavePageRequest>> requests);
156 162
157 void NotifyItemsLoaded(Observer* observer); 163 void NotifyItemsLoaded(Observer* observer);
158 void OnDeletePagesDone(DeletePageResult result); 164 void OnDeletePagesDone(DeletePageResult result);
159 165
160 void AddItemHelper(std::unique_ptr<ItemInfo> item_info); 166 void AddItemHelper(std::unique_ptr<ItemInfo> item_info);
167 // This function is not re-entrant. It temporarily sets |deleting_item_|
168 // while it runs, so that functions such as |GetOfflineIdByGuid| will work
169 // during the |ItemDeleted| callback.
161 void DeleteItemHelper(const std::string& guid); 170 void DeleteItemHelper(const std::string& guid);
162 171
163 // Always valid, this class is a member of the model. 172 // Always valid, this class is a member of the model.
164 OfflinePageModel* model_; 173 OfflinePageModel* model_;
165 174
166 // Always valid, a service. 175 // Always valid, a service.
167 RequestCoordinator* request_coordinator_; 176 RequestCoordinator* request_coordinator_;
168 177
169 // A delegate, supplied at construction. 178 // A delegate, supplied at construction.
170 std::unique_ptr<Delegate> delegate_; 179 std::unique_ptr<Delegate> delegate_;
171 180
172 State state_; 181 State state_;
173 182
174 // The cache of UI items. The key is DownloadUIItem.guid. 183 // The cache of UI items. The key is DownloadUIItem.guid.
175 DownloadUIItems items_; 184 DownloadUIItems items_;
176 185
186 std::unique_ptr<ItemInfo> deleting_item_;
187
177 // The observers. 188 // The observers.
178 base::ObserverList<Observer> observers_; 189 base::ObserverList<Observer> observers_;
179 int observers_count_; 190 int observers_count_;
180 191
181 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_; 192 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_;
182 193
183 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter); 194 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter);
184 }; 195 };
185 196
186 } // namespace offline_pages 197 } // namespace offline_pages
187 198
188 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ 199 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698