| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/geolocation/device_data_provider.h" | |
| 6 | |
| 7 namespace { | |
| 8 | |
| 9 bool CellDataMatches(const CellData &data1, const CellData &data2) { | |
| 10 return data1.Matches(data2); | |
| 11 } | |
| 12 | |
| 13 } // namespace | |
| 14 | |
| 15 CellData::CellData() | |
| 16 : cell_id(kint32min), | |
| 17 location_area_code(kint32min), | |
| 18 mobile_network_code(kint32min), | |
| 19 mobile_country_code(kint32min), | |
| 20 radio_signal_strength(kint32min), | |
| 21 timing_advance(kint32min) { | |
| 22 } | |
| 23 | |
| 24 RadioData::RadioData() | |
| 25 : home_mobile_network_code(kint32min), | |
| 26 home_mobile_country_code(kint32min), | |
| 27 radio_type(RADIO_TYPE_UNKNOWN) { | |
| 28 } | |
| 29 | |
| 30 RadioData::~RadioData() {} | |
| 31 | |
| 32 bool RadioData::Matches(const RadioData &other) const { | |
| 33 if (cell_data.size() != other.cell_data.size()) { | |
| 34 return false; | |
| 35 } | |
| 36 if (!std::equal(cell_data.begin(), cell_data.end(), other.cell_data.begin(), | |
| 37 CellDataMatches)) { | |
| 38 return false; | |
| 39 } | |
| 40 return device_id == other.device_id && | |
| 41 home_mobile_network_code == other.home_mobile_network_code && | |
| 42 home_mobile_country_code == other.home_mobile_country_code && | |
| 43 radio_type == other.radio_type && | |
| 44 carrier == other.carrier; | |
| 45 } | |
| 46 | |
| 47 AccessPointData::AccessPointData() | |
| 48 : radio_signal_strength(kint32min), | |
| 49 channel(kint32min), | |
| 50 signal_to_noise(kint32min) { | |
| 51 } | |
| 52 | |
| 53 AccessPointData::~AccessPointData() {} | |
| 54 | |
| 55 WifiData::WifiData() {} | |
| 56 | |
| 57 WifiData::~WifiData() {} | |
| 58 | |
| 59 bool WifiData::DiffersSignificantly(const WifiData& other) const { | |
| 60 // More than 4 or 50% of access points added or removed is significant. | |
| 61 static const size_t kMinChangedAccessPoints = 4; | |
| 62 const size_t min_ap_count = | |
| 63 std::min(access_point_data.size(), other.access_point_data.size()); | |
| 64 const size_t max_ap_count = | |
| 65 std::max(access_point_data.size(), other.access_point_data.size()); | |
| 66 const size_t difference_threadhold = std::min(kMinChangedAccessPoints, | |
| 67 min_ap_count / 2); | |
| 68 if (max_ap_count > min_ap_count + difference_threadhold) | |
| 69 return true; | |
| 70 // Compute size of interesction of old and new sets. | |
| 71 size_t num_common = 0; | |
| 72 for (AccessPointDataSet::const_iterator iter = access_point_data.begin(); | |
| 73 iter != access_point_data.end(); | |
| 74 iter++) { | |
| 75 if (other.access_point_data.find(*iter) != | |
| 76 other.access_point_data.end()) { | |
| 77 ++num_common; | |
| 78 } | |
| 79 } | |
| 80 DCHECK(num_common <= min_ap_count); | |
| 81 | |
| 82 // Test how many have changed. | |
| 83 return max_ap_count > num_common + difference_threadhold; | |
| 84 } | |
| 85 | |
| 86 GatewayData::GatewayData() {} | |
| 87 | |
| 88 GatewayData::~GatewayData() {} | |
| 89 | |
| 90 bool GatewayData::DiffersSignificantly(const GatewayData& other) const { | |
| 91 // Any change is significant. | |
| 92 if (this->router_data.size() != other.router_data.size()) | |
| 93 return true; | |
| 94 RouterDataSet::const_iterator iter1 = router_data.begin(); | |
| 95 RouterDataSet::const_iterator iter2 = other.router_data.begin(); | |
| 96 while (iter1 != router_data.end()) { | |
| 97 if (iter1->mac_address != iter2->mac_address) { | |
| 98 // There is a difference between the sets of routers. | |
| 99 return true; | |
| 100 } | |
| 101 ++iter1; | |
| 102 ++iter2; | |
| 103 } | |
| 104 return false; | |
| 105 } | |
| OLD | NEW |