Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Unified Diff: chrome/browser/android/banners/app_banner_manager.cc

Issue 893793005: Check if there is a SW controlling the start page for app banner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/banners/app_banner_manager.cc
diff --git a/chrome/browser/android/banners/app_banner_manager.cc b/chrome/browser/android/banners/app_banner_manager.cc
index cbd87921f3bad37c1f05c645ab6d3d7d4c5da2d4..f5c2a73a8f01d4ab3789a3ddc32766cbfb1bc80f 100644
--- a/chrome/browser/android/banners/app_banner_manager.cc
+++ b/chrome/browser/android/banners/app_banner_manager.cc
@@ -24,8 +24,12 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/render_messages.h"
#include "content/public/browser/android/content_view_core.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/service_worker_context.h"
+#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/frame_navigate_params.h"
#include "content/public/common/manifest.h"
@@ -44,8 +48,34 @@ const char kBannerTag[] = "google-play-id";
namespace banners {
+// The AppBannerManager::IOThreadHandler class is used to hold onto the
+// weak pointer to the AppBannerManager. It catches the callbacks on the
+// IO thread, and forwards on the calls to the UI thread. This is required
+// as the weak pointer can only be dereferenced on the UI thread.
+class AppBannerManager::IOThreadHandler
+ : public base::RefCounted<AppBannerManager::IOThreadHandler> {
+ public:
+ explicit IOThreadHandler(
+ const base::WeakPtr<AppBannerManager>& banner_manager)
+ : banner_manager_(banner_manager) {}
+
+ void OnDidCheckHasSameServiceWorkerOnIOThread(bool has_same) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&AppBannerManager::OnDidCheckHasSameServiceWorker,
+ banner_manager_, has_same));
+ }
+
+ private:
+ base::WeakPtr<AppBannerManager> banner_manager_;
+};
+
AppBannerManager::AppBannerManager(JNIEnv* env, jobject obj)
- : weak_java_banner_view_manager_(env, obj) {}
+ : weak_java_banner_view_manager_(env, obj), weak_factory_(this) {
+ io_thread_handler_ =
+ make_scoped_refptr(new IOThreadHandler(weak_factory_.GetWeakPtr()));
+}
AppBannerManager::~AppBannerManager() {
}
@@ -140,21 +170,37 @@ void AppBannerManager::OnDidGetManifest(const content::Manifest& manifest) {
return;
}
- // TODO(benwells): Check triggering parameters here and if there is a meta
- // tag.
-
- // Create an infobar to promote the manifest's app.
manifest_ = manifest;
- GURL icon_url =
- ManifestIconSelector::FindBestMatchingIcon(
- manifest.icons,
- GetPreferredIconSize(),
- gfx::Screen::GetScreenFor(web_contents()->GetNativeView()));
- if (icon_url.is_empty())
- return;
+ // Check to see if there is a single service worker controlling this page
+ // and the manifest's start url.
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents()->GetBrowserContext());
+ content::StoragePartition* storage_partition =
+ content::BrowserContext::GetStoragePartition(
+ profile, web_contents()->GetSiteInstance());
+ DCHECK(storage_partition);
+
+ storage_partition->GetServiceWorkerContext()->CheckHasSameServiceWorker(
+ validated_url_, manifest.start_url,
+ base::Bind(&AppBannerManager::IOThreadHandler::
+ OnDidCheckHasSameServiceWorkerOnIOThread,
+ io_thread_handler_));
+}
- FetchIcon(icon_url);
+void AppBannerManager::OnDidCheckHasSameServiceWorker(bool has_same) {
+ if (has_same) {
+ // TODO(benwells): Check triggering parameters.
+ GURL icon_url =
+ ManifestIconSelector::FindBestMatchingIcon(
+ manifest_.icons,
+ GetPreferredIconSize(),
+ gfx::Screen::GetScreenFor(web_contents()->GetNativeView()));
+ if (icon_url.is_empty())
+ return;
+
+ FetchIcon(icon_url);
+ }
}
bool AppBannerManager::OnMessageReceived(const IPC::Message& message) {

Powered by Google App Engine
This is Rietveld 408576698