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

Side by Side Diff: dbus/bus.h

Issue 14568005: Add a method to check if a D-Bus service has an owner. Use it for mtpd. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros compile Created 7 years, 7 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 | « no previous file | dbus/bus.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 #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> 8 #include <dbus/dbus.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // PRIVATE gives you a private connection, that won't be shared with 154 // PRIVATE gives you a private connection, that won't be shared with
155 // other Bus objects. 155 // other Bus objects.
156 // 156 //
157 // SHARED gives you a connection shared among other Bus objects, which 157 // SHARED gives you a connection shared among other Bus objects, which
158 // is unsafe if the connection is shared with multiple threads. 158 // is unsafe if the connection is shared with multiple threads.
159 enum ConnectionType { 159 enum ConnectionType {
160 PRIVATE, 160 PRIVATE,
161 SHARED, 161 SHARED,
162 }; 162 };
163 163
164 // Specifies whether the GetServiceOwnerAndBlock call should report or
165 // suppress errors.
166 enum GetServiceOwnerOption {
167 REPORT_ERRORS,
168 SUPPRESS_ERRORS,
169 };
170
164 // Options used to create a Bus object. 171 // Options used to create a Bus object.
165 struct CHROME_DBUS_EXPORT Options { 172 struct CHROME_DBUS_EXPORT Options {
166 Options(); 173 Options();
167 ~Options(); 174 ~Options();
168 175
169 BusType bus_type; // SESSION by default. 176 BusType bus_type; // SESSION by default.
170 ConnectionType connection_type; // PRIVATE by default. 177 ConnectionType connection_type; // PRIVATE by default.
171 // If dbus_task_runner is set, the bus object will use that 178 // If dbus_task_runner is set, the bus object will use that
172 // task runner to process asynchronous operations. 179 // task runner to process asynchronous operations.
173 // 180 //
(...skipping 30 matching lines...) Expand all
204 211
205 // Creates a Bus object. The actual connection will be established when 212 // Creates a Bus object. The actual connection will be established when
206 // Connect() is called. 213 // Connect() is called.
207 explicit Bus(const Options& options); 214 explicit Bus(const Options& options);
208 215
209 // Called when an ownership request is complete. 216 // Called when an ownership request is complete.
210 // Parameters: 217 // Parameters:
211 // - the requested service name. 218 // - the requested service name.
212 // - whether ownership has been obtained or not. 219 // - whether ownership has been obtained or not.
213 typedef base::Callback<void (const std::string&, bool)> OnOwnershipCallback; 220 typedef base::Callback<void (const std::string&, bool)> OnOwnershipCallback;
221
222 // Called when GetServiceOwner() completes.
223 // |service_owner| is the return value from GetServiceOwnerAndBlock().
224 typedef base::Callback<void (const std::string& service_owner)>
225 GetServiceOwnerCallback;
226
214 // TODO(satorux): Remove the service name parameter as the caller of 227 // TODO(satorux): Remove the service name parameter as the caller of
215 // RequestOwnership() knows the service name. 228 // RequestOwnership() knows the service name.
216 229
217 // Gets the object proxy for the given service name and the object path. 230 // Gets the object proxy for the given service name and the object path.
218 // The caller must not delete the returned object. 231 // The caller must not delete the returned object.
219 // 232 //
220 // Returns an existing object proxy if the bus object already owns the 233 // Returns an existing object proxy if the bus object already owns the
221 // object proxy for the given service name and the object path. 234 // object proxy for the given service name and the object path.
222 // Never returns NULL. 235 // Never returns NULL.
223 // 236 //
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 536
524 // Check whether the current thread is on the origin thread (the thread 537 // Check whether the current thread is on the origin thread (the thread
525 // that created the bus). If not, DCHECK will fail. 538 // that created the bus). If not, DCHECK will fail.
526 virtual void AssertOnOriginThread(); 539 virtual void AssertOnOriginThread();
527 540
528 // Check whether the current thread is on the D-Bus thread. If not, 541 // Check whether the current thread is on the D-Bus thread. If not,
529 // DCHECK will fail. If the D-Bus thread is not supplied, it calls 542 // DCHECK will fail. If the D-Bus thread is not supplied, it calls
530 // AssertOnOriginThread(). 543 // AssertOnOriginThread().
531 virtual void AssertOnDBusThread(); 544 virtual void AssertOnDBusThread();
532 545
546 // Gets the owner for |service_name| via org.freedesktop.DBus.GetNameOwner.
547 // Returns the owner name, if any, or an empty string on failure.
548 // |options| specifies where to printing error messages or not.
549 //
550 // BLOCKING CALL.
551 virtual std::string GetServiceOwnerAndBlock(const std::string& service_name,
552 GetServiceOwnerOption options);
553
554 // A non-blocking version of GetServiceOwnerAndBlock().
555 // Must be called in the origin thread.
556 virtual void GetServiceOwner(const std::string& service_name,
557 const GetServiceOwnerCallback& callback);
558
533 // Returns true if the bus is connected to D-Bus. 559 // Returns true if the bus is connected to D-Bus.
534 bool is_connected() { return connection_ != NULL; } 560 bool is_connected() { return connection_ != NULL; }
535 561
536 protected: 562 protected:
537 // This is protected, so we can define sub classes. 563 // This is protected, so we can define sub classes.
538 virtual ~Bus(); 564 virtual ~Bus();
539 565
540 private: 566 private:
541 friend class base::RefCountedThreadSafe<Bus>; 567 friend class base::RefCountedThreadSafe<Bus>;
542 568
543 // Helper function used for RemoveObjectProxy(). 569 // Helper function used for RemoveObjectProxy().
544 void RemoveObjectProxyInternal(scoped_refptr<dbus::ObjectProxy> object_proxy, 570 void RemoveObjectProxyInternal(scoped_refptr<dbus::ObjectProxy> object_proxy,
545 const base::Closure& callback); 571 const base::Closure& callback);
546 572
547 // Helper function used for UnregisterExportedObject(). 573 // Helper function used for UnregisterExportedObject().
548 void UnregisterExportedObjectInternal( 574 void UnregisterExportedObjectInternal(
549 scoped_refptr<dbus::ExportedObject> exported_object); 575 scoped_refptr<dbus::ExportedObject> exported_object);
550 576
551 // Helper function used for ShutdownOnDBusThreadAndBlock(). 577 // Helper function used for ShutdownOnDBusThreadAndBlock().
552 void ShutdownOnDBusThreadAndBlockInternal(); 578 void ShutdownOnDBusThreadAndBlockInternal();
553 579
554 // Helper function used for RequestOwnership(). 580 // Helper function used for RequestOwnership().
555 void RequestOwnershipInternal(const std::string& service_name, 581 void RequestOwnershipInternal(const std::string& service_name,
556 OnOwnershipCallback on_ownership_callback); 582 OnOwnershipCallback on_ownership_callback);
557 583
584 // Helper function used for GetServiceOwner().
585 void GetServiceOwnerInternal(const std::string& service_name,
586 const GetServiceOwnerCallback& callback);
587
558 // Processes the all incoming data to the connection, if any. 588 // Processes the all incoming data to the connection, if any.
559 // 589 //
560 // BLOCKING CALL. 590 // BLOCKING CALL.
561 void ProcessAllIncomingDataIfAny(); 591 void ProcessAllIncomingDataIfAny();
562 592
563 // Called when a watch object is added. Used to start monitoring the 593 // Called when a watch object is added. Used to start monitoring the
564 // file descriptor used for D-Bus communication. 594 // file descriptor used for D-Bus communication.
565 dbus_bool_t OnAddWatch(DBusWatch* raw_watch); 595 dbus_bool_t OnAddWatch(DBusWatch* raw_watch);
566 596
567 // Called when a watch object is removed. 597 // Called when a watch object is removed.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 687
658 std::string address_; 688 std::string address_;
659 base::Closure on_disconnected_closure_; 689 base::Closure on_disconnected_closure_;
660 690
661 DISALLOW_COPY_AND_ASSIGN(Bus); 691 DISALLOW_COPY_AND_ASSIGN(Bus);
662 }; 692 };
663 693
664 } // namespace dbus 694 } // namespace dbus
665 695
666 #endif // DBUS_BUS_H_ 696 #endif // DBUS_BUS_H_
OLDNEW
« no previous file with comments | « no previous file | dbus/bus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698