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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 294 |
295 void PageLoadTracker::WebContentsHidden() { | 295 void PageLoadTracker::WebContentsHidden() { |
296 // Only log the first time we background in a given page load. | 296 // Only log the first time we background in a given page load. |
297 if (background_time_.is_null()) { | 297 if (background_time_.is_null()) { |
298 // Make sure we either started in the foreground and haven't been | 298 // Make sure we either started in the foreground and haven't been |
299 // foregrounded yet, or started in the background and have already been | 299 // foregrounded yet, or started in the background and have already been |
300 // foregrounded. | 300 // foregrounded. |
301 DCHECK_EQ(started_in_foreground_, foreground_time_.is_null()); | 301 DCHECK_EQ(started_in_foreground_, foreground_time_.is_null()); |
302 background_time_ = base::TimeTicks::Now(); | 302 background_time_ = base::TimeTicks::Now(); |
303 } | 303 } |
| 304 |
| 305 for (const auto& observer : observers_) |
| 306 observer->OnHidden(); |
304 } | 307 } |
305 | 308 |
306 void PageLoadTracker::WebContentsShown() { | 309 void PageLoadTracker::WebContentsShown() { |
307 // Only log the first time we foreground in a given page load. | 310 // Only log the first time we foreground in a given page load. |
308 if (foreground_time_.is_null()) { | 311 if (foreground_time_.is_null()) { |
309 // Make sure we either started in the background and haven't been | 312 // Make sure we either started in the background and haven't been |
310 // backgrounded yet, or started in the foreground and have already been | 313 // backgrounded yet, or started in the foreground and have already been |
311 // backgrounded. | 314 // backgrounded. |
312 DCHECK_NE(started_in_foreground_, background_time_.is_null()); | 315 DCHECK_NE(started_in_foreground_, background_time_.is_null()); |
313 foreground_time_ = base::TimeTicks::Now(); | 316 foreground_time_ = base::TimeTicks::Now(); |
314 } | 317 } |
| 318 |
| 319 for (const auto& observer : observers_) |
| 320 observer->OnShown(); |
315 } | 321 } |
316 | 322 |
317 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { | 323 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { |
318 // TODO(bmcquade): To improve accuracy, consider adding commit time to | 324 // TODO(bmcquade): To improve accuracy, consider adding commit time to |
319 // NavigationHandle. Taking a timestamp here should be close enough for now. | 325 // NavigationHandle. Taking a timestamp here should be close enough for now. |
320 commit_time_ = base::TimeTicks::Now(); | 326 commit_time_ = base::TimeTicks::Now(); |
321 url_ = navigation_handle->GetURL(); | 327 url_ = navigation_handle->GetURL(); |
322 for (const auto& observer : observers_) { | 328 for (const auto& observer : observers_) { |
323 observer->OnCommit(navigation_handle); | 329 observer->OnCommit(navigation_handle, started_in_foreground_); |
324 } | 330 } |
325 LogAbortChainHistograms(navigation_handle); | 331 LogAbortChainHistograms(navigation_handle); |
326 } | 332 } |
327 | 333 |
328 void PageLoadTracker::FailedProvisionalLoad( | 334 void PageLoadTracker::FailedProvisionalLoad( |
329 content::NavigationHandle* navigation_handle) { | 335 content::NavigationHandle* navigation_handle) { |
330 for (const auto& observer : observers_) { | 336 for (const auto& observer : observers_) { |
331 observer->OnFailedProvisionalLoad(navigation_handle); | 337 observer->OnFailedProvisionalLoad(navigation_handle); |
332 } | 338 } |
333 } | 339 } |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 | 731 |
726 if (!committed_load_->UpdateTiming(timing, metadata)) { | 732 if (!committed_load_->UpdateTiming(timing, metadata)) { |
727 // If the page load tracker cannot update its timing, something is wrong | 733 // If the page load tracker cannot update its timing, something is wrong |
728 // with the IPC (it's from another load, or it's invalid in some other way). | 734 // with the IPC (it's from another load, or it's invalid in some other way). |
729 // We expect this to be a rare occurrence. | 735 // We expect this to be a rare occurrence. |
730 RecordInternalError(ERR_BAD_TIMING_IPC); | 736 RecordInternalError(ERR_BAD_TIMING_IPC); |
731 } | 737 } |
732 } | 738 } |
733 | 739 |
734 } // namespace page_load_metrics | 740 } // namespace page_load_metrics |
OLD | NEW |