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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "mojo/examples/wm_flow/app/embedder.mojom.h"
7 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
6 #include "mojo/public/cpp/application/application_connection.h" 8 #include "mojo/public/cpp/application/application_connection.h"
7 #include "mojo/public/cpp/application/application_delegate.h" 9 #include "mojo/public/cpp/application/application_delegate.h"
8 #include "mojo/public/cpp/application/application_impl.h" 10 #include "mojo/public/cpp/application/application_impl.h"
11 #include "mojo/public/cpp/application/connect.h"
12 #include "mojo/public/cpp/application/exported_service_registry.h"
13 #include "mojo/public/cpp/application/interface_factory_impl.h"
14 #include "mojo/public/interfaces/application/service_provider.mojom.h"
9 #include "mojo/services/public/cpp/view_manager/node.h" 15 #include "mojo/services/public/cpp/view_manager/node.h"
10 #include "mojo/services/public/cpp/view_manager/view.h" 16 #include "mojo/services/public/cpp/view_manager/view.h"
11 #include "mojo/services/public/cpp/view_manager/view_manager.h" 17 #include "mojo/services/public/cpp/view_manager/view_manager.h"
12 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" 18 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
13 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
14 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" 20 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
15 21
16 namespace examples { 22 namespace examples {
17 namespace { 23 namespace {
18 void ConnectCallback(bool success) {} 24 void ConnectCallback(bool success) {}
19 25
20 const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW }; 26 const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW };
21 27
28 class EmbedderImpl : public mojo::InterfaceImpl<Embedder> {
29 public:
30 EmbedderImpl() {}
31 virtual ~EmbedderImpl() {}
32
33 private:
34 // Overridden from Embedder:
35 virtual void HelloWorld(const mojo::Callback<void()>& callback) OVERRIDE {
36 callback.Run();
37 }
38
39 DISALLOW_COPY_AND_ASSIGN(EmbedderImpl);
40 };
41
22 } // namespace 42 } // namespace
23 43
24 // This app starts its life via Connect() rather than by being embed, so it does 44 // This app starts its life via Connect() rather than by being embed, so it does
25 // not start with a connection to the ViewManager service. It has to obtain a 45 // not start with a connection to the ViewManager service. It has to obtain a
26 // connection by connecting to the ViewManagerInit service and asking to be 46 // connection by connecting to the ViewManagerInit service and asking to be
27 // embed without a node context. 47 // embed without a node context.
28 class WMFlowApp : public mojo::ApplicationDelegate, 48 class WMFlowApp : public mojo::ApplicationDelegate,
29 public mojo::ViewManagerDelegate { 49 public mojo::ViewManagerDelegate {
30 public: 50 public:
31 WMFlowApp() : embed_count_(0), view_manager_client_factory_(this) {} 51 WMFlowApp()
52 : embed_count_(0),
53 view_manager_client_factory_(this) {}
32 virtual ~WMFlowApp() {} 54 virtual ~WMFlowApp() {}
33 55
34 private: 56 private:
35 // Overridden from Application: 57 // Overridden from Application:
36 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { 58 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE {
37 mojo::ViewManagerInitServicePtr init_svc; 59 mojo::ViewManagerInitServicePtr init_svc;
60 mojo::ServiceProviderPtr sp;
38 app->ConnectToService("mojo:mojo_view_manager", &init_svc); 61 app->ConnectToService("mojo:mojo_view_manager", &init_svc);
39 init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback)); 62 init_svc->Embed("mojo:mojo_wm_flow_app", sp.Pass(),
40 init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback)); 63 base::Bind(&ConnectCallback));
41 init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback)); 64 //init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
sky 2014/07/31 21:14:10 nit: remove early attempts.
65 //init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback));
42 } 66 }
43 virtual bool ConfigureIncomingConnection( 67 virtual bool ConfigureIncomingConnection(
44 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { 68 mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
45 connection->AddService(&view_manager_client_factory_); 69 connection->AddService(&view_manager_client_factory_);
46 return true; 70 return true;
47 } 71 }
48 72
49 void OnConnect(bool success) {} 73 void OnConnect(bool success) {}
50 74
51 // Overridden from mojo::ViewManagerDelegate: 75 // Overridden from mojo::ViewManagerDelegate:
52 virtual void OnEmbed(mojo::ViewManager* view_manager, 76 virtual void OnEmbed(
53 mojo::Node* root) MOJO_OVERRIDE { 77 mojo::ViewManager* view_manager,
78 mojo::Node* root,
79 mojo::ExportedServiceRegistry* exported_services,
80 scoped_ptr<mojo::ServiceProvider> imported_services) MOJO_OVERRIDE {
54 mojo::View* view = 81 mojo::View* view =
55 mojo::View::Create(view_manager); 82 mojo::View::Create(view_manager);
56 root->SetActiveView(view); 83 root->SetActiveView(view);
57 view->SetColor(kColors[embed_count_++ % arraysize(kColors)]); 84 view->SetColor(kColors[embed_count_++ % arraysize(kColors)]);
85
86 mojo::Node* embed = mojo::Node::Create(view_manager);
87 root->AddChild(embed);
88 gfx::Rect bounds = root->bounds();
89 bounds.Inset(25, 25);
90 embed->SetBounds(bounds);
91
92 scoped_ptr<mojo::ExportedServiceRegistry> registry(
93 new mojo::ExportedServiceRegistry);
94 // Expose some services to the embeddee...
95 registry->AddService(&embedder_factory_);
96 scoped_ptr<mojo::ServiceProvider> imported =
97 embed->Embed("mojo:mojo_wm_flow_embedded", registry.Pass());
98 mojo::ConnectToService(imported.get(), &embeddee_);
99 embeddee_->HelloBack(base::Bind(&WMFlowApp::HelloBackAck,
100 base::Unretained(this)));
58 } 101 }
59 virtual void OnViewManagerDisconnected( 102 virtual void OnViewManagerDisconnected(
60 mojo::ViewManager* view_manager) MOJO_OVERRIDE {} 103 mojo::ViewManager* view_manager) MOJO_OVERRIDE {}
61 104
105 void HelloBackAck() {
106 printf("HelloBack() ack'ed\n");
107 }
108
62 int embed_count_; 109 int embed_count_;
63 mojo::ViewManagerClientFactory view_manager_client_factory_; 110 mojo::ViewManagerClientFactory view_manager_client_factory_;
111 mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_;
112 EmbeddeePtr embeddee_;
64 113
65 DISALLOW_COPY_AND_ASSIGN(WMFlowApp); 114 DISALLOW_COPY_AND_ASSIGN(WMFlowApp);
66 }; 115 };
67 116
68 } // namespace examples 117 } // namespace examples
69 118
70 namespace mojo { 119 namespace mojo {
71 120
72 // static 121 // static
73 ApplicationDelegate* ApplicationDelegate::Create() { 122 ApplicationDelegate* ApplicationDelegate::Create() {
74 return new examples::WMFlowApp; 123 return new examples::WMFlowApp;
75 } 124 }
76 125
77 } // namespace 126 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698