Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/network_state_handler.h" | 5 #include "chromeos/network/network_state_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 } | 78 } |
| 79 | 79 |
| 80 void NetworkStateHandler::Shutdown() { | 80 void NetworkStateHandler::Shutdown() { |
| 81 DCHECK(!did_shutdown_); | 81 DCHECK(!did_shutdown_); |
| 82 did_shutdown_ = true; | 82 did_shutdown_ = true; |
| 83 for (auto& observer : observers_) | 83 for (auto& observer : observers_) |
| 84 observer.OnShuttingDown(); | 84 observer.OnShuttingDown(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void NetworkStateHandler::InitShillPropertyHandler() { | 87 void NetworkStateHandler::InitShillPropertyHandler() { |
| 88 shill_property_handler_.reset(new internal::ShillPropertyHandler(this)); | 88 shill_property_handler_ = |
| 89 base::MakeUnique<internal::ShillPropertyHandler>(this); | |
| 89 shill_property_handler_->Init(); | 90 shill_property_handler_->Init(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 // static | 93 // static |
| 93 NetworkStateHandler* NetworkStateHandler::InitializeForTest() { | 94 std::unique_ptr<NetworkStateHandler> NetworkStateHandler::InitializeForTest() { |
| 94 NetworkStateHandler* handler = new NetworkStateHandler(); | 95 auto handler = base::WrapUnique(new NetworkStateHandler()); |
|
stevenjb
2016/11/04 16:31:37
My understanding is that MakeUnique<NetworkStateHa
Lei Zhang
2016/11/04 18:30:37
First thing I tried, but the ctor is private.
stevenjb
2016/11/04 18:33:31
Ah, right, I remember that part of the discussion
| |
| 95 handler->InitShillPropertyHandler(); | 96 handler->InitShillPropertyHandler(); |
| 96 return handler; | 97 return handler; |
| 97 } | 98 } |
| 98 | 99 |
| 99 void NetworkStateHandler::AddObserver( | 100 void NetworkStateHandler::AddObserver( |
| 100 NetworkStateHandlerObserver* observer, | 101 NetworkStateHandlerObserver* observer, |
| 101 const tracked_objects::Location& from_here) { | 102 const tracked_objects::Location& from_here) { |
| 102 observers_.AddObserver(observer); | 103 observers_.AddObserver(observer); |
| 103 device_event_log::AddEntry( | 104 device_event_log::AddEntry( |
| 104 from_here.file_name(), from_here.line_number(), | 105 from_here.file_name(), from_here.line_number(), |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 if (!network->visible()) | 254 if (!network->visible()) |
| 254 break; | 255 break; |
| 255 if (network->Matches(type)) | 256 if (network->Matches(type)) |
| 256 return network; | 257 return network; |
| 257 } | 258 } |
| 258 return nullptr; | 259 return nullptr; |
| 259 } | 260 } |
| 260 | 261 |
| 261 std::string NetworkStateHandler::FormattedHardwareAddressForType( | 262 std::string NetworkStateHandler::FormattedHardwareAddressForType( |
| 262 const NetworkTypePattern& type) const { | 263 const NetworkTypePattern& type) const { |
| 263 const DeviceState* device = nullptr; | |
| 264 const NetworkState* network = ConnectedNetworkByType(type); | 264 const NetworkState* network = ConnectedNetworkByType(type); |
| 265 if (network) | 265 const DeviceState* device = network ? GetDeviceState(network->device_path()) |
| 266 device = GetDeviceState(network->device_path()); | 266 : GetDeviceStateByType(type); |
| 267 else | |
| 268 device = GetDeviceStateByType(type); | |
| 269 if (!device) | 267 if (!device) |
| 270 return std::string(); | 268 return std::string(); |
| 271 return network_util::FormattedMacAddress(device->mac_address()); | 269 return network_util::FormattedMacAddress(device->mac_address()); |
| 272 } | 270 } |
| 273 | 271 |
| 274 void NetworkStateHandler::GetVisibleNetworkListByType( | 272 void NetworkStateHandler::GetVisibleNetworkListByType( |
| 275 const NetworkTypePattern& type, | 273 const NetworkTypePattern& type, |
| 276 NetworkStateList* list) { | 274 NetworkStateList* list) { |
| 277 GetNetworkListByType(type, false /* configured_only */, | 275 GetNetworkListByType(type, false /* configured_only */, |
| 278 true /* visible_only */, 0 /* no limit */, list); | 276 true /* visible_only */, 0 /* no limit */, list); |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 if (type.MatchesType(shill::kTypeBluetooth)) | 984 if (type.MatchesType(shill::kTypeBluetooth)) |
| 987 technologies.emplace_back(shill::kTypeBluetooth); | 985 technologies.emplace_back(shill::kTypeBluetooth); |
| 988 if (type.MatchesType(shill::kTypeVPN)) | 986 if (type.MatchesType(shill::kTypeVPN)) |
| 989 technologies.emplace_back(shill::kTypeVPN); | 987 technologies.emplace_back(shill::kTypeVPN); |
| 990 | 988 |
| 991 CHECK_GT(technologies.size(), 0ul); | 989 CHECK_GT(technologies.size(), 0ul); |
| 992 return technologies; | 990 return technologies; |
| 993 } | 991 } |
| 994 | 992 |
| 995 } // namespace chromeos | 993 } // namespace chromeos |
| OLD | NEW |