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

Side by Side Diff: content/common/mojo/mojo_shell_connection_impl.cc

Issue 1675153002: ApplicationImpl->ShellConnection, mojom::Application->mojom::ShellClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ci2
Patch Set: . Created 4 years, 10 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
« no previous file with comments | « content/common/mojo/mojo_shell_connection_impl.h ('k') | content/common/process_control.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/common/mojo/mojo_shell_connection_impl.h" 5 #include "content/common/mojo/mojo_shell_connection_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/threading/thread_local.h" 12 #include "base/threading/thread_local.h"
13 #include "mojo/converters/network/network_type_converters.h" 13 #include "mojo/converters/network/network_type_converters.h"
14 #include "mojo/shell/public/cpp/application_impl.h"
15 #include "mojo/shell/public/cpp/shell_client.h" 14 #include "mojo/shell/public/cpp/shell_client.h"
15 #include "mojo/shell/public/cpp/shell_connection.h"
16 #include "mojo/shell/runner/child/runner_connection.h" 16 #include "mojo/shell/runner/child/runner_connection.h"
17 17
18 namespace content { 18 namespace content {
19 namespace { 19 namespace {
20 using MojoShellConnectionPtr = 20 using MojoShellConnectionPtr =
21 base::ThreadLocalPointer<MojoShellConnectionImpl>; 21 base::ThreadLocalPointer<MojoShellConnectionImpl>;
22 22
23 // Env is thread local so that aura may be used on multiple threads. 23 // Env is thread local so that aura may be used on multiple threads.
24 base::LazyInstance<MojoShellConnectionPtr>::Leaky lazy_tls_ptr = 24 base::LazyInstance<MojoShellConnectionPtr>::Leaky lazy_tls_ptr =
25 LAZY_INSTANCE_INITIALIZER; 25 LAZY_INSTANCE_INITIALIZER;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 WaitForShell(std::move(handle)); 57 WaitForShell(std::move(handle));
58 } 58 }
59 59
60 MojoShellConnectionImpl::MojoShellConnectionImpl() : initialized_(false) {} 60 MojoShellConnectionImpl::MojoShellConnectionImpl() : initialized_(false) {}
61 MojoShellConnectionImpl::~MojoShellConnectionImpl() { 61 MojoShellConnectionImpl::~MojoShellConnectionImpl() {
62 STLDeleteElements(&listeners_); 62 STLDeleteElements(&listeners_);
63 } 63 }
64 64
65 void MojoShellConnectionImpl::WaitForShell( 65 void MojoShellConnectionImpl::WaitForShell(
66 mojo::ScopedMessagePipeHandle handle) { 66 mojo::ScopedMessagePipeHandle handle) {
67 mojo::ApplicationRequest application_request; 67 mojo::ShellClientRequest request;
68 runner_connection_.reset(mojo::shell::RunnerConnection::ConnectToRunner( 68 runner_connection_.reset(mojo::shell::RunnerConnection::ConnectToRunner(
69 &application_request, std::move(handle))); 69 &request, std::move(handle)));
70 application_impl_.reset( 70 shell_connection_.reset(new mojo::ShellConnection(this, std::move(request)));
71 new mojo::ApplicationImpl(this, std::move(application_request))); 71 shell_connection_->WaitForInitialize();
72 application_impl_->WaitForInitialize();
73 } 72 }
74 73
75 void MojoShellConnectionImpl::Initialize(mojo::Shell* shell, 74 void MojoShellConnectionImpl::Initialize(mojo::Shell* shell,
76 const std::string& url, 75 const std::string& url,
77 uint32_t id) { 76 uint32_t id) {
78 initialized_ = true; 77 initialized_ = true;
79 } 78 }
80 79
81 bool MojoShellConnectionImpl::AcceptConnection(mojo::Connection* connection) { 80 bool MojoShellConnectionImpl::AcceptConnection(mojo::Connection* connection) {
82 bool found = false; 81 bool found = false;
83 for (auto listener : listeners_) 82 for (auto listener : listeners_)
84 found |= listener->AcceptConnection(connection); 83 found |= listener->AcceptConnection(connection);
85 return found; 84 return found;
86 } 85 }
87 86
88 mojo::Shell* MojoShellConnectionImpl::GetShell() { 87 mojo::Shell* MojoShellConnectionImpl::GetShell() {
89 DCHECK(initialized_); 88 DCHECK(initialized_);
90 return application_impl_.get(); 89 return shell_connection_.get();
91 } 90 }
92 91
93 void MojoShellConnectionImpl::AddListener(Listener* listener) { 92 void MojoShellConnectionImpl::AddListener(Listener* listener) {
94 DCHECK(std::find(listeners_.begin(), listeners_.end(), listener) == 93 DCHECK(std::find(listeners_.begin(), listeners_.end(), listener) ==
95 listeners_.end()); 94 listeners_.end());
96 listeners_.push_back(listener); 95 listeners_.push_back(listener);
97 } 96 }
98 97
99 void MojoShellConnectionImpl::RemoveListener(Listener* listener) { 98 void MojoShellConnectionImpl::RemoveListener(Listener* listener) {
100 auto it = std::find(listeners_.begin(), listeners_.end(), listener); 99 auto it = std::find(listeners_.begin(), listeners_.end(), listener);
101 DCHECK(it != listeners_.end()); 100 DCHECK(it != listeners_.end());
102 listeners_.erase(it); 101 listeners_.erase(it);
103 } 102 }
104 103
105 // static 104 // static
106 MojoShellConnection* MojoShellConnection::Get() { 105 MojoShellConnection* MojoShellConnection::Get() {
107 return lazy_tls_ptr.Pointer()->Get(); 106 return lazy_tls_ptr.Pointer()->Get();
108 } 107 }
109 108
110 // static 109 // static
111 void MojoShellConnection::Destroy() { 110 void MojoShellConnection::Destroy() {
112 // This joins the shell controller thread. 111 // This joins the shell controller thread.
113 delete Get(); 112 delete Get();
114 lazy_tls_ptr.Pointer()->Set(nullptr); 113 lazy_tls_ptr.Pointer()->Set(nullptr);
115 } 114 }
116 115
117 MojoShellConnection::~MojoShellConnection() {} 116 MojoShellConnection::~MojoShellConnection() {}
118 117
119 } // namespace content 118 } // namespace content
OLDNEW
« no previous file with comments | « content/common/mojo/mojo_shell_connection_impl.h ('k') | content/common/process_control.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698