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[] =
FILE_PATH_LITERAL("/run/");
static const char kFeedbackTestUrl[] =
"http://sandbox.google.com/tools/feedback/chrome/__submit";
static const char kFeedbackPostUrl[] =
"https://www.google.com/tools/feedback/chrome/__submit";
} // 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() {
pool_->Shutdown();
}
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.
FeedbackReport::LoadReportsAndQueue(
uploader_->GetFeedbackReportsPath(),
base::Bind(&FeedbackService::QueueExistingReport, impl.get()));
CHECK(impl->Start(bus.get())) << "Failed to start feedback service";
loop.Run();
}
} // 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 (!url.compare("test")) {
url = kFeedbackTestUrl;
LOG(INFO) << "Using test feedback server";
} else {
LOG(INFO) << "Using feedback server at: " << url;
}
feedback::Daemon daemon(url);
daemon.Run();
return 0;
}