[modular][cleanup] Simplify story shutdown & notification flow.

Based on comments from https://fuchsia-review.googlesource.com/c/peridot/+/229846

TEST=existing

Change-Id: I3c7f75c50e8803c4ed60626a2d36cba0be15beca
diff --git a/bin/sessionmgr/story_runner/story_controller_impl.cc b/bin/sessionmgr/story_runner/story_controller_impl.cc
index 0fbff7e..725ac91 100644
--- a/bin/sessionmgr/story_runner/story_controller_impl.cc
+++ b/bin/sessionmgr/story_runner/story_controller_impl.cc
@@ -481,10 +481,9 @@
 class StoryControllerImpl::StopCall : public Operation<> {
  public:
   StopCall(StoryControllerImpl* const story_controller_impl,
-           const bool notify_watchers, std::function<void()> done)
+           std::function<void()> done)
       : Operation("StoryControllerImpl::StopCall", done),
-        story_controller_impl_(story_controller_impl),
-        notify_watchers_(notify_watchers) {}
+        story_controller_impl_(story_controller_impl) {}
 
  private:
   void Run() override {
@@ -538,16 +537,8 @@
           // been destroyed at this point.
           FXL_DCHECK(story_controller_impl_->ongoing_activities_.size() == 0);
 
-          // If this StopCall is part of a DeleteCall, then we don't notify
-          // watchers story state changes; the pertinent state change will be
-          // the delete notification instead.
-          if (notify_watchers_) {
-            story_controller_impl_->SetState(
-                fuchsia::modular::StoryState::STOPPED);
-          } else {
-            story_controller_impl_->state_ =
-                fuchsia::modular::StoryState::STOPPED;
-          }
+          story_controller_impl_->SetState(
+              fuchsia::modular::StoryState::STOPPED);
 
           story_controller_impl_->DestroyStoryEnvironment();
 
@@ -556,7 +547,6 @@
   }
 
   StoryControllerImpl* const story_controller_impl_;  // not owned
-  const bool notify_watchers_;  // Whether to notify state change to watchers.
 
   FXL_DISALLOW_COPY_AND_ASSIGN(StopCall);
 };
@@ -610,8 +600,7 @@
         story_controller_impl_->FindRunningModInfo(module_path_);
     if (running_mod_info &&
         story_controller_impl_->running_mod_infos_.size() == 1) {
-      operation_queue_.Add(new StopCall(story_controller_impl_,
-                                        true /* notify watchers */, [flow] {}));
+      operation_queue_.Add(new StopCall(story_controller_impl_, [flow] {}));
     } else {
       // Otherwise, stop this one module.
       operation_queue_.Add(new StopModuleCall(
@@ -1143,10 +1132,6 @@
   }
 }
 
-void StoryControllerImpl::StopWithoutNotifying(const StopCallback& done) {
-  operation_queue_.Add(new StopCall(this, false /* notify watchers */, done));
-}
-
 fuchsia::modular::StoryState StoryControllerImpl::GetStoryState() const {
   return state_;
 }
@@ -1409,7 +1394,7 @@
 }
 
 void StoryControllerImpl::Stop(StopCallback done) {
-  operation_queue_.Add(new StopCall(this, true /* notify watchers */, done));
+  operation_queue_.Add(new StopCall(this, done));
 }
 
 void StoryControllerImpl::TakeAndLoadSnapshot(
diff --git a/bin/sessionmgr/story_runner/story_controller_impl.h b/bin/sessionmgr/story_runner/story_controller_impl.h
index 1c1c935..1dd366f 100644
--- a/bin/sessionmgr/story_runner/story_controller_impl.h
+++ b/bin/sessionmgr/story_runner/story_controller_impl.h
@@ -64,10 +64,6 @@
   // Called by StoryProviderImpl.
   bool IsRunning();
 
-  // Called by StoryProviderImpl. A variant of Stop() which does not notify
-  // listeners that we stopped the story.
-  void StopWithoutNotifying(const std::function<void()>& done);
-
   // Called by StoryProviderImpl.
   fuchsia::modular::StoryState GetStoryState() const;
 
@@ -169,12 +165,15 @@
       fidl::InterfaceRequest<fuchsia::modular::Entity> entity_request,
       std::function<void(std::string /* entity_reference */)> callback);
 
+  // |StoryController|
+  // NOTE: Public so that StoryProviderImpl can call it.
+  void Stop(StopCallback done) override;
+
  private:
   // |StoryController|
   void GetInfo(GetInfoCallback callback) override;
   void Start(fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner>
                  request) override;
-  void Stop(StopCallback done) override;
   void TakeAndLoadSnapshot(
       fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner> request,
       TakeAndLoadSnapshotCallback done) override;
diff --git a/bin/sessionmgr/story_runner/story_provider_impl.cc b/bin/sessionmgr/story_runner/story_provider_impl.cc
index a19449b..902ffc3 100644
--- a/bin/sessionmgr/story_runner/story_provider_impl.cc
+++ b/bin/sessionmgr/story_runner/story_provider_impl.cc
@@ -69,8 +69,7 @@
     }
 
     FXL_DCHECK(i->second.controller_impl != nullptr);
-    i->second.controller_impl->StopWithoutNotifying(
-        [this, flow] { CleanupRuntime(flow); });
+    i->second.controller_impl->Stop([this, flow] { CleanupRuntime(flow); });
   }
 
   void CleanupRuntime(FlowToken flow) {
@@ -189,18 +188,15 @@
       // complete StopWithoutNotifying(), we will never be called back and the
       // OperationQueue on which we're running will block.  Moving over to
       // fit::promise will allow us to observe cancellation.
-      //
-      // TODO(thatguy): Use StopStoryCall instead of reproducing some of its
-      // logic here.
-      it.second.controller_impl->StopWithoutNotifying(
-          [this, story_id = it.first, flow] {
-            // It is okay to erase story_id because story provider binding has
-            // been closed and this callback cannot be invoked synchronously.
-            story_provider_impl_->story_runtime_containers_.erase(story_id);
-          });
+      operations_.Add(new StopStoryCall(
+          it.first, &story_provider_impl_->story_runtime_containers_,
+          story_provider_impl_->component_context_info_.message_queue_manager,
+          [flow] {}));
     }
   }
 
+  OperationCollection operations_;
+
   StoryProviderImpl* const story_provider_impl_;  // not owned
 
   FXL_DISALLOW_COPY_AND_ASSIGN(StopAllStoriesCall);