| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 "content/browser/geolocation/device_data_provider.h" | |
| 6 | |
| 7 // statics | |
| 8 template<> DeviceDataProvider<WifiData>* | |
| 9 DeviceDataProvider<WifiData>::instance_ = NULL; | |
| 10 template<> DeviceDataProvider<WifiData>::ImplFactoryFunction | |
| 11 DeviceDataProvider<WifiData>::factory_function_ = DefaultFactoryFunction; | |
| 12 | |
| 13 AccessPointData::AccessPointData() | |
| 14 : radio_signal_strength(kint32min), | |
| 15 channel(kint32min), | |
| 16 signal_to_noise(kint32min) { | |
| 17 } | |
| 18 | |
| 19 AccessPointData::~AccessPointData() {} | |
| 20 | |
| 21 WifiData::WifiData() {} | |
| 22 | |
| 23 WifiData::~WifiData() {} | |
| 24 | |
| 25 bool WifiData::DiffersSignificantly(const WifiData& other) const { | |
| 26 // More than 4 or 50% of access points added or removed is significant. | |
| 27 static const size_t kMinChangedAccessPoints = 4; | |
| 28 const size_t min_ap_count = | |
| 29 std::min(access_point_data.size(), other.access_point_data.size()); | |
| 30 const size_t max_ap_count = | |
| 31 std::max(access_point_data.size(), other.access_point_data.size()); | |
| 32 const size_t difference_threadhold = std::min(kMinChangedAccessPoints, | |
| 33 min_ap_count / 2); | |
| 34 if (max_ap_count > min_ap_count + difference_threadhold) | |
| 35 return true; | |
| 36 // Compute size of interesction of old and new sets. | |
| 37 size_t num_common = 0; | |
| 38 for (AccessPointDataSet::const_iterator iter = access_point_data.begin(); | |
| 39 iter != access_point_data.end(); | |
| 40 iter++) { | |
| 41 if (other.access_point_data.find(*iter) != | |
| 42 other.access_point_data.end()) { | |
| 43 ++num_common; | |
| 44 } | |
| 45 } | |
| 46 DCHECK(num_common <= min_ap_count); | |
| 47 | |
| 48 // Test how many have changed. | |
| 49 return max_ap_count > num_common + difference_threadhold; | |
| 50 } | |
| OLD | NEW |