Fix resume from foreground inactive issue

Bug: 1201268
Change-Id: Iec15025ecee7caa4f4ab32f1d7eabe053467a116
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2842353
Auto-Submit: Ganggui Tang <gogerald@chromium.org>
Reviewed-by: Chris Lu <thegreenfrog@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#874806}
GitOrigin-RevId: 12e92b43a0bb50960cece9c7de8e26a3f138bd31
diff --git a/chrome/browser/ui/start_surface/start_surface_scene_agent.mm b/chrome/browser/ui/start_surface/start_surface_scene_agent.mm
index cb611e0..6776126 100644
--- a/chrome/browser/ui/start_surface/start_surface_scene_agent.mm
+++ b/chrome/browser/ui/start_surface/start_surface_scene_agent.mm
@@ -9,18 +9,35 @@
 #error "This file requires ARC support."
 #endif
 
+@interface StartSurfaceSceneAgent ()
+
+// Caches the previous activation level.
+@property(nonatomic, assign) SceneActivationLevel previousActivationLevel;
+
+@end
+
 @implementation StartSurfaceSceneAgent
 
+- (id)init {
+  self = [super init];
+  if (self) {
+    self.previousActivationLevel = SceneActivationLevelUnattached;
+  }
+  return self;
+}
+
 #pragma mark - SceneStateObserver
 
 - (void)sceneState:(SceneState*)sceneState
     transitionedToActivationLevel:(SceneActivationLevel)level {
-  if (level == SceneActivationLevelBackground) {
+  if (level != SceneActivationLevelForegroundActive &&
+      self.previousActivationLevel == SceneActivationLevelForegroundActive) {
     // TODO(crbug.com/1173160): Consider when to clear the session object since
-    // Chrome may be closed without transiting to background, e.g. device power
+    // Chrome may be closed without transiting to inactive, e.g. device power
     // off, then the previous session object is staled.
     SetStartSurfaceSessionObjectForSceneState(sceneState);
   }
+  self.previousActivationLevel = level;
 }
 
 @end