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

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

Issue 2324493005: [Offline Pages] Adds event logs for requests dropped due to number of start or complete attempts. (Closed)
Patch Set: Fixed a new comment and also made the new comments a bit less fragile to specific logger method nam… Created 4 years, 3 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 policy_(std::move(policy)), 87 policy_(std::move(policy)),
88 factory_(std::move(factory)), 88 factory_(std::move(factory)),
89 queue_(std::move(queue)), 89 queue_(std::move(queue)),
90 scheduler_(std::move(scheduler)), 90 scheduler_(std::move(scheduler)),
91 active_request_(nullptr), 91 active_request_(nullptr),
92 last_offlining_status_(Offliner::RequestStatus::UNKNOWN), 92 last_offlining_status_(Offliner::RequestStatus::UNKNOWN),
93 offliner_timeout_(base::TimeDelta::FromSeconds( 93 offliner_timeout_(base::TimeDelta::FromSeconds(
94 policy_->GetSinglePageTimeLimitInSeconds())), 94 policy_->GetSinglePageTimeLimitInSeconds())),
95 weak_ptr_factory_(this) { 95 weak_ptr_factory_(this) {
96 DCHECK(policy_ != nullptr); 96 DCHECK(policy_ != nullptr);
97 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), this)); 97 picker_.reset(
98 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_));
98 } 99 }
99 100
100 RequestCoordinator::~RequestCoordinator() {} 101 RequestCoordinator::~RequestCoordinator() {}
101 102
102 bool RequestCoordinator::SavePageLater( 103 bool RequestCoordinator::SavePageLater(
103 const GURL& url, const ClientId& client_id, bool user_requested) { 104 const GURL& url, const ClientId& client_id, bool user_requested) {
104 DVLOG(2) << "URL is " << url << " " << __func__; 105 DVLOG(2) << "URL is " << url << " " << __func__;
105 106
106 if (!OfflinePageModel::CanSaveURL(url)) { 107 if (!OfflinePageModel::CanSaveURL(url)) {
107 DVLOG(1) << "Not able to save page for requested url: " << url; 108 DVLOG(1) << "Not able to save page for requested url: " << url;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 190 }
190 191
191 return false; 192 return false;
192 } 193 }
193 194
194 void RequestCoordinator::AbortRequestAttempt(SavePageRequest* request) { 195 void RequestCoordinator::AbortRequestAttempt(SavePageRequest* request) {
195 request->MarkAttemptAborted(); 196 request->MarkAttemptAborted();
196 if (request->started_attempt_count() >= policy_->GetMaxStartedTries()) { 197 if (request->started_attempt_count() >= policy_->GetMaxStartedTries()) {
197 RemoveAttemptedRequest(*request, 198 RemoveAttemptedRequest(*request,
198 BackgroundSavePageResult::START_COUNT_EXCEEDED); 199 BackgroundSavePageResult::START_COUNT_EXCEEDED);
200 event_logger_.RecordDroppedSavePageRequest(
201 request->client_id().name_space,
202 BackgroundSavePageResult::START_COUNT_EXCEEDED, request->request_id());
Dmitry Titov 2016/09/12 19:43:13 I'd pull the constant into a local const variable
dougarnett 2016/09/12 20:51:49 Done.
199 } else { 203 } else {
200 queue_->UpdateRequest( 204 queue_->UpdateRequest(
201 *request, 205 *request,
202 base::Bind(&RequestCoordinator::UpdateRequestCallback, 206 base::Bind(&RequestCoordinator::UpdateRequestCallback,
203 weak_ptr_factory_.GetWeakPtr(), request->client_id())); 207 weak_ptr_factory_.GetWeakPtr(), request->client_id()));
204 } 208 }
205 } 209 }
206 210
207 void RequestCoordinator::RemoveAttemptedRequest( 211 void RequestCoordinator::RemoveAttemptedRequest(
208 const SavePageRequest& request, BackgroundSavePageResult status) { 212 const SavePageRequest& request,
213 BackgroundSavePageResult result) {
209 std::vector<int64_t> remove_requests; 214 std::vector<int64_t> remove_requests;
210 remove_requests.push_back(request.request_id()); 215 remove_requests.push_back(request.request_id());
211 queue_->RemoveRequests(remove_requests, 216 queue_->RemoveRequests(remove_requests,
212 base::Bind(&RequestCoordinator::HandleRemovedRequests, 217 base::Bind(&RequestCoordinator::HandleRemovedRequests,
213 weak_ptr_factory_.GetWeakPtr(), status)); 218 weak_ptr_factory_.GetWeakPtr(), result));
214 RecordAttemptCount(request, status); 219 RecordAttemptCount(request, result);
215 } 220 }
216 221
217 void RequestCoordinator::RemoveRequests( 222 void RequestCoordinator::RemoveRequests(
218 const std::vector<int64_t>& request_ids, 223 const std::vector<int64_t>& request_ids,
219 const RemoveRequestsCallback& callback) { 224 const RemoveRequestsCallback& callback) {
220 bool canceled = CancelActiveRequestIfItMatches(request_ids); 225 bool canceled = CancelActiveRequestIfItMatches(request_ids);
221 queue_->RemoveRequests( 226 queue_->RemoveRequests(
222 request_ids, 227 request_ids,
223 base::Bind(&RequestCoordinator::HandleRemovedRequestsAndCallback, 228 base::Bind(&RequestCoordinator::HandleRemovedRequestsAndCallback,
224 weak_ptr_factory_.GetWeakPtr(), callback, 229 weak_ptr_factory_.GetWeakPtr(), callback,
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } 474 }
470 } 475 }
471 476
472 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, 477 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request,
473 Offliner::RequestStatus status) { 478 Offliner::RequestStatus status) {
474 DVLOG(2) << "offliner finished, saved: " 479 DVLOG(2) << "offliner finished, saved: "
475 << (status == Offliner::RequestStatus::SAVED) 480 << (status == Offliner::RequestStatus::SAVED)
476 << ", status: " << static_cast<int>(status) << ", " << __func__; 481 << ", status: " << static_cast<int>(status) << ", " << __func__;
477 DCHECK_NE(status, Offliner::RequestStatus::UNKNOWN); 482 DCHECK_NE(status, Offliner::RequestStatus::UNKNOWN);
478 DCHECK_NE(status, Offliner::RequestStatus::LOADED); 483 DCHECK_NE(status, Offliner::RequestStatus::LOADED);
479 event_logger_.RecordSavePageRequestUpdated(request.client_id().name_space, 484 event_logger_.RecordOfflinerResult(request.client_id().name_space, status,
480 status, request.request_id()); 485 request.request_id());
481 last_offlining_status_ = status; 486 last_offlining_status_ = status;
482 RecordOfflinerResultUMA(request.client_id(), last_offlining_status_); 487 RecordOfflinerResultUMA(request.client_id(), last_offlining_status_);
483 watchdog_timer_.Stop(); 488 watchdog_timer_.Stop();
484 489
485 is_busy_ = false; 490 is_busy_ = false;
486 active_request_.reset(nullptr); 491 active_request_.reset(nullptr);
487 492
488 if (status == Offliner::RequestStatus::FOREGROUND_CANCELED || 493 if (status == Offliner::RequestStatus::FOREGROUND_CANCELED ||
489 status == Offliner::RequestStatus::PRERENDERING_CANCELED) { 494 status == Offliner::RequestStatus::PRERENDERING_CANCELED) {
490 // Update the request for the canceled attempt. 495 // Update the request for the canceled attempt.
491 // TODO(dougarnett): See if we can conclusively identify other attempt 496 // TODO(dougarnett): See if we can conclusively identify other attempt
492 // aborted cases to treat this way (eg, for Render Process Killed). 497 // aborted cases to treat this way (eg, for Render Process Killed).
493 SavePageRequest updated_request(request); 498 SavePageRequest updated_request(request);
494 AbortRequestAttempt(&updated_request); 499 AbortRequestAttempt(&updated_request);
495 NotifyChanged(updated_request); 500 NotifyChanged(updated_request);
496 } else if (status == Offliner::RequestStatus::SAVED) { 501 } else if (status == Offliner::RequestStatus::SAVED) {
497 // Remove the request from the queue if it succeeded. 502 // Remove the request from the queue if it succeeded.
498 RemoveAttemptedRequest(request, BackgroundSavePageResult::SUCCESS); 503 RemoveAttemptedRequest(request, BackgroundSavePageResult::SUCCESS);
499 } else if (request.completed_attempt_count() + 1 >= 504 } else if (request.completed_attempt_count() + 1 >=
500 policy_->GetMaxCompletedTries()) { 505 policy_->GetMaxCompletedTries()) {
501 // Remove from the request queue if we exceeded max retries. The +1 506 // Remove from the request queue if we exceeded max retries. The +1
502 // represents the request that just completed. Since we call 507 // represents the request that just completed. Since we call
503 // MarkAttemptCompleted within the if branches, the completed_attempt_count 508 // MarkAttemptCompleted within the if branches, the completed_attempt_count
504 // has not yet been updated when we are checking the if condition. 509 // has not yet been updated when we are checking the if condition.
505 RemoveAttemptedRequest(request, 510 RemoveAttemptedRequest(request,
506 BackgroundSavePageResult::RETRY_COUNT_EXCEEDED); 511 BackgroundSavePageResult::RETRY_COUNT_EXCEEDED);
512 event_logger_.RecordDroppedSavePageRequest(
513 request.client_id().name_space,
514 BackgroundSavePageResult::RETRY_COUNT_EXCEEDED, request.request_id());
507 } else { 515 } else {
508 // If we failed, but are not over the limit, update the request in the 516 // If we failed, but are not over the limit, update the request in the
509 // queue. 517 // queue.
510 SavePageRequest updated_request(request); 518 SavePageRequest updated_request(request);
511 updated_request.MarkAttemptCompleted(); 519 updated_request.MarkAttemptCompleted();
512 queue_->UpdateRequest(updated_request, 520 queue_->UpdateRequest(updated_request,
513 base::Bind(&RequestCoordinator::UpdateRequestCallback, 521 base::Bind(&RequestCoordinator::UpdateRequestCallback,
514 weak_ptr_factory_.GetWeakPtr(), 522 weak_ptr_factory_.GetWeakPtr(),
515 updated_request.client_id())); 523 updated_request.client_id()));
516 NotifyChanged(updated_request); 524 NotifyChanged(updated_request);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); 578 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request));
571 } 579 }
572 580
573 void RequestCoordinator::GetOffliner() { 581 void RequestCoordinator::GetOffliner() {
574 if (!offliner_) { 582 if (!offliner_) {
575 offliner_ = factory_->GetOffliner(policy_.get()); 583 offliner_ = factory_->GetOffliner(policy_.get());
576 } 584 }
577 } 585 }
578 586
579 } // namespace offline_pages 587 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698