Index: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h |
diff --git a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h |
index 6212b1692eb49449edb1d595c7d44d6abbaf7d30..f2750666c64f40896a9a0de94bbc28ae9068cba2 100644 |
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h |
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h |
@@ -5,8 +5,10 @@ |
#ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
#define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
+#include <utility> |
+ |
#include "base/macros.h" |
-#include "base/memory/ref_counted.h" |
+#include "base/memory/weak_ptr.h" |
#include "base/strings/string16.h" |
#include "base/task/cancelable_task_tracker.h" |
#include "base/timer/timer.h" |
@@ -18,20 +20,13 @@ namespace favicon_base { |
struct FaviconRawBitmapResult; |
} |
-class GURL; |
class InstallableManager; |
struct InstallableData; |
struct WebApplicationInfo; |
// Aysnchronously fetches and processes data needed to create a shortcut for an |
// Android Home screen launcher. |
-// |
-// Because of the various asynchronous calls made by this class, it is |
-// refcounted to prevent the class from being prematurely deleted. If the |
-// |weak_observer_| pointer becomes invalid, the pipeline should kill itself. |
-class AddToHomescreenDataFetcher |
- : public base::RefCounted<AddToHomescreenDataFetcher>, |
- public content::WebContentsObserver { |
+class AddToHomescreenDataFetcher : public content::WebContentsObserver { |
public: |
class Observer { |
public: |
@@ -43,13 +38,6 @@ class AddToHomescreenDataFetcher |
// OnDidDetermineWebApkCompatibility. |
virtual void OnUserTitleAvailable(const base::string16& title) = 0; |
- // Converts the icon into one that can be used on the Android Home screen. |
- // |is_generated| is an out-param that indicates whether the icon was |
- // generated by Chrome. |
- virtual SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, |
- const GURL& url, |
- bool* is_generated) = 0; |
- |
// Called when all the data needed to create a shortcut is available. |
virtual void OnDataAvailable(const ShortcutInfo& info, |
const SkBitmap& primary_icon, |
@@ -62,6 +50,7 @@ class AddToHomescreenDataFetcher |
// Initialize the fetcher by requesting the information about the page from |
// the renderer process. The initialization is asynchronous and |
// OnDidGetWebApplicationInfo is expected to be called when finished. |
+ // |observer| must outlive AddToHomescreenDataFetcher. |
AddToHomescreenDataFetcher(content::WebContents* web_contents, |
int ideal_icon_size_in_px, |
int minimum_icon_size_in_px, |
@@ -72,20 +61,17 @@ class AddToHomescreenDataFetcher |
bool check_webapk_compatible, |
Observer* observer); |
+ ~AddToHomescreenDataFetcher() override; |
+ |
// IPC message received when the initialization is finished. |
void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); |
// Accessors, etc. |
- void set_weak_observer(Observer* observer) { weak_observer_ = observer; } |
const SkBitmap& badge_icon() const { return badge_icon_; } |
const SkBitmap& primary_icon() const { return primary_icon_; } |
ShortcutInfo& shortcut_info() { return shortcut_info_; } |
private: |
- friend class base::RefCounted<AddToHomescreenDataFetcher>; |
- |
- ~AddToHomescreenDataFetcher() override; |
- |
// WebContentsObserver: |
bool OnMessageReceived(const IPC::Message& message, |
content::RenderFrameHost* sender) override; |
@@ -104,21 +90,14 @@ class AddToHomescreenDataFetcher |
void OnFaviconFetched( |
const favicon_base::FaviconRawBitmapResult& bitmap_result); |
- // Creates the launcher icon from the given bitmap. shortcut_info_.url is |
- // used to generate an icon if there is no bitmap in |bitmap_result| or the |
- // bitmap is not large enough. |
- SkBitmap CreateLauncherIconFromFaviconInBackground( |
- const favicon_base::FaviconRawBitmapResult& bitmap_result); |
- |
// Creates the primary launcher icon from the given |icon|. |
void CreateLauncherIcon(const SkBitmap& icon); |
- SkBitmap CreateLauncherIconInBackground(const SkBitmap& icon); |
// Notifies the observer that the shortcut data is all available. |
- void NotifyObserver(const SkBitmap& icon); |
+ void NotifyObserver(const std::pair<SkBitmap, bool /*is_generated*/>& icon); |
InstallableManager* installable_manager_; |
- Observer* weak_observer_; |
+ Observer* observer_; |
// The icons must only be set on the UI thread for thread safety. |
SkBitmap raw_primary_icon_; |
@@ -139,7 +118,8 @@ class AddToHomescreenDataFetcher |
// Indicates whether to check WebAPK compatibility. |
bool check_webapk_compatibility_; |
bool is_waiting_for_web_application_info_; |
- bool is_installable_check_complete_; |
+ |
+ base::WeakPtrFactory<AddToHomescreenDataFetcher> weak_ptr_factory_; |
DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); |
}; |