| 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/background/request_coordinator.h" | 5 #include "components/offline_pages/background/request_coordinator.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 weak_ptr_factory_.GetWeakPtr()), | 89 weak_ptr_factory_.GetWeakPtr()), |
| 90 base::Bind(&RequestCoordinator::RequestQueueEmpty, | 90 base::Bind(&RequestCoordinator::RequestQueueEmpty, |
| 91 weak_ptr_factory_.GetWeakPtr())); | 91 weak_ptr_factory_.GetWeakPtr())); |
| 92 return false; | 92 return false; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void RequestCoordinator::StopProcessing() { | 95 void RequestCoordinator::StopProcessing() { |
| 96 } | 96 } |
| 97 | 97 |
| 98 void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { | 98 void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { |
| 99 // TODO(petewil): Ensure only one offliner at a time is used. |
| 99 // TODO(petewil): When we have multiple offliners, we need to pick one. | 100 // TODO(petewil): When we have multiple offliners, we need to pick one. |
| 100 Offliner* offliner = factory_->GetOffliner(policy_.get()); | 101 Offliner* offliner = factory_->GetOffliner(policy_.get()); |
| 101 if (!offliner) { | 102 if (!offliner) { |
| 102 DVLOG(0) << "Unable to create Offliner. " | 103 DVLOG(0) << "Unable to create Offliner. " |
| 103 << "Cannot background offline page."; | 104 << "Cannot background offline page."; |
| 104 return; | 105 return; |
| 105 } | 106 } |
| 106 | 107 |
| 107 // Start the load and save process in the offliner (Async). | 108 // Start the load and save process in the offliner (Async). |
| 108 offliner->LoadAndSave(request, | 109 offliner->LoadAndSave(request, |
| 109 base::Bind(&RequestCoordinator::OfflinerDoneCallback, | 110 base::Bind(&RequestCoordinator::OfflinerDoneCallback, |
| 110 weak_ptr_factory_.GetWeakPtr())); | 111 weak_ptr_factory_.GetWeakPtr())); |
| 111 } | 112 } |
| 112 | 113 |
| 113 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, | 114 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
| 114 Offliner::RequestStatus status) { | 115 Offliner::RequestStatus status) { |
| 115 DVLOG(2) << "offliner finished, saved: " | 116 DVLOG(2) << "offliner finished, saved: " |
| 116 << (status == Offliner::RequestStatus::SAVED) << ", " | 117 << (status == Offliner::RequestStatus::SAVED) << ", " |
| 117 << __FUNCTION__; | 118 << __FUNCTION__; |
| 118 last_offlining_status_ = status; | 119 last_offlining_status_ = status; |
| 119 | 120 |
| 120 // TODO(petewil): Check time budget. Start a request if we have time, return | 121 // TODO(petewil): Check time budget. Start a request if we have time, return |
| 121 // to the scheduler if we are out of time. | 122 // to the scheduler if we are out of time. |
| 122 | 123 |
| 123 // TODO(petewil): If the request succeeded, remove it from the Queue. | 124 // TODO(petewil): If the request succeeded, remove it from the Queue. |
| 124 } | 125 } |
| 125 | 126 |
| 126 } // namespace offline_pages | 127 } // namespace offline_pages |
| OLD | NEW |