OLD | NEW |
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 "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 started_in_foreground_(in_foreground), | 296 started_in_foreground_(in_foreground), |
297 page_transition_(navigation_handle->GetPageTransition()), | 297 page_transition_(navigation_handle->GetPageTransition()), |
298 num_cache_requests_(0), | 298 num_cache_requests_(0), |
299 num_network_requests_(0), | 299 num_network_requests_(0), |
300 user_gesture_(IsNavigationUserInitiated(navigation_handle)), | 300 user_gesture_(IsNavigationUserInitiated(navigation_handle)), |
301 aborted_chain_size_(aborted_chain_size), | 301 aborted_chain_size_(aborted_chain_size), |
302 aborted_chain_size_same_url_(aborted_chain_size_same_url), | 302 aborted_chain_size_same_url_(aborted_chain_size_same_url), |
303 embedder_interface_(embedder_interface) { | 303 embedder_interface_(embedder_interface) { |
304 DCHECK(!navigation_handle->HasCommitted()); | 304 DCHECK(!navigation_handle->HasCommitted()); |
305 embedder_interface_->RegisterObservers(this); | 305 embedder_interface_->RegisterObservers(this); |
| 306 |
| 307 FilterObservers(navigation_handle); |
306 for (const auto& observer : observers_) { | 308 for (const auto& observer : observers_) { |
307 observer->OnStart(navigation_handle, currently_committed_url, | 309 observer->OnStart(navigation_handle, currently_committed_url, |
308 started_in_foreground_); | 310 started_in_foreground_); |
309 } | 311 } |
310 } | 312 } |
311 | 313 |
312 PageLoadTracker::~PageLoadTracker() { | 314 PageLoadTracker::~PageLoadTracker() { |
313 if (app_entered_background_) { | 315 if (app_entered_background_) { |
314 RecordAppBackgroundPageLoadCompleted(true); | 316 RecordAppBackgroundPageLoadCompleted(true); |
315 } | 317 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 aborted_chain_size_); | 389 aborted_chain_size_); |
388 return; | 390 return; |
389 default: | 391 default: |
390 NOTREACHED() | 392 NOTREACHED() |
391 << "LogAbortChainHistograms received unexpected ui::PageTransition: " | 393 << "LogAbortChainHistograms received unexpected ui::PageTransition: " |
392 << committed_transition; | 394 << committed_transition; |
393 return; | 395 return; |
394 } | 396 } |
395 } | 397 } |
396 | 398 |
| 399 void PageLoadTracker::FilterObservers( |
| 400 content::NavigationHandle* navigation_handle) { |
| 401 auto it = observers_.begin(); |
| 402 while (it != observers_.end()) { |
| 403 if ((*it)->ShouldTrackLoad(navigation_handle) == IGNORE) { |
| 404 it = observers_.erase(it); |
| 405 } else { |
| 406 ++it; |
| 407 } |
| 408 } |
| 409 } |
| 410 |
397 void PageLoadTracker::WebContentsHidden() { | 411 void PageLoadTracker::WebContentsHidden() { |
398 // Only log the first time we background in a given page load. | 412 // Only log the first time we background in a given page load. |
399 if (background_time_.is_null()) { | 413 if (background_time_.is_null()) { |
400 // Make sure we either started in the foreground and haven't been | 414 // Make sure we either started in the foreground and haven't been |
401 // foregrounded yet, or started in the background and have already been | 415 // foregrounded yet, or started in the background and have already been |
402 // foregrounded. | 416 // foregrounded. |
403 DCHECK_EQ(started_in_foreground_, foreground_time_.is_null()); | 417 DCHECK_EQ(started_in_foreground_, foreground_time_.is_null()); |
404 background_time_ = base::TimeTicks::Now(); | 418 background_time_ = base::TimeTicks::Now(); |
405 ClampBrowserTimestampIfInterProcessTimeTickSkew(&background_time_); | 419 ClampBrowserTimestampIfInterProcessTimeTickSkew(&background_time_); |
406 } | 420 } |
(...skipping 19 matching lines...) Expand all Loading... |
426 | 440 |
427 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { | 441 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { |
428 // TODO(bmcquade): To improve accuracy, consider adding commit time to | 442 // TODO(bmcquade): To improve accuracy, consider adding commit time to |
429 // NavigationHandle. Taking a timestamp here should be close enough for now. | 443 // NavigationHandle. Taking a timestamp here should be close enough for now. |
430 commit_time_ = base::TimeTicks::Now(); | 444 commit_time_ = base::TimeTicks::Now(); |
431 ClampBrowserTimestampIfInterProcessTimeTickSkew(&commit_time_); | 445 ClampBrowserTimestampIfInterProcessTimeTickSkew(&commit_time_); |
432 url_ = navigation_handle->GetURL(); | 446 url_ = navigation_handle->GetURL(); |
433 // Some transitions (like CLIENT_REDIRECT) are only known at commit time. | 447 // Some transitions (like CLIENT_REDIRECT) are only known at commit time. |
434 page_transition_ = navigation_handle->GetPageTransition(); | 448 page_transition_ = navigation_handle->GetPageTransition(); |
435 user_gesture_ = navigation_handle->HasUserGesture(); | 449 user_gesture_ = navigation_handle->HasUserGesture(); |
| 450 |
| 451 FilterObservers(navigation_handle); |
436 for (const auto& observer : observers_) { | 452 for (const auto& observer : observers_) { |
437 observer->OnCommit(navigation_handle); | 453 observer->OnCommit(navigation_handle); |
438 } | 454 } |
439 LogAbortChainHistograms(navigation_handle); | 455 LogAbortChainHistograms(navigation_handle); |
440 } | 456 } |
441 | 457 |
442 void PageLoadTracker::FailedProvisionalLoad( | 458 void PageLoadTracker::FailedProvisionalLoad( |
443 content::NavigationHandle* navigation_handle) { | 459 content::NavigationHandle* navigation_handle) { |
444 DCHECK(!failed_provisional_load_info_); | 460 DCHECK(!failed_provisional_load_info_); |
445 failed_provisional_load_info_.reset(new FailedProvisionalLoadInfo( | 461 failed_provisional_load_info_.reset(new FailedProvisionalLoadInfo( |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 // While timings arriving for the wrong frame are expected, we do not expect | 1058 // While timings arriving for the wrong frame are expected, we do not expect |
1043 // any of the errors below. Thus, we track occurrences of all errors below, | 1059 // any of the errors below. Thus, we track occurrences of all errors below, |
1044 // rather than returning early after encountering an error. | 1060 // rather than returning early after encountering an error. |
1045 | 1061 |
1046 bool error = false; | 1062 bool error = false; |
1047 if (!committed_load_) { | 1063 if (!committed_load_) { |
1048 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); | 1064 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); |
1049 error = true; | 1065 error = true; |
1050 } | 1066 } |
1051 | 1067 |
1052 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { | |
1053 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); | |
1054 error = true; | |
1055 } | |
1056 | |
1057 if (error) | 1068 if (error) |
1058 return; | 1069 return; |
1059 | 1070 |
1060 if (!committed_load_->UpdateTiming(timing, metadata)) { | 1071 if (!committed_load_->UpdateTiming(timing, metadata)) { |
1061 // If the page load tracker cannot update its timing, something is wrong | 1072 // If the page load tracker cannot update its timing, something is wrong |
1062 // with the IPC (it's from another load, or it's invalid in some other way). | 1073 // with the IPC (it's from another load, or it's invalid in some other way). |
1063 // We expect this to be a rare occurrence. | 1074 // We expect this to be a rare occurrence. |
1064 RecordInternalError(ERR_BAD_TIMING_IPC); | 1075 RecordInternalError(ERR_BAD_TIMING_IPC); |
1065 } | 1076 } |
1066 } | 1077 } |
1067 | 1078 |
1068 bool MetricsWebContentsObserver::ShouldTrackNavigation( | 1079 bool MetricsWebContentsObserver::ShouldTrackNavigation( |
1069 content::NavigationHandle* navigation_handle) const { | 1080 content::NavigationHandle* navigation_handle) const { |
1070 DCHECK(navigation_handle->IsInMainFrame()); | 1081 DCHECK(navigation_handle->IsInMainFrame()); |
1071 DCHECK(!navigation_handle->HasCommitted() || | 1082 DCHECK(!navigation_handle->HasCommitted() || |
1072 !navigation_handle->IsSamePage()); | 1083 !navigation_handle->IsSamePage()); |
1073 | 1084 |
1074 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), | 1085 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), |
1075 navigation_handle).ShouldTrack(); | 1086 navigation_handle).ShouldTrack(); |
1076 } | 1087 } |
1077 | 1088 |
1078 } // namespace page_load_metrics | 1089 } // namespace page_load_metrics |
OLD | NEW |