Chromium Code Reviews| 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 "components/offline_pages/background/offliner_factory.h" | 10 #include "components/offline_pages/background/offliner_factory.h" |
| 11 #include "components/offline_pages/background/offliner_policy.h" | 11 #include "components/offline_pages/background/offliner_policy.h" |
| 12 #include "components/offline_pages/background/save_page_request.h" | 12 #include "components/offline_pages/background/save_page_request.h" |
| 13 #include "components/offline_pages/background/scheduler.h" | |
| 13 #include "components/offline_pages/offline_page_item.h" | 14 #include "components/offline_pages/offline_page_item.h" |
| 14 | 15 |
| 15 namespace offline_pages { | 16 namespace offline_pages { |
| 16 | 17 |
| 17 RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, | 18 RequestCoordinator::RequestCoordinator( |
| 18 std::unique_ptr<OfflinerFactory> factory, | 19 std::unique_ptr<OfflinerPolicy> policy, |
| 19 std::unique_ptr<RequestQueue> queue) { | 20 std::unique_ptr<OfflinerFactory> factory, |
| 21 std::unique_ptr<RequestQueue> queue, | |
| 22 std::unique_ptr<Scheduler> scheduler) { | |
| 20 // Do setup as needed. | 23 // Do setup as needed. |
| 21 // TODO(petewil): Assert policy not null. | 24 // TODO(petewil): Assert policy not null. |
|
fgorski
2016/05/12 14:32:35
can you already do this?
Pete Williamson
2016/05/12 17:21:18
Done.
| |
| 22 policy_ = std::move(policy); | 25 policy_ = std::move(policy); |
| 23 factory_ = std::move(factory); | 26 factory_ = std::move(factory); |
| 24 queue_ = std::move(queue); | 27 queue_ = std::move(queue); |
| 28 scheduler_ = std::move(scheduler); | |
|
fgorski
2016/05/12 14:32:35
C++: move all assignments to the initializer list.
Pete Williamson
2016/05/12 17:21:18
Done.
| |
| 25 } | 29 } |
| 26 | 30 |
| 27 RequestCoordinator::~RequestCoordinator() {} | 31 RequestCoordinator::~RequestCoordinator() {} |
| 28 | 32 |
| 29 bool RequestCoordinator::SavePageLater( | 33 bool RequestCoordinator::SavePageLater( |
| 30 const GURL& url, const ClientId& client_id) { | 34 const GURL& url, const ClientId& client_id) { |
| 31 DVLOG(2) << "URL is " << url << " " << __FUNCTION__; | 35 DVLOG(2) << "URL is " << url << " " << __FUNCTION__; |
| 32 | 36 |
| 33 // TODO(petewil): We need a robust scheme for allocating new IDs. | 37 // TODO(petewil): We need a robust scheme for allocating new IDs. |
| 34 static int64_t id = 0; | 38 static int64_t id = 0; |
| 35 | 39 |
| 36 // Build a SavePageRequest. | 40 // Build a SavePageRequest. |
| 37 // TODO(petewil): Use something like base::Clock to help in testing. | 41 // TODO(petewil): Use something like base::Clock to help in testing. |
| 38 offline_pages::SavePageRequest request( | 42 offline_pages::SavePageRequest request( |
| 39 id++, url, client_id, base::Time::Now()); | 43 id++, url, client_id, base::Time::Now()); |
| 40 | 44 |
| 41 // Put the request on the request queue. | 45 // Put the request on the request queue. |
| 42 queue_->AddRequest(request, | 46 queue_->AddRequest(request, |
| 43 base::Bind(&RequestCoordinator::AddRequestResultCallback, | 47 base::Bind(&RequestCoordinator::AddRequestResultCallback, |
| 44 AsWeakPtr())); | 48 AsWeakPtr())); |
| 45 // TODO: Do I need to persist the request in case the add fails? | 49 // TODO: Do I need to persist the request in case the add fails? |
| 46 | 50 |
| 51 Scheduler::TriggerCondition conditions; | |
| 52 scheduler_->Schedule(conditions); | |
| 53 | |
| 47 return true; | 54 return true; |
| 48 } | 55 } |
| 49 | 56 |
| 50 void RequestCoordinator::AddRequestResultCallback( | 57 void RequestCoordinator::AddRequestResultCallback( |
| 51 RequestQueue::AddRequestResult result, | 58 RequestQueue::AddRequestResult result, |
| 52 const SavePageRequest& request) { | 59 const SavePageRequest& request) { |
| 53 DVLOG(2) << __FUNCTION__; | 60 DVLOG(2) << __FUNCTION__; |
| 54 | 61 |
| 55 // Inform the scheduler that we have an outstanding task. | 62 // Inform the scheduler that we have an outstanding task. |
|
dougarnett
2016/05/12 15:33:33
Here is where it looked like you were intending to
Pete Williamson
2016/05/12 17:21:18
Ah, right, that code merged in from another change
| |
| 56 // TODO(petewil): implement. | 63 // TODO(petewil): implement. |
| 57 } | 64 } |
| 58 | 65 |
| 59 bool RequestCoordinator::StartProcessing( | 66 bool RequestCoordinator::StartProcessing( |
| 60 const ProcessingDoneCallback& callback) { | 67 const ProcessingDoneCallback& callback) { |
| 61 return false; | 68 return false; |
| 62 } | 69 } |
| 63 | 70 |
| 64 void RequestCoordinator::StopProcessing() { | 71 void RequestCoordinator::StopProcessing() { |
| 65 } | 72 } |
| 66 | 73 |
| 67 } // namespace offline_pages | 74 } // namespace offline_pages |
| OLD | NEW |