Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prerender/prerender_tab_helper.h" | 5 #include "chrome/browser/prerender/prerender_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/prerender/prerender_histograms.h" | 10 #include "chrome/browser/prerender/prerender_histograms.h" |
| 11 #include "chrome/browser/prerender/prerender_local_predictor.h" | 11 #include "chrome/browser/prerender/prerender_local_predictor.h" |
| 12 #include "chrome/browser/prerender/prerender_manager.h" | 12 #include "chrome/browser/prerender/prerender_manager.h" |
| 13 #include "chrome/browser/prerender/prerender_manager_factory.h" | 13 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "components/password_manager/core/browser/password_manager.h" | 15 #include "components/password_manager/core/browser/password_manager.h" |
| 16 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
| 17 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/resource_request_details.h" | |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/frame_navigate_params.h" | 21 #include "content/public/common/frame_navigate_params.h" |
| 21 | 22 |
| 22 using content::WebContents; | 23 using content::WebContents; |
| 23 | 24 |
| 24 DEFINE_WEB_CONTENTS_USER_DATA_KEY(prerender::PrerenderTabHelper); | 25 DEFINE_WEB_CONTENTS_USER_DATA_KEY(prerender::PrerenderTabHelper); |
| 25 | 26 |
| 26 namespace prerender { | 27 namespace prerender { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 prerender_manager->IsWebContentsPrerendering(web_contents, &origin_)) { | 75 prerender_manager->IsWebContentsPrerendering(web_contents, &origin_)) { |
| 75 navigation_type_ = NAVIGATION_TYPE_PRERENDERED; | 76 navigation_type_ = NAVIGATION_TYPE_PRERENDERED; |
| 76 } else { | 77 } else { |
| 77 navigation_type_ = NAVIGATION_TYPE_NORMAL; | 78 navigation_type_ = NAVIGATION_TYPE_NORMAL; |
| 78 } | 79 } |
| 79 } | 80 } |
| 80 | 81 |
| 81 PrerenderTabHelper::~PrerenderTabHelper() { | 82 PrerenderTabHelper::~PrerenderTabHelper() { |
| 82 } | 83 } |
| 83 | 84 |
| 84 void PrerenderTabHelper::ProvisionalChangeToMainFrameUrl( | 85 void PrerenderTabHelper::DidGetRedirectForResourceRequest( |
|
davidben
2014/09/17 15:08:30
For redirects, the difference between this hook an
tburkard
2014/09/18 09:36:04
What do you mean by "previous" here?
Avi (use Gerrit)
2014/09/18 21:00:21
The difference between ProvisionalChangeToMainFram
davidben
2014/09/18 22:14:21
Sorry, that was poorly phrased. Yeah, that was wha
| |
| 85 const GURL& url, | 86 content::RenderViewHost* render_view_host, |
| 86 content::RenderFrameHost* render_frame_host) { | 87 const content::ResourceRedirectDetails& details) { |
| 87 url_ = url; | 88 if (details.resource_type != content::RESOURCE_TYPE_MAIN_FRAME) |
| 89 return; | |
| 90 | |
| 91 url_ = details.new_url; | |
| 88 RecordEvent(EVENT_MAINFRAME_CHANGE); | 92 RecordEvent(EVENT_MAINFRAME_CHANGE); |
| 89 RecordEventIfLoggedInURL(EVENT_MAINFRAME_CHANGE_DOMAIN_LOGGED_IN, url); | 93 RecordEventIfLoggedInURL(EVENT_MAINFRAME_CHANGE_DOMAIN_LOGGED_IN, url_); |
| 90 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); | 94 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); |
| 91 if (!prerender_manager) | 95 if (!prerender_manager) |
| 92 return; | 96 return; |
| 93 if (prerender_manager->IsWebContentsPrerendering(web_contents(), NULL)) | 97 if (prerender_manager->IsWebContentsPrerendering(web_contents(), NULL)) |
| 94 return; | 98 return; |
| 95 ReportTabHelperURLSeenToLocalPredictor(prerender_manager, url, | 99 ReportTabHelperURLSeenToLocalPredictor(prerender_manager, url_, |
| 96 web_contents()); | 100 web_contents()); |
| 97 } | 101 } |
| 98 | 102 |
| 99 void PrerenderTabHelper::DidCommitProvisionalLoadForFrame( | 103 void PrerenderTabHelper::DidCommitProvisionalLoadForFrame( |
| 100 content::RenderFrameHost* render_frame_host, | 104 content::RenderFrameHost* render_frame_host, |
| 101 const GURL& validated_url, | 105 const GURL& validated_url, |
| 102 content::PageTransition transition_type) { | 106 content::PageTransition transition_type) { |
| 103 if (render_frame_host->GetParent()) | 107 if (render_frame_host->GetParent()) |
| 104 return; | 108 return; |
| 105 RecordEvent(EVENT_MAINFRAME_COMMIT); | 109 RecordEvent(EVENT_MAINFRAME_COMMIT); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 RecordPerceivedPageLoadTime( | 152 RecordPerceivedPageLoadTime( |
| 149 now - pplt_load_start_, fraction_elapsed_at_swapin); | 153 now - pplt_load_start_, fraction_elapsed_at_swapin); |
| 150 } | 154 } |
| 151 } | 155 } |
| 152 | 156 |
| 153 // Reset the PPLT metric. | 157 // Reset the PPLT metric. |
| 154 pplt_load_start_ = base::TimeTicks(); | 158 pplt_load_start_ = base::TimeTicks(); |
| 155 actual_load_start_ = base::TimeTicks(); | 159 actual_load_start_ = base::TimeTicks(); |
| 156 } | 160 } |
| 157 | 161 |
| 158 void PrerenderTabHelper::DidStartProvisionalLoadForFrame( | 162 void PrerenderTabHelper::DidStartProvisionalLoadForFrame( |
|
davidben
2014/09/17 15:08:30
[Verified that, for the initial ProvisionalChangeT
| |
| 159 content::RenderFrameHost* render_frame_host, | 163 content::RenderFrameHost* render_frame_host, |
| 160 const GURL& validated_url, | 164 const GURL& validated_url, |
| 161 bool is_error_page, | 165 bool is_error_page, |
| 162 bool is_iframe_srcdoc) { | 166 bool is_iframe_srcdoc) { |
| 163 if (render_frame_host->GetParent()) | 167 if (render_frame_host->GetParent()) |
| 164 return; | 168 return; |
| 165 | 169 |
| 166 // Record PPLT state for the beginning of a new navigation. | 170 // Record PPLT state for the beginning of a new navigation. |
| 167 pplt_load_start_ = base::TimeTicks::Now(); | 171 pplt_load_start_ = base::TimeTicks::Now(); |
| 168 actual_load_start_ = base::TimeTicks(); | 172 actual_load_start_ = base::TimeTicks(); |
| 169 | 173 |
| 170 if (next_load_is_control_prerender_) { | 174 if (next_load_is_control_prerender_) { |
| 171 DCHECK_EQ(NAVIGATION_TYPE_NORMAL, navigation_type_); | 175 DCHECK_EQ(NAVIGATION_TYPE_NORMAL, navigation_type_); |
| 172 navigation_type_ = NAVIGATION_TYPE_WOULD_HAVE_BEEN_PRERENDERED; | 176 navigation_type_ = NAVIGATION_TYPE_WOULD_HAVE_BEEN_PRERENDERED; |
| 173 origin_ = next_load_origin_; | 177 origin_ = next_load_origin_; |
| 174 next_load_is_control_prerender_ = false; | 178 next_load_is_control_prerender_ = false; |
| 175 next_load_origin_ = ORIGIN_NONE; | 179 next_load_origin_ = ORIGIN_NONE; |
| 176 } | 180 } |
| 181 | |
| 182 url_ = validated_url; | |
| 183 RecordEvent(EVENT_MAINFRAME_CHANGE); | |
| 184 RecordEventIfLoggedInURL(EVENT_MAINFRAME_CHANGE_DOMAIN_LOGGED_IN, url_); | |
| 185 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); | |
| 186 if (!prerender_manager) | |
| 187 return; | |
| 188 if (prerender_manager->IsWebContentsPrerendering(web_contents(), NULL)) | |
| 189 return; | |
| 190 ReportTabHelperURLSeenToLocalPredictor(prerender_manager, url_, | |
| 191 web_contents()); | |
|
davidben
2014/09/17 15:08:30
Maybe split this and the other block into their ow
Avi (use Gerrit)
2014/09/18 21:00:21
Done.
| |
| 177 } | 192 } |
| 178 | 193 |
| 179 void PrerenderTabHelper::PasswordSubmitted(const autofill::PasswordForm& form) { | 194 void PrerenderTabHelper::PasswordSubmitted(const autofill::PasswordForm& form) { |
| 180 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); | 195 PrerenderManager* prerender_manager = MaybeGetPrerenderManager(); |
| 181 if (prerender_manager) { | 196 if (prerender_manager) { |
| 182 prerender_manager->RecordLikelyLoginOnURL(form.origin); | 197 prerender_manager->RecordLikelyLoginOnURL(form.origin); |
| 183 RecordEvent(EVENT_LOGIN_ACTION_ADDED); | 198 RecordEvent(EVENT_LOGIN_ACTION_ADDED); |
| 184 if (form.password_value.empty()) | 199 if (form.password_value.empty()) |
| 185 RecordEvent(EVENT_LOGIN_ACTION_ADDED_PW_EMPTY); | 200 RecordEvent(EVENT_LOGIN_ACTION_ADDED_PW_EMPTY); |
| 186 } | 201 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 prerender_manager->RecordPerceivedPageLoadTime( | 282 prerender_manager->RecordPerceivedPageLoadTime( |
| 268 origin_, navigation_type_, perceived_page_load_time, | 283 origin_, navigation_type_, perceived_page_load_time, |
| 269 fraction_plt_elapsed_at_swap_in, url_); | 284 fraction_plt_elapsed_at_swap_in, url_); |
| 270 | 285 |
| 271 // Reset state for the next navigation. | 286 // Reset state for the next navigation. |
| 272 navigation_type_ = NAVIGATION_TYPE_NORMAL; | 287 navigation_type_ = NAVIGATION_TYPE_NORMAL; |
| 273 origin_ = ORIGIN_NONE; | 288 origin_ = ORIGIN_NONE; |
| 274 } | 289 } |
| 275 | 290 |
| 276 } // namespace prerender | 291 } // namespace prerender |
| OLD | NEW |