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

Side by Side Diff: mojo/examples/wm_flow/app/app.cc

Issue 591633002: Replace most uses of ViewManagerInitService with client lib ViewManager::Embed() to offer the same … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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
« no previous file with comments | « mojo/examples/wm_flow/BUILD.gn ('k') | mojo/examples/wm_flow/embedded/embedded.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/application/application_runner_chromium.h" 6 #include "mojo/application/application_runner_chromium.h"
7 #include "mojo/examples/wm_flow/app/embedder.mojom.h" 7 #include "mojo/examples/wm_flow/app/embedder.mojom.h"
8 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h" 8 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
9 #include "mojo/public/c/system/main.h" 9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_impl.h" 12 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/connect.h" 13 #include "mojo/public/cpp/application/connect.h"
14 #include "mojo/public/cpp/application/interface_factory_impl.h" 14 #include "mojo/public/cpp/application/interface_factory_impl.h"
15 #include "mojo/public/cpp/application/service_provider_impl.h" 15 #include "mojo/public/cpp/application/service_provider_impl.h"
16 #include "mojo/public/interfaces/application/service_provider.mojom.h" 16 #include "mojo/public/interfaces/application/service_provider.mojom.h"
17 #include "mojo/services/public/cpp/view_manager/view.h" 17 #include "mojo/services/public/cpp/view_manager/view.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager.h" 18 #include "mojo/services/public/cpp/view_manager/view_manager.h"
19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" 19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
20 #include "mojo/services/public/cpp/view_manager/view_manager_context.h"
20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 21 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
21 #include "mojo/services/public/cpp/view_manager/view_observer.h" 22 #include "mojo/services/public/cpp/view_manager/view_observer.h"
22 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
23 23
24 namespace examples { 24 namespace examples {
25 namespace { 25 namespace {
26 void ConnectCallback(bool success) {}
27 26
28 const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW }; 27 const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW };
29 28
30 class EmbedderImpl : public mojo::InterfaceImpl<Embedder> { 29 class EmbedderImpl : public mojo::InterfaceImpl<Embedder> {
31 public: 30 public:
32 EmbedderImpl() {} 31 EmbedderImpl() {}
33 virtual ~EmbedderImpl() {} 32 virtual ~EmbedderImpl() {}
34 33
35 private: 34 private:
36 // Overridden from Embedder: 35 // Overridden from Embedder:
37 virtual void HelloWorld(const mojo::Callback<void()>& callback) OVERRIDE { 36 virtual void HelloWorld(const mojo::Callback<void()>& callback) OVERRIDE {
38 callback.Run(); 37 callback.Run();
39 } 38 }
40 39
41 DISALLOW_COPY_AND_ASSIGN(EmbedderImpl); 40 DISALLOW_COPY_AND_ASSIGN(EmbedderImpl);
42 }; 41 };
43 42
44 } // namespace 43 } // namespace
45 44
46 // This app starts its life via Connect() rather than by being embed, so it does 45 // This app starts its life via Connect() rather than by being embed, so it does
47 // not start with a connection to the ViewManager service. It has to obtain a 46 // not start with a connection to the ViewManager service. It has to obtain a
48 // connection by connecting to the ViewManagerInit service and asking to be 47 // connection by connecting to the ViewManagerInit service and asking to be
49 // embed without a view context. 48 // embed without a view context.
50 class WMFlowApp : public mojo::ApplicationDelegate, 49 class WMFlowApp : public mojo::ApplicationDelegate,
51 public mojo::ViewManagerDelegate, 50 public mojo::ViewManagerDelegate,
52 public mojo::ViewObserver { 51 public mojo::ViewObserver {
53 public: 52 public:
54 WMFlowApp() 53 WMFlowApp() : embed_count_(0) {}
55 : embed_count_(0),
56 app_(NULL) {}
57 virtual ~WMFlowApp() {} 54 virtual ~WMFlowApp() {}
58 55
59 private: 56 private:
60 // Overridden from Application: 57 // Overridden from Application:
61 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { 58 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE {
62 view_manager_client_factory_.reset( 59 view_manager_client_factory_.reset(
63 new mojo::ViewManagerClientFactory(app->shell(), this)); 60 new mojo::ViewManagerClientFactory(app->shell(), this));
64 app_ = app; 61 view_manager_context_.reset(new mojo::ViewManagerContext(app));
65 OpenNewWindow(); 62 OpenNewWindow();
66 OpenNewWindow(); 63 OpenNewWindow();
67 OpenNewWindow(); 64 OpenNewWindow();
68 } 65 }
69 virtual bool ConfigureIncomingConnection( 66 virtual bool ConfigureIncomingConnection(
70 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { 67 mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
71 connection->AddService(view_manager_client_factory_.get()); 68 connection->AddService(view_manager_client_factory_.get());
72 return true; 69 return true;
73 } 70 }
74 71
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE { 110 virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE {
114 --embed_count_; 111 --embed_count_;
115 view->RemoveObserver(this); 112 view->RemoveObserver(this);
116 } 113 }
117 114
118 void HelloBackAck() { 115 void HelloBackAck() {
119 printf("HelloBack() ack'ed\n"); 116 printf("HelloBack() ack'ed\n");
120 } 117 }
121 118
122 void OpenNewWindow() { 119 void OpenNewWindow() {
123 mojo::ViewManagerInitServicePtr init_svc; 120 view_manager_context_->Embed("mojo:mojo_wm_flow_app");
124 app_->ConnectToService("mojo:mojo_view_manager", &init_svc);
125 mojo::ServiceProviderPtr sp;
126 init_svc->Embed("mojo:mojo_wm_flow_app", sp.Pass(),
127 base::Bind(&ConnectCallback));
128 } 121 }
129 122
130 int embed_count_; 123 int embed_count_;
131 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; 124 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_;
132 mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_; 125 mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_;
126 scoped_ptr<mojo::ViewManagerContext> view_manager_context_;
133 EmbeddeePtr embeddee_; 127 EmbeddeePtr embeddee_;
134 mojo::ApplicationImpl* app_;
135 128
136 DISALLOW_COPY_AND_ASSIGN(WMFlowApp); 129 DISALLOW_COPY_AND_ASSIGN(WMFlowApp);
137 }; 130 };
138 131
139 } // namespace examples 132 } // namespace examples
140 133
141 MojoResult MojoMain(MojoHandle shell_handle) { 134 MojoResult MojoMain(MojoHandle shell_handle) {
142 mojo::ApplicationRunnerChromium runner(new examples::WMFlowApp); 135 mojo::ApplicationRunnerChromium runner(new examples::WMFlowApp);
143 return runner.Run(shell_handle); 136 return runner.Run(shell_handle);
144 } 137 }
OLDNEW
« no previous file with comments | « mojo/examples/wm_flow/BUILD.gn ('k') | mojo/examples/wm_flow/embedded/embedded.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698