Skip to content

Commit

Permalink
Service Manager: Remove ServiceContext* arg from Service::OnStart()
Browse files Browse the repository at this point in the history
This restores the context() accessor to Service, but now
guarantees that ServiceContext always sets the context
before invoking OnStart().

This means that all Service implementations are free to safely
access context() any time after OnStart() regardless of what
service-running mechanism was used to create their
ServiceContext.

BUG=654986

Committed: https://crrev.com/6d9b6cd9869d3f8385a42b3272edd7f5b3a6ac5e
Review-Url: https://codereview.chromium.org/2487573002
Cr-Original-Commit-Position: refs/heads/master@{#431752}
Cr-Commit-Position: refs/heads/master@{#431778}
  • Loading branch information
krockot authored and Commit bot committed Nov 12, 2016
1 parent 14e9548 commit 4b5e64d
Show file tree
Hide file tree
Showing 65 changed files with 239 additions and 339 deletions.
6 changes: 3 additions & 3 deletions ash/autoclick/mus/autoclick_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ AutoclickApplication::AutoclickApplication()

AutoclickApplication::~AutoclickApplication() {}

void AutoclickApplication::OnStart(service_manager::ServiceContext* context) {
void AutoclickApplication::OnStart() {
aura_init_ = base::MakeUnique<views::AuraInit>(
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));
}
Expand Down
2 changes: 1 addition & 1 deletion ash/autoclick/mus/autoclick_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 7 additions & 9 deletions ash/mus/window_manager_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<views::AuraInit>(
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<ui::WindowTreeClient> window_tree_client =
base::MakeUnique<ui::WindowTreeClient>(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";
Expand All @@ -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());
}
Expand Down
8 changes: 1 addition & 7 deletions ash/mus/window_manager_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ class ScopedFakeStatisticsProvider;
}
}

namespace service_manager {
class ServiceContext;
}

namespace views {
class AuraInit;
class SurfaceContextFactory;
Expand Down Expand Up @@ -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<views::AuraInit> aura_init_;
Expand Down
6 changes: 3 additions & 3 deletions ash/touch_hud/mus/touch_hud_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<views::AuraInit>(
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(
Expand Down
2 changes: 1 addition & 1 deletion ash/touch_hud/mus/touch_hud_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions components/filesystem/file_system_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/filesystem/file_system_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions components/font_service/font_service_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/font_service/font_service_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions components/leveldb/leveldb_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/leveldb/leveldb_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
34 changes: 3 additions & 31 deletions content/common/service_manager/service_manager_connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,6 @@ class ServiceManagerConnectionImpl::IOThreadContext
private:
friend class base::RefCountedThreadSafe<IOThreadContext>;

// 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<IOThreadContext> context)
Expand Down Expand Up @@ -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<ForwardingServiceImpl>(this),
base::MakeUnique<service_manager::ForwardingService>(this),
std::move(pending_service_request_),
std::move(io_thread_connector_),
std::move(pending_connector_request_)));
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 5 additions & 6 deletions mash/browser/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -865,18 +865,17 @@ void Browser::RemoveWindow(views::Widget* window) {

std::unique_ptr<navigation::View> Browser::CreateView() {
navigation::mojom::ViewFactoryPtr factory;
context_->connector()->ConnectToInterface("exe:navigation", &factory);
context()->connector()->ConnectToInterface("exe:navigation", &factory);
return base::MakeUnique<navigation::View>(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<views::AuraInit>(
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,
Expand Down
8 changes: 1 addition & 7 deletions mash/browser/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ namespace navigation {
class View;
}

namespace service_manager {
class ServiceContext;
}

namespace views {
class AuraInit;
class Widget;
Expand All @@ -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;

Expand All @@ -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<mojom::Launchable> bindings_;
std::vector<views::Widget*> windows_;

Expand Down
11 changes: 5 additions & 6 deletions mash/catalog_viewer/catalog_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<views::AuraInit>(
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,
Expand All @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions mash/catalog_viewer/catalog_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<mojom::Launchable> bindings_;
std::vector<views::Widget*> windows_;

Expand Down
9 changes: 5 additions & 4 deletions mash/example/views_examples/views_examples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<views::AuraInit>(
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 {
Expand Down
7 changes: 3 additions & 4 deletions mash/example/window_type_launcher/window_type_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<views::AuraInit>(
context->connector(), context->identity(), "views_mus_resources.pak",
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
}

Expand All @@ -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);
Expand Down
Loading

0 comments on commit 4b5e64d

Please sign in to comment.