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

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

Issue 2087633002: Defines TriggerConditions and plumbs up to BackgroundScheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 5 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "components/offline_pages/background/offliner_factory.h" 12 #include "components/offline_pages/background/offliner_factory.h"
13 #include "components/offline_pages/background/offliner_policy.h" 13 #include "components/offline_pages/background/offliner_policy.h"
14 #include "components/offline_pages/background/request_picker.h" 14 #include "components/offline_pages/background/request_picker.h"
15 #include "components/offline_pages/background/save_page_request.h" 15 #include "components/offline_pages/background/save_page_request.h"
16 #include "components/offline_pages/background/scheduler.h" 16 #include "components/offline_pages/background/scheduler.h"
17 #include "components/offline_pages/offline_page_item.h" 17 #include "components/offline_pages/offline_page_item.h"
18 18
19 namespace offline_pages { 19 namespace offline_pages {
20 20
21 namespace {
22 const Scheduler::TriggerConditions kUserRequestTriggerConditions(
23 false /* require_power_connected */,
24 50 /* minimum_battery_percentage */,
Pete Williamson 2016/06/22 20:49:11 25 might be better than 50 here. It might also be
dougarnett 2016/06/22 21:52:17 Added to the TODO comment to consider lowering it
25 false /* require_unmetered_network */);
26 } // namespace
27
21 RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 28 RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
22 std::unique_ptr<OfflinerFactory> factory, 29 std::unique_ptr<OfflinerFactory> factory,
23 std::unique_ptr<RequestQueue> queue, 30 std::unique_ptr<RequestQueue> queue,
24 std::unique_ptr<Scheduler> scheduler) 31 std::unique_ptr<Scheduler> scheduler)
25 : policy_(std::move(policy)), 32 : policy_(std::move(policy)),
26 factory_(std::move(factory)), 33 factory_(std::move(factory)),
27 queue_(std::move(queue)), 34 queue_(std::move(queue)),
28 scheduler_(std::move(scheduler)), 35 scheduler_(std::move(scheduler)),
29 last_offlining_status_(Offliner::RequestStatus::UNKNOWN), 36 last_offlining_status_(Offliner::RequestStatus::UNKNOWN),
30 weak_ptr_factory_(this) { 37 weak_ptr_factory_(this) {
(...skipping 25 matching lines...) Expand all
56 // immediately for testing. It should call SendRequestToOffliner() 63 // immediately for testing. It should call SendRequestToOffliner()
57 64
58 return true; 65 return true;
59 } 66 }
60 67
61 void RequestCoordinator::AddRequestResultCallback( 68 void RequestCoordinator::AddRequestResultCallback(
62 RequestQueue::AddRequestResult result, 69 RequestQueue::AddRequestResult result,
63 const SavePageRequest& request) { 70 const SavePageRequest& request) {
64 71
65 // Inform the scheduler that we have an outstanding task. 72 // Inform the scheduler that we have an outstanding task.
66 // TODO(petewil): Define proper TriggerConditions and set them. 73 // TODO(petewil): Determine trigger conditions from policy.
67 Scheduler::TriggerCondition conditions; 74 scheduler_->Schedule(kUserRequestTriggerConditions);
68 scheduler_->Schedule(conditions);
69 } 75 }
70 76
71 // Called in response to updating a request in the request queue. 77 // Called in response to updating a request in the request queue.
72 void RequestCoordinator::UpdateRequestCallback( 78 void RequestCoordinator::UpdateRequestCallback(
73 RequestQueue::UpdateRequestResult result) {} 79 RequestQueue::UpdateRequestResult result) {}
74 80
75 // Called by the request picker when a request has been picked. 81 // Called by the request picker when a request has been picked.
76 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { 82 void RequestCoordinator::RequestPicked(const SavePageRequest& request) {
77 // Send the request on to the offliner. 83 // Send the request on to the offliner.
78 SendRequestToOffliner(request); 84 SendRequestToOffliner(request);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 weak_ptr_factory_.GetWeakPtr())); 151 weak_ptr_factory_.GetWeakPtr()));
146 152
147 // TODO(petewil): Check time budget. Return to the scheduler if we are out. 153 // TODO(petewil): Check time budget. Return to the scheduler if we are out.
148 154
149 // Start another request if we have time. 155 // Start another request if we have time.
150 TryNextRequest(); 156 TryNextRequest();
151 } 157 }
152 } 158 }
153 159
154 } // namespace offline_pages 160 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698