Chromium Code Reviews| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 const char kAbortChainSizeSameURL[] = | 46 const char kAbortChainSizeSameURL[] = |
| 47 "PageLoad.Internal.ProvisionalAbortChainSize.SameURL"; | 47 "PageLoad.Internal.ProvisionalAbortChainSize.SameURL"; |
| 48 const char kAbortChainSizeNoCommit[] = | 48 const char kAbortChainSizeNoCommit[] = |
| 49 "PageLoad.Internal.ProvisionalAbortChainSize.NoCommit"; | 49 "PageLoad.Internal.ProvisionalAbortChainSize.NoCommit"; |
| 50 const char kClientRedirectFirstPaintToNavigation[] = | 50 const char kClientRedirectFirstPaintToNavigation[] = |
| 51 "PageLoad.Internal.ClientRedirect.FirstPaintToNavigation"; | 51 "PageLoad.Internal.ClientRedirect.FirstPaintToNavigation"; |
| 52 const char kClientRedirectWithoutPaint[] = | 52 const char kClientRedirectWithoutPaint[] = |
| 53 "PageLoad.Internal.ClientRedirect.NavigationWithoutPaint"; | 53 "PageLoad.Internal.ClientRedirect.NavigationWithoutPaint"; |
| 54 const char kCommitToCompleteNoTimingIPCs[] = | 54 const char kCommitToCompleteNoTimingIPCs[] = |
| 55 "PageLoad.Internal.CommitToComplete.NoTimingIPCs"; | 55 "PageLoad.Internal.CommitToComplete.NoTimingIPCs"; |
| 56 const char kPageLoadCompletedAfterAppBackground[] = | |
| 57 "PageLoad.Internal.PageLoadCompleted.AfterAppBackground"; | |
| 56 | 58 |
| 57 } // namespace internal | 59 } // namespace internal |
| 58 | 60 |
| 59 namespace { | 61 namespace { |
| 60 | 62 |
| 61 // Helper to allow use of Optional<> values in LOG() messages. | 63 // Helper to allow use of Optional<> values in LOG() messages. |
| 62 std::ostream& operator<<(std::ostream& os, | 64 std::ostream& operator<<(std::ostream& os, |
| 63 const base::Optional<base::TimeDelta>& opt) { | 65 const base::Optional<base::TimeDelta>& opt) { |
| 64 if (opt) | 66 if (opt) |
| 65 os << opt.value(); | 67 os << opt.value(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 } // namespace | 242 } // namespace |
| 241 | 243 |
| 242 PageLoadTracker::PageLoadTracker( | 244 PageLoadTracker::PageLoadTracker( |
| 243 bool in_foreground, | 245 bool in_foreground, |
| 244 PageLoadMetricsEmbedderInterface* embedder_interface, | 246 PageLoadMetricsEmbedderInterface* embedder_interface, |
| 245 const GURL& currently_committed_url, | 247 const GURL& currently_committed_url, |
| 246 content::NavigationHandle* navigation_handle, | 248 content::NavigationHandle* navigation_handle, |
| 247 int aborted_chain_size, | 249 int aborted_chain_size, |
| 248 int aborted_chain_size_same_url) | 250 int aborted_chain_size_same_url) |
| 249 : did_stop_tracking_(false), | 251 : did_stop_tracking_(false), |
| 252 app_entered_background_(false), | |
| 250 navigation_start_(navigation_handle->NavigationStart()), | 253 navigation_start_(navigation_handle->NavigationStart()), |
| 251 url_(navigation_handle->GetURL()), | 254 url_(navigation_handle->GetURL()), |
| 252 abort_type_(ABORT_NONE), | 255 abort_type_(ABORT_NONE), |
| 253 started_in_foreground_(in_foreground), | 256 started_in_foreground_(in_foreground), |
| 254 aborted_chain_size_(aborted_chain_size), | 257 aborted_chain_size_(aborted_chain_size), |
| 255 aborted_chain_size_same_url_(aborted_chain_size_same_url), | 258 aborted_chain_size_same_url_(aborted_chain_size_same_url), |
| 256 embedder_interface_(embedder_interface) { | 259 embedder_interface_(embedder_interface) { |
| 257 DCHECK(!navigation_handle->HasCommitted()); | 260 DCHECK(!navigation_handle->HasCommitted()); |
| 258 embedder_interface_->RegisterObservers(this); | 261 embedder_interface_->RegisterObservers(this); |
| 259 for (const auto& observer : observers_) { | 262 for (const auto& observer : observers_) { |
| 260 observer->OnStart(navigation_handle, currently_committed_url, | 263 observer->OnStart(navigation_handle, currently_committed_url, |
| 261 started_in_foreground_); | 264 started_in_foreground_); |
| 262 } | 265 } |
| 263 } | 266 } |
| 264 | 267 |
| 265 PageLoadTracker::~PageLoadTracker() { | 268 PageLoadTracker::~PageLoadTracker() { |
| 269 if (app_entered_background_) { | |
| 270 UMA_HISTOGRAM_BOOLEAN(internal::kPageLoadCompletedAfterAppBackground, true); | |
|
Alexei Svitkine (slow)
2016/07/29 17:31:27
Each histogram macro resolves to a lot of machine
Bryan McQuade
2016/07/29 17:48:10
Ah, right, thanks for reminding me about this. Don
| |
| 271 } | |
| 272 | |
| 266 if (did_stop_tracking_) | 273 if (did_stop_tracking_) |
| 267 return; | 274 return; |
| 268 | 275 |
| 269 if (commit_time_.is_null()) { | 276 if (commit_time_.is_null()) { |
| 270 if (!failed_provisional_load_info_) | 277 if (!failed_provisional_load_info_) |
| 271 RecordInternalError(ERR_NO_COMMIT_OR_FAILED_PROVISIONAL_LOAD); | 278 RecordInternalError(ERR_NO_COMMIT_OR_FAILED_PROVISIONAL_LOAD); |
| 272 | 279 |
| 273 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their | 280 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their |
| 274 // chain length added to the next navigation. Take care not to double count | 281 // chain length added to the next navigation. Take care not to double count |
| 275 // them. Also do not double count committed loads, which call this already. | 282 // them. Also do not double count committed loads, which call this already. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 observer->OnRedirect(navigation_handle); | 398 observer->OnRedirect(navigation_handle); |
| 392 } | 399 } |
| 393 } | 400 } |
| 394 | 401 |
| 395 void PageLoadTracker::OnInputEvent(const blink::WebInputEvent& event) { | 402 void PageLoadTracker::OnInputEvent(const blink::WebInputEvent& event) { |
| 396 for (const auto& observer : observers_) { | 403 for (const auto& observer : observers_) { |
| 397 observer->OnUserInput(event); | 404 observer->OnUserInput(event); |
| 398 } | 405 } |
| 399 } | 406 } |
| 400 | 407 |
| 408 void PageLoadTracker::FlushMetricsOnAppEnterBackground() { | |
| 409 if (!app_entered_background_) { | |
| 410 UMA_HISTOGRAM_BOOLEAN(internal::kPageLoadCompletedAfterAppBackground, | |
| 411 false); | |
| 412 app_entered_background_ = true; | |
| 413 } | |
| 414 } | |
| 415 | |
| 401 void PageLoadTracker::NotifyClientRedirectTo( | 416 void PageLoadTracker::NotifyClientRedirectTo( |
| 402 const PageLoadTracker& destination) { | 417 const PageLoadTracker& destination) { |
| 403 if (timing_.first_paint) { | 418 if (timing_.first_paint) { |
| 404 base::TimeTicks first_paint_time = | 419 base::TimeTicks first_paint_time = |
| 405 navigation_start() + timing_.first_paint.value(); | 420 navigation_start() + timing_.first_paint.value(); |
| 406 base::TimeDelta first_paint_to_navigation; | 421 base::TimeDelta first_paint_to_navigation; |
| 407 if (destination.navigation_start() > first_paint_time) | 422 if (destination.navigation_start() > first_paint_time) |
| 408 first_paint_to_navigation = | 423 first_paint_to_navigation = |
| 409 destination.navigation_start() - first_paint_time; | 424 destination.navigation_start() - first_paint_time; |
| 410 PAGE_LOAD_HISTOGRAM(internal::kClientRedirectFirstPaintToNavigation, | 425 PAGE_LOAD_HISTOGRAM(internal::kClientRedirectFirstPaintToNavigation, |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 void MetricsWebContentsObserver::OnInputEvent( | 813 void MetricsWebContentsObserver::OnInputEvent( |
| 799 const blink::WebInputEvent& event) { | 814 const blink::WebInputEvent& event) { |
| 800 // Ignore browser navigation or reload which comes with type Undefined. | 815 // Ignore browser navigation or reload which comes with type Undefined. |
| 801 if (event.type == blink::WebInputEvent::Type::Undefined) | 816 if (event.type == blink::WebInputEvent::Type::Undefined) |
| 802 return; | 817 return; |
| 803 | 818 |
| 804 if (committed_load_) | 819 if (committed_load_) |
| 805 committed_load_->OnInputEvent(event); | 820 committed_load_->OnInputEvent(event); |
| 806 } | 821 } |
| 807 | 822 |
| 823 void MetricsWebContentsObserver::FlushMetricsOnAppEnterBackground() { | |
| 824 if (committed_load_) | |
| 825 committed_load_->FlushMetricsOnAppEnterBackground(); | |
| 826 for (const auto& kv : provisional_loads_) { | |
| 827 kv.second->FlushMetricsOnAppEnterBackground(); | |
| 828 } | |
| 829 for (const auto& tracker : aborted_provisional_loads_) { | |
| 830 tracker->FlushMetricsOnAppEnterBackground(); | |
| 831 } | |
| 832 } | |
| 833 | |
| 808 void MetricsWebContentsObserver::DidRedirectNavigation( | 834 void MetricsWebContentsObserver::DidRedirectNavigation( |
| 809 content::NavigationHandle* navigation_handle) { | 835 content::NavigationHandle* navigation_handle) { |
| 810 if (!navigation_handle->IsInMainFrame()) | 836 if (!navigation_handle->IsInMainFrame()) |
| 811 return; | 837 return; |
| 812 auto it = provisional_loads_.find(navigation_handle); | 838 auto it = provisional_loads_.find(navigation_handle); |
| 813 if (it == provisional_loads_.end()) | 839 if (it == provisional_loads_.end()) |
| 814 return; | 840 return; |
| 815 it->second->Redirect(navigation_handle); | 841 it->second->Redirect(navigation_handle); |
| 816 } | 842 } |
| 817 | 843 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) | 978 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) |
| 953 return false; | 979 return false; |
| 954 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 980 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
| 955 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") | 981 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") |
| 956 return false; | 982 return false; |
| 957 } | 983 } |
| 958 return true; | 984 return true; |
| 959 } | 985 } |
| 960 | 986 |
| 961 } // namespace page_load_metrics | 987 } // namespace page_load_metrics |
| OLD | NEW |