diff options
Diffstat (limited to 'mojo/shell/runner/common/client_util.cc')
-rw-r--r-- | mojo/shell/runner/common/client_util.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/mojo/shell/runner/common/client_util.cc b/mojo/shell/runner/common/client_util.cc new file mode 100644 index 0000000..2c264bd --- /dev/null +++ b/mojo/shell/runner/common/client_util.cc @@ -0,0 +1,38 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "mojo/shell/runner/common/client_util.h" + +#include <string> + +#include "base/command_line.h" +#include "mojo/edk/embedder/embedder.h" +#include "mojo/shell/runner/common/switches.h" + +namespace mojo { +namespace shell { + +mojom::ShellClientPtr PassShellClientRequestOnCommandLine( + base::CommandLine* command_line) { + std::string token = edk::GenerateRandomToken(); + command_line->AppendSwitchASCII(switches::kPrimordialPipeToken, token); + + mojom::ShellClientPtr client; + client.Bind( + mojom::ShellClientPtrInfo(edk::CreateParentMessagePipe(token), 0)); + return client; +} + +mojom::ShellClientRequest GetShellClientRequestFromCommandLine() { + std::string token = + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kPrimordialPipeToken); + mojom::ShellClientRequest request; + if (!token.empty()) + request.Bind(edk::CreateChildMessagePipe(token)); + return request; +} + +} // namespace shell +} // namespace mojo |