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

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

Issue 2400393002: Set up a backup schedule request if we have deferred requests. (Closed)
Patch Set: CR feedback per Dimich 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 10 matching lines...) Expand all
21 #include "components/offline_pages/offline_page_item.h" 21 #include "components/offline_pages/offline_page_item.h"
22 #include "components/offline_pages/offline_page_model.h" 22 #include "components/offline_pages/offline_page_model.h"
23 23
24 namespace offline_pages { 24 namespace offline_pages {
25 25
26 namespace { 26 namespace {
27 const bool kUserRequest = true; 27 const bool kUserRequest = true;
28 const int kMinDurationSeconds = 1; 28 const int kMinDurationSeconds = 1;
29 const int kMaxDurationSeconds = 7 * 24 * 60 * 60; // 7 days 29 const int kMaxDurationSeconds = 7 * 24 * 60 * 60; // 7 days
30 const int kDurationBuckets = 50; 30 const int kDurationBuckets = 50;
31 const int kDisabledTaskRecheckSeconds = 5;
31 32
32 // TODO(dougarnett): Move to util location and share with model impl. 33 // TODO(dougarnett): Move to util location and share with model impl.
33 std::string AddHistogramSuffix(const ClientId& client_id, 34 std::string AddHistogramSuffix(const ClientId& client_id,
34 const char* histogram_name) { 35 const char* histogram_name) {
35 if (client_id.name_space.empty()) { 36 if (client_id.name_space.empty()) {
36 NOTREACHED(); 37 NOTREACHED();
37 return histogram_name; 38 return histogram_name;
38 } 39 }
39 std::string adjusted_histogram_name(histogram_name); 40 std::string adjusted_histogram_name(histogram_name);
40 adjusted_histogram_name += "." + client_id.name_space; 41 adjusted_histogram_name += "." + client_id.name_space;
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 } 494 }
494 } 495 }
495 496
496 void RequestCoordinator::RequestNotPicked( 497 void RequestCoordinator::RequestNotPicked(
497 bool non_user_requested_tasks_remaining) { 498 bool non_user_requested_tasks_remaining) {
498 is_starting_ = false; 499 is_starting_ = false;
499 500
500 // Clear the outstanding "safety" task in the scheduler. 501 // Clear the outstanding "safety" task in the scheduler.
501 scheduler_->Unschedule(); 502 scheduler_->Unschedule();
502 503
503 if (non_user_requested_tasks_remaining) 504 // If disabled tasks remain, post a new safety task for 5 sec from now.
505 if (disabled_requests_.size() > 0) {
506 scheduler_->BackupSchedule(GetTriggerConditions(kUserRequest),
507 kDisabledTaskRecheckSeconds);
508 } else if (non_user_requested_tasks_remaining) {
509 // If we don't have any of those, check for non-user-requested tasks.
504 scheduler_->Schedule(GetTriggerConditions(!kUserRequest)); 510 scheduler_->Schedule(GetTriggerConditions(!kUserRequest));
511 }
512
505 // Let the scheduler know we are done processing. 513 // Let the scheduler know we are done processing.
506 scheduler_callback_.Run(true); 514 scheduler_callback_.Run(true);
507 } 515 }
508 516
509 void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { 517 void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) {
510 // Check that offlining didn't get cancelled while performing some async 518 // Check that offlining didn't get cancelled while performing some async
511 // steps. 519 // steps.
512 if (is_stopped_) 520 if (is_stopped_)
513 return; 521 return;
514 522
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 break; 625 break;
618 default: 626 default:
619 // Make explicit choice about new status codes that actually reach here. 627 // Make explicit choice about new status codes that actually reach here.
620 // Their default is no further processing in this service window. 628 // Their default is no further processing in this service window.
621 NOTREACHED(); 629 NOTREACHED();
622 } 630 }
623 } 631 }
624 632
625 void RequestCoordinator::EnableForOffliner(int64_t request_id) { 633 void RequestCoordinator::EnableForOffliner(int64_t request_id) {
626 disabled_requests_.erase(request_id); 634 disabled_requests_.erase(request_id);
635 // If we are not busy, start processing right away.
636 StartProcessingIfConnected();
627 } 637 }
628 638
629 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {} 639 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {
640 // TODO: Remove the request, but send out SUCCEEDED instead of removed.
641 }
630 642
631 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( 643 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions(
632 const bool user_requested) { 644 const bool user_requested) {
633 return Scheduler::TriggerConditions( 645 return Scheduler::TriggerConditions(
634 policy_->PowerRequired(user_requested), 646 policy_->PowerRequired(user_requested),
635 policy_->BatteryPercentageRequired(user_requested), 647 policy_->BatteryPercentageRequired(user_requested),
636 policy_->UnmeteredNetworkRequired(user_requested)); 648 policy_->UnmeteredNetworkRequired(user_requested));
637 } 649 }
638 650
639 void RequestCoordinator::AddObserver(Observer* observer) { 651 void RequestCoordinator::AddObserver(Observer* observer) {
(...skipping 26 matching lines...) Expand all
666 678
667 ClientPolicyController* RequestCoordinator::GetPolicyController() { 679 ClientPolicyController* RequestCoordinator::GetPolicyController() {
668 return policy_controller_.get(); 680 return policy_controller_.get();
669 } 681 }
670 682
671 void RequestCoordinator::Shutdown() { 683 void RequestCoordinator::Shutdown() {
672 network_quality_estimator_ = nullptr; 684 network_quality_estimator_ = nullptr;
673 } 685 }
674 686
675 } // namespace offline_pages 687 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698