| Index: chrome/browser/chromeos/chrome_interface_factory.cc
|
| diff --git a/chrome/browser/chromeos/chrome_interface_factory.cc b/chrome/browser/chromeos/chrome_interface_factory.cc
|
| index a4b334d8dcbf16edd9190bc3a48a0d2592912427..3e29eec74dc18094909b6f1a792953c8ecf5cccf 100644
|
| --- a/chrome/browser/chromeos/chrome_interface_factory.cc
|
| +++ b/chrome/browser/chromeos/chrome_interface_factory.cc
|
| @@ -4,6 +4,13 @@
|
|
|
| #include "chrome/browser/chromeos/chrome_interface_factory.h"
|
|
|
| +#include <memory>
|
| +
|
| +#include "ash/sysui/public/interfaces/wallpaper.mojom.h"
|
| +#include "base/lazy_instance.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/threading/thread_checker.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/ui/ash/app_list/app_list_presenter_service.h"
|
| @@ -11,7 +18,16 @@
|
| #include "chrome/browser/ui/ash/keyboard_ui_service.h"
|
| #include "chrome/browser/ui/browser_commands.h"
|
| #include "chrome/browser/ui/browser_finder.h"
|
| +#include "content/public/common/mojo_shell_connection.h"
|
| +#include "mash/public/interfaces/launchable.mojom.h"
|
| +#include "mojo/public/cpp/bindings/binding_set.h"
|
| #include "services/shell/public/cpp/connection.h"
|
| +#include "ui/app_list/presenter/app_list_presenter.mojom.h"
|
| +#include "ui/keyboard/keyboard.mojom.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +namespace {
|
|
|
| class ChromeLaunchable : public mash::mojom::Launchable {
|
| public:
|
| @@ -57,49 +73,92 @@ class ChromeLaunchable : public mash::mojom::Launchable {
|
| DISALLOW_COPY_AND_ASSIGN(ChromeLaunchable);
|
| };
|
|
|
| -namespace chromeos {
|
| +class FactoryImpl {
|
| + public:
|
| + FactoryImpl() {}
|
| + ~FactoryImpl() {}
|
| +
|
| + template <typename Interface>
|
| + static void AddFactory(
|
| + shell::Connection* connection,
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
|
| + connection->AddInterface<Interface>(
|
| + base::Bind(&FactoryImpl::CallMainThreadFactory<Interface>),
|
| + task_runner);
|
| + }
|
|
|
| -ChromeInterfaceFactory::ChromeInterfaceFactory() {}
|
| -ChromeInterfaceFactory::~ChromeInterfaceFactory() {}
|
| + private:
|
| + static FactoryImpl* Get() {
|
| + if (!factory_.Get())
|
| + factory_.Get().reset(new FactoryImpl);
|
| + return factory_.Get().get();
|
| + }
|
|
|
| -bool ChromeInterfaceFactory::OnConnect(shell::Connection* connection) {
|
| - connection->AddInterface<keyboard::mojom::Keyboard>(this);
|
| - connection->AddInterface<mash::mojom::Launchable>(this);
|
| - connection->AddInterface<ash::sysui::mojom::WallpaperManager>(this);
|
| - connection->AddInterface<app_list::mojom::AppListPresenter>(this);
|
| - return true;
|
| -}
|
| + template <typename Interface>
|
| + static void CallMainThreadFactory(mojo::InterfaceRequest<Interface> request) {
|
| + Get()->BindRequest(std::move(request));
|
| + }
|
|
|
| -void ChromeInterfaceFactory::Create(
|
| - shell::Connection* connection,
|
| - mojo::InterfaceRequest<keyboard::mojom::Keyboard> request) {
|
| - if (!keyboard_ui_service_)
|
| - keyboard_ui_service_.reset(new KeyboardUIService);
|
| - keyboard_bindings_.AddBinding(keyboard_ui_service_.get(), std::move(request));
|
| -}
|
| + void BindRequest(keyboard::mojom::KeyboardRequest request) {
|
| + if (!keyboard_ui_service_)
|
| + keyboard_ui_service_.reset(new KeyboardUIService);
|
| + keyboard_bindings_.AddBinding(keyboard_ui_service_.get(),
|
| + std::move(request));
|
| + }
|
|
|
| -void ChromeInterfaceFactory::Create(shell::Connection* connection,
|
| - mash::mojom::LaunchableRequest request) {
|
| - if (!launchable_)
|
| - launchable_.reset(new ChromeLaunchable);
|
| - launchable_->ProcessRequest(std::move(request));
|
| -}
|
| + void BindRequest(mash::mojom::LaunchableRequest request) {
|
| + if (!launchable_)
|
| + launchable_.reset(new ChromeLaunchable);
|
| + launchable_->ProcessRequest(std::move(request));
|
| + }
|
|
|
| -void ChromeInterfaceFactory::Create(
|
| - shell::Connection* connection,
|
| - ash::sysui::mojom::WallpaperManagerRequest request) {
|
| - if (!wallpaper_manager_)
|
| - wallpaper_manager_.reset(new ChromeWallpaperManager);
|
| - wallpaper_manager_->ProcessRequest(std::move(request));
|
| -}
|
| + void BindRequest(ash::sysui::mojom::WallpaperManagerRequest request) {
|
| + if (!wallpaper_manager_)
|
| + wallpaper_manager_.reset(new ChromeWallpaperManager);
|
| + wallpaper_manager_->ProcessRequest(std::move(request));
|
| + }
|
| +
|
| + void BindRequest(app_list::mojom::AppListPresenterRequest request) {
|
| + if (!app_list_presenter_service_)
|
| + app_list_presenter_service_.reset(new AppListPresenterService);
|
| + app_list_presenter_bindings_.AddBinding(app_list_presenter_service_.get(),
|
| + std::move(request));
|
| + }
|
| +
|
| + static base::LazyInstance<std::unique_ptr<FactoryImpl>>::Leaky factory_;
|
|
|
| -void ChromeInterfaceFactory::Create(
|
| - shell::Connection* connection,
|
| - mojo::InterfaceRequest<app_list::mojom::AppListPresenter> request) {
|
| - if (!app_list_presenter_service_)
|
| - app_list_presenter_service_.reset(new AppListPresenterService);
|
| - app_list_presenter_bindings_.AddBinding(app_list_presenter_service_.get(),
|
| - std::move(request));
|
| + std::unique_ptr<KeyboardUIService> keyboard_ui_service_;
|
| + mojo::BindingSet<keyboard::mojom::Keyboard> keyboard_bindings_;
|
| + std::unique_ptr<ChromeLaunchable> launchable_;
|
| + std::unique_ptr<ChromeWallpaperManager> wallpaper_manager_;
|
| + std::unique_ptr<AppListPresenterService> app_list_presenter_service_;
|
| + mojo::BindingSet<app_list::mojom::AppListPresenter>
|
| + app_list_presenter_bindings_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FactoryImpl);
|
| +};
|
| +
|
| +base::LazyInstance<std::unique_ptr<FactoryImpl>>::Leaky FactoryImpl::factory_ =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +} // namespace
|
| +
|
| +ChromeInterfaceFactory::ChromeInterfaceFactory()
|
| + : main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
|
| +
|
| +ChromeInterfaceFactory::~ChromeInterfaceFactory() {}
|
| +
|
| +bool ChromeInterfaceFactory::OnConnect(shell::Connection* connection,
|
| + shell::Connector* connector) {
|
| + FactoryImpl::AddFactory<keyboard::mojom::Keyboard>(
|
| + connection, main_thread_task_runner_);
|
| + FactoryImpl::AddFactory<mash::mojom::Launchable>(
|
| + connection, main_thread_task_runner_);
|
| + FactoryImpl::AddFactory<ash::sysui::mojom::WallpaperManager>(
|
| + connection, main_thread_task_runner_);
|
| + FactoryImpl::AddFactory<app_list::mojom::AppListPresenter>(
|
| + connection, main_thread_task_runner_);
|
| + return true;
|
| }
|
|
|
| } // namespace chromeos
|
|
|