| 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 (background_time_.is_null()) | 162 if (background_time_.is_null()) { |
| 163 // Make sure we either started in the foreground and haven't been |
| 164 // foregrounded yet, or started in the background and have already been |
| 165 // foregrounded. |
| 166 DCHECK_EQ(started_in_foreground_, foreground_time_.is_null()); |
| 163 background_time_ = base::TimeTicks::Now(); | 167 background_time_ = base::TimeTicks::Now(); |
| 168 } |
| 164 } | 169 } |
| 165 | 170 |
| 166 void PageLoadTracker::WebContentsShown() { | 171 void PageLoadTracker::WebContentsShown() { |
| 167 // Only log the first time we foreground in a given page load. | 172 // Only log the first time we foreground in a given page load. |
| 168 if (foreground_time_.is_null()) | 173 if (foreground_time_.is_null()) { |
| 174 // Make sure we either started in the background and haven't been |
| 175 // backgrounded yet, or started in the foreground and have already been |
| 176 // backgrounded. |
| 177 DCHECK_NE(started_in_foreground_, background_time_.is_null()); |
| 169 foreground_time_ = base::TimeTicks::Now(); | 178 foreground_time_ = base::TimeTicks::Now(); |
| 179 } |
| 170 } | 180 } |
| 171 | 181 |
| 172 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { | 182 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { |
| 173 // TODO(bmcquade): To improve accuracy, consider adding commit time to | 183 // TODO(bmcquade): To improve accuracy, consider adding commit time to |
| 174 // NavigationHandle. Taking a timestamp here should be close enough for now. | 184 // NavigationHandle. Taking a timestamp here should be close enough for now. |
| 175 commit_time_ = base::TimeTicks::Now(); | 185 commit_time_ = base::TimeTicks::Now(); |
| 176 committed_url_ = navigation_handle->GetURL(); | 186 committed_url_ = navigation_handle->GetURL(); |
| 177 for (const auto& observer : observers_) { | 187 for (const auto& observer : observers_) { |
| 178 observer->OnCommit(navigation_handle); | 188 observer->OnCommit(navigation_handle); |
| 179 } | 189 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 content::NavigationHandle* navigation_handle) { | 442 content::NavigationHandle* navigation_handle) { |
| 433 if (!navigation_handle->IsInMainFrame()) | 443 if (!navigation_handle->IsInMainFrame()) |
| 434 return; | 444 return; |
| 435 auto it = provisional_loads_.find(navigation_handle); | 445 auto it = provisional_loads_.find(navigation_handle); |
| 436 if (it == provisional_loads_.end()) | 446 if (it == provisional_loads_.end()) |
| 437 return; | 447 return; |
| 438 it->second->Redirect(navigation_handle); | 448 it->second->Redirect(navigation_handle); |
| 439 } | 449 } |
| 440 | 450 |
| 441 void MetricsWebContentsObserver::WasShown() { | 451 void MetricsWebContentsObserver::WasShown() { |
| 452 if (in_foreground_) |
| 453 return; |
| 442 in_foreground_ = true; | 454 in_foreground_ = true; |
| 443 if (committed_load_) | 455 if (committed_load_) |
| 444 committed_load_->WebContentsShown(); | 456 committed_load_->WebContentsShown(); |
| 445 for (const auto& kv : provisional_loads_) { | 457 for (const auto& kv : provisional_loads_) { |
| 446 kv.second->WebContentsShown(); | 458 kv.second->WebContentsShown(); |
| 447 } | 459 } |
| 448 } | 460 } |
| 449 | 461 |
| 450 void MetricsWebContentsObserver::WasHidden() { | 462 void MetricsWebContentsObserver::WasHidden() { |
| 463 if (!in_foreground_) |
| 464 return; |
| 451 in_foreground_ = false; | 465 in_foreground_ = false; |
| 452 if (committed_load_) | 466 if (committed_load_) |
| 453 committed_load_->WebContentsHidden(); | 467 committed_load_->WebContentsHidden(); |
| 454 for (const auto& kv : provisional_loads_) { | 468 for (const auto& kv : provisional_loads_) { |
| 455 kv.second->WebContentsHidden(); | 469 kv.second->WebContentsHidden(); |
| 456 } | 470 } |
| 457 } | 471 } |
| 458 | 472 |
| 459 // This will occur when the process for the main RenderFrameHost exits, either | 473 // This will occur when the process for the main RenderFrameHost exits, either |
| 460 // normally or from a crash. We eagerly log data from the last committed load if | 474 // normally or from a crash. We eagerly log data from the last committed load if |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 564 |
| 551 if (!committed_load_->UpdateTiming(timing)) { | 565 if (!committed_load_->UpdateTiming(timing)) { |
| 552 // If the page load tracker cannot update its timing, something is wrong | 566 // If the page load tracker cannot update its timing, something is wrong |
| 553 // with the IPC (it's from another load, or it's invalid in some other way). | 567 // with the IPC (it's from another load, or it's invalid in some other way). |
| 554 // We expect this to be a rare occurrence. | 568 // We expect this to be a rare occurrence. |
| 555 RecordInternalError(ERR_BAD_TIMING_IPC); | 569 RecordInternalError(ERR_BAD_TIMING_IPC); |
| 556 } | 570 } |
| 557 } | 571 } |
| 558 | 572 |
| 559 } // namespace page_load_metrics | 573 } // namespace page_load_metrics |
| OLD | NEW |