Commit 997d6d9c authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

feedv2: Defer surface attach until after sign-in

On first run, when the user signs in, we were making a signed-out
FeedQuery request. This happened because the IdentityManager hadn't
yet gotten any signals about the sign-in process before the feed
surface was opened.

This change waits to attach the feed surface (to native) until
after ChromeTabbedActivity reaches the right initialization step.

Bug: 1044139
Change-Id: Ia55096e8720bb2289ccddef14533caff4cb0c25e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261217Reviewed-by: default avatarJian Li <jianli@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Dan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782131}
parent 2621fe78
...@@ -94,6 +94,37 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -94,6 +94,37 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
return sXSurfaceProcessScope; return sXSurfaceProcessScope;
} }
// We avoid attaching surfaces until after |startup()| is called. This ensures that
// the correct sign-in state is used if attaching the surface triggers a fetch.
private static boolean sStartupCalled;
private static HashSet<FeedStreamSurface> sWaitingSurfaces;
public static void startup() {
if (sStartupCalled) return;
sStartupCalled = true;
xSurfaceProcessScope();
if (sWaitingSurfaces != null) {
for (FeedStreamSurface surface : sWaitingSurfaces) {
surface.surfaceOpened();
}
sWaitingSurfaces = null;
}
}
private static void openSurfaceAtStartup(FeedStreamSurface surface) {
if (sWaitingSurfaces == null) {
sWaitingSurfaces = new HashSet<FeedStreamSurface>();
}
sWaitingSurfaces.add(surface);
}
private static void cancelOpenSurfaceAtStartup(FeedStreamSurface surface) {
if (sWaitingSurfaces != null) {
sWaitingSurfaces.remove(surface);
}
}
/** /**
* Provides logging and context for all surfaces. * Provides logging and context for all surfaces.
* *
...@@ -447,7 +478,12 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -447,7 +478,12 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
* the content is available, onStreamUpdated will be called. * the content is available, onStreamUpdated will be called.
*/ */
public void surfaceOpened() { public void surfaceOpened() {
FeedStreamSurfaceJni.get().surfaceOpened(mNativeFeedStreamSurface, FeedStreamSurface.this); if (!sStartupCalled) {
openSurfaceAtStartup(this);
} else {
FeedStreamSurfaceJni.get().surfaceOpened(
mNativeFeedStreamSurface, FeedStreamSurface.this);
}
} }
/** /**
...@@ -458,7 +494,13 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -458,7 +494,13 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
if (feedCount > 0) { if (feedCount > 0) {
mContentManager.removeContents(mHeaderCount, feedCount); mContentManager.removeContents(mHeaderCount, feedCount);
} }
FeedStreamSurfaceJni.get().surfaceClosed(mNativeFeedStreamSurface, FeedStreamSurface.this);
if (!sStartupCalled) {
cancelOpenSurfaceAtStartup(this);
} else {
FeedStreamSurfaceJni.get().surfaceClosed(
mNativeFeedStreamSurface, FeedStreamSurface.this);
}
} }
private void openUrl(String url, boolean inNewTab) { private void openUrl(String url, boolean inNewTab) {
......
...@@ -795,12 +795,13 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent ...@@ -795,12 +795,13 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent
private void maybeGetFeedAppLifecycleAndMaybeCreatePageViewObserver() { private void maybeGetFeedAppLifecycleAndMaybeCreatePageViewObserver() {
try (TraceEvent e = TraceEvent.scoped("ChromeTabbedActivity." try (TraceEvent e = TraceEvent.scoped("ChromeTabbedActivity."
+ "maybeGetFeedAppLifecycleAndMaybeCreatePageViewObserver")) { + "maybeGetFeedAppLifecycleAndMaybeCreatePageViewObserver")) {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.INTEREST_FEED_CONTENT_SUGGESTIONS)) { if (ChromeFeatureList.isEnabled(ChromeFeatureList.INTEREST_FEED_V2)) {
FeedStreamSurface.startup();
} else if (ChromeFeatureList.isEnabled(
ChromeFeatureList.INTEREST_FEED_CONTENT_SUGGESTIONS)) {
// We call getFeedAppLifecycle() here to ensure the app lifecycle is created so // We call getFeedAppLifecycle() here to ensure the app lifecycle is created so
// that it can start listening for state changes. // that it can start listening for state changes.
FeedProcessScopeFactory.getFeedAppLifecycle(); FeedProcessScopeFactory.getFeedAppLifecycle();
} else if (ChromeFeatureList.isEnabled(ChromeFeatureList.INTEREST_FEED_V2)) {
FeedStreamSurface.xSurfaceProcessScope();
} }
if (UsageStatsService.isEnabled()) { if (UsageStatsService.isEnabled()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment