Chromium Code Reviews| 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 "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/process/process_handle.h" | |
|
Fady Samuel
2015/11/24 04:42:38
delete this.
| |
| 9 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| 10 #include "mojo/application/public/cpp/application_delegate.h" | 11 #include "mojo/application/public/cpp/application_delegate.h" |
| 11 #include "mojo/application/public/cpp/application_impl.h" | 12 #include "mojo/application/public/cpp/application_impl.h" |
| 12 #include "mojo/converters/network/network_type_converters.h" | 13 #include "mojo/converters/network/network_type_converters.h" |
| 13 #include "mojo/runner/child/runner_connection.h" | 14 #include "mojo/runner/child/runner_connection.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 namespace { | 17 namespace { |
| 17 using MojoShellConnectionPtr = | 18 using MojoShellConnectionPtr = |
| 18 base::ThreadLocalPointer<MojoShellConnectionImpl>; | 19 base::ThreadLocalPointer<MojoShellConnectionImpl>; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 this, application_request.Pass())); | 56 this, application_request.Pass())); |
| 56 application_impl_->WaitForInitialize(); | 57 application_impl_->WaitForInitialize(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void MojoShellConnectionImpl::Initialize(mojo::ApplicationImpl* application) { | 60 void MojoShellConnectionImpl::Initialize(mojo::ApplicationImpl* application) { |
| 60 initialized_ = true; | 61 initialized_ = true; |
| 61 } | 62 } |
| 62 | 63 |
| 63 bool MojoShellConnectionImpl::ConfigureIncomingConnection( | 64 bool MojoShellConnectionImpl::ConfigureIncomingConnection( |
| 64 mojo::ApplicationConnection* connection) { | 65 mojo::ApplicationConnection* connection) { |
| 66 fprintf(stderr, "[%d] >>>%s url %s \n", base::GetCurrentProcId(), | |
| 67 __PRETTY_FUNCTION__, connection->GetRemoteApplicationURL().c_str()); | |
| 65 bool found = false; | 68 bool found = false; |
| 66 for (auto listener : listeners_) | 69 for (auto listener : listeners_) |
| 67 found |= listener->ConfigureIncomingConnection(connection); | 70 found |= listener->ConfigureIncomingConnection(connection); |
| 68 return found; | 71 return found; |
| 69 } | 72 } |
| 70 | 73 |
| 71 mojo::ApplicationImpl* MojoShellConnectionImpl::GetApplication() { | 74 mojo::ApplicationImpl* MojoShellConnectionImpl::GetApplication() { |
| 72 DCHECK(initialized_); | 75 DCHECK(initialized_); |
| 73 return application_impl_.get(); | 76 return application_impl_.get(); |
| 74 } | 77 } |
| 75 | 78 |
| 76 void MojoShellConnectionImpl::AddListener(Listener* listener) { | 79 void MojoShellConnectionImpl::AddListener(Listener* listener) { |
| 77 DCHECK(std::find(listeners_.begin(), listeners_.end(), listener) == | 80 DCHECK(std::find(listeners_.begin(), listeners_.end(), listener) == |
| 78 listeners_.end()); | 81 listeners_.end()); |
| 79 listeners_.push_back(listener); | 82 listeners_.push_back(listener); |
| 80 } | 83 } |
| 81 | 84 |
| 82 void MojoShellConnectionImpl::RemoveListener(Listener* listener) { | 85 void MojoShellConnectionImpl::RemoveListener(Listener* listener) { |
| 83 auto it = std::find(listeners_.begin(), listeners_.end(), listener); | 86 auto it = std::find(listeners_.begin(), listeners_.end(), listener); |
| 84 DCHECK(it != listeners_.end()); | 87 DCHECK(it != listeners_.end()); |
| 85 listeners_.erase(it); | 88 listeners_.erase(it); |
| 86 } | 89 } |
| 87 | 90 |
| 91 void MojoShellConnectionImpl::OnDestroy() { | |
| 92 for (auto listener : listeners_) | |
| 93 listener->OnDestroy(); | |
| 94 } | |
| 95 | |
| 88 // static | 96 // static |
| 89 MojoShellConnection* MojoShellConnection::Get() { | 97 MojoShellConnection* MojoShellConnection::Get() { |
| 90 return lazy_tls_ptr.Pointer()->Get(); | 98 return lazy_tls_ptr.Pointer()->Get(); |
| 91 } | 99 } |
| 92 | 100 |
| 93 // static | 101 // static |
| 94 void MojoShellConnection::Destroy() { | 102 void MojoShellConnection::Destroy() { |
| 103 static_cast<MojoShellConnectionImpl*>(Get())->OnDestroy(); | |
| 95 // This joins the shell controller thread. | 104 // This joins the shell controller thread. |
| 96 delete Get(); | 105 delete Get(); |
| 97 lazy_tls_ptr.Pointer()->Set(nullptr); | 106 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 98 } | 107 } |
| 99 | 108 |
| 100 MojoShellConnection::~MojoShellConnection() {} | 109 MojoShellConnection::~MojoShellConnection() {} |
| 101 | 110 |
| 102 } // namespace content | 111 } // namespace content |
| OLD | NEW |