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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); | 97 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); |
98 if (!metrics) { | 98 if (!metrics) { |
99 metrics = new MetricsWebContentsObserver(web_contents, create_params, | 99 metrics = new MetricsWebContentsObserver(web_contents, create_params, |
100 std::move(embedder_interface)); | 100 std::move(embedder_interface)); |
101 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); | 101 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); |
102 } | 102 } |
103 return metrics; | 103 return metrics; |
104 } | 104 } |
105 | 105 |
106 MetricsWebContentsObserver::~MetricsWebContentsObserver() { | 106 MetricsWebContentsObserver::~MetricsWebContentsObserver() {} |
| 107 |
| 108 void MetricsWebContentsObserver::WebContentsDestroyed() { |
107 // TODO(csharrison): Use a more user-initiated signal for CLOSE. | 109 // TODO(csharrison): Use a more user-initiated signal for CLOSE. |
108 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated()); | 110 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated()); |
109 | 111 |
| 112 // We tear down PageLoadTrackers in WebContentsDestroyed, rather than in the |
| 113 // destructor, since |web_contents()| returns nullptr in the destructor, and |
| 114 // PageLoadMetricsObservers can cause code to execute that wants to be able to |
| 115 // access the current WebContents. |
| 116 committed_load_ = nullptr; |
| 117 provisional_loads_.clear(); |
| 118 aborted_provisional_loads_.clear(); |
| 119 |
110 for (auto& observer : testing_observers_) | 120 for (auto& observer : testing_observers_) |
111 observer.OnGoingAway(); | 121 observer.OnGoingAway(); |
112 } | 122 } |
113 | 123 |
114 void MetricsWebContentsObserver::RegisterInputEventObserver( | 124 void MetricsWebContentsObserver::RegisterInputEventObserver( |
115 content::RenderViewHost* host) { | 125 content::RenderViewHost* host) { |
116 if (host != nullptr) | 126 if (host != nullptr) |
117 host->GetWidget()->AddInputEventObserver(this); | 127 host->GetWidget()->AddInputEventObserver(this); |
118 } | 128 } |
119 | 129 |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 observer_->RemoveTestingObserver(this); | 694 observer_->RemoveTestingObserver(this); |
685 observer_ = nullptr; | 695 observer_ = nullptr; |
686 } | 696 } |
687 } | 697 } |
688 | 698 |
689 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { | 699 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { |
690 observer_ = nullptr; | 700 observer_ = nullptr; |
691 } | 701 } |
692 | 702 |
693 } // namespace page_load_metrics | 703 } // namespace page_load_metrics |
OLD | NEW |