• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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/wifi_data.h"
6 
7 #include <algorithm>
8 
9 #include "base/logging.h"
10 
11 namespace content {
12 
AccessPointData()13 AccessPointData::AccessPointData()
14     : radio_signal_strength(kint32min),
15       channel(kint32min),
16       signal_to_noise(kint32min) {
17 }
18 
~AccessPointData()19 AccessPointData::~AccessPointData() {}
20 
WifiData()21 WifiData::WifiData() {}
22 
~WifiData()23 WifiData::~WifiData() {}
24 
DiffersSignificantly(const WifiData & other) const25 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 intersection 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 }
51 
52 }  // namespace content
53