| 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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" | 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 aborted_chain_size_); | 152 aborted_chain_size_); |
| 153 return; | 153 return; |
| 154 default: | 154 default: |
| 155 NOTREACHED(); | 155 NOTREACHED(); |
| 156 return; | 156 return; |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 void PageLoadTracker::WebContentsHidden() { | 160 void PageLoadTracker::WebContentsHidden() { |
| 161 // Only log the first time we background in a given page load. | 161 // Only log the first time we background in a given page load. |
| 162 if (started_in_foreground_ && background_time_.is_null()) | 162 if (background_time_.is_null()) |
| 163 background_time_ = base::TimeTicks::Now(); | 163 background_time_ = base::TimeTicks::Now(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void PageLoadTracker::WebContentsShown() { | 166 void PageLoadTracker::WebContentsShown() { |
| 167 // Only log the first time we foreground in a given page load. | 167 // Only log the first time we foreground in a given page load. |
| 168 // Don't log foreground time if we started foregrounded. | 168 if (foreground_time_.is_null()) |
| 169 if (!started_in_foreground_ && foreground_time_.is_null()) | |
| 170 foreground_time_ = base::TimeTicks::Now(); | 169 foreground_time_ = base::TimeTicks::Now(); |
| 171 } | 170 } |
| 172 | 171 |
| 173 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { | 172 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { |
| 174 // TODO(bmcquade): To improve accuracy, consider adding commit time to | 173 // TODO(bmcquade): To improve accuracy, consider adding commit time to |
| 175 // NavigationHandle. Taking a timestamp here should be close enough for now. | 174 // NavigationHandle. Taking a timestamp here should be close enough for now. |
| 176 commit_time_ = base::TimeTicks::Now(); | 175 commit_time_ = base::TimeTicks::Now(); |
| 177 committed_url_ = navigation_handle->GetURL(); | 176 committed_url_ = navigation_handle->GetURL(); |
| 178 for (const auto& observer : observers_) { | 177 for (const auto& observer : observers_) { |
| 179 observer->OnCommit(navigation_handle); | 178 observer->OnCommit(navigation_handle); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 void PageLoadTracker::AddObserver( | 219 void PageLoadTracker::AddObserver( |
| 221 scoped_ptr<PageLoadMetricsObserver> observer) { | 220 scoped_ptr<PageLoadMetricsObserver> observer) { |
| 222 observers_.push_back(std::move(observer)); | 221 observers_.push_back(std::move(observer)); |
| 223 } | 222 } |
| 224 | 223 |
| 225 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { | 224 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { |
| 226 base::TimeDelta first_background_time; | 225 base::TimeDelta first_background_time; |
| 227 base::TimeDelta first_foreground_time; | 226 base::TimeDelta first_foreground_time; |
| 228 base::TimeDelta time_to_abort; | 227 base::TimeDelta time_to_abort; |
| 229 base::TimeDelta time_to_commit; | 228 base::TimeDelta time_to_commit; |
| 230 if (!background_time_.is_null() && started_in_foreground_) | 229 if (!background_time_.is_null()) |
| 231 first_background_time = background_time_ - navigation_start_; | 230 first_background_time = background_time_ - navigation_start_; |
| 232 if (!foreground_time_.is_null() && !started_in_foreground_) | 231 if (!foreground_time_.is_null()) |
| 233 first_foreground_time = foreground_time_ - navigation_start_; | 232 first_foreground_time = foreground_time_ - navigation_start_; |
| 234 if (abort_type_ != ABORT_NONE) { | 233 if (abort_type_ != ABORT_NONE) { |
| 235 DCHECK_GT(abort_time_, navigation_start_); | 234 DCHECK_GT(abort_time_, navigation_start_); |
| 236 time_to_abort = abort_time_ - navigation_start_; | 235 time_to_abort = abort_time_ - navigation_start_; |
| 237 } else { | 236 } else { |
| 238 DCHECK(abort_time_.is_null()); | 237 DCHECK(abort_time_.is_null()); |
| 239 } | 238 } |
| 240 if (!committed_url_.is_empty()) { | 239 if (!committed_url_.is_empty()) { |
| 241 DCHECK_GT(commit_time_, navigation_start_); | 240 DCHECK_GT(commit_time_, navigation_start_); |
| 242 time_to_commit = commit_time_ - navigation_start_; | 241 time_to_commit = commit_time_ - navigation_start_; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 550 |
| 552 if (!committed_load_->UpdateTiming(timing)) { | 551 if (!committed_load_->UpdateTiming(timing)) { |
| 553 // If the page load tracker cannot update its timing, something is wrong | 552 // If the page load tracker cannot update its timing, something is wrong |
| 554 // with the IPC (it's from another load, or it's invalid in some other way). | 553 // with the IPC (it's from another load, or it's invalid in some other way). |
| 555 // We expect this to be a rare occurrence. | 554 // We expect this to be a rare occurrence. |
| 556 RecordInternalError(ERR_BAD_TIMING_IPC); | 555 RecordInternalError(ERR_BAD_TIMING_IPC); |
| 557 } | 556 } |
| 558 } | 557 } |
| 559 | 558 |
| 560 } // namespace page_load_metrics | 559 } // namespace page_load_metrics |
| OLD | NEW |