Make BaseView et al. take an ApplicationConnector instead of an ApplicationImpl.

In general, it's a bit of a layering violation to pass around
ApplicationImpl*'s, and it also poses some lifetime issues. (Using
ApplicationConnectors resolves any potential lifetime issues.)

Mostly though, I want to rework the way ApplicationImpl, etc. work, and
this gets in the way.

R=jeffbrown@google.com

Review URL: https://codereview.chromium.org/1991853003 .
diff --git a/apps/moterm/moterm_app.cc b/apps/moterm/moterm_app.cc
index ab8abfa..3eabe88 100644
--- a/apps/moterm/moterm_app.cc
+++ b/apps/moterm/moterm_app.cc
@@ -5,6 +5,7 @@
 #include "apps/moterm/moterm_app.h"
 
 #include "apps/moterm/moterm_view.h"
+#include "mojo/public/cpp/application/connect.h"
 
 MotermApp::MotermApp() {}
 
@@ -15,5 +16,6 @@
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
     mojo::InterfaceRequest<mojo::ServiceProvider> services,
     mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) {
-  new MotermView(app_impl(), view_owner_request.Pass(), services.Pass());
+  new MotermView(mojo::CreateApplicationConnector(app_impl()->shell()),
+                 view_owner_request.Pass(), services.Pass());
 }
diff --git a/apps/moterm/moterm_view.cc b/apps/moterm/moterm_view.cc
index e9f942f..43cb2fc 100644
--- a/apps/moterm/moterm_view.cc
+++ b/apps/moterm/moterm_view.cc
@@ -38,10 +38,10 @@
 constexpr uint32_t kRootNodeId = mojo::gfx::composition::kSceneRootNodeId;
 
 MotermView::MotermView(
-    mojo::ApplicationImpl* app_impl,
+    mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
     mojo::InterfaceRequest<mojo::ServiceProvider> service_provider_request)
-    : GaneshView(app_impl, view_owner_request.Pass(), "Moterm"),
+    : GaneshView(app_connector.Pass(), view_owner_request.Pass(), "Moterm"),
       choreographer_(scene(), this),
       input_handler_(GetViewServiceProvider(), this),
       model_(MotermModel::Size(240, 160), MotermModel::Size(24, 80), this),
diff --git a/apps/moterm/moterm_view.h b/apps/moterm/moterm_view.h
index 3595c4e..a98f29d 100644
--- a/apps/moterm/moterm_view.h
+++ b/apps/moterm/moterm_view.h
@@ -32,7 +32,7 @@
                    public mojo::terminal::Terminal {
  public:
   MotermView(
-      mojo::ApplicationImpl* app_impl,
+      mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
       mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
       mojo::InterfaceRequest<mojo::ServiceProvider> service_provider_request);
   ~MotermView() override;
diff --git a/examples/shadows/shadows_app.cc b/examples/shadows/shadows_app.cc
index fd6279a..207476b 100644
--- a/examples/shadows/shadows_app.cc
+++ b/examples/shadows/shadows_app.cc
@@ -5,6 +5,7 @@
 #include "examples/shadows/shadows_app.h"
 
 #include "examples/shadows/shadows_view.h"
+#include "mojo/public/cpp/application/connect.h"
 
 namespace examples {
 
@@ -17,7 +18,8 @@
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
     mojo::InterfaceRequest<mojo::ServiceProvider> services,
     mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) {
-  new ShadowsView(app_impl(), view_owner_request.Pass());
+  new ShadowsView(mojo::CreateApplicationConnector(app_impl()->shell()),
+                  view_owner_request.Pass());
 }
 
 }  // namespace examples
diff --git a/examples/shadows/shadows_view.cc b/examples/shadows/shadows_view.cc
index 86a3f75..a3d5a1a 100644
--- a/examples/shadows/shadows_view.cc
+++ b/examples/shadows/shadows_view.cc
@@ -19,9 +19,9 @@
 }  // namespace
 
 ShadowsView::ShadowsView(
-    mojo::ApplicationImpl* app_impl,
+    mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request)
-    : GLView(app_impl, view_owner_request.Pass(), "Shadows"),
+    : GLView(app_connector.Pass(), view_owner_request.Pass(), "Shadows"),
       choreographer_(scene(), this) {
   mojo::GLContext::Scope gl_scope(gl_context());
   renderer_.reset(new ShadowsRenderer());
diff --git a/examples/shadows/shadows_view.h b/examples/shadows/shadows_view.h
index 893dfad..e5e49a0 100644
--- a/examples/shadows/shadows_view.h
+++ b/examples/shadows/shadows_view.h
@@ -16,7 +16,7 @@
 class ShadowsView : public mojo::ui::GLView,
                     public mojo::ui::ChoreographerDelegate {
  public:
-  ShadowsView(mojo::ApplicationImpl* app_impl,
+  ShadowsView(mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
               mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request);
 
   ~ShadowsView() override;
diff --git a/examples/ui/jank/jank.cc b/examples/ui/jank/jank.cc
index c3efb63..aedb12e 100644
--- a/examples/ui/jank/jank.cc
+++ b/examples/ui/jank/jank.cc
@@ -10,6 +10,7 @@
 #include "base/macros.h"
 #include "mojo/application/application_runner_chromium.h"
 #include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/connect.h"
 #include "mojo/ui/choreographer.h"
 #include "mojo/ui/ganesh_view.h"
 #include "mojo/ui/input_handler.h"
@@ -53,9 +54,9 @@
                  public mojo::ui::ChoreographerDelegate,
                  public mojo::ui::InputListener {
  public:
-  JankView(mojo::ApplicationImpl* app_impl,
+  JankView(mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
            mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request)
-      : GaneshView(app_impl, view_owner_request.Pass(), "Jank"),
+      : GaneshView(app_connector.Pass(), view_owner_request.Pass(), "Jank"),
         choreographer_(scene(), this),
         input_handler_(GetViewServiceProvider(), this),
         typeface_(skia::AdoptRef(SkTypeface::CreateFromStream(
@@ -210,7 +211,8 @@
       mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
       mojo::InterfaceRequest<mojo::ServiceProvider> services,
       mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) override {
-    new JankView(app_impl(), view_owner_request.Pass());
+    new JankView(mojo::CreateApplicationConnector(app_impl()->shell()),
+                 view_owner_request.Pass());
   }
 
  private:
diff --git a/examples/ui/noodles/noodles_app.cc b/examples/ui/noodles/noodles_app.cc
index c790822..1b4034a 100644
--- a/examples/ui/noodles/noodles_app.cc
+++ b/examples/ui/noodles/noodles_app.cc
@@ -5,6 +5,7 @@
 #include "examples/ui/noodles/noodles_app.h"
 
 #include "examples/ui/noodles/noodles_view.h"
+#include "mojo/public/cpp/application/connect.h"
 
 namespace examples {
 
@@ -17,7 +18,8 @@
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
     mojo::InterfaceRequest<mojo::ServiceProvider> services,
     mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) {
-  new NoodlesView(app_impl(), view_owner_request.Pass());
+  new NoodlesView(mojo::CreateApplicationConnector(app_impl()->shell()),
+                  view_owner_request.Pass());
 }
 
 }  // namespace examples
diff --git a/examples/ui/noodles/noodles_view.cc b/examples/ui/noodles/noodles_view.cc
index 6c790a6..eec3045 100644
--- a/examples/ui/noodles/noodles_view.cc
+++ b/examples/ui/noodles/noodles_view.cc
@@ -50,9 +50,9 @@
 }  // namespace
 
 NoodlesView::NoodlesView(
-    mojo::ApplicationImpl* app_impl,
+    mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request)
-    : BaseView(app_impl, view_owner_request.Pass(), "Noodles"),
+    : BaseView(app_connector.Pass(), view_owner_request.Pass(), "Noodles"),
       choreographer_(scene(), this),
       frame_queue_(std::make_shared<FrameQueue>()),
       rasterizer_delegate_(
@@ -65,12 +65,11 @@
   rasterizer_task_runner_ = rasterizer_thread_->message_loop()->task_runner();
 
   rasterizer_task_runner_->PostTask(
-      FROM_HERE,
-      base::Bind(
-          &RasterizerDelegate::CreateRasterizer,
-          base::Unretained(rasterizer_delegate_.get()),
-          base::Passed(mojo::CreateApplicationConnector(app_impl->shell())),
-          base::Passed(TakeScene().PassInterfaceHandle())));
+      FROM_HERE, base::Bind(&RasterizerDelegate::CreateRasterizer,
+                            base::Unretained(rasterizer_delegate_.get()),
+                            base::Passed(mojo::DuplicateApplicationConnector(
+                                BaseView::app_connector())),
+                            base::Passed(TakeScene().PassInterfaceHandle())));
 }
 
 NoodlesView::~NoodlesView() {
diff --git a/examples/ui/noodles/noodles_view.h b/examples/ui/noodles/noodles_view.h
index 8c3470c..c7d1a25 100644
--- a/examples/ui/noodles/noodles_view.h
+++ b/examples/ui/noodles/noodles_view.h
@@ -27,7 +27,7 @@
 class NoodlesView : public mojo::ui::BaseView,
                     public mojo::ui::ChoreographerDelegate {
  public:
-  NoodlesView(mojo::ApplicationImpl* app_impl,
+  NoodlesView(mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
               mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request);
 
   ~NoodlesView() override;
diff --git a/examples/ui/pdf_viewer/pdf_viewer.cc b/examples/ui/pdf_viewer/pdf_viewer.cc
index 8fd3441..2209ba8 100644
--- a/examples/ui/pdf_viewer/pdf_viewer.cc
+++ b/examples/ui/pdf_viewer/pdf_viewer.cc
@@ -11,6 +11,7 @@
 #include "mojo/application/application_runner_chromium.h"
 #include "mojo/data_pipe_utils/data_pipe_utils.h"
 #include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/connect.h"
 #include "mojo/ui/choreographer.h"
 #include "mojo/ui/content_viewer_app.h"
 #include "mojo/ui/ganesh_view.h"
@@ -116,10 +117,12 @@
                         public mojo::ui::InputListener {
  public:
   PDFDocumentView(
-      mojo::ApplicationImpl* app_impl,
+      mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
       mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
       const std::shared_ptr<PDFDocument>& pdf_document)
-      : GaneshView(app_impl, view_owner_request.Pass(), "PDFDocumentViewer"),
+      : GaneshView(app_connector.Pass(),
+                   view_owner_request.Pass(),
+                   "PDFDocumentViewer"),
         pdf_document_(pdf_document),
         choreographer_(scene(), this),
         input_handler_(GetViewServiceProvider(), this) {
@@ -271,7 +274,8 @@
       mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
       mojo::InterfaceRequest<mojo::ServiceProvider> services,
       mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) override {
-    new PDFDocumentView(app_impl(), view_owner_request.Pass(), pdf_document_);
+    new PDFDocumentView(mojo::CreateApplicationConnector(app_impl()->shell()),
+                        view_owner_request.Pass(), pdf_document_);
   }
 
  private:
diff --git a/examples/ui/png_viewer/png_viewer.cc b/examples/ui/png_viewer/png_viewer.cc
index fc7589d..bec7677 100644
--- a/examples/ui/png_viewer/png_viewer.cc
+++ b/examples/ui/png_viewer/png_viewer.cc
@@ -10,6 +10,7 @@
 #include "mojo/application/application_runner_chromium.h"
 #include "mojo/data_pipe_utils/data_pipe_utils.h"
 #include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/connect.h"
 #include "mojo/ui/content_viewer_app.h"
 #include "mojo/ui/ganesh_view.h"
 #include "third_party/skia/include/core/SkBitmap.h"
@@ -27,10 +28,12 @@
 
 class PNGView : public mojo::ui::GaneshView {
  public:
-  PNGView(mojo::ApplicationImpl* app_impl,
+  PNGView(mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
           mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
           const skia::RefPtr<SkImage>& image)
-      : GaneshView(app_impl, view_owner_request.Pass(), "PNGViewer"),
+      : GaneshView(app_connector.Pass(),
+                   view_owner_request.Pass(),
+                   "PNGViewer"),
         image_(image) {
     DCHECK(image_);
   }
@@ -119,7 +122,8 @@
       mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
       mojo::InterfaceRequest<mojo::ServiceProvider> services,
       mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) override {
-    new PNGView(app_impl(), view_owner_request.Pass(), image_);
+    new PNGView(mojo::CreateApplicationConnector(app_impl()->shell()),
+                view_owner_request.Pass(), image_);
   }
 
  private:
diff --git a/examples/ui/shapes/shapes_app.cc b/examples/ui/shapes/shapes_app.cc
index 84643a0..5d0f0c1 100644
--- a/examples/ui/shapes/shapes_app.cc
+++ b/examples/ui/shapes/shapes_app.cc
@@ -5,6 +5,7 @@
 #include "examples/ui/shapes/shapes_app.h"
 
 #include "examples/ui/shapes/shapes_view.h"
+#include "mojo/public/cpp/application/connect.h"
 
 namespace examples {
 
@@ -17,7 +18,8 @@
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
     mojo::InterfaceRequest<mojo::ServiceProvider> services,
     mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) {
-  new ShapesView(app_impl(), view_owner_request.Pass());
+  new ShapesView(mojo::CreateApplicationConnector(app_impl()->shell()),
+                 view_owner_request.Pass());
 }
 
 }  // namespace examples
diff --git a/examples/ui/shapes/shapes_view.cc b/examples/ui/shapes/shapes_view.cc
index 07611aa..721c2a0 100644
--- a/examples/ui/shapes/shapes_view.cc
+++ b/examples/ui/shapes/shapes_view.cc
@@ -18,9 +18,9 @@
 }  // namespace
 
 ShapesView::ShapesView(
-    mojo::ApplicationImpl* app_impl,
+    mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request)
-    : GaneshView(app_impl, view_owner_request.Pass(), "Shapes") {}
+    : GaneshView(app_connector.Pass(), view_owner_request.Pass(), "Shapes") {}
 
 ShapesView::~ShapesView() {}
 
diff --git a/examples/ui/shapes/shapes_view.h b/examples/ui/shapes/shapes_view.h
index bce122f..a4ad165 100644
--- a/examples/ui/shapes/shapes_view.h
+++ b/examples/ui/shapes/shapes_view.h
@@ -13,7 +13,7 @@
 
 class ShapesView : public mojo::ui::GaneshView {
  public:
-  ShapesView(mojo::ApplicationImpl* app_impl,
+  ShapesView(mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
              mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request);
 
   ~ShapesView() override;
diff --git a/examples/ui/spinning_cube/spinning_cube_app.cc b/examples/ui/spinning_cube/spinning_cube_app.cc
index 2fbe9d4..6159641 100644
--- a/examples/ui/spinning_cube/spinning_cube_app.cc
+++ b/examples/ui/spinning_cube/spinning_cube_app.cc
@@ -5,6 +5,7 @@
 #include "examples/ui/spinning_cube/spinning_cube_app.h"
 
 #include "examples/ui/spinning_cube/spinning_cube_view.h"
+#include "mojo/public/cpp/application/connect.h"
 
 namespace examples {
 
@@ -17,7 +18,8 @@
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
     mojo::InterfaceRequest<mojo::ServiceProvider> services,
     mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) {
-  new SpinningCubeView(app_impl(), view_owner_request.Pass());
+  new SpinningCubeView(mojo::CreateApplicationConnector(app_impl()->shell()),
+                       view_owner_request.Pass());
 }
 
 }  // namespace examples
diff --git a/examples/ui/spinning_cube/spinning_cube_view.cc b/examples/ui/spinning_cube/spinning_cube_view.cc
index fab02ec..9386b88 100644
--- a/examples/ui/spinning_cube/spinning_cube_view.cc
+++ b/examples/ui/spinning_cube/spinning_cube_view.cc
@@ -54,9 +54,9 @@
 }  // namespace
 
 SpinningCubeView::SpinningCubeView(
-    mojo::ApplicationImpl* app_impl,
+    mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request)
-    : GLView(app_impl, view_owner_request.Pass(), "SpinningCube"),
+    : GLView(app_connector.Pass(), view_owner_request.Pass(), "SpinningCube"),
       choreographer_(scene(), this),
       input_handler_(GetViewServiceProvider(), this),
       weak_ptr_factory_(this) {
diff --git a/examples/ui/spinning_cube/spinning_cube_view.h b/examples/ui/spinning_cube/spinning_cube_view.h
index 5de87e5..35b0f24 100644
--- a/examples/ui/spinning_cube/spinning_cube_view.h
+++ b/examples/ui/spinning_cube/spinning_cube_view.h
@@ -19,7 +19,7 @@
                          public mojo::ui::InputListener {
  public:
   SpinningCubeView(
-      mojo::ApplicationImpl* app_impl,
+      mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
       mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request);
 
   ~SpinningCubeView() override;
diff --git a/examples/ui/tile/tile_app.cc b/examples/ui/tile/tile_app.cc
index 31a721e..2b39309 100644
--- a/examples/ui/tile/tile_app.cc
+++ b/examples/ui/tile/tile_app.cc
@@ -5,6 +5,7 @@
 #include "base/strings/string_split.h"
 #include "examples/ui/tile/tile_app.h"
 #include "examples/ui/tile/tile_view.h"
+#include "mojo/public/cpp/application/connect.h"
 #include "url/url_parse.h"
 
 namespace examples {
@@ -24,7 +25,8 @@
     return;
   }
 
-  new TileView(app_impl(), view_owner_request.Pass(), params);
+  new TileView(mojo::CreateApplicationConnector(app_impl()->shell()),
+               view_owner_request.Pass(), params);
 }
 
 bool TileApp::ParseParams(const std::string& connection_url,
diff --git a/examples/ui/tile/tile_view.cc b/examples/ui/tile/tile_view.cc
index 4a69986..b09815e 100644
--- a/examples/ui/tile/tile_view.cc
+++ b/examples/ui/tile/tile_view.cc
@@ -27,10 +27,11 @@
 TileParams::~TileParams() {}
 
 TileView::TileView(
-    mojo::ApplicationImpl* app_impl,
+    mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
     mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
     const TileParams& params)
-    : BaseView(app_impl, view_owner_request.Pass(), "Tile"), params_(params) {
+    : BaseView(app_connector.Pass(), view_owner_request.Pass(), "Tile"),
+      params_(params) {
   ConnectViews();
 }
 
@@ -41,7 +42,7 @@
   for (const auto& url : params_.view_urls) {
     // Start connecting to the view provider.
     mojo::ui::ViewProviderPtr provider;
-    mojo::ConnectToService(app_impl()->shell(), url, mojo::GetProxy(&provider));
+    mojo::ConnectToService(app_connector(), url, mojo::GetProxy(&provider));
 
     LOG(INFO) << "Connecting to view: child_key=" << child_key
               << ", url=" << url;
diff --git a/examples/ui/tile/tile_view.h b/examples/ui/tile/tile_view.h
index 3ea7bbd..6ee3193 100644
--- a/examples/ui/tile/tile_view.h
+++ b/examples/ui/tile/tile_view.h
@@ -42,7 +42,7 @@
 
 class TileView : public mojo::ui::BaseView {
  public:
-  TileView(mojo::ApplicationImpl* app_impl_,
+  TileView(mojo::InterfaceHandle<mojo::ApplicationConnector> app_connector,
            mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
            const TileParams& tile_params);
 
diff --git a/mojo/public/cpp/application/connect.h b/mojo/public/cpp/application/connect.h
index 946ca7d..3b3fd9c 100644
--- a/mojo/public/cpp/application/connect.h
+++ b/mojo/public/cpp/application/connect.h
@@ -63,6 +63,12 @@
 // passed to any thread) from the shell.
 InterfaceHandle<ApplicationConnector> CreateApplicationConnector(Shell* shell);
 
+// Helper for "duplicating" a |ApplicationConnector| (typically, from an
+// |ApplicationConnectorPtr|, getting another independent
+// |InterfaceHandle<ApplicationConnector>|).
+InterfaceHandle<ApplicationConnector> DuplicateApplicationConnector(
+    ApplicationConnector* application_connector);
+
 }  // namespace mojo
 
 #endif  // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_
diff --git a/mojo/public/cpp/application/lib/connect.cc b/mojo/public/cpp/application/lib/connect.cc
index 33130da..f6957c3 100644
--- a/mojo/public/cpp/application/lib/connect.cc
+++ b/mojo/public/cpp/application/lib/connect.cc
@@ -14,4 +14,11 @@
   return application_connector;
 }
 
+InterfaceHandle<ApplicationConnector> DuplicateApplicationConnector(
+    ApplicationConnector* application_connector) {
+  InterfaceHandle<ApplicationConnector> new_application_connector;
+  application_connector->Duplicate(GetProxy(&new_application_connector));
+  return new_application_connector;
+}
+
 }  // namespace mojo
diff --git a/mojo/ui/base_view.cc b/mojo/ui/base_view.cc
index 68611d7..124425f 100644
--- a/mojo/ui/base_view.cc
+++ b/mojo/ui/base_view.cc
@@ -10,55 +10,52 @@
 namespace mojo {
 namespace ui {
 
-BaseView::BaseView(
-    mojo::ApplicationImpl* app_impl,
-    mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
-    const std::string& label)
-    : app_impl_(app_impl),
+BaseView::BaseView(InterfaceHandle<ApplicationConnector> app_connector,
+                   InterfaceRequest<ViewOwner> view_owner_request,
+                   const std::string& label)
+    : app_connector_(ApplicationConnectorPtr::Create(app_connector.Pass())),
       view_listener_binding_(this),
       view_container_listener_binding_(this) {
-  DCHECK(app_impl_);
-  ConnectToService(app_impl_->shell(), "mojo:view_manager_service",
-                   mojo::GetProxy(&view_manager_));
+  DCHECK(app_connector_);
+  ConnectToService(app_connector_.get(), "mojo:view_manager_service",
+                   GetProxy(&view_manager_));
 
-  mojo::ui::ViewListenerPtr view_listener;
-  view_listener_binding_.Bind(mojo::GetProxy(&view_listener));
-  view_manager_->CreateView(mojo::GetProxy(&view_), view_owner_request.Pass(),
+  ViewListenerPtr view_listener;
+  view_listener_binding_.Bind(GetProxy(&view_listener));
+  view_manager_->CreateView(GetProxy(&view_), view_owner_request.Pass(),
                             view_listener.Pass(), label);
-  view_->CreateScene(mojo::GetProxy(&scene_));
+  view_->CreateScene(GetProxy(&scene_));
 }
 
 BaseView::~BaseView() {}
 
-mojo::ServiceProvider* BaseView::GetViewServiceProvider() {
+ServiceProvider* BaseView::GetViewServiceProvider() {
   if (!view_service_provider_)
-    view_->GetServiceProvider(mojo::GetProxy(&view_service_provider_));
+    view_->GetServiceProvider(GetProxy(&view_service_provider_));
   return view_service_provider_.get();
 }
 
-mojo::ui::ViewContainer* BaseView::GetViewContainer() {
+ViewContainer* BaseView::GetViewContainer() {
   if (!view_container_) {
-    view_->GetContainer(mojo::GetProxy(&view_container_));
-    mojo::ui::ViewContainerListenerPtr view_container_listener;
-    view_container_listener_binding_.Bind(
-        mojo::GetProxy(&view_container_listener));
+    view_->GetContainer(GetProxy(&view_container_));
+    ViewContainerListenerPtr view_container_listener;
+    view_container_listener_binding_.Bind(GetProxy(&view_container_listener));
     view_container_->SetListener(view_container_listener.Pass());
   }
   return view_container_.get();
 }
 
 void BaseView::OnPropertiesChanged(uint32_t old_scene_version,
-                                   mojo::ui::ViewPropertiesPtr old_properties) {
-}
+                                   ViewPropertiesPtr old_properties) {}
 
 void BaseView::OnChildAttached(uint32_t child_key,
-                               mojo::ui::ViewInfoPtr child_view_info) {}
+                               ViewInfoPtr child_view_info) {}
 
 void BaseView::OnChildUnavailable(uint32_t child_key) {}
 
 void BaseView::OnPropertiesChanged(
     uint32_t scene_version,
-    mojo::ui::ViewPropertiesPtr properties,
+    ViewPropertiesPtr properties,
     const OnPropertiesChangedCallback& callback) {
   DCHECK(properties);
   DCHECK(properties->display_metrics);
@@ -66,7 +63,7 @@
   DCHECK(properties->view_layout->size);
 
   uint32_t old_scene_version = scene_version_;
-  mojo::ui::ViewPropertiesPtr old_properties = properties_.Pass();
+  ViewPropertiesPtr old_properties = properties_.Pass();
   scene_version_ = scene_version;
   properties_ = properties.Pass();
 
@@ -75,7 +72,7 @@
 }
 
 void BaseView::OnChildAttached(uint32_t child_key,
-                               mojo::ui::ViewInfoPtr child_view_info,
+                               ViewInfoPtr child_view_info,
                                const OnChildUnavailableCallback& callback) {
   DCHECK(child_view_info);
 
diff --git a/mojo/ui/base_view.h b/mojo/ui/base_view.h
index e5fe71c..a8f2b69 100644
--- a/mojo/ui/base_view.h
+++ b/mojo/ui/base_view.h
@@ -7,10 +7,11 @@
 
 #include <string>
 
-#include "mojo/public/cpp/application/application_impl.h"
 #include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/interface_handle.h"
 #include "mojo/public/cpp/bindings/strong_binding.h"
 #include "mojo/public/cpp/system/macros.h"
+#include "mojo/public/interfaces/application/application_connector.mojom.h"
 #include "mojo/public/interfaces/application/service_provider.mojom.h"
 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h"
 #include "mojo/services/ui/views/interfaces/view_manager.mojom.h"
@@ -25,55 +26,51 @@
 //
 // It is not necessary to use this class to implement all Views.
 // This class is merely intended to make the simple apps easier to write.
-class BaseView : public mojo::ui::ViewListener,
-                 public mojo::ui::ViewContainerListener {
+class BaseView : public ViewListener, public ViewContainerListener {
  public:
-  // TODO(jeffbrown): Consider switching this over to an ApplicationConnector
-  // but having ApplicationImpl is handy for simple examples.
-  BaseView(mojo::ApplicationImpl* app_impl,
-           mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
+  BaseView(InterfaceHandle<ApplicationConnector> app_connector,
+           InterfaceRequest<ViewOwner> view_owner_request,
            const std::string& label);
 
   ~BaseView() override;
 
   // Gets the application implementation object provided at creation time.
-  mojo::ApplicationImpl* app_impl() { return app_impl_; }
+  ApplicationConnector* app_connector() { return app_connector_.get(); }
 
   // Gets the view manager.
-  mojo::ui::ViewManager* view_manager() { return view_manager_.get(); }
+  ViewManager* view_manager() { return view_manager_.get(); }
 
   // Gets the underlying view interface.
-  mojo::ui::View* view() { return view_.get(); }
+  View* view() { return view_.get(); }
 
   // Gets the service provider for the view.
-  mojo::ServiceProvider* GetViewServiceProvider();
+  ServiceProvider* GetViewServiceProvider();
 
   // Gets the underlying view container interface.
-  mojo::ui::ViewContainer* GetViewContainer();
+  ViewContainer* GetViewContainer();
 
   // Gets the scene for the view.
   // Returns nullptr if the |TakeScene| was called.
-  mojo::gfx::composition::Scene* scene() { return scene_.get(); }
+  gfx::composition::Scene* scene() { return scene_.get(); }
 
   // Takes the scene from the view.
   // This is useful if the scene will be rendered by a separate component.
-  mojo::gfx::composition::ScenePtr TakeScene() { return scene_.Pass(); }
+  gfx::composition::ScenePtr TakeScene() { return scene_.Pass(); }
 
   // Gets the currently requested scene version.
   uint32_t scene_version() { return scene_version_; }
 
   // Gets the current view properties.
   // Returns nullptr if none.
-  mojo::ui::ViewProperties* properties() { return properties_.get(); }
+  ViewProperties* properties() { return properties_.get(); }
 
   // Called when properties changed.
   // Use |scene_version()| and |properties()| to get the current values.
   virtual void OnPropertiesChanged(uint32_t old_scene_version,
-                                   mojo::ui::ViewPropertiesPtr old_properties);
+                                   ViewPropertiesPtr old_properties);
 
   // Called when a child is attached.
-  virtual void OnChildAttached(uint32_t child_key,
-                               mojo::ui::ViewInfoPtr child_view_info);
+  virtual void OnChildAttached(uint32_t child_key, ViewInfoPtr child_view_info);
 
   // Called when a child becomes unavailable.
   virtual void OnChildUnavailable(uint32_t child_key);
@@ -82,28 +79,27 @@
   // |ViewListener|:
   void OnPropertiesChanged(
       uint32_t scene_version,
-      mojo::ui::ViewPropertiesPtr properties,
+      ViewPropertiesPtr properties,
       const OnPropertiesChangedCallback& callback) override;
 
   // |ViewContainerListener|:
   void OnChildAttached(uint32_t child_key,
-                       mojo::ui::ViewInfoPtr child_view_info,
+                       ViewInfoPtr child_view_info,
                        const OnChildAttachedCallback& callback) override;
   void OnChildUnavailable(uint32_t child_key,
                           const OnChildUnavailableCallback& callback) override;
 
-  mojo::ApplicationImpl* app_impl_;
+  ApplicationConnectorPtr app_connector_;
 
-  mojo::StrongBinding<mojo::ui::ViewListener> view_listener_binding_;
-  mojo::Binding<mojo::ui::ViewContainerListener>
-      view_container_listener_binding_;
-  mojo::ui::ViewManagerPtr view_manager_;
-  mojo::ui::ViewPtr view_;
-  mojo::ServiceProviderPtr view_service_provider_;
-  mojo::ui::ViewContainerPtr view_container_;
-  mojo::gfx::composition::ScenePtr scene_;
-  uint32_t scene_version_ = mojo::gfx::composition::kSceneVersionNone;
-  mojo::ui::ViewPropertiesPtr properties_;
+  StrongBinding<ViewListener> view_listener_binding_;
+  Binding<ViewContainerListener> view_container_listener_binding_;
+  ViewManagerPtr view_manager_;
+  ViewPtr view_;
+  ServiceProviderPtr view_service_provider_;
+  ViewContainerPtr view_container_;
+  gfx::composition::ScenePtr scene_;
+  uint32_t scene_version_ = gfx::composition::kSceneVersionNone;
+  ViewPropertiesPtr properties_;
 
   MOJO_DISALLOW_COPY_AND_ASSIGN(BaseView);
 };
diff --git a/mojo/ui/ganesh_view.cc b/mojo/ui/ganesh_view.cc
index 95b1170..857840d 100644
--- a/mojo/ui/ganesh_view.cc
+++ b/mojo/ui/ganesh_view.cc
@@ -5,23 +5,18 @@
 #include "mojo/ui/ganesh_view.h"
 
 #include "base/logging.h"
-#include "mojo/public/cpp/application/connect.h"
 #include "mojo/skia/ganesh_texture_surface.h"
 #include "third_party/skia/include/core/SkCanvas.h"
 
 namespace mojo {
 namespace ui {
 
-GaneshView::GaneshView(
-    mojo::ApplicationImpl* app_impl,
-    mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
-    const std::string& label)
-    : BaseView(app_impl, view_owner_request.Pass(), label),
-      ganesh_renderer_(
-          new mojo::skia::GaneshContext(mojo::GLContext::CreateOffscreen(
-              mojo::ApplicationConnectorPtr::Create(
-                  mojo::CreateApplicationConnector(app_impl->shell()))
-                  .get()))) {}
+GaneshView::GaneshView(InterfaceHandle<ApplicationConnector> app_connector,
+                       InterfaceRequest<ViewOwner> view_owner_request,
+                       const std::string& label)
+    : BaseView(app_connector.Pass(), view_owner_request.Pass(), label),
+      ganesh_renderer_(new skia::GaneshContext(
+          GLContext::CreateOffscreen(BaseView::app_connector()))) {}
 
 GaneshView::~GaneshView() {}
 
diff --git a/mojo/ui/ganesh_view.h b/mojo/ui/ganesh_view.h
index 95c6c36..f42551c 100644
--- a/mojo/ui/ganesh_view.h
+++ b/mojo/ui/ganesh_view.h
@@ -6,6 +6,7 @@
 #define MOJO_UI_GANESH_VIEW_H_
 
 #include "mojo/gpu/gl_context.h"
+#include "mojo/public/cpp/bindings/interface_handle.h"
 #include "mojo/skia/ganesh_context.h"
 #include "mojo/ui/base_view.h"
 #include "mojo/ui/ganesh_renderer.h"
@@ -20,27 +21,27 @@
 // content for the scene.
 class GaneshView : public BaseView {
  public:
-  GaneshView(mojo::ApplicationImpl* app_impl,
-             mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
+  GaneshView(InterfaceHandle<ApplicationConnector> app_connector,
+             InterfaceRequest<ViewOwner> view_owner_request,
              const std::string& label);
 
   ~GaneshView() override;
 
   // Gets the GL context, never null.
-  const scoped_refptr<mojo::GLContext>& gl_context() const {
+  const scoped_refptr<GLContext>& gl_context() const {
     return ganesh_renderer_.gl_context();
   }
 
   // Gets the Ganesh context, never null.
-  const scoped_refptr<mojo::skia::GaneshContext>& ganesh_context() const {
+  const scoped_refptr<skia::GaneshContext>& ganesh_context() const {
     return ganesh_renderer_.ganesh_context();
   }
 
   // Gets the Ganesh renderer, never null.
-  mojo::ui::GaneshRenderer* ganesh_renderer() { return &ganesh_renderer_; }
+  GaneshRenderer* ganesh_renderer() { return &ganesh_renderer_; }
 
  private:
-  mojo::ui::GaneshRenderer ganesh_renderer_;
+  GaneshRenderer ganesh_renderer_;
 
   DISALLOW_COPY_AND_ASSIGN(GaneshView);
 };
diff --git a/mojo/ui/gl_view.cc b/mojo/ui/gl_view.cc
index e3c80f5..79b2c94 100644
--- a/mojo/ui/gl_view.cc
+++ b/mojo/ui/gl_view.cc
@@ -5,19 +5,15 @@
 #include "mojo/ui/gl_view.h"
 
 #include "base/logging.h"
-#include "mojo/public/cpp/application/connect.h"
 
 namespace mojo {
 namespace ui {
 
-GLView::GLView(mojo::ApplicationImpl* app_impl,
-               mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
+GLView::GLView(InterfaceHandle<ApplicationConnector> app_connector,
+               InterfaceRequest<ViewOwner> view_owner_request,
                const std::string& label)
-    : BaseView(app_impl, view_owner_request.Pass(), label),
-      gl_renderer_(mojo::GLContext::CreateOffscreen(
-          ApplicationConnectorPtr::Create(
-              mojo::CreateApplicationConnector(app_impl->shell()))
-              .get())) {}
+    : BaseView(app_connector.Pass(), view_owner_request.Pass(), label),
+      gl_renderer_(GLContext::CreateOffscreen(BaseView::app_connector())) {}
 
 GLView::~GLView() {}
 
diff --git a/mojo/ui/gl_view.h b/mojo/ui/gl_view.h
index 7677084..e6687c8 100644
--- a/mojo/ui/gl_view.h
+++ b/mojo/ui/gl_view.h
@@ -17,22 +17,22 @@
 // content for the scene.
 class GLView : public BaseView {
  public:
-  GLView(mojo::ApplicationImpl* app_impl,
-         mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
+  GLView(InterfaceHandle<ApplicationConnector> app_connector,
+         InterfaceRequest<ViewOwner> view_owner_request,
          const std::string& label);
 
   ~GLView() override;
 
   // Gets the GL context, never null.
-  const scoped_refptr<mojo::GLContext>& gl_context() const {
+  const scoped_refptr<GLContext>& gl_context() const {
     return gl_renderer_.gl_context();
   }
 
   // Gets the GL renderer, never null.
-  mojo::ui::GLRenderer* gl_renderer() { return &gl_renderer_; }
+  GLRenderer* gl_renderer() { return &gl_renderer_; }
 
  private:
-  mojo::ui::GLRenderer gl_renderer_;
+  GLRenderer gl_renderer_;
 
   MOJO_DISALLOW_COPY_AND_ASSIGN(GLView);
 };