OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/offline_page_model.h" | 5 #include "components/offline_pages/offline_page_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 std::vector<int64> bookmark_ids; | 244 std::vector<int64> bookmark_ids; |
245 for (const auto& id_page_pair : offline_pages_) | 245 for (const auto& id_page_pair : offline_pages_) |
246 bookmark_ids.push_back(id_page_pair.first); | 246 bookmark_ids.push_back(id_page_pair.first); |
247 DeletePagesByBookmarkId( | 247 DeletePagesByBookmarkId( |
248 bookmark_ids, | 248 bookmark_ids, |
249 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, | 249 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, |
250 weak_ptr_factory_.GetWeakPtr(), | 250 weak_ptr_factory_.GetWeakPtr(), |
251 callback)); | 251 callback)); |
252 } | 252 } |
253 | 253 |
| 254 bool OfflinePageModel::HasOfflinePages() const { |
| 255 DCHECK(is_loaded_); |
| 256 return !offline_pages_.empty(); |
| 257 } |
| 258 |
254 const std::vector<OfflinePageItem> OfflinePageModel::GetAllPages() const { | 259 const std::vector<OfflinePageItem> OfflinePageModel::GetAllPages() const { |
255 DCHECK(is_loaded_); | 260 DCHECK(is_loaded_); |
256 std::vector<OfflinePageItem> offline_pages; | 261 std::vector<OfflinePageItem> offline_pages; |
257 for (const auto& id_page_pair : offline_pages_) { | 262 for (const auto& id_page_pair : offline_pages_) { |
258 if (id_page_pair.second.IsMarkedForDeletion()) | 263 if (id_page_pair.second.IsMarkedForDeletion()) |
259 continue; | 264 continue; |
260 offline_pages.push_back(id_page_pair.second); | 265 offline_pages.push_back(id_page_pair.second); |
261 } | 266 } |
262 return offline_pages; | 267 return offline_pages; |
263 } | 268 } |
(...skipping 21 matching lines...) Expand all Loading... |
285 const GURL& offline_url) const { | 290 const GURL& offline_url) const { |
286 for (auto iter = offline_pages_.begin(); | 291 for (auto iter = offline_pages_.begin(); |
287 iter != offline_pages_.end(); | 292 iter != offline_pages_.end(); |
288 ++iter) { | 293 ++iter) { |
289 if (iter->second.GetOfflineURL() == offline_url) | 294 if (iter->second.GetOfflineURL() == offline_url) |
290 return &(iter->second); | 295 return &(iter->second); |
291 } | 296 } |
292 return nullptr; | 297 return nullptr; |
293 } | 298 } |
294 | 299 |
| 300 const OfflinePageItem* OfflinePageModel::GetPageByOnlineURL( |
| 301 const GURL& online_url) const { |
| 302 for (auto iter = offline_pages_.begin(); iter != offline_pages_.end(); |
| 303 ++iter) { |
| 304 if (iter->second.url == online_url) |
| 305 return &(iter->second); |
| 306 } |
| 307 return nullptr; |
| 308 } |
| 309 |
295 void OfflinePageModel::CheckForExternalFileDeletion() { | 310 void OfflinePageModel::CheckForExternalFileDeletion() { |
296 DCHECK(is_loaded_); | 311 DCHECK(is_loaded_); |
297 | 312 |
298 std::vector<std::pair<int64, base::FilePath>> id_path_pairs; | 313 std::vector<std::pair<int64, base::FilePath>> id_path_pairs; |
299 for (const auto& id_page_pair : offline_pages_) { | 314 for (const auto& id_page_pair : offline_pages_) { |
300 id_path_pairs.push_back( | 315 id_path_pairs.push_back( |
301 std::make_pair(id_page_pair.first, id_page_pair.second.file_path)); | 316 std::make_pair(id_page_pair.first, id_page_pair.second.file_path)); |
302 } | 317 } |
303 | 318 |
304 std::vector<int64>* ids_of_pages_missing_archive_file = | 319 std::vector<int64>* ids_of_pages_missing_archive_file = |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 } | 647 } |
633 | 648 |
634 void OfflinePageModel::CacheLoadedData( | 649 void OfflinePageModel::CacheLoadedData( |
635 const std::vector<OfflinePageItem>& offline_pages) { | 650 const std::vector<OfflinePageItem>& offline_pages) { |
636 offline_pages_.clear(); | 651 offline_pages_.clear(); |
637 for (const auto& offline_page : offline_pages) | 652 for (const auto& offline_page : offline_pages) |
638 offline_pages_[offline_page.bookmark_id] = offline_page; | 653 offline_pages_[offline_page.bookmark_id] = offline_page; |
639 } | 654 } |
640 | 655 |
641 } // namespace offline_pages | 656 } // namespace offline_pages |
OLD | NEW |