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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/networking_private/networking_private_chromeos.cc
diff --git a/extensions/browser/api/networking_private/networking_private_chromeos.cc b/extensions/browser/api/networking_private/networking_private_chromeos.cc
index b580cdae8b3d9e7e339aae226efff817cd516426..48f13a2ad0f6583d670c19746e57b099d3d785b7 100644
--- a/extensions/browser/api/networking_private/networking_private_chromeos.cc
+++ b/extensions/browser/api/networking_private/networking_private_chromeos.cc
@@ -36,7 +36,6 @@
#include "extensions/common/permissions/permissions_data.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
-using chromeos::DeviceState;
using chromeos::NetworkHandler;
using chromeos::NetworkStateHandler;
using chromeos::NetworkTypePattern;
@@ -93,7 +92,7 @@ bool GetPrimaryUserIdHash(content::BrowserContext* browser_context,
void AppendDeviceState(
const std::string& type,
- const DeviceState* device,
+ const chromeos::DeviceState* device,
NetworkingPrivateDelegate::DeviceStateList* device_state_list) {
DCHECK(!type.empty());
NetworkTypePattern pattern =
@@ -199,6 +198,22 @@ base::DictionaryValue* GetThirdPartyVPNDictionary(
return third_party_vpn;
}
+const chromeos::DeviceState* GetCellularDeviceState(const std::string& guid) {
+ const chromeos::NetworkState* network_state = nullptr;
+ if (!guid.empty())
+ network_state = GetStateHandler()->GetNetworkStateFromGuid(guid);
+ const chromeos::DeviceState* device_state = nullptr;
+ if (network_state) {
+ device_state =
+ GetStateHandler()->GetDeviceState(network_state->device_path());
+ }
+ if (!device_state) {
+ device_state =
+ GetStateHandler()->GetDeviceStateByType(NetworkTypePattern::Cellular());
+ }
+ return device_state;
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -484,14 +499,7 @@ void NetworkingPrivateChromeOS::UnlockCellularSim(
const std::string& puk,
const VoidCallback& success_callback,
const FailureCallback& failure_callback) {
- const chromeos::NetworkState* network_state =
- GetStateHandler()->GetNetworkStateFromGuid(guid);
- if (!network_state) {
- failure_callback.Run(networking_private::kErrorNetworkUnavailable);
- return;
- }
- const chromeos::DeviceState* device_state =
- GetStateHandler()->GetDeviceState(network_state->device_path());
+ const chromeos::DeviceState* device_state = GetCellularDeviceState(guid);
if (!device_state) {
failure_callback.Run(networking_private::kErrorNetworkUnavailable);
return;
@@ -522,14 +530,7 @@ void NetworkingPrivateChromeOS::SetCellularSimState(
const std::string& new_pin,
const VoidCallback& success_callback,
const FailureCallback& failure_callback) {
- const chromeos::NetworkState* network_state =
- GetStateHandler()->GetNetworkStateFromGuid(guid);
- if (!network_state) {
- failure_callback.Run(networking_private::kErrorNetworkUnavailable);
- return;
- }
- const chromeos::DeviceState* device_state =
- GetStateHandler()->GetDeviceState(network_state->device_path());
+ const chromeos::DeviceState* device_state = GetCellularDeviceState(guid);
if (!device_state) {
failure_callback.Run(networking_private::kErrorNetworkUnavailable);
return;
@@ -574,7 +575,7 @@ NetworkingPrivateChromeOS::GetDeviceStateList() {
NetworkHandler::Get()->network_state_handler()->GetDeviceList(&devices);
std::unique_ptr<DeviceStateList> device_state_list(new DeviceStateList);
- for (const DeviceState* device : devices) {
+ for (const chromeos::DeviceState* device : devices) {
std::string onc_type =
chromeos::network_util::TranslateShillTypeToONC(device->type());
AppendDeviceState(onc_type, device, device_state_list.get());

Powered by Google App Engine
This is Rietveld 408576698