summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation/device_data_provider.cc
blob: 9fe592ac4002aff347e99f646dd6eafc27a714c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/geolocation/device_data_provider.h"

namespace {

bool CellDataMatches(const CellData &data1, const CellData &data2) {
  return data1.Matches(data2);
}

}  // namespace

CellData::CellData()
    : cell_id(kint32min),
      location_area_code(kint32min),
      mobile_network_code(kint32min),
      mobile_country_code(kint32min),
      radio_signal_strength(kint32min),
      timing_advance(kint32min) {
}

RadioData::RadioData()
    : home_mobile_network_code(kint32min),
      home_mobile_country_code(kint32min),
      radio_type(RADIO_TYPE_UNKNOWN) {
}

RadioData::~RadioData() {}

bool RadioData::Matches(const RadioData &other) const {
  if (cell_data.size() != other.cell_data.size()) {
    return false;
  }
  if (!std::equal(cell_data.begin(), cell_data.end(), other.cell_data.begin(),
                  CellDataMatches)) {
    return false;
  }
  return device_id == other.device_id &&
         home_mobile_network_code == other.home_mobile_network_code &&
         home_mobile_country_code == other.home_mobile_country_code &&
         radio_type == other.radio_type &&
         carrier == other.carrier;
}

AccessPointData::AccessPointData()
    : radio_signal_strength(kint32min),
      channel(kint32min),
      signal_to_noise(kint32min) {
}

AccessPointData::~AccessPointData() {}

WifiData::WifiData() {}

WifiData::~WifiData() {}

bool WifiData::DiffersSignificantly(const WifiData& other) const {
  // More than 4 or 50% of access points added or removed is significant.
  static const size_t kMinChangedAccessPoints = 4;
  const size_t min_ap_count =
      std::min(access_point_data.size(), other.access_point_data.size());
  const size_t max_ap_count =
      std::max(access_point_data.size(), other.access_point_data.size());
  const size_t difference_threadhold = std::min(kMinChangedAccessPoints,
                                                min_ap_count / 2);
  if (max_ap_count > min_ap_count + difference_threadhold)
    return true;
  // Compute size of interesction of old and new sets.
  size_t num_common = 0;
  for (AccessPointDataSet::const_iterator iter = access_point_data.begin();
       iter != access_point_data.end();
       iter++) {
    if (other.access_point_data.find(*iter) !=
        other.access_point_data.end()) {
      ++num_common;
    }
  }
  DCHECK(num_common <= min_ap_count);

  // Test how many have changed.
  return max_ap_count > num_common + difference_threadhold;
}

GatewayData::GatewayData() {}

GatewayData::~GatewayData() {}

bool GatewayData::DiffersSignificantly(const GatewayData& other) const {
  // Any change is significant.
  if (this->router_data.size() != other.router_data.size())
    return true;
  RouterDataSet::const_iterator iter1 = router_data.begin();
  RouterDataSet::const_iterator iter2 = other.router_data.begin();
  while (iter1 != router_data.end()) {
    if (iter1->mac_address != iter2->mac_address) {
      // There is a difference between the sets of routers.
      return true;
    }
    ++iter1;
    ++iter2;
  }
  return false;
}