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

Unified Diff: chrome/browser/android/webapk/webapk_installer.cc

Issue 2528073002: Add a flag in WebAPK's proto when the Web App Manifest is no longer available. (Closed)
Patch Set: Remove best_icon_hash. Created 4 years 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/webapk/webapk_installer.cc
diff --git a/chrome/browser/android/webapk/webapk_installer.cc b/chrome/browser/android/webapk/webapk_installer.cc
index 348c336ccc867c6c2cc8f7b7523249ddcd72029f..98a95cb2d1fcd8f79387b40a3457a70fa1041e2b 100644
--- a/chrome/browser/android/webapk/webapk_installer.cc
+++ b/chrome/browser/android/webapk/webapk_installer.cc
@@ -110,7 +110,8 @@ std::string getCurrentAbi() {
std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground(
pkotwicz 2016/12/07 20:41:30 We should test the behavior of this method when Sh
Xi Han 2016/12/09 18:40:11 It is easier to parse the created proto directly.
const ShortcutInfo& shortcut_info,
const SkBitmap& shortcut_icon,
- const std::string& shortcut_icon_murmur2_hash) {
+ bool stale_manifest,
+ std::map<std::string, std::string> icon_url_hash_map) {
DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk);
@@ -119,11 +120,7 @@ std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground(
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->set_stale_manifest(stale_manifest);
webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest();
web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name));
@@ -143,17 +140,30 @@ std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground(
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::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_hash_map.find(best_icon_url);
+ if (it != icon_url_hash_map.end())
+ best_image->set_hash(it->second);
+ else
+ best_image->set_hash("");
pkotwicz 2016/12/07 20:41:30 Is line 150 necessary? What would go wrong if we j
Xi Han 2016/12/09 18:40:11 Looks like should be fine. Removed.
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())
+ for (const std::pair<std::string, std::string>& entry : icon_url_hash_map) {
+ if (entry.first == shortcut_info.best_icon_url.spec())
continue;
webapk::Image* image = web_app_manifest->add_icons();
- image->set_src(icon_url);
+ image->set_src(entry.first);
+ // crbug.com/669060. Sends all the icon hashes when the Web Manifest has
+ // been removed and can't be fetched by the WebAPK server. The WebAPK server
+ // will be able to create the same AndroidManifest.xml as before, therefore
+ // prevents unnecessary request for update if the Web Manifest becomes
+ // available again.
+ if (stale_manifest)
+ image->set_hash(entry.second);
pkotwicz 2016/12/07 20:41:30 Can't we always set the hash and remove line 165?
Xi Han 2016/12/09 18:40:11 Personally I don't prefer to do that, since more d
pkotwicz 2016/12/09 20:09:44 Always sending the hashes makes things clearer. Th
}
return webapk;
@@ -249,33 +259,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_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_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_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_hash_map),
base::Bind(&WebApkInstaller::SendUpdateWebApkRequest,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -365,18 +378,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_hash_map;
+ for (const std::string& icon_url: shortcut_info_.icon_urls) {
pkotwicz 2016/12/07 20:41:30 Nit: Space before ':'
Xi Han 2016/12/09 18:40:11 Done.
+ if (icon_url != shortcut_info_.best_icon_url.spec())
+ icon_url_hash_map[icon_url] = "";
+ else
+ icon_url_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_hash_map),
base::Bind(&WebApkInstaller::SendCreateWebApkRequest,
weak_ptr_factory_.GetWeakPtr()));
}

Powered by Google App Engine
This is Rietveld 408576698