OLD | NEW |
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 "components/data_usage/core/data_use.h" | 5 #include "components/data_usage/core/data_use.h" |
6 | 6 |
7 namespace data_usage { | 7 namespace data_usage { |
8 | 8 |
| 9 namespace { |
| 10 |
| 11 bool AreNonByteCountFieldsEqual(const DataUse& a, const DataUse& b) { |
| 12 return a.url == b.url && a.request_start == b.request_start && |
| 13 a.first_party_for_cookies == b.first_party_for_cookies && |
| 14 a.tab_id == b.tab_id && a.connection_type == b.connection_type && |
| 15 a.mcc_mnc == b.mcc_mnc; |
| 16 } |
| 17 |
| 18 bool AreByteCountFieldsEqual(const DataUse& a, const DataUse& b) { |
| 19 return a.tx_bytes == b.tx_bytes && a.rx_bytes == b.rx_bytes; |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
9 DataUse::DataUse(const GURL& url, | 24 DataUse::DataUse(const GURL& url, |
10 const base::TimeTicks& request_start, | 25 const base::TimeTicks& request_start, |
11 const GURL& first_party_for_cookies, | 26 const GURL& first_party_for_cookies, |
12 int32_t tab_id, | 27 int32_t tab_id, |
13 net::NetworkChangeNotifier::ConnectionType connection_type, | 28 net::NetworkChangeNotifier::ConnectionType connection_type, |
14 const std::string& mcc_mnc, | 29 const std::string& mcc_mnc, |
15 int64_t tx_bytes, | 30 int64_t tx_bytes, |
16 int64_t rx_bytes) | 31 int64_t rx_bytes) |
17 : url(url), | 32 : url(url), |
18 request_start(request_start), | 33 request_start(request_start), |
19 first_party_for_cookies(first_party_for_cookies), | 34 first_party_for_cookies(first_party_for_cookies), |
20 tab_id(tab_id), | 35 tab_id(tab_id), |
21 connection_type(connection_type), | 36 connection_type(connection_type), |
22 mcc_mnc(mcc_mnc), | 37 mcc_mnc(mcc_mnc), |
23 tx_bytes(tx_bytes), | 38 tx_bytes(tx_bytes), |
24 rx_bytes(rx_bytes) {} | 39 rx_bytes(rx_bytes) {} |
25 | 40 |
26 DataUse::~DataUse() {} | 41 DataUse::~DataUse() {} |
27 | 42 |
| 43 bool DataUse::operator==(const DataUse& other) const { |
| 44 return AreNonByteCountFieldsEqual(*this, other) && |
| 45 AreByteCountFieldsEqual(*this, other); |
| 46 } |
| 47 |
28 bool DataUse::CanCombineWith(const DataUse& other) const { | 48 bool DataUse::CanCombineWith(const DataUse& other) const { |
29 return url == other.url && request_start == other.request_start && | 49 return AreNonByteCountFieldsEqual(*this, other); |
30 first_party_for_cookies == other.first_party_for_cookies && | |
31 tab_id == other.tab_id && connection_type == other.connection_type && | |
32 mcc_mnc == other.mcc_mnc; | |
33 } | 50 } |
34 | 51 |
35 } // namespace data_usage | 52 } // namespace data_usage |
OLD | NEW |