Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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> |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 // RequestCoordinator::Observer | 106 // RequestCoordinator::Observer |
| 107 void OnAdded(const SavePageRequest& request) override; | 107 void OnAdded(const SavePageRequest& request) override; |
| 108 void OnCompleted(const SavePageRequest& request, | 108 void OnCompleted(const SavePageRequest& request, |
| 109 RequestNotifier::BackgroundSavePageResult status) override; | 109 RequestNotifier::BackgroundSavePageResult status) override; |
| 110 void OnChanged(const SavePageRequest& request) override; | 110 void OnChanged(const SavePageRequest& request) override; |
| 111 | 111 |
| 112 // For the DownloadUIAdapter::Delegate, to report the temporary hidden status | 112 // For the DownloadUIAdapter::Delegate, to report the temporary hidden status |
| 113 // change. | 113 // change. |
| 114 void TemporaryHiddenStatusChanged(const ClientId& client_id); | 114 void TemporaryHiddenStatusChanged(const ClientId& client_id); |
| 115 | 115 |
| 116 Delegate* delegate() { return delegate_.get(); } | |
| 117 | |
| 116 private: | 118 private: |
| 117 enum class State { NOT_LOADED, LOADING_PAGES, LOADING_REQUESTS, LOADED }; | 119 enum class State { NOT_LOADED, LOADING_PAGES, LOADING_REQUESTS, LOADED }; |
| 118 | 120 |
| 119 struct ItemInfo { | 121 struct ItemInfo { |
| 120 explicit ItemInfo(const OfflinePageItem& page); | 122 ItemInfo(Delegate* delegate, const OfflinePageItem& page); |
|
Dmitry Titov
2017/02/14 23:01:03
It'd be nice to avoid passing a delegate simply to
dewittj
2017/02/15 19:49:45
Done.
| |
| 121 explicit ItemInfo(const SavePageRequest& request); | 123 ItemInfo(Delegate* delegate, const SavePageRequest& request); |
| 122 ~ItemInfo(); | 124 ~ItemInfo(); |
| 123 | 125 |
| 124 std::unique_ptr<DownloadUIItem> ui_item; | 126 std::unique_ptr<DownloadUIItem> ui_item; |
| 125 | 127 |
| 126 // Additional cached data, not exposed to UI through DownloadUIItem. | 128 // Additional cached data, not exposed to UI through DownloadUIItem. |
| 127 // Indicates if this item wraps the completed page or in-progress request. | 129 // Indicates if this item wraps the completed page or in-progress request. |
| 128 bool is_request; | 130 bool is_request; |
| 129 | 131 |
| 130 // These are shared between pages and requests. | 132 // These are shared between pages and requests. |
| 131 int64_t offline_id; | 133 int64_t offline_id; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 151 void ClearCache(); | 153 void ClearCache(); |
| 152 | 154 |
| 153 // Task callbacks. | 155 // Task callbacks. |
| 154 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages); | 156 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages); |
| 155 void OnRequestsLoaded(std::vector<std::unique_ptr<SavePageRequest>> requests); | 157 void OnRequestsLoaded(std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 156 | 158 |
| 157 void NotifyItemsLoaded(Observer* observer); | 159 void NotifyItemsLoaded(Observer* observer); |
| 158 void OnDeletePagesDone(DeletePageResult result); | 160 void OnDeletePagesDone(DeletePageResult result); |
| 159 | 161 |
| 160 void AddItemHelper(std::unique_ptr<ItemInfo> item_info); | 162 void AddItemHelper(std::unique_ptr<ItemInfo> item_info); |
| 163 // This function is not re-entrant. It temporarily sets |deleting_item_| | |
| 164 // while it runs, so that functions such as |GetOfflineIdByGuid| will work | |
| 165 // during the |ItemDeleted| callback. | |
| 161 void DeleteItemHelper(const std::string& guid); | 166 void DeleteItemHelper(const std::string& guid); |
| 162 | 167 |
| 163 // Always valid, this class is a member of the model. | 168 // Always valid, this class is a member of the model. |
| 164 OfflinePageModel* model_; | 169 OfflinePageModel* model_; |
| 165 | 170 |
| 166 // Always valid, a service. | 171 // Always valid, a service. |
| 167 RequestCoordinator* request_coordinator_; | 172 RequestCoordinator* request_coordinator_; |
| 168 | 173 |
| 169 // A delegate, supplied at construction. | 174 // A delegate, supplied at construction. |
| 170 std::unique_ptr<Delegate> delegate_; | 175 std::unique_ptr<Delegate> delegate_; |
| 171 | 176 |
| 172 State state_; | 177 State state_; |
| 173 | 178 |
| 174 // The cache of UI items. The key is DownloadUIItem.guid. | 179 // The cache of UI items. The key is DownloadUIItem.guid. |
| 175 DownloadUIItems items_; | 180 DownloadUIItems items_; |
| 176 | 181 |
| 182 std::unique_ptr<ItemInfo> deleting_item_; | |
| 183 | |
| 177 // The observers. | 184 // The observers. |
| 178 base::ObserverList<Observer> observers_; | 185 base::ObserverList<Observer> observers_; |
| 179 int observers_count_; | 186 int observers_count_; |
| 180 | 187 |
| 181 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_; | 188 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_; |
| 182 | 189 |
| 183 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter); | 190 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter); |
| 184 }; | 191 }; |
| 185 | 192 |
| 186 } // namespace offline_pages | 193 } // namespace offline_pages |
| 187 | 194 |
| 188 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ | 195 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ |
| OLD | NEW |