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

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"
16 #include "content/public/common/connection_filter.h"
13 #include "content/public/common/mojo_shell_connection.h" 17 #include "content/public/common/mojo_shell_connection.h"
14 #include "content/renderer/mus/render_widget_mus_connection.h" 18 #include "content/renderer/mus/render_widget_mus_connection.h"
15 #include "mojo/public/cpp/bindings/binding_set.h" 19 #include "mojo/public/cpp/bindings/binding_set.h"
16 #include "services/shell/public/cpp/connection.h"
17 #include "services/shell/public/cpp/interface_factory.h" 20 #include "services/shell/public/cpp/interface_factory.h"
18 #include "services/shell/public/cpp/service.h" 21 #include "services/shell/public/cpp/service.h"
19 #include "services/ui/public/interfaces/window_tree.mojom.h" 22 #include "services/ui/public/interfaces/window_tree.mojom.h"
20 #include "url/gurl.h" 23 #include "url/gurl.h"
21 24
22 namespace content { 25 namespace content {
23 26
24 namespace { 27 namespace {
25 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
26 // 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
27 // registered with it. 38 // registered with it.
28 class RenderWidgetWindowTreeClientFactoryImpl 39 class RenderWidgetWindowTreeClientFactoryImpl
29 : public shell::Service, 40 : public ConnectionFilter,
30 public shell::InterfaceFactory< 41 public shell::InterfaceFactory<
31 mojom::RenderWidgetWindowTreeClientFactory>, 42 mojom::RenderWidgetWindowTreeClientFactory>,
32 public mojom::RenderWidgetWindowTreeClientFactory { 43 public mojom::RenderWidgetWindowTreeClientFactory {
33 public: 44 public:
34 RenderWidgetWindowTreeClientFactoryImpl() { 45 RenderWidgetWindowTreeClientFactoryImpl() {
35 DCHECK(MojoShellConnection::GetForProcess()); 46 DCHECK(MojoShellConnection::GetForProcess());
47
48 main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get();
36 } 49 }
37 50
38 ~RenderWidgetWindowTreeClientFactoryImpl() override {} 51 ~RenderWidgetWindowTreeClientFactoryImpl() override {}
39 52
40 private: 53 private:
41 // shell::Service implementation: 54 // ConnectionFilter implementation:
42 bool OnConnect(shell::Connection* connection) override { 55 bool OnConnect(shell::Connection* connection,
56 shell::Connector* connector) override {
43 connection->AddInterface<mojom::RenderWidgetWindowTreeClientFactory>(this); 57 connection->AddInterface<mojom::RenderWidgetWindowTreeClientFactory>(this);
44 return true; 58 return true;
45 } 59 }
46 60
47 // shell::InterfaceFactory<mojom::RenderWidgetWindowTreeClientFactory>: 61 // shell::InterfaceFactory<mojom::RenderWidgetWindowTreeClientFactory>:
48 void Create(shell::Connection* connection, 62 void Create(shell::Connection* connection,
49 mojo::InterfaceRequest<mojom::RenderWidgetWindowTreeClientFactory> 63 mojo::InterfaceRequest<mojom::RenderWidgetWindowTreeClientFactory>
50 request) override { 64 request) override {
51 bindings_.AddBinding(this, std::move(request)); 65 bindings_.AddBinding(this, std::move(request));
52 } 66 }
53 67
54 // mojom::RenderWidgetWindowTreeClientFactory implementation. 68 // mojom::RenderWidgetWindowTreeClientFactory implementation.
55 void CreateWindowTreeClientForRenderWidget( 69 void CreateWindowTreeClientForRenderWidget(
56 uint32_t routing_id, 70 uint32_t routing_id,
57 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) override { 71 ui::mojom::WindowTreeClientRequest request) override {
58 RenderWidgetMusConnection* connection = 72 main_thread_task_runner_->PostTask(
59 RenderWidgetMusConnection::GetOrCreate(routing_id); 73 FROM_HERE, base::Bind(&BindMusConnectionOnMainThread, routing_id,
60 connection->Bind(std::move(request)); 74 base::Passed(&request)));
61 } 75 }
62 76
77 scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner_;
63 mojo::BindingSet<mojom::RenderWidgetWindowTreeClientFactory> bindings_; 78 mojo::BindingSet<mojom::RenderWidgetWindowTreeClientFactory> bindings_;
64 79
65 DISALLOW_COPY_AND_ASSIGN(RenderWidgetWindowTreeClientFactoryImpl); 80 DISALLOW_COPY_AND_ASSIGN(RenderWidgetWindowTreeClientFactoryImpl);
66 }; 81 };
67 82
68 } // namespace 83 } // namespace
69 84
70 void CreateRenderWidgetWindowTreeClientFactory() { 85 void CreateRenderWidgetWindowTreeClientFactory(
71 MojoShellConnection::GetForProcess()->MergeService( 86 MojoShellConnection* connection) {
72 base::WrapUnique(new RenderWidgetWindowTreeClientFactoryImpl)); 87 connection->AddConnectionFilter(
88 base::MakeUnique<RenderWidgetWindowTreeClientFactoryImpl>());
73 } 89 }
74 90
75 } // namespace content 91 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698