| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/at_exit.h" | |
| 6 #include "base/command_line.h" | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/threading/sequenced_worker_pool.h" | |
| 10 #include "mojo/message_pump/message_pump_mojo.h" | |
| 11 #include "mojo/public/c/system/main.h" | |
| 12 #include "mojo/services/package_manager/package_manager.h" | |
| 13 #include "mojo/shell/public/cpp/shell_connection.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 const size_t kMaxBlockingPoolThreads = 3; | |
| 17 | |
| 18 MojoResult Run(MojoHandle shell_handle) { | |
| 19 scoped_ptr<base::AtExitManager> at_exit; | |
| 20 if (!base::CommandLine::InitializedForCurrentProcess() || | |
| 21 !base::CommandLine::ForCurrentProcess()->HasSwitch("single-process")) { | |
| 22 at_exit.reset(new base::AtExitManager); | |
| 23 } | |
| 24 | |
| 25 { | |
| 26 scoped_ptr<base::MessageLoop> loop( | |
| 27 new base::MessageLoop(common::MessagePumpMojo::Create())); | |
| 28 scoped_refptr<base::SequencedWorkerPool> blocking_pool( | |
| 29 new base::SequencedWorkerPool(kMaxBlockingPoolThreads, | |
| 30 "blocking_pool")); | |
| 31 scoped_ptr<mojo::ShellClient> shell_client( | |
| 32 new package_manager::PackageManager(blocking_pool.get(), nullptr)); | |
| 33 mojo::ShellConnection connection( | |
| 34 shell_client.get(), MakeRequest<mojo::shell::mojom::ShellClient>( | |
| 35 MakeScopedHandle(MessagePipeHandle(shell_handle)))); | |
| 36 loop->Run(); | |
| 37 blocking_pool->Shutdown(); | |
| 38 loop.reset(); | |
| 39 shell_client.reset(); | |
| 40 } | |
| 41 return MOJO_RESULT_OK; | |
| 42 } | |
| 43 | |
| 44 } // namespace mojo | |
| 45 | |
| 46 MojoResult MojoMain(MojoHandle shell_handle) { | |
| 47 return mojo::Run(shell_handle); | |
| 48 } | |
| OLD | NEW |