Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1550)

Unified Diff: mojo/examples/wm_flow/app/app.cc

Issue 433513005: Pass ServiceProvider thru ViewManagerService::Embed() allowing embedder & embeddee to expose servic… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/examples/wm_flow/app/app.cc
diff --git a/mojo/examples/wm_flow/app/app.cc b/mojo/examples/wm_flow/app/app.cc
index 075f98ae84bcb203852da06f67926080f5057592..fbcf27a60ec1d5a1096a0c1a1857a5498f8f00c8 100644
--- a/mojo/examples/wm_flow/app/app.cc
+++ b/mojo/examples/wm_flow/app/app.cc
@@ -3,9 +3,15 @@
// found in the LICENSE file.
#include "base/bind.h"
+#include "mojo/examples/wm_flow/app/embedder.mojom.h"
+#include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/connect.h"
+#include "mojo/public/cpp/application/exported_service_registry.h"
+#include "mojo/public/cpp/application/interface_factory_impl.h"
+#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
@@ -19,6 +25,20 @@ void ConnectCallback(bool success) {}
const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW };
+class EmbedderImpl : public mojo::InterfaceImpl<Embedder> {
+ public:
+ EmbedderImpl() {}
+ virtual ~EmbedderImpl() {}
+
+ private:
+ // Overridden from Embedder:
+ virtual void HelloWorld(const mojo::Callback<void()>& callback) OVERRIDE {
+ callback.Run();
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(EmbedderImpl);
+};
+
} // namespace
// This app starts its life via Connect() rather than by being embed, so it does
@@ -28,17 +48,21 @@ const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW };
class WMFlowApp : public mojo::ApplicationDelegate,
public mojo::ViewManagerDelegate {
public:
- WMFlowApp() : embed_count_(0), view_manager_client_factory_(this) {}
+ WMFlowApp()
+ : embed_count_(0),
+ view_manager_client_factory_(this) {}
virtual ~WMFlowApp() {}
private:
// Overridden from Application:
virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE {
mojo::ViewManagerInitServicePtr init_svc;
+ mojo::ServiceProviderPtr sp;
app->ConnectToService("mojo:mojo_view_manager", &init_svc);
- init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
- init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
- init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
+ init_svc->Embed("mojo:mojo_wm_flow_app", sp.Pass(),
+ base::Bind(&ConnectCallback));
+ //init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
sky 2014/07/31 21:14:10 nit: remove early attempts.
+ //init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
}
virtual bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
@@ -49,18 +73,43 @@ class WMFlowApp : public mojo::ApplicationDelegate,
void OnConnect(bool success) {}
// Overridden from mojo::ViewManagerDelegate:
- virtual void OnEmbed(mojo::ViewManager* view_manager,
- mojo::Node* root) MOJO_OVERRIDE {
+ virtual void OnEmbed(
+ mojo::ViewManager* view_manager,
+ mojo::Node* root,
+ mojo::ExportedServiceRegistry* exported_services,
+ scoped_ptr<mojo::ServiceProvider> imported_services) MOJO_OVERRIDE {
mojo::View* view =
mojo::View::Create(view_manager);
root->SetActiveView(view);
view->SetColor(kColors[embed_count_++ % arraysize(kColors)]);
+
+ mojo::Node* embed = mojo::Node::Create(view_manager);
+ root->AddChild(embed);
+ gfx::Rect bounds = root->bounds();
+ bounds.Inset(25, 25);
+ embed->SetBounds(bounds);
+
+ scoped_ptr<mojo::ExportedServiceRegistry> registry(
+ new mojo::ExportedServiceRegistry);
+ // Expose some services to the embeddee...
+ registry->AddService(&embedder_factory_);
+ scoped_ptr<mojo::ServiceProvider> imported =
+ embed->Embed("mojo:mojo_wm_flow_embedded", registry.Pass());
+ mojo::ConnectToService(imported.get(), &embeddee_);
+ embeddee_->HelloBack(base::Bind(&WMFlowApp::HelloBackAck,
+ base::Unretained(this)));
}
virtual void OnViewManagerDisconnected(
mojo::ViewManager* view_manager) MOJO_OVERRIDE {}
+ void HelloBackAck() {
+ printf("HelloBack() ack'ed\n");
+ }
+
int embed_count_;
mojo::ViewManagerClientFactory view_manager_client_factory_;
+ mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_;
+ EmbeddeePtr embeddee_;
DISALLOW_COPY_AND_ASSIGN(WMFlowApp);
};

Powered by Google App Engine
This is Rietveld 408576698