From b63aff333b2f923c890bc08b36d652ed6150032f Mon Sep 17 00:00:00 2001
From: David Worsham <dworsham@google.com>
Date: Wed, 1 May 2019 22:07:27 +0000
Subject: [PATCH] [scenic] Convert session_shell to ViewToken

Tested: No behavior changed; modular_tests, started story in sysUI
SCN-1018 #comment
SCN-1291 #comment

Change-Id: I8509501a15094d7d381557c186a9d0463488a956
---
 peridot/bin/sessionmgr/BUILD.gn                |  1 -
 peridot/bin/sessionmgr/dev_session_shell.cc    | 17 ++++++++++++-----
 peridot/bin/sessionmgr/story_runner/BUILD.gn   |  1 -
 .../story_runner/story_controller_impl.cc      | 18 ++++++------------
 .../story_runner/story_provider_impl.cc        | 14 +++++++-------
 .../story_runner/story_provider_impl.h         | 11 +++++------
 peridot/lib/testing/BUILD.gn                   |  1 -
 peridot/lib/testing/session_shell_impl.cc      |  7 +++++++
 peridot/lib/testing/session_shell_impl.h       |  7 ++++++-
 sdk/fidl/fuchsia.modular/fuchsia.modular.api   |  2 +-
 .../fuchsia.modular/session/session_shell.fidl |  5 +++++
 11 files changed, 49 insertions(+), 35 deletions(-)

diff --git a/peridot/bin/sessionmgr/BUILD.gn b/peridot/bin/sessionmgr/BUILD.gn
index 3de5b70e38a..8d9845c6bfe 100644
--- a/peridot/bin/sessionmgr/BUILD.gn
+++ b/peridot/bin/sessionmgr/BUILD.gn
@@ -130,7 +130,6 @@ executable_package("dev_session_shell") {
     "//sdk/fidl/fuchsia.modular",
     "//sdk/fidl/fuchsia.ui.scenic",
     "//sdk/fidl/fuchsia.ui.views",
-    "//sdk/fidl/fuchsia.ui.viewsv1token",
     "//sdk/lib/fidl/cpp",
     "//sdk/lib/ui/scenic/cpp",
     "//src/lib/fxl",
diff --git a/peridot/bin/sessionmgr/dev_session_shell.cc b/peridot/bin/sessionmgr/dev_session_shell.cc
index d84c1414e51..d2dac47ec47 100644
--- a/peridot/bin/sessionmgr/dev_session_shell.cc
+++ b/peridot/bin/sessionmgr/dev_session_shell.cc
@@ -6,9 +6,6 @@
 // root module URL and data for its fuchsia::modular::Link as command line
 // arguments, which can be set using the basemgr --user-shell-args flag.
 
-#include <memory>
-#include <utility>
-
 #include <fuchsia/modular/cpp/fidl.h>
 #include <fuchsia/sys/cpp/fidl.h>
 #include <fuchsia/ui/scenic/cpp/fidl.h>
@@ -27,6 +24,9 @@
 #include <src/lib/fxl/logging.h>
 #include <src/lib/fxl/macros.h>
 
+#include <memory>
+#include <utility>
+
 #include "peridot/lib/fidl/single_service_app.h"
 #include "peridot/lib/fidl/view_host.h"
 #include "peridot/lib/rapidjson/rapidjson.h"
@@ -209,9 +209,16 @@ class DevSessionShellApp : fuchsia::modular::StoryWatcher,
   void AttachView(fuchsia::modular::ViewIdentifier view_id,
                   fidl::InterfaceHandle<fuchsia::ui::viewsv1token::ViewOwner>
                       view_owner) override {
+    AttachView2(view_id, scenic::ToViewHolderToken(zx::eventpair(
+                             view_owner.TakeChannel().release())));
+  }
+
+  // |SessionShell|
+  void AttachView2(
+      fuchsia::modular::ViewIdentifier view_id,
+      fuchsia::ui::views::ViewHolderToken view_holder_token) override {
     FXL_LOG(INFO) << "DevSessionShell AttachView(): " << view_id.story_id;
-    view_->ConnectView(scenic::ToViewHolderToken(
-        zx::eventpair(view_owner.TakeChannel().release())));
+    view_->ConnectView(std::move(view_holder_token));
   }
 
   // |SessionShell|
diff --git a/peridot/bin/sessionmgr/story_runner/BUILD.gn b/peridot/bin/sessionmgr/story_runner/BUILD.gn
index eba48f3baef..4fed8780562 100644
--- a/peridot/bin/sessionmgr/story_runner/BUILD.gn
+++ b/peridot/bin/sessionmgr/story_runner/BUILD.gn
@@ -75,7 +75,6 @@ source_set("story_runner") {
     "//sdk/fidl/fuchsia.scenic.snapshot",
     "//sdk/fidl/fuchsia.ui.policy",
     "//sdk/fidl/fuchsia.ui.views",
-    "//sdk/fidl/fuchsia.ui.viewsv1token",
     "//sdk/lib/fidl/cpp",
     "//src/ledger/bin/fidl",
     "//src/lib/fxl",
diff --git a/peridot/bin/sessionmgr/story_runner/story_controller_impl.cc b/peridot/bin/sessionmgr/story_runner/story_controller_impl.cc
index c7b57b2fab9..36b61ced6d6 100644
--- a/peridot/bin/sessionmgr/story_runner/story_controller_impl.cc
+++ b/peridot/bin/sessionmgr/story_runner/story_controller_impl.cc
@@ -4,10 +4,6 @@
 
 #include "peridot/bin/sessionmgr/story_runner/story_controller_impl.h"
 
-#include <memory>
-#include <string>
-#include <vector>
-
 #include <fuchsia/ledger/cpp/fidl.h>
 #include <fuchsia/modular/cpp/fidl.h>
 #include <fuchsia/modular/internal/cpp/fidl.h>
@@ -701,8 +697,9 @@ class StoryControllerImpl::OnModuleDataUpdatedCall : public Operation<> {
     //
     // TODO(thatguy): Revisit this decision. It seems wrong: we do not want to
     // auto-start mods added through ModuleContext.EmbedModule(), because we do
-    // not have the necessary capabilities (the ImportToken). Mods added through
-    // ModuleContext.AddModuleToStory() can be started automatically, however.
+    // not have the necessary capabilities (the ViewHolderToken). Mods added
+    // through ModuleContext.AddModuleToStory() can be started automatically,
+    // however.
     if (module_data_.module_source ==
         fuchsia::modular::ModuleSource::INTERNAL) {
       return;
@@ -1366,15 +1363,12 @@ void StoryControllerImpl::GetLink(
 }
 
 void StoryControllerImpl::StartStoryShell() {
-  fuchsia::ui::viewsv1token::ViewOwnerPtr view_owner;
+  auto [view_token, view_holder_token] = scenic::NewViewTokenPair();
 
   story_shell_holder_ = story_provider_impl_->StartStoryShell(
-      story_id_,
-      scenic::ToViewToken(
-          zx::eventpair(view_owner.NewRequest().TakeChannel().release())),
-      story_shell_.NewRequest());
+      story_id_, std::move(view_token), story_shell_.NewRequest());
 
-  story_provider_impl_->AttachView(story_id_, std::move(view_owner));
+  story_provider_impl_->AttachView(story_id_, std::move(view_holder_token));
 
   fuchsia::modular::StoryShellContextPtr story_shell_context;
   story_shell_context_impl_.Connect(story_shell_context.NewRequest());
diff --git a/peridot/bin/sessionmgr/story_runner/story_provider_impl.cc b/peridot/bin/sessionmgr/story_runner/story_provider_impl.cc
index b8711beb75a..3f5bf3c2641 100644
--- a/peridot/bin/sessionmgr/story_runner/story_provider_impl.cc
+++ b/peridot/bin/sessionmgr/story_runner/story_provider_impl.cc
@@ -4,10 +4,6 @@
 
 #include "peridot/bin/sessionmgr/story_runner/story_provider_impl.h"
 
-#include <memory>
-#include <utility>
-#include <vector>
-
 #include <fuchsia/scenic/snapshot/cpp/fidl.h>
 #include <fuchsia/ui/app/cpp/fidl.h>
 #include <lib/async/cpp/task.h>
@@ -18,7 +14,10 @@
 #include <lib/fsl/handles/object_info.h>
 #include <lib/fsl/vmo/strings.h>
 #include <lib/zx/time.h>
-#include "src/lib/uuid/uuid.h"
+
+#include <memory>
+#include <utility>
+#include <vector>
 
 #include "peridot/bin/basemgr/cobalt/cobalt.h"
 #include "peridot/bin/sessionmgr/focus.h"
@@ -34,6 +33,7 @@
 #include "peridot/lib/fidl/clone.h"
 #include "peridot/lib/fidl/proxy.h"
 #include "peridot/lib/rapidjson/rapidjson.h"
+#include "src/lib/uuid/uuid.h"
 
 // In tests prefetching mondrian saved ~30ms in story start up time.
 #define PREFETCH_MONDRIAN 1
@@ -529,11 +529,11 @@ void StoryProviderImpl::RequestStoryFocus(fidl::StringPtr story_id) {
 
 void StoryProviderImpl::AttachView(
     fidl::StringPtr story_id,
-    fuchsia::ui::viewsv1token::ViewOwnerPtr view_owner) {
+    fuchsia::ui::views::ViewHolderToken view_holder_token) {
   FXL_CHECK(session_shell_);
   fuchsia::modular::ViewIdentifier view_id;
   view_id.story_id = std::move(story_id);
-  session_shell_->AttachView(std::move(view_id), std::move(view_owner));
+  session_shell_->AttachView2(std::move(view_id), std::move(view_holder_token));
 }
 
 void StoryProviderImpl::DetachView(fidl::StringPtr story_id,
diff --git a/peridot/bin/sessionmgr/story_runner/story_provider_impl.h b/peridot/bin/sessionmgr/story_runner/story_provider_impl.h
index b4e5c1254df..45fd7b1af06 100644
--- a/peridot/bin/sessionmgr/story_runner/story_provider_impl.h
+++ b/peridot/bin/sessionmgr/story_runner/story_provider_impl.h
@@ -5,10 +5,6 @@
 #ifndef PERIDOT_BIN_SESSIONMGR_STORY_RUNNER_STORY_PROVIDER_IMPL_H_
 #define PERIDOT_BIN_SESSIONMGR_STORY_RUNNER_STORY_PROVIDER_IMPL_H_
 
-#include <map>
-#include <memory>
-#include <set>
-
 #include <fuchsia/ledger/cpp/fidl.h>
 #include <fuchsia/modular/cpp/fidl.h>
 #include <fuchsia/modular/internal/cpp/fidl.h>
@@ -16,7 +12,6 @@
 #include <fuchsia/ui/policy/cpp/fidl.h>
 #include <fuchsia/ui/views/cpp/fidl.h>
 #include <fuchsia/ui/viewsv1/cpp/fidl.h>
-#include <fuchsia/ui/viewsv1token/cpp/fidl.h>
 #include <lib/async/cpp/operation.h>
 #include <lib/fidl/cpp/binding_set.h>
 #include <lib/fidl/cpp/interface_ptr.h>
@@ -26,6 +21,10 @@
 #include <lib/fit/function.h>
 #include <src/lib/fxl/macros.h>
 
+#include <map>
+#include <memory>
+#include <set>
+
 #include "peridot/bin/sessionmgr/agent_runner/agent_runner.h"
 #include "peridot/bin/sessionmgr/component_context_impl.h"
 #include "peridot/bin/sessionmgr/message_queue/message_queue_manager.h"
@@ -136,7 +135,7 @@ class StoryProviderImpl : fuchsia::modular::StoryProvider,
   // Called by StoryControllerImpl. Sends, using AttachView(), a token for the
   // view of the story identified by |story_id| to the current session shell.
   void AttachView(fidl::StringPtr story_id,
-                  fuchsia::ui::viewsv1token::ViewOwnerPtr view_owner);
+                  fuchsia::ui::views::ViewHolderToken view_holder_token);
 
   // Called by StoryControllerImpl. Notifies, using DetachView(), the current
   // session shell that the view of the story identified by |story_id| is about
diff --git a/peridot/lib/testing/BUILD.gn b/peridot/lib/testing/BUILD.gn
index dd86f045587..2ded3334fe7 100644
--- a/peridot/lib/testing/BUILD.gn
+++ b/peridot/lib/testing/BUILD.gn
@@ -140,7 +140,6 @@ source_set("session_shell_impl") {
     "//peridot/public/lib/integration_testing/cpp",
     "//sdk/fidl/fuchsia.modular",
     "//sdk/fidl/fuchsia.ui.views",
-    "//sdk/fidl/fuchsia.ui.viewsv1token",
     "//sdk/lib/fidl/cpp",
     "//src/lib/fxl",
     "//zircon/public/lib/async-loop-cpp",
diff --git a/peridot/lib/testing/session_shell_impl.cc b/peridot/lib/testing/session_shell_impl.cc
index 763bfedbdf1..4b6bda465cb 100644
--- a/peridot/lib/testing/session_shell_impl.cc
+++ b/peridot/lib/testing/session_shell_impl.cc
@@ -25,6 +25,13 @@ void SessionShellImpl::AttachView(
   on_attach_view_(std::move(view_id));
 }
 
+// |SessionShell|
+void SessionShellImpl::AttachView2(
+    fuchsia::modular::ViewIdentifier view_id,
+    fuchsia::ui::views::ViewHolderToken view_holder_token) {
+  on_attach_view_(std::move(view_id));
+}
+
 // |SessionShell|
 void SessionShellImpl::DetachView(fuchsia::modular::ViewIdentifier view_id,
                                   fit::function<void()> done) {
diff --git a/peridot/lib/testing/session_shell_impl.h b/peridot/lib/testing/session_shell_impl.h
index 18569636bb9..8093995809d 100644
--- a/peridot/lib/testing/session_shell_impl.h
+++ b/peridot/lib/testing/session_shell_impl.h
@@ -32,7 +32,7 @@ class SessionShellImpl : fuchsia::modular::SessionShell {
   fidl::InterfaceRequestHandler<fuchsia::modular::SessionShell> GetHandler();
 
   // Whenever SessionShell.AttachView() is called, the supplied callback is
-  // invoked with the view ID. The ImportToken is dropped.
+  // invoked with the view ID. The ViewHolderToken is dropped.
   void set_on_attach_view(fit::function<void(ViewId view_id)> callback) {
     on_attach_view_ = std::move(callback);
   }
@@ -57,6 +57,11 @@ class SessionShellImpl : fuchsia::modular::SessionShell {
                   fidl::InterfaceHandle<fuchsia::ui::viewsv1token::ViewOwner>
                       view_owner) override;
 
+  // |SessionShell|
+  void AttachView2(
+      fuchsia::modular::ViewIdentifier view_id,
+      fuchsia::ui::views::ViewHolderToken view_holder_token) override;
+
   // |SessionShell|
   void DetachView(fuchsia::modular::ViewIdentifier view_id,
                   fit::function<void()> done) override;
diff --git a/sdk/fidl/fuchsia.modular/fuchsia.modular.api b/sdk/fidl/fuchsia.modular/fuchsia.modular.api
index 30231c57601..bb3f4dad238 100644
--- a/sdk/fidl/fuchsia.modular/fuchsia.modular.api
+++ b/sdk/fidl/fuchsia.modular/fuchsia.modular.api
@@ -32,7 +32,7 @@
   "fidl/fuchsia.modular/module_resolver/module_resolver.fidl": "e6837b2e15ce3a7a1c899e02110b933d",
   "fidl/fuchsia.modular/session/device_map.fidl": "3cd55018a8967d8d483fd02d172de98f",
   "fidl/fuchsia.modular/session/focus.fidl": "7787b6c08cacd6c981d729c952f12f17",
-  "fidl/fuchsia.modular/session/session_shell.fidl": "8c9a5c08c1ff04ca3c8f3dcd61d01cfc",
+  "fidl/fuchsia.modular/session/session_shell.fidl": "0fee7f4ea179d0515d0fda320fc20994",
   "fidl/fuchsia.modular/story/create_link.fidl": "a3e1da920eb02637478b914c2009bf90",
   "fidl/fuchsia.modular/story/create_module_parameter_map.fidl": "79bf5bdf04655966584b72ff0b1b3066",
   "fidl/fuchsia.modular/story/link.fidl": "5a0130509caadb5e6263ae76adbccd50",
diff --git a/sdk/fidl/fuchsia.modular/session/session_shell.fidl b/sdk/fidl/fuchsia.modular/session/session_shell.fidl
index 6f8e7000178..c89c35125a5 100644
--- a/sdk/fidl/fuchsia.modular/session/session_shell.fidl
+++ b/sdk/fidl/fuchsia.modular/session/session_shell.fidl
@@ -7,6 +7,7 @@ library fuchsia.modular;
 using fuchsia.modular.auth;
 using fuchsia.speech;
 using fuchsia.ui.policy;
+using fuchsia.ui.views;
 using fuchsia.ui.viewsv1token;
 
 // This interface is implemented by a session shell and is used by the
@@ -16,7 +17,11 @@ using fuchsia.ui.viewsv1token;
 protocol SessionShell {
     // Displays the given story view. The story this view belongs to is
     // identified by |view_id.story_id|.
+    // DEPRECATED.  For transitional purposes only.
+    [Transitional]
     AttachView(ViewIdentifier view_id, fuchsia.ui.viewsv1token.ViewOwner view_owner);
+    [Transitional]
+    AttachView2(ViewIdentifier view_id, fuchsia.ui.views.ViewHolderToken view_holder_token);
 
     // Instructs the session shell to detach the view identified by |view_id|
     // that was previously provided by AttachView() from the UI of the session
-- 
GitLab