Index: chrome/browser/android/webapk/webapk_installer.cc |
diff --git a/chrome/browser/android/webapk/webapk_installer.cc b/chrome/browser/android/webapk/webapk_installer.cc |
index 840e1147b10384bafe8f733ff94de58fd64767f1..13ee327e700aafd46d12c45f6b3c93fed8f96587 100644 |
--- a/chrome/browser/android/webapk/webapk_installer.cc |
+++ b/chrome/browser/android/webapk/webapk_installer.cc |
@@ -106,60 +106,6 @@ std::string getCurrentAbi() { |
#endif |
} |
-// Populates webapk::WebApk and returns it. |
-// Must be called on a worker thread because it encodes an SkBitmap. |
-std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground( |
- const ShortcutInfo& shortcut_info, |
- const SkBitmap& shortcut_icon, |
- const std::string& shortcut_icon_murmur2_hash) { |
- DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
- |
- std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); |
- webapk->set_manifest_url(shortcut_info.manifest_url.spec()); |
- webapk->set_requester_application_package( |
- base::android::BuildInfo::GetInstance()->package_name()); |
- webapk->set_requester_application_version(version_info::GetVersionNumber()); |
- webapk->set_android_abi(getCurrentAbi()); |
- |
- // TODO(hanxi): crbug.com/665078. Add a flag in WebAPK's proto to indicate |
- // that the Web Manifest data in the proto might be stale. |
- if (shortcut_icon_murmur2_hash.empty()) |
- return webapk; |
- |
- webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); |
- web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); |
- web_app_manifest->set_short_name( |
- base::UTF16ToUTF8(shortcut_info.short_name)); |
- web_app_manifest->set_start_url(shortcut_info.url.spec()); |
- web_app_manifest->set_orientation( |
- content::WebScreenOrientationLockTypeToString( |
- shortcut_info.orientation)); |
- web_app_manifest->set_display_mode( |
- content::WebDisplayModeToString(shortcut_info.display)); |
- web_app_manifest->set_background_color( |
- ColorToString(shortcut_info.background_color)); |
- web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); |
- |
- std::string* scope = web_app_manifest->add_scopes(); |
- scope->assign(GetScope(shortcut_info).spec()); |
- |
- webapk::Image* best_image = web_app_manifest->add_icons(); |
- best_image->set_src(shortcut_info.best_icon_url.spec()); |
- best_image->set_hash(shortcut_icon_murmur2_hash); |
- std::vector<unsigned char> png_bytes; |
- gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes); |
- best_image->set_image_data(&png_bytes.front(), png_bytes.size()); |
- |
- for (const std::string& icon_url : shortcut_info.icon_urls) { |
- if (icon_url == shortcut_info.best_icon_url.spec()) |
- continue; |
- webapk::Image* image = web_app_manifest->add_icons(); |
- image->set_src(icon_url); |
- } |
- |
- return webapk; |
-} |
- |
// Returns task runner for running background tasks. |
scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { |
return content::BrowserThread::GetBlockingPool() |
@@ -250,33 +196,36 @@ void WebApkInstaller::InstallAsyncWithURLRequestContextGetter( |
DownloadAppIconAndComputeMurmur2Hash(); |
} |
-void WebApkInstaller::UpdateAsync(content::BrowserContext* browser_context, |
- const FinishCallback& finish_callback, |
- const std::string& icon_murmur2_hash, |
- const std::string& webapk_package, |
- int webapk_version) { |
+void WebApkInstaller::UpdateAsync( |
+ content::BrowserContext* browser_context, |
+ const FinishCallback& finish_callback, |
+ const std::string& webapk_package, |
+ int webapk_version, |
+ bool stale_manifest, |
+ const std::map<std::string, std::string>& icon_url_to_murmur2_hash_map) { |
UpdateAsyncWithURLRequestContextGetter( |
Profile::FromBrowserContext(browser_context)->GetRequestContext(), |
- finish_callback, icon_murmur2_hash, webapk_package, webapk_version); |
+ finish_callback, webapk_package, webapk_version, stale_manifest, |
+ icon_url_to_murmur2_hash_map); |
} |
void WebApkInstaller::UpdateAsyncWithURLRequestContextGetter( |
net::URLRequestContextGetter* request_context_getter, |
const FinishCallback& finish_callback, |
- const std::string& icon_murmur2_hash, |
const std::string& webapk_package, |
- int webapk_version) { |
+ int webapk_version, |
+ bool stale_manifest, |
+ const std::map<std::string, std::string>& icon_url_to_murmur2_hash_map) { |
request_context_getter_ = request_context_getter; |
finish_callback_ = finish_callback; |
- shortcut_icon_murmur2_hash_ = icon_murmur2_hash; |
webapk_package_ = webapk_package; |
webapk_version_ = webapk_version; |
task_type_ = UPDATE; |
base::PostTaskAndReplyWithResult( |
GetBackgroundTaskRunner().get(), FROM_HERE, |
- base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, |
- shortcut_icon_, shortcut_icon_murmur2_hash_), |
+ base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, |
+ stale_manifest, icon_url_to_murmur2_hash_map), |
base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, |
weak_ptr_factory_.GetWeakPtr())); |
} |
@@ -410,18 +359,24 @@ void WebApkInstaller::OnGotIconMurmur2Hash( |
timer_.Stop(); |
icon_hasher_.reset(); |
- shortcut_icon_murmur2_hash_ = icon_murmur2_hash; |
- |
// An empty hash indicates that |icon_hasher_| encountered an error. |
if (icon_murmur2_hash.empty()) { |
OnFailure(); |
return; |
} |
+ std::map<std::string, std::string> icon_url_to_murmur2_hash_map; |
+ for (const std::string& icon_url : shortcut_info_.icon_urls) { |
+ if (icon_url != shortcut_info_.best_icon_url.spec()) |
+ icon_url_to_murmur2_hash_map[icon_url] = ""; |
+ else |
+ icon_url_to_murmur2_hash_map[icon_url] = icon_murmur2_hash; |
+ } |
+ |
base::PostTaskAndReplyWithResult( |
GetBackgroundTaskRunner().get(), FROM_HERE, |
- base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, |
- shortcut_icon_, shortcut_icon_murmur2_hash_), |
+ base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, |
+ false, icon_url_to_murmur2_hash_map), |
base::Bind(&WebApkInstaller::SendCreateWebApkRequest, |
weak_ptr_factory_.GetWeakPtr())); |
} |
@@ -567,3 +522,59 @@ void WebApkInstaller::OnFailure() { |
finish_callback_.Run(false, webapk_package_); |
delete this; |
} |
+ |
+// static |
+std::unique_ptr<webapk::WebApk> WebApkInstaller::BuildWebApkProtoInBackground( |
+ const ShortcutInfo& shortcut_info, |
+ const SkBitmap& shortcut_icon, |
+ bool stale_manifest, |
+ std::map<std::string, std::string> icon_url_to_murmur2_hash_map) { |
+ DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
+ |
+ std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); |
+ webapk->set_manifest_url(shortcut_info.manifest_url.spec()); |
+ webapk->set_requester_application_package( |
+ base::android::BuildInfo::GetInstance()->package_name()); |
+ webapk->set_requester_application_version(version_info::GetVersionNumber()); |
+ webapk->set_android_abi(getCurrentAbi()); |
+ webapk->set_stale_manifest(stale_manifest); |
+ |
+ webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); |
+ web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); |
+ web_app_manifest->set_short_name( |
+ base::UTF16ToUTF8(shortcut_info.short_name)); |
+ web_app_manifest->set_start_url(shortcut_info.url.spec()); |
+ web_app_manifest->set_orientation( |
+ content::WebScreenOrientationLockTypeToString( |
+ shortcut_info.orientation)); |
+ web_app_manifest->set_display_mode( |
+ content::WebDisplayModeToString(shortcut_info.display)); |
+ web_app_manifest->set_background_color( |
+ ColorToString(shortcut_info.background_color)); |
+ web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); |
+ |
+ std::string* scope = web_app_manifest->add_scopes(); |
+ scope->assign(GetScope(shortcut_info).spec()); |
+ |
+ webapk::Image* best_image = web_app_manifest->add_icons(); |
+ std::string best_icon_url = shortcut_info.best_icon_url.spec(); |
+ best_image->set_src(best_icon_url); |
+ std::map<std::string, std::string>::iterator it = |
+ icon_url_to_murmur2_hash_map.find(best_icon_url); |
+ if (it != icon_url_to_murmur2_hash_map.end()) |
+ best_image->set_hash(it->second); |
+ std::vector<unsigned char> png_bytes; |
+ gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes); |
+ best_image->set_image_data(&png_bytes.front(), png_bytes.size()); |
+ |
+ for (const std::pair<std::string, std::string>& entry : |
+ icon_url_to_murmur2_hash_map) { |
+ if (entry.first == shortcut_info.best_icon_url.spec()) |
+ continue; |
+ webapk::Image* image = web_app_manifest->add_icons(); |
+ image->set_src(entry.first); |
+ image->set_hash(entry.second); |
+ } |
+ |
+ return webapk; |
+} |