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

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

Issue 2425873003: [Offline Pages] Add evaluation test support in RequestCoordinator. (Closed)
Patch Set: Addressed comments. 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 <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 test_connection_type_(), 129 test_connection_type_(),
130 offliner_(nullptr), 130 offliner_(nullptr),
131 policy_(std::move(policy)), 131 policy_(std::move(policy)),
132 factory_(std::move(factory)), 132 factory_(std::move(factory)),
133 queue_(std::move(queue)), 133 queue_(std::move(queue)),
134 scheduler_(std::move(scheduler)), 134 scheduler_(std::move(scheduler)),
135 policy_controller_(new ClientPolicyController()), 135 policy_controller_(new ClientPolicyController()),
136 network_quality_estimator_(network_quality_estimator), 136 network_quality_estimator_(network_quality_estimator),
137 active_request_(nullptr), 137 active_request_(nullptr),
138 last_offlining_status_(Offliner::RequestStatus::UNKNOWN), 138 last_offlining_status_(Offliner::RequestStatus::UNKNOWN),
139 immediate_schedule_callback_(base::Bind(&EmptySchedulerCallback)),
139 weak_ptr_factory_(this) { 140 weak_ptr_factory_(this) {
140 DCHECK(policy_ != nullptr); 141 DCHECK(policy_ != nullptr);
141 picker_.reset( 142 picker_.reset(
142 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_)); 143 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_));
143 } 144 }
144 145
145 RequestCoordinator::~RequestCoordinator() {} 146 RequestCoordinator::~RequestCoordinator() {}
146 147
147 int64_t RequestCoordinator::SavePageLater(const GURL& url, 148 int64_t RequestCoordinator::SavePageLater(const GURL& url,
148 const ClientId& client_id, 149 const ClientId& client_id,
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) 458 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G)
458 return OfflinerImmediateStartStatus::WEAK_CONNECTION; 459 return OfflinerImmediateStartStatus::WEAK_CONNECTION;
459 } else if (GetConnectionType() == 460 } else if (GetConnectionType() ==
460 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { 461 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) {
461 return OfflinerImmediateStartStatus::NO_CONNECTION; 462 return OfflinerImmediateStartStatus::NO_CONNECTION;
462 } 463 }
463 464
464 // Start processing with manufactured conservative battery conditions 465 // Start processing with manufactured conservative battery conditions
465 // (i.e., assume no battery). 466 // (i.e., assume no battery).
466 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). 467 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java).
468
467 DeviceConditions device_conditions(false, 0, GetConnectionType()); 469 DeviceConditions device_conditions(false, 0, GetConnectionType());
468 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, 470 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW,
469 device_conditions, 471 device_conditions, immediate_schedule_callback_))
470 base::Bind(&EmptySchedulerCallback)))
471 return OfflinerImmediateStartStatus::STARTED; 472 return OfflinerImmediateStartStatus::STARTED;
472 else 473 else
473 return OfflinerImmediateStartStatus::NOT_ACCEPTED; 474 return OfflinerImmediateStartStatus::NOT_ACCEPTED;
474 } 475 }
475 476
476 void RequestCoordinator::TryNextRequest() { 477 void RequestCoordinator::TryNextRequest() {
477 // If there is no time left in the budget, return to the scheduler. 478 // If there is no time left in the budget, return to the scheduler.
478 // We do not remove the pending task that was set up earlier in case 479 // We do not remove the pending task that was set up earlier in case
479 // we run out of time, so the background scheduler will return to us 480 // we run out of time, so the background scheduler will return to us
480 // at the next opportunity to run background tasks. 481 // at the next opportunity to run background tasks.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 case Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED: 640 case Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED:
640 case Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT: 641 case Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT:
641 case Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY: 642 case Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY:
642 // Consider processing another request in this service window. 643 // Consider processing another request in this service window.
643 TryNextRequest(); 644 TryNextRequest();
644 break; 645 break;
645 case Offliner::RequestStatus::FOREGROUND_CANCELED: 646 case Offliner::RequestStatus::FOREGROUND_CANCELED:
646 case Offliner::RequestStatus::PRERENDERING_CANCELED: 647 case Offliner::RequestStatus::PRERENDERING_CANCELED:
647 case Offliner::RequestStatus::PRERENDERING_FAILED: 648 case Offliner::RequestStatus::PRERENDERING_FAILED:
648 // No further processing in this service window. 649 // No further processing in this service window.
650 // Let the scheduler know we are done processing.
651 scheduler_callback_.Run(true);
649 break; 652 break;
650 default: 653 default:
651 // Make explicit choice about new status codes that actually reach here. 654 // Make explicit choice about new status codes that actually reach here.
652 // Their default is no further processing in this service window. 655 // Their default is no further processing in this service window.
653 NOTREACHED(); 656 NOTREACHED();
654 } 657 }
655 } 658 }
656 659
657 void RequestCoordinator::EnableForOffliner(int64_t request_id) { 660 void RequestCoordinator::EnableForOffliner(int64_t request_id) {
658 // Since the recent tab helper might call multiple times, ignore subsequent 661 // Since the recent tab helper might call multiple times, ignore subsequent
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 723
721 ClientPolicyController* RequestCoordinator::GetPolicyController() { 724 ClientPolicyController* RequestCoordinator::GetPolicyController() {
722 return policy_controller_.get(); 725 return policy_controller_.get();
723 } 726 }
724 727
725 void RequestCoordinator::Shutdown() { 728 void RequestCoordinator::Shutdown() {
726 network_quality_estimator_ = nullptr; 729 network_quality_estimator_ = nullptr;
727 } 730 }
728 731
729 } // namespace offline_pages 732 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698