Skip to content

Commit

Permalink
Add an application for the Shell.
Browse files Browse the repository at this point in the history
Adds an implementation of ApplicationManager interface, which allows registration of instances launched by other process launchers.

R=sky@chromium.org
BUG=none

Review URL: https://codereview.chromium.org/1435933003

Cr-Commit-Position: refs/heads/master@{#359385}
  • Loading branch information
ben authored and Commit bot committed Nov 12, 2015
1 parent f911237 commit 86c0f7e
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 5 deletions.
16 changes: 16 additions & 0 deletions mojo/mojo_shell.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
'shell/package_manager.h',
'shell/query_util.cc',
'shell/query_util.h',
'shell/shell_application_delegate.cc',
'shell/shell_application_delegate.h',
'shell/shell_application_loader.cc',
'shell/shell_application_loader.h',
'shell/static_application_loader.cc',
'shell/static_application_loader.h',
'shell/switches.cc',
Expand All @@ -43,6 +47,7 @@
'<(DEPTH)/mojo/mojo_base.gyp:mojo_common_lib',
'<(DEPTH)/mojo/mojo_base.gyp:mojo_environment_chromium',
'<(DEPTH)/mojo/mojo_base.gyp:mojo_url_type_converters',
'<(DEPTH)/mojo/mojo_shell.gyp:mojo_shell_interfaces',
'<(DEPTH)/url/url.gyp:url_lib',
],
}, {
Expand Down Expand Up @@ -118,5 +123,16 @@
'includes': [
'../third_party/mojo/mojom_bindings_generator_explicit.gypi',
],
}, {
'target_name': 'mojo_shell_interfaces',
'type': 'none',
'variables': {
'mojom_files': [
'shell/application_manager.mojom',
],
},
'includes': [
'../third_party/mojo/mojom_bindings_generator_explicit.gypi',
],
}],
}
11 changes: 11 additions & 0 deletions mojo/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ source_set("shell") {
"package_manager.h",
"query_util.cc",
"query_util.h",
"shell_application_delegate.cc",
"shell_application_delegate.h",
"shell_application_loader.cc",
"shell_application_loader.h",
"static_application_loader.cc",
"static_application_loader.h",
"switches.cc",
Expand All @@ -45,6 +49,7 @@ source_set("shell") {
"//url",
]
deps = [
":interfaces",
"//base/third_party/dynamic_annotations",
"//crypto:crypto",
"//mojo/application/public/cpp:sources",
Expand Down Expand Up @@ -107,3 +112,9 @@ mojom("test_bindings") {
"test.mojom",
]
}

mojom("interfaces") {
sources = [
"application_manager.mojom",
]
}
9 changes: 4 additions & 5 deletions mojo/shell/application_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "mojo/shell/fetcher.h"
#include "mojo/shell/package_manager.h"
#include "mojo/shell/query_util.h"
#include "mojo/shell/shell_application_loader.h"
#include "mojo/shell/switches.h"
#include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"

Expand Down Expand Up @@ -50,11 +51,7 @@ bool ApplicationManager::TestAPI::HasRunningInstanceForURL(

ApplicationManager::ApplicationManager(
scoped_ptr<PackageManager> package_manager)
: package_manager_(package_manager.Pass()),
task_runner_(nullptr),
weak_ptr_factory_(this) {
package_manager_->SetApplicationManager(this);
}
: ApplicationManager(package_manager.Pass(), nullptr, nullptr) {}

ApplicationManager::ApplicationManager(
scoped_ptr<PackageManager> package_manager,
Expand All @@ -65,6 +62,8 @@ ApplicationManager::ApplicationManager(
native_runner_factory_(native_runner_factory.Pass()),
weak_ptr_factory_(this) {
package_manager_->SetApplicationManager(this);
SetLoaderForURL(make_scoped_ptr(new ShellApplicationLoader(this)),
GURL("mojo:shell"));
}

ApplicationManager::~ApplicationManager() {
Expand Down
14 changes: 14 additions & 0 deletions mojo/shell/application_manager.mojom
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module mojo.shell.mojom;

interface ApplicationManager {
// Instructs the ApplicationManager to create an instance for an existing
// process at the other end of |channel|, and perform applicable
// initialization. This assumes the target process will bind the other end of
// channel to an implementation of ChildController and bind an Application
// request there.
CreateInstanceForHandle(handle channel);
};
35 changes: 35 additions & 0 deletions mojo/shell/shell_application_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/shell/shell_application_delegate.h"

#include "mojo/application/public/cpp/application_connection.h"

namespace mojo {
namespace shell {

ShellApplicationDelegate::ShellApplicationDelegate(
mojo::shell::ApplicationManager* manager)
: manager_(manager) {}
ShellApplicationDelegate::~ShellApplicationDelegate() {}

void ShellApplicationDelegate::Initialize(ApplicationImpl* app) {}
bool ShellApplicationDelegate::ConfigureIncomingConnection(
ApplicationConnection* connection) {
connection->AddService<mojom::ApplicationManager>(this);
return true;
}

void ShellApplicationDelegate::Create(
ApplicationConnection* connection,
InterfaceRequest<mojom::ApplicationManager> request) {
bindings_.AddBinding(this, request.Pass());
}

void ShellApplicationDelegate::CreateInstanceForHandle(ScopedHandle channel) {
// TODO(beng): create the instance.
}

} // namespace shell
} // namespace mojo
50 changes: 50 additions & 0 deletions mojo/shell/shell_application_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_SHELL_SHELL_APPLICATION_DELEGATE_H_
#define MOJO_SHELL_SHELL_APPLICATION_DELEGATE_H_

#include "mojo/application/public/cpp/application_delegate.h"

#include "base/macros.h"
#include "mojo/application/public/cpp/interface_factory.h"
#include "mojo/common/weak_binding_set.h"
#include "mojo/shell/application_manager.mojom.h"

namespace mojo {
namespace shell {
class ApplicationManager;

class ShellApplicationDelegate
: public ApplicationDelegate,
public InterfaceFactory<mojom::ApplicationManager>,
public mojom::ApplicationManager {
public:
explicit ShellApplicationDelegate(mojo::shell::ApplicationManager* manager);
~ShellApplicationDelegate() override;

private:
// Overridden from ApplicationDelegate:
void Initialize(ApplicationImpl* app) override;
bool ConfigureIncomingConnection(ApplicationConnection* connection) override;

// Overridden from InterfaceFactory<mojom::ApplicationManager>:
void Create(
ApplicationConnection* connection,
InterfaceRequest<mojom::ApplicationManager> request) override;

// Overridden from mojom::ApplicationManager:
void CreateInstanceForHandle(ScopedHandle channel) override;

mojo::shell::ApplicationManager* manager_;

WeakBindingSet<mojom::ApplicationManager> bindings_;

DISALLOW_COPY_AND_ASSIGN(ShellApplicationDelegate);
};

} // namespace shell
} // namespace mojo

#endif // MOJO_SHELL_SHELL_APPLICATION_DELEGATE_H_
26 changes: 26 additions & 0 deletions mojo/shell/shell_application_loader.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/shell/shell_application_loader.h"

#include "mojo/application/public/cpp/application_impl.h"
#include "mojo/shell/shell_application_delegate.h"

namespace mojo {
namespace shell {

ShellApplicationLoader::ShellApplicationLoader(ApplicationManager* manager)
: manager_(manager) {}
ShellApplicationLoader::~ShellApplicationLoader() {}

void ShellApplicationLoader::Load(
const GURL& url,
InterfaceRequest<Application> application_request) {
DCHECK(application_request.is_pending());
app_.reset(new ApplicationImpl(new ShellApplicationDelegate(manager_),
application_request.Pass()));
}

} // namespace shell
} // namespace mojo
36 changes: 36 additions & 0 deletions mojo/shell/shell_application_loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_SHELL_SHELL_APPLICATION_LOADER_H_
#define MOJO_SHELL_SHELL_APPLICATION_LOADER_H_

#include "base/macros.h"
#include "mojo/shell/application_loader.h"

namespace mojo {
class ApplicationImpl;
namespace shell {

class ShellApplicationLoader : public ApplicationLoader {
public:
explicit ShellApplicationLoader(ApplicationManager* manager);
~ShellApplicationLoader() override;

private:
// Overridden from ApplicationLoader:
void Load(
const GURL& url,
InterfaceRequest<Application> application_request) override;

scoped_ptr<ApplicationImpl> app_;

ApplicationManager* manager_;

DISALLOW_COPY_AND_ASSIGN(ShellApplicationLoader);
};

} // namespace shell
} // namespace mojo

#endif // MOJO_SHELL_SHELL_APPLICATION_LOADER_H_

0 comments on commit 86c0f7e

Please sign in to comment.