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

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

Issue 1985223003: Factor stuff from ApplicationImpl out to a new class, ApplicationImplBase. (Closed) Base URL: https://github.com/domokit/mojo.git@work790_app_test_base_no_app_impl
Patch Set: fix android Created 4 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
OLDNEW
(Empty)
1 // Copyright 2016 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_CPP_APPLICATION_APPLICATION_IMPL_BASE_H_
6 #define MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_IMPL_BASE_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "mojo/public/cpp/bindings/binding.h"
13 #include "mojo/public/cpp/bindings/interface_request.h"
14 #include "mojo/public/cpp/system/macros.h"
15 #include "mojo/public/interfaces/application/application.mojom.h"
16 #include "mojo/public/interfaces/application/shell.mojom.h"
17
18 namespace mojo {
19
20 class ServiceProviderImpl;
21
22 // Base helper class for implementing the |Application| interface, which the
23 // shell uses for basic communication with an application (e.g., to connect
24 // clients to services provided by an application).
25 //
26 // To use this class, subclass it and implement/override the required methods
27 // (see below).
28 //
29 // TODO(vtl): ApplicationRunners should take this instead of an
30 // ApplicationDelegate. Write more here when that's true (it's pretty hard to
31 // use this class in the current setup).
32 class ApplicationImplBase : public Application {
33 public:
34 explicit ApplicationImplBase(
35 InterfaceRequest<Application> application_request);
36 ~ApplicationImplBase() override;
37
38 // Quits the main run loop for this application.
39 // TODO(vtl): This is implemented in application_runner.cc (for example). Its
40 // presence here is pretty dubious.
41 static void Terminate();
42
43 // This will be valid after |Initialize()| has been received and remain valid
44 // until this object is destroyed.
45 Shell* shell() const { return shell_.get(); }
46
47 // Returns any initial configuration arguments, passed by the shell.
48 const std::vector<std::string>& args() const { return args_; }
49 bool HasArg(const std::string& arg) const;
50
51 const std::string& url() const { return url_; }
52
53 // Methods to be implemented/overridden by subclasses:
54
55 // Called after |Initialize()| has been received (|shell()|, |args()|, and
56 // |url()| will be valid when this is called. The default implementation does
57 // nothing.
58 virtual void OnInitialize() {}
59
60 // Called when another application connects to this application (i.e., we
61 // receive |AcceptConnection()|). This should either configure what services
62 // are "provided" (made available via a |ServiceProvider|) to that application
63 // and return true, or this may return false to reject the connection
64 // entirely.
65 virtual bool OnAcceptConnection(
66 ServiceProviderImpl* service_provider_impl) = 0;
67
68 // Called before quitting the main message (run) loop, i.e., before
69 // |Terminate()|. The default implementation does nothing.
70 virtual void OnQuit() {}
71
72 private:
73 // |Application| implementation. In general, you probably shouldn't call these
74 // directly (but I can't really stop you).
75 void Initialize(InterfaceHandle<Shell> shell,
76 Array<String> args,
77 const mojo::String& url) final;
78 void AcceptConnection(const String& requestor_url,
79 InterfaceRequest<ServiceProvider> services,
80 InterfaceHandle<ServiceProvider> exposed_services,
81 const String& url) final;
82 void RequestQuit() final;
83
84 Binding<Application> application_binding_;
85
86 // Set by |Initialize()|.
87 ShellPtr shell_;
88 std::vector<std::string> args_;
89 std::string url_;
90
91 std::vector<std::unique_ptr<ServiceProviderImpl>> service_provider_impls_;
92
93 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImplBase);
94 };
95
96 } // namespace mojo
97
98 #endif // MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_IMPL_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698