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

Side by Side Diff: chrome/browser/chromeos/chrome_interface_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/chromeos/chrome_interface_factory.h" 5 #include "chrome/browser/chromeos/chrome_interface_factory.h"
6 6
7 #include <memory>
8
9 #include "ash/sysui/public/interfaces/wallpaper.mojom.h"
10 #include "base/lazy_instance.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "base/threading/thread_task_runner_handle.h"
7 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/ui/ash/app_list/app_list_presenter_service.h" 16 #include "chrome/browser/ui/ash/app_list/app_list_presenter_service.h"
10 #include "chrome/browser/ui/ash/chrome_wallpaper_manager.h" 17 #include "chrome/browser/ui/ash/chrome_wallpaper_manager.h"
11 #include "chrome/browser/ui/ash/keyboard_ui_service.h" 18 #include "chrome/browser/ui/ash/keyboard_ui_service.h"
12 #include "chrome/browser/ui/browser_commands.h" 19 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
21 #include "content/public/common/mojo_shell_connection.h"
22 #include "mash/public/interfaces/launchable.mojom.h"
23 #include "mojo/public/cpp/bindings/binding_set.h"
14 #include "services/shell/public/cpp/connection.h" 24 #include "services/shell/public/cpp/connection.h"
25 #include "ui/app_list/presenter/app_list_presenter.mojom.h"
26 #include "ui/keyboard/keyboard.mojom.h"
27
28 namespace chromeos {
29
30 namespace {
15 31
16 class ChromeLaunchable : public mash::mojom::Launchable { 32 class ChromeLaunchable : public mash::mojom::Launchable {
17 public: 33 public:
18 ChromeLaunchable() {} 34 ChromeLaunchable() {}
19 ~ChromeLaunchable() override {} 35 ~ChromeLaunchable() override {}
20 36
21 void ProcessRequest(mash::mojom::LaunchableRequest request) { 37 void ProcessRequest(mash::mojom::LaunchableRequest request) {
22 bindings_.AddBinding(this, std::move(request)); 38 bindings_.AddBinding(this, std::move(request));
23 } 39 }
24 40
(...skipping 25 matching lines...) Expand all
50 default: 66 default:
51 NOTREACHED(); 67 NOTREACHED();
52 } 68 }
53 } 69 }
54 70
55 mojo::BindingSet<mash::mojom::Launchable> bindings_; 71 mojo::BindingSet<mash::mojom::Launchable> bindings_;
56 72
57 DISALLOW_COPY_AND_ASSIGN(ChromeLaunchable); 73 DISALLOW_COPY_AND_ASSIGN(ChromeLaunchable);
58 }; 74 };
59 75
60 namespace chromeos { 76 class FactoryImpl {
77 public:
78 FactoryImpl() {}
79 ~FactoryImpl() {}
61 80
62 ChromeInterfaceFactory::ChromeInterfaceFactory() {} 81 template <typename Interface>
82 static void AddFactory(
83 shell::Connection* connection,
84 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
85 connection->AddInterface<Interface>(
86 base::Bind(&FactoryImpl::CallMainThreadFactory<Interface>),
87 task_runner);
88 }
89
90 private:
91 static FactoryImpl* Get() {
92 if (!factory_.Get())
93 factory_.Get().reset(new FactoryImpl);
94 return factory_.Get().get();
95 }
96
97 template <typename Interface>
98 static void CallMainThreadFactory(mojo::InterfaceRequest<Interface> request) {
99 Get()->BindRequest(std::move(request));
100 }
101
102 void BindRequest(keyboard::mojom::KeyboardRequest request) {
103 if (!keyboard_ui_service_)
104 keyboard_ui_service_.reset(new KeyboardUIService);
105 keyboard_bindings_.AddBinding(keyboard_ui_service_.get(),
106 std::move(request));
107 }
108
109 void BindRequest(mash::mojom::LaunchableRequest request) {
110 if (!launchable_)
111 launchable_.reset(new ChromeLaunchable);
112 launchable_->ProcessRequest(std::move(request));
113 }
114
115 void BindRequest(ash::sysui::mojom::WallpaperManagerRequest request) {
116 if (!wallpaper_manager_)
117 wallpaper_manager_.reset(new ChromeWallpaperManager);
118 wallpaper_manager_->ProcessRequest(std::move(request));
119 }
120
121 void BindRequest(app_list::mojom::AppListPresenterRequest request) {
122 if (!app_list_presenter_service_)
123 app_list_presenter_service_.reset(new AppListPresenterService);
124 app_list_presenter_bindings_.AddBinding(app_list_presenter_service_.get(),
125 std::move(request));
126 }
127
128 static base::LazyInstance<std::unique_ptr<FactoryImpl>>::Leaky factory_;
129
130 std::unique_ptr<KeyboardUIService> keyboard_ui_service_;
131 mojo::BindingSet<keyboard::mojom::Keyboard> keyboard_bindings_;
132 std::unique_ptr<ChromeLaunchable> launchable_;
133 std::unique_ptr<ChromeWallpaperManager> wallpaper_manager_;
134 std::unique_ptr<AppListPresenterService> app_list_presenter_service_;
135 mojo::BindingSet<app_list::mojom::AppListPresenter>
136 app_list_presenter_bindings_;
137
138 DISALLOW_COPY_AND_ASSIGN(FactoryImpl);
139 };
140
141 base::LazyInstance<std::unique_ptr<FactoryImpl>>::Leaky FactoryImpl::factory_ =
142 LAZY_INSTANCE_INITIALIZER;
143
144 } // namespace
145
146 ChromeInterfaceFactory::ChromeInterfaceFactory()
147 : main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
148
63 ChromeInterfaceFactory::~ChromeInterfaceFactory() {} 149 ChromeInterfaceFactory::~ChromeInterfaceFactory() {}
64 150
65 bool ChromeInterfaceFactory::OnConnect(shell::Connection* connection) { 151 bool ChromeInterfaceFactory::OnConnect(shell::Connection* connection,
66 connection->AddInterface<keyboard::mojom::Keyboard>(this); 152 shell::Connector* connector) {
67 connection->AddInterface<mash::mojom::Launchable>(this); 153 FactoryImpl::AddFactory<keyboard::mojom::Keyboard>(
68 connection->AddInterface<ash::sysui::mojom::WallpaperManager>(this); 154 connection, main_thread_task_runner_);
69 connection->AddInterface<app_list::mojom::AppListPresenter>(this); 155 FactoryImpl::AddFactory<mash::mojom::Launchable>(
156 connection, main_thread_task_runner_);
157 FactoryImpl::AddFactory<ash::sysui::mojom::WallpaperManager>(
158 connection, main_thread_task_runner_);
159 FactoryImpl::AddFactory<app_list::mojom::AppListPresenter>(
160 connection, main_thread_task_runner_);
70 return true; 161 return true;
71 } 162 }
72 163
73 void ChromeInterfaceFactory::Create(
74 shell::Connection* connection,
75 mojo::InterfaceRequest<keyboard::mojom::Keyboard> request) {
76 if (!keyboard_ui_service_)
77 keyboard_ui_service_.reset(new KeyboardUIService);
78 keyboard_bindings_.AddBinding(keyboard_ui_service_.get(), std::move(request));
79 }
80
81 void ChromeInterfaceFactory::Create(shell::Connection* connection,
82 mash::mojom::LaunchableRequest request) {
83 if (!launchable_)
84 launchable_.reset(new ChromeLaunchable);
85 launchable_->ProcessRequest(std::move(request));
86 }
87
88 void ChromeInterfaceFactory::Create(
89 shell::Connection* connection,
90 ash::sysui::mojom::WallpaperManagerRequest request) {
91 if (!wallpaper_manager_)
92 wallpaper_manager_.reset(new ChromeWallpaperManager);
93 wallpaper_manager_->ProcessRequest(std::move(request));
94 }
95
96 void ChromeInterfaceFactory::Create(
97 shell::Connection* connection,
98 mojo::InterfaceRequest<app_list::mojom::AppListPresenter> request) {
99 if (!app_list_presenter_service_)
100 app_list_presenter_service_.reset(new AppListPresenterService);
101 app_list_presenter_bindings_.AddBinding(app_list_presenter_service_.get(),
102 std::move(request));
103 }
104
105 } // namespace chromeos 164 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/chrome_interface_factory.h ('k') | chrome/test/base/mash_browser_tests_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698