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

Unified Diff: mojo/application/run_application.cc

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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/application/BUILD.gn ('k') | mojo/application/run_application_options_chromium.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/application/run_application.cc
diff --git a/mojo/application/run_application.cc b/mojo/application/run_application.cc
index d06feb9769fadea62ea43cf5f5c4ca5e5a915718..ea067d4ae42380c421120548feed8e63b301519c 100644
--- a/mojo/application/run_application.cc
+++ b/mojo/application/run_application.cc
@@ -9,8 +9,9 @@
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/debug/stack_trace.h"
+#include "base/lazy_instance.h"
#include "base/message_loop/message_loop.h"
-#include "base/threading/thread_local_storage.h"
+#include "base/threading/thread_local.h"
#include "build/build_config.h"
#include "mojo/application/run_application_options_chromium.h"
#include "mojo/message_pump/message_pump_mojo.h"
@@ -21,8 +22,6 @@ namespace mojo {
namespace {
-base::ThreadLocalStorage::StaticSlot g_current_result_holder = TLS_INITIALIZER;
-
// We store a pointer to a |ResultHolder|, which just stores a |MojoResult|, in
// TLS so that |TerminateApplication()| can provide the result that
// |RunApplication()| will return. (The |ResultHolder| is just on
@@ -36,30 +35,18 @@ struct ResultHolder {
MojoResult result = MOJO_RESULT_OK;
};
-} // namespace
-
-MojoResult RunMainApplication(MojoHandle application_request_handle,
- ApplicationImplBase* application_impl,
- const RunApplicationOptions* options) {
- base::CommandLine::Init(0, nullptr);
- base::AtExitManager at_exit;
-
- g_current_result_holder.Initialize(nullptr);
-
-#if !defined(NDEBUG) && !defined(OS_NACL)
- base::debug::EnableInProcessStackDumping();
-#endif
+base::LazyInstance<base::ThreadLocalPointer<ResultHolder>>::Leaky
+ g_current_result_holder = LAZY_INSTANCE_INITIALIZER;
- return RunApplication(application_request_handle, application_impl, options);
-}
+} // namespace
MojoResult RunApplication(MojoHandle application_request_handle,
ApplicationImplBase* application_impl,
const RunApplicationOptions* options) {
- DCHECK(!g_current_result_holder.Get());
+ DCHECK(!g_current_result_holder.Pointer()->Get());
ResultHolder result_holder;
- g_current_result_holder.Set(&result_holder);
+ g_current_result_holder.Pointer()->Set(&result_holder);
// Note: If |options| is non-null, it better point to a
// |RunApplicationOptionsChromium|.
@@ -76,7 +63,7 @@ MojoResult RunApplication(MojoHandle application_request_handle,
MakeScopedHandle(MessagePipeHandle(application_request_handle))));
loop->Run();
- g_current_result_holder.Set(nullptr);
+ g_current_result_holder.Pointer()->Set(nullptr);
// TODO(vtl): We'd like to enable the following assertion, but we quit the
// current message loop directly in various places.
@@ -85,16 +72,11 @@ MojoResult RunApplication(MojoHandle application_request_handle,
return result_holder.result;
}
-void TerminateMainApplication(MojoResult result) {
- TerminateApplication(result);
-}
-
void TerminateApplication(MojoResult result) {
DCHECK(base::MessageLoop::current()->is_running());
base::MessageLoop::current()->Quit();
- ResultHolder* result_holder =
- static_cast<ResultHolder*>(g_current_result_holder.Get());
+ ResultHolder* result_holder = g_current_result_holder.Pointer()->Get();
DCHECK(result_holder);
result_holder->result = result;
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
« no previous file with comments | « mojo/application/BUILD.gn ('k') | mojo/application/run_application_options_chromium.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698