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

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

Issue 2015643002: Add (optional) options to Run[Main]Application(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh 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
16 // implementation of these functions may (but need not, in which case no options
17 // are available) separately provide an implementation subclass, which would be
18 // specific to that implementation. (The "standalone" implementation has no
19 // options.)
20 class RunApplicationOptions {
21 protected:
22 RunApplicationOptions() {}
23 ~RunApplicationOptions() {}
24 };
25
15 // |RunMainApplication()| and |RunApplication()| set up a message (run) loop and 26 // |RunMainApplication()| and |RunApplication()| set up a message (run) loop and
16 // run the provided application implementation. |RunMainApplication()| should be 27 // run the provided application implementation. |RunMainApplication()| should be
17 // used on the application's main thread (e.g., from |MojoMain()|) and may do 28 // used on the application's main thread (e.g., from |MojoMain()|) and may do
18 // additional initialization. (In the case of the "standalone" implementation, 29 // additional initialization. (In the case of the "standalone" implementation,
19 // the two are equivalent.) The return value will be the one provided to 30 // the two are equivalent.) The return value will be the one provided to
20 // |TerminateMainApplication()| or |TerminateApplication()|, respectively. 31 // |TerminateMainApplication()| or |TerminateApplication()|, respectively.
21 // 32 //
22 // Typical use (where |MyApplicationImpl| is an implementation of 33 // Typical use (where |MyApplicationImpl| is an implementation of
23 // |ApplicationImplBase|): 34 // |ApplicationImplBase|):
24 // 35 //
25 // MojoResult MojoMain(MojoHandle application_request_handle) { 36 // MojoResult MojoMain(MojoHandle application_request_handle) {
26 // MyApplicationImpl my_app; 37 // MyApplicationImpl my_app;
27 // return mojo::RunMainApplication(application_request_handle, &my_app); 38 // return mojo::RunMainApplication(application_request_handle, &my_app);
28 // } 39 // }
29 // 40 //
30 // |RunApplication()| may be used on secondary threads (that are not already 41 // |RunApplication()| may be used on secondary threads (that are not already
31 // running a message loop of some sort). 42 // running a message loop of some sort).
32 // 43 //
33 // |*application_impl| must remain alive until the message loop starts running 44 // |*application_impl| must remain alive until the message loop starts running
34 // (thus it may own itself). 45 // (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|;
47 // |*options| must remain alive for the duration of the call.
35 MojoResult RunMainApplication(MojoHandle application_request_handle, 48 MojoResult RunMainApplication(MojoHandle application_request_handle,
36 ApplicationImplBase* application_impl); 49 ApplicationImplBase* application_impl,
50 const RunApplicationOptions* options = nullptr);
37 MojoResult RunApplication(MojoHandle application_request_handle, 51 MojoResult RunApplication(MojoHandle application_request_handle,
38 ApplicationImplBase* application_impl); 52 ApplicationImplBase* application_impl,
53 const RunApplicationOptions* options = nullptr);
39 54
40 // |TerminateMainApplication()| and |TerminateApplication()| terminate the 55 // |TerminateMainApplication()| and |TerminateApplication()| terminate the
41 // application that is running on the current thread. They may only be called 56 // application that is running on the current thread. They may only be called
42 // from "inside" |RunMainApplication()| and |RunApplication()| respectively 57 // from "inside" |RunMainApplication()| and |RunApplication()| respectively
43 // (i.e., |Run[Main]Application()| is on the stack, which means that the message 58 // (i.e., |Run[Main]Application()| is on the stack, which means that the message
44 // loop is running). They will cause |Run[Main]Application()| to return "soon" 59 // loop is running). They will cause |Run[Main]Application()| to return "soon"
45 // (assuming the message loop is not blocked processing some task), with return 60 // (assuming the message loop is not blocked processing some task), with return
46 // value |result|. They may cause queued work to *not* be executed. They should 61 // value |result|. They may cause queued work to *not* be executed. They should
47 // be executed at most once (per |Run[Main]Application()|). 62 // be executed at most once (per |Run[Main]Application()|).
48 void TerminateMainApplication(MojoResult result); 63 void TerminateMainApplication(MojoResult result);
49 void TerminateApplication(MojoResult result); 64 void TerminateApplication(MojoResult result);
50 65
51 } // namespace mojo 66 } // namespace mojo
52 67
53 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ 68 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698