| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/data_use_measurement/content/content_url_request_classifier
.h" | 5 #include "components/data_use_measurement/content/content_url_request_classifier
.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/metrics/sparse_histogram.h" |
| 7 #include "content/public/browser/resource_request_info.h" | 9 #include "content/public/browser/resource_request_info.h" |
| 8 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
| 11 #include "ui/base/page_transition_types.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Data use broken by page transition type. This enum must remain synchronized |
| 16 // with the enum of the same name in metrics/histograms/histograms.xml. The enum |
| 17 // values have the same meaning as ui::PageTransition in |
| 18 // ui/base/page_transition_types.h. These values are written to logs. New enum |
| 19 // values can be added, but existing enums must never be renumbered or deleted |
| 20 // and reused. |
| 21 enum DataUsePageTransition { |
| 22 LINK = 0, |
| 23 TYPED = 1, |
| 24 AUTO_BOOKMARK = 2, |
| 25 SUBFRAME = 3, // AUTO_SUBFRAME and MANUAL_SUBFRAME transitions. |
| 26 GENERATED = 4, |
| 27 AUTO_TOPLEVEL = 5, |
| 28 FORM_SUBMIT = 6, |
| 29 RELOAD = 7, |
| 30 KEYWORD = 8, // KEYWORD and KEYWORD_GENERATED transitions. |
| 31 FORWARD_BACK = 9, |
| 32 HOME_PAGE = 10, |
| 33 TRANSITION_MAX = 11, |
| 34 }; |
| 35 |
| 36 } // namespace |
| 9 | 37 |
| 10 namespace data_use_measurement { | 38 namespace data_use_measurement { |
| 11 | 39 |
| 12 bool IsUserRequest(const net::URLRequest& request) { | 40 bool IsUserRequest(const net::URLRequest& request) { |
| 13 // The presence of ResourecRequestInfo in |request| implies that this request | 41 // The presence of ResourecRequestInfo in |request| implies that this request |
| 14 // was created for a content::WebContents. For now we could add a condition to | 42 // was created for a content::WebContents. For now we could add a condition to |
| 15 // check ProcessType in info is content::PROCESS_TYPE_RENDERER, but it won't | 43 // check ProcessType in info is content::PROCESS_TYPE_RENDERER, but it won't |
| 16 // be compatible with upcoming PlzNavigate architecture. So just existence of | 44 // be compatible with upcoming PlzNavigate architecture. So just existence of |
| 17 // ResourceRequestInfo is verified, and the current check should be compatible | 45 // ResourceRequestInfo is verified, and the current check should be compatible |
| 18 // with upcoming changes in PlzNavigate. | 46 // with upcoming changes in PlzNavigate. |
| 19 // TODO(rajendrant): Verify this condition for different use cases. See | 47 // TODO(rajendrant): Verify this condition for different use cases. See |
| 20 // crbug.com/626063. | 48 // crbug.com/626063. |
| 21 return content::ResourceRequestInfo::ForRequest(&request) != nullptr; | 49 return content::ResourceRequestInfo::ForRequest(&request) != nullptr; |
| 22 } | 50 } |
| 23 | 51 |
| 24 bool ContentURLRequestClassifier::IsUserRequest( | 52 bool ContentURLRequestClassifier::IsUserRequest( |
| 25 const net::URLRequest& request) const { | 53 const net::URLRequest& request) const { |
| 26 return data_use_measurement::IsUserRequest(request); | 54 return data_use_measurement::IsUserRequest(request); |
| 27 } | 55 } |
| 28 | 56 |
| 57 void ContentURLRequestClassifier::RecordPageTransitionUMA( |
| 58 uint64_t page_transition, |
| 59 int64_t received_bytes) const { |
| 60 DataUsePageTransition data_use_page_transition = |
| 61 DataUsePageTransition::TRANSITION_MAX; |
| 62 if (received_bytes <= 0) |
| 63 return; |
| 64 |
| 65 if (page_transition & ui::PAGE_TRANSITION_FORWARD_BACK) { |
| 66 data_use_page_transition = DataUsePageTransition::FORWARD_BACK; |
| 67 } else if (page_transition & ui::PAGE_TRANSITION_HOME_PAGE) { |
| 68 data_use_page_transition = DataUsePageTransition::HOME_PAGE; |
| 69 } else { |
| 70 switch (page_transition & ui::PAGE_TRANSITION_CORE_MASK) { |
| 71 case ui::PAGE_TRANSITION_LINK: |
| 72 data_use_page_transition = DataUsePageTransition::LINK; |
| 73 break; |
| 74 case ui::PAGE_TRANSITION_TYPED: |
| 75 data_use_page_transition = DataUsePageTransition::TYPED; |
| 76 break; |
| 77 case ui::PAGE_TRANSITION_AUTO_BOOKMARK: |
| 78 data_use_page_transition = DataUsePageTransition::AUTO_BOOKMARK; |
| 79 break; |
| 80 case ui::PAGE_TRANSITION_AUTO_SUBFRAME: |
| 81 case ui::PAGE_TRANSITION_MANUAL_SUBFRAME: |
| 82 data_use_page_transition = DataUsePageTransition::SUBFRAME; |
| 83 break; |
| 84 case ui::PAGE_TRANSITION_GENERATED: |
| 85 data_use_page_transition = DataUsePageTransition::GENERATED; |
| 86 break; |
| 87 case ui::PAGE_TRANSITION_AUTO_TOPLEVEL: |
| 88 data_use_page_transition = DataUsePageTransition::AUTO_TOPLEVEL; |
| 89 break; |
| 90 case ui::PAGE_TRANSITION_FORM_SUBMIT: |
| 91 data_use_page_transition = DataUsePageTransition::FORM_SUBMIT; |
| 92 break; |
| 93 case ui::PAGE_TRANSITION_RELOAD: |
| 94 data_use_page_transition = DataUsePageTransition::RELOAD; |
| 95 break; |
| 96 case ui::PAGE_TRANSITION_KEYWORD: |
| 97 case ui::PAGE_TRANSITION_KEYWORD_GENERATED: |
| 98 data_use_page_transition = DataUsePageTransition::KEYWORD; |
| 99 break; |
| 100 } |
| 101 } |
| 102 DCHECK_NE(DataUsePageTransition::TRANSITION_MAX, data_use_page_transition); |
| 103 |
| 104 // Use the more primitive STATIC_HISTOGRAM_POINTER_BLOCK macro because the |
| 105 // simple UMA_HISTOGRAM_ENUMERATION macros don't expose 'AddCount'. |
| 106 STATIC_HISTOGRAM_POINTER_BLOCK( |
| 107 "DataUse.PageTransition.UserTraffic", |
| 108 AddCount(data_use_page_transition, received_bytes), |
| 109 base::LinearHistogram::FactoryGet( |
| 110 "DataUse.PageTransition.UserTraffic", 1, |
| 111 DataUsePageTransition::TRANSITION_MAX, |
| 112 DataUsePageTransition::TRANSITION_MAX + 1, |
| 113 base::HistogramBase::kUmaTargetedHistogramFlag)); |
| 114 } |
| 115 |
| 29 } // namespace data_use_measurement | 116 } // namespace data_use_measurement |
| OLD | NEW |