Chromium Code Reviews| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 // Make a copy of the cached item and update it. The cached item should only | 225 // Make a copy of the cached item and update it. The cached item should only |
| 226 // be updated upon the successful store operation. | 226 // be updated upon the successful store operation. |
| 227 OfflinePageItem offline_page_item = iter->second; | 227 OfflinePageItem offline_page_item = iter->second; |
| 228 offline_page_item.MarkForDeletion(); | 228 offline_page_item.MarkForDeletion(); |
| 229 store_->AddOrUpdateOfflinePage( | 229 store_->AddOrUpdateOfflinePage( |
| 230 offline_page_item, | 230 offline_page_item, |
| 231 base::Bind(&OfflinePageModel::OnMarkPageForDeletionDone, | 231 base::Bind(&OfflinePageModel::OnMarkPageForDeletionDone, |
| 232 weak_ptr_factory_.GetWeakPtr(), offline_page_item, callback)); | 232 weak_ptr_factory_.GetWeakPtr(), offline_page_item, callback)); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void OfflinePageModel::DeletePageByBookmarkId( | |
| 236 int64_t bookmark_id, | |
| 237 const DeletePageCallback& callback) { | |
| 238 DCHECK(is_loaded_); | |
| 239 std::vector<int64_t> bookmark_ids_to_delete; | |
| 240 bookmark_ids_to_delete.push_back(bookmark_id); | |
| 241 DeletePagesByBookmarkId(bookmark_ids_to_delete, callback); | |
| 242 } | |
| 243 | |
| 244 void OfflinePageModel::DeletePagesByBookmarkId( | 235 void OfflinePageModel::DeletePagesByBookmarkId( |
| 245 const std::vector<int64_t>& bookmark_ids, | 236 const std::vector<int64_t>& bookmark_ids, |
| 246 const DeletePageCallback& callback) { | 237 const DeletePageCallback& callback) { |
| 247 DCHECK(is_loaded_); | 238 DCHECK(is_loaded_); |
| 248 | 239 |
| 249 std::vector<base::FilePath> paths_to_delete; | 240 std::vector<base::FilePath> paths_to_delete; |
| 250 for (const auto& bookmark_id : bookmark_ids) { | 241 for (const auto& bookmark_id : bookmark_ids) { |
| 251 auto iter = offline_pages_.find(bookmark_id); | 242 auto iter = offline_pages_.find(bookmark_id); |
| 252 if (iter != offline_pages_.end()) { | 243 if (iter != offline_pages_.end()) { |
| 253 paths_to_delete.push_back(iter->second.file_path); | 244 paths_to_delete.push_back(iter->second.file_path); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 } | 519 } |
| 529 MarkPageForDeletion(node->id(), base::Bind(&EmptyDeleteCallback)); | 520 MarkPageForDeletion(node->id(), base::Bind(&EmptyDeleteCallback)); |
| 530 } | 521 } |
| 531 | 522 |
| 532 void OfflinePageModel::BookmarkNodeChanged( | 523 void OfflinePageModel::BookmarkNodeChanged( |
| 533 bookmarks::BookmarkModel* model, | 524 bookmarks::BookmarkModel* model, |
| 534 const bookmarks::BookmarkNode* node) { | 525 const bookmarks::BookmarkNode* node) { |
| 535 // BookmarkNodeChanged could be triggered if title or URL gets changed. If | 526 // BookmarkNodeChanged could be triggered if title or URL gets changed. If |
| 536 // the latter, we need to invalidate the offline copy. | 527 // the latter, we need to invalidate the offline copy. |
| 537 auto iter = offline_pages_.find(node->id()); | 528 auto iter = offline_pages_.find(node->id()); |
| 538 if (iter != offline_pages_.end() && iter->second.url != node->url()) | 529 if (iter != offline_pages_.end() && iter->second.url != node->url()) { |
| 539 DeletePageByBookmarkId(node->id(), DeletePageCallback()); | 530 DeletePagesByBookmarkId(std::vector<int64_t>(1, node->id()), |
|
fgorski
2016/02/26 21:31:10
ugly, do we need this?
Will the offline_id patch n
dewittj
2016/03/01 22:28:52
Done.
| |
| 531 DeletePageCallback()); | |
| 532 } | |
| 540 } | 533 } |
| 541 | 534 |
| 542 void OfflinePageModel::OnEnsureArchivesDirCreatedDone() { | 535 void OfflinePageModel::OnEnsureArchivesDirCreatedDone() { |
| 543 store_->Load(base::Bind(&OfflinePageModel::OnLoadDone, | 536 store_->Load(base::Bind(&OfflinePageModel::OnLoadDone, |
| 544 weak_ptr_factory_.GetWeakPtr())); | 537 weak_ptr_factory_.GetWeakPtr())); |
| 545 } | 538 } |
| 546 | 539 |
| 547 void OfflinePageModel::OnLoadDone( | 540 void OfflinePageModel::OnLoadDone( |
| 548 OfflinePageMetadataStore::LoadStatus load_status, | 541 OfflinePageMetadataStore::LoadStatus load_status, |
| 549 const std::vector<OfflinePageItem>& offline_pages) { | 542 const std::vector<OfflinePageItem>& offline_pages) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 } | 724 } |
| 732 | 725 |
| 733 void OfflinePageModel::CacheLoadedData( | 726 void OfflinePageModel::CacheLoadedData( |
| 734 const std::vector<OfflinePageItem>& offline_pages) { | 727 const std::vector<OfflinePageItem>& offline_pages) { |
| 735 offline_pages_.clear(); | 728 offline_pages_.clear(); |
| 736 for (const auto& offline_page : offline_pages) | 729 for (const auto& offline_page : offline_pages) |
| 737 offline_pages_[offline_page.bookmark_id] = offline_page; | 730 offline_pages_[offline_page.bookmark_id] = offline_page; |
| 738 } | 731 } |
| 739 | 732 |
| 740 } // namespace offline_pages | 733 } // namespace offline_pages |
| OLD | NEW |