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

Side by Side Diff: chrome/browser/chromeos/chrome_interface_factory.cc

Issue 2138263002: Revert of Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
14 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h" 8 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/ash/app_list/app_list_presenter_service.h" 9 #include "chrome/browser/ui/ash/app_list/app_list_presenter_service.h"
17 #include "chrome/browser/ui/ash/chrome_wallpaper_manager.h" 10 #include "chrome/browser/ui/ash/chrome_wallpaper_manager.h"
18 #include "chrome/browser/ui/ash/keyboard_ui_service.h" 11 #include "chrome/browser/ui/ash/keyboard_ui_service.h"
19 #include "chrome/browser/ui/browser_commands.h" 12 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/browser/ui/browser_finder.h" 13 #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"
24 #include "services/shell/public/cpp/connection.h" 14 #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 {
31 15
32 class ChromeLaunchable : public mash::mojom::Launchable { 16 class ChromeLaunchable : public mash::mojom::Launchable {
33 public: 17 public:
34 ChromeLaunchable() {} 18 ChromeLaunchable() {}
35 ~ChromeLaunchable() override {} 19 ~ChromeLaunchable() override {}
36 20
37 void ProcessRequest(mash::mojom::LaunchableRequest request) { 21 void ProcessRequest(mash::mojom::LaunchableRequest request) {
38 bindings_.AddBinding(this, std::move(request)); 22 bindings_.AddBinding(this, std::move(request));
39 } 23 }
40 24
(...skipping 25 matching lines...) Expand all
66 default: 50 default:
67 NOTREACHED(); 51 NOTREACHED();
68 } 52 }
69 } 53 }
70 54
71 mojo::BindingSet<mash::mojom::Launchable> bindings_; 55 mojo::BindingSet<mash::mojom::Launchable> bindings_;
72 56
73 DISALLOW_COPY_AND_ASSIGN(ChromeLaunchable); 57 DISALLOW_COPY_AND_ASSIGN(ChromeLaunchable);
74 }; 58 };
75 59
76 class FactoryImpl { 60 namespace chromeos {
77 public:
78 FactoryImpl() {}
79 ~FactoryImpl() {}
80 61
81 template <typename Interface> 62 ChromeInterfaceFactory::ChromeInterfaceFactory() {}
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
149 ChromeInterfaceFactory::~ChromeInterfaceFactory() {} 63 ChromeInterfaceFactory::~ChromeInterfaceFactory() {}
150 64
151 bool ChromeInterfaceFactory::OnConnect(shell::Connection* connection, 65 bool ChromeInterfaceFactory::OnConnect(shell::Connection* connection) {
152 shell::Connector* connector) { 66 connection->AddInterface<keyboard::mojom::Keyboard>(this);
153 FactoryImpl::AddFactory<keyboard::mojom::Keyboard>( 67 connection->AddInterface<mash::mojom::Launchable>(this);
154 connection, main_thread_task_runner_); 68 connection->AddInterface<ash::sysui::mojom::WallpaperManager>(this);
155 FactoryImpl::AddFactory<mash::mojom::Launchable>( 69 connection->AddInterface<app_list::mojom::AppListPresenter>(this);
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_);
161 return true; 70 return true;
162 } 71 }
163 72
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
164 } // namespace chromeos 105 } // 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