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

Side by Side Diff: dbus/bus.h

Issue 9668018: dbus: remove service name from ExportedObject (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pay more attention when fixing mock Created 8 years, 9 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 | « chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc ('k') | 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 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // requirements: 169 // requirements:
170 // 1) Already running. 170 // 1) Already running.
171 // 2) Has a MessageLoopForIO. 171 // 2) Has a MessageLoopForIO.
172 scoped_refptr<base::MessageLoopProxy> dbus_thread_message_loop_proxy; 172 scoped_refptr<base::MessageLoopProxy> dbus_thread_message_loop_proxy;
173 }; 173 };
174 174
175 // Creates a Bus object. The actual connection will be established when 175 // Creates a Bus object. The actual connection will be established when
176 // Connect() is called. 176 // Connect() is called.
177 explicit Bus(const Options& options); 177 explicit Bus(const Options& options);
178 178
179 // Called when an ownership request is complete.
180 // Parameters:
181 // - the requested service name.
182 // - whether ownership has been obtained or not.
183 typedef base::Callback<void (const std::string&, bool)> OnOwnershipCallback;
184
179 // Gets the object proxy for the given service name and the object path. 185 // Gets the object proxy for the given service name and the object path.
180 // The caller must not delete the returned object. 186 // The caller must not delete the returned object.
181 // 187 //
182 // Returns an existing object proxy if the bus object already owns the 188 // Returns an existing object proxy if the bus object already owns the
183 // object proxy for the given service name and the object path. 189 // object proxy for the given service name and the object path.
184 // Never returns NULL. 190 // Never returns NULL.
185 // 191 //
186 // The bus will own all object proxies created by the bus, to ensure 192 // The bus will own all object proxies created by the bus, to ensure
187 // that the object proxies are detached from remote objects at the 193 // that the object proxies are detached from remote objects at the
188 // shutdown time of the bus. 194 // shutdown time of the bus.
189 // 195 //
190 // The object proxy is used to call methods of remote objects, and 196 // The object proxy is used to call methods of remote objects, and
191 // receive signals from them. 197 // receive signals from them.
192 // 198 //
193 // |service_name| looks like "org.freedesktop.NetworkManager", and 199 // |service_name| looks like "org.freedesktop.NetworkManager", and
194 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0". 200 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0".
195 // 201 //
196 // Must be called in the origin thread. 202 // Must be called in the origin thread.
197 virtual ObjectProxy* GetObjectProxy(const std::string& service_name, 203 virtual ObjectProxy* GetObjectProxy(const std::string& service_name,
198 const ObjectPath& object_path); 204 const ObjectPath& object_path);
199 205
200 // Same as above, but also takes a bitfield of ObjectProxy::Options. 206 // Same as above, but also takes a bitfield of ObjectProxy::Options.
201 // See object_proxy.h for available options. 207 // See object_proxy.h for available options.
202 virtual ObjectProxy* GetObjectProxyWithOptions( 208 virtual ObjectProxy* GetObjectProxyWithOptions(
203 const std::string& service_name, 209 const std::string& service_name,
204 const ObjectPath& object_path, 210 const ObjectPath& object_path,
205 int options); 211 int options);
206 212
207 // Gets the exported object for the given service name and the object 213 // Gets the exported object for the given object path.
208 // path. The caller must not delete the returned object. 214 // The caller must not delete the returned object.
209 // 215 //
210 // Returns an existing exported object if the bus object already owns 216 // Returns an existing exported object if the bus object already owns
211 // the exported object for the given service name and the object path. 217 // the exported object for the given object path. Never returns NULL.
212 // Never returns NULL.
213 // 218 //
214 // The bus will own all exported objects created by the bus, to ensure 219 // The bus will own all exported objects created by the bus, to ensure
215 // that the exported objects are unregistered at the shutdown time of 220 // that the exported objects are unregistered at the shutdown time of
216 // the bus. 221 // the bus.
217 // 222 //
218 // The exported object is used to export methods of local objects, and 223 // The exported object is used to export methods of local objects, and
219 // send signal from them. 224 // send signal from them.
220 // 225 //
221 // Must be called in the origin thread. 226 // Must be called in the origin thread.
222 virtual ExportedObject* GetExportedObject(const std::string& service_name, 227 virtual ExportedObject* GetExportedObject(const ObjectPath& object_path);
223 const ObjectPath& object_path);
224 228
225 // Shuts down the bus and blocks until it's done. More specifically, this 229 // Shuts down the bus and blocks until it's done. More specifically, this
226 // function does the following: 230 // function does the following:
227 // 231 //
228 // - Unregisters the object paths 232 // - Unregisters the object paths
229 // - Releases the service names 233 // - Releases the service names
230 // - Closes the connection to dbus-daemon. 234 // - Closes the connection to dbus-daemon.
231 // 235 //
232 // BLOCKING CALL. 236 // BLOCKING CALL.
233 virtual void ShutdownAndBlock(); 237 virtual void ShutdownAndBlock();
(...skipping 14 matching lines...) Expand all
248 // The public functions below are not intended to be used in client 252 // The public functions below are not intended to be used in client
249 // code. These are used to implement ObjectProxy and ExportedObject. 253 // code. These are used to implement ObjectProxy and ExportedObject.
250 // 254 //
251 255
252 // Connects the bus to the dbus-daemon. 256 // Connects the bus to the dbus-daemon.
253 // Returns true on success, or the bus is already connected. 257 // Returns true on success, or the bus is already connected.
254 // 258 //
255 // BLOCKING CALL. 259 // BLOCKING CALL.
256 virtual bool Connect(); 260 virtual bool Connect();
257 261
262 // Requests the ownership of the service name given by |service_name|.
263 // See also RequestOwnershipAndBlock().
264 //
265 // |on_ownership_callback| is called when the service name is obtained
266 // or failed to be obtained, in the origin thread.
267 //
268 // Must be called in the origin thread.
269 virtual void RequestOwnership(const std::string& service_name,
270 OnOwnershipCallback on_ownership_callback);
271
258 // Requests the ownership of the given service name. 272 // Requests the ownership of the given service name.
259 // Returns true on success, or the the service name is already obtained. 273 // Returns true on success, or the the service name is already obtained.
260 // 274 //
261 // BLOCKING CALL. 275 // BLOCKING CALL.
262 virtual bool RequestOwnership(const std::string& service_name); 276 virtual bool RequestOwnershipAndBlock(const std::string& service_name);
263 277
264 // Releases the ownership of the given service name. 278 // Releases the ownership of the given service name.
265 // Returns true on success. 279 // Returns true on success.
266 // 280 //
267 // BLOCKING CALL. 281 // BLOCKING CALL.
268 virtual bool ReleaseOwnership(const std::string& service_name); 282 virtual bool ReleaseOwnership(const std::string& service_name);
269 283
270 // Sets up async operations. 284 // Sets up async operations.
271 // Returns true on success, or it's already set up. 285 // Returns true on success, or it's already set up.
272 // This function needs to be called before starting async operations. 286 // This function needs to be called before starting async operations.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 protected: 416 protected:
403 // This is protected, so we can define sub classes. 417 // This is protected, so we can define sub classes.
404 virtual ~Bus(); 418 virtual ~Bus();
405 419
406 private: 420 private:
407 friend class base::RefCountedThreadSafe<Bus>; 421 friend class base::RefCountedThreadSafe<Bus>;
408 422
409 // Helper function used for ShutdownOnDBusThreadAndBlock(). 423 // Helper function used for ShutdownOnDBusThreadAndBlock().
410 void ShutdownOnDBusThreadAndBlockInternal(); 424 void ShutdownOnDBusThreadAndBlockInternal();
411 425
426 // Helper function used for RequestOwnership().
427 void RequestOwnershipInternal(const std::string& service_name,
428 OnOwnershipCallback on_ownership_callback);
429
430 // Called when the ownership request is completed.
431 void OnOwnership(OnOwnershipCallback on_ownership_callback,
432 const std::string& service_name,
433 bool success);
434
412 // Processes the all incoming data to the connection, if any. 435 // Processes the all incoming data to the connection, if any.
413 // 436 //
414 // BLOCKING CALL. 437 // BLOCKING CALL.
415 void ProcessAllIncomingDataIfAny(); 438 void ProcessAllIncomingDataIfAny();
416 439
417 // Called when a watch object is added. Used to start monitoring the 440 // Called when a watch object is added. Used to start monitoring the
418 // file descriptor used for D-Bus communication. 441 // file descriptor used for D-Bus communication.
419 dbus_bool_t OnAddWatch(DBusWatch* raw_watch); 442 dbus_bool_t OnAddWatch(DBusWatch* raw_watch);
420 443
421 // Called when a watch object is removed. 444 // Called when a watch object is removed.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 // service name + object path, like 494 // service name + object path, like
472 // "org.chromium.TestService/org/chromium/TestObject". 495 // "org.chromium.TestService/org/chromium/TestObject".
473 // The second part is the ObjectProxy::Options for the proxy. 496 // The second part is the ObjectProxy::Options for the proxy.
474 typedef std::map<std::pair<std::string, int>, 497 typedef std::map<std::pair<std::string, int>,
475 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable; 498 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable;
476 ObjectProxyTable object_proxy_table_; 499 ObjectProxyTable object_proxy_table_;
477 500
478 // ExportedObjectTable is used to hold the exported objects created by 501 // ExportedObjectTable is used to hold the exported objects created by
479 // the bus object. Key is a concatenated string of service name + 502 // the bus object. Key is a concatenated string of service name +
480 // object path, like "org.chromium.TestService/org/chromium/TestObject". 503 // object path, like "org.chromium.TestService/org/chromium/TestObject".
481 typedef std::map<std::string, 504 typedef std::map<const dbus::ObjectPath,
482 scoped_refptr<dbus::ExportedObject> > ExportedObjectTable; 505 scoped_refptr<dbus::ExportedObject> > ExportedObjectTable;
483 ExportedObjectTable exported_object_table_; 506 ExportedObjectTable exported_object_table_;
484 507
485 bool async_operations_set_up_; 508 bool async_operations_set_up_;
486 bool shutdown_completed_; 509 bool shutdown_completed_;
487 510
488 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and 511 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and
489 // OnAddTimeout()/OnRemoveTimeou() are balanced. 512 // OnAddTimeout()/OnRemoveTimeou() are balanced.
490 int num_pending_watches_; 513 int num_pending_watches_;
491 int num_pending_timeouts_; 514 int num_pending_timeouts_;
492 515
493 DISALLOW_COPY_AND_ASSIGN(Bus); 516 DISALLOW_COPY_AND_ASSIGN(Bus);
494 }; 517 };
495 518
496 } // namespace dbus 519 } // namespace dbus
497 520
498 #endif // DBUS_BUS_H_ 521 #endif // DBUS_BUS_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc ('k') | dbus/bus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698