Index: mojo/examples/wm_flow/embedded/embedded.cc |
diff --git a/mojo/examples/wm_flow/app/app.cc b/mojo/examples/wm_flow/embedded/embedded.cc |
similarity index 50% |
copy from mojo/examples/wm_flow/app/app.cc |
copy to mojo/examples/wm_flow/embedded/embedded.cc |
index 075f98ae84bcb203852da06f67926080f5057592..00b242c153651ef6c7d700c714757615f7a88997 100644 |
--- a/mojo/examples/wm_flow/app/app.cc |
+++ b/mojo/examples/wm_flow/embedded/embedded.cc |
@@ -3,9 +3,14 @@ |
// 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/interface_factory_impl.h" |
+#include "mojo/public/cpp/application/service_provider_impl.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" |
@@ -14,31 +19,35 @@ |
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
namespace examples { |
+ |
namespace { |
-void ConnectCallback(bool success) {} |
-const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW }; |
+class EmbeddeeImpl : public mojo::InterfaceImpl<Embeddee> { |
+ public: |
+ EmbeddeeImpl() {} |
+ virtual ~EmbeddeeImpl() {} |
+ |
+ private: |
+ // Overridden from Embeddee: |
+ virtual void HelloBack(const mojo::Callback<void()>& callback) OVERRIDE { |
+ callback.Run(); |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(EmbeddeeImpl); |
+}; |
} // namespace |
-// This app starts its life via Connect() rather than by being embed, so it does |
-// not start with a connection to the ViewManager service. It has to obtain a |
-// connection by connecting to the ViewManagerInit service and asking to be |
-// embed without a node context. |
-class WMFlowApp : public mojo::ApplicationDelegate, |
- public mojo::ViewManagerDelegate { |
+class WMFlowEmbedded : public mojo::ApplicationDelegate, |
+ public mojo::ViewManagerDelegate { |
public: |
- WMFlowApp() : embed_count_(0), view_manager_client_factory_(this) {} |
- virtual ~WMFlowApp() {} |
+ WMFlowEmbedded() |
+ : view_manager_client_factory_(this) {} |
+ virtual ~WMFlowEmbedded() {} |
private: |
// Overridden from Application: |
virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { |
- mojo::ViewManagerInitServicePtr init_svc; |
- 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)); |
} |
virtual bool ConfigureIncomingConnection( |
mojo::ApplicationConnection* connection) MOJO_OVERRIDE { |
@@ -46,23 +55,34 @@ class WMFlowApp : public mojo::ApplicationDelegate, |
return true; |
} |
- 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::ServiceProviderImpl* 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)]); |
+ view->SetColor(SK_ColorMAGENTA); |
+ |
+ exported_services->AddService(&embeddee_factory_); |
+ mojo::ConnectToService(imported_services.get(), &embedder_); |
+ embedder_->HelloWorld(base::Bind(&WMFlowEmbedded::HelloWorldAck, |
+ base::Unretained(this))); |
} |
virtual void OnViewManagerDisconnected( |
mojo::ViewManager* view_manager) MOJO_OVERRIDE {} |
- int embed_count_; |
+ void HelloWorldAck() { |
+ printf("HelloWorld() ack'ed\n"); |
+ } |
+ |
mojo::ViewManagerClientFactory view_manager_client_factory_; |
+ EmbedderPtr embedder_; |
+ mojo::InterfaceFactoryImpl<EmbeddeeImpl> embeddee_factory_; |
- DISALLOW_COPY_AND_ASSIGN(WMFlowApp); |
+ DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded); |
}; |
} // namespace examples |
@@ -71,7 +91,7 @@ namespace mojo { |
// static |
ApplicationDelegate* ApplicationDelegate::Create() { |
- return new examples::WMFlowApp; |
+ return new examples::WMFlowEmbedded; |
} |
} // namespace |