OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/networking_private/networking_private_chromeos. h" | 5 #include "extensions/browser/api/networking_private/networking_private_chromeos. h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 return nullptr; | 192 return nullptr; |
193 if (GetStringFromDictionary(*vpn_dict, ::onc::vpn::kType) != | 193 if (GetStringFromDictionary(*vpn_dict, ::onc::vpn::kType) != |
194 ::onc::vpn::kThirdPartyVpn) { | 194 ::onc::vpn::kThirdPartyVpn) { |
195 return nullptr; | 195 return nullptr; |
196 } | 196 } |
197 base::DictionaryValue* third_party_vpn = nullptr; | 197 base::DictionaryValue* third_party_vpn = nullptr; |
198 vpn_dict->GetDictionary(::onc::vpn::kThirdPartyVpn, &third_party_vpn); | 198 vpn_dict->GetDictionary(::onc::vpn::kThirdPartyVpn, &third_party_vpn); |
199 return third_party_vpn; | 199 return third_party_vpn; |
200 } | 200 } |
201 | 201 |
202 const chromeos::DeviceState* GetCellularDeviceState(const std::string& guid) { | |
michaelpg
2016/09/06 21:10:38
chromeos::DeviceState is using'd at the top of the
stevenjb
2016/09/12 19:46:42
I remove the 'using'.
| |
203 const chromeos::NetworkState* network_state = nullptr; | |
204 if (!guid.empty()) | |
205 network_state = GetStateHandler()->GetNetworkStateFromGuid(guid); | |
206 const chromeos::DeviceState* device_state = nullptr; | |
207 if (network_state) { | |
208 device_state = | |
209 GetStateHandler()->GetDeviceState(network_state->device_path()); | |
210 } | |
211 if (!device_state) { | |
212 device_state = | |
213 GetStateHandler()->GetDeviceStateByType(NetworkTypePattern::Cellular()); | |
214 } | |
215 return device_state; | |
216 } | |
217 | |
202 } // namespace | 218 } // namespace |
203 | 219 |
204 //////////////////////////////////////////////////////////////////////////////// | 220 //////////////////////////////////////////////////////////////////////////////// |
205 | 221 |
206 namespace extensions { | 222 namespace extensions { |
207 | 223 |
208 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS( | 224 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS( |
209 content::BrowserContext* browser_context, | 225 content::BrowserContext* browser_context, |
210 std::unique_ptr<VerifyDelegate> verify_delegate) | 226 std::unique_ptr<VerifyDelegate> verify_delegate) |
211 : NetworkingPrivateDelegate(std::move(verify_delegate)), | 227 : NetworkingPrivateDelegate(std::move(verify_delegate)), |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 ->GetCaptivePortalState(guid) | 493 ->GetCaptivePortalState(guid) |
478 .status)); | 494 .status)); |
479 } | 495 } |
480 | 496 |
481 void NetworkingPrivateChromeOS::UnlockCellularSim( | 497 void NetworkingPrivateChromeOS::UnlockCellularSim( |
482 const std::string& guid, | 498 const std::string& guid, |
483 const std::string& pin, | 499 const std::string& pin, |
484 const std::string& puk, | 500 const std::string& puk, |
485 const VoidCallback& success_callback, | 501 const VoidCallback& success_callback, |
486 const FailureCallback& failure_callback) { | 502 const FailureCallback& failure_callback) { |
487 const chromeos::NetworkState* network_state = | 503 const chromeos::DeviceState* device_state = GetCellularDeviceState(guid); |
488 GetStateHandler()->GetNetworkStateFromGuid(guid); | |
489 if (!network_state) { | |
490 failure_callback.Run(networking_private::kErrorNetworkUnavailable); | |
491 return; | |
492 } | |
493 const chromeos::DeviceState* device_state = | |
494 GetStateHandler()->GetDeviceState(network_state->device_path()); | |
495 if (!device_state) { | 504 if (!device_state) { |
496 failure_callback.Run(networking_private::kErrorNetworkUnavailable); | 505 failure_callback.Run(networking_private::kErrorNetworkUnavailable); |
497 return; | 506 return; |
498 } | 507 } |
499 std::string lock_type = device_state->sim_lock_type(); | 508 std::string lock_type = device_state->sim_lock_type(); |
500 if (lock_type.empty()) { | 509 if (lock_type.empty()) { |
501 // Sim is already unlocked. | 510 // Sim is already unlocked. |
502 failure_callback.Run(networking_private::kErrorInvalidNetworkOperation); | 511 failure_callback.Run(networking_private::kErrorInvalidNetworkOperation); |
503 return; | 512 return; |
504 } | 513 } |
(...skipping 10 matching lines...) Expand all Loading... | |
515 } | 524 } |
516 } | 525 } |
517 | 526 |
518 void NetworkingPrivateChromeOS::SetCellularSimState( | 527 void NetworkingPrivateChromeOS::SetCellularSimState( |
519 const std::string& guid, | 528 const std::string& guid, |
520 bool require_pin, | 529 bool require_pin, |
521 const std::string& current_pin, | 530 const std::string& current_pin, |
522 const std::string& new_pin, | 531 const std::string& new_pin, |
523 const VoidCallback& success_callback, | 532 const VoidCallback& success_callback, |
524 const FailureCallback& failure_callback) { | 533 const FailureCallback& failure_callback) { |
525 const chromeos::NetworkState* network_state = | 534 const chromeos::DeviceState* device_state = GetCellularDeviceState(guid); |
526 GetStateHandler()->GetNetworkStateFromGuid(guid); | |
527 if (!network_state) { | |
528 failure_callback.Run(networking_private::kErrorNetworkUnavailable); | |
529 return; | |
530 } | |
531 const chromeos::DeviceState* device_state = | |
532 GetStateHandler()->GetDeviceState(network_state->device_path()); | |
533 if (!device_state) { | 535 if (!device_state) { |
534 failure_callback.Run(networking_private::kErrorNetworkUnavailable); | 536 failure_callback.Run(networking_private::kErrorNetworkUnavailable); |
535 return; | 537 return; |
536 } | 538 } |
537 if (!device_state->sim_lock_type().empty()) { | 539 if (!device_state->sim_lock_type().empty()) { |
538 // The SIM needs to be unlocked before the state can be changed. | 540 // The SIM needs to be unlocked before the state can be changed. |
539 failure_callback.Run(networking_private::kErrorSimLocked); | 541 failure_callback.Run(networking_private::kErrorSimLocked); |
540 return; | 542 return; |
541 } | 543 } |
542 | 544 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 // Eventually the caller (e.g. Settings) should handle any failures and | 667 // Eventually the caller (e.g. Settings) should handle any failures and |
666 // show its own configuration UI. crbug.com/380937. | 668 // show its own configuration UI. crbug.com/380937. |
667 if (ui_delegate()->HandleConnectFailed(guid, error_name)) { | 669 if (ui_delegate()->HandleConnectFailed(guid, error_name)) { |
668 success_callback.Run(); | 670 success_callback.Run(); |
669 return; | 671 return; |
670 } | 672 } |
671 failure_callback.Run(error_name); | 673 failure_callback.Run(error_name); |
672 } | 674 } |
673 | 675 |
674 } // namespace extensions | 676 } // namespace extensions |
OLD | NEW |