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

Side by Side Diff: mojo/shell/dbus_service_loader_linux.h

Issue 242763003: Implement a trivial Mojo EchoService that can be connected to over DBus (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to switch MojoChannelInit to ChannelInit Created 6 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 | « mojo/shell/context.cc ('k') | mojo/shell/dbus_service_loader_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef MOJO_SHELL_DBUS_SERVICE_LOADER_H_
6 #define MOJO_SHELL_DBUS_SERVICE_LOADER_H_
7
8 #include <map>
9
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "mojo/public/cpp/system/core.h"
13 #include "mojo/public/interfaces/shell/shell.mojom.h"
14 #include "mojo/service_manager/service_loader.h"
15 #include "mojo/shell/keep_alive.h"
16 #include "url/gurl.h"
17
18 namespace dbus {
19 class Bus;
20 } // namespace dbus
21
22 namespace mojo {
23 namespace shell {
24
25 class Context;
26
27 // An implementation of ServiceLoader that contacts a system service
28 // and bootstraps a Mojo connection to it over DBus.
29 //
30 // In order to allow the externally-running service to accept connections from
31 // a Mojo shell, we need to get it a ShellHandle. This class creates a
32 // dedicated MessagePipe, passes a handle to one end to the desired service
33 // over DBus, and then passes the ShellHandle over that pipe.
34 //
35 // This class assumes the following:
36 // 1) Your service is already running.
37 // 2) Your service implements the Mojo ExternalService API
38 // (from external_service.mojom).
39 // 3) Your service exports an object that implements the org.chromium.Mojo DBus
40 // interface:
41 // <interface name="org.chromium.Mojo">
42 // <method name="ConnectChannel">
43 // <arg type="h" name="file_descriptor" direction="in" />
44 // </method>
45 // </interface>
46 class DBusServiceLoader : public ServiceLoader {
47 public:
48 DBusServiceLoader(Context* context);
49 virtual ~DBusServiceLoader();
50
51 // URL for DBus services are of the following format:
52 // dbus:tld.domain.ServiceName/path/to/DBusObject
53 //
54 // This is simply the scheme (dbus:) and then the DBus service name followed
55 // by the DBus object path of an object that implements the org.chromium.Mojo
56 // interface as discussed above.
57 //
58 // Example:
59 // dbus:org.chromium.EchoService/org/chromium/MojoImpl
60 //
61 // This will tell DBusServiceLoader to reach out to a service with
62 // the name "org.chromium.EchoService" and invoke the method
63 // "org.chromium.Mojo.ConnectChannel" on the object exported at
64 // "/org/chromium/MojoImpl".
65 virtual void LoadService(ServiceManager* manager,
66 const GURL& url,
67 ScopedShellHandle service_handle) OVERRIDE;
68
69 virtual void OnServiceError(ServiceManager* manager, const GURL& url)
70 OVERRIDE;
71
72 private:
73 class LoadContext;
74
75 // Tosses out connection-related state to service at given URL.
76 void ForgetService(const GURL& url);
77
78 Context* const context_;
79 scoped_refptr<dbus::Bus> bus_;
80
81 typedef std::map<GURL, LoadContext*> LoadContextMap;
82 LoadContextMap url_to_load_context_;
83
84 DISALLOW_COPY_AND_ASSIGN(DBusServiceLoader);
85 };
86
87 } // namespace shell
88 } // namespace mojo
89
90 #endif // MOJO_SHELL_DBUS_SERVICE_LOADER_H_
OLDNEW
« no previous file with comments | « mojo/shell/context.cc ('k') | mojo/shell/dbus_service_loader_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698