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 #include "components/offline_pages/downloads/download_ui_adapter.h" | 5 #include "components/offline_pages/downloads/download_ui_adapter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 std::vector<std::string> added_guids; | 191 std::vector<std::string> added_guids; |
192 for (const auto& page : pages) { | 192 for (const auto& page : pages) { |
193 if (!IsVisibleInUI(page.client_id)) // Item should be filtered out. | 193 if (!IsVisibleInUI(page.client_id)) // Item should be filtered out. |
194 continue; | 194 continue; |
195 const std::string& guid = page.client_id.id; | 195 const std::string& guid = page.client_id.id; |
196 if (items_.find(guid) != items_.end()) // Item already exists. | 196 if (items_.find(guid) != items_.end()) // Item already exists. |
197 continue; | 197 continue; |
198 items_[guid] = base::MakeUnique<ItemInfo>(page); | 198 items_[guid] = base::MakeUnique<ItemInfo>(page); |
199 added_guids.push_back(guid); | 199 added_guids.push_back(guid); |
200 } | 200 } |
201 // Only one added page | |
202 CHECK(added_guids.size() <= 1); | |
203 for (auto& guid : added_guids) { | 201 for (auto& guid : added_guids) { |
204 const DownloadUIItem& item = *(items_.find(guid)->second->ui_item.get()); | 202 const DownloadUIItem& item = *(items_.find(guid)->second->ui_item.get()); |
205 FOR_EACH_OBSERVER(Observer, observers_, ItemAdded(item)); | 203 FOR_EACH_OBSERVER(Observer, observers_, ItemAdded(item)); |
206 } | 204 } |
207 } | 205 } |
208 | 206 |
209 void DownloadUIAdapter::OnDeletePagesDone(DeletePageResult result) { | 207 void DownloadUIAdapter::OnDeletePagesDone(DeletePageResult result) { |
210 // TODO(dimich): Consider adding UMA to record user actions. | 208 // TODO(dimich): Consider adding UMA to record user actions. |
211 } | 209 } |
212 | 210 |
213 // static | 211 // static |
214 bool DownloadUIAdapter::IsVisibleInUI(const ClientId& client_id) { | 212 bool DownloadUIAdapter::IsVisibleInUI(const ClientId& client_id) { |
215 const std::string& name_space = client_id.name_space; | 213 const std::string& name_space = client_id.name_space; |
216 return (name_space == kAsyncNamespace || name_space == kDownloadNamespace) && | 214 return (name_space == kAsyncNamespace || name_space == kDownloadNamespace) && |
217 base::IsValidGUID(client_id.id); | 215 base::IsValidGUID(client_id.id); |
218 } | 216 } |
219 | 217 |
220 } // namespace offline_pages | 218 } // namespace offline_pages |
OLD | NEW |