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

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

Issue 2011383002: Get rid of {Run,Terminate}MainApplication(), and more ApplicationDelegate conversion. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 4 years, 6 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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_CPP_APPLICATION_RUN_APPLICATION_H_ 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_
6 #define MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ 6 #define MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_
7 7
8 #include "mojo/public/c/system/handle.h" 8 #include "mojo/public/c/system/handle.h"
9 #include "mojo/public/c/system/result.h" 9 #include "mojo/public/c/system/result.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 12
13 class ApplicationImplBase; 13 class ApplicationImplBase;
14 14
15 // Base class for options to |RunMainApplication()| and |RunApplication()|. An 15 // Base class for options to |RunApplication()|. An implementation of these
16 // implementation of these functions may (but need not, in which case no options 16 // functions may (but need not, in which case no options are available)
17 // are available) separately provide an implementation subclass, which would be 17 // separately provide an implementation subclass, which would be specific to
18 // specific to that implementation. (The "standalone" implementation has no 18 // that implementation. (The "standalone" implementation has no options.)
19 // options.)
20 class RunApplicationOptions { 19 class RunApplicationOptions {
21 protected: 20 protected:
22 RunApplicationOptions() {} 21 RunApplicationOptions() {}
23 ~RunApplicationOptions() {} 22 ~RunApplicationOptions() {}
24 }; 23 };
25 24
26 // |RunMainApplication()| and |RunApplication()| set up a message (run) loop and 25 // |RunApplication()| sets up a message (run) loop and runs the provided
27 // run the provided application implementation. |RunMainApplication()| should be 26 // application implementation. The return value will be the one provided to
28 // used on the application's main thread (e.g., from |MojoMain()|) and may do 27 // |TerminateApplication()|.
29 // additional initialization. (In the case of the "standalone" implementation,
30 // the two are equivalent.) The return value will be the one provided to
31 // |TerminateMainApplication()| or |TerminateApplication()|, respectively.
32 // 28 //
33 // Typical use (where |MyApplicationImpl| is an implementation of 29 // Typical use (where |MyApplicationImpl| is an implementation of
34 // |ApplicationImplBase|): 30 // |ApplicationImplBase|):
35 // 31 //
36 // MojoResult MojoMain(MojoHandle application_request_handle) { 32 // MojoResult MojoMain(MojoHandle application_request_handle) {
37 // MyApplicationImpl my_app; 33 // MyApplicationImpl my_app;
38 // return mojo::RunMainApplication(application_request_handle, &my_app); 34 // return mojo::RunApplication(application_request_handle, &my_app);
39 // } 35 // }
40 // 36 //
41 // |RunApplication()| may be used on secondary threads (that are not already 37 // Note that |RunApplication()| may also be used on secondary threads (that are
42 // running a message loop of some sort). 38 // not already running a message loop of some sort).
43 // 39 //
44 // |*application_impl| must remain alive until the message loop starts running 40 // |*application_impl| must remain alive until the message loop starts running
45 // (thus it may own itself). If |options| is non-null, then it must point to an 41 // (thus it may own itself). If |options| is non-null, then it must point to an
46 // instance of an implementation-specific subclass of |RunApplicationOptions|; 42 // instance of an implementation-specific subclass of |RunApplicationOptions|;
47 // |*options| must remain alive for the duration of the call. 43 // |*options| must remain alive for the duration of the call.
48 MojoResult RunMainApplication(MojoHandle application_request_handle,
49 ApplicationImplBase* application_impl,
50 const RunApplicationOptions* options = nullptr);
51 MojoResult RunApplication(MojoHandle application_request_handle, 44 MojoResult RunApplication(MojoHandle application_request_handle,
52 ApplicationImplBase* application_impl, 45 ApplicationImplBase* application_impl,
53 const RunApplicationOptions* options = nullptr); 46 const RunApplicationOptions* options = nullptr);
54 47
55 // |TerminateMainApplication()| and |TerminateApplication()| terminate the 48 // |TerminateApplication()| terminates the application that is running on the
56 // application that is running on the current thread. They may only be called 49 // current thread. It may only be called from "inside" |RunApplication()| (i.e.,
57 // from "inside" |RunMainApplication()| and |RunApplication()| respectively 50 // with |RunApplication()| on the stack, which means that the message loop is
58 // (i.e., |Run[Main]Application()| is on the stack, which means that the message 51 // running). It causes |RunApplication()| to return "soon" (assuming the message
59 // loop is running). They will cause |Run[Main]Application()| to return "soon" 52 // loop is not blocked processing some task), with return value |result|. It may
60 // (assuming the message loop is not blocked processing some task), with return 53 // cause queued work to *not* be executed. It should be executed at most once
61 // value |result|. They may cause queued work to *not* be executed. They should 54 // (per |RunApplication()|).
62 // be executed at most once (per |Run[Main]Application()|).
63 void TerminateMainApplication(MojoResult result);
64 void TerminateApplication(MojoResult result); 55 void TerminateApplication(MojoResult result);
65 56
66 } // namespace mojo 57 } // namespace mojo
67 58
68 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ 59 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/lib/run_application.cc ('k') | mojo/public/cpp/bindings/tests/versioning_test_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698