OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/net/loading_predictor_observer.h" | 5 #include "chrome/browser/net/loading_predictor_observer.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 class WebContents; | 19 class WebContents; |
20 } | 20 } |
21 | 21 |
22 using content::BrowserThread; | 22 using content::BrowserThread; |
23 using predictors::LoadingPredictor; | 23 using predictors::LoadingPredictor; |
24 using predictors::ResourcePrefetchPredictor; | 24 using predictors::ResourcePrefetchPredictor; |
25 using predictors::LoadingDataCollector; | |
25 using URLRequestSummary = | 26 using URLRequestSummary = |
26 predictors::ResourcePrefetchPredictor::URLRequestSummary; | 27 predictors::ResourcePrefetchPredictor::URLRequestSummary; |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // Enum for measuring statistics pertaining to observed request, responses and | 31 // Enum for measuring statistics pertaining to observed request, responses and |
31 // redirects. | 32 // redirects. |
32 enum RequestStats { | 33 enum RequestStats { |
33 REQUEST_STATS_TOTAL_RESPONSES = 0, | 34 REQUEST_STATS_TOTAL_RESPONSES = 0, |
34 REQUEST_STATS_TOTAL_PROCESSED_RESPONSES = 1, | 35 REQUEST_STATS_TOTAL_PROCESSED_RESPONSES = 1, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 void LoadingPredictorObserver::OnRequestStarted( | 92 void LoadingPredictorObserver::OnRequestStarted( |
92 net::URLRequest* request, | 93 net::URLRequest* request, |
93 content::ResourceType resource_type, | 94 content::ResourceType resource_type, |
94 const content::ResourceRequestInfo::WebContentsGetter& | 95 const content::ResourceRequestInfo::WebContentsGetter& |
95 web_contents_getter) { | 96 web_contents_getter) { |
96 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 97 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
97 | 98 |
98 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) | 99 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) |
99 ReportMainFrameRequestStats(MAIN_FRAME_REQUEST_STATS_TOTAL_REQUESTS); | 100 ReportMainFrameRequestStats(MAIN_FRAME_REQUEST_STATS_TOTAL_REQUESTS); |
100 | 101 |
101 if (!ResourcePrefetchPredictor::ShouldRecordRequest(request, resource_type)) | 102 if (!LoadingDataCollector::ShouldRecordRequest(request, resource_type)) |
102 return; | 103 return; |
103 | 104 |
104 auto summary = base::MakeUnique<URLRequestSummary>(); | 105 auto summary = base::MakeUnique<URLRequestSummary>(); |
105 summary->resource_url = request->original_url(); | 106 summary->resource_url = request->original_url(); |
106 summary->resource_type = resource_type; | 107 summary->resource_type = resource_type; |
107 | 108 |
108 BrowserThread::PostTask( | 109 BrowserThread::PostTask( |
109 BrowserThread::UI, FROM_HERE, | 110 BrowserThread::UI, FROM_HERE, |
110 base::BindOnce(&LoadingPredictorObserver::OnRequestStartedOnUIThread, | 111 base::BindOnce(&LoadingPredictorObserver::OnRequestStartedOnUIThread, |
111 base::Unretained(this), base::Passed(std::move(summary)), | 112 base::Unretained(this), base::Passed(std::move(summary)), |
(...skipping 11 matching lines...) Expand all Loading... | |
123 web_contents_getter) { | 124 web_contents_getter) { |
124 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 125 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
125 | 126 |
126 const content::ResourceRequestInfo* request_info = | 127 const content::ResourceRequestInfo* request_info = |
127 content::ResourceRequestInfo::ForRequest(request); | 128 content::ResourceRequestInfo::ForRequest(request); |
128 if (request_info && | 129 if (request_info && |
129 request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { | 130 request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { |
130 ReportMainFrameRequestStats(MAIN_FRAME_REQUEST_STATS_TOTAL_REDIRECTS); | 131 ReportMainFrameRequestStats(MAIN_FRAME_REQUEST_STATS_TOTAL_REDIRECTS); |
131 } | 132 } |
132 | 133 |
133 if (!ResourcePrefetchPredictor::ShouldRecordRedirect(request)) | 134 if (!LoadingDataCollector::ShouldRecordRedirect(request)) |
134 return; | 135 return; |
135 | 136 |
136 auto summary = base::MakeUnique<URLRequestSummary>(); | 137 auto summary = base::MakeUnique<URLRequestSummary>(); |
137 if (!ResourcePrefetchPredictor::URLRequestSummary::SummarizeResponse( | 138 if (!URLRequestSummary::SummarizeResponse(*request, summary.get())) { |
138 *request, summary.get())) { | |
139 return; | 139 return; |
140 } | 140 } |
141 summary->redirect_url = redirect_url; | 141 summary->redirect_url = redirect_url; |
142 | 142 |
143 BrowserThread::PostTask( | 143 BrowserThread::PostTask( |
144 BrowserThread::UI, FROM_HERE, | 144 BrowserThread::UI, FROM_HERE, |
145 base::BindOnce(&LoadingPredictorObserver::OnRequestRedirectedOnUIThread, | 145 base::BindOnce(&LoadingPredictorObserver::OnRequestRedirectedOnUIThread, |
146 base::Unretained(this), base::Passed(std::move(summary)), | 146 base::Unretained(this), base::Passed(std::move(summary)), |
147 web_contents_getter, request->first_party_for_cookies(), | 147 web_contents_getter, request->first_party_for_cookies(), |
148 request->creation_time())); | 148 request->creation_time())); |
(...skipping 12 matching lines...) Expand all Loading... | |
161 | 161 |
162 ReportRequestStats(REQUEST_STATS_TOTAL_RESPONSES); | 162 ReportRequestStats(REQUEST_STATS_TOTAL_RESPONSES); |
163 | 163 |
164 const content::ResourceRequestInfo* request_info = | 164 const content::ResourceRequestInfo* request_info = |
165 content::ResourceRequestInfo::ForRequest(request); | 165 content::ResourceRequestInfo::ForRequest(request); |
166 if (request_info && | 166 if (request_info && |
167 request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { | 167 request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { |
168 ReportMainFrameRequestStats(MAIN_FRAME_REQUEST_STATS_TOTAL_RESPONSES); | 168 ReportMainFrameRequestStats(MAIN_FRAME_REQUEST_STATS_TOTAL_RESPONSES); |
169 } | 169 } |
170 | 170 |
171 if (!ResourcePrefetchPredictor::ShouldRecordResponse(request)) | 171 if (!LoadingDataCollector::ShouldRecordResponse(request)) |
172 return; | 172 return; |
173 auto summary = base::MakeUnique<URLRequestSummary>(); | 173 auto summary = base::MakeUnique<URLRequestSummary>(); |
174 if (!ResourcePrefetchPredictor::URLRequestSummary::SummarizeResponse( | 174 if (!URLRequestSummary::SummarizeResponse(*request, summary.get())) { |
175 *request, summary.get())) { | |
176 return; | 175 return; |
177 } | 176 } |
178 | 177 |
179 BrowserThread::PostTask( | 178 BrowserThread::PostTask( |
180 BrowserThread::UI, FROM_HERE, | 179 BrowserThread::UI, FROM_HERE, |
181 base::BindOnce(&LoadingPredictorObserver::OnResponseStartedOnUIThread, | 180 base::BindOnce(&LoadingPredictorObserver::OnResponseStartedOnUIThread, |
182 base::Unretained(this), base::Passed(std::move(summary)), | 181 base::Unretained(this), base::Passed(std::move(summary)), |
183 web_contents_getter, request->first_party_for_cookies(), | 182 web_contents_getter, request->first_party_for_cookies(), |
184 request->creation_time())); | 183 request->creation_time())); |
185 | 184 |
186 ReportRequestStats(REQUEST_STATS_TOTAL_PROCESSED_RESPONSES); | 185 ReportRequestStats(REQUEST_STATS_TOTAL_PROCESSED_RESPONSES); |
187 if (request_info && | 186 if (request_info && |
188 request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { | 187 request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { |
189 ReportMainFrameRequestStats(MAIN_FRAME_REQUEST_STATS_PROCESSED_RESPONSES); | 188 ReportMainFrameRequestStats(MAIN_FRAME_REQUEST_STATS_PROCESSED_RESPONSES); |
190 } | 189 } |
191 } | 190 } |
192 | 191 |
193 void LoadingPredictorObserver::OnRequestStartedOnUIThread( | 192 void LoadingPredictorObserver::OnRequestStartedOnUIThread( |
194 std::unique_ptr<URLRequestSummary> summary, | 193 std::unique_ptr<URLRequestSummary> summary, |
195 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 194 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
196 const GURL& main_frame_url, | 195 const GURL& main_frame_url, |
197 const base::TimeTicks& creation_time) const { | 196 const base::TimeTicks& creation_time) const { |
198 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 197 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
199 if (!TryToFillNavigationID(&summary->navigation_id, web_contents_getter, | 198 if (!TryToFillNavigationID(&summary->navigation_id, web_contents_getter, |
200 main_frame_url, creation_time)) { | 199 main_frame_url, creation_time)) { |
201 return; | 200 return; |
202 } | 201 } |
203 if (summary->resource_type == content::RESOURCE_TYPE_MAIN_FRAME) | 202 if (summary->resource_type == content::RESOURCE_TYPE_MAIN_FRAME) |
204 predictor_->OnMainFrameRequest(*summary); | 203 predictor_->OnMainFrameRequest(*summary); |
205 predictor_->resource_prefetch_predictor()->RecordURLRequest(*summary); | 204 predictor_->loading_data_collector()->RecordURLRequest(*summary); |
206 } | 205 } |
207 | 206 |
208 void LoadingPredictorObserver::OnRequestRedirectedOnUIThread( | 207 void LoadingPredictorObserver::OnRequestRedirectedOnUIThread( |
209 std::unique_ptr<URLRequestSummary> summary, | 208 std::unique_ptr<URLRequestSummary> summary, |
210 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 209 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
211 const GURL& main_frame_url, | 210 const GURL& main_frame_url, |
212 const base::TimeTicks& creation_time) const { | 211 const base::TimeTicks& creation_time) const { |
213 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 212 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
214 if (!TryToFillNavigationID(&summary->navigation_id, web_contents_getter, | 213 if (!TryToFillNavigationID(&summary->navigation_id, web_contents_getter, |
215 main_frame_url, creation_time)) { | 214 main_frame_url, creation_time)) { |
216 return; | 215 return; |
217 } | 216 } |
218 if (summary->resource_type == content::RESOURCE_TYPE_MAIN_FRAME) | 217 if (summary->resource_type == content::RESOURCE_TYPE_MAIN_FRAME) |
219 predictor_->OnMainFrameRedirect(*summary); | 218 predictor_->OnMainFrameRedirect(*summary); |
220 predictor_->resource_prefetch_predictor()->RecordURLRedirect(*summary); | 219 predictor_->resource_prefetch_predictor()->RecordURLRedirect(*summary); |
Benoit L
2017/06/02 12:43:59
Shouldn't this be removed?
trevordixon
2017/06/06 13:08:03
Yes. Merge mistake.
| |
220 predictor_->loading_data_collector()->RecordURLRedirect(*summary); | |
221 } | 221 } |
222 | 222 |
223 void LoadingPredictorObserver::OnResponseStartedOnUIThread( | 223 void LoadingPredictorObserver::OnResponseStartedOnUIThread( |
224 std::unique_ptr<URLRequestSummary> summary, | 224 std::unique_ptr<URLRequestSummary> summary, |
225 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 225 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
226 const GURL& main_frame_url, | 226 const GURL& main_frame_url, |
227 const base::TimeTicks& creation_time) const { | 227 const base::TimeTicks& creation_time) const { |
228 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 228 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
229 if (!TryToFillNavigationID(&summary->navigation_id, web_contents_getter, | 229 if (!TryToFillNavigationID(&summary->navigation_id, web_contents_getter, |
230 main_frame_url, creation_time)) { | 230 main_frame_url, creation_time)) { |
231 return; | 231 return; |
232 } | 232 } |
233 if (summary->resource_type == content::RESOURCE_TYPE_MAIN_FRAME) | 233 if (summary->resource_type == content::RESOURCE_TYPE_MAIN_FRAME) |
234 predictor_->OnMainFrameResponse(*summary); | 234 predictor_->OnMainFrameResponse(*summary); |
235 predictor_->resource_prefetch_predictor()->RecordURLResponse(*summary); | 235 predictor_->loading_data_collector()->RecordURLResponse(*summary); |
236 } | 236 } |
237 | 237 |
238 } // namespace chrome_browser_net | 238 } // namespace chrome_browser_net |
OLD | NEW |