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 #ifndef CHROMEOS_NETWORK_NETWORK_HANDLER_CALLBACKS_H_ 6 #define CHROMEOS_NETWORK_NETWORK_HANDLER_CALLBACKS_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "base/callback.h" 12 #include "base/component_export.h" 13 #include "base/optional.h" 14 #include "base/values.h" 15 #include "chromeos/dbus/dbus_method_call_status.h" 16 17 namespace chromeos { 18 namespace network_handler { 19 20 COMPONENT_EXPORT(CHROMEOS_NETWORK) extern const char kDBusFailedError[]; 21 COMPONENT_EXPORT(CHROMEOS_NETWORK) extern const char kDBusFailedErrorMessage[]; 22 COMPONENT_EXPORT(CHROMEOS_NETWORK) extern const char kErrorName[]; 23 COMPONENT_EXPORT(CHROMEOS_NETWORK) extern const char kErrorDetail[]; 24 COMPONENT_EXPORT(CHROMEOS_NETWORK) extern const char kDbusErrorName[]; 25 COMPONENT_EXPORT(CHROMEOS_NETWORK) extern const char kDbusErrorMessage[]; 26 27 // On success, |result| contains the result. On failure, |result| is nullopt. 28 using ResultCallback = 29 base::OnceCallback<void(const std::string& service_path, 30 base::Optional<base::Value> result)>; 31 32 // On success, |properties| contains the resulting properties and |error| is 33 // nullopt. On failure, |result| is nullopt and |error| may contain an error 34 // identifier. 35 using PropertiesCallback = 36 base::OnceCallback<void(const std::string& service_path, 37 base::Optional<base::Value> properties, 38 base::Optional<std::string> error)>; 39 40 // An error callback used by both the configuration handler and the state 41 // handler to receive error results from the API. 42 using ErrorCallback = 43 base::OnceCallback<void(const std::string& error_name, 44 std::unique_ptr<base::DictionaryValue> error_data)>; 45 46 using ServiceResultCallback = 47 base::OnceCallback<void(const std::string& service_path, 48 const std::string& guid)>; 49 50 // Create a DictionaryValue for passing to ErrorCallback. 51 COMPONENT_EXPORT(CHROMEOS_NETWORK) 52 base::DictionaryValue* CreateErrorData(const std::string& path, 53 const std::string& error_name, 54 const std::string& error_detail); 55 56 // If not NULL, runs |error_callback| with an ErrorData dictionary created from 57 // the other arguments. 58 COMPONENT_EXPORT(CHROMEOS_NETWORK) 59 void RunErrorCallback(ErrorCallback error_callback, 60 const std::string& path, 61 const std::string& error_name, 62 const std::string& error_detail); 63 64 COMPONENT_EXPORT(CHROMEOS_NETWORK) 65 std::unique_ptr<base::DictionaryValue> CreateDBusErrorData( 66 const std::string& path, 67 const std::string& error_name, 68 const std::string& error_detail, 69 const std::string& dbus_error_name, 70 const std::string& dbus_error_message); 71 72 // Callback for Shill errors. 73 // |error_name| is the error name passed to |error_callback|. 74 // |path| is the associated object path or blank if not relevant. 75 // |dbus_error_name| and |dbus_error_message| are provided by the DBus handler. 76 // Logs an error and calls |error_callback| if not null. 77 COMPONENT_EXPORT(CHROMEOS_NETWORK) 78 void ShillErrorCallbackFunction(const std::string& error_name, 79 const std::string& path, 80 ErrorCallback error_callback, 81 const std::string& dbus_error_name, 82 const std::string& dbus_error_message); 83 84 } // namespace network_handler 85 } // namespace chromeos 86 87 #endif // CHROMEOS_NETWORK_NETWORK_HANDLER_CALLBACKS_H_ 88