Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: chrome/browser/page_load_metrics/observers/google_captcha_observer.cc

Issue 1473153002: PageLoadMetricsObservers observe individual page loads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: destroy order Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/observers/google_captcha_observer.h" 5 #include "chrome/browser/page_load_metrics/observers/google_captcha_observer.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "components/page_load_metrics/browser/page_load_metrics_util.h" 9 #include "components/page_load_metrics/browser/page_load_metrics_util.h"
10 #include "components/page_load_metrics/common/page_load_timing.h" 10 #include "components/page_load_metrics/common/page_load_timing.h"
(...skipping 23 matching lines...) Expand all
34 } // namespace 34 } // namespace
35 35
36 bool IsGoogleCaptcha(const GURL& url) { 36 bool IsGoogleCaptcha(const GURL& url) {
37 return (base::StartsWith(url.host(), "ipv4.google.", 37 return (base::StartsWith(url.host(), "ipv4.google.",
38 base::CompareCase::SENSITIVE) 38 base::CompareCase::SENSITIVE)
39 || base::StartsWith(url.host(), "ipv6.google.", 39 || base::StartsWith(url.host(), "ipv6.google.",
40 base::CompareCase::SENSITIVE)) 40 base::CompareCase::SENSITIVE))
41 && base::StartsWith(url.path(), "/sorry", base::CompareCase::SENSITIVE); 41 && base::StartsWith(url.path(), "/sorry", base::CompareCase::SENSITIVE);
42 } 42 }
43 43
44 GoogleCaptchaObserver::GoogleCaptchaObserver( 44 GoogleCaptchaObserver::GoogleCaptchaObserver() : saw_solution_(false) {}
45 page_load_metrics::PageLoadMetricsObservable* metrics)
46 : saw_solution_(false), metrics_(metrics) {}
47 45
48 void GoogleCaptchaObserver::OnCommit( 46 void GoogleCaptchaObserver::OnCommit(
49 content::NavigationHandle* navigation_handle) { 47 content::NavigationHandle* navigation_handle) {
50 if (IsGoogleCaptcha(navigation_handle->GetURL())) 48 if (!navigation_handle->IsSamePage()
49 && IsGoogleCaptcha(navigation_handle->GetURL())) {
51 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SHOWN); 50 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SHOWN);
52 if (saw_solution_) {
53 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SOLVED);
54 saw_solution_ = false;
55 } 51 }
56 } 52 }
57 53
58 void GoogleCaptchaObserver::OnRedirect( 54 void GoogleCaptchaObserver::OnRedirect(
59 content::NavigationHandle* navigation_handle) { 55 content::NavigationHandle* navigation_handle) {
60 if (IsGoogleCaptcha(navigation_handle->GetReferrer().url)) 56 if (IsGoogleCaptcha(navigation_handle->GetReferrer().url) && !saw_solution_) {
57 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SOLVED);
61 saw_solution_ = true; 58 saw_solution_ = true;
62 } 59 }
63
64 void GoogleCaptchaObserver::OnPageLoadMetricsGoingAway() {
65 metrics_->RemoveObserver(this);
66 delete this;
67 } 60 }
68 61
69 } // namespace google_captcha_observer 62 } // namespace google_captcha_observer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698