Commit 7cd54a4d authored by Michael McGreevy's avatar Michael McGreevy Committed by Commit Bot

Split AppBannerManager::Stop() into two methods.

This means that ReportStatus is only called in one place
(apart from AppBannerManagerDesktop::ShowBannerUi), making it easier
to verify that it is called the appropriate number of times.

It also removes the need for hacks such as pre-updating the state to COMPLETE
in AppBannerManager::DisplayAppBanner.


Bug: 770016
Change-Id: Iedf93b7a3c6c211b2188032259906bd49bcd4555
Reviewed-on: https://chromium-review.googlesource.com/691494
Commit-Queue: Michael McGreevy <mcgreevy@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505334}
parent 71d5ed5b
...@@ -174,6 +174,8 @@ void AppBannerManagerAndroid::PerformInstallableCheck() { ...@@ -174,6 +174,8 @@ void AppBannerManagerAndroid::PerformInstallableCheck() {
for (const auto& application : manifest_.related_applications) { for (const auto& application : manifest_.related_applications) {
std::string platform = base::UTF16ToUTF8(application.platform.string()); std::string platform = base::UTF16ToUTF8(application.platform.string());
std::string id = base::UTF16ToUTF8(application.id.string()); std::string id = base::UTF16ToUTF8(application.id.string());
// TODO(crbug/770050): convert CanHandleNonWebApp() to return an
// InstallableStatusCode and pass it to StopWithCode here.
if (CanHandleNonWebApp(platform, application.url, id)) if (CanHandleNonWebApp(platform, application.url, id))
return; return;
} }
...@@ -182,8 +184,7 @@ void AppBannerManagerAndroid::PerformInstallableCheck() { ...@@ -182,8 +184,7 @@ void AppBannerManagerAndroid::PerformInstallableCheck() {
if (can_install_webapk_) { if (can_install_webapk_) {
if (!AreWebManifestUrlsWebApkCompatible(manifest_)) { if (!AreWebManifestUrlsWebApkCompatible(manifest_)) {
ReportStatus(web_contents(), URL_NOT_SUPPORTED_FOR_WEBAPK); StopWithCode(URL_NOT_SUPPORTED_FOR_WEBAPK);
Stop();
return; return;
} }
} }
...@@ -206,8 +207,7 @@ void AppBannerManagerAndroid::OnDidPerformInstallableCheck( ...@@ -206,8 +207,7 @@ void AppBannerManagerAndroid::OnDidPerformInstallableCheck(
void AppBannerManagerAndroid::OnAppIconFetched(const SkBitmap& bitmap) { void AppBannerManagerAndroid::OnAppIconFetched(const SkBitmap& bitmap) {
if (bitmap.drawsNothing()) { if (bitmap.drawsNothing()) {
ReportStatus(web_contents(), NO_ICON_AVAILABLE); StopWithCode(NO_ICON_AVAILABLE);
Stop();
return; return;
} }
......
...@@ -87,8 +87,7 @@ void AppBannerManager::RequestAppBanner(const GURL& validated_url, ...@@ -87,8 +87,7 @@ void AppBannerManager::RequestAppBanner(const GURL& validated_url,
} }
if (code != NO_ERROR_DETECTED) { if (code != NO_ERROR_DETECTED) {
ReportStatus(contents, code); StopWithCode(code);
Stop();
return; return;
} }
...@@ -183,8 +182,7 @@ bool AppBannerManager::IsWebAppInstalled( ...@@ -183,8 +182,7 @@ bool AppBannerManager::IsWebAppInstalled(
void AppBannerManager::OnDidGetManifest(const InstallableData& data) { void AppBannerManager::OnDidGetManifest(const InstallableData& data) {
UpdateState(State::ACTIVE); UpdateState(State::ACTIVE);
if (data.error_code != NO_ERROR_DETECTED) { if (data.error_code != NO_ERROR_DETECTED) {
ReportStatus(web_contents(), data.error_code); StopWithCode(data.error_code);
Stop();
return; return;
} }
...@@ -229,8 +227,7 @@ void AppBannerManager::OnDidPerformInstallableCheck( ...@@ -229,8 +227,7 @@ void AppBannerManager::OnDidPerformInstallableCheck(
if (data.error_code == NO_MATCHING_SERVICE_WORKER) if (data.error_code == NO_MATCHING_SERVICE_WORKER)
TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER);
ReportStatus(web_contents(), data.error_code); StopWithCode(data.error_code);
Stop();
return; return;
} }
...@@ -287,7 +284,6 @@ void AppBannerManager::ResetCurrentPageData() { ...@@ -287,7 +284,6 @@ void AppBannerManager::ResetCurrentPageData() {
} }
void AppBannerManager::Stop() { void AppBannerManager::Stop() {
// Record the status if we are currently waiting for data.
InstallableStatusCode code = NO_ERROR_DETECTED; InstallableStatusCode code = NO_ERROR_DETECTED;
switch (state_) { switch (state_) {
case State::PENDING_PROMPT: case State::PENDING_PROMPT:
...@@ -314,7 +310,10 @@ void AppBannerManager::Stop() { ...@@ -314,7 +310,10 @@ void AppBannerManager::Stop() {
case State::COMPLETE: case State::COMPLETE:
break; break;
} }
StopWithCode(code);
}
void AppBannerManager::StopWithCode(InstallableStatusCode code) {
if (code != NO_ERROR_DETECTED) if (code != NO_ERROR_DETECTED)
ReportStatus(web_contents(), code); ReportStatus(web_contents(), code);
...@@ -516,8 +515,7 @@ bool AppBannerManager::CheckIfShouldShowBanner() { ...@@ -516,8 +515,7 @@ bool AppBannerManager::CheckIfShouldShowBanner() {
default: default:
NOTREACHED(); NOTREACHED();
} }
ReportStatus(contents, code); StopWithCode(code);
Stop();
return false; return false;
} }
return true; return true;
...@@ -585,12 +583,7 @@ void AppBannerManager::ShowBanner() { ...@@ -585,12 +583,7 @@ void AppBannerManager::ShowBanner() {
void AppBannerManager::DisplayAppBanner(bool user_gesture) { void AppBannerManager::DisplayAppBanner(bool user_gesture) {
if (IsExperimentalAppBannersEnabled() && !user_gesture) { if (IsExperimentalAppBannersEnabled() && !user_gesture) {
ReportStatus(web_contents(), NO_GESTURE); StopWithCode(NO_GESTURE);
// The state is manually set to COMPLETE before calling Stop, because
// otherwise Stop will complain that the status has already been reported.
UpdateState(State::COMPLETE);
Stop();
return; return;
} }
......
...@@ -192,10 +192,12 @@ class AppBannerManager : public content::WebContentsObserver, ...@@ -192,10 +192,12 @@ class AppBannerManager : public content::WebContentsObserver,
// Resets all fetched data for the current page. // Resets all fetched data for the current page.
virtual void ResetCurrentPageData(); virtual void ResetCurrentPageData();
void Stop();
// Stops the banner pipeline, preventing any outstanding callbacks from // Stops the banner pipeline, preventing any outstanding callbacks from
// running and resetting the manager state. This method is virtual to allow // running and resetting the manager state. This method is virtual to allow
// tests to intercept it and verify correct behaviour. // tests to intercept it and verify correct behaviour.
virtual void Stop(); virtual void StopWithCode(InstallableStatusCode code);
// Sends a message to the renderer that the page has met the requirements to // Sends a message to the renderer that the page has met the requirements to
// show a banner. The page can respond to cancel the banner (and possibly // show a banner. The page can respond to cancel the banner (and possibly
......
...@@ -82,12 +82,12 @@ class AppBannerManagerTest : public AppBannerManager { ...@@ -82,12 +82,12 @@ class AppBannerManagerTest : public AppBannerManager {
} }
protected: protected:
// All calls to RequestAppBanner should terminate in one of Stop() (not // All calls to RequestAppBanner should terminate in one of StopWithCode()
// showing banner), UpdateState(State::PENDING_ENGAGEMENT) (waiting for // (not showing banner), UpdateState(State::PENDING_ENGAGEMENT) (waiting for
// sufficient engagement), or ShowBannerUi(). Override these methods to // sufficient engagement), or ShowBannerUi(). Override these methods to
// capture test status. // capture test status.
void Stop() override { void StopWithCode(InstallableStatusCode code) override {
AppBannerManager::Stop(); AppBannerManager::StopWithCode(code);
ASSERT_FALSE(will_show_.get()); ASSERT_FALSE(will_show_.get());
will_show_.reset(new bool(false)); will_show_.reset(new bool(false));
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
......
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