OLD | NEW |
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 void SetCurrentResultHolder(ResultHolder* result_holder) { | 53 void SetCurrentResultHolder(ResultHolder* result_holder) { |
54 InitializeCurrentResultHolderIfNecessary(); | 54 InitializeCurrentResultHolderIfNecessary(); |
55 | 55 |
56 int error = pthread_setspecific(g_current_result_holder_key, result_holder); | 56 int error = pthread_setspecific(g_current_result_holder_key, result_holder); |
57 MOJO_ALLOW_UNUSED_LOCAL(error); | 57 MOJO_ALLOW_UNUSED_LOCAL(error); |
58 assert(!error); | 58 assert(!error); |
59 } | 59 } |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 MojoResult RunMainApplication(MojoHandle application_request_handle, | |
64 ApplicationImplBase* application_impl, | |
65 const RunApplicationOptions* options) { | |
66 return RunApplication(application_request_handle, application_impl, options); | |
67 } | |
68 | |
69 MojoResult RunApplication(MojoHandle application_request_handle, | 63 MojoResult RunApplication(MojoHandle application_request_handle, |
70 ApplicationImplBase* application_impl, | 64 ApplicationImplBase* application_impl, |
71 const RunApplicationOptions* options) { | 65 const RunApplicationOptions* options) { |
72 assert(!options); // No options supported! | 66 assert(!options); // No options supported! |
73 assert(!GetCurrentResultHolder()); | 67 assert(!GetCurrentResultHolder()); |
74 | 68 |
75 ResultHolder result_holder; | 69 ResultHolder result_holder; |
76 SetCurrentResultHolder(&result_holder); | 70 SetCurrentResultHolder(&result_holder); |
77 | 71 |
78 RunLoop loop; | 72 RunLoop loop; |
79 application_impl->Bind(InterfaceRequest<Application>( | 73 application_impl->Bind(InterfaceRequest<Application>( |
80 MakeScopedHandle(MessagePipeHandle(application_request_handle)))); | 74 MakeScopedHandle(MessagePipeHandle(application_request_handle)))); |
81 loop.Run(); | 75 loop.Run(); |
82 | 76 |
83 // TODO(vtl): Should we unbind stuff here? (Should there be "will start"/"did | 77 // TODO(vtl): Should we unbind stuff here? (Should there be "will start"/"did |
84 // stop" notifications to the |ApplicationImplBase|?) | 78 // stop" notifications to the |ApplicationImplBase|?) |
85 | 79 |
86 SetCurrentResultHolder(nullptr); | 80 SetCurrentResultHolder(nullptr); |
87 | 81 |
88 // TODO(vtl): We'd like to enable the following assertion, but we do things | 82 // TODO(vtl): We'd like to enable the following assertion, but we do things |
89 // like |RunLoop::current()->Quit()| in various places. | 83 // like |RunLoop::current()->Quit()| in various places. |
90 // assert(result_holder.is_set); | 84 // assert(result_holder.is_set); |
91 | 85 |
92 return result_holder.result; | 86 return result_holder.result; |
93 } | 87 } |
94 | 88 |
95 void TerminateMainApplication(MojoResult result) { | |
96 TerminateApplication(result); | |
97 } | |
98 | |
99 void TerminateApplication(MojoResult result) { | 89 void TerminateApplication(MojoResult result) { |
100 RunLoop::current()->Quit(); | 90 RunLoop::current()->Quit(); |
101 | 91 |
102 ResultHolder* result_holder = GetCurrentResultHolder(); | 92 ResultHolder* result_holder = GetCurrentResultHolder(); |
103 assert(result_holder); | 93 assert(result_holder); |
104 assert(!result_holder->is_set); | 94 assert(!result_holder->is_set); |
105 result_holder->result = result; | 95 result_holder->result = result; |
106 #ifndef NDEBUG | 96 #ifndef NDEBUG |
107 result_holder->is_set = true; | 97 result_holder->is_set = true; |
108 #endif | 98 #endif |
109 } | 99 } |
110 | 100 |
111 } // namespace mojo | 101 } // namespace mojo |
OLD | NEW |