1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MOJO_SHELL_DBUS_APPLICATION_LOADER_LINUX_H_
6 #define MOJO_SHELL_DBUS_APPLICATION_LOADER_LINUX_H_
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "mojo/application_manager/application_loader.h"
13 #include "mojo/public/cpp/system/core.h"
25 // An implementation of ApplicationLoader that contacts a system service
26 // and bootstraps a Mojo connection to it over DBus.
28 // In order to allow the externally-running service to accept connections from
29 // a Mojo shell, we need to get it a ShellHandle. This class creates a
30 // dedicated MessagePipe, passes a handle to one end to the desired service
31 // over DBus, and then passes the ShellHandle over that pipe.
33 // This class assumes the following:
34 // 1) Your service is already running.
35 // 2) Your service implements the Mojo ExternalService API
36 // (from external_service.mojom).
37 // 3) Your service exports an object that implements the org.chromium.Mojo DBus
39 // <interface name="org.chromium.Mojo">
40 // <method name="ConnectChannel">
41 // <arg type="h" name="file_descriptor" direction="in" />
44 class DBusApplicationLoader : public ApplicationLoader {
46 DBusApplicationLoader(Context* context);
47 virtual ~DBusApplicationLoader();
49 // URL for DBus services are of the following format:
50 // dbus:tld.domain.ServiceName/path/to/DBusObject
52 // This is simply the scheme (dbus:) and then the DBus service name followed
53 // by the DBus object path of an object that implements the org.chromium.Mojo
54 // interface as discussed above.
57 // dbus:org.chromium.EchoService/org/chromium/MojoImpl
59 // This will tell DBusApplicationLoader to reach out to a service with
60 // the name "org.chromium.EchoService" and invoke the method
61 // "org.chromium.Mojo.ConnectChannel" on the object exported at
62 // "/org/chromium/MojoImpl".
63 virtual void Load(ApplicationManager* manager,
65 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE;
67 virtual void OnApplicationError(ApplicationManager* manager,
68 const GURL& url) OVERRIDE;
73 // Tosses out connection-related state to service at given URL.
74 void ForgetService(const GURL& url);
76 Context* const context_;
77 scoped_refptr<dbus::Bus> bus_;
79 typedef std::map<GURL, LoadContext*> LoadContextMap;
80 LoadContextMap url_to_load_context_;
82 DISALLOW_COPY_AND_ASSIGN(DBusApplicationLoader);
88 #endif // MOJO_SHELL_DBUS_APPLICATION_LOADER_LINUX_H_