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

Side by Side Diff: mojo/shell/runner/child/runner_connection.cc

Issue 1801963002: Change primordial pipes to ShellClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase onto catalog CL Created 4 years, 9 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
(Empty)
1 // Copyright 2015 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 "mojo/shell/runner/child/runner_connection.h"
6
7 #include <stdint.h>
8
9 #include <utility>
10
11 #include "base/bind.h"
12 #include "base/callback.h"
13 #include "base/command_line.h"
14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "mojo/edk/embedder/embedder.h"
18 #include "mojo/edk/embedder/platform_channel_pair.h"
19 #include "mojo/edk/embedder/scoped_platform_handle.h"
20 #include "mojo/public/cpp/bindings/binding.h"
21 #include "mojo/shell/public/interfaces/shell_client_factory.mojom.h"
22 #include "mojo/shell/runner/common/switches.h"
23
24 namespace mojo {
25 namespace shell {
26 namespace {
27
28 class RunnerConnectionImpl : public RunnerConnection,
29 public mojom::ShellClientFactory {
30 public:
31 RunnerConnectionImpl(mojo::ShellConnection* shell_connetion,
32 mojom::ShellClientFactoryRequest client_factory_request,
33 bool exit_on_error)
34 : shell_connection_(shell_connetion),
35 binding_(this, std::move(client_factory_request)),
36 exit_on_error_(exit_on_error) {
37 binding_.set_connection_error_handler([this] { OnConnectionError(); });
38 }
39
40 ~RunnerConnectionImpl() override {}
41
42 private:
43 // mojom::ShellClientFactory:
44 void CreateShellClient(mojom::ShellClientRequest client_request,
45 const String& name) override {
46 shell_connection_->BindToRequest(std::move(client_request));
47 }
48
49 void OnConnectionError() {
50 // A connection error means the connection to the shell is lost. This is not
51 // recoverable.
52 DLOG(ERROR) << "Connection error to the shell.";
53 if (exit_on_error_)
54 _exit(1);
55 }
56
57 mojo::ShellConnection* const shell_connection_;
58 Binding<mojom::ShellClientFactory> binding_;
59 const bool exit_on_error_;
60
61 DISALLOW_COPY_AND_ASSIGN(RunnerConnectionImpl);
62 };
63
64 } // namespace
65
66 RunnerConnection::~RunnerConnection() {}
67
68 // static
69 scoped_ptr<RunnerConnection> RunnerConnection::Create(
70 mojo::ShellConnection* shell_connection,
71 bool exit_on_error) {
72 std::string primordial_pipe_token =
73 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
74 switches::kPrimordialPipeToken);
75 mojom::ShellClientFactoryRequest client_factory_request;
76 client_factory_request.Bind(
77 edk::CreateChildMessagePipe(primordial_pipe_token));
78
79 return make_scoped_ptr(new RunnerConnectionImpl(
80 shell_connection, std::move(client_factory_request), exit_on_error));
81 }
82
83 RunnerConnection::RunnerConnection() {}
84
85 } // namespace shell
86 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/runner/child/runner_connection.h ('k') | mojo/shell/runner/child/test_native_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698