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

Side by Side Diff: mojo/public/cpp/application/application_impl.h

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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
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_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
7 #include <vector>
8
9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/application/lib/service_connector.h"
11 #include "mojo/public/cpp/application/lib/service_registry.h"
12 #include "mojo/public/cpp/system/core.h"
13 #include "mojo/public/interfaces/application/application.mojom.h"
14 #include "mojo/public/interfaces/application/shell.mojom.h"
15
16 namespace mojo {
17
18 class ApplicationDelegate;
19
20 // Utility class for communicating with the Shell, and providing Services
21 // to clients.
22 //
23 // To use define a class that implements your specific server api, e.g. FooImpl
24 // to implement a service named Foo.
25 // That class must subclass an InterfaceImpl specialization.
26 //
27 // If there is context that is to be shared amongst all instances, define a
28 // constructor with that class as its only argument, otherwise define an empty
29 // constructor.
30 //
31 // class FooImpl : public InterfaceImpl<Foo> {
32 // public:
33 // FooImpl(ApplicationContext* app_context) {}
34 // };
35 //
36 // or
37 //
38 // class BarImpl : public InterfaceImpl<Bar> {
39 // public:
40 // // contexts will remain valid for the lifetime of BarImpl.
41 // BarImpl(ApplicationContext* app_context, BarContext* service_context)
42 // : app_context_(app_context), servicecontext_(context) {}
43 //
44 // Create an ApplicationImpl instance that collects any service implementations.
45 //
46 // ApplicationImpl app(service_provider_handle);
47 // app.AddService<FooImpl>();
48 //
49 // BarContext context;
50 // app.AddService<BarImpl>(&context);
51 //
52 //
53 class ApplicationImpl : public InterfaceImpl<Application> {
54 public:
55 ApplicationImpl(ApplicationDelegate* delegate,
56 ScopedMessagePipeHandle shell_handle);
57 ApplicationImpl(ApplicationDelegate* delegate, MojoHandle shell_handle);
58 ~ApplicationImpl() override;
59
60 Shell* shell() const { return shell_.get(); }
61
62 // Returns any initial configuration arguments, passed by the Shell.
63 const std::vector<std::string>& args() const { return args_; }
64 bool HasArg(const std::string& arg) const;
65
66 // Establishes a new connection to an application. Caller does not own.
67 ApplicationConnection* ConnectToApplication(const String& application_url);
68
69 // Connect to application identified by |application_url| and connect to the
70 // service implementation of the interface identified by |Interface|.
71 template <typename Interface>
72 void ConnectToService(const std::string& application_url,
73 InterfacePtr<Interface>* ptr) {
74 ConnectToApplication(application_url)->ConnectToService(ptr);
75 }
76
77 // Wait for the ShellPtr's Initialize message.
78 bool WaitForInitialize();
79
80 // Unbind the shell from this application and return its handle.
81 ScopedMessagePipeHandle UnbindShell();
82
83 // Application implementation.
84 void Initialize(Array<String> args) override;
85
86 // Quits the main run loop for this application.
87 static void Terminate();
88
89 private:
90 class ShellPtrWatcher;
91
92 void BindShell(ScopedMessagePipeHandle shell_handle);
93 void ClearConnections();
94 void OnShellError() {
95 ClearConnections();
96 Terminate();
97 }
98
99 // Application implementation.
100 void AcceptConnection(const String& requestor_url,
101 InterfaceRequest<ServiceProvider> services,
102 ServiceProviderPtr exposed_services) override;
103
104 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList;
105
106 bool initialized_;
107 ServiceRegistryList incoming_service_registries_;
108 ServiceRegistryList outgoing_service_registries_;
109 ApplicationDelegate* delegate_;
110 ShellPtr shell_;
111 ShellPtrWatcher* shell_watch_;
112 std::vector<std::string> args_;
113
114 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl);
115 };
116
117 } // namespace mojo
118
119 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/application_delegate.h ('k') | mojo/public/cpp/application/application_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698