blob: d137d05236e28809348023c8652e028d92ff2375 [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_daemon.h"
#include <unistd.h>
#include <base/at_exit.h>
#include <base/bind.h>
#include <base/command_line.h>
#include <base/logging.h>
#include <base/run_loop.h>
#include <base/strings/string_util.h>
#include <brillo/syslog_logging.h>
#include <dbus/bus.h>
#include "components/feedback/feedback_report.h"
#include "feedback/feedback_uploader_http.h"
namespace {
// string, set to "test" to use the sandbox server, otherwise a url
// to send the report to.
static const char kSwitchCustomServer[] = "url";
static const int kMaxPoolThreads = 1;
static const char kPoolName[] = "FeedbackWorkerPool";
static const base::FilePath::CharType kFeedbackReportPath[] =
static const char kFeedbackTestUrl[] =
static const char kFeedbackPostUrl[] =
} // namespace
namespace feedback {
Daemon::Daemon(const std::string& url)
: loop_(base::MessageLoop::TYPE_IO),
pool_(new base::SequencedWorkerPool(kMaxPoolThreads, kPoolName)),
uploader_(new FeedbackUploaderHttp(base::FilePath(kFeedbackReportPath),
pool_.get(), url)) {}
Daemon::~Daemon() {
void Daemon::Run() {
base::RunLoop loop;
dbus::Bus::Options options;
options.bus_type = dbus::Bus::SYSTEM;
scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
scoped_refptr<DBusFeedbackServiceImpl> impl =
new DBusFeedbackServiceImpl(uploader_.get());
// Load all reports currently on disk and queue them for sending.
base::Bind(&FeedbackService::QueueExistingReport, impl.get()));
CHECK(impl->Start(bus.get())) << "Failed to start feedback service";
} // namespace feedback
int main(int argc, char** argv) {
base::CommandLine::Init(argc, argv);
base::CommandLine *args = base::CommandLine::ForCurrentProcess();
// Some libchrome calls need this.
base::AtExitManager at_exit_manager;
brillo::InitLog(brillo::kLogToSyslog | brillo::kLogToStderr);
std::string url = args->GetSwitchValueASCII(kSwitchCustomServer);
if (url.empty()) {
url = kFeedbackPostUrl;
} else if (!"test")) {
url = kFeedbackTestUrl;
LOG(INFO) << "Using test feedback server";
} else {
LOG(INFO) << "Using feedback server at: " << url;
feedback::Daemon daemon(url);
return 0;