| 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/core/offline_page_model_impl.h" | 5 #include "components/offline_pages/core/offline_page_model_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 DCHECK(is_loaded_); | 565 DCHECK(is_loaded_); |
| 566 callback.Run(MaybeGetOfflineIdsForClientId(client_id)); | 566 callback.Run(MaybeGetOfflineIdsForClientId(client_id)); |
| 567 } | 567 } |
| 568 | 568 |
| 569 const std::vector<int64_t> OfflinePageModelImpl::MaybeGetOfflineIdsForClientId( | 569 const std::vector<int64_t> OfflinePageModelImpl::MaybeGetOfflineIdsForClientId( |
| 570 const ClientId& client_id) const { | 570 const ClientId& client_id) const { |
| 571 DCHECK(is_loaded_); | 571 DCHECK(is_loaded_); |
| 572 std::vector<int64_t> results; | 572 std::vector<int64_t> results; |
| 573 | 573 |
| 574 // We want only all pages, including those marked for deletion. | 574 // We want only all pages, including those marked for deletion. |
| 575 // TODO(fgorski): actually use an index rather than linear scan. | |
| 576 for (const auto& id_page_pair : offline_pages_) { | 575 for (const auto& id_page_pair : offline_pages_) { |
| 577 if (id_page_pair.second.client_id == client_id) | 576 if (id_page_pair.second.client_id == client_id) |
| 578 results.push_back(id_page_pair.second.offline_id); | 577 results.push_back(id_page_pair.second.offline_id); |
| 579 } | 578 } |
| 580 return results; | 579 return results; |
| 581 } | 580 } |
| 582 | 581 |
| 583 void OfflinePageModelImpl::GetPageByOfflineId( | 582 void OfflinePageModelImpl::GetPageByOfflineId( |
| 584 int64_t offline_id, | 583 int64_t offline_id, |
| 585 const SingleOfflinePageItemCallback& callback) { | 584 const SingleOfflinePageItemCallback& callback) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 const base::Time& start_time, | 682 const base::Time& start_time, |
| 684 const SavePageCallback& callback, | 683 const SavePageCallback& callback, |
| 685 OfflinePageArchiver* archiver, | 684 OfflinePageArchiver* archiver, |
| 686 ArchiverResult archiver_result, | 685 ArchiverResult archiver_result, |
| 687 const GURL& url, | 686 const GURL& url, |
| 688 const base::FilePath& file_path, | 687 const base::FilePath& file_path, |
| 689 const base::string16& title, | 688 const base::string16& title, |
| 690 int64_t file_size) { | 689 int64_t file_size) { |
| 691 if (save_page_params.url != url) { | 690 if (save_page_params.url != url) { |
| 692 DVLOG(1) << "Saved URL does not match requested URL."; | 691 DVLOG(1) << "Saved URL does not match requested URL."; |
| 693 // TODO(fgorski): We have created an archive for a wrong URL. It should be | |
| 694 // deleted from here, once archiver has the right functionality. | |
| 695 InformSavePageDone(callback, SavePageResult::ARCHIVE_CREATION_FAILED, | 692 InformSavePageDone(callback, SavePageResult::ARCHIVE_CREATION_FAILED, |
| 696 save_page_params.client_id, offline_id); | 693 save_page_params.client_id, offline_id); |
| 697 DeletePendingArchiver(archiver); | 694 DeletePendingArchiver(archiver); |
| 698 return; | 695 return; |
| 699 } | 696 } |
| 700 | 697 |
| 701 if (archiver_result != ArchiverResult::SUCCESSFULLY_CREATED) { | 698 if (archiver_result != ArchiverResult::SUCCESSFULLY_CREATED) { |
| 702 SavePageResult result = ToSavePageResult(archiver_result); | 699 SavePageResult result = ToSavePageResult(archiver_result); |
| 703 InformSavePageDone( | 700 InformSavePageDone( |
| 704 callback, result, save_page_params.client_id, offline_id); | 701 callback, result, save_page_params.client_id, offline_id); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 if (iter == offline_pages_.end()) | 946 if (iter == offline_pages_.end()) |
| 950 continue; | 947 continue; |
| 951 offline_pages_.erase(iter); | 948 offline_pages_.erase(iter); |
| 952 } | 949 } |
| 953 | 950 |
| 954 for (const auto& page : result->updated_items) { | 951 for (const auto& page : result->updated_items) { |
| 955 for (Observer& observer : observers_) | 952 for (Observer& observer : observers_) |
| 956 observer.OfflinePageDeleted(page.offline_id, page.client_id); | 953 observer.OfflinePageDeleted(page.offline_id, page.client_id); |
| 957 } | 954 } |
| 958 | 955 |
| 959 // TODO(fgorski): React the FAILED_INITIALIZATION, FAILED_RESET here. | |
| 960 // TODO(fgorski): We need a better callback interface for the Remove action on | |
| 961 // the this class. Currently removing an item that does not exist is | |
| 962 // considered a success, but not called out as such to the caller. | |
| 963 DeletePageResult delete_result; | 956 DeletePageResult delete_result; |
| 964 if (result->store_state == StoreState::LOADED) | 957 if (result->store_state == StoreState::LOADED) |
| 965 delete_result = DeletePageResult::SUCCESS; | 958 delete_result = DeletePageResult::SUCCESS; |
| 966 else | 959 else |
| 967 delete_result = DeletePageResult::STORE_FAILURE; | 960 delete_result = DeletePageResult::STORE_FAILURE; |
| 968 | 961 |
| 969 InformDeletePageDone(callback, delete_result); | 962 InformDeletePageDone(callback, delete_result); |
| 970 } | 963 } |
| 971 | 964 |
| 972 void OfflinePageModelImpl::InformDeletePageDone( | 965 void OfflinePageModelImpl::InformDeletePageDone( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 } | 1088 } |
| 1096 | 1089 |
| 1097 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1090 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1098 } | 1091 } |
| 1099 | 1092 |
| 1100 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1093 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1101 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1094 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1102 } | 1095 } |
| 1103 | 1096 |
| 1104 } // namespace offline_pages | 1097 } // namespace offline_pages |
| OLD | NEW |