| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/network/geolocation_handler.h" | 5 #include "chromeos/network/geolocation_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 8 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/values.h" | 12 #include "base/values.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/shill_manager_client.h" | 14 #include "chromeos/dbus/shill_manager_client.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 | 16 |
| 14 namespace chromeos { | 17 namespace chromeos { |
| 15 | 18 |
| 16 GeolocationHandler::GeolocationHandler() | 19 GeolocationHandler::GeolocationHandler() |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 void GeolocationHandler::Init() { | 31 void GeolocationHandler::Init() { |
| 29 ShillManagerClient* manager_client = | 32 ShillManagerClient* manager_client = |
| 30 DBusThreadManager::Get()->GetShillManagerClient(); | 33 DBusThreadManager::Get()->GetShillManagerClient(); |
| 31 manager_client->GetProperties( | 34 manager_client->GetProperties( |
| 32 base::Bind(&GeolocationHandler::ManagerPropertiesCallback, | 35 base::Bind(&GeolocationHandler::ManagerPropertiesCallback, |
| 33 weak_ptr_factory_.GetWeakPtr())); | 36 weak_ptr_factory_.GetWeakPtr())); |
| 34 manager_client->AddPropertyChangedObserver(this); | 37 manager_client->AddPropertyChangedObserver(this); |
| 35 } | 38 } |
| 36 | 39 |
| 37 bool GeolocationHandler::GetWifiAccessPoints( | 40 bool GeolocationHandler::GetWifiAccessPoints( |
| 38 WifiAccessPointVector* access_points, int64* age_ms) { | 41 WifiAccessPointVector* access_points, |
| 42 int64_t* age_ms) { |
| 39 if (!wifi_enabled_) | 43 if (!wifi_enabled_) |
| 40 return false; | 44 return false; |
| 41 // Always request updated access points. | 45 // Always request updated access points. |
| 42 RequestWifiAccessPoints(); | 46 RequestWifiAccessPoints(); |
| 43 // If no data has been received, return false. | 47 // If no data has been received, return false. |
| 44 if (geolocation_received_time_.is_null()) | 48 if (geolocation_received_time_.is_null()) |
| 45 return false; | 49 return false; |
| 46 if (access_points) | 50 if (access_points) |
| 47 *access_points = wifi_access_points_; | 51 *access_points = wifi_access_points_; |
| 48 if (age_ms) { | 52 if (age_ms) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 const base::DictionaryValue* entry = NULL; | 124 const base::DictionaryValue* entry = NULL; |
| 121 if (!entry_list->GetDictionary(i, &entry) || !entry) { | 125 if (!entry_list->GetDictionary(i, &entry) || !entry) { |
| 122 LOG(WARNING) << "Geolocation list value not a Dictionary: " << i; | 126 LOG(WARNING) << "Geolocation list value not a Dictionary: " << i; |
| 123 continue; | 127 continue; |
| 124 } | 128 } |
| 125 // Docs: developers.google.com/maps/documentation/business/geolocation | 129 // Docs: developers.google.com/maps/documentation/business/geolocation |
| 126 WifiAccessPoint wap; | 130 WifiAccessPoint wap; |
| 127 entry->GetString(shill::kGeoMacAddressProperty, &wap.mac_address); | 131 entry->GetString(shill::kGeoMacAddressProperty, &wap.mac_address); |
| 128 std::string age_str; | 132 std::string age_str; |
| 129 if (entry->GetString(shill::kGeoAgeProperty, &age_str)) { | 133 if (entry->GetString(shill::kGeoAgeProperty, &age_str)) { |
| 130 int64 age_ms; | 134 int64_t age_ms; |
| 131 if (base::StringToInt64(age_str, &age_ms)) { | 135 if (base::StringToInt64(age_str, &age_ms)) { |
| 132 wap.timestamp = | 136 wap.timestamp = |
| 133 base::Time::Now() - base::TimeDelta::FromMilliseconds(age_ms); | 137 base::Time::Now() - base::TimeDelta::FromMilliseconds(age_ms); |
| 134 } | 138 } |
| 135 } | 139 } |
| 136 std::string strength_str; | 140 std::string strength_str; |
| 137 if (entry->GetString(shill::kGeoSignalStrengthProperty, &strength_str)) | 141 if (entry->GetString(shill::kGeoSignalStrengthProperty, &strength_str)) |
| 138 base::StringToInt(strength_str, &wap.signal_strength); | 142 base::StringToInt(strength_str, &wap.signal_strength); |
| 139 std::string signal_str; | 143 std::string signal_str; |
| 140 if (entry->GetString(shill::kGeoSignalToNoiseRatioProperty, &signal_str)) | 144 if (entry->GetString(shill::kGeoSignalToNoiseRatioProperty, &signal_str)) |
| 141 base::StringToInt(signal_str, &wap.signal_to_noise); | 145 base::StringToInt(signal_str, &wap.signal_to_noise); |
| 142 std::string channel_str; | 146 std::string channel_str; |
| 143 if (entry->GetString(shill::kGeoChannelProperty, &channel_str)) | 147 if (entry->GetString(shill::kGeoChannelProperty, &channel_str)) |
| 144 base::StringToInt(channel_str, &wap.channel); | 148 base::StringToInt(channel_str, &wap.channel); |
| 145 wifi_access_points_.push_back(wap); | 149 wifi_access_points_.push_back(wap); |
| 146 } | 150 } |
| 147 } | 151 } |
| 148 geolocation_received_time_ = base::Time::Now(); | 152 geolocation_received_time_ = base::Time::Now(); |
| 149 } | 153 } |
| 150 | 154 |
| 151 } // namespace chromeos | 155 } // namespace chromeos |
| OLD | NEW |