network_handler_callbacks.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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 3// found in the LICENSE file. 4 5#include "chromeos/network/network_handler_callbacks.h" 6 7#include "base/logging.h" 8#include "base/values.h" 9#include "chromeos/network/network_event_log.h" 10 11namespace chromeos { 12namespace network_handler { 13 14// These are names of fields in the error data dictionary for ErrorCallback. 15const char kErrorName[] = "errorName"; 16const char kErrorMessage[] = "errorMessage"; 17const char kServicePath[] = "servicePath"; 18 19base::DictionaryValue* CreateErrorData(const std::string& service_path, 20 const std::string& error_name, 21 const std::string& error_message) { 22 base::DictionaryValue* error_data(new base::DictionaryValue); 23 error_data->SetString(kErrorName, error_name); 24 error_data->SetString(kErrorMessage, error_message); 25 if (!service_path.empty()) 26 error_data->SetString(kServicePath, service_path); 27 return error_data; 28} 29 30void ShillErrorCallbackFunction(const std::string& path, 31 const ErrorCallback& error_callback, 32 const std::string& error_name, 33 const std::string& error_message) { 34 std::string error = "Shill Error"; 35 if (!path.empty()) 36 error += " For " + path; 37 error += ": " + error_name; 38 NET_LOG_ERROR(error, error_message); 39 LOG(ERROR) << error << " : " << error_message; 40 if (error_callback.is_null()) 41 return; 42 scoped_ptr<base::DictionaryValue> error_data( 43 CreateErrorData(path, error_name, error_message)); 44 error_callback.Run(error_name, error_data.Pass()); 45} 46 47} // namespace network_handler 48} // namespace chromeos 49