Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: mojo/shell/background/background_shell.cc

Issue 1722743002: Adds ability for chrome to behave as mojo_runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge to tip of tree Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/background/background_shell.h" 5 #include "mojo/shell/background/background_shell.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 private: 66 private:
67 DISALLOW_COPY_AND_ASSIGN(MojoMessageLoop); 67 DISALLOW_COPY_AND_ASSIGN(MojoMessageLoop);
68 }; 68 };
69 69
70 } // namespace 70 } // namespace
71 71
72 // Manages the thread to startup mojo. 72 // Manages the thread to startup mojo.
73 class BackgroundShell::MojoThread : public base::SimpleThread { 73 class BackgroundShell::MojoThread : public base::SimpleThread {
74 public: 74 public:
75 explicit MojoThread( 75 explicit MojoThread(NativeRunnerDelegate* native_runner_delegate)
76 const std::vector<CommandLineSwitch>& command_line_switches)
77 : SimpleThread("mojo-background-shell"), 76 : SimpleThread("mojo-background-shell"),
78 command_line_switches_(command_line_switches) {} 77 native_runner_delegate_(native_runner_delegate) {}
79 ~MojoThread() override {} 78 ~MojoThread() override {}
80 79
81 void CreateShellClientRequest(base::WaitableEvent* signal, 80 void CreateShellClientRequest(base::WaitableEvent* signal,
82 scoped_ptr<ConnectParams> params, 81 scoped_ptr<ConnectParams> params,
83 mojom::ShellClientRequest* request) { 82 mojom::ShellClientRequest* request) {
84 // Only valid to call this on the background thread. 83 // Only valid to call this on the background thread.
85 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 84 DCHECK_EQ(message_loop_, base::MessageLoop::current());
86 85
87 // Ownership of |loader| passes to ApplicationManager. 86 // Ownership of |loader| passes to ApplicationManager.
88 const GURL url = params->target().url(); 87 const GURL url = params->target().url();
(...skipping 30 matching lines...) Expand all
119 118
120 Context::EnsureEmbedderIsInitialized(); 119 Context::EnsureEmbedderIsInitialized();
121 120
122 message_loop_->BindToCurrentThread(); 121 message_loop_->BindToCurrentThread();
123 122
124 base::FilePath shell_dir; 123 base::FilePath shell_dir;
125 PathService::Get(base::DIR_MODULE, &shell_dir); 124 PathService::Get(base::DIR_MODULE, &shell_dir);
126 125
127 scoped_ptr<Context> context(new Context); 126 scoped_ptr<Context> context(new Context);
128 context_ = context.get(); 127 context_ = context.get();
129 context_->set_command_line_switches(command_line_switches_); 128 context_->set_native_runner_delegate(native_runner_delegate_);
130 context_->Init(shell_dir); 129 context_->Init(shell_dir);
131 130
132 message_loop_->Run(); 131 message_loop_->Run();
133 132
134 // Has to happen after run, but while messageloop still valid. 133 // Has to happen after run, but while messageloop still valid.
135 context_->Shutdown(); 134 context_->Shutdown();
136 135
137 // Context has to be destroyed after the MessageLoop has been destroyed. 136 // Context has to be destroyed after the MessageLoop has been destroyed.
138 message_loop.reset(); 137 message_loop.reset();
139 context_ = nullptr; 138 context_ = nullptr;
140 } 139 }
141 140
142 private: 141 private:
143 void OnGotApplicationRequest(const GURL& url, 142 void OnGotApplicationRequest(const GURL& url,
144 base::WaitableEvent* signal, 143 base::WaitableEvent* signal,
145 mojom::ShellClientRequest* request_result, 144 mojom::ShellClientRequest* request_result,
146 mojom::ShellClientRequest actual_request) { 145 mojom::ShellClientRequest actual_request) {
147 *request_result = std::move(actual_request); 146 *request_result = std::move(actual_request);
148 // Trigger destruction of the loader. 147 // Trigger destruction of the loader.
149 context_->application_manager()->SetLoaderForURL(nullptr, url); 148 context_->application_manager()->SetLoaderForURL(nullptr, url);
150 signal->Signal(); 149 signal->Signal();
151 } 150 }
152 151
153 // We own this. It's created on the main thread, but destroyed on the 152 // We own this. It's created on the main thread, but destroyed on the
154 // background thread. 153 // background thread.
155 MojoMessageLoop* message_loop_ = nullptr; 154 MojoMessageLoop* message_loop_ = nullptr;
156 // Created in Run() on the background thread. 155 // Created in Run() on the background thread.
157 Context* context_ = nullptr; 156 Context* context_ = nullptr;
158 157
159 const std::vector<CommandLineSwitch> command_line_switches_; 158 NativeRunnerDelegate* native_runner_delegate_;
160 159
161 DISALLOW_COPY_AND_ASSIGN(MojoThread); 160 DISALLOW_COPY_AND_ASSIGN(MojoThread);
162 }; 161 };
163 162
164 BackgroundShell::BackgroundShell() {} 163 BackgroundShell::BackgroundShell() {}
165 164
166 BackgroundShell::~BackgroundShell() { 165 BackgroundShell::~BackgroundShell() {
167 thread_->Stop(); 166 thread_->Stop();
168 } 167 }
169 168
170 void BackgroundShell::Init( 169 void BackgroundShell::Init(NativeRunnerDelegate* native_runner_delegate) {
171 const std::vector<CommandLineSwitch>& command_line_switches) {
172 DCHECK(!thread_); 170 DCHECK(!thread_);
173 thread_.reset(new MojoThread(command_line_switches)); 171 thread_.reset(new MojoThread(native_runner_delegate));
174 thread_->Start(); 172 thread_->Start();
175 } 173 }
176 174
177 mojom::ShellClientRequest BackgroundShell::CreateShellClientRequest( 175 mojom::ShellClientRequest BackgroundShell::CreateShellClientRequest(
178 const GURL& url) { 176 const GURL& url) {
179 scoped_ptr<ConnectParams> params(new ConnectParams); 177 scoped_ptr<ConnectParams> params(new ConnectParams);
180 params->set_target( 178 params->set_target(
181 Identity(url, std::string(), GetPermissiveCapabilityFilter())); 179 Identity(url, std::string(), GetPermissiveCapabilityFilter()));
182 mojom::ShellClientRequest request; 180 mojom::ShellClientRequest request;
183 base::WaitableEvent signal(true, false); 181 base::WaitableEvent signal(true, false);
184 thread_->message_loop()->task_runner()->PostTask( 182 thread_->message_loop()->task_runner()->PostTask(
185 FROM_HERE, base::Bind(&MojoThread::CreateShellClientRequest, 183 FROM_HERE, base::Bind(&MojoThread::CreateShellClientRequest,
186 base::Unretained(thread_.get()), &signal, 184 base::Unretained(thread_.get()), &signal,
187 base::Passed(&params), &request)); 185 base::Passed(&params), &request));
188 signal.Wait(); 186 signal.Wait();
189 return request; 187 return request;
190 } 188 }
191 189
192 } // namespace shell 190 } // namespace shell
193 } // namespace mojo 191 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698