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

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

Issue 2420503002: [Offline Pages] Define separate watchdog timeout for concurrent bg loads (Closed)
Patch Set: Created 4 years, 2 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 test_connection_type_(), 126 test_connection_type_(),
127 offliner_(nullptr), 127 offliner_(nullptr),
128 policy_(std::move(policy)), 128 policy_(std::move(policy)),
129 factory_(std::move(factory)), 129 factory_(std::move(factory)),
130 queue_(std::move(queue)), 130 queue_(std::move(queue)),
131 scheduler_(std::move(scheduler)), 131 scheduler_(std::move(scheduler)),
132 policy_controller_(new ClientPolicyController()), 132 policy_controller_(new ClientPolicyController()),
133 network_quality_estimator_(network_quality_estimator), 133 network_quality_estimator_(network_quality_estimator),
134 active_request_(nullptr), 134 active_request_(nullptr),
135 last_offlining_status_(Offliner::RequestStatus::UNKNOWN), 135 last_offlining_status_(Offliner::RequestStatus::UNKNOWN),
136 offliner_timeout_(base::TimeDelta::FromSeconds(
137 policy_->GetSinglePageTimeLimitInSeconds())),
138 weak_ptr_factory_(this) { 136 weak_ptr_factory_(this) {
139 DCHECK(policy_ != nullptr); 137 DCHECK(policy_ != nullptr);
140 picker_.reset( 138 picker_.reset(
141 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_)); 139 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_));
142 } 140 }
143 141
144 RequestCoordinator::~RequestCoordinator() {} 142 RequestCoordinator::~RequestCoordinator() {}
145 143
146 int64_t RequestCoordinator::SavePageLater(const GURL& url, 144 int64_t RequestCoordinator::SavePageLater(const GURL& url,
147 const ClientId& client_id, 145 const ClientId& client_id,
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 scheduler_callback_.Run(true); 397 scheduler_callback_.Run(true);
400 } 398 }
401 399
402 void RequestCoordinator::HandleWatchdogTimeout() { 400 void RequestCoordinator::HandleWatchdogTimeout() {
403 StopProcessing(Offliner::REQUEST_COORDINATOR_TIMED_OUT); 401 StopProcessing(Offliner::REQUEST_COORDINATOR_TIMED_OUT);
404 } 402 }
405 403
406 // Returns true if the caller should expect a callback, false otherwise. For 404 // Returns true if the caller should expect a callback, false otherwise. For
407 // instance, this would return false if a request is already in progress. 405 // instance, this would return false if a request is already in progress.
408 bool RequestCoordinator::StartProcessing( 406 bool RequestCoordinator::StartProcessing(
407 bool is_background_scheduled,
409 const DeviceConditions& device_conditions, 408 const DeviceConditions& device_conditions,
410 const base::Callback<void(bool)>& callback) { 409 const base::Callback<void(bool)>& callback) {
411 current_conditions_.reset(new DeviceConditions(device_conditions)); 410 current_conditions_.reset(new DeviceConditions(device_conditions));
412 if (is_starting_ || is_busy_) 411 if (is_starting_ || is_busy_)
413 return false; 412 return false;
414 is_starting_ = true; 413 is_starting_ = true;
415 414
416 // Mark the time at which we started processing so we can check our time 415 // Mark the time at which we started processing so we can check our time
417 // budget. 416 // budget.
418 operation_start_time_ = base::Time::Now(); 417 operation_start_time_ = base::Time::Now();
418 offliner_timeout_ = base::TimeDelta::FromSeconds(
Pete Williamson 2016/10/12 22:33:24 It's a bit fragile to have this changing constantl
dougarnett 2016/10/13 19:46:45 It is really tied to the service window though - n
419 policy_->GetSinglePageTimeLimitInSeconds(is_background_scheduled));
419 420
420 is_stopped_ = false; 421 is_stopped_ = false;
421 scheduler_callback_ = callback; 422 scheduler_callback_ = callback;
422 423
423 TryNextRequest(); 424 TryNextRequest();
424 425
425 return true; 426 return true;
426 } 427 }
427 428
428 void RequestCoordinator::StartProcessingIfConnected() { 429 void RequestCoordinator::StartProcessingIfConnected() {
(...skipping 22 matching lines...) Expand all
451 return OfflinerImmediateStartStatus::WEAK_CONNECTION; 452 return OfflinerImmediateStartStatus::WEAK_CONNECTION;
452 } else if (GetConnectionType() == 453 } else if (GetConnectionType() ==
453 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { 454 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) {
454 return OfflinerImmediateStartStatus::NO_CONNECTION; 455 return OfflinerImmediateStartStatus::NO_CONNECTION;
455 } 456 }
456 457
457 // Start processing with manufactured conservative battery conditions 458 // Start processing with manufactured conservative battery conditions
458 // (i.e., assume no battery). 459 // (i.e., assume no battery).
459 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). 460 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java).
460 DeviceConditions device_conditions(false, 0, GetConnectionType()); 461 DeviceConditions device_conditions(false, 0, GetConnectionType());
461 if (StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback))) 462 if (StartProcessing(false /* is_background_scheduled */, device_conditions,
463 base::Bind(&EmptySchedulerCallback)))
462 return OfflinerImmediateStartStatus::STARTED; 464 return OfflinerImmediateStartStatus::STARTED;
463 else 465 else
464 return OfflinerImmediateStartStatus::NOT_ACCEPTED; 466 return OfflinerImmediateStartStatus::NOT_ACCEPTED;
465 } 467 }
466 468
467 void RequestCoordinator::TryNextRequest() { 469 void RequestCoordinator::TryNextRequest() {
468 // If there is no time left in the budget, return to the scheduler. 470 // If there is no time left in the budget, return to the scheduler.
469 // We do not remove the pending task that was set up earlier in case 471 // We do not remove the pending task that was set up earlier in case
470 // we run out of time, so the background scheduler will return to us 472 // we run out of time, so the background scheduler will return to us
471 // at the next opportunity to run background tasks. 473 // at the next opportunity to run background tasks.
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 695
694 ClientPolicyController* RequestCoordinator::GetPolicyController() { 696 ClientPolicyController* RequestCoordinator::GetPolicyController() {
695 return policy_controller_.get(); 697 return policy_controller_.get();
696 } 698 }
697 699
698 void RequestCoordinator::Shutdown() { 700 void RequestCoordinator::Shutdown() {
699 network_quality_estimator_ = nullptr; 701 network_quality_estimator_ = nullptr;
700 } 702 }
701 703
702 } // namespace offline_pages 704 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698