| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/application/public/cpp/application_runner.h" | 5 #include "mojo/application/public/cpp/application_runner.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 base::CommandLine::Init(g_argc, g_argv); | 38 base::CommandLine::Init(g_argc, g_argv); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void ApplicationRunner::set_message_loop_type(base::MessageLoop::Type type) { | 41 void ApplicationRunner::set_message_loop_type(base::MessageLoop::Type type) { |
| 42 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type); | 42 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type); |
| 43 DCHECK(!has_run_); | 43 DCHECK(!has_run_); |
| 44 | 44 |
| 45 message_loop_type_ = type; | 45 message_loop_type_ = type; |
| 46 } | 46 } |
| 47 | 47 |
| 48 MojoResult ApplicationRunner::Run(MojoHandle application_request_handle) { | 48 MojoResult ApplicationRunner::Run(MojoHandle application_request_handle, |
| 49 bool init_base) { |
| 49 DCHECK(!has_run_); | 50 DCHECK(!has_run_); |
| 50 has_run_ = true; | 51 has_run_ = true; |
| 51 | 52 |
| 52 InitBaseCommandLine(); | 53 if (init_base) { |
| 53 base::AtExitManager at_exit; | 54 InitBaseCommandLine(); |
| 54 | 55 base::AtExitManager at_exit; |
| 55 #ifndef NDEBUG | 56 #ifndef NDEBUG |
| 56 base::debug::EnableInProcessStackDumping(); | 57 base::debug::EnableInProcessStackDumping(); |
| 57 #endif | 58 #endif |
| 59 } |
| 58 | 60 |
| 59 { | 61 { |
| 60 scoped_ptr<base::MessageLoop> loop; | 62 scoped_ptr<base::MessageLoop> loop; |
| 61 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) | 63 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) |
| 62 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); | 64 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); |
| 63 else | 65 else |
| 64 loop.reset(new base::MessageLoop(message_loop_type_)); | 66 loop.reset(new base::MessageLoop(message_loop_type_)); |
| 65 | 67 |
| 66 ApplicationImpl impl(delegate_.get(), | 68 ApplicationImpl impl(delegate_.get(), |
| 67 MakeRequest<Application>(MakeScopedHandle( | 69 MakeRequest<Application>(MakeScopedHandle( |
| 68 MessagePipeHandle(application_request_handle)))); | 70 MessagePipeHandle(application_request_handle)))); |
| 69 loop->Run(); | 71 loop->Run(); |
| 70 // It's very common for the delegate to cache the app and terminate on | 72 // It's very common for the delegate to cache the app and terminate on |
| 71 // errors. If we don't delete the delegate before the app we run the risk | 73 // errors. If we don't delete the delegate before the app we run the risk |
| 72 // of the delegate having a stale reference to the app and trying to use it. | 74 // of the delegate having a stale reference to the app and trying to use it. |
| 73 // Note that we destruct the message loop first because that might trigger | 75 // Note that we destruct the message loop first because that might trigger |
| 74 // connection error handlers and they might access objects created by the | 76 // connection error handlers and they might access objects created by the |
| 75 // delegate. | 77 // delegate. |
| 76 loop.reset(); | 78 loop.reset(); |
| 77 delegate_.reset(); | 79 delegate_.reset(); |
| 78 } | 80 } |
| 79 return MOJO_RESULT_OK; | 81 return MOJO_RESULT_OK; |
| 80 } | 82 } |
| 81 | 83 |
| 84 MojoResult ApplicationRunner::Run(MojoHandle application_request_handle) { |
| 85 return Run(application_request_handle, true); |
| 86 } |
| 87 |
| 82 } // namespace mojo | 88 } // namespace mojo |
| OLD | NEW |