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

Unified Diff: chrome/browser/android/shortcut_helper.h

Issue 563843002: Refactor ShortcutHelper (Java/C++) to allow asynchronous init. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_manager_content
Patch Set: review comments Created 6 years, 3 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/shortcut_helper.h
diff --git a/chrome/browser/android/shortcut_helper.h b/chrome/browser/android/shortcut_helper.h
index bf7911a0cdab7b0d80aca89c940bd6f3f25d6706..7d92415e15898431f9618e07e0c01c844542a69a 100644
--- a/chrome/browser/android/shortcut_helper.h
+++ b/chrome/browser/android/shortcut_helper.h
@@ -5,17 +5,14 @@
#ifndef CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
#define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
+#include "base/android/jni_android.h"
#include "base/android/jni_weak_ref.h"
#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "base/task/cancelable_task_tracker.h"
-#include "chrome/browser/android/tab_android.h"
+#include "components/favicon_base/favicon_types.h"
#include "content/public/browser/web_contents_observer.h"
-namespace favicon_base {
-struct FaviconRawBitmapResult;
-} // namespace favicon_base
-
namespace content {
class WebContents;
} // namespace content
@@ -26,15 +23,12 @@ class Message;
class GURL;
-// Adds a shortcut to the current URL to the Android home screen.
-// This proceeds over three phases:
-// 1) The renderer is asked to parse out webapp related meta tags with an async
-// IPC message.
-// 2) The highest-resolution favicon available is retrieved for use as the
-// icon on the home screen.
-// 3) A JNI call is made to fire an Intent at the Android launcher, which adds
-// the shortcut.
-class ShortcutBuilder : public content::WebContentsObserver {
+// ShortcutHelper is the C++ counterpart of org.chromium.chrome.browser's
+// ShortcutHelper in Java. The object is owned by the Java object. It is created
+// from there via a JNI (Initialize) call and can be destroyed from Java too
+// using TearDown. When the Java implementations calls AddShortcut, it gives up
+// the ownership of the object. The instance will then destroy itself when done.
+class ShortcutHelper : public content::WebContentsObserver {
public:
enum ShortcutType {
APP_SHORTCUT,
@@ -42,16 +36,31 @@ class ShortcutBuilder : public content::WebContentsObserver {
BOOKMARK
};
- explicit ShortcutBuilder(content::WebContents* web_contents,
- const base::string16& title,
- int launcher_large_icon_size);
- virtual ~ShortcutBuilder() {}
+ explicit ShortcutHelper(JNIEnv* env,
+ jobject obj,
+ content::WebContents* web_contents);
+
+ // Initialize the helper by requesting the information about the page to the
+ // renderer process. The initialization is asynchronous and
+ // OnDidRetrieveWebappInformation is expected to be called when finished.
+ void Initialize();
+ // Called by the Java counter part to let the object knows that it can destroy
+ // itself.
+ void TearDown(JNIEnv* env, jobject obj);
+
+ // IPC message received when the initialization is finished.
void OnDidRetrieveWebappInformation(bool success,
bool is_mobile_webapp_capable,
bool is_apple_mobile_webapp_capable,
const GURL& expected_url);
+ // Adds a shortcut to the current URL to the Android home screen.
+ void AddShortcut(JNIEnv* env,
+ jobject obj,
+ jstring title,
+ jint launcher_large_icon_size);
+
void FinishAddingShortcut(
const favicon_base::FaviconRawBitmapResult& bitmap_result);
@@ -59,37 +68,30 @@ class ShortcutBuilder : public content::WebContentsObserver {
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void WebContentsDestroyed() OVERRIDE;
- private:
- void Destroy();
-
- GURL url_;
- base::string16 title_;
- int launcher_large_icon_size_;
- ShortcutType shortcut_type_;
- base::CancelableTaskTracker cancelable_task_tracker_;
-
- DISALLOW_COPY_AND_ASSIGN(ShortcutBuilder);
-};
-
-class ShortcutHelper {
- public:
- // Adds a shortcut to the current URL to the Android home screen, firing
- // background tasks to pull all the data required.
- static void AddShortcut(content::WebContents* web_contents,
- const base::string16& title,
- int launcher_larger_icon_size);
-
// Adds a shortcut to the launcher. Must be called from a WorkerPool task.
static void AddShortcutInBackground(
const GURL& url,
const base::string16& title,
- ShortcutBuilder::ShortcutType shortcut_type,
+ ShortcutType shortcut_type,
const favicon_base::FaviconRawBitmapResult& bitmap_result);
// Registers JNI hooks.
static bool RegisterShortcutHelper(JNIEnv* env);
private:
+ virtual ~ShortcutHelper();
+
+ void Destroy();
+
+ JavaObjectWeakGlobalRef java_ref_;
+
+ GURL url_;
+ base::string16 title_;
+ int launcher_large_icon_size_;
+ ShortcutType shortcut_type_;
+ favicon_base::FaviconRawBitmapResult icon_;
+ base::CancelableTaskTracker cancelable_task_tracker_;
+
DISALLOW_COPY_AND_ASSIGN(ShortcutHelper);
};

Powered by Google App Engine
This is Rietveld 408576698