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

Side by Side Diff: services/shell/runner/host/child_process_base.cc

Issue 1882423004: Move shell service to toplevel shell namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 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/shell/runner/host/child_process_base.h" 5 #include "services/shell/runner/host/child_process_base.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "mojo/edk/embedder/embedder.h" 14 #include "mojo/edk/embedder/embedder.h"
15 #include "mojo/edk/embedder/process_delegate.h" 15 #include "mojo/edk/embedder/process_delegate.h"
16 #include "services/shell/runner/common/client_util.h" 16 #include "services/shell/runner/common/client_util.h"
17 17
18 namespace mojo {
19 namespace shell { 18 namespace shell {
20 19
21 namespace { 20 namespace {
22 21
23 // Should be created and initialized on the main thread and kept alive as long 22 // Should be created and initialized on the main thread and kept alive as long
24 // a Mojo application is running in the current process. 23 // a Mojo application is running in the current process.
25 class ScopedAppContext : public edk::ProcessDelegate { 24 class ScopedAppContext : public mojo::edk::ProcessDelegate {
26 public: 25 public:
27 ScopedAppContext() 26 ScopedAppContext()
28 : io_thread_("io_thread"), wait_for_shutdown_event_(true, false) { 27 : io_thread_("io_thread"), wait_for_shutdown_event_(true, false) {
29 // Initialize Mojo before starting any threads. 28 // Initialize Mojo before starting any threads.
30 edk::Init(); 29 mojo::edk::Init();
31 30
32 // Create and start our I/O thread. 31 // Create and start our I/O thread.
33 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); 32 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0);
34 CHECK(io_thread_.StartWithOptions(io_thread_options)); 33 CHECK(io_thread_.StartWithOptions(io_thread_options));
35 io_runner_ = io_thread_.task_runner().get(); 34 io_runner_ = io_thread_.task_runner().get();
36 CHECK(io_runner_.get()); 35 CHECK(io_runner_.get());
37 36
38 edk::InitIPCSupport(this, io_runner_); 37 mojo::edk::InitIPCSupport(this, io_runner_);
39 edk::SetParentPipeHandleFromCommandLine(); 38 mojo::edk::SetParentPipeHandleFromCommandLine();
40 } 39 }
41 40
42 ~ScopedAppContext() override { 41 ~ScopedAppContext() override {
43 edk::ShutdownIPCSupport(); 42 mojo::edk::ShutdownIPCSupport();
44 wait_for_shutdown_event_.Wait(); 43 wait_for_shutdown_event_.Wait();
45 } 44 }
46 45
47 private: 46 private:
48 // ProcessDelegate implementation. 47 // ProcessDelegate implementation.
49 void OnShutdownComplete() override { 48 void OnShutdownComplete() override {
50 wait_for_shutdown_event_.Signal(); 49 wait_for_shutdown_event_.Signal();
51 } 50 }
52 51
53 base::Thread io_thread_; 52 base::Thread io_thread_;
54 scoped_refptr<base::SingleThreadTaskRunner> io_runner_; 53 scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
55 54
56 // Used to unblock the main thread on shutdown. 55 // Used to unblock the main thread on shutdown.
57 base::WaitableEvent wait_for_shutdown_event_; 56 base::WaitableEvent wait_for_shutdown_event_;
58 57
59 DISALLOW_COPY_AND_ASSIGN(ScopedAppContext); 58 DISALLOW_COPY_AND_ASSIGN(ScopedAppContext);
60 }; 59 };
61 60
62 } // namespace 61 } // namespace
63 62
64 void ChildProcessMain(const RunCallback& callback) { 63 void ChildProcessMain(const RunCallback& callback) {
65 DCHECK(!base::MessageLoop::current()); 64 DCHECK(!base::MessageLoop::current());
66 65
67 ScopedAppContext app_context; 66 ScopedAppContext app_context;
68 callback.Run(GetShellClientRequestFromCommandLine()); 67 callback.Run(GetShellClientRequestFromCommandLine());
69 } 68 }
70 69
71 } // namespace shell 70 } // namespace shell
72 } // namespace mojo
OLDNEW
« no previous file with comments | « services/shell/runner/host/child_process_base.h ('k') | services/shell/runner/host/child_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698