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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/banners/AppDetailsDelegate.java

Issue 156343002: Let AppBannerManager really create and manage banners (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Upload error Created 6 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/android/java/src/org/chromium/chrome/browser/banners/AppDetailsDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/banners/AppDetailsDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/banners/AppDetailsDelegate.java
new file mode 100644
index 0000000000000000000000000000000000000000..833516c322074a8c04250fd7c8b920e25df63780
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/banners/AppDetailsDelegate.java
@@ -0,0 +1,75 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.banners;
+
+import android.content.Context;
+import android.os.AsyncTask;
+
+/**
+ * Fetches data about the given app.
+ */
+public abstract class AppDetailsDelegate {
+ /**
+ * Class to inform when the app's details have been retrieved.
+ */
+ interface Observer {
+ /**
+ * Called when the task has finished.
+ * @param data Data about the requested package. Will be null if retrieval failed.
+ */
+ public void onAppDetailsRetrieved(AppData data);
+ }
+
+ /**
+ * Runs a background task to retrieve details about an app.
+ */
+ class DetailsTask extends AsyncTask<Void, Void, Boolean> {
+ final Observer mObserver;
+ final AppData mData;
+ final int mIconSize;
+
+ DetailsTask(Observer observer, Context context, String url, String packageName) {
+ mObserver = observer;
+ mData = new AppData(url, packageName);
+ mIconSize = AppBannerView.getIconSize(context);
+ }
+
+ @Override
+ protected Boolean doInBackground(Void... args) {
+ return getAppDetails(mData, mIconSize);
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ mObserver.onAppDetailsRetrieved(result ? mData : null);
+ }
+ }
+
+ /**
+ * Creates a task to retrieve data about the given app.
+ * @param observer Observer to inform about the task's completion.
+ * @param context Context to grab resources from.
+ * @param url URL of the page that is requesting a banner.
+ * @param packageName Package name for the app being displayed.
+ * @return
+ */
+ DetailsTask createTask(Observer observer, Context context, String url, String packageName) {
+ return new DetailsTask(observer, context, url, packageName);
+ }
+
+ /**
+ * Retrieves information about the given package.
+ * @param data Data about the app will be placed in this class. Must already contain
+ * the name of the package to retrieve data for.
+ * @param iconSize Size of the icon to retrieve.
+ * @return True if the data was retrieved successfully.
+ */
+ protected abstract boolean getAppDetails(AppData data, int iconSize);
+
+ /**
+ * Destroy the delegate, cleaning up any open hooks.
+ */
+ public abstract void destroy();
+}

Powered by Google App Engine
This is Rietveld 408576698