OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "dbus/bus.h" | 5 #include "dbus/bus.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 DCHECK(match_rules_added_.empty()); | 204 DCHECK(match_rules_added_.empty()); |
205 DCHECK(filter_functions_added_.empty()); | 205 DCHECK(filter_functions_added_.empty()); |
206 DCHECK(registered_object_paths_.empty()); | 206 DCHECK(registered_object_paths_.empty()); |
207 DCHECK_EQ(0, num_pending_watches_); | 207 DCHECK_EQ(0, num_pending_watches_); |
208 // TODO(satorux): This check fails occasionally in browser_tests for tests | 208 // TODO(satorux): This check fails occasionally in browser_tests for tests |
209 // that run very quickly. Perhaps something does not have time to clean up. | 209 // that run very quickly. Perhaps something does not have time to clean up. |
210 // Despite the check failing, the tests seem to run fine. crosbug.com/23416 | 210 // Despite the check failing, the tests seem to run fine. crosbug.com/23416 |
211 // DCHECK_EQ(0, num_pending_timeouts_); | 211 // DCHECK_EQ(0, num_pending_timeouts_); |
212 } | 212 } |
213 | 213 |
| 214 void Bus::SetDisconnectedCallback(const OnDisconnectedCallback& callback) { |
| 215 on_disconnected_callback_ = callback; |
| 216 } |
| 217 |
214 ObjectProxy* Bus::GetObjectProxy(const std::string& service_name, | 218 ObjectProxy* Bus::GetObjectProxy(const std::string& service_name, |
215 const ObjectPath& object_path) { | 219 const ObjectPath& object_path) { |
216 return GetObjectProxyWithOptions(service_name, object_path, | 220 return GetObjectProxyWithOptions(service_name, object_path, |
217 ObjectProxy::DEFAULT_OPTIONS); | 221 ObjectProxy::DEFAULT_OPTIONS); |
218 } | 222 } |
219 | 223 |
220 ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, | 224 ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, |
221 const dbus::ObjectPath& object_path, | 225 const dbus::ObjectPath& object_path, |
222 int options) { | 226 int options) { |
223 AssertOnOriginThread(); | 227 AssertOnOriginThread(); |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 this)); | 872 this)); |
869 } | 873 } |
870 | 874 |
871 void Bus::OnConnectionDisconnected(DBusConnection* connection) { | 875 void Bus::OnConnectionDisconnected(DBusConnection* connection) { |
872 AssertOnDBusThread(); | 876 AssertOnDBusThread(); |
873 | 877 |
874 if (!connection) | 878 if (!connection) |
875 return; | 879 return; |
876 DCHECK(!dbus_connection_get_is_connected(connection)); | 880 DCHECK(!dbus_connection_get_is_connected(connection)); |
877 | 881 |
| 882 if (!on_disconnected_callback_.is_null()) |
| 883 PostTaskToOriginThread(FROM_HERE, on_disconnected_callback_); |
| 884 |
878 if (shutdown_completed_) | 885 if (shutdown_completed_) |
879 return; // Do nothing if the shutdown is already completed. | 886 return; // Do nothing if the shutdown is already completed. |
880 | 887 |
881 // Unexpected disconnection, maybe the peer closes the connection. | 888 // Unexpected disconnection, maybe the peer closes the connection. |
882 DCHECK_EQ(connection, connection_); | 889 DCHECK_EQ(connection, connection_); |
883 ShutdownAndBlock(); | 890 ShutdownAndBlock(); |
884 } | 891 } |
885 | 892 |
886 dbus_bool_t Bus::OnAddWatchThunk(DBusWatch* raw_watch, void* data) { | 893 dbus_bool_t Bus::OnAddWatchThunk(DBusWatch* raw_watch, void* data) { |
887 Bus* self = static_cast<Bus*>(data); | 894 Bus* self = static_cast<Bus*>(data); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 kDisconnectedSignal)) { | 936 kDisconnectedSignal)) { |
930 Bus* self = static_cast<Bus*>(data); | 937 Bus* self = static_cast<Bus*>(data); |
931 self->AssertOnDBusThread(); | 938 self->AssertOnDBusThread(); |
932 self->OnConnectionDisconnected(connection); | 939 self->OnConnectionDisconnected(connection); |
933 return DBUS_HANDLER_RESULT_HANDLED; | 940 return DBUS_HANDLER_RESULT_HANDLED; |
934 } | 941 } |
935 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 942 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
936 } | 943 } |
937 | 944 |
938 } // namespace dbus | 945 } // namespace dbus |
OLD | NEW |