| 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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
_use_observer.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
_use_observer.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" | 8 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" |
| 9 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" | 9 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" |
| 10 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" | 10 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 void IncrementBytes(int64_t network_bytes, int64_t original_bytes) { | 33 void IncrementBytes(int64_t network_bytes, int64_t original_bytes) { |
| 34 network_bytes_ += network_bytes; | 34 network_bytes_ += network_bytes; |
| 35 original_bytes_ += original_bytes; | 35 original_bytes_ += original_bytes; |
| 36 } | 36 } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 int64_t network_bytes_; | 39 int64_t network_bytes_; |
| 40 int64_t original_bytes_; | 40 int64_t original_bytes_; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // Hostname used for the other bucket which consists of chrome-services traffic. |
| 44 // This should be in sync with the same in DataReductionSiteBreakdownView.java |
| 45 const char kOtherHostName[] = "Other"; |
| 46 |
| 43 // static | 47 // static |
| 44 const void* DataUseUserDataBytes::kUserDataKey = | 48 const void* DataUseUserDataBytes::kUserDataKey = |
| 45 &DataUseUserDataBytes::kUserDataKey; | 49 &DataUseUserDataBytes::kUserDataKey; |
| 46 | 50 |
| 47 } // namespace | 51 } // namespace |
| 48 | 52 |
| 49 namespace data_reduction_proxy { | 53 namespace data_reduction_proxy { |
| 50 | 54 |
| 51 DataReductionProxyDataUseObserver::DataReductionProxyDataUseObserver( | 55 DataReductionProxyDataUseObserver::DataReductionProxyDataUseObserver( |
| 52 DataReductionProxyIOData* data_reduction_proxy_io_data, | 56 DataReductionProxyIOData* data_reduction_proxy_io_data, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 77 data_use->url().HostNoBrackets()); | 81 data_use->url().HostNoBrackets()); |
| 78 data_use->RemoveUserData(DataUseUserDataBytes::kUserDataKey); | 82 data_use->RemoveUserData(DataUseUserDataBytes::kUserDataKey); |
| 79 } | 83 } |
| 80 } | 84 } |
| 81 | 85 |
| 82 void DataReductionProxyDataUseObserver::OnPageResourceLoad( | 86 void DataReductionProxyDataUseObserver::OnPageResourceLoad( |
| 83 const net::URLRequest& request, | 87 const net::URLRequest& request, |
| 84 data_use_measurement::DataUse* data_use) { | 88 data_use_measurement::DataUse* data_use) { |
| 85 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 89 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 86 | 90 |
| 87 if (data_use->traffic_type() != | |
| 88 data_use_measurement::DataUse::TrafficType::USER_TRAFFIC) { | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 if (!request.url().SchemeIs(url::kHttpsScheme) && | 91 if (!request.url().SchemeIs(url::kHttpsScheme) && |
| 93 !request.url().SchemeIs(url::kHttpScheme)) { | 92 !request.url().SchemeIs(url::kHttpScheme)) { |
| 94 return; | 93 return; |
| 95 } | 94 } |
| 96 | 95 |
| 96 if (request.GetTotalReceivedBytes() <= 0) |
| 97 return; |
| 98 |
| 97 int64_t network_bytes = request.GetTotalReceivedBytes(); | 99 int64_t network_bytes = request.GetTotalReceivedBytes(); |
| 98 DataReductionProxyRequestType request_type = GetDataReductionProxyRequestType( | 100 DataReductionProxyRequestType request_type = GetDataReductionProxyRequestType( |
| 99 request, data_reduction_proxy_io_data_->configurator()->GetProxyConfig(), | 101 request, data_reduction_proxy_io_data_->configurator()->GetProxyConfig(), |
| 100 *data_reduction_proxy_io_data_->config()); | 102 *data_reduction_proxy_io_data_->config()); |
| 101 | 103 |
| 102 // Estimate how many bytes would have been used if the DataReductionProxy was | 104 // Estimate how many bytes would have been used if the DataReductionProxy was |
| 103 // not used, and record the data usage. | 105 // not used, and record the data usage. |
| 104 int64_t original_bytes = util::EstimateOriginalReceivedBytes( | 106 int64_t original_bytes = util::EstimateOriginalReceivedBytes( |
| 105 request, request_type == VIA_DATA_REDUCTION_PROXY, | 107 request, request_type == VIA_DATA_REDUCTION_PROXY, |
| 106 data_reduction_proxy_io_data_->lofi_decider()); | 108 data_reduction_proxy_io_data_->lofi_decider()); |
| 107 | 109 |
| 108 if (!data_use->url().is_valid()) { | 110 if (data_use->traffic_type() == |
| 111 data_use_measurement::DataUse::TrafficType::USER_TRAFFIC && |
| 112 !data_use->url().is_valid()) { |
| 109 // URL will be empty until pageload navigation commits. Save the data use of | 113 // URL will be empty until pageload navigation commits. Save the data use of |
| 110 // these mainframe, subresource, redirected requests in user data until | 114 // these mainframe, subresource, redirected requests in user data until |
| 111 // then. | 115 // then. |
| 112 DataUseUserDataBytes* bytes = reinterpret_cast<DataUseUserDataBytes*>( | 116 DataUseUserDataBytes* bytes = reinterpret_cast<DataUseUserDataBytes*>( |
| 113 data_use->GetUserData(DataUseUserDataBytes::kUserDataKey)); | 117 data_use->GetUserData(DataUseUserDataBytes::kUserDataKey)); |
| 114 if (bytes) { | 118 if (bytes) { |
| 115 bytes->IncrementBytes(network_bytes, original_bytes); | 119 bytes->IncrementBytes(network_bytes, original_bytes); |
| 116 } else { | 120 } else { |
| 117 data_use->SetUserData(DataUseUserDataBytes::kUserDataKey, | 121 data_use->SetUserData(DataUseUserDataBytes::kUserDataKey, |
| 118 base::MakeUnique<DataUseUserDataBytes>( | 122 base::MakeUnique<DataUseUserDataBytes>( |
| 119 network_bytes, original_bytes)); | 123 network_bytes, original_bytes)); |
| 120 } | 124 } |
| 121 } else { | 125 } else { |
| 122 data_reduction_proxy_io_data_->UpdateDataUseForHost( | 126 data_reduction_proxy_io_data_->UpdateDataUseForHost( |
| 123 network_bytes, original_bytes, data_use->url().HostNoBrackets()); | 127 network_bytes, original_bytes, |
| 128 data_use->traffic_type() == |
| 129 data_use_measurement::DataUse::TrafficType::USER_TRAFFIC |
| 130 ? data_use->url().HostNoBrackets() |
| 131 : kOtherHostName); |
| 124 } | 132 } |
| 125 } | 133 } |
| 126 | 134 |
| 127 } // namespace data_reduction_proxy | 135 } // namespace data_reduction_proxy |
| OLD | NEW |