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

Side by Side Diff: extensions/browser/api/networking_private/networking_private_chromeos.cc

Issue 2303093003: MD Settings: Internet: Enable SIM unlock with no cellular network (Closed)
Patch Set: Rebase plus Feedback Created 4 years, 3 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
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 18 matching lines...) Expand all
29 #include "content/public/browser/browser_context.h" 29 #include "content/public/browser/browser_context.h"
30 #include "extensions/browser/api/networking_private/networking_private_api.h" 30 #include "extensions/browser/api/networking_private/networking_private_api.h"
31 #include "extensions/browser/extension_registry.h" 31 #include "extensions/browser/extension_registry.h"
32 #include "extensions/browser/extensions_browser_client.h" 32 #include "extensions/browser/extensions_browser_client.h"
33 #include "extensions/common/extension.h" 33 #include "extensions/common/extension.h"
34 #include "extensions/common/extension_set.h" 34 #include "extensions/common/extension_set.h"
35 #include "extensions/common/permissions/api_permission.h" 35 #include "extensions/common/permissions/api_permission.h"
36 #include "extensions/common/permissions/permissions_data.h" 36 #include "extensions/common/permissions/permissions_data.h"
37 #include "third_party/cros_system_api/dbus/service_constants.h" 37 #include "third_party/cros_system_api/dbus/service_constants.h"
38 38
39 using chromeos::DeviceState;
40 using chromeos::NetworkHandler; 39 using chromeos::NetworkHandler;
41 using chromeos::NetworkStateHandler; 40 using chromeos::NetworkStateHandler;
42 using chromeos::NetworkTypePattern; 41 using chromeos::NetworkTypePattern;
43 using chromeos::ShillManagerClient; 42 using chromeos::ShillManagerClient;
44 using extensions::NetworkingPrivateDelegate; 43 using extensions::NetworkingPrivateDelegate;
45 44
46 namespace private_api = extensions::api::networking_private; 45 namespace private_api = extensions::api::networking_private;
47 46
48 namespace { 47 namespace {
49 48
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 *error = "Error.NonPrimaryUser"; 85 *error = "Error.NonPrimaryUser";
87 return false; 86 return false;
88 } 87 }
89 if (user_hash) 88 if (user_hash)
90 *user_hash = context_user_hash; 89 *user_hash = context_user_hash;
91 return true; 90 return true;
92 } 91 }
93 92
94 void AppendDeviceState( 93 void AppendDeviceState(
95 const std::string& type, 94 const std::string& type,
96 const DeviceState* device, 95 const chromeos::DeviceState* device,
97 NetworkingPrivateDelegate::DeviceStateList* device_state_list) { 96 NetworkingPrivateDelegate::DeviceStateList* device_state_list) {
98 DCHECK(!type.empty()); 97 DCHECK(!type.empty());
99 NetworkTypePattern pattern = 98 NetworkTypePattern pattern =
100 chromeos::onc::NetworkTypePatternFromOncType(type); 99 chromeos::onc::NetworkTypePatternFromOncType(type);
101 NetworkStateHandler::TechnologyState technology_state = 100 NetworkStateHandler::TechnologyState technology_state =
102 GetStateHandler()->GetTechnologyState(pattern); 101 GetStateHandler()->GetTechnologyState(pattern);
103 private_api::DeviceStateType state = private_api::DEVICE_STATE_TYPE_NONE; 102 private_api::DeviceStateType state = private_api::DEVICE_STATE_TYPE_NONE;
104 switch (technology_state) { 103 switch (technology_state) {
105 case NetworkStateHandler::TECHNOLOGY_UNAVAILABLE: 104 case NetworkStateHandler::TECHNOLOGY_UNAVAILABLE:
106 if (!device) 105 if (!device)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 return nullptr; 191 return nullptr;
193 if (GetStringFromDictionary(*vpn_dict, ::onc::vpn::kType) != 192 if (GetStringFromDictionary(*vpn_dict, ::onc::vpn::kType) !=
194 ::onc::vpn::kThirdPartyVpn) { 193 ::onc::vpn::kThirdPartyVpn) {
195 return nullptr; 194 return nullptr;
196 } 195 }
197 base::DictionaryValue* third_party_vpn = nullptr; 196 base::DictionaryValue* third_party_vpn = nullptr;
198 vpn_dict->GetDictionary(::onc::vpn::kThirdPartyVpn, &third_party_vpn); 197 vpn_dict->GetDictionary(::onc::vpn::kThirdPartyVpn, &third_party_vpn);
199 return third_party_vpn; 198 return third_party_vpn;
200 } 199 }
201 200
201 const chromeos::DeviceState* GetCellularDeviceState(const std::string& guid) {
202 const chromeos::NetworkState* network_state = nullptr;
203 if (!guid.empty())
204 network_state = GetStateHandler()->GetNetworkStateFromGuid(guid);
205 const chromeos::DeviceState* device_state = nullptr;
206 if (network_state) {
207 device_state =
208 GetStateHandler()->GetDeviceState(network_state->device_path());
209 }
210 if (!device_state) {
211 device_state =
212 GetStateHandler()->GetDeviceStateByType(NetworkTypePattern::Cellular());
213 }
214 return device_state;
215 }
216
202 } // namespace 217 } // namespace
203 218
204 //////////////////////////////////////////////////////////////////////////////// 219 ////////////////////////////////////////////////////////////////////////////////
205 220
206 namespace extensions { 221 namespace extensions {
207 222
208 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS( 223 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS(
209 content::BrowserContext* browser_context, 224 content::BrowserContext* browser_context,
210 std::unique_ptr<VerifyDelegate> verify_delegate) 225 std::unique_ptr<VerifyDelegate> verify_delegate)
211 : NetworkingPrivateDelegate(std::move(verify_delegate)), 226 : NetworkingPrivateDelegate(std::move(verify_delegate)),
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 ->GetCaptivePortalState(guid) 492 ->GetCaptivePortalState(guid)
478 .status)); 493 .status));
479 } 494 }
480 495
481 void NetworkingPrivateChromeOS::UnlockCellularSim( 496 void NetworkingPrivateChromeOS::UnlockCellularSim(
482 const std::string& guid, 497 const std::string& guid,
483 const std::string& pin, 498 const std::string& pin,
484 const std::string& puk, 499 const std::string& puk,
485 const VoidCallback& success_callback, 500 const VoidCallback& success_callback,
486 const FailureCallback& failure_callback) { 501 const FailureCallback& failure_callback) {
487 const chromeos::NetworkState* network_state = 502 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) { 503 if (!device_state) {
496 failure_callback.Run(networking_private::kErrorNetworkUnavailable); 504 failure_callback.Run(networking_private::kErrorNetworkUnavailable);
497 return; 505 return;
498 } 506 }
499 std::string lock_type = device_state->sim_lock_type(); 507 std::string lock_type = device_state->sim_lock_type();
500 if (lock_type.empty()) { 508 if (lock_type.empty()) {
501 // Sim is already unlocked. 509 // Sim is already unlocked.
502 failure_callback.Run(networking_private::kErrorInvalidNetworkOperation); 510 failure_callback.Run(networking_private::kErrorInvalidNetworkOperation);
503 return; 511 return;
504 } 512 }
(...skipping 10 matching lines...) Expand all
515 } 523 }
516 } 524 }
517 525
518 void NetworkingPrivateChromeOS::SetCellularSimState( 526 void NetworkingPrivateChromeOS::SetCellularSimState(
519 const std::string& guid, 527 const std::string& guid,
520 bool require_pin, 528 bool require_pin,
521 const std::string& current_pin, 529 const std::string& current_pin,
522 const std::string& new_pin, 530 const std::string& new_pin,
523 const VoidCallback& success_callback, 531 const VoidCallback& success_callback,
524 const FailureCallback& failure_callback) { 532 const FailureCallback& failure_callback) {
525 const chromeos::NetworkState* network_state = 533 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) { 534 if (!device_state) {
534 failure_callback.Run(networking_private::kErrorNetworkUnavailable); 535 failure_callback.Run(networking_private::kErrorNetworkUnavailable);
535 return; 536 return;
536 } 537 }
537 if (!device_state->sim_lock_type().empty()) { 538 if (!device_state->sim_lock_type().empty()) {
538 // The SIM needs to be unlocked before the state can be changed. 539 // The SIM needs to be unlocked before the state can be changed.
539 failure_callback.Run(networking_private::kErrorSimLocked); 540 failure_callback.Run(networking_private::kErrorSimLocked);
540 return; 541 return;
541 } 542 }
542 543
(...skipping 24 matching lines...) Expand all
567 return network_list; 568 return network_list;
568 } 569 }
569 570
570 std::unique_ptr<NetworkingPrivateDelegate::DeviceStateList> 571 std::unique_ptr<NetworkingPrivateDelegate::DeviceStateList>
571 NetworkingPrivateChromeOS::GetDeviceStateList() { 572 NetworkingPrivateChromeOS::GetDeviceStateList() {
572 std::set<std::string> technologies_found; 573 std::set<std::string> technologies_found;
573 NetworkStateHandler::DeviceStateList devices; 574 NetworkStateHandler::DeviceStateList devices;
574 NetworkHandler::Get()->network_state_handler()->GetDeviceList(&devices); 575 NetworkHandler::Get()->network_state_handler()->GetDeviceList(&devices);
575 576
576 std::unique_ptr<DeviceStateList> device_state_list(new DeviceStateList); 577 std::unique_ptr<DeviceStateList> device_state_list(new DeviceStateList);
577 for (const DeviceState* device : devices) { 578 for (const chromeos::DeviceState* device : devices) {
578 std::string onc_type = 579 std::string onc_type =
579 chromeos::network_util::TranslateShillTypeToONC(device->type()); 580 chromeos::network_util::TranslateShillTypeToONC(device->type());
580 AppendDeviceState(onc_type, device, device_state_list.get()); 581 AppendDeviceState(onc_type, device, device_state_list.get());
581 technologies_found.insert(onc_type); 582 technologies_found.insert(onc_type);
582 } 583 }
583 584
584 // For any technologies that we do not have a DeviceState entry for, append 585 // For any technologies that we do not have a DeviceState entry for, append
585 // an entry if the technolog is available. 586 // an entry if the technolog is available.
586 const char* technology_types[] = {::onc::network_type::kEthernet, 587 const char* technology_types[] = {::onc::network_type::kEthernet,
587 ::onc::network_type::kWiFi, 588 ::onc::network_type::kWiFi,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 // Eventually the caller (e.g. Settings) should handle any failures and 666 // Eventually the caller (e.g. Settings) should handle any failures and
666 // show its own configuration UI. crbug.com/380937. 667 // show its own configuration UI. crbug.com/380937.
667 if (ui_delegate()->HandleConnectFailed(guid, error_name)) { 668 if (ui_delegate()->HandleConnectFailed(guid, error_name)) {
668 success_callback.Run(); 669 success_callback.Run();
669 return; 670 return;
670 } 671 }
671 failure_callback.Run(error_name); 672 failure_callback.Run(error_name);
672 } 673 }
673 674
674 } // namespace extensions 675 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698