| 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 base::Closure& closure) { |
| 215 on_disconnected_closure_ = closure; |
| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // We shouldn't exit on the disconnected signal. | 370 // We shouldn't exit on the disconnected signal. |
| 367 dbus_connection_set_exit_on_disconnect(connection_, false); | 371 dbus_connection_set_exit_on_disconnect(connection_, false); |
| 368 | 372 |
| 369 // Watch Disconnected signal. | 373 // Watch Disconnected signal. |
| 370 AddFilterFunction(Bus::OnConnectionDisconnectedFilter, this); | 374 AddFilterFunction(Bus::OnConnectionDisconnectedFilter, this); |
| 371 AddMatch(kDisconnectedMatchRule, error.get()); | 375 AddMatch(kDisconnectedMatchRule, error.get()); |
| 372 | 376 |
| 373 return true; | 377 return true; |
| 374 } | 378 } |
| 375 | 379 |
| 380 void Bus::CloseConnection() { |
| 381 // dbus_connection_close is blocking call. |
| 382 AssertOnDBusThread(); |
| 383 |
| 384 if (connection_type_ == PRIVATE) |
| 385 dbus_connection_close(connection_); |
| 386 } |
| 387 |
| 376 void Bus::ShutdownAndBlock() { | 388 void Bus::ShutdownAndBlock() { |
| 377 AssertOnDBusThread(); | 389 AssertOnDBusThread(); |
| 378 | 390 |
| 379 if (shutdown_completed_) | 391 if (shutdown_completed_) |
| 380 return; // Already shutdowned, just return. | 392 return; // Already shutdowned, just return. |
| 381 | 393 |
| 382 // Unregister the exported objects. | 394 // Unregister the exported objects. |
| 383 for (ExportedObjectTable::iterator iter = exported_object_table_.begin(); | 395 for (ExportedObjectTable::iterator iter = exported_object_table_.begin(); |
| 384 iter != exported_object_table_.end(); ++iter) { | 396 iter != exported_object_table_.end(); ++iter) { |
| 385 iter->second->Unregister(); | 397 iter->second->Unregister(); |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 this)); | 880 this)); |
| 869 } | 881 } |
| 870 | 882 |
| 871 void Bus::OnConnectionDisconnected(DBusConnection* connection) { | 883 void Bus::OnConnectionDisconnected(DBusConnection* connection) { |
| 872 AssertOnDBusThread(); | 884 AssertOnDBusThread(); |
| 873 | 885 |
| 874 if (!connection) | 886 if (!connection) |
| 875 return; | 887 return; |
| 876 DCHECK(!dbus_connection_get_is_connected(connection)); | 888 DCHECK(!dbus_connection_get_is_connected(connection)); |
| 877 | 889 |
| 890 if (!on_disconnected_closure_.is_null()) |
| 891 PostTaskToOriginThread(FROM_HERE, on_disconnected_closure_); |
| 892 |
| 878 if (shutdown_completed_) | 893 if (shutdown_completed_) |
| 879 return; // Do nothing if the shutdown is already completed. | 894 return; // Do nothing if the shutdown is already completed. |
| 880 | 895 |
| 881 // Unexpected disconnection, maybe the peer closes the connection. | 896 // Unexpected disconnection, maybe the peer closes the connection. |
| 882 DCHECK_EQ(connection, connection_); | 897 DCHECK_EQ(connection, connection_); |
| 883 ShutdownAndBlock(); | 898 ShutdownAndBlock(); |
| 884 } | 899 } |
| 885 | 900 |
| 886 dbus_bool_t Bus::OnAddWatchThunk(DBusWatch* raw_watch, void* data) { | 901 dbus_bool_t Bus::OnAddWatchThunk(DBusWatch* raw_watch, void* data) { |
| 887 Bus* self = static_cast<Bus*>(data); | 902 Bus* self = static_cast<Bus*>(data); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 kDisconnectedSignal)) { | 944 kDisconnectedSignal)) { |
| 930 Bus* self = static_cast<Bus*>(data); | 945 Bus* self = static_cast<Bus*>(data); |
| 931 self->AssertOnDBusThread(); | 946 self->AssertOnDBusThread(); |
| 932 self->OnConnectionDisconnected(connection); | 947 self->OnConnectionDisconnected(connection); |
| 933 return DBUS_HANDLER_RESULT_HANDLED; | 948 return DBUS_HANDLER_RESULT_HANDLED; |
| 934 } | 949 } |
| 935 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 950 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 936 } | 951 } |
| 937 | 952 |
| 938 } // namespace dbus | 953 } // namespace dbus |
| OLD | NEW |