OLD | NEW |
---|---|
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" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get()); | 82 return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get()); |
83 } | 83 } |
84 | 84 |
85 void MojoShellConnectionImpl::BindToRequestFromCommandLine() { | 85 void MojoShellConnectionImpl::BindToRequestFromCommandLine() { |
86 DCHECK(!shell_connection_); | 86 DCHECK(!shell_connection_); |
87 shell_connection_.reset(new shell::ShellConnection( | 87 shell_connection_.reset(new shell::ShellConnection( |
88 this, shell::GetShellClientRequestFromCommandLine())); | 88 this, shell::GetShellClientRequestFromCommandLine())); |
89 } | 89 } |
90 | 90 |
91 MojoShellConnectionImpl::MojoShellConnectionImpl(bool external) | 91 MojoShellConnectionImpl::MojoShellConnectionImpl(bool external) |
92 : external_(external) {} | 92 : external_(external), connection_lost_(false) {} |
93 | 93 |
94 MojoShellConnectionImpl::~MojoShellConnectionImpl() { | 94 MojoShellConnectionImpl::~MojoShellConnectionImpl() { |
95 STLDeleteElements(&listeners_); | 95 STLDeleteElements(&listeners_); |
96 } | 96 } |
97 | 97 |
98 void MojoShellConnectionImpl::Initialize(shell::Connector* connector, | 98 void MojoShellConnectionImpl::Initialize(shell::Connector* connector, |
99 const shell::Identity& identity, | 99 const shell::Identity& identity, |
100 uint32_t id) {} | 100 uint32_t id) {} |
101 | 101 |
102 bool MojoShellConnectionImpl::AcceptConnection(shell::Connection* connection) { | 102 bool MojoShellConnectionImpl::AcceptConnection(shell::Connection* connection) { |
103 bool found = false; | 103 bool found = false; |
104 for (auto listener : listeners_) | 104 for (auto listener : listeners_) |
105 found |= listener->AcceptConnection(connection); | 105 found |= listener->AcceptConnection(connection); |
106 return found; | 106 return found; |
107 } | 107 } |
108 | 108 |
109 bool MojoShellConnectionImpl::ShellConnectionLost() { | |
110 connection_lost_ = true; | |
111 // Allow termination to proceed. | |
112 return true; | |
113 } | |
114 | |
109 shell::Connector* MojoShellConnectionImpl::GetConnector() { | 115 shell::Connector* MojoShellConnectionImpl::GetConnector() { |
110 DCHECK(shell_connection_); | 116 DCHECK(shell_connection_); |
111 return shell_connection_->connector(); | 117 return shell_connection_->connector(); |
112 } | 118 } |
113 | 119 |
114 const shell::Identity& MojoShellConnectionImpl::GetIdentity() const { | 120 const shell::Identity& MojoShellConnectionImpl::GetIdentity() const { |
115 DCHECK(shell_connection_); | 121 DCHECK(shell_connection_); |
116 return shell_connection_->identity(); | 122 return shell_connection_->identity(); |
117 } | 123 } |
118 | 124 |
119 bool MojoShellConnectionImpl::UsingExternalShell() const { | 125 bool MojoShellConnectionImpl::UsingExternalShell() const { |
120 return external_; | 126 return external_; |
121 } | 127 } |
122 | 128 |
123 void MojoShellConnectionImpl::SetConnectionLostClosure( | 129 void MojoShellConnectionImpl::SetConnectionLostClosure( |
124 const base::Closure& closure) { | 130 const base::Closure& closure) { |
125 shell_connection_->set_connection_lost_closure(closure); | 131 if (connection_lost_) |
132 closure.Run(); | |
133 else | |
134 shell_connection_->set_connection_lost_closure(closure); | |
sadrul
2016/04/27 20:00:38
Alternatively, ShellConnection::set_connection_los
sky
2016/04/27 21:18:56
I would add this to ShellConnection as it seems ea
sadrul
2016/04/27 22:11:18
Done.
| |
126 } | 135 } |
127 | 136 |
128 void MojoShellConnectionImpl::AddListener(std::unique_ptr<Listener> listener) { | 137 void MojoShellConnectionImpl::AddListener(std::unique_ptr<Listener> listener) { |
129 DCHECK(std::find(listeners_.begin(), listeners_.end(), listener.get()) == | 138 DCHECK(std::find(listeners_.begin(), listeners_.end(), listener.get()) == |
130 listeners_.end()); | 139 listeners_.end()); |
131 listeners_.push_back(listener.release()); | 140 listeners_.push_back(listener.release()); |
132 } | 141 } |
133 | 142 |
134 std::unique_ptr<MojoShellConnection::Listener> | 143 std::unique_ptr<MojoShellConnection::Listener> |
135 MojoShellConnectionImpl::RemoveListener(Listener* listener) { | 144 MojoShellConnectionImpl::RemoveListener(Listener* listener) { |
(...skipping 11 matching lines...) Expand all Loading... | |
147 // static | 156 // static |
148 void MojoShellConnection::Destroy() { | 157 void MojoShellConnection::Destroy() { |
149 // This joins the shell controller thread. | 158 // This joins the shell controller thread. |
150 delete Get(); | 159 delete Get(); |
151 lazy_tls_ptr.Pointer()->Set(nullptr); | 160 lazy_tls_ptr.Pointer()->Set(nullptr); |
152 } | 161 } |
153 | 162 |
154 MojoShellConnection::~MojoShellConnection() {} | 163 MojoShellConnection::~MojoShellConnection() {} |
155 | 164 |
156 } // namespace content | 165 } // namespace content |
OLD | NEW |