blob: 1ddef60187718d0f41e8a104c3bc997123575d68 [file] [log] [blame]
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "feedback/feedback_service_interface.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "chromeos/dbus/service_constants.h"
#include "components/feedback/feedback_common.h"
#include "components/feedback/proto/extension.pb.h"
#include "dbus/object_proxy.h"
DBusFeedbackServiceInterface::DBusFeedbackServiceInterface() {
dbus::Bus::Options options;
options.bus_type = dbus::Bus::SYSTEM;
bus_ = new dbus::Bus(options);
}
bool DBusFeedbackServiceInterface::SendFeedback(
const FeedbackCommon& feedback,
FeedbackResultCallback callback) {
// A product ID of 0 generally means that the caller just forgot to
// set it at all, and an empty description is apparently ignored
// by the feedback servers.
if (feedback.description().empty() || feedback.product_id() == 0) {
return false;
}
userfeedback::ExtensionSubmit submit;
feedback.PrepareReport(&submit);
dbus::MethodCall call(feedback::kFeedbackServiceName,
feedback::kSendFeedback);
dbus::MessageWriter writer(&call);
writer.AppendProtoAsArrayOfBytes(submit);
dbus::ObjectProxy* object = bus_->GetObjectProxy(
feedback::kFeedbackServiceName,
dbus::ObjectPath(feedback::kFeedbackServicePath));
scoped_ptr<dbus::Response> response(object->CallMethodAndBlock(
&call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
if (response.get() == nullptr) {
callback.Run(false);
return true;
}
bool status = false;
const auto &message_type = response->GetMessageType();
if (message_type == dbus::ErrorResponse::MESSAGE_METHOD_RETURN) {
dbus::MessageReader reader(response.get());
reader.PopBool(&status);
}
callback.Run(status);
return true;
}