| 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/renderer/mus/render_widget_window_tree_client_factory.h" | 5 #include "content/renderer/mus/render_widget_window_tree_client_factory.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "content/common/render_widget_window_tree_client_factory.mojom.h" | 16 #include "content/common/render_widget_window_tree_client_factory.mojom.h" |
| 17 #include "content/public/common/connection_filter.h" | 17 #include "content/public/common/connection_filter.h" |
| 18 #include "content/public/common/service_manager_connection.h" | 18 #include "content/public/common/service_manager_connection.h" |
| 19 #include "content/renderer/mus/renderer_window_tree_client.h" | 19 #include "content/renderer/mus/renderer_window_tree_client.h" |
| 20 #include "mojo/public/cpp/bindings/binding_set.h" | 20 #include "mojo/public/cpp/bindings/binding_set.h" |
| 21 #include "services/service_manager/public/cpp/interface_factory.h" | 21 #include "services/service_manager/public/cpp/interface_factory.h" |
| 22 #include "services/service_manager/public/cpp/interface_registry.h" | |
| 23 #include "services/service_manager/public/cpp/service.h" | 22 #include "services/service_manager/public/cpp/service.h" |
| 24 #include "services/ui/public/interfaces/window_tree.mojom.h" | 23 #include "services/ui/public/interfaces/window_tree.mojom.h" |
| 25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 void BindMusConnectionOnMainThread( | 30 void BindMusConnectionOnMainThread( |
| 32 uint32_t routing_id, | 31 uint32_t routing_id, |
| 33 ui::mojom::WindowTreeClientRequest request) { | 32 ui::mojom::WindowTreeClientRequest request) { |
| 34 RendererWindowTreeClient::CreateIfNecessary(routing_id); | 33 RendererWindowTreeClient::CreateIfNecessary(routing_id); |
| 35 RendererWindowTreeClient::Get(routing_id)->Bind(std::move(request)); | 34 RendererWindowTreeClient::Get(routing_id)->Bind(std::move(request)); |
| 36 } | 35 } |
| 37 | 36 |
| 38 // This object's lifetime is managed by ServiceManagerConnection because it's a | 37 // This object's lifetime is managed by ServiceManagerConnection because it's a |
| 39 // registered with it. | 38 // registered with it. |
| 40 class RenderWidgetWindowTreeClientFactoryImpl | 39 class RenderWidgetWindowTreeClientFactoryImpl |
| 41 : public ConnectionFilter, | 40 : public ConnectionFilter, |
| 42 public mojom::RenderWidgetWindowTreeClientFactory { | 41 public mojom::RenderWidgetWindowTreeClientFactory { |
| 43 public: | 42 public: |
| 44 RenderWidgetWindowTreeClientFactoryImpl() : weak_factory_(this) { | 43 RenderWidgetWindowTreeClientFactoryImpl() { |
| 45 main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 44 main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 46 } | 45 } |
| 47 | 46 |
| 48 ~RenderWidgetWindowTreeClientFactoryImpl() override {} | 47 ~RenderWidgetWindowTreeClientFactoryImpl() override {} |
| 49 | 48 |
| 50 private: | 49 private: |
| 51 // ConnectionFilter implementation: | 50 // ConnectionFilter implementation: |
| 52 bool OnConnect(const service_manager::Identity& remote_identity, | 51 void OnBindInterface(const service_manager::ServiceInfo& source_info, |
| 53 service_manager::InterfaceRegistry* registry, | 52 const std::string& interface_name, |
| 54 service_manager::Connector* connector) override { | 53 mojo::ScopedMessagePipeHandle* interface_pipe, |
| 55 registry->AddInterface( | 54 service_manager::Connector* connector) override { |
| 56 base::Bind(&RenderWidgetWindowTreeClientFactoryImpl::CreateFactory, | 55 if (interface_name == mojom::RenderWidgetWindowTreeClientFactory::Name_) { |
| 57 weak_factory_.GetWeakPtr())); | 56 bindings_.AddBinding( |
| 58 return true; | 57 this, mojo::MakeRequest<mojom::RenderWidgetWindowTreeClientFactory>( |
| 58 std::move(*interface_pipe))); |
| 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 61 // mojom::RenderWidgetWindowTreeClientFactory implementation. | 62 // mojom::RenderWidgetWindowTreeClientFactory implementation. |
| 62 void CreateWindowTreeClientForRenderWidget( | 63 void CreateWindowTreeClientForRenderWidget( |
| 63 uint32_t routing_id, | 64 uint32_t routing_id, |
| 64 ui::mojom::WindowTreeClientRequest request) override { | 65 ui::mojom::WindowTreeClientRequest request) override { |
| 65 main_thread_task_runner_->PostTask( | 66 main_thread_task_runner_->PostTask( |
| 66 FROM_HERE, base::Bind(&BindMusConnectionOnMainThread, routing_id, | 67 FROM_HERE, base::Bind(&BindMusConnectionOnMainThread, routing_id, |
| 67 base::Passed(&request))); | 68 base::Passed(&request))); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void CreateFactory( | |
| 71 mojom::RenderWidgetWindowTreeClientFactoryRequest request) { | |
| 72 bindings_.AddBinding(this, std::move(request)); | |
| 73 } | |
| 74 | |
| 75 scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner_; | 71 scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner_; |
| 76 mojo::BindingSet<mojom::RenderWidgetWindowTreeClientFactory> bindings_; | 72 mojo::BindingSet<mojom::RenderWidgetWindowTreeClientFactory> bindings_; |
| 77 base::WeakPtrFactory<RenderWidgetWindowTreeClientFactoryImpl> weak_factory_; | |
| 78 | 73 |
| 79 DISALLOW_COPY_AND_ASSIGN(RenderWidgetWindowTreeClientFactoryImpl); | 74 DISALLOW_COPY_AND_ASSIGN(RenderWidgetWindowTreeClientFactoryImpl); |
| 80 }; | 75 }; |
| 81 | 76 |
| 82 } // namespace | 77 } // namespace |
| 83 | 78 |
| 84 void CreateRenderWidgetWindowTreeClientFactory( | 79 void CreateRenderWidgetWindowTreeClientFactory( |
| 85 ServiceManagerConnection* connection) { | 80 ServiceManagerConnection* connection) { |
| 86 connection->AddConnectionFilter( | 81 connection->AddConnectionFilter( |
| 87 base::MakeUnique<RenderWidgetWindowTreeClientFactoryImpl>()); | 82 base::MakeUnique<RenderWidgetWindowTreeClientFactoryImpl>()); |
| 88 } | 83 } |
| 89 | 84 |
| 90 } // namespace content | 85 } // namespace content |
| OLD | NEW |