blob: cbdf70d2fccde48265c844edf1542b383ab4936e [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 <chromeos/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("/var/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_, url)) {}
Daemon::~Daemon() {
pool_->Shutdown();
}
void Daemon::Run() {
base::RunLoop loop;
dbus::Bus::Options options;
options.bus_type = dbus::Bus::SYSTEM;
options.disconnected_callback = loop.QuitClosure();
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)) << "Failed to start feedback service";
loop.Run();
}
} // namespace feedback
int main(int argc, char** argv) {
CommandLine::Init(argc, argv);
CommandLine *args = CommandLine::ForCurrentProcess();
// Some libchrome calls need this.
base::AtExitManager at_exit_manager;
chromeos::InitLog(chromeos::kLogToSyslog | chromeos::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;
}