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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 bool Connect() { return connection_.Connect(); } | 35 bool Connect() { return connection_.Connect(); } |
36 | 36 |
37 bool Register() { | 37 bool Register() { |
38 DCHECK(!run_loop_.get()); | 38 DCHECK(!run_loop_.get()); |
39 run_loop_.reset(new base::RunLoop); | 39 run_loop_.reset(new base::RunLoop); |
40 connection_.Register( | 40 connection_.Register( |
41 app_url_, app_args_, | 41 app_url_, app_args_, |
42 base::Bind(&Launcher::OnRegistered, base::Unretained(this))); | 42 base::Bind(&Launcher::OnRegistered, base::Unretained(this))); |
43 run_loop_->Run(); | 43 run_loop_->Run(); |
44 run_loop_.reset(); | 44 run_loop_.reset(); |
45 return shell_handle_.is_valid(); | 45 return application_request_.is_pending(); |
46 } | 46 } |
47 | 47 |
48 void Run() { | 48 void Run() { |
49 DCHECK(!run_loop_.get()); | 49 DCHECK(!run_loop_.get()); |
50 DCHECK(shell_handle_.is_valid()); | 50 DCHECK(application_request_.is_pending()); |
51 mojo::shell::InProcessDynamicServiceRunner service_runner(nullptr); | 51 mojo::shell::InProcessDynamicServiceRunner service_runner(nullptr); |
52 run_loop_.reset(new base::RunLoop); | 52 run_loop_.reset(new base::RunLoop); |
53 service_runner.Start( | 53 service_runner.Start( |
54 app_path_, shell_handle_.Pass(), | 54 app_path_, application_request_.Pass(), |
55 base::Bind(&Launcher::OnAppCompleted, base::Unretained(this))); | 55 base::Bind(&Launcher::OnAppCompleted, base::Unretained(this))); |
56 run_loop_->Run(); | 56 run_loop_->Run(); |
57 run_loop_.reset(); | 57 run_loop_.reset(); |
58 } | 58 } |
59 | 59 |
60 private: | 60 private: |
61 void OnRegistered(mojo::ShellPtr shell) { | 61 void OnRegistered( |
62 shell_handle_ = shell.PassMessagePipe(); | 62 mojo::InterfaceRequest<mojo::Application> application_request) { |
| 63 application_request_ = application_request.Pass(); |
63 run_loop_->Quit(); | 64 run_loop_->Quit(); |
64 } | 65 } |
65 | 66 |
66 void OnAppCompleted() { run_loop_->Quit(); } | 67 void OnAppCompleted() { run_loop_->Quit(); } |
67 | 68 |
68 const base::FilePath app_path_; | 69 const base::FilePath app_path_; |
69 const GURL app_url_; | 70 const GURL app_url_; |
70 std::vector<std::string> app_args_; | 71 std::vector<std::string> app_args_; |
71 base::MessageLoop loop_; | 72 base::MessageLoop loop_; |
72 mojo::shell::ExternalApplicationRegistrarConnection connection_; | 73 mojo::shell::ExternalApplicationRegistrarConnection connection_; |
73 mojo::ScopedMessagePipeHandle shell_handle_; | 74 mojo::InterfaceRequest<mojo::Application> application_request_; |
74 scoped_ptr<base::RunLoop> run_loop_; | 75 scoped_ptr<base::RunLoop> run_loop_; |
75 }; | 76 }; |
76 | 77 |
77 #if defined(OS_WIN) | 78 #if defined(OS_WIN) |
78 int main(int argc, wchar_t** argv) { | 79 int main(int argc, wchar_t** argv) { |
79 #else | 80 #else |
80 int main(int argc, char** argv) { | 81 int main(int argc, char** argv) { |
81 #endif | 82 #endif |
82 base::AtExitManager at_exit; | 83 base::AtExitManager at_exit; |
83 mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( | 84 mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( |
(...skipping 12 matching lines...) Expand all Loading... |
96 | 97 |
97 if (!launcher.Register()) { | 98 if (!launcher.Register()) { |
98 LOG(ERROR) << "Error registering " | 99 LOG(ERROR) << "Error registering " |
99 << command_line->GetSwitchValueASCII(kAppURL); | 100 << command_line->GetSwitchValueASCII(kAppURL); |
100 return MOJO_RESULT_INVALID_ARGUMENT; | 101 return MOJO_RESULT_INVALID_ARGUMENT; |
101 } | 102 } |
102 | 103 |
103 launcher.Run(); | 104 launcher.Run(); |
104 return MOJO_RESULT_OK; | 105 return MOJO_RESULT_OK; |
105 } | 106 } |
OLD | NEW |