Get rid of {Run,Terminate}MainApplication(), and more ApplicationDelegate conversion.
Why RunMainApplication() was a bad idea:
1. The intention is to allow the use of //base, which often requires
some initialization (e.g., having an AtExitManager).
2. But your ApplicationImplBase implementation would be created before
that initialization (so using //base in its constructor would be
dodgy).
3. And it would be destroyed after, e.g., the AtExitManager was torn
down (so using //base in its destructor -- or in the destructor of
any member variable of your ApplicationImplBase implementation -- is
potentially problematic).
So, instead just have a ScopedChromiumInit class, to make that stuff
explicit, and make the "scopes" not overlap.
Note that ApplicationRunnerChromium had a similar problem: Your
ApplicationDelegate implementation would be created before that
initialization (like 2.). However, the ApplicationImpl would destroy
your ApplicationDelegate implementation before tearing down the
AtExitManager, so it didn't have problem 3. (exactly). Nonetheless, it
was kind of horrible (since you couldn't really use //base in your
MojoMain()).
R=vardhan@google.com
Review URL: https://codereview.chromium.org/2011383002 .
diff --git a/examples/apptest/example_service_application.cc b/examples/apptest/example_service_application.cc
index 578bf59..ccdd6f3 100644
--- a/examples/apptest/example_service_application.cc
+++ b/examples/apptest/example_service_application.cc
@@ -29,6 +29,6 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::ExampleServiceApplication example_service_application;
- return mojo::RunMainApplication(application_request,
- &example_service_application);
+ return mojo::RunApplication(application_request,
+ &example_service_application);
}
diff --git a/examples/audio_play_test/play_tone.cc b/examples/audio_play_test/play_tone.cc
index ccbab46..2407fd9 100644
--- a/examples/audio_play_test/play_tone.cc
+++ b/examples/audio_play_test/play_tone.cc
@@ -243,5 +243,5 @@
MojoResult MojoMain(MojoHandle app_request) {
mojo::media::audio::examples::PlayToneApp play_tone_app;
- return mojo::RunMainApplication(app_request, &play_tone_app);
+ return mojo::RunApplication(app_request, &play_tone_app);
}
diff --git a/examples/audio_play_test/play_wav.cc b/examples/audio_play_test/play_wav.cc
index a05fe26..ee3dd32 100644
--- a/examples/audio_play_test/play_wav.cc
+++ b/examples/audio_play_test/play_wav.cc
@@ -557,5 +557,5 @@
MojoResult MojoMain(MojoHandle app_request) {
mojo::media::audio::examples::PlayWAVApp play_wav_app;
- return mojo::RunMainApplication(app_request, &play_wav_app);
+ return mojo::RunApplication(app_request, &play_wav_app);
}
diff --git a/examples/authentication_demo/google_authentication_demo.cc b/examples/authentication_demo/google_authentication_demo.cc
index 8b5bf06..3ddd52d 100644
--- a/examples/authentication_demo/google_authentication_demo.cc
+++ b/examples/authentication_demo/google_authentication_demo.cc
@@ -128,5 +128,5 @@
MojoResult MojoMain(MojoHandle application_request) {
examples::authentication::GoogleAuthApp google_auth_app;
- return mojo::RunMainApplication(application_request, &google_auth_app);
+ return mojo::RunApplication(application_request, &google_auth_app);
}
diff --git a/examples/bank_app/bank.cc b/examples/bank_app/bank.cc
index dec7814..dca5fc8 100644
--- a/examples/bank_app/bank.cc
+++ b/examples/bank_app/bank.cc
@@ -91,5 +91,5 @@
MojoResult MojoMain(MojoHandle application_request) {
examples::BankApp bank_app;
- return mojo::RunMainApplication(application_request, &bank_app);
+ return mojo::RunApplication(application_request, &bank_app);
}
diff --git a/examples/bank_app/customer.cc b/examples/bank_app/customer.cc
index 9d9790f..dfc67b8 100644
--- a/examples/bank_app/customer.cc
+++ b/examples/bank_app/customer.cc
@@ -54,5 +54,5 @@
MojoResult MojoMain(MojoHandle application_request) {
examples::BankCustomer bank_customer;
- return mojo::RunMainApplication(application_request, &bank_customer);
+ return mojo::RunApplication(application_request, &bank_customer);
}
diff --git a/examples/content_handler_demo/content_handler_demo.cc b/examples/content_handler_demo/content_handler_demo.cc
index fb322eb..fa1a8e9 100644
--- a/examples/content_handler_demo/content_handler_demo.cc
+++ b/examples/content_handler_demo/content_handler_demo.cc
@@ -114,5 +114,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::examples::ContentHandlerApp content_handler_app;
- return mojo::RunMainApplication(application_request, &content_handler_app);
+ return mojo::RunApplication(application_request, &content_handler_app);
}
diff --git a/examples/echo/echo_client.cc b/examples/echo/echo_client.cc
index beef9c1..0c3383d 100644
--- a/examples/echo/echo_client.cc
+++ b/examples/echo/echo_client.cc
@@ -38,5 +38,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::examples::EchoClientApp echo_client_app;
- return mojo::RunMainApplication(application_request, &echo_client_app);
+ return mojo::RunApplication(application_request, &echo_client_app);
}
diff --git a/examples/echo/echo_client_sync.cc b/examples/echo/echo_client_sync.cc
index 50e5215..64c649a 100644
--- a/examples/echo/echo_client_sync.cc
+++ b/examples/echo/echo_client_sync.cc
@@ -36,5 +36,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::examples::EchoClientApp echo_client_app;
- return mojo::RunMainApplication(application_request, &echo_client_app);
+ return mojo::RunApplication(application_request, &echo_client_app);
}
diff --git a/examples/echo/echo_server.cc b/examples/echo/echo_server.cc
index 093705c..e89e8bc 100644
--- a/examples/echo/echo_server.cc
+++ b/examples/echo/echo_server.cc
@@ -125,5 +125,5 @@
mojo::examples::MultiServer server_app;
// mojo::examples::SingletonServer server_app;
// mojo::examples::OneAtATimeServer server_app;
- return mojo::RunMainApplication(application_request, &server_app);
+ return mojo::RunApplication(application_request, &server_app);
}
diff --git a/examples/echo_terminal/main.cc b/examples/echo_terminal/main.cc
index 518be21..9e7af70 100644
--- a/examples/echo_terminal/main.cc
+++ b/examples/echo_terminal/main.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "mojo/common/binding_set.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -129,6 +130,7 @@
};
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
EchoTerminalApp echo_terminal_app;
- return mojo::RunMainApplication(application_request, &echo_terminal_app);
+ return mojo::RunApplication(application_request, &echo_terminal_app);
}
diff --git a/examples/hello_mojo/hello_mojo_client.cc b/examples/hello_mojo/hello_mojo_client.cc
index c0305a2..63851dd 100644
--- a/examples/hello_mojo/hello_mojo_client.cc
+++ b/examples/hello_mojo/hello_mojo_client.cc
@@ -47,5 +47,5 @@
MojoResult MojoMain(MojoHandle application_request) {
HelloMojoClientApp hello_mojo_client_app;
- return mojo::RunMainApplication(application_request, &hello_mojo_client_app);
+ return mojo::RunApplication(application_request, &hello_mojo_client_app);
}
diff --git a/examples/hello_mojo/hello_mojo_server.cc b/examples/hello_mojo/hello_mojo_server.cc
index 2cde005..0abb5fb 100644
--- a/examples/hello_mojo/hello_mojo_server.cc
+++ b/examples/hello_mojo/hello_mojo_server.cc
@@ -60,5 +60,5 @@
MojoResult MojoMain(MojoHandle application_request) {
HelloMojoServerApp hello_mojo_server_app;
- return mojo::RunMainApplication(application_request, &hello_mojo_server_app);
+ return mojo::RunApplication(application_request, &hello_mojo_server_app);
}
diff --git a/examples/http_handler/http_handler.cc b/examples/http_handler/http_handler.cc
index 95fe142..735ed54 100644
--- a/examples/http_handler/http_handler.cc
+++ b/examples/http_handler/http_handler.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/bind.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/connect.h"
@@ -75,6 +76,7 @@
} // namespace mojo
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
mojo::examples::HttpHandler http_handler;
- return mojo::RunMainApplication(application_request, &http_handler);
+ return mojo::RunApplication(application_request, &http_handler);
}
diff --git a/examples/indirect_service/indirect_integer_service.cc b/examples/indirect_service/indirect_integer_service.cc
index f8dc3c9..dbc354b 100644
--- a/examples/indirect_service/indirect_integer_service.cc
+++ b/examples/indirect_service/indirect_integer_service.cc
@@ -64,6 +64,6 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::examples::IndirectIntegerServiceApp indirect_integer_service_app;
- return mojo::RunMainApplication(application_request,
- &indirect_integer_service_app);
+ return mojo::RunApplication(application_request,
+ &indirect_integer_service_app);
}
diff --git a/examples/indirect_service/indirect_service_demo.cc b/examples/indirect_service/indirect_service_demo.cc
index 313b5c4..ad47701 100644
--- a/examples/indirect_service/indirect_service_demo.cc
+++ b/examples/indirect_service/indirect_service_demo.cc
@@ -9,6 +9,7 @@
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "examples/indirect_service/indirect_service_demo.mojom.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
@@ -139,7 +140,7 @@
tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end());
delete task; // Stop the DemoTask's thread etc.
if (tasks_.empty())
- TerminateMainApplication(MOJO_RESULT_OK);
+ TerminateApplication(MOJO_RESULT_OK);
}
IndirectIntegerServicePtr indirect_integer_service_;
@@ -150,7 +151,7 @@
} // namespace mojo
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
mojo::examples::IndirectServiceDemoApp indirect_service_demo_app;
- return mojo::RunMainApplication(application_request,
- &indirect_service_demo_app);
+ return mojo::RunApplication(application_request, &indirect_service_demo_app);
}
diff --git a/examples/indirect_service/integer_service.cc b/examples/indirect_service/integer_service.cc
index 0db7eaf..58ce1bf 100644
--- a/examples/indirect_service/integer_service.cc
+++ b/examples/indirect_service/integer_service.cc
@@ -44,6 +44,6 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::examples::IntegerServiceApp integer_service_app;
- return mojo::RunMainApplication(application_request, &integer_service_app);
+ return mojo::RunApplication(application_request, &integer_service_app);
}
diff --git a/examples/media_test/media_test_app.cc b/examples/media_test/media_test_app.cc
index 3ce8e8a..c05e526 100644
--- a/examples/media_test/media_test_app.cc
+++ b/examples/media_test/media_test_app.cc
@@ -10,6 +10,7 @@
#include "base/message_loop/message_loop.h"
#include "examples/media_test/keystroke.h"
#include "examples/media_test/media_test.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -313,6 +314,7 @@
} // namespace mojo
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
mojo::media::examples::MediaTestApp media_test_app;
- return mojo::RunMainApplication(application_request, &media_test_app);
+ return mojo::RunApplication(application_request, &media_test_app);
}
diff --git a/examples/native_run_app/native_run_app.cc b/examples/native_run_app/native_run_app.cc
index dc02ff0..9b0e554 100644
--- a/examples/native_run_app/native_run_app.cc
+++ b/examples/native_run_app/native_run_app.cc
@@ -23,6 +23,7 @@
#include "base/macros.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl_base.h"
@@ -252,6 +253,7 @@
};
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
NativeRunApp native_run_app;
- return mojo::RunMainApplication(application_request, &native_run_app);
+ return mojo::RunApplication(application_request, &native_run_app);
}
diff --git a/examples/notification_generator/notification_generator.cc b/examples/notification_generator/notification_generator.cc
index 9b173be..08ee9dc 100644
--- a/examples/notification_generator/notification_generator.cc
+++ b/examples/notification_generator/notification_generator.cc
@@ -8,6 +8,7 @@
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "mojo/common/binding_set.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/connect.h"
@@ -118,7 +119,7 @@
} // namespace examples
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
examples::NotificationGeneratorApp notification_generator_app;
- return mojo::RunMainApplication(application_request,
- ¬ification_generator_app);
+ return mojo::RunApplication(application_request, ¬ification_generator_app);
}
diff --git a/examples/spinning_cube/spinning_cube_app.cc b/examples/spinning_cube/spinning_cube_app.cc
index a1fc4a7..eac07b2 100644
--- a/examples/spinning_cube/spinning_cube_app.cc
+++ b/examples/spinning_cube/spinning_cube_app.cc
@@ -95,5 +95,5 @@
MojoResult MojoMain(MojoHandle application_request) {
examples::SpinningCubeApp spinning_cube_app;
- return mojo::RunMainApplication(application_request, &spinning_cube_app);
+ return mojo::RunApplication(application_request, &spinning_cube_app);
}
diff --git a/examples/wget/wget.cc b/examples/wget/wget.cc
index d333093..d8d6235 100644
--- a/examples/wget/wget.cc
+++ b/examples/wget/wget.cc
@@ -112,5 +112,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::examples::WGetApp wget_app;
- return mojo::RunMainApplication(application_request, &wget_app);
+ return mojo::RunApplication(application_request, &wget_app);
}
diff --git a/mojo/application/BUILD.gn b/mojo/application/BUILD.gn
index e8f7b21..3781c55 100644
--- a/mojo/application/BUILD.gn
+++ b/mojo/application/BUILD.gn
@@ -11,11 +11,11 @@
]
public_deps = [
+ "//mojo/environment:chromium",
"//mojo/public/cpp/application",
]
deps = [
"//base",
- "//mojo/environment:chromium",
"//mojo/message_pump",
"//mojo/public/cpp/system",
]
diff --git a/mojo/application/run_application.cc b/mojo/application/run_application.cc
index d06feb9..ea067d4 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 {
-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 @@
MojoResult result = MOJO_RESULT_OK;
};
+base::LazyInstance<base::ThreadLocalPointer<ResultHolder>>::Leaky
+ g_current_result_holder = LAZY_INSTANCE_INITIALIZER;
+
} // 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
-
- return RunApplication(application_request_handle, application_impl, options);
-}
-
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 @@
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 @@
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)
diff --git a/mojo/application/run_application_options_chromium.h b/mojo/application/run_application_options_chromium.h
index 54a5578..9084d41 100644
--- a/mojo/application/run_application_options_chromium.h
+++ b/mojo/application/run_application_options_chromium.h
@@ -10,8 +10,7 @@
namespace mojo {
-// Options for the "chromium" implementation of |RunMainApplication()| and
-// |RunApplication()|.
+// Options for the "chromium" implementation of |RunApplication()|.
class RunApplicationOptionsChromium : public RunApplicationOptions {
public:
explicit RunApplicationOptionsChromium(
diff --git a/mojo/environment/BUILD.gn b/mojo/environment/BUILD.gn
index 2bf0c58..dc21a24 100644
--- a/mojo/environment/BUILD.gn
+++ b/mojo/environment/BUILD.gn
@@ -9,6 +9,8 @@
"default_logger.cc",
"default_logger.h",
"environment.cc",
+ "scoped_chromium_init.cc",
+ "scoped_chromium_init.h",
# TODO(vtl): This is kind of ugly. (See TODO in logging.h.)
"../public/cpp/environment/async_waiter.h",
diff --git a/mojo/environment/scoped_chromium_init.cc b/mojo/environment/scoped_chromium_init.cc
new file mode 100644
index 0000000..9917d54
--- /dev/null
+++ b/mojo/environment/scoped_chromium_init.cc
@@ -0,0 +1,22 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/environment/scoped_chromium_init.h"
+
+#include "base/command_line.h"
+#include "base/debug/stack_trace.h"
+
+namespace mojo {
+
+ScopedChromiumInit::ScopedChromiumInit() {
+ base::CommandLine::Init(0, nullptr);
+
+#if !defined(NDEBUG) && !defined(OS_NACL)
+ base::debug::EnableInProcessStackDumping();
+#endif
+}
+
+ScopedChromiumInit::~ScopedChromiumInit() {}
+
+} // namespace mojo
diff --git a/mojo/environment/scoped_chromium_init.h b/mojo/environment/scoped_chromium_init.h
new file mode 100644
index 0000000..4908cb4
--- /dev/null
+++ b/mojo/environment/scoped_chromium_init.h
@@ -0,0 +1,42 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_ENVIRONMENT_SCOPED_CHROMIUM_INIT_H_
+#define MOJO_ENVIRONMENT_SCOPED_CHROMIUM_INIT_H_
+
+#include "base/at_exit.h"
+#include "base/macros.h"
+
+namespace mojo {
+
+// Using code from //base typically requires that a number of things be
+// initialized/present. In particular the global |base::CommandLine| singleton
+// should be initialized and an |AtExitManager| should be present.
+//
+// This class is a simple helper that does these things (and tears down the
+// |AtExitManager| on destruction). Typically, it should be used in |MojoMain()|
+// as follows:
+//
+// MojoResult MojoMain(MojoHandle application_request) {
+// mojo::ScopedBaseInit init;
+// ...
+// }
+//
+// TODO(vtl): Maybe this should be called |ScopedBaseInit|, but for now I'm
+// being consistent with everything else that refers to things that use //base
+// as "chromium".
+class ScopedChromiumInit {
+ public:
+ ScopedChromiumInit();
+ ~ScopedChromiumInit();
+
+ private:
+ base::AtExitManager at_exit_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedChromiumInit);
+};
+
+} // namespace mojo
+
+#endif // MOJO_ENVIRONMENT_SCOPED_CHROMIUM_INIT_H_
diff --git a/mojo/public/cpp/application/lib/run_application.cc b/mojo/public/cpp/application/lib/run_application.cc
index 570736a..4848b4e 100644
--- a/mojo/public/cpp/application/lib/run_application.cc
+++ b/mojo/public/cpp/application/lib/run_application.cc
@@ -60,12 +60,6 @@
} // namespace
-MojoResult RunMainApplication(MojoHandle application_request_handle,
- ApplicationImplBase* application_impl,
- const RunApplicationOptions* options) {
- return RunApplication(application_request_handle, application_impl, options);
-}
-
MojoResult RunApplication(MojoHandle application_request_handle,
ApplicationImplBase* application_impl,
const RunApplicationOptions* options) {
@@ -92,10 +86,6 @@
return result_holder.result;
}
-void TerminateMainApplication(MojoResult result) {
- TerminateApplication(result);
-}
-
void TerminateApplication(MojoResult result) {
RunLoop::current()->Quit();
diff --git a/mojo/public/cpp/application/run_application.h b/mojo/public/cpp/application/run_application.h
index d22de41..1c6008b 100644
--- a/mojo/public/cpp/application/run_application.h
+++ b/mojo/public/cpp/application/run_application.h
@@ -12,55 +12,46 @@
class ApplicationImplBase;
-// Base class for options to |RunMainApplication()| and |RunApplication()|. An
-// implementation of these functions may (but need not, in which case no options
-// are available) separately provide an implementation subclass, which would be
-// specific to that implementation. (The "standalone" implementation has no
-// options.)
+// Base class for options to |RunApplication()|. An implementation of these
+// functions may (but need not, in which case no options are available)
+// separately provide an implementation subclass, which would be specific to
+// that implementation. (The "standalone" implementation has no options.)
class RunApplicationOptions {
protected:
RunApplicationOptions() {}
~RunApplicationOptions() {}
};
-// |RunMainApplication()| and |RunApplication()| set up a message (run) loop and
-// run the provided application implementation. |RunMainApplication()| should be
-// used on the application's main thread (e.g., from |MojoMain()|) and may do
-// additional initialization. (In the case of the "standalone" implementation,
-// the two are equivalent.) The return value will be the one provided to
-// |TerminateMainApplication()| or |TerminateApplication()|, respectively.
+// |RunApplication()| sets up a message (run) loop and runs the provided
+// application implementation. The return value will be the one provided to
+// |TerminateApplication()|.
//
// Typical use (where |MyApplicationImpl| is an implementation of
// |ApplicationImplBase|):
//
// MojoResult MojoMain(MojoHandle application_request_handle) {
// MyApplicationImpl my_app;
-// return mojo::RunMainApplication(application_request_handle, &my_app);
+// return mojo::RunApplication(application_request_handle, &my_app);
// }
//
-// |RunApplication()| may be used on secondary threads (that are not already
-// running a message loop of some sort).
+// Note that |RunApplication()| may also be used on secondary threads (that are
+// not already running a message loop of some sort).
//
// |*application_impl| must remain alive until the message loop starts running
// (thus it may own itself). If |options| is non-null, then it must point to an
// instance of an implementation-specific subclass of |RunApplicationOptions|;
// |*options| must remain alive for the duration of the call.
-MojoResult RunMainApplication(MojoHandle application_request_handle,
- ApplicationImplBase* application_impl,
- const RunApplicationOptions* options = nullptr);
MojoResult RunApplication(MojoHandle application_request_handle,
ApplicationImplBase* application_impl,
const RunApplicationOptions* options = nullptr);
-// |TerminateMainApplication()| and |TerminateApplication()| terminate the
-// application that is running on the current thread. They may only be called
-// from "inside" |RunMainApplication()| and |RunApplication()| respectively
-// (i.e., |Run[Main]Application()| is on the stack, which means that the message
-// loop is running). They will cause |Run[Main]Application()| to return "soon"
-// (assuming the message loop is not blocked processing some task), with return
-// value |result|. They may cause queued work to *not* be executed. They should
-// be executed at most once (per |Run[Main]Application()|).
-void TerminateMainApplication(MojoResult result);
+// |TerminateApplication()| terminates the application that is running on the
+// current thread. It may only be called from "inside" |RunApplication()| (i.e.,
+// with |RunApplication()| on the stack, which means that the message loop is
+// running). It causes |RunApplication()| to return "soon" (assuming the message
+// loop is not blocked processing some task), with return value |result|. It may
+// cause queued work to *not* be executed. It should be executed at most once
+// (per |RunApplication()|).
void TerminateApplication(MojoResult result);
} // namespace mojo
diff --git a/mojo/public/cpp/bindings/tests/versioning_test_service.cc b/mojo/public/cpp/bindings/tests/versioning_test_service.cc
index b7298fe..7c59787 100644
--- a/mojo/public/cpp/bindings/tests/versioning_test_service.cc
+++ b/mojo/public/cpp/bindings/tests/versioning_test_service.cc
@@ -121,5 +121,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::test::versioning::HumanResourceSystemServer hr_system_server;
- return mojo::RunMainApplication(application_request, &hr_system_server);
+ return mojo::RunApplication(application_request, &hr_system_server);
}
diff --git a/mojo/services/log/cpp/log_client.h b/mojo/services/log/cpp/log_client.h
index 2f99013..4c10c5c 100644
--- a/mojo/services/log/cpp/log_client.h
+++ b/mojo/services/log/cpp/log_client.h
@@ -25,7 +25,7 @@
//
// MojoResult MojoMain(MojoHandle app_request) {
// MyApp app;
-// return mojo::RunMainApplication(&app);
+// return mojo::RunApplication(&app);
// }
#ifndef MOJO_SERVICES_LOG_CPP_LOG_CLIENT_H_
diff --git a/services/asset_bundle/main.cc b/services/asset_bundle/main.cc
index d6c8d63..7ea64f8 100644
--- a/services/asset_bundle/main.cc
+++ b/services/asset_bundle/main.cc
@@ -4,6 +4,7 @@
#include "base/macros.h"
#include "base/threading/sequenced_worker_pool.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -25,8 +26,9 @@
[this](const ConnectionContext& connection_context,
InterfaceRequest<AssetUnpacker> asset_unpacker_request) {
// Lazily initialize |sequenced_worker_pool_|. (We can't create it in
- // the constructor, since AtExitManager is only created in
- // mojo::RunMainApplication().)
+ // the constructor, since the message loop (which implies that there's
+ // a current SingleThreadTaskRunner) is only created in
+ // mojo::RunApplication().)
if (!sequenced_worker_pool_) {
// TODO(vtl): What's the "right" way to choose the maximum number of
// threads?
@@ -53,6 +55,7 @@
} // namespace mojo
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
mojo::asset_bundle::AssetBundleApp asset_bundle_app;
- return mojo::RunMainApplication(application_request, &asset_bundle_app);
+ return mojo::RunApplication(application_request, &asset_bundle_app);
}
diff --git a/services/authenticating_url_loader_interceptor/main.cc b/services/authenticating_url_loader_interceptor/main.cc
index ff9548e..6a13516 100644
--- a/services/authenticating_url_loader_interceptor/main.cc
+++ b/services/authenticating_url_loader_interceptor/main.cc
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/run_application.h"
#include "services/authenticating_url_loader_interceptor/authenticating_url_loader_interceptor_app.h"
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
mojo::AuthenticatingURLLoaderInterceptorApp app;
- return mojo::RunMainApplication(application_request, &app);
+ return mojo::RunApplication(application_request, &app);
}
diff --git a/services/authentication/main.cc b/services/authentication/main.cc
index 331d306..f8763e2 100644
--- a/services/authentication/main.cc
+++ b/services/authentication/main.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "mojo/common/binding_set.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/connect.h"
@@ -56,7 +57,7 @@
} // namespace authentication
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
authentication::GoogleAccountManagerApp google_account_manager_app;
- return mojo::RunMainApplication(application_request,
- &google_account_manager_app);
+ return mojo::RunApplication(application_request, &google_account_manager_app);
}
diff --git a/services/clipboard/main.cc b/services/clipboard/main.cc
index 80bab3c..8e6fc15 100644
--- a/services/clipboard/main.cc
+++ b/services/clipboard/main.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -32,6 +33,7 @@
} // namespace
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
ClipboardApp clipboard_app;
- return mojo::RunMainApplication(application_request, &clipboard_app);
+ return mojo::RunApplication(application_request, &clipboard_app);
}
diff --git a/services/device_info/device_info.cc b/services/device_info/device_info.cc
index 76d4def..855f774 100644
--- a/services/device_info/device_info.cc
+++ b/services/device_info/device_info.cc
@@ -46,5 +46,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::services::device_info::DeviceInfoApp device_info_app;
- return mojo::RunMainApplication(application_request, &device_info_app);
+ return mojo::RunApplication(application_request, &device_info_app);
}
diff --git a/services/files/main.cc b/services/files/main.cc
index 500cd9e..9edd5b2 100644
--- a/services/files/main.cc
+++ b/services/files/main.cc
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/run_application.h"
#include "services/files/files_app.h"
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
mojo::files::FilesApp files_app;
- return mojo::RunMainApplication(application_request, &files_app);
+ return mojo::RunApplication(application_request, &files_app);
}
diff --git a/services/http_server/http_server_app.cc b/services/http_server/http_server_app.cc
index 315e2c0..c6d6b3c 100644
--- a/services/http_server/http_server_app.cc
+++ b/services/http_server/http_server_app.cc
@@ -41,5 +41,5 @@
MojoResult MojoMain(MojoHandle application_request) {
http_server::HttpServerApp http_server_app;
- return mojo::RunMainApplication(application_request, &http_server_app);
+ return mojo::RunApplication(application_request, &http_server_app);
}
diff --git a/services/icu_data/main.cc b/services/icu_data/main.cc
index 880a180..0c409b0 100644
--- a/services/icu_data/main.cc
+++ b/services/icu_data/main.cc
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/run_application.h"
#include "services/icu_data/icu_data_impl.h"
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
icu_data::ICUDataImpl icu_data_impl;
- return mojo::RunMainApplication(application_request, &icu_data_impl);
+ return mojo::RunApplication(application_request, &icu_data_impl);
}
diff --git a/services/js/content_handler_main.cc b/services/js/content_handler_main.cc
index 79eb6c5..dfd1610 100644
--- a/services/js/content_handler_main.cc
+++ b/services/js/content_handler_main.cc
@@ -6,6 +6,7 @@
#include "gin/array_buffer.h"
#include "gin/public/isolate_holder.h"
#include "mojo/application/content_handler_factory.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -51,6 +52,7 @@
} // namespace js
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
js::JsContentHandler js_content_handler;
- return mojo::RunMainApplication(application_request, &js_content_handler);
+ return mojo::RunApplication(application_request, &js_content_handler);
}
diff --git a/services/keyboard/linux/main.cc b/services/keyboard/linux/main.cc
index 4784487..3b30a6f 100644
--- a/services/keyboard/linux/main.cc
+++ b/services/keyboard/linux/main.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/macros.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -56,6 +57,7 @@
} // namespace keyboard
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
keyboard::KeyboardServiceApp keyboard_service_app;
- return mojo::RunMainApplication(application_request, &keyboard_service_app);
+ return mojo::RunApplication(application_request, &keyboard_service_app);
}
diff --git a/services/log/main.cc b/services/log/main.cc
index 9ea6dba..a6da07d 100644
--- a/services/log/main.cc
+++ b/services/log/main.cc
@@ -6,6 +6,7 @@
#include <utility>
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -45,6 +46,7 @@
} // namespace mojo
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
mojo::log::LogApp log_app;
- return mojo::RunMainApplication(application_request, &log_app);
+ return mojo::RunApplication(application_request, &log_app);
}
diff --git a/services/media/audio/audio_server_app.cc b/services/media/audio/audio_server_app.cc
index 0da6188..2f25fdd 100644
--- a/services/media/audio/audio_server_app.cc
+++ b/services/media/audio/audio_server_app.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/logging.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/run_application.h"
#include "mojo/public/cpp/application/service_provider_impl.h"
@@ -33,6 +34,7 @@
} // namespace mojo
MojoResult MojoMain(MojoHandle app_request) {
+ mojo::ScopedChromiumInit init;
mojo::media::audio::AudioServerApp audio_server_app;
- return mojo::RunMainApplication(app_request, &audio_server_app);
+ return mojo::RunApplication(app_request, &audio_server_app);
}
diff --git a/services/nacl/nonsfi/content_handler_main_nexe.cc b/services/nacl/nonsfi/content_handler_main_nexe.cc
index 9701bbd..07e2c9a 100644
--- a/services/nacl/nonsfi/content_handler_main_nexe.cc
+++ b/services/nacl/nonsfi/content_handler_main_nexe.cc
@@ -8,6 +8,7 @@
#include "base/message_loop/message_loop.h"
#include "mojo/application/content_handler_factory.h"
#include "mojo/data_pipe_utils/data_pipe_utils.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h"
#include "mojo/public/c/system/main.h"
@@ -61,6 +62,7 @@
} // namespace nacl
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
nacl::content_handler::NaClContentHandler nacl_content_handler;
- return mojo::RunMainApplication(application_request, &nacl_content_handler);
+ return mojo::RunApplication(application_request, &nacl_content_handler);
}
diff --git a/services/nacl/nonsfi/content_handler_main_pexe.cc b/services/nacl/nonsfi/content_handler_main_pexe.cc
index b9e6f2b..0478eb8 100644
--- a/services/nacl/nonsfi/content_handler_main_pexe.cc
+++ b/services/nacl/nonsfi/content_handler_main_pexe.cc
@@ -10,6 +10,7 @@
#include "base/strings/string_number_conversions.h"
#include "mojo/application/content_handler_factory.h"
#include "mojo/data_pipe_utils/data_pipe_utils.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/file_utils/file_util.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/nacl/nonsfi/file_util.h"
@@ -162,6 +163,7 @@
} // namespace nacl
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
nacl::content_handler::PexeContentHandler pexe_content_handler;
- return mojo::RunMainApplication(application_request, &pexe_content_handler);
+ return mojo::RunApplication(application_request, &pexe_content_handler);
}
diff --git a/services/nacl/nonsfi/pnacl_compile.cc b/services/nacl/nonsfi/pnacl_compile.cc
index d8bcf75..963cf39 100644
--- a/services/nacl/nonsfi/pnacl_compile.cc
+++ b/services/nacl/nonsfi/pnacl_compile.cc
@@ -59,5 +59,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::nacl::MultiPexeCompiler multi_pexe_compiler;
- return mojo::RunMainApplication(application_request, &multi_pexe_compiler);
+ return mojo::RunApplication(application_request, &multi_pexe_compiler);
}
diff --git a/services/nacl/nonsfi/pnacl_link.cc b/services/nacl/nonsfi/pnacl_link.cc
index 9a2ef24..373f66b 100644
--- a/services/nacl/nonsfi/pnacl_link.cc
+++ b/services/nacl/nonsfi/pnacl_link.cc
@@ -56,5 +56,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::nacl::MultiPexeLinker multi_pexe_linker;
- return mojo::RunMainApplication(application_request, &multi_pexe_linker);
+ return mojo::RunApplication(application_request, &multi_pexe_linker);
}
diff --git a/services/nacl/sfi/content_handler_main.cc b/services/nacl/sfi/content_handler_main.cc
index 35a6fb1..405cf7a 100644
--- a/services/nacl/sfi/content_handler_main.cc
+++ b/services/nacl/sfi/content_handler_main.cc
@@ -8,6 +8,7 @@
#include "build/build_config.h"
#include "mojo/application/content_handler_factory.h"
#include "mojo/data_pipe_utils/data_pipe_utils.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/nacl/sfi/nacl_bindings/monacl_sel_main.h"
#include "mojo/public/c/system/main.h"
@@ -150,6 +151,7 @@
} // namespace nacl
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
nacl::content_handler::NaClContentHandler nacl_content_handler;
- return mojo::RunMainApplication(application_request, &nacl_content_handler);
+ return mojo::RunApplication(application_request, &nacl_content_handler);
}
diff --git a/services/native_support/main.cc b/services/native_support/main.cc
index e174a31..f2deec6 100644
--- a/services/native_support/main.cc
+++ b/services/native_support/main.cc
@@ -7,6 +7,7 @@
#include "base/message_loop/message_loop.h"
#include "base/threading/sequenced_worker_pool.h"
#include "mojo/application/run_application_options_chromium.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -23,9 +24,8 @@
public:
NativeSupportApp() {}
~NativeSupportApp() override {
- // TODO(vtl): Doing this here is a bit of a hack, but we may not
- // consistently call |OnQuit()|.
- OnQuit();
+ if (worker_pool_)
+ worker_pool_->Shutdown();
}
private:
@@ -44,13 +44,6 @@
return true;
}
- void OnQuit() override {
- if (worker_pool_) {
- worker_pool_->Shutdown();
- worker_pool_ = nullptr;
- }
- }
-
scoped_refptr<base::SequencedWorkerPool> worker_pool_;
DISALLOW_COPY_AND_ASSIGN(NativeSupportApp);
@@ -59,9 +52,10 @@
} // namespace native_support
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
native_support::NativeSupportApp native_support_app;
// We need an I/O message loop, since we'll want to watch FDs.
mojo::RunApplicationOptionsChromium options(base::MessageLoop::TYPE_IO);
- return mojo::RunMainApplication(application_request, &native_support_app,
- &options);
+ return mojo::RunApplication(application_request, &native_support_app,
+ &options);
}
diff --git a/services/native_viewport/BUILD.gn b/services/native_viewport/BUILD.gn
index 360b650..d0fe7f5 100644
--- a/services/native_viewport/BUILD.gn
+++ b/services/native_viewport/BUILD.gn
@@ -12,9 +12,9 @@
group("native_viewport") {
deps = [
+ ":jni_headers",
":lib",
":native_viewport_java",
- ":jni_headers",
]
}
@@ -24,10 +24,10 @@
deps = [
"//base:base_java",
- "//services/keyboard",
- "//mojo/services/keyboard/interfaces:interfaces_java",
"//mojo/public/java:bindings",
"//mojo/public/java:system",
+ "//mojo/services/keyboard/interfaces:interfaces_java",
+ "//services/keyboard",
]
}
@@ -48,7 +48,6 @@
mojo_native_application("native_viewport") {
output_name = "native_viewport_service"
sources = [
- "app_delegate.cc",
"main.cc",
]
deps = [
@@ -58,8 +57,8 @@
"//mojo/application",
"//mojo/common:tracing_impl",
"//mojo/public/cpp/bindings:bindings",
- "//mojo/services/native_viewport/interfaces",
"//mojo/services/native_viewport/cpp:args",
+ "//mojo/services/native_viewport/interfaces",
"//services/gles2",
"//ui/events",
"//ui/events/platform",
@@ -67,13 +66,21 @@
]
if (use_ozone) {
- sources += [ "ozone/app_delegate_ozone.cc" ]
+ sources += [
+ "ozone/native_viewport_app_ozone.cc",
+ "ozone/native_viewport_app_ozone.h",
+ ]
deps += [
"//mojo/services/ozone_drm_gpu/interfaces",
"//mojo/services/ozone_drm_host/interfaces",
"//ui/events/ozone:events_ozone_evdev",
"//ui/ozone",
]
+ } else {
+ sources += [
+ "native_viewport_app.cc",
+ "native_viewport_app.h",
+ ]
}
}
}
@@ -106,16 +113,16 @@
"//mojo/converters/input_events",
"//mojo/converters/native_viewport",
"//mojo/environment:chromium",
- "//services/gles2",
"//mojo/services/geometry/interfaces",
"//mojo/services/native_viewport/interfaces",
+ "//services/gles2",
+ "//ui/display/types",
"//ui/events",
"//ui/events/platform",
"//ui/gfx",
"//ui/gfx/geometry",
"//ui/gl",
"//ui/platform_window",
- "//ui/display/types",
]
if (is_android) {
diff --git a/services/native_viewport/app_delegate.h b/services/native_viewport/app_delegate.h
deleted file mode 100644
index 4c4390c..0000000
--- a/services/native_viewport/app_delegate.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SERVICES_NATIVE_VIEWPORT_APP_DELEGATE_H_
-#define SERVICES_NATIVE_VIEWPORT_APP_DELEGATE_H_
-
-#include <algorithm>
-
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/common/tracing_impl.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/services/native_viewport/cpp/args.h"
-#include "services/gles2/gpu_impl.h"
-#include "services/native_viewport/native_viewport_impl.h"
-#include "ui/events/event_switches.h"
-#include "ui/gl/gl_surface.h"
-
-namespace native_viewport {
-
-class NativeViewportAppDelegate : public mojo::ApplicationDelegate {
- public:
- NativeViewportAppDelegate();
- ~NativeViewportAppDelegate() override;
-
- // mojo::ApplicationDelegate implementation.
- void Initialize(mojo::ApplicationImpl* application) override;
-
- bool ConfigureIncomingConnection(
- mojo::ServiceProviderImpl* service_provider_impl) override;
-
- private:
- void InitLogging(mojo::ApplicationImpl* application);
-
- mojo::ApplicationImpl* application_;
- scoped_refptr<gles2::GpuState> gpu_state_;
- bool is_headless_;
- mojo::TracingImpl tracing_;
-
- DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate);
-};
-
-} // namespace native_viewport
-
-#endif
diff --git a/services/native_viewport/main.cc b/services/native_viewport/main.cc
index cff828b..76959f8 100644
--- a/services/native_viewport/main.cc
+++ b/services/native_viewport/main.cc
@@ -2,20 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "mojo/application/run_application_options_chromium.h"
+#include "mojo/environment/scoped_chromium_init.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/run_application.h"
+
#if defined(USE_OZONE)
-#include "services/native_viewport/ozone/app_delegate_ozone.h"
+#include "services/native_viewport/ozone/native_viewport_app_ozone.h"
#else
-#include "services/native_viewport/app_delegate.h"
+#include "services/native_viewport/native_viewport_app.h"
#endif
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
#if defined(USE_OZONE)
- mojo::ApplicationRunnerChromium runner(
- new native_viewport::NativeViewportOzoneAppDelegate);
+ native_viewport::NativeViewportAppOzone native_viewport_app;
#else
- mojo::ApplicationRunnerChromium runner(
- new native_viewport::NativeViewportAppDelegate);
+ native_viewport::NativeViewportApp native_viewport_app;
#endif
- runner.set_message_loop_type(base::MessageLoop::TYPE_UI);
- return runner.Run(application_request);
+ mojo::RunApplicationOptionsChromium options(base::MessageLoop::TYPE_UI);
+ return mojo::RunApplication(application_request, &native_viewport_app,
+ &options);
}
diff --git a/services/native_viewport/app_delegate.cc b/services/native_viewport/native_viewport_app.cc
similarity index 60%
rename from services/native_viewport/app_delegate.cc
rename to services/native_viewport/native_viewport_app.cc
index e0aeda1..242ed48 100644
--- a/services/native_viewport/app_delegate.cc
+++ b/services/native_viewport/native_viewport_app.cc
@@ -2,71 +2,57 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "services/native_viewport/app_delegate.h"
+#include "services/native_viewport/native_viewport_app.h"
#include <vector>
#include "gpu/config/gpu_util.h"
+#include "mojo/public/cpp/application/service_provider_impl.h"
+#include "mojo/services/native_viewport/cpp/args.h"
+#include "services/gles2/gpu_impl.h"
+#include "services/native_viewport/native_viewport_impl.h"
+#include "ui/events/event_switches.h"
+#include "ui/gl/gl_surface.h"
namespace native_viewport {
-NativeViewportAppDelegate::NativeViewportAppDelegate() : is_headless_(false) {}
+NativeViewportApp::NativeViewportApp() : is_headless_(false) {}
-NativeViewportAppDelegate::~NativeViewportAppDelegate() {}
+NativeViewportApp::~NativeViewportApp() {}
-void NativeViewportAppDelegate::InitLogging(
- mojo::ApplicationImpl* application) {
- std::vector<const char*> args;
- for (auto& a : application->args()) {
- args.push_back(a.c_str());
- }
-
- base::CommandLine::Reset();
- base::CommandLine::Init(args.size(), args.data());
-
- logging::LoggingSettings settings;
- settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
- logging::InitLogging(settings);
-}
-
-void NativeViewportAppDelegate::Initialize(mojo::ApplicationImpl* application) {
- application_ = application;
-
- InitLogging(application);
- tracing_.Initialize(application->shell(), &application->args());
+void NativeViewportApp::OnInitialize() {
+ InitLogging();
+ tracing_.Initialize(shell(), &args());
// Apply the switch for kTouchEvents to CommandLine (if set). This allows
// redirecting the mouse to a touch device on X for testing.
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
const std::string touch_event_string("--" +
std::string(switches::kTouchDevices));
- auto touch_iter = std::find(application->args().begin(),
- application->args().end(), touch_event_string);
- if (touch_iter != application->args().end() &&
- ++touch_iter != application->args().end()) {
+ auto touch_iter = std::find(args().begin(), args().end(), touch_event_string);
+ if (touch_iter != args().end() && ++touch_iter != args().end())
command_line->AppendSwitchASCII(touch_event_string, *touch_iter);
- }
gpu::ApplyGpuDriverBugWorkarounds(command_line);
- if (application->HasArg(mojo::kUseTestConfig))
+ if (HasArg(mojo::kUseTestConfig))
gfx::GLSurface::InitializeOneOffForTests();
- else if (application->HasArg(mojo::kUseOSMesa))
+ else if (HasArg(mojo::kUseOSMesa))
gfx::GLSurface::InitializeOneOff(gfx::kGLImplementationOSMesaGL);
else
gfx::GLSurface::InitializeOneOff();
- is_headless_ = application->HasArg(mojo::kUseHeadlessConfig);
+ is_headless_ = HasArg(mojo::kUseHeadlessConfig);
}
-bool NativeViewportAppDelegate::ConfigureIncomingConnection(
+bool NativeViewportApp::OnAcceptConnection(
mojo::ServiceProviderImpl* service_provider_impl) {
service_provider_impl->AddService<mojo::NativeViewport>([this](
const mojo::ConnectionContext& connection_context,
mojo::InterfaceRequest<mojo::NativeViewport> native_viewport_request) {
if (!gpu_state_.get())
gpu_state_ = new gles2::GpuState();
- new NativeViewportImpl(application_->shell(), is_headless_, gpu_state_,
+ new NativeViewportImpl(shell(), is_headless_, gpu_state_,
native_viewport_request.Pass());
});
@@ -81,4 +67,17 @@
return true;
}
+void NativeViewportApp::InitLogging() {
+ std::vector<const char*> argv;
+ for (const auto& a : args())
+ argv.push_back(a.c_str());
+
+ base::CommandLine::Reset();
+ base::CommandLine::Init(argv.size(), argv.data());
+
+ logging::LoggingSettings settings;
+ settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+ logging::InitLogging(settings);
+}
+
} // namespace native_viewport
diff --git a/services/native_viewport/native_viewport_app.h b/services/native_viewport/native_viewport_app.h
new file mode 100644
index 0000000..da8c743
--- /dev/null
+++ b/services/native_viewport/native_viewport_app.h
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SERVICES_NATIVE_VIEWPORT_APP_H_
+#define SERVICES_NATIVE_VIEWPORT_APP_H_
+
+#include "base/macros.h"
+#include "mojo/common/tracing_impl.h"
+#include "mojo/public/cpp/application/application_impl_base.h"
+#include "services/gles2/gpu_state.h"
+
+namespace native_viewport {
+
+class NativeViewportApp : public mojo::ApplicationImplBase {
+ public:
+ NativeViewportApp();
+ ~NativeViewportApp() override;
+
+ // mojo::ApplicationImplBase overrides.
+ void OnInitialize() override;
+ bool OnAcceptConnection(
+ mojo::ServiceProviderImpl* service_provider_impl) override;
+
+ private:
+ void InitLogging();
+
+ scoped_refptr<gles2::GpuState> gpu_state_;
+ bool is_headless_;
+ mojo::TracingImpl tracing_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeViewportApp);
+};
+
+} // namespace native_viewport
+
+#endif // SERVICES_NATIVE_VIEWPORT_APP_H_
diff --git a/services/native_viewport/ozone/app_delegate_ozone.cc b/services/native_viewport/ozone/app_delegate_ozone.cc
deleted file mode 100644
index 22d964f..0000000
--- a/services/native_viewport/ozone/app_delegate_ozone.cc
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "services/native_viewport/ozone/app_delegate_ozone.h"
-#include "ui/ozone/public/ipc_init_helper_mojo.h"
-#include "ui/ozone/public/ozone_platform.h"
-
-namespace native_viewport {
-
-void NativeViewportOzoneAppDelegate::Initialize(
- mojo::ApplicationImpl* application) {
- NativeViewportAppDelegate::Initialize(application);
-
- ui::OzonePlatform::InitializeForUI();
-
- auto ipc_init_helper = static_cast<ui::IpcInitHelperMojo*>(
- ui::OzonePlatform::GetInstance()->GetIpcInitHelperOzone());
-
- ipc_init_helper->HostInitialize(application);
- ipc_init_helper->GpuInitialize(application);
-
- display_manager_.reset(new DisplayManager());
-}
-
-bool NativeViewportOzoneAppDelegate::ConfigureIncomingConnection(
- ServiceProviderImpl* service_provider_impl) {
- if (!NativeViewportAppDelegate::ConfigureIncomingConnection(
- service_provider_impl))
- return false;
-
- auto ipc_init_helper = static_cast<ui::IpcInitHelperMojo*>(
- ui::OzonePlatform::GetInstance()->GetIpcInitHelperOzone());
-
- ipc_init_helper->HostConfigureIncomingConnection(connection);
- ipc_init_helper->GpuConfigureIncomingConnection(connection);
-
- return true;
-}
-
-} // namespace native_viewport
diff --git a/services/native_viewport/ozone/app_delegate_ozone.h b/services/native_viewport/ozone/app_delegate_ozone.h
deleted file mode 100644
index c500206..0000000
--- a/services/native_viewport/ozone/app_delegate_ozone.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SERVICES_NATIVE_VIEWPORT_APP_DELEGATE_OZONE_H_
-#define SERVICES_NATIVE_VIEWPORT_APP_DELEGATE_OZONE_H_
-
-#include "services/native_viewport/app_delegate.h"
-#include "services/native_viewport/ozone/display_manager.h"
-
-namespace native_viewport {
-
-class NativeViewportOzoneAppDelegate : public NativeViewportAppDelegate {
- public:
- using NativeViewportAppDelegate::Create;
-
- void Initialize(mojo::ApplicationImpl* application) override;
- bool ConfigureIncomingConnection(
- mojo::ServiceProviderImpl* service_provider_impl) override;
-
- private:
- std::unique_ptr<DisplayManager> display_manager_;
-};
-
-} // namespace native_viewport
-
-#endif
diff --git a/services/native_viewport/ozone/native_viewport_app_ozone.cc b/services/native_viewport/ozone/native_viewport_app_ozone.cc
new file mode 100644
index 0000000..d24b6e5
--- /dev/null
+++ b/services/native_viewport/ozone/native_viewport_app_ozone.cc
@@ -0,0 +1,39 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/native_viewport/ozone/native_viewport_app_ozone.h"
+#include "ui/ozone/public/ipc_init_helper_mojo.h"
+#include "ui/ozone/public/ozone_platform.h"
+
+namespace native_viewport {
+
+void NativeViewportAppOzone::OnInitialize() {
+ NativeViewportApp::OnInitialize();
+
+ ui::OzonePlatform::InitializeForUI();
+
+ auto ipc_init_helper = static_cast<ui::IpcInitHelperMojo*>(
+ ui::OzonePlatform::GetInstance()->GetIpcInitHelperOzone());
+
+ ipc_init_helper->HostInitialize(shell());
+ ipc_init_helper->GpuInitialize(shell());
+
+ display_manager_.reset(new DisplayManager());
+}
+
+bool NativeViewportAppOzone::OnAcceptConnection(
+ ServiceProviderImpl* service_provider_impl) {
+ if (!NativeViewportApp::OnAcceptConnection(service_provider_impl))
+ return false;
+
+ auto ipc_init_helper = static_cast<ui::IpcInitHelperMojo*>(
+ ui::OzonePlatform::GetInstance()->GetIpcInitHelperOzone());
+
+ ipc_init_helper->HostAcceptConnection(service_provider_impl);
+ ipc_init_helper->GpuAcceptConnection(service_provider_impl);
+
+ return true;
+}
+
+} // namespace native_viewport
diff --git a/services/native_viewport/ozone/native_viewport_app_ozone.h b/services/native_viewport/ozone/native_viewport_app_ozone.h
new file mode 100644
index 0000000..3d87fce
--- /dev/null
+++ b/services/native_viewport/ozone/native_viewport_app_ozone.h
@@ -0,0 +1,27 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SERVICES_NATIVE_VIEWPORT_OZONE_NATIVE_VIEWPORT_APP_OZONE_H_
+#define SERVICES_NATIVE_VIEWPORT_OZONE_NATIVE_VIEWPORT_APP_OZONE_H_
+
+#include "services/native_viewport/native_viewport_app.h"
+#include "services/native_viewport/ozone/display_manager.h"
+
+namespace native_viewport {
+
+class NativeViewportAppOzone : public NativeViewportApp {
+ public:
+ using NativeViewportApp::Create;
+
+ void OnInitialize() override;
+ bool OnAcceptConnection(
+ mojo::ServiceProviderImpl* service_provider_impl) override;
+
+ private:
+ std::unique_ptr<DisplayManager> display_manager_;
+};
+
+} // namespace native_viewport
+
+#endif // SERVICES_NATIVE_VIEWPORT_OZONE_NATIVE_VIEWPORT_APP_OZONE_H_
diff --git a/services/prediction/prediction_service_impl.cc b/services/prediction/prediction_service_impl.cc
index ce26d6e..5e2467c 100644
--- a/services/prediction/prediction_service_impl.cc
+++ b/services/prediction/prediction_service_impl.cc
@@ -4,6 +4,7 @@
#include "services/prediction/prediction_service_impl.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -52,6 +53,7 @@
} // namespace prediction
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
prediction::PredictionServiceApp prediction_service_app;
- return mojo::RunMainApplication(application_request, &prediction_service_app);
+ return mojo::RunApplication(application_request, &prediction_service_app);
}
diff --git a/services/python/content_handler/content_handler_main.cc b/services/python/content_handler/content_handler_main.cc
index 3695889..d7d6ea3 100644
--- a/services/python/content_handler/content_handler_main.cc
+++ b/services/python/content_handler/content_handler_main.cc
@@ -12,6 +12,7 @@
#include "base/strings/stringprintf.h"
#include "mojo/application/content_handler_factory.h"
#include "mojo/data_pipe_utils/data_pipe_utils.h"
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/application/run_application.h"
@@ -242,8 +243,8 @@
} // namespace services
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
services::python::content_handler::PythonContentHandlerApp
python_content_handler_app;
- return mojo::RunMainApplication(application_request,
- &python_content_handler_app);
+ return mojo::RunApplication(application_request, &python_content_handler_app);
}
diff --git a/services/test_service/test_request_tracker_application.cc b/services/test_service/test_request_tracker_application.cc
index 856142f..9a0f612 100644
--- a/services/test_service/test_request_tracker_application.cc
+++ b/services/test_service/test_request_tracker_application.cc
@@ -43,5 +43,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::test::TestRequestTrackerApplication app;
- return mojo::RunMainApplication(application_request, &app);
+ return mojo::RunApplication(application_request, &app);
}
diff --git a/services/test_service/test_service_application.cc b/services/test_service/test_service_application.cc
index 5e623b6..af116a3 100644
--- a/services/test_service/test_service_application.cc
+++ b/services/test_service/test_service_application.cc
@@ -52,5 +52,5 @@
MojoResult MojoMain(MojoHandle application_request) {
mojo::test::TestServiceApplication app;
- return mojo::RunMainApplication(application_request, &app);
+ return mojo::RunApplication(application_request, &app);
}
diff --git a/services/tracing/main.cc b/services/tracing/main.cc
index 2c9ca06..96ee48c 100644
--- a/services/tracing/main.cc
+++ b/services/tracing/main.cc
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "mojo/environment/scoped_chromium_init.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/run_application.h"
#include "services/tracing/tracing_app.h"
MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ScopedChromiumInit init;
tracing::TracingApp tracing_app;
- return mojo::RunMainApplication(application_request, &tracing_app);
+ return mojo::RunApplication(application_request, &tracing_app);
}
diff --git a/shell/test/pingable_app.cc b/shell/test/pingable_app.cc
index 6f4481c..0337e74 100644
--- a/shell/test/pingable_app.cc
+++ b/shell/test/pingable_app.cc
@@ -57,5 +57,5 @@
MojoResult MojoMain(MojoHandle application_request) {
PingableApp pingable_app;
- return mojo::RunMainApplication(application_request, &pingable_app);
+ return mojo::RunApplication(application_request, &pingable_app);
}
diff --git a/ui/ozone/platform/drm/mojo/drm_ipc_init_helper.cc b/ui/ozone/platform/drm/mojo/drm_ipc_init_helper.cc
index ee97c98..ddcad8d 100644
--- a/ui/ozone/platform/drm/mojo/drm_ipc_init_helper.cc
+++ b/ui/ozone/platform/drm/mojo/drm_ipc_init_helper.cc
@@ -19,12 +19,12 @@
DrmIpcInitHelperMojo();
~DrmIpcInitHelperMojo();
- void HostInitialize(mojo::ApplicationImpl* application) override;
- bool HostConfigureIncomingConnection(
+ void HostInitialize(mojo::Shell* shell) override;
+ bool HostAcceptConnection(
mojo::ServiceProviderImpl* service_provider_impl) override;
- void GpuInitialize(mojo::ApplicationImpl* application) override;
- bool GpuConfigureIncomingConnection(
+ void GpuInitialize(mojo::Shell* shell) override;
+ bool GpuAcceptConnection(
mojo::ServiceProviderImpl* service_provider_impl) override;
private:
@@ -36,19 +36,19 @@
DrmIpcInitHelperMojo::~DrmIpcInitHelperMojo() {}
-void DrmIpcInitHelperMojo::HostInitialize(mojo::ApplicationImpl* application) {
- mojo::ConnectToService(application->shell(), "mojo:native_viewport_service",
+void DrmIpcInitHelperMojo::HostInitialize(mojo::Shell* shell) {
+ mojo::ConnectToService(shell, "mojo:native_viewport_service",
GetProxy(&ozone_drm_gpu_));
new MojoDrmHostDelegate(ozone_drm_gpu_.get());
}
-void DrmIpcInitHelperMojo::GpuInitialize(mojo::ApplicationImpl* application) {
- mojo::ConnectToService(application->shell(), "mojo:native_viewport_service",
+void DrmIpcInitHelperMojo::GpuInitialize(mojo::Shell* shell) {
+ mojo::ConnectToService(shell, "mojo:native_viewport_service",
GetProxy(&ozone_drm_host_));
new MojoDrmGpuDelegate(ozone_drm_host_.get());
}
-bool DrmIpcInitHelperMojo::HostConfigureIncomingConnection(
+bool DrmIpcInitHelperMojo::HostAcceptConnection(
mojo::ServiceProviderImpl* service_provider_impl) {
service_provider_impl->AddService<mojo::OzoneDrmHost>(
[](const mojo::ConnectionContext& connection_context,
@@ -58,7 +58,7 @@
return true;
}
-bool DrmIpcInitHelperMojo::GpuConfigureIncomingConnection(
+bool DrmIpcInitHelperMojo::GpuAcceptConnection(
mojo::ServiceProviderImpl* service_provider_impl) {
service_provider_impl->AddService<mojo::OzoneDrmGpu>(
[](const mojo::ConnectionContext& connection_context,
diff --git a/ui/ozone/public/ipc_init_helper_mojo.h b/ui/ozone/public/ipc_init_helper_mojo.h
index c7754be..4264d32 100644
--- a/ui/ozone/public/ipc_init_helper_mojo.h
+++ b/ui/ozone/public/ipc_init_helper_mojo.h
@@ -5,23 +5,26 @@
#ifndef UI_OZONE_PUBLIC_IPC_INIT_HELPER_MOJO_H_
#define UI_OZONE_PUBLIC_IPC_INIT_HELPER_MOJO_H_
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/service_provider_impl.h"
#include "ui/ozone/public/ipc_init_helper_ozone.h"
+namespace mojo {
+class ServiceProviderImpl;
+class Shell;
+} // namespace mojo
+
namespace ui {
class IpcInitHelperMojo : public IpcInitHelperOzone {
public:
- virtual void HostInitialize(mojo::ApplicationImpl* application) = 0;
- virtual bool HostConfigureIncomingConnection(
+ virtual void HostInitialize(mojo::Shell* shell) = 0;
+ virtual bool HostAcceptConnection(
mojo::ServiceProviderImpl* service_provider_impl) = 0;
- virtual void GpuInitialize(mojo::ApplicationImpl* application) = 0;
- virtual bool GpuConfigureIncomingConnection(
+ virtual void GpuInitialize(mojo::Shell* shell) = 0;
+ virtual bool GpuAcceptConnection(
mojo::ServiceProviderImpl* service_provider_impl) = 0;
};
} // namespace ui
-#endif
+#endif // UI_OZONE_PUBLIC_IPC_INIT_HELPER_MOJO_H_