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

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

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 state = private_api::DEVICE_STATE_TYPE_ENABLING; 119 state = private_api::DEVICE_STATE_TYPE_ENABLING;
120 break; 120 break;
121 case NetworkStateHandler::TECHNOLOGY_ENABLED: 121 case NetworkStateHandler::TECHNOLOGY_ENABLED:
122 state = private_api::DEVICE_STATE_TYPE_ENABLED; 122 state = private_api::DEVICE_STATE_TYPE_ENABLED;
123 break; 123 break;
124 case NetworkStateHandler::TECHNOLOGY_PROHIBITED: 124 case NetworkStateHandler::TECHNOLOGY_PROHIBITED:
125 state = private_api::DEVICE_STATE_TYPE_PROHIBITED; 125 state = private_api::DEVICE_STATE_TYPE_PROHIBITED;
126 break; 126 break;
127 } 127 }
128 DCHECK_NE(private_api::DEVICE_STATE_TYPE_NONE, state); 128 DCHECK_NE(private_api::DEVICE_STATE_TYPE_NONE, state);
129 scoped_ptr<private_api::DeviceStateProperties> properties( 129 std::unique_ptr<private_api::DeviceStateProperties> properties(
130 new private_api::DeviceStateProperties); 130 new private_api::DeviceStateProperties);
131 properties->type = private_api::ParseNetworkType(type); 131 properties->type = private_api::ParseNetworkType(type);
132 properties->state = state; 132 properties->state = state;
133 if (device && state == private_api::DEVICE_STATE_TYPE_ENABLED) 133 if (device && state == private_api::DEVICE_STATE_TYPE_ENABLED)
134 properties->scanning.reset(new bool(device->scanning())); 134 properties->scanning.reset(new bool(device->scanning()));
135 if (device && type == ::onc::network_config::kCellular) { 135 if (device && type == ::onc::network_config::kCellular) {
136 properties->sim_present.reset(new bool(!device->IsSimAbsent())); 136 properties->sim_present.reset(new bool(!device->IsSimAbsent()));
137 if (!device->sim_lock_type().empty()) 137 if (!device->sim_lock_type().empty())
138 properties->sim_lock_type.reset(new std::string(device->sim_lock_type())); 138 properties->sim_lock_type.reset(new std::string(device->sim_lock_type()));
139 } 139 }
140 device_state_list->push_back(std::move(properties)); 140 device_state_list->push_back(std::move(properties));
141 } 141 }
142 142
143 void NetworkHandlerFailureCallback( 143 void NetworkHandlerFailureCallback(
144 const NetworkingPrivateDelegate::FailureCallback& callback, 144 const NetworkingPrivateDelegate::FailureCallback& callback,
145 const std::string& error_name, 145 const std::string& error_name,
146 scoped_ptr<base::DictionaryValue> error_data) { 146 std::unique_ptr<base::DictionaryValue> error_data) {
147 callback.Run(error_name); 147 callback.Run(error_name);
148 } 148 }
149 149
150 void RequirePinSuccess( 150 void RequirePinSuccess(
151 const std::string& device_path, 151 const std::string& device_path,
152 const std::string& current_pin, 152 const std::string& current_pin,
153 const std::string& new_pin, 153 const std::string& new_pin,
154 const extensions::NetworkingPrivateChromeOS::VoidCallback& success_callback, 154 const extensions::NetworkingPrivateChromeOS::VoidCallback& success_callback,
155 const extensions::NetworkingPrivateChromeOS::FailureCallback& 155 const extensions::NetworkingPrivateChromeOS::FailureCallback&
156 failure_callback) { 156 failure_callback) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 } // namespace 202 } // namespace
203 203
204 //////////////////////////////////////////////////////////////////////////////// 204 ////////////////////////////////////////////////////////////////////////////////
205 205
206 namespace extensions { 206 namespace extensions {
207 207
208 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS( 208 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS(
209 content::BrowserContext* browser_context, 209 content::BrowserContext* browser_context,
210 scoped_ptr<VerifyDelegate> verify_delegate) 210 std::unique_ptr<VerifyDelegate> verify_delegate)
211 : NetworkingPrivateDelegate(std::move(verify_delegate)), 211 : NetworkingPrivateDelegate(std::move(verify_delegate)),
212 browser_context_(browser_context), 212 browser_context_(browser_context),
213 weak_ptr_factory_(this) {} 213 weak_ptr_factory_(this) {}
214 214
215 NetworkingPrivateChromeOS::~NetworkingPrivateChromeOS() { 215 NetworkingPrivateChromeOS::~NetworkingPrivateChromeOS() {
216 } 216 }
217 217
218 void NetworkingPrivateChromeOS::GetProperties( 218 void NetworkingPrivateChromeOS::GetProperties(
219 const std::string& guid, 219 const std::string& guid,
220 const DictionaryCallback& success_callback, 220 const DictionaryCallback& success_callback,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 272 }
273 273
274 const chromeos::NetworkState* network_state = 274 const chromeos::NetworkState* network_state =
275 GetStateHandler()->GetNetworkStateFromServicePath( 275 GetStateHandler()->GetNetworkStateFromServicePath(
276 service_path, false /* configured_only */); 276 service_path, false /* configured_only */);
277 if (!network_state) { 277 if (!network_state) {
278 failure_callback.Run(networking_private::kErrorNetworkUnavailable); 278 failure_callback.Run(networking_private::kErrorNetworkUnavailable);
279 return; 279 return;
280 } 280 }
281 281
282 scoped_ptr<base::DictionaryValue> network_properties = 282 std::unique_ptr<base::DictionaryValue> network_properties =
283 chromeos::network_util::TranslateNetworkStateToONC(network_state); 283 chromeos::network_util::TranslateNetworkStateToONC(network_state);
284 AppendThirdPartyProviderName(network_properties.get()); 284 AppendThirdPartyProviderName(network_properties.get());
285 285
286 success_callback.Run(std::move(network_properties)); 286 success_callback.Run(std::move(network_properties));
287 } 287 }
288 288
289 void NetworkingPrivateChromeOS::SetProperties( 289 void NetworkingPrivateChromeOS::SetProperties(
290 const std::string& guid, 290 const std::string& guid,
291 scoped_ptr<base::DictionaryValue> properties, 291 std::unique_ptr<base::DictionaryValue> properties,
292 const VoidCallback& success_callback, 292 const VoidCallback& success_callback,
293 const FailureCallback& failure_callback) { 293 const FailureCallback& failure_callback) {
294 std::string service_path, error; 294 std::string service_path, error;
295 if (!GetServicePathFromGuid(guid, &service_path, &error)) { 295 if (!GetServicePathFromGuid(guid, &service_path, &error)) {
296 failure_callback.Run(error); 296 failure_callback.Run(error);
297 return; 297 return;
298 } 298 }
299 299
300 GetManagedConfigurationHandler()->SetProperties( 300 GetManagedConfigurationHandler()->SetProperties(
301 service_path, *properties, success_callback, 301 service_path, *properties, success_callback,
302 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); 302 base::Bind(&NetworkHandlerFailureCallback, failure_callback));
303 } 303 }
304 304
305 void NetworkHandlerCreateCallback( 305 void NetworkHandlerCreateCallback(
306 const NetworkingPrivateDelegate::StringCallback& callback, 306 const NetworkingPrivateDelegate::StringCallback& callback,
307 const std::string& service_path, 307 const std::string& service_path,
308 const std::string& guid) { 308 const std::string& guid) {
309 callback.Run(guid); 309 callback.Run(guid);
310 } 310 }
311 311
312 void NetworkingPrivateChromeOS::CreateNetwork( 312 void NetworkingPrivateChromeOS::CreateNetwork(
313 bool shared, 313 bool shared,
314 scoped_ptr<base::DictionaryValue> properties, 314 std::unique_ptr<base::DictionaryValue> properties,
315 const StringCallback& success_callback, 315 const StringCallback& success_callback,
316 const FailureCallback& failure_callback) { 316 const FailureCallback& failure_callback) {
317 std::string user_id_hash, error; 317 std::string user_id_hash, error;
318 // Do not allow configuring a non-shared network from a non-primary user. 318 // Do not allow configuring a non-shared network from a non-primary user.
319 if (!shared && 319 if (!shared &&
320 !GetPrimaryUserIdHash(browser_context_, &user_id_hash, &error)) { 320 !GetPrimaryUserIdHash(browser_context_, &user_id_hash, &error)) {
321 failure_callback.Run(error); 321 failure_callback.Run(error);
322 return; 322 return;
323 } 323 }
324 324
(...skipping 20 matching lines...) Expand all
345 345
346 void NetworkingPrivateChromeOS::GetNetworks( 346 void NetworkingPrivateChromeOS::GetNetworks(
347 const std::string& network_type, 347 const std::string& network_type,
348 bool configured_only, 348 bool configured_only,
349 bool visible_only, 349 bool visible_only,
350 int limit, 350 int limit,
351 const NetworkListCallback& success_callback, 351 const NetworkListCallback& success_callback,
352 const FailureCallback& failure_callback) { 352 const FailureCallback& failure_callback) {
353 NetworkTypePattern pattern = 353 NetworkTypePattern pattern =
354 chromeos::onc::NetworkTypePatternFromOncType(network_type); 354 chromeos::onc::NetworkTypePatternFromOncType(network_type);
355 scoped_ptr<base::ListValue> network_properties_list = 355 std::unique_ptr<base::ListValue> network_properties_list =
356 chromeos::network_util::TranslateNetworkListToONC( 356 chromeos::network_util::TranslateNetworkListToONC(
357 pattern, configured_only, visible_only, limit); 357 pattern, configured_only, visible_only, limit);
358 358
359 for (base::Value* value : *network_properties_list) { 359 for (base::Value* value : *network_properties_list) {
360 base::DictionaryValue* network_dict = nullptr; 360 base::DictionaryValue* network_dict = nullptr;
361 value->GetAsDictionary(&network_dict); 361 value->GetAsDictionary(&network_dict);
362 DCHECK(network_dict); 362 DCHECK(network_dict);
363 if (GetThirdPartyVPNDictionary(network_dict)) 363 if (GetThirdPartyVPNDictionary(network_dict))
364 AppendThirdPartyProviderName(network_dict); 364 AppendThirdPartyProviderName(network_dict);
365 } 365 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 542
543 // Only set a new pin if require_pin is true. 543 // Only set a new pin if require_pin is true.
544 std::string set_new_pin = require_pin ? new_pin : ""; 544 std::string set_new_pin = require_pin ? new_pin : "";
545 NetworkHandler::Get()->network_device_handler()->RequirePin( 545 NetworkHandler::Get()->network_device_handler()->RequirePin(
546 device_state->path(), require_pin, current_pin, 546 device_state->path(), require_pin, current_pin,
547 base::Bind(&RequirePinSuccess, device_state->path(), current_pin, 547 base::Bind(&RequirePinSuccess, device_state->path(), current_pin,
548 set_new_pin, success_callback, failure_callback), 548 set_new_pin, success_callback, failure_callback),
549 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); 549 base::Bind(&NetworkHandlerFailureCallback, failure_callback));
550 } 550 }
551 551
552 scoped_ptr<base::ListValue> 552 std::unique_ptr<base::ListValue>
553 NetworkingPrivateChromeOS::GetEnabledNetworkTypes() { 553 NetworkingPrivateChromeOS::GetEnabledNetworkTypes() {
554 chromeos::NetworkStateHandler* state_handler = GetStateHandler(); 554 chromeos::NetworkStateHandler* state_handler = GetStateHandler();
555 555
556 scoped_ptr<base::ListValue> network_list(new base::ListValue); 556 std::unique_ptr<base::ListValue> network_list(new base::ListValue);
557 557
558 if (state_handler->IsTechnologyEnabled(NetworkTypePattern::Ethernet())) 558 if (state_handler->IsTechnologyEnabled(NetworkTypePattern::Ethernet()))
559 network_list->AppendString(::onc::network_type::kEthernet); 559 network_list->AppendString(::onc::network_type::kEthernet);
560 if (state_handler->IsTechnologyEnabled(NetworkTypePattern::WiFi())) 560 if (state_handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()))
561 network_list->AppendString(::onc::network_type::kWiFi); 561 network_list->AppendString(::onc::network_type::kWiFi);
562 if (state_handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())) 562 if (state_handler->IsTechnologyEnabled(NetworkTypePattern::Wimax()))
563 network_list->AppendString(::onc::network_type::kWimax); 563 network_list->AppendString(::onc::network_type::kWimax);
564 if (state_handler->IsTechnologyEnabled(NetworkTypePattern::Cellular())) 564 if (state_handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()))
565 network_list->AppendString(::onc::network_type::kCellular); 565 network_list->AppendString(::onc::network_type::kCellular);
566 566
567 return network_list; 567 return network_list;
568 } 568 }
569 569
570 scoped_ptr<NetworkingPrivateDelegate::DeviceStateList> 570 std::unique_ptr<NetworkingPrivateDelegate::DeviceStateList>
571 NetworkingPrivateChromeOS::GetDeviceStateList() { 571 NetworkingPrivateChromeOS::GetDeviceStateList() {
572 std::set<std::string> technologies_found; 572 std::set<std::string> technologies_found;
573 NetworkStateHandler::DeviceStateList devices; 573 NetworkStateHandler::DeviceStateList devices;
574 NetworkHandler::Get()->network_state_handler()->GetDeviceList(&devices); 574 NetworkHandler::Get()->network_state_handler()->GetDeviceList(&devices);
575 575
576 scoped_ptr<DeviceStateList> device_state_list(new DeviceStateList); 576 std::unique_ptr<DeviceStateList> device_state_list(new DeviceStateList);
577 for (const DeviceState* device : devices) { 577 for (const DeviceState* device : devices) {
578 std::string onc_type = 578 std::string onc_type =
579 chromeos::network_util::TranslateShillTypeToONC(device->type()); 579 chromeos::network_util::TranslateShillTypeToONC(device->type());
580 AppendDeviceState(onc_type, device, device_state_list.get()); 580 AppendDeviceState(onc_type, device, device_state_list.get());
581 technologies_found.insert(onc_type); 581 technologies_found.insert(onc_type);
582 } 582 }
583 583
584 // For any technologies that we do not have a DeviceState entry for, append 584 // For any technologies that we do not have a DeviceState entry for, append
585 // an entry if the technolog is available. 585 // an entry if the technolog is available.
586 const char* technology_types[] = {::onc::network_type::kEthernet, 586 const char* technology_types[] = {::onc::network_type::kEthernet,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 GetStateHandler()->RequestScan(); 620 GetStateHandler()->RequestScan();
621 return true; 621 return true;
622 } 622 }
623 623
624 // Private methods 624 // Private methods
625 625
626 void NetworkingPrivateChromeOS::GetPropertiesCallback( 626 void NetworkingPrivateChromeOS::GetPropertiesCallback(
627 const DictionaryCallback& callback, 627 const DictionaryCallback& callback,
628 const std::string& service_path, 628 const std::string& service_path,
629 const base::DictionaryValue& dictionary) { 629 const base::DictionaryValue& dictionary) {
630 scoped_ptr<base::DictionaryValue> dictionary_copy(dictionary.DeepCopy()); 630 std::unique_ptr<base::DictionaryValue> dictionary_copy(dictionary.DeepCopy());
631 AppendThirdPartyProviderName(dictionary_copy.get()); 631 AppendThirdPartyProviderName(dictionary_copy.get());
632 callback.Run(std::move(dictionary_copy)); 632 callback.Run(std::move(dictionary_copy));
633 } 633 }
634 634
635 // Populate ThirdPartyVPN.kProviderName for third-party VPNs. 635 // Populate ThirdPartyVPN.kProviderName for third-party VPNs.
636 void NetworkingPrivateChromeOS::AppendThirdPartyProviderName( 636 void NetworkingPrivateChromeOS::AppendThirdPartyProviderName(
637 base::DictionaryValue* dictionary) { 637 base::DictionaryValue* dictionary) {
638 base::DictionaryValue* third_party_vpn = 638 base::DictionaryValue* third_party_vpn =
639 GetThirdPartyVPNDictionary(dictionary); 639 GetThirdPartyVPNDictionary(dictionary);
640 if (!third_party_vpn) 640 if (!third_party_vpn)
(...skipping 12 matching lines...) Expand all
653 break; 653 break;
654 } 654 }
655 } 655 }
656 } 656 }
657 657
658 void NetworkingPrivateChromeOS::ConnectFailureCallback( 658 void NetworkingPrivateChromeOS::ConnectFailureCallback(
659 const std::string& guid, 659 const std::string& guid,
660 const VoidCallback& success_callback, 660 const VoidCallback& success_callback,
661 const FailureCallback& failure_callback, 661 const FailureCallback& failure_callback,
662 const std::string& error_name, 662 const std::string& error_name,
663 scoped_ptr<base::DictionaryValue> error_data) { 663 std::unique_ptr<base::DictionaryValue> error_data) {
664 // TODO(stevenjb): Temporary workaround to show the configuration UI. 664 // TODO(stevenjb): Temporary workaround to show the configuration UI.
665 // Eventually the caller (e.g. Settings) should handle any failures and 665 // Eventually the caller (e.g. Settings) should handle any failures and
666 // show its own configuration UI. crbug.com/380937. 666 // show its own configuration UI. crbug.com/380937.
667 if (ui_delegate()->HandleConnectFailed(guid, error_name)) { 667 if (ui_delegate()->HandleConnectFailed(guid, error_name)) {
668 success_callback.Run(); 668 success_callback.Run();
669 return; 669 return;
670 } 670 }
671 failure_callback.Run(error_name); 671 failure_callback.Run(error_name);
672 } 672 }
673 673
674 } // namespace extensions 674 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698