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

Side by Side Diff: dbus/bus.h

Issue 12255043: DBus: Use TaskRunners instead of MessageLoopProxies. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase 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
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 #ifndef DBUS_BUS_H_ 5 #ifndef DBUS_BUS_H_
6 #define DBUS_BUS_H_ 6 #define DBUS_BUS_H_
7 7
8 #include <dbus/dbus.h>
9
8 #include <map> 10 #include <map>
9 #include <set> 11 #include <set>
10 #include <string> 12 #include <string>
11 #include <utility> 13 #include <utility>
12 #include <dbus/dbus.h>
13 14
14 #include "base/callback.h" 15 #include "base/callback.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
17 #include "base/threading/platform_thread.h" 18 #include "base/threading/platform_thread.h"
18 #include "base/tracked_objects.h"
19 #include "dbus/dbus_export.h" 19 #include "dbus/dbus_export.h"
20 #include "dbus/object_path.h" 20 #include "dbus/object_path.h"
21 21
22 class MessageLoop; 22 namespace base {
23 class SequencedTaskRunner;
24 class SingleThreadTaskRunner;
25 class Thread;
26 }
23 27
24 namespace base { 28 namespace tracked_objects {
25 class Thread; 29 class Location;
26 class MessageLoopProxy;
27 } 30 }
28 31
29 namespace dbus { 32 namespace dbus {
30 33
31 class ExportedObject; 34 class ExportedObject;
32 class ObjectProxy; 35 class ObjectProxy;
33 36
34 // Bus is used to establish a connection with D-Bus, create object 37 // Bus is used to establish a connection with D-Bus, create object
35 // proxies, and export objects. 38 // proxies, and export objects.
36 // 39 //
37 // For asynchronous operations such as an asynchronous method call, the 40 // For asynchronous operations such as an asynchronous method call, the
38 // bus object will use a message loop to monitor the underlying file 41 // bus object will use a task runner to monitor the underlying file
39 // descriptor used for D-Bus communication. By default, the bus will use 42 // descriptor used for D-Bus communication. By default, the bus will use
40 // the current thread's MessageLoopForIO. If |dbus_thread_message_loop_proxy| 43 // the current thread's task runner. If |dbus_task_runner| option is
41 // option is specified, the bus will use that message loop instead. 44 // specified, the bus will use that task runner instead.
42 // 45 //
43 // THREADING 46 // THREADING
44 // 47 //
45 // In the D-Bus library, we use the two threads: 48 // In the D-Bus library, we use the two threads:
46 // 49 //
47 // - The origin thread: the thread that created the Bus object. 50 // - The origin thread: the thread that created the Bus object.
48 // - The D-Bus thread: the thread servicing |dbus_thread_message_loop_proxy|. 51 // - The D-Bus thread: the thread servicing |dbus_task_runner|.
49 // 52 //
50 // The origin thread is usually Chrome's UI thread. The D-Bus thread is 53 // The origin thread is usually Chrome's UI thread. The D-Bus thread is
51 // usually a dedicated thread for the D-Bus library. 54 // usually a dedicated thread for the D-Bus library.
52 // 55 //
53 // BLOCKING CALLS 56 // BLOCKING CALLS
54 // 57 //
55 // Functions that issue blocking calls are marked "BLOCKING CALL" and 58 // Functions that issue blocking calls are marked "BLOCKING CALL" and
56 // these functions should be called in the D-Bus thread (if 59 // these functions should be called in the D-Bus thread (if
57 // supplied). AssertOnDBusThread() is placed in these functions. 60 // supplied). AssertOnDBusThread() is placed in these functions.
58 // 61 //
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 SHARED, 160 SHARED,
158 }; 161 };
159 162
160 // Options used to create a Bus object. 163 // Options used to create a Bus object.
161 struct CHROME_DBUS_EXPORT Options { 164 struct CHROME_DBUS_EXPORT Options {
162 Options(); 165 Options();
163 ~Options(); 166 ~Options();
164 167
165 BusType bus_type; // SESSION by default. 168 BusType bus_type; // SESSION by default.
166 ConnectionType connection_type; // PRIVATE by default. 169 ConnectionType connection_type; // PRIVATE by default.
167 // If dbus_thread_message_loop_proxy is set, the bus object will use that 170 // If dbus_task_runner is set, the bus object will use that
168 // message loop to process asynchronous operations. 171 // task runner to process asynchronous operations.
169 // 172 //
170 // The thread servicing the message loop proxy should meet the following 173 // The thread servicing the task runner should meet the following
171 // requirements: 174 // requirements:
172 // 1) Already running. 175 // 1) Already running.
173 // 2) Has a MessageLoopForIO. 176 // 2) Has a MessageLoopForIO.
174 scoped_refptr<base::MessageLoopProxy> dbus_thread_message_loop_proxy; 177 scoped_refptr<base::SequencedTaskRunner> dbus_task_runner;
175 178
176 // Specifies the server addresses to be connected. If you want to 179 // Specifies the server addresses to be connected. If you want to
177 // communicate with non dbus-daemon such as ibus-daemon, set |bus_type| to 180 // communicate with non dbus-daemon such as ibus-daemon, set |bus_type| to
178 // CUSTOM_ADDRESS, and |address| to the D-Bus server address you want to 181 // CUSTOM_ADDRESS, and |address| to the D-Bus server address you want to
179 // connect to. The format of this address value is the dbus address style 182 // connect to. The format of this address value is the dbus address style
180 // which is described in 183 // which is described in
181 // http://dbus.freedesktop.org/doc/dbus-specification.html#addresses 184 // http://dbus.freedesktop.org/doc/dbus-specification.html#addresses
182 // 185 //
183 // EXAMPLE USAGE: 186 // EXAMPLE USAGE:
184 // dbus::Bus::Options options; 187 // dbus::Bus::Options options;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 virtual bool TryRegisterObjectPath(const ObjectPath& object_path, 459 virtual bool TryRegisterObjectPath(const ObjectPath& object_path,
457 const DBusObjectPathVTable* vtable, 460 const DBusObjectPathVTable* vtable,
458 void* user_data, 461 void* user_data,
459 DBusError* error); 462 DBusError* error);
460 463
461 // Unregister the object path. 464 // Unregister the object path.
462 // 465 //
463 // BLOCKING CALL. 466 // BLOCKING CALL.
464 virtual void UnregisterObjectPath(const ObjectPath& object_path); 467 virtual void UnregisterObjectPath(const ObjectPath& object_path);
465 468
466 // Posts the task to the message loop of the thread that created the bus. 469 // Posts the task to the task runner of the thread that created the bus.
467 virtual void PostTaskToOriginThread( 470 virtual void PostTaskToOriginThread(
468 const tracked_objects::Location& from_here, 471 const tracked_objects::Location& from_here,
469 const base::Closure& task); 472 const base::Closure& task);
470 473
471 // Posts the task to the message loop of the D-Bus thread. If D-Bus 474 // Posts the task to the task runner of the D-Bus thread. If D-Bus
472 // thread is not supplied, the message loop of the origin thread will be 475 // thread is not supplied, the task runner of the origin thread will be
473 // used. 476 // used.
474 virtual void PostTaskToDBusThread( 477 virtual void PostTaskToDBusThread(
475 const tracked_objects::Location& from_here, 478 const tracked_objects::Location& from_here,
476 const base::Closure& task); 479 const base::Closure& task);
477 480
478 // Posts the delayed task to the message loop of the D-Bus thread. If 481 // Posts the delayed task to the task runner of the D-Bus thread. If
479 // D-Bus thread is not supplied, the message loop of the origin thread 482 // D-Bus thread is not supplied, the task runner of the origin thread
480 // will be used. 483 // will be used.
481 virtual void PostDelayedTaskToDBusThread( 484 virtual void PostDelayedTaskToDBusThread(
482 const tracked_objects::Location& from_here, 485 const tracked_objects::Location& from_here,
483 const base::Closure& task, 486 const base::Closure& task,
484 base::TimeDelta delay); 487 base::TimeDelta delay);
485 488
486 // Returns true if the bus has the D-Bus thread. 489 // Returns true if the bus has the D-Bus thread.
487 virtual bool HasDBusThread(); 490 virtual bool HasDBusThread();
488 491
489 // Check whether the current thread is on the origin thread (the thread 492 // Check whether the current thread is on the origin thread (the thread
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 static void OnToggleWatchThunk(DBusWatch* raw_watch, void* data); 562 static void OnToggleWatchThunk(DBusWatch* raw_watch, void* data);
560 static dbus_bool_t OnAddTimeoutThunk(DBusTimeout* raw_timeout, void* data); 563 static dbus_bool_t OnAddTimeoutThunk(DBusTimeout* raw_timeout, void* data);
561 static void OnRemoveTimeoutThunk(DBusTimeout* raw_timeout, void* data); 564 static void OnRemoveTimeoutThunk(DBusTimeout* raw_timeout, void* data);
562 static void OnToggleTimeoutThunk(DBusTimeout* raw_timeout, void* data); 565 static void OnToggleTimeoutThunk(DBusTimeout* raw_timeout, void* data);
563 static void OnDispatchStatusChangedThunk(DBusConnection* connection, 566 static void OnDispatchStatusChangedThunk(DBusConnection* connection,
564 DBusDispatchStatus status, 567 DBusDispatchStatus status,
565 void* data); 568 void* data);
566 569
567 // Calls OnConnectionDisconnected if the Diconnected signal is received. 570 // Calls OnConnectionDisconnected if the Diconnected signal is received.
568 static DBusHandlerResult OnConnectionDisconnectedFilter( 571 static DBusHandlerResult OnConnectionDisconnectedFilter(
569 DBusConnection *connection, 572 DBusConnection* connection,
570 DBusMessage *message, 573 DBusMessage* message,
571 void *user_data); 574 void* user_data);
572 575
573 const BusType bus_type_; 576 const BusType bus_type_;
574 const ConnectionType connection_type_; 577 const ConnectionType connection_type_;
575 scoped_refptr<base::MessageLoopProxy> dbus_thread_message_loop_proxy_; 578 scoped_refptr<base::SequencedTaskRunner> dbus_task_runner_;
576 base::WaitableEvent on_shutdown_; 579 base::WaitableEvent on_shutdown_;
577 DBusConnection* connection_; 580 DBusConnection* connection_;
578 581
579 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; 582 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_;
580 base::PlatformThreadId origin_thread_id_; 583 base::PlatformThreadId origin_thread_id_;
581 584
582 std::set<std::string> owned_service_names_; 585 std::set<std::string> owned_service_names_;
583 // The following sets are used to check if rules/object_paths/filters 586 // The following sets are used to check if rules/object_paths/filters
584 // are properly cleaned up before destruction of the bus object. 587 // are properly cleaned up before destruction of the bus object.
585 // Since it's not an error to add the same match rule twice, the repeated 588 // Since it's not an error to add the same match rule twice, the repeated
586 // match rules are counted in a map. 589 // match rules are counted in a map.
587 std::map<std::string, int> match_rules_added_; 590 std::map<std::string, int> match_rules_added_;
588 std::set<ObjectPath> registered_object_paths_; 591 std::set<ObjectPath> registered_object_paths_;
589 std::set<std::pair<DBusHandleMessageFunction, void*> > 592 std::set<std::pair<DBusHandleMessageFunction, void*> >
(...skipping 25 matching lines...) Expand all
615 618
616 std::string address_; 619 std::string address_;
617 base::Closure on_disconnected_closure_; 620 base::Closure on_disconnected_closure_;
618 621
619 DISALLOW_COPY_AND_ASSIGN(Bus); 622 DISALLOW_COPY_AND_ASSIGN(Bus);
620 }; 623 };
621 624
622 } // namespace dbus 625 } // namespace dbus
623 626
624 #endif // DBUS_BUS_H_ 627 #endif // DBUS_BUS_H_
OLDNEW
« no previous file with comments | « chromeos/dbus/dbus_thread_manager.cc ('k') | dbus/bus.cc » ('j') | dbus/mock_bus.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698