| 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/background/reconcile_task.h" | 5 #include "components/offline_pages/core/background/reconcile_task.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "components/offline_pages/core/background/offliner_policy.h" | 9 #include "components/offline_pages/core/background/offliner_policy.h" |
| 10 #include "components/offline_pages/core/background/request_coordinator_event_log
ger.h" | 10 #include "components/offline_pages/core/background/request_coordinator_event_log
ger.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 return; | 41 return; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Check for tasks in the OFFLINING state, and change the state back to | 44 // Check for tasks in the OFFLINING state, and change the state back to |
| 45 // AVAILABLE. | 45 // AVAILABLE. |
| 46 std::vector<SavePageRequest> items_to_update; | 46 std::vector<SavePageRequest> items_to_update; |
| 47 for (auto& request : requests) { | 47 for (auto& request : requests) { |
| 48 if (request->request_state() == SavePageRequest::RequestState::OFFLINING) { | 48 if (request->request_state() == SavePageRequest::RequestState::OFFLINING) { |
| 49 request->set_request_state(SavePageRequest::RequestState::AVAILABLE); | 49 request->set_request_state(SavePageRequest::RequestState::AVAILABLE); |
| 50 items_to_update.push_back(*request.get()); | 50 items_to_update.push_back(*request.get()); |
| 51 // TODO(petewil): Consider adding UMA to see how often chrome gets killed | |
| 52 // while processing a request. | |
| 53 } | 51 } |
| 54 } | 52 } |
| 55 | 53 |
| 56 // If there is no work (most common case), just return, no need for a | 54 // If there is no work (most common case), just return, no need for a |
| 57 // callback. | 55 // callback. |
| 58 if (items_to_update.empty()) { | 56 if (items_to_update.empty()) { |
| 59 TaskComplete(); | 57 TaskComplete(); |
| 60 return; | 58 return; |
| 61 } | 59 } |
| 62 | 60 |
| 63 store_->UpdateRequests(items_to_update, | 61 store_->UpdateRequests(items_to_update, |
| 64 base::Bind(&ReconcileTask::UpdateCompleted, | 62 base::Bind(&ReconcileTask::UpdateCompleted, |
| 65 weak_ptr_factory_.GetWeakPtr())); | 63 weak_ptr_factory_.GetWeakPtr())); |
| 66 } | 64 } |
| 67 | 65 |
| 68 void ReconcileTask::UpdateCompleted( | 66 void ReconcileTask::UpdateCompleted( |
| 69 std::unique_ptr<UpdateRequestsResult> update_result) { | 67 std::unique_ptr<UpdateRequestsResult> update_result) { |
| 70 // Send a notification to the UI that these items have updated. | 68 // Send a notification to the UI that these items have updated. |
| 71 callback_.Run(std::move(update_result)); | 69 callback_.Run(std::move(update_result)); |
| 72 TaskComplete(); | 70 TaskComplete(); |
| 73 } | 71 } |
| 74 | 72 |
| 75 } // namespace offline_pages | 73 } // namespace offline_pages |
| OLD | NEW |