| 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/callback.h" | 10 #include "base/callback.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 int64_t id = GenerateOfflineId(); | 87 int64_t id = GenerateOfflineId(); |
| 88 | 88 |
| 89 // Build a SavePageRequest. | 89 // Build a SavePageRequest. |
| 90 offline_pages::SavePageRequest request(id, url, client_id, base::Time::Now(), | 90 offline_pages::SavePageRequest request(id, url, client_id, base::Time::Now(), |
| 91 user_requested); | 91 user_requested); |
| 92 | 92 |
| 93 // Put the request on the request queue. | 93 // Put the request on the request queue. |
| 94 queue_->AddRequest(request, | 94 queue_->AddRequest(request, |
| 95 base::Bind(&RequestCoordinator::AddRequestResultCallback, | 95 base::Bind(&RequestCoordinator::AddRequestResultCallback, |
| 96 weak_ptr_factory_.GetWeakPtr())); | 96 weak_ptr_factory_.GetWeakPtr())); |
| 97 NotifyAdded(request); | |
| 98 return true; | 97 return true; |
| 99 } | 98 } |
| 100 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) { | 99 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) { |
| 101 // Get all matching requests from the request queue, send them to our | 100 // Get all matching requests from the request queue, send them to our |
| 102 // callback. We bind the namespace and callback to the front of the callback | 101 // callback. We bind the namespace and callback to the front of the callback |
| 103 // param set. | 102 // param set. |
| 104 queue_->GetRequests(base::Bind(&RequestCoordinator::GetQueuedRequestsCallback, | 103 queue_->GetRequests(base::Bind(&RequestCoordinator::GetQueuedRequestsCallback, |
| 105 weak_ptr_factory_.GetWeakPtr(), callback)); | 104 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 106 } | 105 } |
| 107 | 106 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 132 queue_->ChangeRequestsState( | 131 queue_->ChangeRequestsState( |
| 133 request_ids, SavePageRequest::RequestState::AVAILABLE, | 132 request_ids, SavePageRequest::RequestState::AVAILABLE, |
| 134 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, | 133 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, |
| 135 weak_ptr_factory_.GetWeakPtr())); | 134 weak_ptr_factory_.GetWeakPtr())); |
| 136 // TODO: Should we also schedule a task, in case there is not one scheduled? | 135 // TODO: Should we also schedule a task, in case there is not one scheduled? |
| 137 } | 136 } |
| 138 | 137 |
| 139 void RequestCoordinator::AddRequestResultCallback( | 138 void RequestCoordinator::AddRequestResultCallback( |
| 140 RequestQueue::AddRequestResult result, | 139 RequestQueue::AddRequestResult result, |
| 141 const SavePageRequest& request) { | 140 const SavePageRequest& request) { |
| 141 NotifyAdded(request); |
| 142 // Inform the scheduler that we have an outstanding task.. | 142 // Inform the scheduler that we have an outstanding task.. |
| 143 scheduler_->Schedule(GetTriggerConditionsForUserRequest()); | 143 scheduler_->Schedule(GetTriggerConditionsForUserRequest()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Called in response to updating a request in the request queue. | 146 // Called in response to updating a request in the request queue. |
| 147 void RequestCoordinator::UpdateRequestCallback( | 147 void RequestCoordinator::UpdateRequestCallback( |
| 148 const ClientId& client_id, | 148 const ClientId& client_id, |
| 149 RequestQueue::UpdateRequestResult result) { | 149 RequestQueue::UpdateRequestResult result) { |
| 150 // If the request succeeded, nothing to do. If it failed, we can't really do | 150 // If the request succeeded, nothing to do. If it failed, we can't really do |
| 151 // much, so just log it. | 151 // much, so just log it. |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); | 405 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); |
| 406 } | 406 } |
| 407 | 407 |
| 408 void RequestCoordinator::GetOffliner() { | 408 void RequestCoordinator::GetOffliner() { |
| 409 if (!offliner_) { | 409 if (!offliner_) { |
| 410 offliner_ = factory_->GetOffliner(policy_.get()); | 410 offliner_ = factory_->GetOffliner(policy_.get()); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 } // namespace offline_pages | 414 } // namespace offline_pages |
| OLD | NEW |