| 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_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ | 6 #define COMPONENTS_OFFLINE_PAGE_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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 void DeleteItem(const std::string& guid); | 74 void DeleteItem(const std::string& guid); |
| 75 GURL GetOfflineUrlByGuid(const std::string& guid) const; | 75 GURL GetOfflineUrlByGuid(const std::string& guid) const; |
| 76 | 76 |
| 77 // OfflinePageModel::Observer | 77 // OfflinePageModel::Observer |
| 78 void OfflinePageModelLoaded(OfflinePageModel* model) override; | 78 void OfflinePageModelLoaded(OfflinePageModel* model) override; |
| 79 void OfflinePageModelChanged(OfflinePageModel* model) override; | 79 void OfflinePageModelChanged(OfflinePageModel* model) override; |
| 80 void OfflinePageDeleted(int64_t offline_id, | 80 void OfflinePageDeleted(int64_t offline_id, |
| 81 const ClientId& client_id) override; | 81 const ClientId& client_id) override; |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 enum class State { |
| 85 NOT_LOADED, |
| 86 LOADING, |
| 87 LOADED |
| 88 }; |
| 89 |
| 84 struct ItemInfo { | 90 struct ItemInfo { |
| 85 explicit ItemInfo(const OfflinePageItem& page); | 91 explicit ItemInfo(const OfflinePageItem& page); |
| 86 ~ItemInfo(); | 92 ~ItemInfo(); |
| 87 | 93 |
| 88 std::unique_ptr<DownloadUIItem> ui_item; | 94 std::unique_ptr<DownloadUIItem> ui_item; |
| 89 // Additional cached data, not exposed to UI through DownloadUIItem. | 95 // Additional cached data, not exposed to UI through DownloadUIItem. |
| 90 int64_t offline_id; | 96 int64_t offline_id; |
| 91 GURL offline_url; | 97 GURL offline_url; |
| 92 | 98 |
| 93 private: | 99 private: |
| 94 DISALLOW_COPY_AND_ASSIGN(ItemInfo); | 100 DISALLOW_COPY_AND_ASSIGN(ItemInfo); |
| 95 }; | 101 }; |
| 96 | 102 |
| 97 typedef std::map<std::string, std::unique_ptr<ItemInfo>> DownloadUIItems; | 103 typedef std::map<std::string, std::unique_ptr<ItemInfo>> DownloadUIItems; |
| 98 | 104 |
| 99 void LoadCache(); | 105 void LoadCache(); |
| 100 void ClearCache(); | 106 void ClearCache(); |
| 101 | 107 |
| 102 // Task callbacks. | 108 // Task callbacks. |
| 103 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages); | 109 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages); |
| 104 void NotifyItemsLoaded(Observer* observer); | 110 void NotifyItemsLoaded(Observer* observer); |
| 105 void OnOfflinePagesChanged(const MultipleOfflinePageItemResult& pages); | 111 void OnOfflinePagesChanged(const MultipleOfflinePageItemResult& pages); |
| 106 void OnDeletePagesDone(DeletePageResult result); | 112 void OnDeletePagesDone(DeletePageResult result); |
| 107 | 113 |
| 108 bool IsVisibleInUI(const ClientId& page); | 114 bool IsVisibleInUI(const ClientId& page); |
| 109 | 115 |
| 110 // Always valid, this class is a member of the model. | 116 // Always valid, this class is a member of the model. |
| 111 OfflinePageModel* model_; | 117 OfflinePageModel* model_; |
| 112 | 118 |
| 113 bool is_loaded_; | 119 State state_; |
| 114 | 120 |
| 115 // The cache of UI items. The key is DownloadUIItem.guid. | 121 // The cache of UI items. The key is DownloadUIItem.guid. |
| 116 DownloadUIItems items_; | 122 DownloadUIItems items_; |
| 117 | 123 |
| 118 // The observers. | 124 // The observers. |
| 119 base::ObserverList<Observer> observers_; | 125 base::ObserverList<Observer> observers_; |
| 126 int observers_count_; |
| 120 | 127 |
| 121 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_; | 128 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_; |
| 122 | 129 |
| 123 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter); | 130 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter); |
| 124 }; | 131 }; |
| 125 | 132 |
| 126 } // namespace offline_pages | 133 } // namespace offline_pages |
| 127 | 134 |
| 128 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ | 135 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ |
| OLD | NEW |