Chromium Code Reviews| 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 "chrome/browser/ui/webui/chromeos/network_config_message_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/network_config_message_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chromeos/login/login_state.h" | 13 #include "chromeos/login/login_state.h" |
| 14 #include "chromeos/network/device_state.h" | |
| 14 #include "chromeos/network/managed_network_configuration_handler.h" | 15 #include "chromeos/network/managed_network_configuration_handler.h" |
| 15 #include "chromeos/network/network_configuration_handler.h" | 16 #include "chromeos/network/network_configuration_handler.h" |
| 16 #include "chromeos/network/network_state.h" | 17 #include "chromeos/network/network_state.h" |
| 17 #include "chromeos/network/network_state_handler.h" | 18 #include "chromeos/network/network_state_handler.h" |
| 18 #include "chromeos/network/network_util.h" | 19 #include "chromeos/network/network_util.h" |
| 19 #include "chromeos/network/onc/onc_signature.h" | 20 #include "chromeos/network/onc/onc_signature.h" |
| 20 #include "chromeos/network/onc/onc_utils.h" | 21 #include "chromeos/network/onc/onc_utils.h" |
| 21 #include "chromeos/network/shill_property_util.h" | 22 #include "chromeos/network/shill_property_util.h" |
| 22 #include "components/onc/onc_constants.h" | 23 #include "components/onc/onc_constants.h" |
| 23 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 NOTREACHED(); | 167 NOTREACHED(); |
| 167 } | 168 } |
| 168 std::string service_path; | 169 std::string service_path; |
| 169 if (!GetServicePathFromGuid(guid, &service_path)) { | 170 if (!GetServicePathFromGuid(guid, &service_path)) { |
| 170 scoped_ptr<base::DictionaryValue> error_data; | 171 scoped_ptr<base::DictionaryValue> error_data; |
| 171 ErrorCallback(callback_id, "Error.InvalidNetworkGuid", error_data.Pass()); | 172 ErrorCallback(callback_id, "Error.InvalidNetworkGuid", error_data.Pass()); |
| 172 return; | 173 return; |
| 173 } | 174 } |
| 174 NetworkHandler::Get()->network_configuration_handler()->GetProperties( | 175 NetworkHandler::Get()->network_configuration_handler()->GetProperties( |
| 175 service_path, | 176 service_path, |
| 176 base::Bind(&NetworkConfigMessageHandler::GetPropertiesSuccess, | 177 base::Bind(&NetworkConfigMessageHandler::GetShillPropertiesSuccess, |
| 177 weak_ptr_factory_.GetWeakPtr(), callback_id), | 178 weak_ptr_factory_.GetWeakPtr(), callback_id), |
| 178 base::Bind(&NetworkConfigMessageHandler::ErrorCallback, | 179 base::Bind(&NetworkConfigMessageHandler::ErrorCallback, |
| 179 weak_ptr_factory_.GetWeakPtr(), callback_id)); | 180 weak_ptr_factory_.GetWeakPtr(), callback_id)); |
| 180 } | 181 } |
| 181 | 182 |
| 183 void NetworkConfigMessageHandler::GetShillPropertiesSuccess( | |
| 184 int callback_id, | |
| 185 const std::string& service_path, | |
| 186 const base::DictionaryValue& dictionary) const { | |
| 187 scoped_ptr<base::DictionaryValue> dictionary_copy(dictionary.DeepCopy()); | |
| 188 | |
| 189 // Get the device properties for debugging. | |
| 190 std::string device; | |
| 191 dictionary_copy->GetStringWithoutPathExpansion( | |
| 192 shill::kDeviceProperty, &device); | |
| 193 const DeviceState* device_state = | |
| 194 NetworkHandler::Get()->network_state_handler()->GetDeviceState(device); | |
| 195 if (device_state) { | |
| 196 base::DictionaryValue* device_dictionary = | |
| 197 device_state->properties().DeepCopy(); | |
| 198 dictionary_copy->Set("Device", device_dictionary); | |
|
pneubeck (no reviews)
2014/08/22 08:55:32
nit: FWIW, in ManagedNetworkConfigurationHandlerIm
stevenjb
2014/08/22 17:08:43
Done.
| |
| 199 } | |
| 200 GetPropertiesSuccess(callback_id, service_path, *dictionary_copy); | |
| 201 } | |
| 202 | |
| 182 void NetworkConfigMessageHandler::InvokeCallback( | 203 void NetworkConfigMessageHandler::InvokeCallback( |
| 183 const base::ListValue& arg_list) const { | 204 const base::ListValue& arg_list) const { |
| 184 web_ui()->CallJavascriptFunction( | 205 web_ui()->CallJavascriptFunction( |
| 185 "networkConfig.chromeCallbackSuccess", arg_list); | 206 "networkConfig.chromeCallbackSuccess", arg_list); |
| 186 } | 207 } |
| 187 | 208 |
| 188 void NetworkConfigMessageHandler::ErrorCallback( | 209 void NetworkConfigMessageHandler::ErrorCallback( |
| 189 int callback_id, | 210 int callback_id, |
| 190 const std::string& error_name, | 211 const std::string& error_name, |
| 191 scoped_ptr<base::DictionaryValue> error_data) const { | 212 scoped_ptr<base::DictionaryValue> error_data) const { |
| 192 LOG(ERROR) << "NetworkConfigMessageHandler Error: " << error_name; | 213 LOG(ERROR) << "NetworkConfigMessageHandler Error: " << error_name; |
| 193 base::ListValue arg_list; | 214 base::ListValue arg_list; |
| 194 arg_list.AppendInteger(callback_id); | 215 arg_list.AppendInteger(callback_id); |
| 195 arg_list.AppendString(error_name); | 216 arg_list.AppendString(error_name); |
| 196 web_ui()->CallJavascriptFunction( | 217 web_ui()->CallJavascriptFunction( |
| 197 "networkConfig.chromeCallbackError", arg_list); | 218 "networkConfig.chromeCallbackError", arg_list); |
| 198 } | 219 } |
| 199 | 220 |
| 200 } // namespace chromeos | 221 } // namespace chromeos |
| OLD | NEW |