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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 | 86 |
| 87 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); | 87 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); |
| 88 if (!metrics) { | 88 if (!metrics) { |
| 89 metrics = new MetricsWebContentsObserver(web_contents, | 89 metrics = new MetricsWebContentsObserver(web_contents, |
| 90 std::move(embedder_interface)); | 90 std::move(embedder_interface)); |
| 91 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); | 91 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); |
| 92 } | 92 } |
| 93 return metrics; | 93 return metrics; |
| 94 } | 94 } |
| 95 | 95 |
| 96 MetricsWebContentsObserver::~MetricsWebContentsObserver() { | 96 MetricsWebContentsObserver::~MetricsWebContentsObserver() {} |
| 97 | |
| 98 void MetricsWebContentsObserver::WebContentsDestroyed() { | |
| 97 // TODO(csharrison): Use a more user-initiated signal for CLOSE. | 99 // TODO(csharrison): Use a more user-initiated signal for CLOSE. |
| 98 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated()); | 100 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated()); |
| 99 | 101 |
| 102 // We tear down PageLoadTrackers in WebContentsDestroyed, rather than in the | |
| 103 // destructor, since |web_contents()| returns nullptr in the destructor, and | |
| 104 // PageLoadMetricsObservers can cause code to execute that wants to be able to | |
|
Charlie Harrison
2017/05/26 19:31:34
which code? It would be nice to be specific here i
Bryan McQuade
2017/05/26 20:07:32
any access to web_contents() in the context of a W
| |
| 105 // access the current WebContents. | |
| 106 committed_load_ = nullptr; | |
| 107 provisional_loads_.clear(); | |
| 108 aborted_provisional_loads_.clear(); | |
| 109 | |
| 100 for (auto& observer : testing_observers_) | 110 for (auto& observer : testing_observers_) |
| 101 observer.OnGoingAway(); | 111 observer.OnGoingAway(); |
| 102 } | 112 } |
| 103 | |
| 104 void MetricsWebContentsObserver::RegisterInputEventObserver( | 113 void MetricsWebContentsObserver::RegisterInputEventObserver( |
| 105 content::RenderViewHost* host) { | 114 content::RenderViewHost* host) { |
| 106 if (host != nullptr) | 115 if (host != nullptr) |
| 107 host->GetWidget()->AddInputEventObserver(this); | 116 host->GetWidget()->AddInputEventObserver(this); |
| 108 } | 117 } |
| 109 | 118 |
| 110 void MetricsWebContentsObserver::UnregisterInputEventObserver( | 119 void MetricsWebContentsObserver::UnregisterInputEventObserver( |
| 111 content::RenderViewHost* host) { | 120 content::RenderViewHost* host) { |
| 112 if (host != nullptr) | 121 if (host != nullptr) |
| 113 host->GetWidget()->RemoveInputEventObserver(this); | 122 host->GetWidget()->RemoveInputEventObserver(this); |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 observer_->RemoveTestingObserver(this); | 683 observer_->RemoveTestingObserver(this); |
| 675 observer_ = nullptr; | 684 observer_ = nullptr; |
| 676 } | 685 } |
| 677 } | 686 } |
| 678 | 687 |
| 679 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { | 688 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { |
| 680 observer_ = nullptr; | 689 observer_ = nullptr; |
| 681 } | 690 } |
| 682 | 691 |
| 683 } // namespace page_load_metrics | 692 } // namespace page_load_metrics |
| OLD | NEW |