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 "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "components/offline_pages/background/offliner_factory.h" | 16 #include "components/offline_pages/background/offliner_factory.h" |
17 #include "components/offline_pages/background/offliner_policy.h" | 17 #include "components/offline_pages/background/offliner_policy.h" |
18 #include "components/offline_pages/background/request_picker.h" | 18 #include "components/offline_pages/background/request_picker.h" |
19 #include "components/offline_pages/background/save_page_request.h" | 19 #include "components/offline_pages/background/save_page_request.h" |
20 #include "components/offline_pages/client_policy_controller.h" | 20 #include "components/offline_pages/client_policy_controller.h" |
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 kDisabledTaskRecheckSeconds = 5 * 60; | |
Dmitry Titov
2016/10/10 17:29:45
I think this needs to be a much shorter interval.
Pete Williamson
2016/10/10 19:45:17
Done.
| |
28 | 29 |
29 // Records the final request status UMA for an offlining request. This should | 30 // Records the final request status UMA for an offlining request. This should |
30 // only be called once per Offliner::LoadAndSave request. | 31 // only be called once per Offliner::LoadAndSave request. |
31 void RecordOfflinerResultUMA(const ClientId& client_id, | 32 void RecordOfflinerResultUMA(const ClientId& client_id, |
32 Offliner::RequestStatus request_status) { | 33 Offliner::RequestStatus request_status) { |
33 // TODO(dougarnett): Consider exposing AddHistogramSuffix from | 34 // TODO(dougarnett): Consider exposing AddHistogramSuffix from |
34 // offline_page_model_impl.cc as visible utility method. | 35 // offline_page_model_impl.cc as visible utility method. |
35 std::string histogram_name("OfflinePages.Background.OfflinerRequestStatus"); | 36 std::string histogram_name("OfflinePages.Background.OfflinerRequestStatus"); |
36 if (!client_id.name_space.empty()) { | 37 if (!client_id.name_space.empty()) { |
37 histogram_name += "." + client_id.name_space; | 38 histogram_name += "." + client_id.name_space; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 } | 454 } |
454 } | 455 } |
455 | 456 |
456 void RequestCoordinator::RequestNotPicked( | 457 void RequestCoordinator::RequestNotPicked( |
457 bool non_user_requested_tasks_remaining) { | 458 bool non_user_requested_tasks_remaining) { |
458 is_starting_ = false; | 459 is_starting_ = false; |
459 | 460 |
460 // Clear the outstanding "safety" task in the scheduler. | 461 // Clear the outstanding "safety" task in the scheduler. |
461 scheduler_->Unschedule(); | 462 scheduler_->Unschedule(); |
462 | 463 |
463 if (non_user_requested_tasks_remaining) | 464 // If disabled tasks remain, post a new safety task for 5 min from now. |
465 if (disabled_requests_.size() > 0) { | |
466 scheduler_->BackupSchedule(GetTriggerConditions(kUserRequest), | |
467 kDisabledTaskRecheckSeconds); | |
468 } else if (non_user_requested_tasks_remaining) { | |
469 // If we don't have any of those, check for non-user-requested tasks. | |
464 scheduler_->Schedule(GetTriggerConditions(!kUserRequest)); | 470 scheduler_->Schedule(GetTriggerConditions(!kUserRequest)); |
471 } | |
472 | |
465 // Let the scheduler know we are done processing. | 473 // Let the scheduler know we are done processing. |
466 scheduler_callback_.Run(true); | 474 scheduler_callback_.Run(true); |
467 } | 475 } |
468 | 476 |
469 void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { | 477 void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { |
470 // Check that offlining didn't get cancelled while performing some async | 478 // Check that offlining didn't get cancelled while performing some async |
471 // steps. | 479 // steps. |
472 if (is_stopped_) | 480 if (is_stopped_) |
473 return; | 481 return; |
474 | 482 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 break; | 584 break; |
577 default: | 585 default: |
578 // Make explicit choice about new status codes that actually reach here. | 586 // Make explicit choice about new status codes that actually reach here. |
579 // Their default is no further processing in this service window. | 587 // Their default is no further processing in this service window. |
580 NOTREACHED(); | 588 NOTREACHED(); |
581 } | 589 } |
582 } | 590 } |
583 | 591 |
584 void RequestCoordinator::EnableForOffliner(int64_t request_id) { | 592 void RequestCoordinator::EnableForOffliner(int64_t request_id) { |
585 disabled_requests_.erase(request_id); | 593 disabled_requests_.erase(request_id); |
594 // If we are not busy, start processing right away. | |
595 StartProcessingIfConnected(); | |
586 } | 596 } |
587 | 597 |
588 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {} | 598 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) { |
599 // TODO: Remove the request, but send out SUCCEEDED instead of removed. | |
600 } | |
589 | 601 |
590 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( | 602 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( |
591 const bool user_requested) { | 603 const bool user_requested) { |
592 return Scheduler::TriggerConditions( | 604 return Scheduler::TriggerConditions( |
593 policy_->PowerRequired(user_requested), | 605 policy_->PowerRequired(user_requested), |
594 policy_->BatteryPercentageRequired(user_requested), | 606 policy_->BatteryPercentageRequired(user_requested), |
595 policy_->UnmeteredNetworkRequired(user_requested)); | 607 policy_->UnmeteredNetworkRequired(user_requested)); |
596 } | 608 } |
597 | 609 |
598 void RequestCoordinator::AddObserver(Observer* observer) { | 610 void RequestCoordinator::AddObserver(Observer* observer) { |
(...skipping 26 matching lines...) Expand all Loading... | |
625 | 637 |
626 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 638 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
627 return policy_controller_.get(); | 639 return policy_controller_.get(); |
628 } | 640 } |
629 | 641 |
630 void RequestCoordinator::Shutdown() { | 642 void RequestCoordinator::Shutdown() { |
631 network_quality_estimator_ = nullptr; | 643 network_quality_estimator_ = nullptr; |
632 } | 644 } |
633 | 645 |
634 } // namespace offline_pages | 646 } // namespace offline_pages |
OLD | NEW |