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/shell/public/cpp/application_runner.h" | 5 #include "mojo/shell/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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 | 49 |
50 { | 50 { |
51 scoped_ptr<base::MessageLoop> loop; | 51 scoped_ptr<base::MessageLoop> loop; |
52 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) | 52 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) |
53 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); | 53 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); |
54 else | 54 else |
55 loop.reset(new base::MessageLoop(message_loop_type_)); | 55 loop.reset(new base::MessageLoop(message_loop_type_)); |
56 | 56 |
57 ApplicationImpl impl(delegate_.get(), | 57 ApplicationImpl impl(delegate_.get(), |
58 MakeRequest<Application>(MakeScopedHandle( | 58 MakeRequest<shell::mojom::Application>( |
59 MessagePipeHandle(application_request_handle)))); | 59 MakeScopedHandle(MessagePipeHandle( |
| 60 application_request_handle)))); |
60 loop->Run(); | 61 loop->Run(); |
61 // It's very common for the delegate to cache the app and terminate on | 62 // It's very common for the delegate to cache the app and terminate on |
62 // errors. If we don't delete the delegate before the app we run the risk | 63 // errors. If we don't delete the delegate before the app we run the risk |
63 // of the delegate having a stale reference to the app and trying to use it. | 64 // of the delegate having a stale reference to the app and trying to use it. |
64 // Note that we destruct the message loop first because that might trigger | 65 // Note that we destruct the message loop first because that might trigger |
65 // connection error handlers and they might access objects created by the | 66 // connection error handlers and they might access objects created by the |
66 // delegate. | 67 // delegate. |
67 loop.reset(); | 68 loop.reset(); |
68 delegate_.reset(); | 69 delegate_.reset(); |
69 } | 70 } |
70 return MOJO_RESULT_OK; | 71 return MOJO_RESULT_OK; |
71 } | 72 } |
72 | 73 |
73 MojoResult ApplicationRunner::Run(MojoHandle application_request_handle) { | 74 MojoResult ApplicationRunner::Run(MojoHandle application_request_handle) { |
74 return Run(application_request_handle, true); | 75 return Run(application_request_handle, true); |
75 } | 76 } |
76 | 77 |
77 } // namespace mojo | 78 } // namespace mojo |
OLD | NEW |