| 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 "content/app/mojo/mojo_init.h" | 5 #include "content/app/mojo/mojo_init.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| 11 #include "ipc/ipc_channel.h" | 11 #include "ipc/ipc_channel.h" |
| 12 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | 12 #include "mojo/edk/embedder/embedder.h" |
| 13 | 13 |
| 14 #if defined(MOJO_SHELL_CLIENT) | 14 #if defined(MOJO_SHELL_CLIENT) |
| 15 #include "content/common/mojo/mojo_shell_connection_impl.h" | 15 #include "content/common/mojo/mojo_shell_connection_impl.h" |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class MojoInitializer { | 22 class MojoInitializer { |
| 23 public: | 23 public: |
| 24 MojoInitializer() { | 24 MojoInitializer() { |
| 25 const base::CommandLine& command_line = | 25 const base::CommandLine& command_line = |
| 26 *base::CommandLine::ForCurrentProcess(); | 26 *base::CommandLine::ForCurrentProcess(); |
| 27 std::string process_type = | 27 std::string process_type = |
| 28 command_line.GetSwitchValueASCII(switches::kProcessType); | 28 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 29 if (process_type.empty() && !command_line.HasSwitch("use-old-edk")) { | 29 bool initialize_as_parent = process_type.empty(); |
| 30 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 30 #if defined(MOJO_SHELL_CLIENT) |
| 31 "use-new-edk"); | 31 if (IsRunningInMojoShell()) |
| 32 initialize_as_parent = false; |
| 33 #endif |
| 34 if (initialize_as_parent) { |
| 35 mojo::edk::PreInitializeParentProcess(); |
| 36 } else { |
| 37 mojo::edk::PreInitializeChildProcess(); |
| 32 } | 38 } |
| 33 | 39 |
| 34 if (command_line.HasSwitch("use-new-edk")) { | 40 mojo::edk::SetMaxMessageSize(IPC::Channel::kMaximumMessageSize); |
| 35 bool initialize_as_parent = process_type.empty(); | 41 mojo::edk::Init(); |
| 36 #if defined(MOJO_SHELL_CLIENT) | |
| 37 if (IsRunningInMojoShell()) | |
| 38 initialize_as_parent = false; | |
| 39 #endif | |
| 40 if (initialize_as_parent) { | |
| 41 mojo::embedder::PreInitializeParentProcess(); | |
| 42 } else { | |
| 43 mojo::embedder::PreInitializeChildProcess(); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 mojo::embedder::SetMaxMessageSize(IPC::Channel::kMaximumMessageSize); | |
| 48 mojo::embedder::Init(); | |
| 49 } | 42 } |
| 50 }; | 43 }; |
| 51 | 44 |
| 52 base::LazyInstance<MojoInitializer>::Leaky mojo_initializer; | 45 base::LazyInstance<MojoInitializer>::Leaky mojo_initializer; |
| 53 | 46 |
| 54 } // namespace | 47 } // namespace |
| 55 | 48 |
| 56 void InitializeMojo() { | 49 void InitializeMojo() { |
| 57 mojo_initializer.Get(); | 50 mojo_initializer.Get(); |
| 58 } | 51 } |
| 59 | 52 |
| 60 } // namespace content | 53 } // namespace content |
| OLD | NEW |