diff --git a/ash/autoclick/mus/autoclick_application.cc b/ash/autoclick/mus/autoclick_application.cc index 6469b79c6b041a..c66ca870997d96 100644 --- a/ash/autoclick/mus/autoclick_application.cc +++ b/ash/autoclick/mus/autoclick_application.cc @@ -77,11 +77,11 @@ AutoclickApplication::AutoclickApplication() AutoclickApplication::~AutoclickApplication() {} -void AutoclickApplication::OnStart(service_manager::ServiceContext* context) { +void AutoclickApplication::OnStart() { aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), "views_mus_resources.pak"); window_manager_connection_ = views::WindowManagerConnection::Create( - context->connector(), context->identity()); + context()->connector(), context()->identity()); autoclick_controller_common_.reset(new AutoclickControllerCommon( base::TimeDelta::FromMilliseconds(kDefaultAutoclickDelayMs), this)); } diff --git a/ash/autoclick/mus/autoclick_application.h b/ash/autoclick/mus/autoclick_application.h index 60d1fdc849c564..2314782f4908aa 100644 --- a/ash/autoclick/mus/autoclick_application.h +++ b/ash/autoclick/mus/autoclick_application.h @@ -39,7 +39,7 @@ class AutoclickApplication private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/ash/mus/window_manager_application.cc b/ash/mus/window_manager_application.cc index d12b63caed2813..83c4a9b914cbb7 100644 --- a/ash/mus/window_manager_application.cc +++ b/ash/mus/window_manager_application.cc @@ -117,27 +117,25 @@ void WindowManagerApplication::ShutdownComponents() { message_center::MessageCenter::Shutdown(); } -void WindowManagerApplication::OnStart( - service_manager::ServiceContext* context) { - context_ = context; +void WindowManagerApplication::OnStart() { aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "ash_mus_resources.pak", + context()->connector(), context()->identity(), "ash_mus_resources.pak", "ash_mus_resources_200.pak"); - gpu_service_ = ui::GpuService::Create(context->connector()); + gpu_service_ = ui::GpuService::Create(context()->connector()); compositor_context_factory_.reset( new views::SurfaceContextFactory(gpu_service_.get())); aura::Env::GetInstance()->set_context_factory( compositor_context_factory_.get()); - window_manager_.reset(new WindowManager(context->connector())); + window_manager_.reset(new WindowManager(context()->connector())); MaterialDesignController::Initialize(); - tracing_.Initialize(context->connector(), context->identity().name()); + tracing_.Initialize(context()->connector(), context()->identity().name()); std::unique_ptr window_tree_client = base::MakeUnique(window_manager_.get(), window_manager_.get()); - window_tree_client->ConnectAsWindowManager(context->connector()); + window_tree_client->ConnectAsWindowManager(context()->connector()); const size_t kMaxNumberThreads = 3u; // Matches that of content. const char kThreadNamePrefix[] = "MashBlocking"; @@ -154,7 +152,7 @@ bool WindowManagerApplication::OnConnect( registry, base::ThreadTaskRunnerHandle::Get()); if (remote_info.identity.name() == "service:mash_session") { - context_->connector()->ConnectToInterface(remote_info.identity, &session_); + context()->connector()->ConnectToInterface(remote_info.identity, &session_); session_->AddScreenlockStateListener( screenlock_state_listener_binding_.CreateInterfacePtrAndBind()); } diff --git a/ash/mus/window_manager_application.h b/ash/mus/window_manager_application.h index 9a9cf51c4fdce1..57c376eaec88cc 100644 --- a/ash/mus/window_manager_application.h +++ b/ash/mus/window_manager_application.h @@ -29,10 +29,6 @@ class ScopedFakeStatisticsProvider; } } -namespace service_manager { -class ServiceContext; -} - namespace views { class AuraInit; class SurfaceContextFactory; @@ -76,15 +72,13 @@ class WindowManagerApplication void ShutdownComponents(); // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; // session::mojom::ScreenlockStateListener: void ScreenlockStateChanged(bool locked) override; - service_manager::ServiceContext* context_ = nullptr; - tracing::Provider tracing_; std::unique_ptr aura_init_; diff --git a/ash/touch_hud/mus/touch_hud_application.cc b/ash/touch_hud/mus/touch_hud_application.cc index 03e01fc4484b05..d6ab7cb2ec8768 100644 --- a/ash/touch_hud/mus/touch_hud_application.cc +++ b/ash/touch_hud/mus/touch_hud_application.cc @@ -67,11 +67,11 @@ class TouchHudUI : public views::WidgetDelegateView, TouchHudApplication::TouchHudApplication() : binding_(this) {} TouchHudApplication::~TouchHudApplication() {} -void TouchHudApplication::OnStart(service_manager::ServiceContext* context) { +void TouchHudApplication::OnStart() { aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), "views_mus_resources.pak"); window_manager_connection_ = views::WindowManagerConnection::Create( - context->connector(), context->identity()); + context()->connector(), context()->identity()); } bool TouchHudApplication::OnConnect( diff --git a/ash/touch_hud/mus/touch_hud_application.h b/ash/touch_hud/mus/touch_hud_application.h index 78a340973784b0..43ebfed3c23430 100644 --- a/ash/touch_hud/mus/touch_hud_application.h +++ b/ash/touch_hud/mus/touch_hud_application.h @@ -32,7 +32,7 @@ class TouchHudApplication private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/components/filesystem/file_system_app.cc b/components/filesystem/file_system_app.cc index 203c4d2a173987..ac41d092048ea3 100644 --- a/components/filesystem/file_system_app.cc +++ b/components/filesystem/file_system_app.cc @@ -42,8 +42,8 @@ FileSystemApp::FileSystemApp() : lock_table_(new LockTable) {} FileSystemApp::~FileSystemApp() {} -void FileSystemApp::OnStart(service_manager::ServiceContext* context) { - tracing_.Initialize(context->connector(), context->identity().name()); +void FileSystemApp::OnStart() { + tracing_.Initialize(context()->connector(), context()->identity().name()); } bool FileSystemApp::OnConnect(const service_manager::ServiceInfo& remote_info, diff --git a/components/filesystem/file_system_app.h b/components/filesystem/file_system_app.h index ee05f037201c50..53ea98d976cc12 100644 --- a/components/filesystem/file_system_app.h +++ b/components/filesystem/file_system_app.h @@ -32,7 +32,7 @@ class FileSystemApp static base::FilePath GetUserDataDir(); // |service_manager::Service| override: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/components/font_service/font_service_app.cc b/components/font_service/font_service_app.cc index bd9f49074ff3ad..f78b4c23b93129 100644 --- a/components/font_service/font_service_app.cc +++ b/components/font_service/font_service_app.cc @@ -50,8 +50,8 @@ FontServiceApp::FontServiceApp() {} FontServiceApp::~FontServiceApp() {} -void FontServiceApp::OnStart(service_manager::ServiceContext* context) { - tracing_.Initialize(context->connector(), context->identity().name()); +void FontServiceApp::OnStart() { + tracing_.Initialize(context()->connector(), context()->identity().name()); } bool FontServiceApp::OnConnect(const service_manager::ServiceInfo& remote_info, diff --git a/components/font_service/font_service_app.h b/components/font_service/font_service_app.h index 5d15905bc2a181..39f2d33db95a78 100644 --- a/components/font_service/font_service_app.h +++ b/components/font_service/font_service_app.h @@ -28,7 +28,7 @@ class FontServiceApp private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/components/leveldb/leveldb_app.cc b/components/leveldb/leveldb_app.cc index a8402408755dbf..cff8bc3374ffe5 100644 --- a/components/leveldb/leveldb_app.cc +++ b/components/leveldb/leveldb_app.cc @@ -15,8 +15,8 @@ LevelDBApp::LevelDBApp() {} LevelDBApp::~LevelDBApp() {} -void LevelDBApp::OnStart(service_manager::ServiceContext* context) { - tracing_.Initialize(context->connector(), context->identity().name()); +void LevelDBApp::OnStart() { + tracing_.Initialize(context()->connector(), context()->identity().name()); } bool LevelDBApp::OnConnect(const service_manager::ServiceInfo& remote_info, diff --git a/components/leveldb/leveldb_app.h b/components/leveldb/leveldb_app.h index 0968359503f96b..fcaa15f603cdf6 100644 --- a/components/leveldb/leveldb_app.h +++ b/components/leveldb/leveldb_app.h @@ -24,7 +24,7 @@ class LevelDBApp private: // |Service| override: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/content/common/service_manager/service_manager_connection_impl.cc b/content/common/service_manager/service_manager_connection_impl.cc index 971cfdd8f73239..ac6d1f6fccbd57 100644 --- a/content/common/service_manager/service_manager_connection_impl.cc +++ b/content/common/service_manager/service_manager_connection_impl.cc @@ -127,34 +127,6 @@ class ServiceManagerConnectionImpl::IOThreadContext private: friend class base::RefCountedThreadSafe; - // A forwarding service_manager::Service implementation to account for the - // fact that IOThreadContext is a Service which owns its ServiceContext, but - // ServiceContext should own its Service. - // - // TODO(rockot): Clean this up. - class ForwardingServiceImpl : public service_manager::Service { - public: - explicit ForwardingServiceImpl(service_manager::Service* service) - : service_(service) {} - ~ForwardingServiceImpl() override {} - - // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override { - service_->OnStart(context); - } - - bool OnConnect(const service_manager::ServiceInfo& remote_info, - service_manager::InterfaceRegistry* registry) override { - return service_->OnConnect(remote_info, registry); - } - - bool OnStop() override { return service_->OnStop(); } - - private: - service_manager::Service* const service_; - DISALLOW_COPY_AND_ASSIGN(ForwardingServiceImpl); - }; - class MessageLoopObserver : public base::MessageLoop::DestructionObserver { public: explicit MessageLoopObserver(base::WeakPtr context) @@ -197,7 +169,7 @@ class ServiceManagerConnectionImpl::IOThreadContext // Should bind |io_thread_checker_| to the context's thread. DCHECK(io_thread_checker_.CalledOnValidThread()); service_context_.reset(new service_manager::ServiceContext( - base::MakeUnique(this), + base::MakeUnique(this), std::move(pending_service_request_), std::move(io_thread_connector_), std::move(pending_connector_request_))); @@ -251,10 +223,10 @@ class ServiceManagerConnectionImpl::IOThreadContext ///////////////////////////////////////////////////////////////////////////// // service_manager::Service implementation - void OnStart(service_manager::ServiceContext* context) override { + void OnStart() override { DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK(!initialize_handler_.is_null()); - local_info_ = context->local_info(); + local_info_ = context()->local_info(); InitializeCallback handler = base::ResetAndReturn(&initialize_handler_); callback_task_runner_->PostTask(FROM_HERE, diff --git a/mash/browser/browser.cc b/mash/browser/browser.cc index 816afb0d6a7065..9b5cb22c2a9d21 100644 --- a/mash/browser/browser.cc +++ b/mash/browser/browser.cc @@ -865,18 +865,17 @@ void Browser::RemoveWindow(views::Widget* window) { std::unique_ptr Browser::CreateView() { navigation::mojom::ViewFactoryPtr factory; - context_->connector()->ConnectToInterface("exe:navigation", &factory); + context()->connector()->ConnectToInterface("exe:navigation", &factory); return base::MakeUnique(std::move(factory)); } -void Browser::OnStart(service_manager::ServiceContext* context) { - context_ = context; - tracing_.Initialize(context->connector(), context->identity().name()); +void Browser::OnStart() { + tracing_.Initialize(context()->connector(), context()->identity().name()); aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), "views_mus_resources.pak"); window_manager_connection_ = views::WindowManagerConnection::Create( - context->connector(), context->identity()); + context()->connector(), context()->identity()); } bool Browser::OnConnect(const service_manager::ServiceInfo& remote_info, diff --git a/mash/browser/browser.h b/mash/browser/browser.h index f9fc353531d2d3..2428b47af72fe6 100644 --- a/mash/browser/browser.h +++ b/mash/browser/browser.h @@ -18,10 +18,6 @@ namespace navigation { class View; } -namespace service_manager { -class ServiceContext; -} - namespace views { class AuraInit; class Widget; @@ -48,7 +44,7 @@ class Browser : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; @@ -59,8 +55,6 @@ class Browser : public service_manager::Service, void Create(const service_manager::Identity& remote_identity, mojom::LaunchableRequest request) override; - service_manager::ServiceContext* context_ = nullptr; - mojo::BindingSet bindings_; std::vector windows_; diff --git a/mash/catalog_viewer/catalog_viewer.cc b/mash/catalog_viewer/catalog_viewer.cc index c2adf45d3510cd..73cbcfc09e40d2 100644 --- a/mash/catalog_viewer/catalog_viewer.cc +++ b/mash/catalog_viewer/catalog_viewer.cc @@ -217,14 +217,13 @@ void CatalogViewer::RemoveWindow(views::Widget* window) { base::MessageLoop::current()->QuitWhenIdle(); } -void CatalogViewer::OnStart(service_manager::ServiceContext* context) { - context_ = context; - tracing_.Initialize(context->connector(), context->identity().name()); +void CatalogViewer::OnStart() { + tracing_.Initialize(context()->connector(), context()->identity().name()); aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), "views_mus_resources.pak"); window_manager_connection_ = views::WindowManagerConnection::Create( - context->connector(), context->identity()); + context()->connector(), context()->identity()); } bool CatalogViewer::OnConnect(const service_manager::ServiceInfo& remote_info, @@ -241,7 +240,7 @@ void CatalogViewer::Launch(uint32_t what, mojom::LaunchMode how) { return; } catalog::mojom::CatalogPtr catalog; - context_->connector()->ConnectToInterface("service:catalog", &catalog); + context()->connector()->ConnectToInterface("service:catalog", &catalog); views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( new CatalogViewerContents(this, std::move(catalog)), nullptr, diff --git a/mash/catalog_viewer/catalog_viewer.h b/mash/catalog_viewer/catalog_viewer.h index b527b992589117..afc59d2bdde64f 100644 --- a/mash/catalog_viewer/catalog_viewer.h +++ b/mash/catalog_viewer/catalog_viewer.h @@ -16,10 +16,6 @@ #include "services/service_manager/public/cpp/service.h" #include "services/tracing/public/cpp/provider.h" -namespace service_manager { -class ServiceContext; -} - namespace views { class AuraInit; class Widget; @@ -41,7 +37,7 @@ class CatalogViewer private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; @@ -52,8 +48,6 @@ class CatalogViewer void Create(const service_manager::Identity& remote_identity, mojom::LaunchableRequest request) override; - service_manager::ServiceContext* context_ = nullptr; - mojo::BindingSet bindings_; std::vector windows_; diff --git a/mash/example/views_examples/views_examples.cc b/mash/example/views_examples/views_examples.cc index 7c3380eccaecc1..43b82f26203016 100644 --- a/mash/example/views_examples/views_examples.cc +++ b/mash/example/views_examples/views_examples.cc @@ -37,12 +37,13 @@ class ViewsExamples private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override { - tracing_.Initialize(context->connector(), context->identity().name()); + void OnStart() override { + tracing_.Initialize(context()->connector(), context()->identity().name()); aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), + "views_mus_resources.pak"); window_manager_connection_ = views::WindowManagerConnection::Create( - context->connector(), context->identity()); + context()->connector(), context()->identity()); } bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override { diff --git a/mash/example/window_type_launcher/window_type_launcher.cc b/mash/example/window_type_launcher/window_type_launcher.cc index c650f06cbbacfc..dba68c410fc587 100644 --- a/mash/example/window_type_launcher/window_type_launcher.cc +++ b/mash/example/window_type_launcher/window_type_launcher.cc @@ -473,10 +473,9 @@ void WindowTypeLauncher::RemoveWindow(views::Widget* window) { base::MessageLoop::current()->QuitWhenIdle(); } -void WindowTypeLauncher::OnStart(service_manager::ServiceContext* context) { - context_ = context; +void WindowTypeLauncher::OnStart() { aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak", + context()->connector(), context()->identity(), "views_mus_resources.pak", std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); } @@ -496,7 +495,7 @@ void WindowTypeLauncher::Launch(uint32_t what, mash::mojom::LaunchMode how) { } views::Widget* window = new views::Widget; views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); - params.delegate = new WindowTypeLauncherView(this, context_->connector()); + params.delegate = new WindowTypeLauncherView(this, context()->connector()); window->Init(params); window->Show(); windows_.push_back(window); diff --git a/mash/example/window_type_launcher/window_type_launcher.h b/mash/example/window_type_launcher/window_type_launcher.h index b1663a68e40052..bee66f16f87976 100644 --- a/mash/example/window_type_launcher/window_type_launcher.h +++ b/mash/example/window_type_launcher/window_type_launcher.h @@ -13,10 +13,6 @@ #include "services/service_manager/public/cpp/interface_factory.h" #include "services/service_manager/public/cpp/service.h" -namespace service_manager { -class ServiceContext; -} - namespace views { class AuraInit; class Widget; @@ -34,7 +30,7 @@ class WindowTypeLauncher private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; @@ -45,8 +41,6 @@ class WindowTypeLauncher void Create(const service_manager::Identity& remote_identity, mash::mojom::LaunchableRequest request) override; - service_manager::ServiceContext* context_ = nullptr; - mojo::BindingSet bindings_; std::vector windows_; diff --git a/mash/init/init.cc b/mash/init/init.cc index 2789820606aafb..a167bf7c4af201 100644 --- a/mash/init/init.cc +++ b/mash/init/init.cc @@ -19,9 +19,8 @@ namespace init { Init::Init() {} Init::~Init() {} -void Init::OnStart(service_manager::ServiceContext* context) { - context_ = context; - context->connector()->Connect("service:ui"); +void Init::OnStart() { + context()->connector()->Connect("service:ui"); StartTracing(); StartLogin(); } @@ -37,7 +36,7 @@ void Init::StartService(const std::string& name, const std::string& user_id) { service_manager::Connector::ConnectParams params( service_manager::Identity(name, user_id)); std::unique_ptr connection = - context_->connector()->Connect(¶ms); + context()->connector()->Connect(¶ms); connection->SetConnectionLostClosure( base::Bind(&Init::UserServiceQuit, base::Unretained(this), user_id)); user_services_[user_id] = std::move(connection); @@ -62,11 +61,11 @@ void Init::UserServiceQuit(const std::string& user_id) { } void Init::StartTracing() { - context_->connector()->Connect("service:tracing"); + context()->connector()->Connect("service:tracing"); } void Init::StartLogin() { - login_connection_ = context_->connector()->Connect("service:login"); + login_connection_ = context()->connector()->Connect("service:login"); mash::login::mojom::LoginPtr login; login_connection_->GetInterface(&login); login->ShowLoginUI(); diff --git a/mash/init/init.h b/mash/init/init.h index e1987a9b6aceee..71782d256aaef3 100644 --- a/mash/init/init.h +++ b/mash/init/init.h @@ -18,7 +18,6 @@ namespace service_manager { class Connection; -class ServiceContext; } namespace mash { @@ -33,7 +32,7 @@ class Init : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; @@ -51,8 +50,6 @@ class Init : public service_manager::Service, void StartTracing(); void StartLogin(); - service_manager::ServiceContext* context_ = nullptr; - std::unique_ptr login_connection_; mojo::BindingSet init_bindings_; std::map> diff --git a/mash/login/login.cc b/mash/login/login.cc index deec2e09ee9556..67954443ffb69c 100644 --- a/mash/login/login.cc +++ b/mash/login/login.cc @@ -144,22 +144,22 @@ class Login : public service_manager::Service, void LoginAs(const std::string& user_id) { user_access_manager_->SetActiveUser(user_id); mash::init::mojom::InitPtr init; - context_->connector()->ConnectToInterface("service:mash_init", &init); + context()->connector()->ConnectToInterface("service:mash_init", &init); init->StartService("service:mash_session", user_id); } private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override { - context_ = context; - tracing_.Initialize(context->connector(), context->identity().name()); + void OnStart() override { + tracing_.Initialize(context()->connector(), context()->identity().name()); aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), + "views_mus_resources.pak"); - context->connector()->ConnectToInterface( + context()->connector()->ConnectToInterface( "service:ui", &user_access_manager_); - user_access_manager_->SetActiveUser(context->identity().user_id()); + user_access_manager_->SetActiveUser(context()->identity().user_id()); } bool OnConnect(const service_manager::ServiceInfo& remote_info, @@ -176,16 +176,14 @@ class Login : public service_manager::Service, // mojom::Login: void ShowLoginUI() override { - UI::Show(context_->connector(), context_->identity(), this); + UI::Show(context()->connector(), context()->identity(), this); } void SwitchUser() override { - UI::Show(context_->connector(), context_->identity(), this); + UI::Show(context()->connector(), context()->identity(), this); } void StartWindowManager(); - service_manager::ServiceContext* context_ = nullptr; - tracing::Provider tracing_; std::unique_ptr aura_init_; mojo::BindingSet bindings_; diff --git a/mash/quick_launch/quick_launch.cc b/mash/quick_launch/quick_launch.cc index c8bcbbfdd7c2d2..21f3dc92e0c099 100644 --- a/mash/quick_launch/quick_launch.cc +++ b/mash/quick_launch/quick_launch.cc @@ -166,14 +166,13 @@ void QuickLaunch::RemoveWindow(views::Widget* window) { base::MessageLoop::current()->QuitWhenIdle(); } -void QuickLaunch::OnStart(service_manager::ServiceContext* context) { - context_ = context; - tracing_.Initialize(context->connector(), context->identity().name()); +void QuickLaunch::OnStart() { + tracing_.Initialize(context()->connector(), context()->identity().name()); aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), "views_mus_resources.pak"); window_manager_connection_ = views::WindowManagerConnection::Create( - context->connector(), context->identity()); + context()->connector(), context()->identity()); Launch(mojom::kWindow, mojom::LaunchMode::MAKE_NEW); } @@ -192,10 +191,10 @@ void QuickLaunch::Launch(uint32_t what, mojom::LaunchMode how) { return; } catalog::mojom::CatalogPtr catalog; - context_->connector()->ConnectToInterface("service:catalog", &catalog); + context()->connector()->ConnectToInterface("service:catalog", &catalog); views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( - new QuickLaunchUI(this, context_->connector(), std::move(catalog)), + new QuickLaunchUI(this, context()->connector(), std::move(catalog)), nullptr, gfx::Rect(10, 640, 0, 0)); window->Show(); windows_.push_back(window); diff --git a/mash/quick_launch/quick_launch.h b/mash/quick_launch/quick_launch.h index ae0e6409ce2499..e4848756ce7a0e 100644 --- a/mash/quick_launch/quick_launch.h +++ b/mash/quick_launch/quick_launch.h @@ -14,10 +14,6 @@ #include "services/service_manager/public/cpp/service.h" #include "services/tracing/public/cpp/provider.h" -namespace service_manager { -class ServiceContext; -} - namespace views { class AuraInit; class Widget; @@ -39,7 +35,7 @@ class QuickLaunch private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; @@ -50,8 +46,6 @@ class QuickLaunch void Create(const service_manager::Identity& remote_identity, mojom::LaunchableRequest request) override; - service_manager::ServiceContext* context_ = nullptr; - mojo::BindingSet bindings_; std::vector windows_; diff --git a/mash/screenlock/screenlock.cc b/mash/screenlock/screenlock.cc index 895c32a6b8f6c9..2a47278398cfe6 100644 --- a/mash/screenlock/screenlock.cc +++ b/mash/screenlock/screenlock.cc @@ -75,23 +75,23 @@ class ScreenlockView : public views::WidgetDelegateView, Screenlock::Screenlock() {} Screenlock::~Screenlock() {} -void Screenlock::OnStart(service_manager::ServiceContext* context) { - tracing_.Initialize(context->connector(), context->identity().name()); +void Screenlock::OnStart() { + tracing_.Initialize(context()->connector(), context()->identity().name()); mash::session::mojom::SessionPtr session; - context->connector()->ConnectToInterface("service:mash_session", &session); + context()->connector()->ConnectToInterface("service:mash_session", &session); session->AddScreenlockStateListener( bindings_.CreateInterfacePtrAndBind(this)); aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), "views_mus_resources.pak"); window_manager_connection_ = views::WindowManagerConnection::Create( - context->connector(), context->identity()); + context()->connector(), context()->identity()); views::Widget* widget = new views::Widget; views::Widget::InitParams params( views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.delegate = new ScreenlockView(context->connector()); + params.delegate = new ScreenlockView(context()->connector()); std::map> properties; properties[ui::mojom::WindowManager::kInitialContainerId_Property] = diff --git a/mash/screenlock/screenlock.h b/mash/screenlock/screenlock.h index a0d6f5d71d638b..bf68971369de74 100644 --- a/mash/screenlock/screenlock.h +++ b/mash/screenlock/screenlock.h @@ -30,7 +30,7 @@ class Screenlock : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/mash/session/session.cc b/mash/session/session.cc index a4640efb4fe93f..f10b3535fce516 100644 --- a/mash/session/session.cc +++ b/mash/session/session.cc @@ -29,14 +29,12 @@ namespace session { Session::Session() : screen_locked_(false) {} Session::~Session() {} -void Session::OnStart(service_manager::ServiceContext* context) { - context_ = context; - +void Session::OnStart() { StartWindowManager(); StartQuickLaunch(); // Launch a chrome window for dev convience; don't do this in the long term. - context->connector()->Connect("service:content_browser"); + context()->connector()->Connect("service:content_browser"); } bool Session::OnConnect(const service_manager::ServiceInfo& remote_info, @@ -49,7 +47,7 @@ void Session::Logout() { // TODO(beng): Notify connected listeners that login is happening, potentially // give them the option to stop it. mash::login::mojom::LoginPtr login; - context_->connector()->ConnectToInterface("service:login", &login); + context()->connector()->ConnectToInterface("service:login", &login); login->ShowLoginUI(); // This kills the user environment. base::MessageLoop::current()->QuitWhenIdle(); @@ -57,7 +55,7 @@ void Session::Logout() { void Session::SwitchUser() { mash::login::mojom::LoginPtr login; - context_->connector()->ConnectToInterface("service:login", &login); + context()->connector()->ConnectToInterface("service:login", &login); login->SwitchUser(); } @@ -126,7 +124,7 @@ void Session::StartRestartableService( // TODO(beng): This would be the place to insert logic that counted restarts // to avoid infinite crash-restart loops. std::unique_ptr connection = - context_->connector()->Connect(url); + context()->connector()->Connect(url); // Note: |connection| may be null if we've lost our connection to the service // manager. if (connection) { diff --git a/mash/session/session.h b/mash/session/session.h index 211387332757be..576492b102c166 100644 --- a/mash/session/session.h +++ b/mash/session/session.h @@ -18,7 +18,6 @@ namespace service_manager { class Connection; -class ServiceContext; } namespace mash { @@ -33,7 +32,7 @@ class Session : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; @@ -60,8 +59,6 @@ class Session : public service_manager::Service, void StartRestartableService(const std::string& url, const base::Closure& restart_callback); - service_manager::ServiceContext* context_ = nullptr; - std::map> connections_; bool screen_locked_; diff --git a/mash/task_viewer/task_viewer.cc b/mash/task_viewer/task_viewer.cc index 1950037f2aec59..f48a56b28fec86 100644 --- a/mash/task_viewer/task_viewer.cc +++ b/mash/task_viewer/task_viewer.cc @@ -289,15 +289,13 @@ void TaskViewer::RemoveWindow(views::Widget* widget) { base::MessageLoop::current()->QuitWhenIdle(); } -void TaskViewer::OnStart(service_manager::ServiceContext* context) { - context_ = context; - - tracing_.Initialize(context->connector(), context->identity().name()); +void TaskViewer::OnStart() { + tracing_.Initialize(context()->connector(), context()->identity().name()); aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), "views_mus_resources.pak"); window_manager_connection_ = views::WindowManagerConnection::Create( - context->connector(), context->identity()); + context()->connector(), context()->identity()); } bool TaskViewer::OnConnect(const service_manager::ServiceInfo& remote_info, @@ -315,7 +313,7 @@ void TaskViewer::Launch(uint32_t what, mojom::LaunchMode how) { } service_manager::mojom::ServiceManagerPtr service_manager; - context_->connector()->ConnectToInterface( + context()->connector()->ConnectToInterface( "service:service_manager", &service_manager); service_manager::mojom::ServiceManagerListenerPtr listener; @@ -324,7 +322,7 @@ void TaskViewer::Launch(uint32_t what, mojom::LaunchMode how) { service_manager->AddListener(std::move(listener)); catalog::mojom::CatalogPtr catalog; - context_->connector()->ConnectToInterface("service:catalog", &catalog); + context()->connector()->ConnectToInterface("service:catalog", &catalog); TaskViewerContents* task_viewer = new TaskViewerContents( this, std::move(request), std::move(catalog)); diff --git a/mash/task_viewer/task_viewer.h b/mash/task_viewer/task_viewer.h index 1f94aaa04f3407..1190c34d9d0822 100644 --- a/mash/task_viewer/task_viewer.h +++ b/mash/task_viewer/task_viewer.h @@ -16,10 +16,6 @@ #include "services/service_manager/public/cpp/service.h" #include "services/tracing/public/cpp/provider.h" -namespace service_manager { -class ServiceContext; -} - namespace views { class AuraInit; class Widget; @@ -40,7 +36,7 @@ class TaskViewer : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; @@ -51,8 +47,6 @@ class TaskViewer : public service_manager::Service, void Create(const service_manager::Identity& remote_identity, mojom::LaunchableRequest request) override; - service_manager::ServiceContext* context_ = nullptr; - mojo::BindingSet bindings_; std::vector windows_; diff --git a/mash/webtest/webtest.cc b/mash/webtest/webtest.cc index 83958647191bf3..6f182a80af2a3d 100644 --- a/mash/webtest/webtest.cc +++ b/mash/webtest/webtest.cc @@ -158,14 +158,12 @@ void Webtest::RemoveWindow(views::Widget* window) { base::MessageLoop::current()->QuitWhenIdle(); } -void Webtest::OnStart(service_manager::ServiceContext* context) { - context_ = context; - - tracing_.Initialize(context->connector(), context->identity().name()); +void Webtest::OnStart() { + tracing_.Initialize(context()->connector(), context()->identity().name()); aura_init_ = base::MakeUnique( - context->connector(), context->identity(), "views_mus_resources.pak"); + context()->connector(), context()->identity(), "views_mus_resources.pak"); window_manager_connection_ = views::WindowManagerConnection::Create( - context->connector(), context->identity()); + context()->connector(), context()->identity()); } bool Webtest::OnConnect(const service_manager::ServiceInfo& remote_info, @@ -183,7 +181,7 @@ void Webtest::Launch(uint32_t what, mojom::LaunchMode how) { } navigation::mojom::ViewFactoryPtr view_factory; - context_->connector()->ConnectToInterface("exe:navigation", &view_factory); + context()->connector()->ConnectToInterface("exe:navigation", &view_factory); navigation::mojom::ViewPtr view; navigation::mojom::ViewClientPtr view_client; navigation::mojom::ViewClientRequest view_client_request = diff --git a/mash/webtest/webtest.h b/mash/webtest/webtest.h index d5012e374d1d7a..3a54053a22769c 100644 --- a/mash/webtest/webtest.h +++ b/mash/webtest/webtest.h @@ -14,10 +14,6 @@ #include "services/service_manager/public/cpp/service.h" #include "services/tracing/public/cpp/provider.h" -namespace service_manager { -class ServiceContext; -} - namespace views { class AuraInit; class Widget; @@ -39,7 +35,7 @@ class Webtest : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; @@ -50,8 +46,6 @@ class Webtest : public service_manager::Service, void Create(const service_manager::Identity& remote_identity, mojom::LaunchableRequest request) override; - service_manager::ServiceContext* context_ = nullptr; - mojo::BindingSet bindings_; std::vector windows_; diff --git a/media/mojo/services/media_service.cc b/media/mojo/services/media_service.cc index aa922d5b4a1296..7463d27b7e90b5 100644 --- a/media/mojo/services/media_service.cc +++ b/media/mojo/services/media_service.cc @@ -25,10 +25,10 @@ MediaService::MediaService(std::unique_ptr mojo_media_client) MediaService::~MediaService() {} -void MediaService::OnStart(service_manager::ServiceContext* context) { +void MediaService::OnStart() { ref_factory_.reset(new service_manager::ServiceContextRefFactory( base::Bind(&service_manager::ServiceContext::RequestQuit, - base::Unretained(context)))); + base::Unretained(context())))); mojo_media_client_->Initialize(); } diff --git a/media/mojo/services/media_service.h b/media/mojo/services/media_service.h index 7a39a7e504f190..52abaff674b941 100644 --- a/media/mojo/services/media_service.h +++ b/media/mojo/services/media_service.h @@ -38,7 +38,7 @@ class MEDIA_MOJO_EXPORT MediaService private: // service_manager::Service implementation. - void OnStart(service_manager::ServiceContext* context) final; + void OnStart() final; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) final; bool OnStop() final; diff --git a/services/device/device_service.cc b/services/device/device_service.cc index acf5f7b6c4a85d..924c8039e7f524 100644 --- a/services/device/device_service.cc +++ b/services/device/device_service.cc @@ -22,7 +22,7 @@ DeviceService::DeviceService( DeviceService::~DeviceService() {} -void DeviceService::OnStart(service_manager::ServiceContext* context) {} +void DeviceService::OnStart() {} bool DeviceService::OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) { diff --git a/services/device/device_service.h b/services/device/device_service.h index b1e9e49ca7499f..6f55953f91b6b2 100644 --- a/services/device/device_service.h +++ b/services/device/device_service.h @@ -24,7 +24,7 @@ class DeviceService : public service_manager::Service { private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/services/file/file_service.cc b/services/file/file_service.cc index 4e844209c4fa27..c469fac960480e 100644 --- a/services/file/file_service.cc +++ b/services/file/file_service.cc @@ -89,9 +89,9 @@ FileService::~FileService() { leveldb_service_runner_->DeleteSoon(FROM_HERE, leveldb_objects_.release()); } -void FileService::OnStart(service_manager::ServiceContext* context) { +void FileService::OnStart() { file_system_objects_.reset(new FileService::FileSystemObjects( - GetUserDirForUserId(context->identity().user_id()))); + GetUserDirForUserId(context()->identity().user_id()))); leveldb_objects_.reset( new FileService::LevelDBServiceObjects(leveldb_service_runner_)); } diff --git a/services/file/file_service.h b/services/file/file_service.h index f9303ea351f301..357aa88dc6377d 100644 --- a/services/file/file_service.h +++ b/services/file/file_service.h @@ -32,7 +32,7 @@ class FileService private: // |Service| override: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/services/image_decoder/image_decoder_service.cc b/services/image_decoder/image_decoder_service.cc index ddfbf93d346711..5295e25299989e 100644 --- a/services/image_decoder/image_decoder_service.cc +++ b/services/image_decoder/image_decoder_service.cc @@ -39,10 +39,10 @@ std::unique_ptr ImageDecoderService::Create() { return base::MakeUnique(); } -void ImageDecoderService::OnStart(service_manager::ServiceContext* context) { +void ImageDecoderService::OnStart() { ref_factory_.reset(new service_manager::ServiceContextRefFactory( base::Bind(&service_manager::ServiceContext::RequestQuit, - base::Unretained(context)))); + base::Unretained(context())))); } bool ImageDecoderService::OnConnect( diff --git a/services/image_decoder/image_decoder_service.h b/services/image_decoder/image_decoder_service.h index 2f4643f7555cc1..4babc6d1b94602 100644 --- a/services/image_decoder/image_decoder_service.h +++ b/services/image_decoder/image_decoder_service.h @@ -23,7 +23,7 @@ class ImageDecoderService : public service_manager::Service { static std::unique_ptr Create(); // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; bool OnStop() override; diff --git a/services/navigation/navigation.cc b/services/navigation/navigation.cc index 6fe4f700b6584e..d5c2c70fd6013c 100644 --- a/services/navigation/navigation.cc +++ b/services/navigation/navigation.cc @@ -44,10 +44,6 @@ Navigation::Navigation() } Navigation::~Navigation() {} -void Navigation::OnStart(service_manager::ServiceContext* context) { - context_ = context; -} - bool Navigation::OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) { std::string remote_user_id = remote_info.identity.user_id(); @@ -66,7 +62,7 @@ bool Navigation::OnConnect(const service_manager::ServiceInfo& remote_info, void Navigation::CreateView(mojom::ViewClientPtr client, mojom::ViewRequest request) { std::unique_ptr new_connector = - context_->connector()->Clone(); + context()->connector()->Clone(); std::unique_ptr context_ref = ref_factory_.CreateRef(); view_task_runner_->PostTask( diff --git a/services/navigation/navigation.h b/services/navigation/navigation.h index ba2ec84c9cf459..a48a91b64f28eb 100644 --- a/services/navigation/navigation.h +++ b/services/navigation/navigation.h @@ -30,7 +30,6 @@ class Navigation : public service_manager::Service, public mojom::ViewFactory { private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; @@ -43,8 +42,6 @@ class Navigation : public service_manager::Service, public mojom::ViewFactory { scoped_refptr view_task_runner_; - service_manager::ServiceContext* context_; - std::string client_user_id_; service_manager::ServiceContextRefFactory ref_factory_; diff --git a/services/service_manager/public/cpp/lib/service.cc b/services/service_manager/public/cpp/lib/service.cc index 7d0d72a269cc14..c9d85ce73032fd 100644 --- a/services/service_manager/public/cpp/lib/service.cc +++ b/services/service_manager/public/cpp/lib/service.cc @@ -4,12 +4,43 @@ #include "services/service_manager/public/cpp/service.h" +#include "base/logging.h" + namespace service_manager { -Service::~Service() {} +Service::Service() = default; + +Service::~Service() = default; + +void Service::OnStart() {} -void Service::OnStart(ServiceContext* context) {} +bool Service::OnConnect(const ServiceInfo& remote_info, + InterfaceRegistry* registry) { + return false; +} bool Service::OnStop() { return true; } +ServiceContext* Service::context() const { + DCHECK(service_context_) + << "Service::context() may only be called during or after OnStart()."; + return service_context_; +} + +ForwardingService::ForwardingService(Service* target) : target_(target) {} + +ForwardingService::~ForwardingService() {} + +void ForwardingService::OnStart() { + target_->set_context(context()); + target_->OnStart(); +} + +bool ForwardingService::OnConnect(const ServiceInfo& remote_info, + InterfaceRegistry* registry) { + return target_->OnConnect(remote_info, registry); +} + +bool ForwardingService::OnStop() { return target_->OnStop(); } + } // namespace service_manager diff --git a/services/service_manager/public/cpp/lib/service_context.cc b/services/service_manager/public/cpp/lib/service_context.cc index d95d60629ee2e6..d2997a67cecb19 100644 --- a/services/service_manager/public/cpp/lib/service_context.cc +++ b/services/service_manager/public/cpp/lib/service_context.cc @@ -81,7 +81,9 @@ void ServiceContext::OnStart(const ServiceInfo& info, local_info_ = info; callback.Run(std::move(pending_connector_request_), mojo::GetProxy(&service_control_, binding_.associated_group())); - service_->OnStart(this); + + service_->set_context(this); + service_->OnStart(); } void ServiceContext::OnConnect( diff --git a/services/service_manager/public/cpp/lib/service_test.cc b/services/service_manager/public/cpp/lib/service_test.cc index 664756912f1c7e..4031c0c5e3eeec 100644 --- a/services/service_manager/public/cpp/lib/service_test.cc +++ b/services/service_manager/public/cpp/lib/service_test.cc @@ -18,9 +18,9 @@ ServiceTestClient::ServiceTestClient(ServiceTest* test) : test_(test) {} ServiceTestClient::~ServiceTestClient() {} -void ServiceTestClient::OnStart(ServiceContext* context) { - test_->OnStartCalled(context->connector(), context->identity().name(), - context->identity().user_id()); +void ServiceTestClient::OnStart() { + test_->OnStartCalled(context()->connector(), context()->identity().name(), + context()->identity().user_id()); } bool ServiceTestClient::OnConnect(const ServiceInfo& remote_info, diff --git a/services/service_manager/public/cpp/service.h b/services/service_manager/public/cpp/service.h index 958f10f16bb997..2b8e780d0b815c 100644 --- a/services/service_manager/public/cpp/service.h +++ b/services/service_manager/public/cpp/service.h @@ -12,33 +12,26 @@ class ServiceContext; struct ServiceInfo; // The primary contract between a Service and the Service Manager, receiving -// lifecycle notifications and connection requests. Every Service must minimally -// implement OnConnect(). +// lifecycle notifications and connection requests. class Service { public: + Service(); virtual ~Service(); - // Called once a bidirectional connection with the Service Manager has been - // established. - // - // |context| is the ServiceContext for this instance of the service. It's - // guaranteed to outlive the Service instance and therefore may be retained by - // it. - // - // Use the context to retrieve information about the service instance, make - // outgoing service connections, and issue other requests to the Service - // Manager on behalf of this instance. - // - // Called exactly once before any calls to OnConnect(). - virtual void OnStart(ServiceContext* context); + // Called exactly once, when a bidirectional connection with the Service + // Manager has been established. No calls to OnConnect() will be received + // before this. + virtual void OnStart(); // Called each time a connection to this service is brokered by the Service // Manager. Implement this to expose interfaces to other services. // // Return true if the connection should succeed or false if the connection // should be rejected. + // + // The default implementation returns false. virtual bool OnConnect(const ServiceInfo& remote_info, - InterfaceRegistry* registry) = 0; + InterfaceRegistry* registry); // Called when the Service Manager has stopped tracking this instance. The // service should use this as a signal to shut down, and in fact its process @@ -56,6 +49,40 @@ class Service { // OnConnect() is invoked, neither will be invoked at any point after this // OnStop(). virtual bool OnStop(); + + protected: + // Access the ServiceContext associated with this Service. Note that this is + // only valid to call during or after OnStart(), but never before! As such, + // it's always safe to call in OnStart() and OnConnect(), but should generally + // be avoided in OnStop(). + ServiceContext* context() const; + + private: + friend class ForwardingService; + friend class ServiceContext; + + // NOTE: This is guaranteed to be called before OnStart(). + void set_context(ServiceContext* context) { service_context_ = context; } + + ServiceContext* service_context_ = nullptr; +}; + +// TODO(rockot): Remove this. It's here to satisfy a few remaining use cases +// where a Service impl is owned by something other than its ServiceContext. +class ForwardingService : public Service { + public: + // |target| must outlive this object. + explicit ForwardingService(Service* target); + ~ForwardingService() override; + + private: + // Service: + void OnStart() override; + bool OnConnect(const ServiceInfo& remote_info, + InterfaceRegistry* registry) override; + bool OnStop() override; + + Service* const target_ = nullptr; }; } // namespace service_manager diff --git a/services/service_manager/public/cpp/service_test.h b/services/service_manager/public/cpp/service_test.h index d8d38a1541f21e..2cdde3d91a0414 100644 --- a/services/service_manager/public/cpp/service_test.h +++ b/services/service_manager/public/cpp/service_test.h @@ -35,7 +35,7 @@ class ServiceTestClient : public Service { ~ServiceTestClient() override; protected: - void OnStart(ServiceContext* context) override; + void OnStart() override; bool OnConnect(const ServiceInfo& remote_info, InterfaceRegistry* registry) override; diff --git a/services/service_manager/tests/connect/connect_test_app.cc b/services/service_manager/tests/connect/connect_test_app.cc index b3be3a6ab794af..8d427c097f847f 100644 --- a/services/service_manager/tests/connect/connect_test_app.cc +++ b/services/service_manager/tests/connect/connect_test_app.cc @@ -54,8 +54,7 @@ class ConnectTestApp : public Service, private: // service_manager::Service: - void OnStart(ServiceContext* context) override { - context_ = context; + void OnStart() override { bindings_.set_connection_error_handler( base::Bind(&ConnectTestApp::OnConnectionError, base::Unretained(this))); @@ -63,6 +62,7 @@ class ConnectTestApp : public Service, base::Bind(&ConnectTestApp::OnConnectionError, base::Unretained(this))); } + bool OnConnect(const ServiceInfo& remote_info, InterfaceRegistry* registry) override { registry->AddInterface(this); @@ -73,10 +73,10 @@ class ConnectTestApp : public Service, test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); state->connection_remote_name = remote_info.identity.name(); state->connection_remote_userid = remote_info.identity.user_id(); - state->initialize_local_name = context_->identity().name(); - state->initialize_userid = context_->identity().user_id(); + state->initialize_local_name = context()->identity().name(); + state->initialize_userid = context()->identity().user_id(); - context_->connector()->ConnectToInterface(remote_info.identity, &caller_); + context()->connector()->ConnectToInterface(remote_info.identity, &caller_); caller_->ConnectionAccepted(std::move(state)); return true; @@ -111,7 +111,7 @@ class ConnectTestApp : public Service, callback.Run("APP"); } void GetInstance(const GetInstanceCallback& callback) override { - callback.Run(context_->identity().instance()); + callback.Run(context()->identity().instance()); } // test::mojom::StandaloneApp: @@ -119,7 +119,7 @@ class ConnectTestApp : public Service, const ConnectToAllowedAppInBlockedPackageCallback& callback) override { base::RunLoop run_loop; std::unique_ptr connection = - context_->connector()->Connect("service:connect_test_a"); + context()->connector()->Connect("service:connect_test_a"); connection->SetConnectionLostClosure( base::Bind(&ConnectTestApp::OnConnectionBlocked, base::Unretained(this), callback, &run_loop)); @@ -139,7 +139,7 @@ class ConnectTestApp : public Service, void ConnectToClassInterface( const ConnectToClassInterfaceCallback& callback) override { std::unique_ptr connection = - context_->connector()->Connect("service:connect_test_class_app"); + context()->connector()->Connect("service:connect_test_class_app"); test::mojom::ClassInterfacePtr class_interface; connection->GetInterface(&class_interface); std::string ping_response; @@ -174,7 +174,7 @@ class ConnectTestApp : public Service, const ConnectToClassAppAsDifferentUserCallback& callback) override { Connector::ConnectParams params(target); std::unique_ptr connection = - context_->connector()->Connect(¶ms); + context()->connector()->Connect(¶ms); { base::RunLoop loop; connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); @@ -206,7 +206,6 @@ class ConnectTestApp : public Service, base::MessageLoop::current()->QuitWhenIdle(); } - ServiceContext* context_ = nullptr; mojo::BindingSet bindings_; mojo::BindingSet standalone_bindings_; mojo::BindingSet blocked_bindings_; diff --git a/services/service_manager/tests/connect/connect_test_class_app.cc b/services/service_manager/tests/connect/connect_test_class_app.cc index b6a731829cfb05..8e19e61125c382 100644 --- a/services/service_manager/tests/connect/connect_test_class_app.cc +++ b/services/service_manager/tests/connect/connect_test_class_app.cc @@ -33,10 +33,6 @@ class ConnectTestClassApp private: // service_manager::Service: - void OnStart(ServiceContext* context) override { - context_ = context; - } - bool OnConnect(const ServiceInfo& remote_info, InterfaceRegistry* registry) override { registry->AddInterface(this); @@ -65,7 +61,7 @@ class ConnectTestClassApp callback.Run("CLASS APP"); } void GetInstance(const GetInstanceCallback& callback) override { - callback.Run(context_->identity().instance()); + callback.Run(context()->identity().instance()); } // test::mojom::ClassInterface: @@ -78,10 +74,9 @@ class ConnectTestClassApp DCHECK(it != inbound_connections_.end()); inbound_connections_.erase(it); if (inbound_connections_.empty()) - context_->QuitNow(); + context()->QuitNow(); } - ServiceContext* context_ = nullptr; std::set inbound_connections_; mojo::BindingSet bindings_; mojo::BindingSet class_interface_bindings_; diff --git a/services/service_manager/tests/connect/connect_test_exe.cc b/services/service_manager/tests/connect/connect_test_exe.cc index c5a40b980ff0a8..60de89e968bbbe 100644 --- a/services/service_manager/tests/connect/connect_test_exe.cc +++ b/services/service_manager/tests/connect/connect_test_exe.cc @@ -31,10 +31,6 @@ class Target : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override { - identity_ = context->identity(); - } - bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override { registry->AddInterface(this); @@ -52,10 +48,9 @@ class Target : public service_manager::Service, callback.Run("connect_test_exe"); } void GetInstance(const GetInstanceCallback& callback) override { - callback.Run(identity_.instance()); + callback.Run(context()->identity().instance()); } - service_manager::Identity identity_; mojo::BindingSet bindings_; DISALLOW_COPY_AND_ASSIGN(Target); diff --git a/services/service_manager/tests/connect/connect_test_package.cc b/services/service_manager/tests/connect/connect_test_package.cc index 9d4a3d22775a7b..e62b65fe017a0d 100644 --- a/services/service_manager/tests/connect/connect_test_package.cc +++ b/services/service_manager/tests/connect/connect_test_package.cc @@ -54,33 +54,8 @@ class ProvidedService } private: - class ForwardingServiceImpl : public Service { - public: - explicit ForwardingServiceImpl(Service* service) - : service_(service) {} - ~ForwardingServiceImpl() override {} - - // Service: - void OnStart(ServiceContext* context) override { - service_->OnStart(context); - } - - bool OnConnect(const ServiceInfo& remote_info, - InterfaceRegistry* registry) override { - return service_->OnConnect(remote_info, registry); - } - - bool OnStop() override { return service_->OnStop(); } - - private: - Service* const service_; - - DISALLOW_COPY_AND_ASSIGN(ForwardingServiceImpl); - }; - // service_manager::Service: - void OnStart(ServiceContext* context) override { - context_ = context; + void OnStart() override { bindings_.set_connection_error_handler( base::Bind(&ProvidedService::OnConnectionError, base::Unretained(this))); @@ -95,10 +70,10 @@ class ProvidedService test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); state->connection_remote_name = remote_info.identity.name(); state->connection_remote_userid = remote_info.identity.user_id(); - state->initialize_local_name = context_->identity().name(); - state->initialize_userid = context_->identity().user_id(); + state->initialize_local_name = context()->identity().name(); + state->initialize_userid = context()->identity().user_id(); - context_->connector()->ConnectToInterface(remote_info.identity, &caller_); + context()->connector()->ConnectToInterface(remote_info.identity, &caller_); caller_->ConnectionAccepted(std::move(state)); return true; @@ -128,7 +103,7 @@ class ProvidedService } void GetInstance(const GetInstanceCallback& callback) override { - callback.Run(context_->identity().instance()); + callback.Run(context()->identity().instance()); } // test::mojom::BlockedInterface: @@ -142,7 +117,7 @@ class ProvidedService const ConnectToClassAppAsDifferentUserCallback& callback) override { Connector::ConnectParams params(target); std::unique_ptr connection = - context_->connector()->Connect(¶ms); + context()->connector()->Connect(¶ms); { base::RunLoop loop; connection->AddConnectionCompletedClosure(loop.QuitClosure()); @@ -156,7 +131,7 @@ class ProvidedService // base::SimpleThread: void Run() override { - ServiceRunner(new ForwardingServiceImpl(this)).Run( + ServiceRunner(new ForwardingService(this)).Run( request_.PassMessagePipe().release().value(), false); caller_.reset(); bindings_.CloseAllBindings(); @@ -169,7 +144,6 @@ class ProvidedService base::MessageLoop::current()->QuitWhenIdle(); } - ServiceContext* context_ = nullptr; const std::string title_; mojom::ServiceRequest request_; test::mojom::ExposedInterfacePtr caller_; @@ -192,9 +166,7 @@ class ConnectTestService private: // service_manager::Service: - void OnStart(ServiceContext* context) override { - context_ = context; - + void OnStart() override { base::Closure error_handler = base::Bind(&ConnectTestService::OnConnectionError, base::Unretained(this)); @@ -244,15 +216,14 @@ class ConnectTestService } void GetInstance(const GetInstanceCallback& callback) override { - callback.Run(context_->identity().instance()); + callback.Run(context()->identity().instance()); } void OnConnectionError() { if (bindings_.empty() && service_factory_bindings_.empty()) - context_->RequestQuit(); + context()->RequestQuit(); } - ServiceContext* context_ = nullptr; std::vector> delegates_; mojo::BindingSet service_factory_bindings_; mojo::BindingSet bindings_; diff --git a/services/service_manager/tests/lifecycle/app_client.cc b/services/service_manager/tests/lifecycle/app_client.cc index 905260cf55fbc3..9ada68bed8af23 100644 --- a/services/service_manager/tests/lifecycle/app_client.cc +++ b/services/service_manager/tests/lifecycle/app_client.cc @@ -15,10 +15,6 @@ AppClient::AppClient() {} AppClient::~AppClient() {} -void AppClient::OnStart(ServiceContext* context) { - context_ = context; -} - bool AppClient::OnConnect(const ServiceInfo& remote_info, InterfaceRegistry* registry) { registry->AddInterface(this); @@ -40,7 +36,7 @@ void AppClient::Ping(const PingCallback& callback) { } void AppClient::GracefulQuit() { - context_->RequestQuit(); + context()->RequestQuit(); } void AppClient::Crash() { @@ -51,7 +47,7 @@ void AppClient::Crash() { } void AppClient::CloseServiceManagerConnection() { - context_->DisconnectFromServiceManager(); + context()->DisconnectFromServiceManager(); bindings_.set_connection_error_handler( base::Bind(&AppClient::BindingLost, base::Unretained(this))); } diff --git a/services/service_manager/tests/lifecycle/app_client.h b/services/service_manager/tests/lifecycle/app_client.h index 83d1848b8ac40a..2c31a3fc22c8a9 100644 --- a/services/service_manager/tests/lifecycle/app_client.h +++ b/services/service_manager/tests/lifecycle/app_client.h @@ -28,8 +28,7 @@ class AppClient : public Service, void set_runner(ServiceRunner* runner) { runner_ = runner; } - // Serivce: - void OnStart(ServiceContext* context) override; + // Service: bool OnConnect(const ServiceInfo& remote_info, InterfaceRegistry* registry) override; bool OnStop() override; @@ -49,7 +48,6 @@ class AppClient : public Service, void BindingLost(); - ServiceContext* context_; ServiceRunner* runner_ = nullptr; mojo::BindingSet bindings_; diff --git a/services/service_manager/tests/lifecycle/package.cc b/services/service_manager/tests/lifecycle/package.cc index 1be7d9353a3a6f..72874098c15adf 100644 --- a/services/service_manager/tests/lifecycle/package.cc +++ b/services/service_manager/tests/lifecycle/package.cc @@ -40,10 +40,6 @@ class PackagedApp private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override { - context_ = context; - } - bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override { registry->AddInterface( @@ -78,7 +74,7 @@ class PackagedApp void CloseServiceManagerConnection() override { service_manager_connection_closed_callback_.Run(); - context_->QuitNow(); + context()->QuitNow(); // This only closed our relationship with the service manager, existing // |bindings_| // remain active. @@ -91,7 +87,6 @@ class PackagedApp } } - service_manager::ServiceContext* context_; mojo::BindingSet bindings_; // Run when this object's connection to the service manager is closed. @@ -112,9 +107,7 @@ class Package : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override { - app_client_.OnStart(context); - } + void OnStart() override { app_client_.OnStart(); } bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override { diff --git a/services/service_manager/tests/lifecycle/parent.cc b/services/service_manager/tests/lifecycle/parent.cc index 3659159bd3e1a7..4c656eced06adb 100644 --- a/services/service_manager/tests/lifecycle/parent.cc +++ b/services/service_manager/tests/lifecycle/parent.cc @@ -36,10 +36,6 @@ class Parent : public service_manager::Service, private: // Service: - void OnStart(service_manager::ServiceContext* context) override { - context_ = context; - } - bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override { registry->AddInterface(this); @@ -55,7 +51,7 @@ class Parent : public service_manager::Service, // service_manager::test::mojom::Parent: void ConnectToChild(const ConnectToChildCallback& callback) override { child_connection_ = - context_->connector()->Connect("service:lifecycle_unittest_app"); + context()->connector()->Connect("service:lifecycle_unittest_app"); service_manager::test::mojom::LifecycleControlPtr lifecycle; child_connection_->GetInterface(&lifecycle); { @@ -71,7 +67,6 @@ class Parent : public service_manager::Service, base::MessageLoop::current()->QuitWhenIdle(); } - service_manager::ServiceContext* context_ = nullptr; std::unique_ptr child_connection_; mojo::BindingSet parent_bindings_; diff --git a/services/service_manager/tests/service_manager/target.cc b/services/service_manager/tests/service_manager/target.cc index 204d10ea937fd6..4e04b55dcdf4d6 100644 --- a/services/service_manager/tests/service_manager/target.cc +++ b/services/service_manager/tests/service_manager/target.cc @@ -25,11 +25,11 @@ class Target : public service_manager::Service { private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override { + void OnStart() override { CreateInstanceTestPtr service; - context->connector()->ConnectToInterface( + context()->connector()->ConnectToInterface( "service:service_manager_unittest", &service); - service->SetTargetIdentity(context->identity()); + service->SetTargetIdentity(context()->identity()); } bool OnConnect(const service_manager::ServiceInfo& remote_info, diff --git a/services/service_manager/tests/shutdown/shutdown_client_app.cc b/services/service_manager/tests/shutdown/shutdown_client_app.cc index bc222d6f897703..b91e8f686f37cf 100644 --- a/services/service_manager/tests/shutdown/shutdown_client_app.cc +++ b/services/service_manager/tests/shutdown/shutdown_client_app.cc @@ -27,10 +27,6 @@ class ShutdownClientApp private: // service_manager::Service: - void OnStart(ServiceContext* context) override { - context_ = context; - } - bool OnConnect(const ServiceInfo& remote_info, InterfaceRegistry* registry) override { registry->AddInterface(this); @@ -46,7 +42,7 @@ class ShutdownClientApp // mojom::ShutdownTestClientController: void ConnectAndWait(const ConnectAndWaitCallback& callback) override { mojom::ShutdownTestServicePtr service; - context_->connector()->ConnectToInterface( + context()->connector()->ConnectToInterface( "service:shutdown_service", &service); mojo::Binding client_binding(this); @@ -65,7 +61,6 @@ class ShutdownClientApp callback.Run(); } - ServiceContext* context_ = nullptr; mojo::BindingSet bindings_; DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp); diff --git a/services/ui/demo/mus_demo.cc b/services/ui/demo/mus_demo.cc index 5190e90f32c038..5f75e9aea08365 100644 --- a/services/ui/demo/mus_demo.cc +++ b/services/ui/demo/mus_demo.cc @@ -64,10 +64,10 @@ MusDemo::MusDemo() {} MusDemo::~MusDemo() {} -void MusDemo::OnStart(service_manager::ServiceContext* context) { - gpu_service_ = GpuService::Create(context->connector()); +void MusDemo::OnStart() { + gpu_service_ = GpuService::Create(context()->connector()); window_tree_client_ = base::MakeUnique(this, this); - window_tree_client_->ConnectAsWindowManager(context->connector()); + window_tree_client_->ConnectAsWindowManager(context()->connector()); } bool MusDemo::OnConnect(const service_manager::ServiceInfo& remote_info, diff --git a/services/ui/demo/mus_demo.h b/services/ui/demo/mus_demo.h index 53e41578c839e0..912519a19058e9 100644 --- a/services/ui/demo/mus_demo.h +++ b/services/ui/demo/mus_demo.h @@ -37,7 +37,7 @@ class MusDemo : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/services/ui/ime/test_ime_driver/test_ime_application.cc b/services/ui/ime/test_ime_driver/test_ime_application.cc index d84e4481fd0d44..19a3f88724a17f 100644 --- a/services/ui/ime/test_ime_driver/test_ime_application.cc +++ b/services/ui/ime/test_ime_driver/test_ime_application.cc @@ -17,13 +17,13 @@ TestIMEApplication::TestIMEApplication() {} TestIMEApplication::~TestIMEApplication() {} -void TestIMEApplication::OnStart(service_manager::ServiceContext* context) { +void TestIMEApplication::OnStart() { mojom::IMEDriverPtr ime_driver_ptr; mojo::MakeStrongBinding(base::MakeUnique(), GetProxy(&ime_driver_ptr)); ui::mojom::IMERegistrarPtr ime_registrar; - context->connector()->ConnectToInterface("service:ui", &ime_registrar); + context()->connector()->ConnectToInterface("service:ui", &ime_registrar); ime_registrar->RegisterDriver(std::move(ime_driver_ptr)); } diff --git a/services/ui/ime/test_ime_driver/test_ime_application.h b/services/ui/ime/test_ime_driver/test_ime_application.h index f62c402756a751..a194f6d2d63dab 100644 --- a/services/ui/ime/test_ime_driver/test_ime_application.h +++ b/services/ui/ime/test_ime_driver/test_ime_application.h @@ -18,7 +18,7 @@ class TestIMEApplication : public service_manager::Service { private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/services/ui/service.cc b/services/ui/service.cc index e67356c8e92c21..9861c2886a5aa7 100644 --- a/services/ui/service.cc +++ b/services/ui/service.cc @@ -137,9 +137,9 @@ void Service::AddUserIfNecessary( window_server_->user_id_tracker()->AddUserId(remote_identity.user_id()); } -void Service::OnStart(service_manager::ServiceContext* context) { +void Service::OnStart() { base::PlatformThread::SetName("mus"); - tracing_.Initialize(context->connector(), context->identity().name()); + tracing_.Initialize(context()->connector(), context()->identity().name()); TRACE_EVENT0("mus", "Service::Initialize started"); test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( @@ -150,7 +150,7 @@ void Service::OnStart(service_manager::ServiceContext* context) { ui::test::SetUseOverrideRedirectWindowByDefault(true); #endif - InitializeResources(context->connector()); + InitializeResources(context()->connector()); #if defined(USE_OZONE) // The ozone platform can provide its own event source. So initialize the @@ -158,7 +158,7 @@ void Service::OnStart(service_manager::ServiceContext* context) { // Because GL libraries need to be initialized before entering the sandbox, // in MUS, |InitializeForUI| will load the GL libraries. ui::OzonePlatform::InitParams params; - params.connector = context->connector(); + params.connector = context()->connector(); params.single_process = false; ui::OzonePlatform::InitializeForUI(params); @@ -195,7 +195,7 @@ void Service::OnStart(service_manager::ServiceContext* context) { platform_screen_->Init(window_server_->display_manager()); - ime_server_.Init(context->connector()); + ime_server_.Init(context()->connector()); } bool Service::OnConnect(const service_manager::ServiceInfo& remote_info, diff --git a/services/ui/service.h b/services/ui/service.h index ec8d447d08d37f..9e0a73574b3129 100644 --- a/services/ui/service.h +++ b/services/ui/service.h @@ -100,7 +100,7 @@ class Service void AddUserIfNecessary(const service_manager::Identity& remote_identity); // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override; + void OnStart() override; bool OnConnect(const service_manager::ServiceInfo& remote_info, service_manager::InterfaceRegistry* registry) override; diff --git a/services/ui/test_wm/test_wm.cc b/services/ui/test_wm/test_wm.cc index e1c248a0679767..58ba24aed2fe9c 100644 --- a/services/ui/test_wm/test_wm.cc +++ b/services/ui/test_wm/test_wm.cc @@ -29,9 +29,9 @@ class TestWM : public service_manager::Service, private: // service_manager::Service: - void OnStart(service_manager::ServiceContext* context) override { + void OnStart() override { window_tree_client_.reset(new ui::WindowTreeClient(this, this)); - window_tree_client_->ConnectAsWindowManager(context->connector()); + window_tree_client_->ConnectAsWindowManager(context()->connector()); } bool OnConnect(const service_manager::ServiceInfo& remote_info,