| 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 "services/service_manager/public/cpp/service_runner.h" | 5 #include "services/service_manager/public/cpp/service_runner.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 std::unique_ptr<base::MessageLoop> loop; | 52 std::unique_ptr<base::MessageLoop> loop; |
| 53 loop.reset(new base::MessageLoop(message_loop_type_)); | 53 loop.reset(new base::MessageLoop(message_loop_type_)); |
| 54 | 54 |
| 55 context_.reset(new ServiceContext( | 55 context_.reset(new ServiceContext( |
| 56 std::move(service_), | 56 std::move(service_), |
| 57 mojo::MakeRequest<mojom::Service>(mojo::MakeScopedHandle( | 57 mojo::MakeRequest<mojom::Service>(mojo::MakeScopedHandle( |
| 58 mojo::MessagePipeHandle(service_request_handle))))); | 58 mojo::MessagePipeHandle(service_request_handle))))); |
| 59 base::RunLoop run_loop; | 59 base::RunLoop run_loop; |
| 60 context_->SetConnectionLostClosure(run_loop.QuitClosure()); | 60 context_->SetConnectionLostClosure(run_loop.QuitClosure()); |
| 61 run_loop.Run(); | 61 run_loop.Run(); |
| 62 // It's very common for the service to cache the app and terminate on | |
| 63 // errors. If we don't delete the service before the app we run the risk of | |
| 64 // the service having a stale reference to the app and trying to use it. | |
| 65 // Note that we destruct the message loop first because that might trigger | |
| 66 // connection error handlers and they might access objects created by the | |
| 67 // service. | |
| 68 loop.reset(); | |
| 69 context_.reset(); | 62 context_.reset(); |
| 70 } | 63 } |
| 71 return MOJO_RESULT_OK; | 64 return MOJO_RESULT_OK; |
| 72 } | 65 } |
| 73 | 66 |
| 74 MojoResult ServiceRunner::Run(MojoHandle service_request_handle) { | 67 MojoResult ServiceRunner::Run(MojoHandle service_request_handle) { |
| 75 return Run(service_request_handle, false); | 68 return Run(service_request_handle, false); |
| 76 } | 69 } |
| 77 | 70 |
| 78 void ServiceRunner::Quit() { | 71 void ServiceRunner::Quit() { |
| 79 base::MessageLoop::current()->QuitWhenIdle(); | 72 base::MessageLoop::current()->QuitWhenIdle(); |
| 80 } | 73 } |
| 81 | 74 |
| 82 } // namespace service_manager | 75 } // namespace service_manager |
| OLD | NEW |