Roll WebRTC 9745:9761, Libjingle 9742:9761
[chromium-blink-merge.git] / chromeos / network / network_handler_callbacks.cc
blob5d15182be8cb51269d6d644356a74d3610b27c9f
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.
5 #include "chromeos/network/network_handler_callbacks.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "components/device_event_log/device_event_log.h"
11 namespace {
13 bool SuppressError(const std::string& dbus_error_message) {
14 if (dbus_error_message == "Wake on WiFi not supported")
15 return true;
16 return false;
19 } // namespace
21 namespace chromeos {
22 namespace network_handler {
24 // None of these messages are user-facing, they should only appear in logs.
25 const char kDBusFailedError[] = "Error.DBusFailed";
26 const char kDBusFailedErrorMessage[] = "DBus call failed.";
28 // These are names of fields in the error data dictionary for ErrorCallback.
29 const char kErrorName[] = "errorName";
30 const char kErrorDetail[] = "errorDetail";
31 const char kDbusErrorName[] = "dbusErrorName";
32 const char kDbusErrorMessage[] = "dbusErrorMessage";
33 const char kPath[] = "path";
35 base::DictionaryValue* CreateErrorData(const std::string& path,
36 const std::string& error_name,
37 const std::string& error_detail) {
38 return CreateDBusErrorData(path, error_name, error_detail, "", "");
41 void RunErrorCallback(const ErrorCallback& error_callback,
42 const std::string& path,
43 const std::string& error_name,
44 const std::string& error_detail) {
45 if (error_callback.is_null())
46 return;
47 error_callback.Run(
48 error_name,
49 make_scoped_ptr(CreateErrorData(path, error_name, error_detail)));
52 base::DictionaryValue* CreateDBusErrorData(
53 const std::string& path,
54 const std::string& error_name,
55 const std::string& error_detail,
56 const std::string& dbus_error_name,
57 const std::string& dbus_error_message) {
58 base::DictionaryValue* error_data(new base::DictionaryValue);
59 error_data->SetString(kErrorName, error_name);
60 error_data->SetString(kErrorDetail, error_detail);
61 error_data->SetString(kDbusErrorName, dbus_error_name);
62 error_data->SetString(kDbusErrorMessage, dbus_error_message);
63 if (!path.empty())
64 error_data->SetString(kPath, path);
65 return error_data;
68 void ShillErrorCallbackFunction(const std::string& error_name,
69 const std::string& path,
70 const ErrorCallback& error_callback,
71 const std::string& dbus_error_name,
72 const std::string& dbus_error_message) {
73 std::string detail = error_name + ": ";
74 if (!path.empty())
75 detail += path + ": ";
76 detail += dbus_error_name;
77 if (!dbus_error_message.empty())
78 detail += ": " + dbus_error_message;
79 device_event_log::LogLevel log_level =
80 SuppressError(dbus_error_message) ? device_event_log::LOG_LEVEL_DEBUG
81 : device_event_log::LOG_LEVEL_ERROR;
82 DEVICE_LOG(::device_event_log::LOG_TYPE_NETWORK, log_level) << detail;
84 if (error_callback.is_null())
85 return;
86 scoped_ptr<base::DictionaryValue> error_data(CreateDBusErrorData(
87 path, error_name, detail, dbus_error_name, dbus_error_message));
88 error_callback.Run(error_name, error_data.Pass());
91 void GetPropertiesCallback(const DictionaryResultCallback& callback,
92 const ErrorCallback& error_callback,
93 const std::string& path,
94 DBusMethodCallStatus call_status,
95 const base::DictionaryValue& value) {
96 if (call_status != DBUS_METHOD_CALL_SUCCESS) {
97 NET_LOG(ERROR) << "GetProperties failed: " << path
98 << " Status: " << call_status;
99 RunErrorCallback(
100 error_callback, path, kDBusFailedError, kDBusFailedErrorMessage);
101 } else if (!callback.is_null()) {
102 callback.Run(path, value);
106 } // namespace network_handler
107 } // namespace chromeos