Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: dbus/bus.cc

Issue 12224139: Supporting callback for Disconnected signal. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing comments Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dbus/bus.h ('k') | dbus/end_to_end_async_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 : bus_type_(options.bus_type), 182 : bus_type_(options.bus_type),
183 connection_type_(options.connection_type), 183 connection_type_(options.connection_type),
184 dbus_thread_message_loop_proxy_(options.dbus_thread_message_loop_proxy), 184 dbus_thread_message_loop_proxy_(options.dbus_thread_message_loop_proxy),
185 on_shutdown_(false /* manual_reset */, false /* initially_signaled */), 185 on_shutdown_(false /* manual_reset */, false /* initially_signaled */),
186 connection_(NULL), 186 connection_(NULL),
187 origin_thread_id_(base::PlatformThread::CurrentId()), 187 origin_thread_id_(base::PlatformThread::CurrentId()),
188 async_operations_set_up_(false), 188 async_operations_set_up_(false),
189 shutdown_completed_(false), 189 shutdown_completed_(false),
190 num_pending_watches_(0), 190 num_pending_watches_(0),
191 num_pending_timeouts_(0), 191 num_pending_timeouts_(0),
192 address_(options.address) { 192 address_(options.address),
193 on_disconnected_closure_(options.disconnected_callback) {
193 // This is safe to call multiple times. 194 // This is safe to call multiple times.
194 dbus_threads_init_default(); 195 dbus_threads_init_default();
195 // The origin message loop is unnecessary if the client uses synchronous 196 // The origin message loop is unnecessary if the client uses synchronous
196 // functions only. 197 // functions only.
197 if (MessageLoop::current()) 198 if (MessageLoop::current())
198 origin_message_loop_proxy_ = MessageLoop::current()->message_loop_proxy(); 199 origin_message_loop_proxy_ = MessageLoop::current()->message_loop_proxy();
199 } 200 }
200 201
201 Bus::~Bus() { 202 Bus::~Bus() {
202 DCHECK(!connection_); 203 DCHECK(!connection_);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // We shouldn't exit on the disconnected signal. 367 // We shouldn't exit on the disconnected signal.
367 dbus_connection_set_exit_on_disconnect(connection_, false); 368 dbus_connection_set_exit_on_disconnect(connection_, false);
368 369
369 // Watch Disconnected signal. 370 // Watch Disconnected signal.
370 AddFilterFunction(Bus::OnConnectionDisconnectedFilter, this); 371 AddFilterFunction(Bus::OnConnectionDisconnectedFilter, this);
371 AddMatch(kDisconnectedMatchRule, error.get()); 372 AddMatch(kDisconnectedMatchRule, error.get());
372 373
373 return true; 374 return true;
374 } 375 }
375 376
377 void Bus::ClosePrivateConnection() {
378 // dbus_connection_close is blocking call.
379 AssertOnDBusThread();
380 DCHECK_EQ(PRIVATE, connection_type_)
381 << "non-private connection should not be closed";
382 dbus_connection_close(connection_);
383 }
384
376 void Bus::ShutdownAndBlock() { 385 void Bus::ShutdownAndBlock() {
377 AssertOnDBusThread(); 386 AssertOnDBusThread();
378 387
379 if (shutdown_completed_) 388 if (shutdown_completed_)
380 return; // Already shutdowned, just return. 389 return; // Already shutdowned, just return.
381 390
382 // Unregister the exported objects. 391 // Unregister the exported objects.
383 for (ExportedObjectTable::iterator iter = exported_object_table_.begin(); 392 for (ExportedObjectTable::iterator iter = exported_object_table_.begin();
384 iter != exported_object_table_.end(); ++iter) { 393 iter != exported_object_table_.end(); ++iter) {
385 iter->second->Unregister(); 394 iter->second->Unregister();
(...skipping 25 matching lines...) Expand all
411 exported_object_table_.clear(); 420 exported_object_table_.clear();
412 421
413 // Private connection should be closed. 422 // Private connection should be closed.
414 if (connection_) { 423 if (connection_) {
415 // Remove Disconnected watcher. 424 // Remove Disconnected watcher.
416 ScopedDBusError error; 425 ScopedDBusError error;
417 RemoveFilterFunction(Bus::OnConnectionDisconnectedFilter, this); 426 RemoveFilterFunction(Bus::OnConnectionDisconnectedFilter, this);
418 RemoveMatch(kDisconnectedMatchRule, error.get()); 427 RemoveMatch(kDisconnectedMatchRule, error.get());
419 428
420 if (connection_type_ == PRIVATE) 429 if (connection_type_ == PRIVATE)
421 dbus_connection_close(connection_); 430 ClosePrivateConnection();
422 // dbus_connection_close() won't unref. 431 // dbus_connection_close() won't unref.
423 dbus_connection_unref(connection_); 432 dbus_connection_unref(connection_);
424 } 433 }
425 434
426 connection_ = NULL; 435 connection_ = NULL;
427 shutdown_completed_ = true; 436 shutdown_completed_ = true;
428 } 437 }
429 438
430 void Bus::ShutdownOnDBusThreadAndBlock() { 439 void Bus::ShutdownOnDBusThreadAndBlock() {
431 AssertOnOriginThread(); 440 AssertOnOriginThread();
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 // prohibited by the D-Bus library. Hence, we post a task here instead. 873 // prohibited by the D-Bus library. Hence, we post a task here instead.
865 // See comments for dbus_connection_set_dispatch_status_function(). 874 // See comments for dbus_connection_set_dispatch_status_function().
866 PostTaskToDBusThread(FROM_HERE, 875 PostTaskToDBusThread(FROM_HERE,
867 base::Bind(&Bus::ProcessAllIncomingDataIfAny, 876 base::Bind(&Bus::ProcessAllIncomingDataIfAny,
868 this)); 877 this));
869 } 878 }
870 879
871 void Bus::OnConnectionDisconnected(DBusConnection* connection) { 880 void Bus::OnConnectionDisconnected(DBusConnection* connection) {
872 AssertOnDBusThread(); 881 AssertOnDBusThread();
873 882
883 if (!on_disconnected_closure_.is_null())
884 PostTaskToOriginThread(FROM_HERE, on_disconnected_closure_);
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
878 ShutdownAndBlock(); 890 ShutdownAndBlock();
879 } 891 }
880 892
881 dbus_bool_t Bus::OnAddWatchThunk(DBusWatch* raw_watch, void* data) { 893 dbus_bool_t Bus::OnAddWatchThunk(DBusWatch* raw_watch, void* data) {
882 Bus* self = static_cast<Bus*>(data); 894 Bus* self = static_cast<Bus*>(data);
883 return self->OnAddWatch(raw_watch); 895 return self->OnAddWatch(raw_watch);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 kDisconnectedSignal)) { 936 kDisconnectedSignal)) {
925 Bus* self = static_cast<Bus*>(data); 937 Bus* self = static_cast<Bus*>(data);
926 self->AssertOnDBusThread(); 938 self->AssertOnDBusThread();
927 self->OnConnectionDisconnected(connection); 939 self->OnConnectionDisconnected(connection);
928 return DBUS_HANDLER_RESULT_HANDLED; 940 return DBUS_HANDLER_RESULT_HANDLED;
929 } 941 }
930 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 942 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
931 } 943 }
932 944
933 } // namespace dbus 945 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/bus.h ('k') | dbus/end_to_end_async_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698