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

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

Issue 394903005: mojo: terminate apps if the shell goes away (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable tests that touch nss for now Created 6 years, 4 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/public/cpp/application/DEPS ('k') | mojo/public/cpp/application/lib/application_impl.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 2014 The Chromium Authors. All rights reserved. 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 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 MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ 5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ 6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
7 #include <vector> 7 #include <vector>
8 8
9 #include "mojo/public/cpp/application/application_connection.h" 9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/application/lib/service_connector.h" 10 #include "mojo/public/cpp/application/lib/service_connector.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // }; 52 // };
53 // 53 //
54 // or 54 // or
55 // 55 //
56 // class BarImpl : public InterfaceImpl<Bar> { 56 // class BarImpl : public InterfaceImpl<Bar> {
57 // public: 57 // public:
58 // // contexts will remain valid for the lifetime of BarImpl. 58 // // contexts will remain valid for the lifetime of BarImpl.
59 // BarImpl(ApplicationContext* app_context, BarContext* service_context) 59 // BarImpl(ApplicationContext* app_context, BarContext* service_context)
60 // : app_context_(app_context), servicecontext_(context) {} 60 // : app_context_(app_context), servicecontext_(context) {}
61 // 61 //
62 // Create an ApplicationDele instance that collects any service implementations. 62 // Create an ApplicationImpl instance that collects any service implementations.
63 // 63 //
64 // ApplicationImpl app(service_provider_handle); 64 // ApplicationImpl app(service_provider_handle);
65 // app.AddService<FooImpl>(); 65 // app.AddService<FooImpl>();
66 // 66 //
67 // BarContext context; 67 // BarContext context;
68 // app.AddService<BarImpl>(&context); 68 // app.AddService<BarImpl>(&context);
69 // 69 //
70 // 70 //
71 class ApplicationImpl : public InterfaceImpl<Application> { 71 class ApplicationImpl : public InterfaceImpl<Application> {
72 public: 72 public:
73 explicit ApplicationImpl(ApplicationDelegate* delegate); 73 explicit ApplicationImpl(ApplicationDelegate* delegate);
74 ApplicationImpl(ApplicationDelegate* delegate, 74 ApplicationImpl(ApplicationDelegate* delegate,
75 ScopedMessagePipeHandle shell_handle); 75 ScopedMessagePipeHandle shell_handle);
76 ApplicationImpl(ApplicationDelegate* delegate, 76 ApplicationImpl(ApplicationDelegate* delegate,
77 MojoHandle shell_handle); 77 MojoHandle shell_handle);
78 virtual ~ApplicationImpl(); 78 virtual ~ApplicationImpl();
79 79
80 // Establishes a new connection to an application. Caller does not own. 80 // Establishes a new connection to an application. Caller does not own.
81 ApplicationConnection* ConnectToApplication(const String& application_url); 81 ApplicationConnection* ConnectToApplication(const String& application_url);
82 82
83 // Connect to application identified by |application_url| and connect to the 83 // Connect to application identified by |application_url| and connect to the
84 // service implementation of the interface identified by |Interface|. 84 // service implementation of the interface identified by |Interface|.
85 template <typename Interface> 85 template <typename Interface>
86 void ConnectToService(const std::string& application_url, 86 void ConnectToService(const std::string& application_url,
87 InterfacePtr<Interface>* ptr) { 87 InterfacePtr<Interface>* ptr) {
88 ConnectToApplication(application_url)->ConnectToService(ptr); 88 ConnectToApplication(application_url)->ConnectToService(ptr);
89 } 89 }
90 90
91 private: 91 private:
92 class ShellPtrWatcher : public ErrorHandler {
93 public:
94 explicit ShellPtrWatcher(ApplicationImpl* impl);
95 virtual ~ShellPtrWatcher();
96 virtual void OnConnectionError() MOJO_OVERRIDE;
97 private:
98 ApplicationImpl* impl_;
99 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellPtrWatcher);
100 };
101
92 friend MojoResult (::MojoMain)(MojoHandle); 102 friend MojoResult (::MojoMain)(MojoHandle);
93 103
94 void BindShell(ScopedMessagePipeHandle shell_handle); 104 void BindShell(ScopedMessagePipeHandle shell_handle);
95 void BindShell(MojoHandle shell_handle); 105 void BindShell(MojoHandle shell_handle);
106 void ClearConnections();
107 void OnShellError() { ClearConnections(); Terminate(); };
108
109 // Quits the main run loop for this application.
110 void Terminate();
96 111
97 // Application implementation. 112 // Application implementation.
98 virtual void AcceptConnection(const String& requestor_url, 113 virtual void AcceptConnection(const String& requestor_url,
99 ServiceProviderPtr provider) MOJO_OVERRIDE; 114 ServiceProviderPtr provider) MOJO_OVERRIDE;
100 115
101 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; 116 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList;
102 ServiceRegistryList incoming_service_registries_; 117 ServiceRegistryList incoming_service_registries_;
103 ServiceRegistryList outgoing_service_registries_; 118 ServiceRegistryList outgoing_service_registries_;
104 ApplicationDelegate* delegate_; 119 ApplicationDelegate* delegate_;
105 ShellPtr shell_; 120 ShellPtr shell_;
121 ShellPtrWatcher shell_watch_;
106 122
107 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); 123 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl);
108 }; 124 };
109 125
110 } // namespace mojo 126 } // namespace mojo
111 127
112 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ 128 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/DEPS ('k') | mojo/public/cpp/application/lib/application_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698