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 "chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 : is_page_ready_(false), | 129 : is_page_ready_(false), |
130 scanning_(false), | 130 scanning_(false), |
131 has_pending_results_(false) { | 131 has_pending_results_(false) { |
132 NetworkStateHandler* handler = GetNetworkStateHandler(); | 132 NetworkStateHandler* handler = GetNetworkStateHandler(); |
133 const DeviceState* cellular = | 133 const DeviceState* cellular = |
134 handler->GetDeviceStateByType(NetworkTypePattern::Cellular()); | 134 handler->GetDeviceStateByType(NetworkTypePattern::Cellular()); |
135 if (!cellular) { | 135 if (!cellular) { |
136 NET_LOG_ERROR( | 136 NET_LOG_ERROR( |
137 "A cellular device is not available.", | 137 "A cellular device is not available.", |
138 "Cannot initiate a cellular network scan without a cellular device."); | 138 "Cannot initiate a cellular network scan without a cellular device."); |
| 139 // If there is no cellular device, we set |has_pending_results_| to true so |
| 140 // that HandlePageReady() will show "No networks found." on the web UI. |
| 141 has_pending_results_ = true; |
139 return; | 142 return; |
140 } | 143 } |
141 handler->AddObserver(this, FROM_HERE); | 144 handler->AddObserver(this, FROM_HERE); |
142 device_path_ = cellular->path(); | 145 device_path_ = cellular->path(); |
143 GetNetworkDeviceHandler()->ProposeScan( | 146 GetNetworkDeviceHandler()->ProposeScan( |
144 device_path_, | 147 device_path_, |
145 base::Bind(&base::DoNothing), | 148 base::Bind(&base::DoNothing), |
146 base::Bind(&NetworkOperationErrorCallback, "ProposeScan")); | 149 base::Bind(&NetworkOperationErrorCallback, "ProposeScan")); |
147 } | 150 } |
148 | 151 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } | 217 } |
215 } | 218 } |
216 | 219 |
217 void ChooseMobileNetworkHandler::HandleCancel(const base::ListValue* args) { | 220 void ChooseMobileNetworkHandler::HandleCancel(const base::ListValue* args) { |
218 const size_t kConnectParamCount = 0; | 221 const size_t kConnectParamCount = 0; |
219 if (args->GetSize() != kConnectParamCount) { | 222 if (args->GetSize() != kConnectParamCount) { |
220 NOTREACHED(); | 223 NOTREACHED(); |
221 return; | 224 return; |
222 } | 225 } |
223 | 226 |
| 227 if (device_path_.empty()) |
| 228 return; |
| 229 |
224 // Switch to automatic mode. | 230 // Switch to automatic mode. |
225 GetNetworkDeviceHandler()->RegisterCellularNetwork( | 231 GetNetworkDeviceHandler()->RegisterCellularNetwork( |
226 device_path_, | 232 device_path_, |
227 "", // An empty string is for registration with the home network. | 233 "", // An empty string is for registration with the home network. |
228 base::Bind(&base::DoNothing), | 234 base::Bind(&base::DoNothing), |
229 base::Bind(&NetworkOperationErrorCallback, | 235 base::Bind(&NetworkOperationErrorCallback, |
230 "Register in automatic mode.")); | 236 "Register in automatic mode.")); |
231 } | 237 } |
232 | 238 |
233 void ChooseMobileNetworkHandler::HandleConnect(const base::ListValue* args) { | 239 void ChooseMobileNetworkHandler::HandleConnect(const base::ListValue* args) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 ChooseMobileNetworkUI::ChooseMobileNetworkUI(content::WebUI* web_ui) | 275 ChooseMobileNetworkUI::ChooseMobileNetworkUI(content::WebUI* web_ui) |
270 : WebUIController(web_ui) { | 276 : WebUIController(web_ui) { |
271 web_ui->AddMessageHandler(base::MakeUnique<ChooseMobileNetworkHandler>()); | 277 web_ui->AddMessageHandler(base::MakeUnique<ChooseMobileNetworkHandler>()); |
272 // Set up the "chrome://choose-mobile-network" source. | 278 // Set up the "chrome://choose-mobile-network" source. |
273 Profile* profile = Profile::FromWebUI(web_ui); | 279 Profile* profile = Profile::FromWebUI(web_ui); |
274 content::WebUIDataSource::Add( | 280 content::WebUIDataSource::Add( |
275 profile, CreateChooseMobileNetworkUIHTMLSource()); | 281 profile, CreateChooseMobileNetworkUIHTMLSource()); |
276 } | 282 } |
277 | 283 |
278 } // namespace chromeos | 284 } // namespace chromeos |
OLD | NEW |