Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: components/offline_pages/background/request_coordinator.cc

Issue 2066593003: Add a general purpose facility for letting background tasks wait until (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 RequestQueue::AddRequestResult result, 62 RequestQueue::AddRequestResult result,
63 const SavePageRequest& request) { 63 const SavePageRequest& request) {
64 64
65 // Inform the scheduler that we have an outstanding task. 65 // Inform the scheduler that we have an outstanding task.
66 // TODO(petewil): Define proper TriggerConditions and set them. 66 // TODO(petewil): Define proper TriggerConditions and set them.
67 Scheduler::TriggerCondition conditions; 67 Scheduler::TriggerCondition conditions;
68 scheduler_->Schedule(conditions); 68 scheduler_->Schedule(conditions);
69 } 69 }
70 70
71 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { 71 void RequestCoordinator::RequestPicked(const SavePageRequest& request) {
72 Scheduler::TriggerCondition conditions;
73
74 // Ensure that the scheduler has actively scheduled a task.
75 scheduler_->Schedule(conditions);
76
77 // Send the request on to the offliner. 72 // Send the request on to the offliner.
78 SendRequestToOffliner(request); 73 SendRequestToOffliner(request);
79 } 74 }
80 75
81 void RequestCoordinator::RequestQueueEmpty() { 76 void RequestCoordinator::RequestQueueEmpty() {
82 // TODO(petewil): return to the BackgroundScheduler by calling 77 // TODO(petewil): return to the BackgroundScheduler by calling
83 // ProcessingDoneCallback 78 // ProcessingDoneCallback
84 } 79 }
85 80
86 bool RequestCoordinator::StartProcessing( 81 bool RequestCoordinator::StartProcessing(
87 const base::Callback<void(bool)>& callback) { 82 base::Callback<void(bool)> callback) {
83 scheduler_callback_ = callback;
88 // TODO(petewil): Check existing conditions (should be passed down from 84 // TODO(petewil): Check existing conditions (should be passed down from
89 // BackgroundTask) 85 // BackgroundTask)
90 86
91 // Choose a request to process that meets the available conditions. 87 // Choose a request to process that meets the available conditions.
92 // This is an async call, and returns right away. 88 // This is an async call, and returns right away.
93 picker_->ChooseNextRequest( 89 picker_->ChooseNextRequest(
94 base::Bind(&RequestCoordinator::RequestPicked, 90 base::Bind(&RequestCoordinator::RequestPicked,
95 weak_ptr_factory_.GetWeakPtr()), 91 weak_ptr_factory_.GetWeakPtr()),
96 base::Bind(&RequestCoordinator::RequestQueueEmpty, 92 base::Bind(&RequestCoordinator::RequestQueueEmpty,
97 weak_ptr_factory_.GetWeakPtr())); 93 weak_ptr_factory_.GetWeakPtr()));
(...skipping 23 matching lines...) Expand all
121 Offliner::RequestStatus status) { 117 Offliner::RequestStatus status) {
122 DVLOG(2) << "offliner finished, saved: " 118 DVLOG(2) << "offliner finished, saved: "
123 << (status == Offliner::RequestStatus::SAVED) << ", " 119 << (status == Offliner::RequestStatus::SAVED) << ", "
124 << __FUNCTION__; 120 << __FUNCTION__;
125 last_offlining_status_ = status; 121 last_offlining_status_ = status;
126 122
127 // TODO(petewil): Check time budget. Start a request if we have time, return 123 // TODO(petewil): Check time budget. Start a request if we have time, return
128 // to the scheduler if we are out of time. 124 // to the scheduler if we are out of time.
129 125
130 // TODO(petewil): If the request succeeded, remove it from the Queue. 126 // TODO(petewil): If the request succeeded, remove it from the Queue.
127
128 // Return control to the scheduler when there is no more to do.
129 scheduler_callback_.Run(status == Offliner::RequestStatus::SAVED);
131 } 130 }
132 131
133 } // namespace offline_pages 132 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698