| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/shill_manager_client.h" | 11 #include "chromeos/dbus/shill_manager_client.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace chromeos { |
| 15 | 15 |
| 16 static GeolocationHandler* g_geolocation_handler = NULL; | |
| 17 | |
| 18 GeolocationHandler::GeolocationHandler() | 16 GeolocationHandler::GeolocationHandler() |
| 19 : wifi_enabled_(false), | 17 : wifi_enabled_(false), |
| 20 weak_ptr_factory_(this) { | 18 weak_ptr_factory_(this) { |
| 21 } | 19 } |
| 22 | 20 |
| 23 GeolocationHandler::~GeolocationHandler() { | 21 GeolocationHandler::~GeolocationHandler() { |
| 24 ShillManagerClient* manager_client = | 22 ShillManagerClient* manager_client = |
| 25 DBusThreadManager::Get()->GetShillManagerClient(); | 23 DBusThreadManager::Get()->GetShillManagerClient(); |
| 26 if (manager_client) | 24 if (manager_client) |
| 27 manager_client->RemovePropertyChangedObserver(this); | 25 manager_client->RemovePropertyChangedObserver(this); |
| 28 } | 26 } |
| 29 | 27 |
| 30 void GeolocationHandler::Init() { | 28 void GeolocationHandler::Init() { |
| 31 ShillManagerClient* manager_client = | 29 ShillManagerClient* manager_client = |
| 32 DBusThreadManager::Get()->GetShillManagerClient(); | 30 DBusThreadManager::Get()->GetShillManagerClient(); |
| 33 manager_client->GetProperties( | 31 manager_client->GetProperties( |
| 34 base::Bind(&GeolocationHandler::ManagerPropertiesCallback, | 32 base::Bind(&GeolocationHandler::ManagerPropertiesCallback, |
| 35 weak_ptr_factory_.GetWeakPtr())); | 33 weak_ptr_factory_.GetWeakPtr())); |
| 36 manager_client->AddPropertyChangedObserver(this); | 34 manager_client->AddPropertyChangedObserver(this); |
| 37 } | 35 } |
| 38 | 36 |
| 39 // static | |
| 40 void GeolocationHandler::Initialize() { | |
| 41 CHECK(!g_geolocation_handler); | |
| 42 g_geolocation_handler = new GeolocationHandler(); | |
| 43 g_geolocation_handler->Init(); | |
| 44 } | |
| 45 | |
| 46 // static | |
| 47 void GeolocationHandler::Shutdown() { | |
| 48 CHECK(g_geolocation_handler); | |
| 49 delete g_geolocation_handler; | |
| 50 g_geolocation_handler = NULL; | |
| 51 } | |
| 52 | |
| 53 // static | |
| 54 GeolocationHandler* GeolocationHandler::Get() { | |
| 55 CHECK(g_geolocation_handler) | |
| 56 << "GeolocationHandler::Get() called before Initialize()"; | |
| 57 return g_geolocation_handler; | |
| 58 } | |
| 59 | |
| 60 bool GeolocationHandler::GetWifiAccessPoints( | 37 bool GeolocationHandler::GetWifiAccessPoints( |
| 61 WifiAccessPointVector* access_points, int64* age_ms) { | 38 WifiAccessPointVector* access_points, int64* age_ms) { |
| 62 if (!wifi_enabled_) | 39 if (!wifi_enabled_) |
| 63 return false; | 40 return false; |
| 64 // Always request updated access points. | 41 // Always request updated access points. |
| 65 RequestWifiAccessPoints(); | 42 RequestWifiAccessPoints(); |
| 66 // If no data has been received, return false. | 43 // If no data has been received, return false. |
| 67 if (geolocation_received_time_.is_null()) | 44 if (geolocation_received_time_.is_null()) |
| 68 return false; | 45 return false; |
| 69 if (access_points) | 46 if (access_points) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 std::string channel_str; | 142 std::string channel_str; |
| 166 if (entry->GetString(shill::kGeoChannelProperty, &channel_str)) | 143 if (entry->GetString(shill::kGeoChannelProperty, &channel_str)) |
| 167 base::StringToInt(channel_str, &wap.channel); | 144 base::StringToInt(channel_str, &wap.channel); |
| 168 wifi_access_points_.push_back(wap); | 145 wifi_access_points_.push_back(wap); |
| 169 } | 146 } |
| 170 } | 147 } |
| 171 geolocation_received_time_ = base::Time::Now(); | 148 geolocation_received_time_ = base::Time::Now(); |
| 172 } | 149 } |
| 173 | 150 |
| 174 } // namespace chromeos | 151 } // namespace chromeos |
| OLD | NEW |