OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/task/cancelable_task_tracker.h" | 10 #include "base/task/cancelable_task_tracker.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace favicon_base { | 24 namespace favicon_base { |
25 struct FaviconRawBitmapResult; | 25 struct FaviconRawBitmapResult; |
26 } | 26 } |
27 | 27 |
28 namespace IPC { | 28 namespace IPC { |
29 class Message; | 29 class Message; |
30 } | 30 } |
31 | 31 |
32 class GURL; | 32 class GURL; |
| 33 class InstallableManager; |
33 struct InstallableData; | 34 struct InstallableData; |
34 struct WebApplicationInfo; | 35 struct WebApplicationInfo; |
35 | 36 |
36 // Aysnchronously fetches and processes data needed to create a shortcut for an | 37 // Aysnchronously fetches and processes data needed to create a shortcut for an |
37 // Android Home screen launcher. | 38 // Android Home screen launcher. |
38 // | 39 // |
39 // Because of the various asynchronous calls made by this class, it is | 40 // Because of the various asynchronous calls made by this class, it is |
40 // refcounted to prevent the class from being prematurely deleted. If the | 41 // refcounted to prevent the class from being prematurely deleted. If the |
41 // pointer to the ShortcutHelper becomes invalid, the pipeline should kill | 42 // |weak_observer_| pointer becomes invalid, the pipeline should kill itself. |
42 // itself. | |
43 class AddToHomescreenDataFetcher | 43 class AddToHomescreenDataFetcher |
44 : public base::RefCounted<AddToHomescreenDataFetcher>, | 44 : public base::RefCounted<AddToHomescreenDataFetcher>, |
45 public content::WebContentsObserver { | 45 public content::WebContentsObserver { |
46 public: | 46 public: |
47 class Observer { | 47 class Observer { |
48 public: | 48 public: |
49 // Callded when the installable check is compelte. | 49 // Callded when the installable check is compelte. |
50 virtual void OnDidDetermineWebApkCompatibility( | 50 virtual void OnDidDetermineWebApkCompatibility( |
51 bool is_webapk_compatible) = 0; | 51 bool is_webapk_compatible) = 0; |
52 | 52 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 ~AddToHomescreenDataFetcher() override; | 96 ~AddToHomescreenDataFetcher() override; |
97 | 97 |
98 // WebContentsObserver: | 98 // WebContentsObserver: |
99 bool OnMessageReceived(const IPC::Message& message, | 99 bool OnMessageReceived(const IPC::Message& message, |
100 content::RenderFrameHost* sender) override; | 100 content::RenderFrameHost* sender) override; |
101 | 101 |
102 // Called if either InstallableManager or the favicon fetch takes too long. | 102 // Called if either InstallableManager or the favicon fetch takes too long. |
103 void OnDataTimedout(); | 103 void OnDataTimedout(); |
104 | 104 |
105 // Called when InstallableManager finishes looking for a manifest and icon. | 105 // Called when InstallableManager finishes looking for a manifest and icon. |
| 106 void OnDidGetManifestAndIcon(const InstallableData& data); |
| 107 |
| 108 // Called when InstallableManager finishes checking for installability. |
106 void OnDidPerformInstallableCheck(const InstallableData& data); | 109 void OnDidPerformInstallableCheck(const InstallableData& data); |
107 | 110 |
108 // Grabs the favicon for the current URL. | 111 // Grabs the favicon for the current URL. |
109 void FetchFavicon(); | 112 void FetchFavicon(); |
110 void OnFaviconFetched( | 113 void OnFaviconFetched( |
111 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 114 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
112 | 115 |
113 // Creates the launcher icon from the given bitmap. shortcut_info_.url is | 116 // Creates the launcher icon from the given bitmap. shortcut_info_.url is |
114 // used to generate an icon if there is no bitmap in |bitmap_result| or the | 117 // used to generate an icon if there is no bitmap in |bitmap_result| or the |
115 // bitmap is not large enough. | 118 // bitmap is not large enough. |
116 SkBitmap CreateLauncherIconFromFaviconInBackground( | 119 SkBitmap CreateLauncherIconFromFaviconInBackground( |
117 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 120 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
118 | 121 |
119 // Creates the launcher icon from the given |raw_icon|. | 122 // Creates the primary launcher icon from the given |icon|. |
120 void CreateLauncherIcon(const SkBitmap& raw_icon); | 123 void CreateLauncherIcon(const SkBitmap& icon); |
121 SkBitmap CreateLauncherIconInBackground(const SkBitmap& raw_icon); | 124 SkBitmap CreateLauncherIconInBackground(const SkBitmap& icon); |
122 | 125 |
123 // Notifies the observer that the shortcut data is all available. | 126 // Notifies the observer that the shortcut data is all available. |
124 void NotifyObserver(const SkBitmap& icon); | 127 void NotifyObserver(const SkBitmap& icon); |
125 | 128 |
126 scoped_refptr<base::TaskRunner> background_task_runner_; | 129 scoped_refptr<base::TaskRunner> background_task_runner_; |
127 | 130 |
| 131 InstallableManager* installable_manager_; |
128 Observer* weak_observer_; | 132 Observer* weak_observer_; |
129 | 133 |
130 // The icons must only be set on the UI thread for thread safety. | 134 // The icons must only be set on the UI thread for thread safety. |
| 135 SkBitmap raw_icon_; |
131 SkBitmap badge_icon_; | 136 SkBitmap badge_icon_; |
132 SkBitmap primary_icon_; | 137 SkBitmap primary_icon_; |
133 ShortcutInfo shortcut_info_; | 138 ShortcutInfo shortcut_info_; |
134 | 139 |
135 base::CancelableTaskTracker favicon_task_tracker_; | 140 base::CancelableTaskTracker favicon_task_tracker_; |
136 base::OneShotTimer data_timeout_timer_; | 141 base::OneShotTimer data_timeout_timer_; |
137 | 142 |
138 const int ideal_icon_size_in_px_; | 143 const int ideal_icon_size_in_px_; |
139 const int minimum_icon_size_in_px_; | 144 const int minimum_icon_size_in_px_; |
140 const int ideal_splash_image_size_in_px_; | 145 const int ideal_splash_image_size_in_px_; |
141 const int minimum_splash_image_size_in_px_; | 146 const int minimum_splash_image_size_in_px_; |
142 const int badge_size_in_px_; | 147 const int badge_size_in_px_; |
143 | 148 |
144 // Indicates whether to check WebAPK compatibility. | 149 // Indicates whether to check WebAPK compatibility. |
145 bool check_webapk_compatibility_; | 150 bool check_webapk_compatibility_; |
146 bool is_waiting_for_web_application_info_; | 151 bool is_waiting_for_web_application_info_; |
147 bool is_installable_check_complete_; | 152 bool is_installable_check_complete_; |
148 bool is_icon_saved_; | 153 bool is_icon_saved_; |
149 | 154 |
150 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); | 155 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); |
151 }; | 156 }; |
152 | 157 |
153 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 158 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
OLD | NEW |