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 | |
Charlie Harrison
2017/05/26 19:31:34
keep the whitespace
Bryan McQuade
2017/05/26 20:07:32
Done
| |
114 void MetricsWebContentsObserver::RegisterInputEventObserver( | 123 void MetricsWebContentsObserver::RegisterInputEventObserver( |
115 content::RenderViewHost* host) { | 124 content::RenderViewHost* host) { |
116 if (host != nullptr) | 125 if (host != nullptr) |
117 host->GetWidget()->AddInputEventObserver(this); | 126 host->GetWidget()->AddInputEventObserver(this); |
118 } | 127 } |
119 | 128 |
120 void MetricsWebContentsObserver::UnregisterInputEventObserver( | 129 void MetricsWebContentsObserver::UnregisterInputEventObserver( |
121 content::RenderViewHost* host) { | 130 content::RenderViewHost* host) { |
122 if (host != nullptr) | 131 if (host != nullptr) |
123 host->GetWidget()->RemoveInputEventObserver(this); | 132 host->GetWidget()->RemoveInputEventObserver(this); |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 observer_->RemoveTestingObserver(this); | 693 observer_->RemoveTestingObserver(this); |
685 observer_ = nullptr; | 694 observer_ = nullptr; |
686 } | 695 } |
687 } | 696 } |
688 | 697 |
689 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { | 698 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { |
690 observer_ = nullptr; | 699 observer_ = nullptr; |
691 } | 700 } |
692 | 701 |
693 } // namespace page_load_metrics | 702 } // namespace page_load_metrics |
OLD | NEW |