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

Side by Side Diff: net/nqe/network_quality_estimator.cc

Issue 2712443002: NQE: Move ECT computation to NotifyHeadersReceived (Closed)
Patch Set: Created 3 years, 10 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 | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "net/nqe/network_quality_estimator.h" 5 #include "net/nqe/network_quality_estimator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 return accuracy_recording_intervals_; 386 return accuracy_recording_intervals_;
387 } 387 }
388 388
389 void NetworkQualityEstimator::NotifyStartTransaction( 389 void NetworkQualityEstimator::NotifyStartTransaction(
390 const URLRequest& request) { 390 const URLRequest& request) {
391 DCHECK(thread_checker_.CalledOnValidThread()); 391 DCHECK(thread_checker_.CalledOnValidThread());
392 392
393 if (!RequestSchemeIsHTTPOrHTTPS(request)) 393 if (!RequestSchemeIsHTTPOrHTTPS(request))
394 return; 394 return;
395 395
396 throughput_analyzer_->NotifyStartTransaction(request);
397 }
398
399 void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) {
400 TRACE_EVENT0(kNetTracingCategory,
401 "NetworkQualityEstimator::NotifyHeadersReceived");
402 DCHECK(thread_checker_.CalledOnValidThread());
403
404 if (!RequestSchemeIsHTTPOrHTTPS(request) ||
405 !RequestProvidesRTTObservation(request)) {
406 return;
407 }
408
409 const base::TimeTicks now = tick_clock_->NowTicks();
410
411 // Update |estimated_quality_at_last_main_frame_| if this is a main frame 396 // Update |estimated_quality_at_last_main_frame_| if this is a main frame
412 // request. 397 // request.
413 // TODO(tbansal): Refactor this to a separate method. 398 // TODO(tbansal): Refactor this to a separate method.
414 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) { 399 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) {
400 base::TimeTicks now = tick_clock_->NowTicks();
415 last_main_frame_request_ = now; 401 last_main_frame_request_ = now;
416 402
417 ComputeEffectiveConnectionType(); 403 MaybeComputeEffectiveConnectionType();
418 effective_connection_type_at_last_main_frame_ = effective_connection_type_; 404 effective_connection_type_at_last_main_frame_ = effective_connection_type_;
419 estimated_quality_at_last_main_frame_ = network_quality_; 405 estimated_quality_at_last_main_frame_ = network_quality_;
420 406
421 RecordMetricsOnMainFrameRequest();
422 MaybeQueryExternalEstimateProvider();
423
424 // Post the tasks which will run in the future and record the estimation 407 // Post the tasks which will run in the future and record the estimation
425 // accuracy based on the observations received between now and the time of 408 // accuracy based on the observations received between now and the time of
426 // task execution. Posting the task at different intervals makes it 409 // task execution. Posting the task at different intervals makes it
427 // possible to measure the accuracy by comparing the estimate with the 410 // possible to measure the accuracy by comparing the estimate with the
428 // observations received over intervals of varying durations. 411 // observations received over intervals of varying durations.
429 for (const base::TimeDelta& measuring_delay : 412 for (const base::TimeDelta& measuring_delay :
430 GetAccuracyRecordingIntervals()) { 413 GetAccuracyRecordingIntervals()) {
431 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 414 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
432 FROM_HERE, 415 FROM_HERE,
433 base::Bind(&NetworkQualityEstimator::RecordAccuracyAfterMainFrame, 416 base::Bind(&NetworkQualityEstimator::RecordAccuracyAfterMainFrame,
434 weak_ptr_factory_.GetWeakPtr(), measuring_delay), 417 weak_ptr_factory_.GetWeakPtr(), measuring_delay),
435 measuring_delay); 418 measuring_delay);
436 } 419 }
437 UpdateSignalStrength(); 420 UpdateSignalStrength();
438 } 421 }
422 throughput_analyzer_->NotifyStartTransaction(request);
423 }
424
425 void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) {
426 TRACE_EVENT0(kNetTracingCategory,
427 "NetworkQualityEstimator::NotifyHeadersReceived");
428 DCHECK(thread_checker_.CalledOnValidThread());
429
430 if (!RequestSchemeIsHTTPOrHTTPS(request) ||
431 !RequestProvidesRTTObservation(request)) {
432 return;
433 }
434
435 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) {
436 ComputeEffectiveConnectionType();
437 RecordMetricsOnMainFrameRequest();
438 MaybeQueryExternalEstimateProvider();
439 }
439 440
440 LoadTimingInfo load_timing_info; 441 LoadTimingInfo load_timing_info;
441 request.GetLoadTimingInfo(&load_timing_info); 442 request.GetLoadTimingInfo(&load_timing_info);
442 443
443 // If the load timing info is unavailable, it probably means that the request 444 // If the load timing info is unavailable, it probably means that the request
444 // did not go over the network. 445 // did not go over the network.
445 if (load_timing_info.send_start.is_null() || 446 if (load_timing_info.send_start.is_null() ||
446 load_timing_info.receive_headers_end.is_null()) { 447 load_timing_info.receive_headers_end.is_null()) {
447 return; 448 return;
448 } 449 }
449 DCHECK(!request.response_info().was_cached); 450 DCHECK(!request.response_info().was_cached);
450 451
451 // Duration between when the resource was requested and when the response 452 // Duration between when the resource was requested and when the response
452 // headers were received. 453 // headers were received.
453 base::TimeDelta observed_http_rtt = 454 base::TimeDelta observed_http_rtt =
454 load_timing_info.receive_headers_end - load_timing_info.send_start; 455 load_timing_info.receive_headers_end - load_timing_info.send_start;
455 DCHECK_GE(observed_http_rtt, base::TimeDelta()); 456 DCHECK_GE(observed_http_rtt, base::TimeDelta());
456 if (observed_http_rtt < peak_network_quality_.http_rtt() || 457 if (observed_http_rtt < peak_network_quality_.http_rtt() ||
457 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { 458 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) {
458 peak_network_quality_ = nqe::internal::NetworkQuality( 459 peak_network_quality_ = nqe::internal::NetworkQuality(
459 observed_http_rtt, peak_network_quality_.transport_rtt(), 460 observed_http_rtt, peak_network_quality_.transport_rtt(),
460 peak_network_quality_.downstream_throughput_kbps()); 461 peak_network_quality_.downstream_throughput_kbps());
461 } 462 }
462 463
463 RttObservation http_rtt_observation(observed_http_rtt, now, 464 RttObservation http_rtt_observation(
464 signal_strength_dbm_, 465 observed_http_rtt, tick_clock_->NowTicks(), signal_strength_dbm_,
465 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); 466 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP);
466 rtt_observations_.AddObservation(http_rtt_observation); 467 rtt_observations_.AddObservation(http_rtt_observation);
467 NotifyObserversOfRTT(http_rtt_observation); 468 NotifyObserversOfRTT(http_rtt_observation);
468 } 469 }
469 470
470 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( 471 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame(
471 base::TimeDelta measuring_duration) const { 472 base::TimeDelta measuring_duration) const {
472 DCHECK(thread_checker_.CalledOnValidThread()); 473 DCHECK(thread_checker_.CalledOnValidThread());
473 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); 474 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000);
474 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration)); 475 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration));
475 476
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); 1700 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1700 downstream_throughput_kbps_observations_.AddObservation( 1701 downstream_throughput_kbps_observations_.AddObservation(
1701 throughput_observation); 1702 throughput_observation);
1702 NotifyObserversOfThroughput(throughput_observation); 1703 NotifyObserversOfThroughput(throughput_observation);
1703 } 1704 }
1704 1705
1705 ComputeEffectiveConnectionType(); 1706 ComputeEffectiveConnectionType();
1706 } 1707 }
1707 1708
1708 } // namespace net 1709 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698