| 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_api.h" | 5 #include "extensions/browser/api/networking_private/networking_private_api.h" | 
| 6 | 6 | 
|  | 7 #include <utility> | 
|  | 8 | 
| 7 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" | 
| 9 #include "base/callback.h" | 11 #include "base/callback.h" | 
| 10 #include "components/onc/onc_constants.h" | 12 #include "components/onc/onc_constants.h" | 
| 11 #include "extensions/browser/api/networking_private/networking_private_delegate.
     h" | 13 #include "extensions/browser/api/networking_private/networking_private_delegate.
     h" | 
| 12 #include "extensions/browser/api/networking_private/networking_private_delegate_
     factory.h" | 14 #include "extensions/browser/api/networking_private/networking_private_delegate_
     factory.h" | 
| 13 #include "extensions/browser/extension_function_registry.h" | 15 #include "extensions/browser/extension_function_registry.h" | 
| 14 #include "extensions/common/api/networking_private.h" | 16 #include "extensions/common/api/networking_private.h" | 
| 15 | 17 | 
| 16 namespace { | 18 namespace { | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 57   GetDelegate(browser_context()) | 59   GetDelegate(browser_context()) | 
| 58       ->GetProperties( | 60       ->GetProperties( | 
| 59           params->network_guid, | 61           params->network_guid, | 
| 60           base::Bind(&NetworkingPrivateGetPropertiesFunction::Success, this), | 62           base::Bind(&NetworkingPrivateGetPropertiesFunction::Success, this), | 
| 61           base::Bind(&NetworkingPrivateGetPropertiesFunction::Failure, this)); | 63           base::Bind(&NetworkingPrivateGetPropertiesFunction::Failure, this)); | 
| 62   return true; | 64   return true; | 
| 63 } | 65 } | 
| 64 | 66 | 
| 65 void NetworkingPrivateGetPropertiesFunction::Success( | 67 void NetworkingPrivateGetPropertiesFunction::Success( | 
| 66     std::unique_ptr<base::DictionaryValue> result) { | 68     std::unique_ptr<base::DictionaryValue> result) { | 
| 67   SetResult(result.release()); | 69   SetResult(std::move(result)); | 
| 68   SendResponse(true); | 70   SendResponse(true); | 
| 69 } | 71 } | 
| 70 | 72 | 
| 71 void NetworkingPrivateGetPropertiesFunction::Failure(const std::string& error) { | 73 void NetworkingPrivateGetPropertiesFunction::Failure(const std::string& error) { | 
| 72   error_ = error; | 74   error_ = error; | 
| 73   SendResponse(false); | 75   SendResponse(false); | 
| 74 } | 76 } | 
| 75 | 77 | 
| 76 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// | 
| 77 // NetworkingPrivateGetManagedPropertiesFunction | 79 // NetworkingPrivateGetManagedPropertiesFunction | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 90           params->network_guid, | 92           params->network_guid, | 
| 91           base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success, | 93           base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success, | 
| 92                      this), | 94                      this), | 
| 93           base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure, | 95           base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure, | 
| 94                      this)); | 96                      this)); | 
| 95   return true; | 97   return true; | 
| 96 } | 98 } | 
| 97 | 99 | 
| 98 void NetworkingPrivateGetManagedPropertiesFunction::Success( | 100 void NetworkingPrivateGetManagedPropertiesFunction::Success( | 
| 99     std::unique_ptr<base::DictionaryValue> result) { | 101     std::unique_ptr<base::DictionaryValue> result) { | 
| 100   SetResult(result.release()); | 102   SetResult(std::move(result)); | 
| 101   SendResponse(true); | 103   SendResponse(true); | 
| 102 } | 104 } | 
| 103 | 105 | 
| 104 void NetworkingPrivateGetManagedPropertiesFunction::Failure( | 106 void NetworkingPrivateGetManagedPropertiesFunction::Failure( | 
| 105     const std::string& error) { | 107     const std::string& error) { | 
| 106   error_ = error; | 108   error_ = error; | 
| 107   SendResponse(false); | 109   SendResponse(false); | 
| 108 } | 110 } | 
| 109 | 111 | 
| 110 //////////////////////////////////////////////////////////////////////////////// | 112 //////////////////////////////////////////////////////////////////////////////// | 
| 111 // NetworkingPrivateGetStateFunction | 113 // NetworkingPrivateGetStateFunction | 
| 112 | 114 | 
| 113 NetworkingPrivateGetStateFunction::~NetworkingPrivateGetStateFunction() { | 115 NetworkingPrivateGetStateFunction::~NetworkingPrivateGetStateFunction() { | 
| 114 } | 116 } | 
| 115 | 117 | 
| 116 bool NetworkingPrivateGetStateFunction::RunAsync() { | 118 bool NetworkingPrivateGetStateFunction::RunAsync() { | 
| 117   std::unique_ptr<private_api::GetState::Params> params = | 119   std::unique_ptr<private_api::GetState::Params> params = | 
| 118       private_api::GetState::Params::Create(*args_); | 120       private_api::GetState::Params::Create(*args_); | 
| 119   EXTENSION_FUNCTION_VALIDATE(params); | 121   EXTENSION_FUNCTION_VALIDATE(params); | 
| 120 | 122 | 
| 121   GetDelegate(browser_context()) | 123   GetDelegate(browser_context()) | 
| 122       ->GetState(params->network_guid, | 124       ->GetState(params->network_guid, | 
| 123                  base::Bind(&NetworkingPrivateGetStateFunction::Success, this), | 125                  base::Bind(&NetworkingPrivateGetStateFunction::Success, this), | 
| 124                  base::Bind(&NetworkingPrivateGetStateFunction::Failure, this)); | 126                  base::Bind(&NetworkingPrivateGetStateFunction::Failure, this)); | 
| 125   return true; | 127   return true; | 
| 126 } | 128 } | 
| 127 | 129 | 
| 128 void NetworkingPrivateGetStateFunction::Success( | 130 void NetworkingPrivateGetStateFunction::Success( | 
| 129     std::unique_ptr<base::DictionaryValue> result) { | 131     std::unique_ptr<base::DictionaryValue> result) { | 
| 130   SetResult(result.release()); | 132   SetResult(std::move(result)); | 
| 131   SendResponse(true); | 133   SendResponse(true); | 
| 132 } | 134 } | 
| 133 | 135 | 
| 134 void NetworkingPrivateGetStateFunction::Failure(const std::string& error) { | 136 void NetworkingPrivateGetStateFunction::Failure(const std::string& error) { | 
| 135   error_ = error; | 137   error_ = error; | 
| 136   SendResponse(false); | 138   SendResponse(false); | 
| 137 } | 139 } | 
| 138 | 140 | 
| 139 //////////////////////////////////////////////////////////////////////////////// | 141 //////////////////////////////////////////////////////////////////////////////// | 
| 140 // NetworkingPrivateSetPropertiesFunction | 142 // NetworkingPrivateSetPropertiesFunction | 
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 252   GetDelegate(browser_context()) | 254   GetDelegate(browser_context()) | 
| 253       ->GetNetworks( | 255       ->GetNetworks( | 
| 254           network_type, configured_only, visible_only, limit, | 256           network_type, configured_only, visible_only, limit, | 
| 255           base::Bind(&NetworkingPrivateGetNetworksFunction::Success, this), | 257           base::Bind(&NetworkingPrivateGetNetworksFunction::Success, this), | 
| 256           base::Bind(&NetworkingPrivateGetNetworksFunction::Failure, this)); | 258           base::Bind(&NetworkingPrivateGetNetworksFunction::Failure, this)); | 
| 257   return true; | 259   return true; | 
| 258 } | 260 } | 
| 259 | 261 | 
| 260 void NetworkingPrivateGetNetworksFunction::Success( | 262 void NetworkingPrivateGetNetworksFunction::Success( | 
| 261     std::unique_ptr<base::ListValue> network_list) { | 263     std::unique_ptr<base::ListValue> network_list) { | 
| 262   SetResult(network_list.release()); | 264   SetResult(std::move(network_list)); | 
| 263   SendResponse(true); | 265   SendResponse(true); | 
| 264 } | 266 } | 
| 265 | 267 | 
| 266 void NetworkingPrivateGetNetworksFunction::Failure(const std::string& error) { | 268 void NetworkingPrivateGetNetworksFunction::Failure(const std::string& error) { | 
| 267   error_ = error; | 269   error_ = error; | 
| 268   SendResponse(false); | 270   SendResponse(false); | 
| 269 } | 271 } | 
| 270 | 272 | 
| 271 //////////////////////////////////////////////////////////////////////////////// | 273 //////////////////////////////////////////////////////////////////////////////// | 
| 272 // NetworkingPrivateGetVisibleNetworksFunction | 274 // NetworkingPrivateGetVisibleNetworksFunction | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 289           network_type, configured_only, visible_only, kDefaultNetworkListLimit, | 291           network_type, configured_only, visible_only, kDefaultNetworkListLimit, | 
| 290           base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success, | 292           base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success, | 
| 291                      this), | 293                      this), | 
| 292           base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure, | 294           base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure, | 
| 293                      this)); | 295                      this)); | 
| 294   return true; | 296   return true; | 
| 295 } | 297 } | 
| 296 | 298 | 
| 297 void NetworkingPrivateGetVisibleNetworksFunction::Success( | 299 void NetworkingPrivateGetVisibleNetworksFunction::Success( | 
| 298     std::unique_ptr<base::ListValue> network_properties_list) { | 300     std::unique_ptr<base::ListValue> network_properties_list) { | 
| 299   SetResult(network_properties_list.release()); | 301   SetResult(std::move(network_properties_list)); | 
| 300   SendResponse(true); | 302   SendResponse(true); | 
| 301 } | 303 } | 
| 302 | 304 | 
| 303 void NetworkingPrivateGetVisibleNetworksFunction::Failure( | 305 void NetworkingPrivateGetVisibleNetworksFunction::Failure( | 
| 304     const std::string& error) { | 306     const std::string& error) { | 
| 305   error_ = error; | 307   error_ = error; | 
| 306   SendResponse(false); | 308   SendResponse(false); | 
| 307 } | 309 } | 
| 308 | 310 | 
| 309 //////////////////////////////////////////////////////////////////////////////// | 311 //////////////////////////////////////////////////////////////////////////////// | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 335     } else if (type == ::onc::network_type::kWimax) { | 337     } else if (type == ::onc::network_type::kWimax) { | 
| 336       enabled_networks_list->AppendString( | 338       enabled_networks_list->AppendString( | 
| 337           private_api::ToString(private_api::NETWORK_TYPE_WIMAX)); | 339           private_api::ToString(private_api::NETWORK_TYPE_WIMAX)); | 
| 338     } else if (type == ::onc::network_type::kCellular) { | 340     } else if (type == ::onc::network_type::kCellular) { | 
| 339       enabled_networks_list->AppendString( | 341       enabled_networks_list->AppendString( | 
| 340           private_api::ToString(private_api::NETWORK_TYPE_CELLULAR)); | 342           private_api::ToString(private_api::NETWORK_TYPE_CELLULAR)); | 
| 341     } else { | 343     } else { | 
| 342       LOG(ERROR) << "networkingPrivate: Unexpected type: " << type; | 344       LOG(ERROR) << "networkingPrivate: Unexpected type: " << type; | 
| 343     } | 345     } | 
| 344   } | 346   } | 
| 345   SetResult(enabled_networks_list.release()); | 347   SetResult(std::move(enabled_networks_list)); | 
| 346   return true; | 348   return true; | 
| 347 } | 349 } | 
| 348 | 350 | 
| 349 //////////////////////////////////////////////////////////////////////////////// | 351 //////////////////////////////////////////////////////////////////////////////// | 
| 350 // NetworkingPrivateGetDeviceStatesFunction | 352 // NetworkingPrivateGetDeviceStatesFunction | 
| 351 | 353 | 
| 352 NetworkingPrivateGetDeviceStatesFunction:: | 354 NetworkingPrivateGetDeviceStatesFunction:: | 
| 353     ~NetworkingPrivateGetDeviceStatesFunction() { | 355     ~NetworkingPrivateGetDeviceStatesFunction() { | 
| 354 } | 356 } | 
| 355 | 357 | 
| 356 bool NetworkingPrivateGetDeviceStatesFunction::RunSync() { | 358 bool NetworkingPrivateGetDeviceStatesFunction::RunSync() { | 
| 357   std::unique_ptr<NetworkingPrivateDelegate::DeviceStateList> device_states( | 359   std::unique_ptr<NetworkingPrivateDelegate::DeviceStateList> device_states( | 
| 358       GetDelegate(browser_context())->GetDeviceStateList()); | 360       GetDelegate(browser_context())->GetDeviceStateList()); | 
| 359   if (!device_states) { | 361   if (!device_states) { | 
| 360     error_ = networking_private::kErrorNotSupported; | 362     error_ = networking_private::kErrorNotSupported; | 
| 361     return false; | 363     return false; | 
| 362   } | 364   } | 
| 363 | 365 | 
| 364   std::unique_ptr<base::ListValue> device_state_list(new base::ListValue); | 366   std::unique_ptr<base::ListValue> device_state_list(new base::ListValue); | 
| 365   for (const auto& properties : *device_states) | 367   for (const auto& properties : *device_states) | 
| 366     device_state_list->Append(properties->ToValue().release()); | 368     device_state_list->Append(properties->ToValue().release()); | 
| 367   SetResult(device_state_list.release()); | 369   SetResult(std::move(device_state_list)); | 
| 368   return true; | 370   return true; | 
| 369 } | 371 } | 
| 370 | 372 | 
| 371 //////////////////////////////////////////////////////////////////////////////// | 373 //////////////////////////////////////////////////////////////////////////////// | 
| 372 // NetworkingPrivateEnableNetworkTypeFunction | 374 // NetworkingPrivateEnableNetworkTypeFunction | 
| 373 | 375 | 
| 374 NetworkingPrivateEnableNetworkTypeFunction:: | 376 NetworkingPrivateEnableNetworkTypeFunction:: | 
| 375     ~NetworkingPrivateEnableNetworkTypeFunction() { | 377     ~NetworkingPrivateEnableNetworkTypeFunction() { | 
| 376 } | 378 } | 
| 377 | 379 | 
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 764   SendResponse(true); | 766   SendResponse(true); | 
| 765 } | 767 } | 
| 766 | 768 | 
| 767 void NetworkingPrivateSetCellularSimStateFunction::Failure( | 769 void NetworkingPrivateSetCellularSimStateFunction::Failure( | 
| 768     const std::string& error) { | 770     const std::string& error) { | 
| 769   error_ = error; | 771   error_ = error; | 
| 770   SendResponse(false); | 772   SendResponse(false); | 
| 771 } | 773 } | 
| 772 | 774 | 
| 773 }  // namespace extensions | 775 }  // namespace extensions | 
| OLD | NEW | 
|---|