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

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

Issue 2429213009: Fix occasional crash in TryNextRequest (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 scheduler_callback_(base::Bind(&EmptySchedulerCallback)),
139 immediate_schedule_callback_(base::Bind(&EmptySchedulerCallback)), 140 immediate_schedule_callback_(base::Bind(&EmptySchedulerCallback)),
140 weak_ptr_factory_(this) { 141 weak_ptr_factory_(this) {
141 DCHECK(policy_ != nullptr); 142 DCHECK(policy_ != nullptr);
142 picker_.reset( 143 picker_.reset(
143 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_)); 144 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_));
144 } 145 }
145 146
146 RequestCoordinator::~RequestCoordinator() {} 147 RequestCoordinator::~RequestCoordinator() {}
147 148
148 int64_t RequestCoordinator::SavePageLater(const GURL& url, 149 int64_t RequestCoordinator::SavePageLater(const GURL& url,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 233
233 bool RequestCoordinator::CancelActiveRequestIfItMatches( 234 bool RequestCoordinator::CancelActiveRequestIfItMatches(
234 const std::vector<int64_t>& request_ids) { 235 const std::vector<int64_t>& request_ids) {
235 // If we have a request in progress and need to cancel it, call the 236 // If we have a request in progress and need to cancel it, call the
236 // pre-renderer to cancel. TODO Make sure we remove any page created by the 237 // pre-renderer to cancel. TODO Make sure we remove any page created by the
237 // prerenderer if it doesn't get the cancel in time. 238 // prerenderer if it doesn't get the cancel in time.
238 if (active_request_ != nullptr) { 239 if (active_request_ != nullptr) {
239 if (request_ids.end() != std::find(request_ids.begin(), request_ids.end(), 240 if (request_ids.end() != std::find(request_ids.begin(), request_ids.end(),
240 active_request_->request_id())) { 241 active_request_->request_id())) {
241 StopPrerendering(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED); 242 StopPrerendering(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED);
243 active_request_.reset(nullptr);
242 return true; 244 return true;
243 } 245 }
244 } 246 }
245 247
246 return false; 248 return false;
247 } 249 }
248 250
249 void RequestCoordinator::AbortRequestAttempt(SavePageRequest* request) { 251 void RequestCoordinator::AbortRequestAttempt(SavePageRequest* request) {
250 request->MarkAttemptAborted(); 252 request->MarkAttemptAborted();
251 if (request->started_attempt_count() >= policy_->GetMaxStartedTries()) { 253 if (request->started_attempt_count() >= policy_->GetMaxStartedTries()) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // If there is no time left in the budget, return to the scheduler. 480 // If there is no time left in the budget, return to the scheduler.
479 // We do not remove the pending task that was set up earlier in case 481 // We do not remove the pending task that was set up earlier in case
480 // we run out of time, so the background scheduler will return to us 482 // we run out of time, so the background scheduler will return to us
481 // at the next opportunity to run background tasks. 483 // at the next opportunity to run background tasks.
482 if (base::Time::Now() - operation_start_time_ > 484 if (base::Time::Now() - operation_start_time_ >
483 base::TimeDelta::FromSeconds( 485 base::TimeDelta::FromSeconds(
484 policy_->GetBackgroundProcessingTimeBudgetSeconds())) { 486 policy_->GetBackgroundProcessingTimeBudgetSeconds())) {
485 is_starting_ = false; 487 is_starting_ = false;
486 488
487 // Let the scheduler know we are done processing. 489 // Let the scheduler know we are done processing.
490 // TODO: Make sure the scheduler callback is valid before running it.
dougarnett 2016/10/21 16:46:02 wonder if we could base on processing_state != STO
488 scheduler_callback_.Run(true); 491 scheduler_callback_.Run(true);
489 492
490 return; 493 return;
491 } 494 }
492 495
493 // Choose a request to process that meets the available conditions. 496 // Choose a request to process that meets the available conditions.
494 // This is an async call, and returns right away. 497 // This is an async call, and returns right away.
495 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked, 498 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked,
496 weak_ptr_factory_.GetWeakPtr()), 499 weak_ptr_factory_.GetWeakPtr()),
497 base::Bind(&RequestCoordinator::RequestNotPicked, 500 base::Bind(&RequestCoordinator::RequestNotPicked,
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 753
751 ClientPolicyController* RequestCoordinator::GetPolicyController() { 754 ClientPolicyController* RequestCoordinator::GetPolicyController() {
752 return policy_controller_.get(); 755 return policy_controller_.get();
753 } 756 }
754 757
755 void RequestCoordinator::Shutdown() { 758 void RequestCoordinator::Shutdown() {
756 network_quality_estimator_ = nullptr; 759 network_quality_estimator_ = nullptr;
757 } 760 }
758 761
759 } // namespace offline_pages 762 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698