OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/webui/ntp/ntp_user_data_logger.h" | 5 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/search/search.h" | 8 #include "chrome/browser/search/search.h" |
9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
10 #include "content/public/browser/navigation_details.h" | 10 #include "content/public/browser/navigation_details.h" |
11 | 11 |
12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); | 12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); |
13 | 13 |
14 NTPUserDataLogger::~NTPUserDataLogger() {} | 14 NTPUserDataLogger::~NTPUserDataLogger() {} |
15 | 15 |
16 void NTPUserDataLogger::EmitThumbnailErrorRate() { | 16 void NTPUserDataLogger::EmitThumbnailErrorRate() { |
17 DCHECK_LE(number_of_thumbnail_errors_, number_of_thumbnail_attempts_); | 17 DCHECK_LE(number_of_thumbnail_errors_, number_of_thumbnail_attempts_); |
18 DCHECK_LE(number_of_fallback_thumbnails_used_, | |
19 number_of_fallback_thumbnails_requested_); | |
Alexei Svitkine (slow)
2013/09/05 14:59:25
Nit: Move this above the if block that logs it.
beaudoin
2013/09/05 15:02:55
Done.
| |
18 if (number_of_thumbnail_attempts_ != 0) { | 20 if (number_of_thumbnail_attempts_ != 0) { |
19 UMA_HISTOGRAM_PERCENTAGE("NewTabPage.ThumbnailErrorRate", | 21 UMA_HISTOGRAM_PERCENTAGE( |
20 GetPercentError(number_of_thumbnail_errors_, | 22 "NewTabPage.ThumbnailErrorRate", |
21 number_of_thumbnail_attempts_)); | 23 GetPercentError(number_of_thumbnail_errors_, |
24 number_of_thumbnail_attempts_)); | |
25 } | |
26 if (number_of_fallback_thumbnails_requested_ != 0) { | |
27 UMA_HISTOGRAM_PERCENTAGE( | |
28 "NewTabPage.ThumbnailFallbackRate", | |
29 GetPercentError(number_of_fallback_thumbnails_used_, | |
30 number_of_fallback_thumbnails_requested_)); | |
22 } | 31 } |
23 number_of_thumbnail_attempts_ = 0; | 32 number_of_thumbnail_attempts_ = 0; |
24 number_of_thumbnail_errors_ = 0; | 33 number_of_thumbnail_errors_ = 0; |
34 number_of_fallback_thumbnails_requested_ = 0; | |
35 number_of_fallback_thumbnails_used_ = 0; | |
25 } | 36 } |
26 | 37 |
27 void NTPUserDataLogger::EmitMouseoverCount() { | 38 void NTPUserDataLogger::EmitMouseoverCount() { |
28 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_); | 39 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_); |
29 number_of_mouseovers_ = 0; | 40 number_of_mouseovers_ = 0; |
30 } | 41 } |
31 | 42 |
32 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event) { | 43 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event) { |
33 switch (event) { | 44 switch (event) { |
34 case NTP_MOUSEOVER: | 45 case NTP_MOUSEOVER: |
35 number_of_mouseovers_++; | 46 number_of_mouseovers_++; |
36 break; | 47 break; |
37 case NTP_THUMBNAIL_ATTEMPT: | 48 case NTP_THUMBNAIL_ATTEMPT: |
38 number_of_thumbnail_attempts_++; | 49 number_of_thumbnail_attempts_++; |
39 break; | 50 break; |
40 case NTP_THUMBNAIL_ERROR: | 51 case NTP_THUMBNAIL_ERROR: |
41 number_of_thumbnail_errors_++; | 52 number_of_thumbnail_errors_++; |
42 break; | 53 break; |
54 case NTP_FALLBACK_THUMBNAIL_REQUESTED: | |
55 number_of_fallback_thumbnails_requested_++; | |
56 break; | |
57 case NTP_FALLBACK_THUMBNAIL_USED: | |
58 number_of_fallback_thumbnails_used_++; | |
59 break; | |
43 default: | 60 default: |
44 NOTREACHED(); | 61 NOTREACHED(); |
45 } | 62 } |
46 } | 63 } |
47 | 64 |
48 // content::WebContentsObserver override | 65 // content::WebContentsObserver override |
49 void NTPUserDataLogger::NavigationEntryCommitted( | 66 void NTPUserDataLogger::NavigationEntryCommitted( |
50 const content::LoadCommittedDetails& load_details) { | 67 const content::LoadCommittedDetails& load_details) { |
51 if (!load_details.previous_url.is_valid()) | 68 if (!load_details.previous_url.is_valid()) |
52 return; | 69 return; |
53 | 70 |
54 if (chrome::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { | 71 if (chrome::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { |
55 EmitMouseoverCount(); | 72 EmitMouseoverCount(); |
56 // Only log thumbnail error rates for Instant NTP pages, as we do not have | 73 // Only log thumbnail error rates for Instant NTP pages, as we do not have |
57 // this data for non-Instant NTPs. | 74 // this data for non-Instant NTPs. |
58 if (ntp_url_ != GURL(chrome::kChromeUINewTabURL)) | 75 if (ntp_url_ != GURL(chrome::kChromeUINewTabURL)) |
59 EmitThumbnailErrorRate(); | 76 EmitThumbnailErrorRate(); |
60 } | 77 } |
61 } | 78 } |
62 | 79 |
63 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) | 80 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) |
64 : content::WebContentsObserver(contents), | 81 : content::WebContentsObserver(contents), |
65 number_of_mouseovers_(0), | 82 number_of_mouseovers_(0), |
66 number_of_thumbnail_attempts_(0), | 83 number_of_thumbnail_attempts_(0), |
67 number_of_thumbnail_errors_(0) { | 84 number_of_thumbnail_errors_(0), |
85 number_of_fallback_thumbnails_requested_(0), | |
86 number_of_fallback_thumbnails_used_(0) { | |
68 } | 87 } |
69 | 88 |
70 size_t NTPUserDataLogger::GetPercentError(size_t errors, size_t events) const { | 89 size_t NTPUserDataLogger::GetPercentError(size_t errors, size_t events) const { |
71 return (100 * errors) / events; | 90 return (100 * errors) / events; |
72 } | 91 } |
OLD | NEW |