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

Side by Side Diff: content/renderer/mus/render_widget_window_tree_client_factory.cc

Issue 2111353002: Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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
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"
13 #include "base/sequenced_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h"
12 #include "content/common/render_widget_window_tree_client_factory.mojom.h" 15 #include "content/common/render_widget_window_tree_client_factory.mojom.h"
13 #include "content/public/child/child_thread.h" 16 #include "content/public/common/connection_filter.h"
14 #include "content/public/common/mojo_shell_connection.h" 17 #include "content/public/common/mojo_shell_connection.h"
15 #include "content/renderer/mus/render_widget_mus_connection.h" 18 #include "content/renderer/mus/render_widget_mus_connection.h"
16 #include "mojo/public/cpp/bindings/binding_set.h" 19 #include "mojo/public/cpp/bindings/binding_set.h"
17 #include "services/shell/public/cpp/connection.h"
18 #include "services/shell/public/cpp/interface_factory.h" 20 #include "services/shell/public/cpp/interface_factory.h"
19 #include "services/shell/public/cpp/service.h" 21 #include "services/shell/public/cpp/service.h"
20 #include "services/ui/public/interfaces/window_tree.mojom.h" 22 #include "services/ui/public/interfaces/window_tree.mojom.h"
21 #include "url/gurl.h" 23 #include "url/gurl.h"
22 24
23 namespace content { 25 namespace content {
24 26
25 namespace { 27 namespace {
26 28
29 void BindMusConnectionOnMainThread(
30 uint32_t routing_id,
31 ui::mojom::WindowTreeClientRequest request) {
32 RenderWidgetMusConnection* connection =
33 RenderWidgetMusConnection::GetOrCreate(routing_id);
34 connection->Bind(std::move(request));
35 }
36
27 // This object's lifetime is managed by MojoShellConnection because it's a 37 // This object's lifetime is managed by MojoShellConnection because it's a
28 // registered with it. 38 // registered with it.
29 class RenderWidgetWindowTreeClientFactoryImpl 39 class RenderWidgetWindowTreeClientFactoryImpl
30 : public shell::Service, 40 : public ConnectionFilter,
31 public shell::InterfaceFactory< 41 public shell::InterfaceFactory<
32 mojom::RenderWidgetWindowTreeClientFactory>, 42 mojom::RenderWidgetWindowTreeClientFactory>,
33 public mojom::RenderWidgetWindowTreeClientFactory { 43 public mojom::RenderWidgetWindowTreeClientFactory {
34 public: 44 public:
35 RenderWidgetWindowTreeClientFactoryImpl() { 45 RenderWidgetWindowTreeClientFactoryImpl() {
36 DCHECK(ChildThread::Get()->GetMojoShellConnection()); 46 main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get();
37 } 47 }
38 48
39 ~RenderWidgetWindowTreeClientFactoryImpl() override {} 49 ~RenderWidgetWindowTreeClientFactoryImpl() override {}
40 50
41 private: 51 private:
42 // shell::Service implementation: 52 // ConnectionFilter implementation:
43 bool OnConnect(shell::Connection* connection) override { 53 bool OnConnect(shell::Connection* connection,
54 shell::Connector* connector) override {
44 connection->AddInterface<mojom::RenderWidgetWindowTreeClientFactory>(this); 55 connection->AddInterface<mojom::RenderWidgetWindowTreeClientFactory>(this);
45 return true; 56 return true;
46 } 57 }
47 58
48 // shell::InterfaceFactory<mojom::RenderWidgetWindowTreeClientFactory>: 59 // shell::InterfaceFactory<mojom::RenderWidgetWindowTreeClientFactory>:
49 void Create(shell::Connection* connection, 60 void Create(shell::Connection* connection,
50 mojo::InterfaceRequest<mojom::RenderWidgetWindowTreeClientFactory> 61 mojo::InterfaceRequest<mojom::RenderWidgetWindowTreeClientFactory>
51 request) override { 62 request) override {
52 bindings_.AddBinding(this, std::move(request)); 63 bindings_.AddBinding(this, std::move(request));
53 } 64 }
54 65
55 // mojom::RenderWidgetWindowTreeClientFactory implementation. 66 // mojom::RenderWidgetWindowTreeClientFactory implementation.
56 void CreateWindowTreeClientForRenderWidget( 67 void CreateWindowTreeClientForRenderWidget(
57 uint32_t routing_id, 68 uint32_t routing_id,
58 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) override { 69 ui::mojom::WindowTreeClientRequest request) override {
59 RenderWidgetMusConnection* connection = 70 main_thread_task_runner_->PostTask(
60 RenderWidgetMusConnection::GetOrCreate(routing_id); 71 FROM_HERE, base::Bind(&BindMusConnectionOnMainThread, routing_id,
61 connection->Bind(std::move(request)); 72 base::Passed(&request)));
62 } 73 }
63 74
75 scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner_;
64 mojo::BindingSet<mojom::RenderWidgetWindowTreeClientFactory> bindings_; 76 mojo::BindingSet<mojom::RenderWidgetWindowTreeClientFactory> bindings_;
65 77
66 DISALLOW_COPY_AND_ASSIGN(RenderWidgetWindowTreeClientFactoryImpl); 78 DISALLOW_COPY_AND_ASSIGN(RenderWidgetWindowTreeClientFactoryImpl);
67 }; 79 };
68 80
69 } // namespace 81 } // namespace
70 82
71 void CreateRenderWidgetWindowTreeClientFactory() { 83 void CreateRenderWidgetWindowTreeClientFactory(
72 ChildThread::Get()->GetMojoShellConnection()->MergeService( 84 MojoShellConnection* connection) {
73 base::WrapUnique(new RenderWidgetWindowTreeClientFactoryImpl)); 85 connection->AddConnectionFilter(
86 base::MakeUnique<RenderWidgetWindowTreeClientFactoryImpl>());
74 } 87 }
75 88
76 } // namespace content 89 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/mus/render_widget_window_tree_client_factory.h ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698