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

Side by Side Diff: mojo/public/cpp/application/lib/run_application.cc

Issue 2008543004: Add RunMainApplication()/TerminateMainApplication() for use in MojoMain(). (Closed) Base URL: https://github.com/domokit/mojo.git@work796_run_app_returns
Patch Set: 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
« no previous file with comments | « mojo/public/cpp/application/BUILD.gn ('k') | mojo/public/cpp/application/run_application.h » ('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 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 #include "mojo/public/cpp/application/run_application.h" 5 #include "mojo/public/cpp/application/run_application.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <pthread.h> 8 #include <pthread.h>
9 9
10 #include "mojo/public/cpp/application/application_impl_base.h" 10 #include "mojo/public/cpp/application/application_impl_base.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 void SetCurrentResultHolder(ResultHolder* result_holder) { 51 void SetCurrentResultHolder(ResultHolder* result_holder) {
52 InitializeCurrentResultHolderIfNecessary(); 52 InitializeCurrentResultHolderIfNecessary();
53 53
54 int error = pthread_setspecific(g_current_result_holder_key, result_holder); 54 int error = pthread_setspecific(g_current_result_holder_key, result_holder);
55 MOJO_ALLOW_UNUSED_LOCAL(error); 55 MOJO_ALLOW_UNUSED_LOCAL(error);
56 assert(!error); 56 assert(!error);
57 } 57 }
58 58
59 } // namespace 59 } // namespace
60 60
61 MojoResult RunMainApplication(MojoHandle application_request_handle,
62 ApplicationImplBase* application_impl) {
63 return RunApplication(application_request_handle, application_impl);
64 }
65
61 MojoResult RunApplication(MojoHandle application_request_handle, 66 MojoResult RunApplication(MojoHandle application_request_handle,
62 ApplicationImplBase* application_impl) { 67 ApplicationImplBase* application_impl) {
63 assert(!GetCurrentResultHolder()); 68 assert(!GetCurrentResultHolder());
64 69
65 ResultHolder result_holder; 70 ResultHolder result_holder;
66 SetCurrentResultHolder(&result_holder); 71 SetCurrentResultHolder(&result_holder);
67 72
68 RunLoop loop; 73 RunLoop loop;
69 application_impl->Bind(InterfaceRequest<Application>( 74 application_impl->Bind(InterfaceRequest<Application>(
70 MakeScopedHandle(MessagePipeHandle(application_request_handle)))); 75 MakeScopedHandle(MessagePipeHandle(application_request_handle))));
71 loop.Run(); 76 loop.Run();
72 77
73 // TODO(vtl): Should we unbind stuff here? (Should there be "will start"/"did 78 // TODO(vtl): Should we unbind stuff here? (Should there be "will start"/"did
74 // stop" notifications to the |ApplicationImplBase|?) 79 // stop" notifications to the |ApplicationImplBase|?)
75 80
76 SetCurrentResultHolder(nullptr); 81 SetCurrentResultHolder(nullptr);
77 82
78 // TODO(vtl): We'd like to enable the following assertion, but we do things 83 // TODO(vtl): We'd like to enable the following assertion, but we do things
79 // like |RunLoop::current()->Quit()| in various places. 84 // like |RunLoop::current()->Quit()| in various places.
80 // assert(result_holder.is_set); 85 // assert(result_holder.is_set);
81 86
82 return result_holder.result; 87 return result_holder.result;
83 } 88 }
84 89
90 void TerminateMainApplication(MojoResult result) {
91 TerminateApplication(result);
92 }
93
85 void TerminateApplication(MojoResult result) { 94 void TerminateApplication(MojoResult result) {
86 RunLoop::current()->Quit(); 95 RunLoop::current()->Quit();
87 96
88 ResultHolder* result_holder = GetCurrentResultHolder(); 97 ResultHolder* result_holder = GetCurrentResultHolder();
89 assert(result_holder); 98 assert(result_holder);
90 assert(!result_holder->is_set); 99 assert(!result_holder->is_set);
91 result_holder->result = result; 100 result_holder->result = result;
92 #ifndef NDEBUG 101 #ifndef NDEBUG
93 result_holder->is_set = true; 102 result_holder->is_set = true;
94 #endif 103 #endif
95 } 104 }
96 105
97 } // namespace mojo 106 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/BUILD.gn ('k') | mojo/public/cpp/application/run_application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698