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