Commit b57c4658 authored by Chris Morin's avatar Chris Morin Committed by Commit Bot

arc: support receiving notification of arc stopped from upstart job

Add support for receiving the signal that the ARC++ container has
stopped from an Upstart Job script. After the change on the ChromeOS side
is made to send the stopped signal from the job script instead of from
session_manager, support for receiving the signal from session_manager
will be removed.

Bug: b:133248517
Change-Id: I932778fde1f14a0581c96f0efb4f28892e991b8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1673862
Commit-Queue: Chris Morin <cmtm@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672225}
parent c6445f87
...@@ -28,6 +28,9 @@ FakeUpstartClient::~FakeUpstartClient() { ...@@ -28,6 +28,9 @@ FakeUpstartClient::~FakeUpstartClient() {
g_instance = nullptr; g_instance = nullptr;
} }
void FakeUpstartClient::AddObserver(Observer* observer) {}
void FakeUpstartClient::RemoveObserver(Observer* observer) {}
// static // static
FakeUpstartClient* FakeUpstartClient::Get() { FakeUpstartClient* FakeUpstartClient::Get() {
return g_instance; return g_instance;
......
...@@ -17,6 +17,10 @@ class COMPONENT_EXPORT(UPSTART_CLIENT) FakeUpstartClient ...@@ -17,6 +17,10 @@ class COMPONENT_EXPORT(UPSTART_CLIENT) FakeUpstartClient
FakeUpstartClient(); FakeUpstartClient();
~FakeUpstartClient() override; ~FakeUpstartClient() override;
// Adds or removes an observer.
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
// Returns the fake global instance if initialized. May return null. // Returns the fake global instance if initialized. May return null.
static FakeUpstartClient* Get(); static FakeUpstartClient* Get();
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "dbus/bus.h" #include "dbus/bus.h"
#include "dbus/message.h" #include "dbus/message.h"
#include "dbus/object_proxy.h" #include "dbus/object_proxy.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos { namespace chromeos {
...@@ -35,10 +36,27 @@ UpstartClient* g_instance = nullptr; ...@@ -35,10 +36,27 @@ UpstartClient* g_instance = nullptr;
class UpstartClientImpl : public UpstartClient { class UpstartClientImpl : public UpstartClient {
public: public:
explicit UpstartClientImpl(dbus::Bus* bus) explicit UpstartClientImpl(dbus::Bus* bus)
: bus_(bus), weak_ptr_factory_(this) {} : bus_(bus), weak_ptr_factory_(this) {
dbus::ObjectProxy* arc_proxy = bus_->GetObjectProxy(
arc::kArcServiceName, dbus::ObjectPath(arc::kArcServicePath));
arc_proxy->ConnectToSignal(
arc::kArcInterfaceName, arc::kArcStopped,
base::Bind(&UpstartClientImpl::ArcStoppedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&UpstartClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
}
~UpstartClientImpl() override = default; ~UpstartClientImpl() override = default;
void AddObserver(Observer* observer) override {
observers_.AddObserver(observer);
}
void RemoveObserver(Observer* observer) override {
observers_.RemoveObserver(observer);
}
// UpstartClient overrides: // UpstartClient overrides:
void StartJob(const std::string& job, void StartJob(const std::string& job,
const std::vector<std::string>& upstart_env, const std::vector<std::string>& upstart_env,
...@@ -102,12 +120,26 @@ class UpstartClientImpl : public UpstartClient { ...@@ -102,12 +120,26 @@ class UpstartClientImpl : public UpstartClient {
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
// Called when the object is connected to the signal.
void SignalConnected(const std::string& interface_name,
const std::string& signal_name,
bool success) {
LOG_IF(ERROR, !success) << "Failed to connect to " << signal_name;
}
void ArcStoppedReceived(dbus::Signal* signal) {
for (auto& observer : observers_)
observer.ArcStopped();
}
void OnVoidMethod(VoidDBusMethodCallback callback, dbus::Response* response) { void OnVoidMethod(VoidDBusMethodCallback callback, dbus::Response* response) {
std::move(callback).Run(response); std::move(callback).Run(response);
} }
dbus::Bus* bus_ = nullptr; dbus::Bus* bus_ = nullptr;
base::ObserverList<Observer> observers_;
// Note: This should remain the last member so it'll be destroyed and // Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed. // invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<UpstartClientImpl> weak_ptr_factory_; base::WeakPtrFactory<UpstartClientImpl> weak_ptr_factory_;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/component_export.h" #include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h"
#include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/dbus_method_call_status.h"
namespace dbus { namespace dbus {
...@@ -24,6 +25,13 @@ namespace chromeos { ...@@ -24,6 +25,13 @@ namespace chromeos {
// initializes the DBusThreadManager instance. // initializes the DBusThreadManager instance.
class COMPONENT_EXPORT(UPSTART_CLIENT) UpstartClient { class COMPONENT_EXPORT(UPSTART_CLIENT) UpstartClient {
public: public:
class Observer : public base::CheckedObserver {
public:
~Observer() override {}
// Called when the ARC is stopped after it had already started.
virtual void ArcStopped() {}
};
virtual ~UpstartClient(); virtual ~UpstartClient();
// Creates and initializes the global instance. |bus| must not be null. // Creates and initializes the global instance. |bus| must not be null.
...@@ -38,6 +46,10 @@ class COMPONENT_EXPORT(UPSTART_CLIENT) UpstartClient { ...@@ -38,6 +46,10 @@ class COMPONENT_EXPORT(UPSTART_CLIENT) UpstartClient {
// Returns the global instance if initialized. May return null. // Returns the global instance if initialized. May return null.
static UpstartClient* Get(); static UpstartClient* Get();
// Adds or removes an observer.
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
// Starts an Upstart job. // Starts an Upstart job.
// |job|: Name of Upstart job. // |job|: Name of Upstart job.
// |upstart_env|: List of upstart environment variables to be passed to the // |upstart_env|: List of upstart environment variables to be passed to the
......
...@@ -12,21 +12,27 @@ ...@@ -12,21 +12,27 @@
#include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/dbus_method_call_status.h"
#include "chromeos/dbus/login_manager/arc.pb.h" #include "chromeos/dbus/login_manager/arc.pb.h"
#include "chromeos/dbus/session_manager/session_manager_client.h" #include "chromeos/dbus/session_manager/session_manager_client.h"
#include "chromeos/dbus/upstart/upstart_client.h"
namespace arc { namespace arc {
class ArcContainerClientAdapter class ArcContainerClientAdapter
: public ArcClientAdapter, : public ArcClientAdapter,
public chromeos::SessionManagerClient::Observer { public chromeos::SessionManagerClient::Observer,
public chromeos::UpstartClient::Observer {
public: public:
ArcContainerClientAdapter() { ArcContainerClientAdapter() {
if (chromeos::SessionManagerClient::Get()) if (chromeos::SessionManagerClient::Get())
chromeos::SessionManagerClient::Get()->AddObserver(this); chromeos::SessionManagerClient::Get()->AddObserver(this);
if (chromeos::UpstartClient::Get())
chromeos::UpstartClient::Get()->AddObserver(this);
} }
~ArcContainerClientAdapter() override { ~ArcContainerClientAdapter() override {
if (chromeos::SessionManagerClient::Get()) if (chromeos::SessionManagerClient::Get())
chromeos::SessionManagerClient::Get()->RemoveObserver(this); chromeos::SessionManagerClient::Get()->RemoveObserver(this);
if (chromeos::UpstartClient::Get())
chromeos::UpstartClient::Get()->RemoveObserver(this);
} }
// ArcClientAdapter overrides: // ArcClientAdapter overrides:
...@@ -57,6 +63,12 @@ class ArcContainerClientAdapter ...@@ -57,6 +63,12 @@ class ArcContainerClientAdapter
observer.ArcInstanceStopped(); observer.ArcInstanceStopped();
} }
// chromeos::UpstartClient::Observer overrides:
void ArcStopped() override {
for (auto& observer : observer_list_)
observer.ArcInstanceStopped();
}
private: private:
DISALLOW_COPY_AND_ASSIGN(ArcContainerClientAdapter); DISALLOW_COPY_AND_ASSIGN(ArcContainerClientAdapter);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment