Skip to content

Commit

Permalink
Exit chrome when dbus-daemon crashes
Browse files Browse the repository at this point in the history
BUG=432980

Review URL: https://codereview.chromium.org/746373003

Cr-Commit-Position: refs/heads/master@{#307419}
  • Loading branch information
hashimoto authored and Commit bot committed Dec 9, 2014
1 parent 2345c1f commit e8aa0b4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 51 deletions.
24 changes: 4 additions & 20 deletions dbus/bus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ Bus::Bus(const Options& options)
shutdown_completed_(false),
num_pending_watches_(0),
num_pending_timeouts_(0),
address_(options.address),
on_disconnected_closure_(options.disconnected_callback) {
address_(options.address) {
// This is safe to call multiple times.
dbus_threads_init_default();
// The origin message loop is unnecessary if the client uses synchronous
Expand Down Expand Up @@ -824,8 +823,7 @@ void Bus::ProcessAllIncomingDataIfAny() {
return;

// It is safe and necessary to call dbus_connection_get_dispatch_status even
// if the connection is lost. Otherwise we will miss "Disconnected" signal.
// (crbug.com/174431)
// if the connection is lost.
if (dbus_connection_get_dispatch_status(connection_) ==
DBUS_DISPATCH_DATA_REMAINS) {
while (dbus_connection_dispatch(connection_) ==
Expand Down Expand Up @@ -1104,19 +1102,6 @@ void Bus::OnDispatchStatusChanged(DBusConnection* connection,
this));
}

void Bus::OnConnectionDisconnected(DBusConnection* connection) {
AssertOnDBusThread();

if (!on_disconnected_closure_.is_null())
GetOriginTaskRunner()->PostTask(FROM_HERE, on_disconnected_closure_);

if (!connection)
return;
DCHECK(!dbus_connection_get_is_connected(connection));

ShutdownAndBlock();
}

void Bus::OnServiceOwnerChanged(DBusMessage* message) {
DCHECK(message);
AssertOnDBusThread();
Expand Down Expand Up @@ -1207,9 +1192,8 @@ DBusHandlerResult Bus::OnConnectionDisconnectedFilter(
if (dbus_message_is_signal(message,
DBUS_INTERFACE_LOCAL,
kDisconnectedSignal)) {
Bus* self = static_cast<Bus*>(data);
self->OnConnectionDisconnected(connection);
return DBUS_HANDLER_RESULT_HANDLED;
// Abort when the connection is lost.
LOG(FATAL) << "D-Bus connection was disconnected. Aborting.";
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
Expand Down
10 changes: 0 additions & 10 deletions dbus/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,6 @@ class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> {
// // Do something.
//
std::string address;

// If the connection with dbus-daemon is closed, |disconnected_callback|
// will be called on the origin thread. This is also called when the
// disonnection by ShutdownAndBlock. |disconnected_callback| can be null
// callback
base::Closure disconnected_callback;
};

// Creates a Bus object. The actual connection will be established when
Expand Down Expand Up @@ -670,9 +664,6 @@ class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> {
void OnDispatchStatusChanged(DBusConnection* connection,
DBusDispatchStatus status);

// Called when the connection is diconnected.
void OnConnectionDisconnected(DBusConnection* connection);

// Called when a service owner change occurs.
void OnServiceOwnerChanged(DBusMessage* message);

Expand Down Expand Up @@ -760,7 +751,6 @@ class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> {
int num_pending_timeouts_;

std::string address_;
base::Closure on_disconnected_closure_;

DISALLOW_COPY_AND_ASSIGN(Bus);
};
Expand Down
21 changes: 0 additions & 21 deletions dbus/end_to_end_async_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const int kHugePayloadSize = 64 << 20; // 64 MB
// ExportedObject.
class EndToEndAsyncTest : public testing::Test {
public:
EndToEndAsyncTest() : on_disconnected_call_count_(0) {}

virtual void SetUp() {
// Make the main thread not to allow IO.
base::ThreadRestrictions::SetIOAllowed(false);
Expand All @@ -60,8 +58,6 @@ class EndToEndAsyncTest : public testing::Test {
bus_options.bus_type = Bus::SESSION;
bus_options.connection_type = Bus::PRIVATE;
bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy();
bus_options.disconnected_callback =
base::Bind(&EndToEndAsyncTest::OnDisconnected, base::Unretained(this));
bus_ = new Bus(bus_options);
object_proxy_ = bus_->GetObjectProxy(
"org.chromium.TestService",
Expand Down Expand Up @@ -248,12 +244,6 @@ class EndToEndAsyncTest : public testing::Test {
run_loop_->Quit();
}

// Called when the connection with dbus-daemon is disconnected.
void OnDisconnected() {
run_loop_->Quit();
++on_disconnected_call_count_;
}

// Wait for the hey signal to be received.
void WaitForTestSignal() {
// OnTestSignal() will quit the message loop.
Expand All @@ -274,7 +264,6 @@ class EndToEndAsyncTest : public testing::Test {
std::string test_signal_string_;
// Text message from "Test" signal delivered to root.
std::string root_test_signal_string_;
int on_disconnected_call_count_;
};

TEST_F(EndToEndAsyncTest, Echo) {
Expand Down Expand Up @@ -588,16 +577,6 @@ TEST_F(EndToEndAsyncTest, TestHugeSignal) {
ASSERT_EQ(kHugeMessage, test_signal_string_);
}

TEST_F(EndToEndAsyncTest, DisconnectedSignal) {
bus_->GetDBusTaskRunner()->PostTask(FROM_HERE,
base::Bind(&Bus::ClosePrivateConnection,
base::Unretained(bus_.get())));
// OnDisconnected callback quits message loop.
run_loop_.reset(new base::RunLoop);
run_loop_->Run();
EXPECT_EQ(1, on_disconnected_call_count_);
}

class SignalMultipleHandlerTest : public EndToEndAsyncTest {
public:
SignalMultipleHandlerTest() {
Expand Down

0 comments on commit e8aa0b4

Please sign in to comment.