Skip to content

Commit

Permalink
Shell -> ServiceManager
Browse files Browse the repository at this point in the history
TBR=rockot@chromium.org,tsepez@chromium.org
http://crbug.com/625840

Review-Url: https://codereview.chromium.org/2124883002
Cr-Commit-Position: refs/heads/master@{#403838}
  • Loading branch information
ben authored and Commit bot committed Jul 6, 2016
1 parent 0903d9b commit 9bf1b2e
Show file tree
Hide file tree
Showing 37 changed files with 404 additions and 393 deletions.
29 changes: 15 additions & 14 deletions chrome/test/base/mojo_test_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "services/shell/public/cpp/shell_connection.h"
#include "services/shell/runner/common/client_util.h"
#include "services/shell/runner/common/switches.h"
#include "services/shell/shell.h"
#include "services/shell/service_manager.h"
#include "services/shell/switches.h"

using shell::mojom::Service;
Expand Down Expand Up @@ -83,7 +83,7 @@ class BackgroundTestState {
// Prepares the command line and other setup for connecting the test to mojo.
// Must be paired with a call to ChildProcessLaunched().
void Connect(base::CommandLine* command_line,
shell::Shell* shell,
shell::ServiceManager* service_manager,
const std::string& instance,
base::TestLauncher::LaunchOptions* test_launch_options) {
command_line->AppendSwitch(MojoTestConnector::kTestSwitch);
Expand All @@ -106,7 +106,7 @@ class BackgroundTestState {
shell::PassServiceRequestOnCommandLine(command_line, child_token_);

std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams);
params->set_source(shell::CreateShellIdentity());
params->set_source(shell::CreateServiceManagerIdentity());
params->set_target(
shell::Identity(kTestName, shell::mojom::kRootUserID, instance));

Expand All @@ -117,7 +117,7 @@ class BackgroundTestState {
client_process_connection->pid_receiver_request =
mojo::GetProxy(&pid_receiver_).PassMessagePipe();
params->set_client_process_connection(std::move(client_process_connection));
shell->Connect(std::move(params));
service_manager->Connect(std::move(params));
}

// Called after the test process has launched. Completes the registration done
Expand Down Expand Up @@ -146,7 +146,7 @@ class BackgroundTestState {
// Called used destroy BackgroundTestState on the background thread.
void DestroyBackgroundStateOnBackgroundThread(
std::unique_ptr<BackgroundTestState> state,
shell::Shell* shell) {}
shell::ServiceManager* service_manager) {}

// State created per test. Manages creation of the corresponding
// BackgroundTestState and making sure processing runs on the right threads.
Expand All @@ -160,7 +160,7 @@ class MojoTestState : public content::TestState {
// BackgroundState needs to be destroyed on the background thread. We're
// guaranteed |background_shell_| has been created by the time we reach
// here as Init() blocks until |background_shell_| has been created.
background_shell_->ExecuteOnShellThread(
background_shell_->ExecuteOnServiceManagerThread(
base::Bind(&DestroyBackgroundStateOnBackgroundThread,
base::Passed(&background_state_)));
}
Expand All @@ -169,7 +169,7 @@ class MojoTestState : public content::TestState {
base::TestLauncher::LaunchOptions* test_launch_options) {
base::WaitableEvent signal(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
background_shell_->ExecuteOnShellThread(base::Bind(
background_shell_->ExecuteOnServiceManagerThread(base::Bind(
&MojoTestState::BindOnBackgroundThread, base::Unretained(this), &signal,
command_line, test_launch_options));
signal.Wait();
Expand All @@ -185,16 +185,17 @@ class MojoTestState : public content::TestState {
// that |handle| is still valid.
base::WaitableEvent signal(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
background_shell_->ExecuteOnShellThread(
background_shell_->ExecuteOnServiceManagerThread(
base::Bind(&MojoTestState::ChildProcessLaunchedOnBackgroundThread,
base::Unretained(this), handle, pid, &signal));
signal.Wait();
}

void ChildProcessLaunchedOnBackgroundThread(base::ProcessHandle handle,
base::ProcessId pid,
base::WaitableEvent* signal,
shell::Shell* shell) {
void ChildProcessLaunchedOnBackgroundThread(
base::ProcessHandle handle,
base::ProcessId pid,
base::WaitableEvent* signal,
shell::ServiceManager* service_manager) {
background_state_->ChildProcessLaunched(handle, pid);
signal->Signal();
}
Expand All @@ -203,12 +204,12 @@ class MojoTestState : public content::TestState {
base::WaitableEvent* signal,
base::CommandLine* command_line,
base::TestLauncher::LaunchOptions* test_launch_options,
shell::Shell* shell) {
shell::ServiceManager* service_manager) {
static int instance_id = 0;
const std::string instance_name =
"instance-" + base::IntToString(instance_id++);
background_state_.reset(new BackgroundTestState);
background_state_->Connect(command_line, shell, instance_name,
background_state_->Connect(command_line, service_manager, instance_name,
test_launch_options);
signal->Signal();
}
Expand Down
8 changes: 5 additions & 3 deletions content/browser/mojo/mojo_shell_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,11 @@ MojoShellContext::MojoShellContext() {
mojo::edk::SetParentPipeHandleFromCommandLine();
request = shell::GetServiceRequestFromCommandLine();
} else {
shell_.reset(new shell::Shell(std::move(native_runner_factory),
service_manager_.reset(
new shell::ServiceManager(std::move(native_runner_factory),
catalog_->TakeService()));
request = shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName);
request = service_manager_->StartEmbedderService(
kBrowserMojoApplicationName);
}
MojoShellConnection::SetForProcess(
MojoShellConnection::Create(std::move(request)));
Expand Down Expand Up @@ -356,7 +358,7 @@ void MojoShellContext::ConnectToApplicationOnOwnThread(
params->set_remote_interfaces(std::move(request));
params->set_local_interfaces(std::move(exposed_services));
params->set_connect_callback(callback);
shell_->Connect(std::move(params));
service_manager_->Connect(std::move(params));
}

} // namespace content
4 changes: 2 additions & 2 deletions content/browser/mojo/mojo_shell_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "base/macros.h"
#include "content/common/content_export.h"
#include "services/shell/public/interfaces/connector.mojom.h"
#include "services/shell/shell.h"
#include "services/shell/service_manager.h"

namespace catalog {
class Catalog;
Expand Down Expand Up @@ -61,7 +61,7 @@ class CONTENT_EXPORT MojoShellContext {

std::unique_ptr<BuiltinManifestProvider> manifest_provider_;
std::unique_ptr<catalog::Catalog> catalog_;
std::unique_ptr<shell::Shell> shell_;
std::unique_ptr<shell::ServiceManager> service_manager_;

DISALLOW_COPY_AND_ASSIGN(MojoShellContext);
};
Expand Down
2 changes: 0 additions & 2 deletions mash/catalog_viewer/catalog_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ namespace mash {
namespace catalog_viewer {
namespace {

using shell::mojom::InstanceInfoPtr;

class CatalogViewerContents : public views::WidgetDelegateView,
public ui::TableModel {
public:
Expand Down
2 changes: 1 addition & 1 deletion mash/task_viewer/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"mojo:catalog": {
"interfaces": [ "catalog::mojom::Catalog" ]
},
"mojo:shell": { "interfaces": [ "shell::mojom::Shell" ] }
"mojo:shell": { "interfaces": [ "shell::mojom::ServiceManager" ] }
}
}
}
42 changes: 21 additions & 21 deletions mash/task_viewer/task_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "services/catalog/public/interfaces/catalog.mojom.h"
#include "services/shell/public/cpp/connection.h"
#include "services/shell/public/cpp/connector.h"
#include "services/shell/public/interfaces/shell.mojom.h"
#include "services/shell/public/interfaces/service_manager.mojom.h"
#include "ui/base/models/table_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/resources/grit/ui_resources.h"
Expand All @@ -34,15 +34,15 @@ namespace mash {
namespace task_viewer {
namespace {

using shell::mojom::InstanceInfoPtr;
using shell::mojom::ServiceInfoPtr;

class TaskViewerContents : public views::WidgetDelegateView,
public ui::TableModel,
public views::ButtonListener,
public shell::mojom::InstanceListener {
public shell::mojom::ServiceManagerListener {
public:
TaskViewerContents(TaskViewer* task_viewer,
shell::mojom::InstanceListenerRequest request,
shell::mojom::ServiceManagerListenerRequest request,
catalog::mojom::CatalogPtr catalog)
: task_viewer_(task_viewer),
binding_(this, std::move(request)),
Expand Down Expand Up @@ -151,8 +151,8 @@ class TaskViewerContents : public views::WidgetDelegateView,
process.Terminate(9, true);
}

// Overridden from shell::mojom::InstanceListener:
void SetExistingInstances(mojo::Array<InstanceInfoPtr> instances) override {
// Overridden from shell::mojom::ServiceManagerListener:
void OnInit(mojo::Array<ServiceInfoPtr> instances) override {
// This callback should only be called with an empty model.
DCHECK(instances_.empty());
mojo::Array<mojo::String> names;
Expand All @@ -165,7 +165,7 @@ class TaskViewerContents : public views::WidgetDelegateView,
base::Bind(&TaskViewerContents::OnGotCatalogEntries,
weak_ptr_factory_.GetWeakPtr()));
}
void InstanceCreated(InstanceInfoPtr instance) override {
void OnServiceCreated(ServiceInfoPtr instance) override {
DCHECK(!ContainsId(instance->id));
InsertInstance(instance->id, instance->identity->name, instance->pid);
observer_->OnItemsAdded(static_cast<int>(instances_.size()), 1);
Expand All @@ -175,26 +175,26 @@ class TaskViewerContents : public views::WidgetDelegateView,
base::Bind(&TaskViewerContents::OnGotCatalogEntries,
weak_ptr_factory_.GetWeakPtr()));
}
void InstanceDestroyed(uint32_t id) override {
void OnServiceStarted(uint32_t id, uint32_t pid) override {
for (auto it = instances_.begin(); it != instances_.end(); ++it) {
if ((*it)->id == id) {
observer_->OnItemsRemoved(
static_cast<int>(it - instances_.begin()), 1);
instances_.erase(it);
(*it)->pid = pid;
observer_->OnItemsChanged(
static_cast<int>(it - instances_.begin()), 1);
return;
}
}
NOTREACHED();
}
void InstancePIDAvailable(uint32_t id, uint32_t pid) override {
void OnServiceStopped(uint32_t id) override {
for (auto it = instances_.begin(); it != instances_.end(); ++it) {
if ((*it)->id == id) {
(*it)->pid = pid;
observer_->OnItemsChanged(
observer_->OnItemsRemoved(
static_cast<int>(it - instances_.begin()), 1);
instances_.erase(it);
return;
}
}
NOTREACHED();
}

bool ContainsId(uint32_t id) const {
Expand Down Expand Up @@ -255,7 +255,7 @@ class TaskViewerContents : public views::WidgetDelegateView,
}

TaskViewer* task_viewer_;
mojo::Binding<shell::mojom::InstanceListener> binding_;
mojo::Binding<shell::mojom::ServiceManagerListener> binding_;
catalog::mojom::CatalogPtr catalog_;

views::TableView* table_view_;
Expand Down Expand Up @@ -307,12 +307,12 @@ void TaskViewer::Launch(uint32_t what, mojom::LaunchMode how) {
return;
}

shell::mojom::ShellPtr shell;
connector_->ConnectToInterface("mojo:shell", &shell);
shell::mojom::ServiceManagerPtr service_manager;
connector_->ConnectToInterface("mojo:shell", &service_manager);

shell::mojom::InstanceListenerPtr listener;
shell::mojom::InstanceListenerRequest request = GetProxy(&listener);
shell->AddInstanceListener(std::move(listener));
shell::mojom::ServiceManagerListenerPtr listener;
shell::mojom::ServiceManagerListenerRequest request = GetProxy(&listener);
service_manager->AddListener(std::move(listener));

catalog::mojom::CatalogPtr catalog;
connector_->ConnectToInterface("mojo:catalog", &catalog);
Expand Down
6 changes: 3 additions & 3 deletions services/catalog/catalog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ void Catalog::ScanSystemPackageDir() {
bool Catalog::OnConnect(shell::Connection* connection) {
connection->AddInterface<mojom::Catalog>(this);
connection->AddInterface<filesystem::mojom::Directory>(this);
connection->AddInterface<shell::mojom::ShellResolver>(this);
connection->AddInterface<shell::mojom::Resolver>(this);
return true;
}

void Catalog::Create(shell::Connection* connection,
shell::mojom::ShellResolverRequest request) {
shell::mojom::ResolverRequest request) {
Instance* instance =
GetInstanceForUserId(connection->GetRemoteIdentity().user_id());
instance->BindShellResolver(std::move(request));
instance->BindResolver(std::move(request));
}

void Catalog::Create(shell::Connection* connection,
Expand Down
8 changes: 4 additions & 4 deletions services/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "services/catalog/public/interfaces/catalog.mojom.h"
#include "services/catalog/types.h"
#include "services/shell/public/cpp/service.h"
#include "services/shell/public/interfaces/resolver.mojom.h"
#include "services/shell/public/interfaces/service.mojom.h"
#include "services/shell/public/interfaces/shell_resolver.mojom.h"

namespace base {
class SequencedWorkerPool;
Expand All @@ -44,7 +44,7 @@ class Store;
class Catalog : public shell::Service,
public shell::InterfaceFactory<mojom::Catalog>,
public shell::InterfaceFactory<filesystem::mojom::Directory>,
public shell::InterfaceFactory<shell::mojom::ShellResolver> {
public shell::InterfaceFactory<shell::mojom::Resolver> {
public:
// |manifest_provider| may be null.
Catalog(base::SequencedWorkerPool* worker_pool,
Expand All @@ -66,9 +66,9 @@ class Catalog : public shell::Service,
// shell::Service:
bool OnConnect(shell::Connection* connection) override;

// shell::InterfaceFactory<shell::mojom::ShellResolver>:
// shell::InterfaceFactory<shell::mojom::Resolver>:
void Create(shell::Connection* connection,
shell::mojom::ShellResolverRequest request) override;
shell::mojom::ResolverRequest request) override;

// shell::InterfaceFactory<mojom::Catalog>:
void Create(shell::Connection* connection,
Expand Down
13 changes: 6 additions & 7 deletions services/catalog/instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ Instance::Instance(std::unique_ptr<Store> store, Reader* system_reader)
weak_factory_(this) {}
Instance::~Instance() {}

void Instance::BindShellResolver(
shell::mojom::ShellResolverRequest request) {
void Instance::BindResolver(shell::mojom::ResolverRequest request) {
if (system_cache_)
shell_resolver_bindings_.AddBinding(this, std::move(request));
resolver_bindings_.AddBinding(this, std::move(request));
else
pending_shell_resolver_requests_.push_back(std::move(request));
pending_resolver_requests_.push_back(std::move(request));
}

void Instance::BindCatalog(mojom::CatalogRequest request) {
Expand All @@ -50,14 +49,14 @@ void Instance::BindCatalog(mojom::CatalogRequest request) {
void Instance::CacheReady(EntryCache* cache) {
system_cache_ = cache;
DeserializeCatalog();
for (auto& request : pending_shell_resolver_requests_)
BindShellResolver(std::move(request));
for (auto& request : pending_resolver_requests_)
BindResolver(std::move(request));
for (auto& request : pending_catalog_requests_)
BindCatalog(std::move(request));
}

////////////////////////////////////////////////////////////////////////////////
// Instance, shell::mojom::ShellResolver:
// Instance, shell::mojom::Resolver:

void Instance::ResolveMojoName(const mojo::String& mojo_name,
const ResolveMojoNameCallback& callback) {
Expand Down
Loading

0 comments on commit 9bf1b2e

Please sign in to comment.