Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: content/browser/geolocation/wifi_data.cc

Issue 2192683002: Reland 2:Geolocation: move from content/browser to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ignore size_t_to_int truncation warning Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 <stddef.h>
8 #include <stdint.h>
9
10 #include <algorithm>
11 #include <limits>
12
13 #include "base/logging.h"
14
15 namespace content {
16
17 AccessPointData::AccessPointData()
18 : radio_signal_strength(std::numeric_limits<int32_t>::min()),
19 channel(std::numeric_limits<int32_t>::min()),
20 signal_to_noise(std::numeric_limits<int32_t>::min()) {}
21
22 AccessPointData::~AccessPointData() {}
23
24 WifiData::WifiData() {}
25
26 WifiData::WifiData(const WifiData& other) = default;
27
28 WifiData::~WifiData() {}
29
30 bool WifiData::DiffersSignificantly(const WifiData& other) const {
31 // More than 4 or 50% of access points added or removed is significant.
32 static const size_t kMinChangedAccessPoints = 4;
33 const size_t min_ap_count =
34 std::min(access_point_data.size(), other.access_point_data.size());
35 const size_t max_ap_count =
36 std::max(access_point_data.size(), other.access_point_data.size());
37 const size_t difference_threadhold = std::min(kMinChangedAccessPoints,
38 min_ap_count / 2);
39 if (max_ap_count > min_ap_count + difference_threadhold)
40 return true;
41 // Compute size of intersection of old and new sets.
42 size_t num_common = 0;
43 for (AccessPointDataSet::const_iterator iter = access_point_data.begin();
44 iter != access_point_data.end();
45 iter++) {
46 if (other.access_point_data.find(*iter) !=
47 other.access_point_data.end()) {
48 ++num_common;
49 }
50 }
51 DCHECK(num_common <= min_ap_count);
52
53 // Test how many have changed.
54 return max_ap_count > num_common + difference_threadhold;
55 }
56
57 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/wifi_data.h ('k') | content/browser/geolocation/wifi_data_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698