blob: 7e4c44ed1da634cfb78c503e252d0bcf3f7d1e48 [file] [log] [blame]
// Copyright (c) 2012 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 <base/cancelable_callback.h>
#include <base/macros.h>
#include <base/memory/ref_counted.h>
#include <base/memory/weak_ptr.h>
#include <base/time/time.h>
#include "login_manager/liveness_checker.h"
namespace dbus {
class ObjectProxy;
class Response;
} // namespace dbus
namespace login_manager {
class ProcessManagerServiceInterface;
// An implementation of LivenessChecker that pings the browser over DBus,
// and expects the response to a ping to come in reliably before the next
// ping is sent. If not, it may ask |manager| to abort the browser process.
// Actual aborting behavior is controlled by the enable_aborting flag.
class LivenessCheckerImpl : public LivenessChecker {
LivenessCheckerImpl(ProcessManagerServiceInterface* manager,
dbus::ObjectProxy* chrome_dbus_proxy,
bool enable_aborting,
base::TimeDelta interval);
virtual ~LivenessCheckerImpl();
// Implementation of LivenessChecker.
void Start();
void Stop();
bool IsRunning();
// If a liveness check is outstanding, kills the browser and clears liveness
// tracking state. This instance will be stopped at that point in time.
// If no ping is outstanding, sends a liveness check to the browser over DBus,
// then reschedules itself after interval.
void CheckAndSendLivenessPing(base::TimeDelta interval);
void set_manager(ProcessManagerServiceInterface* manager) {
manager_ = manager;
// Handle async response to liveness ping by setting last_ping_acked_,
// iff there is a successful response.
void HandleAck(dbus::Response* response);
ProcessManagerServiceInterface* manager_; // Owned by the caller.
dbus::ObjectProxy* chrome_dbus_proxy_; // Owned by the caller.
const bool enable_aborting_;
const base::TimeDelta interval_;
bool last_ping_acked_;
base::CancelableClosure liveness_check_;
base::WeakPtrFactory<LivenessCheckerImpl> weak_ptr_factory_;
} // namespace login_manager