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

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: Fix the compile error. 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..75bd6b3ec192dae1259b8cba3121ea69f14702c2 100644
--- a/chrome/browser/android/webapk/webapk_installer.cc
+++ b/chrome/browser/android/webapk/webapk_installer.cc
@@ -110,7 +110,9 @@ std::string getCurrentAbi() {
std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground(
const ShortcutInfo& shortcut_info,
const SkBitmap& shortcut_icon,
- const std::string& shortcut_icon_murmur2_hash) {
+ const std::string& shortcut_icon_murmur2_hash,
+ bool stale_manifest,
+ const std::vector<std::string>& icon_hashs) {
DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk);
@@ -119,11 +121,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));
@@ -149,11 +147,19 @@ std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground(
gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes);
best_image->set_image_data(&png_bytes.front(), png_bytes.size());
pkotwicz 2016/12/06 17:53:37 This function should fail (return NULL) if the ico
Xi Han 2016/12/07 19:42:51 Pass in a map instead of two arrays, and this func
- for (const std::string& icon_url : shortcut_info.icon_urls) {
- if (icon_url == shortcut_info.best_icon_url.spec())
+ bool add_icon_hash = stale_manifest && !icon_hashs.empty();
+ for (size_t i = 0; i < shortcut_info.icon_urls.size(); ++i) {
+ if (shortcut_info.icon_urls[i] == shortcut_info.best_icon_url.spec())
continue;
webapk::Image* image = web_app_manifest->add_icons();
- image->set_src(icon_url);
+ image->set_src(shortcut_info.icon_urls[i]);
+ // crbug.com/669060. Sends all the icon hashs 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 (add_icon_hash)
+ image->set_hash(icon_hashs[i]);
}
return webapk;
@@ -253,10 +259,13 @@ 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) {
+ int webapk_version,
+ bool stale_manifest,
+ const std::vector<std::string>& icon_hashs) {
pkotwicz 2016/12/06 17:53:37 Nit: icon_hashs -> icon_hashes
Xi Han 2016/12/07 19:42:51 Done.
UpdateAsyncWithURLRequestContextGetter(
Profile::FromBrowserContext(browser_context)->GetRequestContext(),
- finish_callback, icon_murmur2_hash, webapk_package, webapk_version);
+ finish_callback, icon_murmur2_hash, webapk_package, webapk_version,
+ stale_manifest, icon_hashs);
}
void WebApkInstaller::UpdateAsyncWithURLRequestContextGetter(
@@ -264,7 +273,9 @@ void WebApkInstaller::UpdateAsyncWithURLRequestContextGetter(
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::vector<std::string>& icon_hashs) {
request_context_getter_ = request_context_getter;
finish_callback_ = finish_callback;
shortcut_icon_murmur2_hash_ = icon_murmur2_hash;
@@ -274,8 +285,8 @@ void WebApkInstaller::UpdateAsyncWithURLRequestContextGetter(
base::PostTaskAndReplyWithResult(
GetBackgroundTaskRunner().get(), FROM_HERE,
- base::Bind(&BuildWebApkProtoInBackground, shortcut_info_,
- shortcut_icon_, shortcut_icon_murmur2_hash_),
+ base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_,
+ shortcut_icon_murmur2_hash_, stale_manifest, icon_hashs),
base::Bind(&WebApkInstaller::SendUpdateWebApkRequest,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -375,8 +386,9 @@ void WebApkInstaller::OnGotIconMurmur2Hash(
base::PostTaskAndReplyWithResult(
GetBackgroundTaskRunner().get(), FROM_HERE,
- base::Bind(&BuildWebApkProtoInBackground, shortcut_info_,
- shortcut_icon_, shortcut_icon_murmur2_hash_),
+ base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_,
+ shortcut_icon_murmur2_hash_, false,
+ std::vector<std::string>()),
base::Bind(&WebApkInstaller::SendCreateWebApkRequest,
weak_ptr_factory_.GetWeakPtr()));
}

Powered by Google App Engine
This is Rietveld 408576698