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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 protected: | 49 protected: |
50 virtual ~Observer() = default; | 50 virtual ~Observer() = default; |
51 }; | 51 }; |
52 | 52 |
53 explicit DownloadUIAdapter(OfflinePageModel* model); | 53 explicit DownloadUIAdapter(OfflinePageModel* model); |
54 ~DownloadUIAdapter() override; | 54 ~DownloadUIAdapter() override; |
55 | 55 |
56 static DownloadUIAdapter* FromOfflinePageModel( | 56 static DownloadUIAdapter* FromOfflinePageModel( |
57 OfflinePageModel* offline_page_model); | 57 OfflinePageModel* offline_page_model); |
58 | 58 |
| 59 // Checks a client ID for proper namespace and ID format to be shown in the |
| 60 // Downloads Home UI. |
| 61 static bool IsVisibleInUI(const ClientId& page); |
| 62 |
59 // This adapter is potentially shared by UI elements, each of which adds | 63 // This adapter is potentially shared by UI elements, each of which adds |
60 // itself as an observer. | 64 // itself as an observer. |
61 // When the last observer si removed, cached list of items is destroyed and | 65 // When the last observer si removed, cached list of items is destroyed and |
62 // next time the initial loading will take longer. | 66 // next time the initial loading will take longer. |
63 void AddObserver(Observer* observer); | 67 void AddObserver(Observer* observer); |
64 void RemoveObserver(Observer* observer); | 68 void RemoveObserver(Observer* observer); |
65 | 69 |
66 // Returns all UI items. The list contains references to items in the cache | 70 // Returns all UI items. The list contains references to items in the cache |
67 // and has to be used synchronously. | 71 // and has to be used synchronously. |
68 std::vector<const DownloadUIItem*> GetAllItems() const; | 72 std::vector<const DownloadUIItem*> GetAllItems() const; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 108 |
105 void LoadCache(); | 109 void LoadCache(); |
106 void ClearCache(); | 110 void ClearCache(); |
107 | 111 |
108 // Task callbacks. | 112 // Task callbacks. |
109 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages); | 113 void OnOfflinePagesLoaded(const MultipleOfflinePageItemResult& pages); |
110 void NotifyItemsLoaded(Observer* observer); | 114 void NotifyItemsLoaded(Observer* observer); |
111 void OnOfflinePagesChanged(const MultipleOfflinePageItemResult& pages); | 115 void OnOfflinePagesChanged(const MultipleOfflinePageItemResult& pages); |
112 void OnDeletePagesDone(DeletePageResult result); | 116 void OnDeletePagesDone(DeletePageResult result); |
113 | 117 |
114 bool IsVisibleInUI(const ClientId& page); | |
115 | |
116 // Always valid, this class is a member of the model. | 118 // Always valid, this class is a member of the model. |
117 OfflinePageModel* model_; | 119 OfflinePageModel* model_; |
118 | 120 |
119 State state_; | 121 State state_; |
120 | 122 |
121 // The cache of UI items. The key is DownloadUIItem.guid. | 123 // The cache of UI items. The key is DownloadUIItem.guid. |
122 DownloadUIItems items_; | 124 DownloadUIItems items_; |
123 | 125 |
124 // The observers. | 126 // The observers. |
125 base::ObserverList<Observer> observers_; | 127 base::ObserverList<Observer> observers_; |
126 int observers_count_; | 128 int observers_count_; |
127 | 129 |
128 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_; | 130 base::WeakPtrFactory<DownloadUIAdapter> weak_ptr_factory_; |
129 | 131 |
130 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter); | 132 DISALLOW_COPY_AND_ASSIGN(DownloadUIAdapter); |
131 }; | 133 }; |
132 | 134 |
133 } // namespace offline_pages | 135 } // namespace offline_pages |
134 | 136 |
135 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ | 137 #endif // COMPONENTS_OFFLINE_PAGE_DOWNLOADS_DOWNLOAD_UI_ADAPTER_H_ |
OLD | NEW |