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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "chrome/browser/android/webapk/webapk_installer.h" 5 #include "chrome/browser/android/webapk/webapk_installer.h"
6 6
7 #include "base/android/build_info.h" 7 #include "base/android/build_info.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/path_utils.h" 10 #include "base/android/path_utils.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 #else 103 #else
104 #error "Unsupported target abi" 104 #error "Unsupported target abi"
105 #endif 105 #endif
106 } 106 }
107 107
108 // Populates webapk::WebApk and returns it. 108 // Populates webapk::WebApk and returns it.
109 // Must be called on a worker thread because it encodes an SkBitmap. 109 // Must be called on a worker thread because it encodes an SkBitmap.
110 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground( 110 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground(
111 const ShortcutInfo& shortcut_info, 111 const ShortcutInfo& shortcut_info,
112 const SkBitmap& shortcut_icon, 112 const SkBitmap& shortcut_icon,
113 const std::string& shortcut_icon_murmur2_hash) { 113 const std::string& shortcut_icon_murmur2_hash,
114 bool stale_manifest,
115 const std::vector<std::string>& icon_hashs) {
114 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 116 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
115 117
116 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); 118 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk);
117 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); 119 webapk->set_manifest_url(shortcut_info.manifest_url.spec());
118 webapk->set_requester_application_package( 120 webapk->set_requester_application_package(
119 base::android::BuildInfo::GetInstance()->package_name()); 121 base::android::BuildInfo::GetInstance()->package_name());
120 webapk->set_requester_application_version(version_info::GetVersionNumber()); 122 webapk->set_requester_application_version(version_info::GetVersionNumber());
121 webapk->set_android_abi(getCurrentAbi()); 123 webapk->set_android_abi(getCurrentAbi());
122 124 webapk->set_stale_manifest(stale_manifest);
123 // TODO(hanxi): crbug.com/665078. Add a flag in WebAPK's proto to indicate
124 // that the Web Manifest data in the proto might be stale.
125 if (shortcut_icon_murmur2_hash.empty())
126 return webapk;
127 125
128 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); 126 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest();
129 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); 127 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name));
130 web_app_manifest->set_short_name( 128 web_app_manifest->set_short_name(
131 base::UTF16ToUTF8(shortcut_info.short_name)); 129 base::UTF16ToUTF8(shortcut_info.short_name));
132 web_app_manifest->set_start_url(shortcut_info.url.spec()); 130 web_app_manifest->set_start_url(shortcut_info.url.spec());
133 web_app_manifest->set_orientation( 131 web_app_manifest->set_orientation(
134 content::WebScreenOrientationLockTypeToString( 132 content::WebScreenOrientationLockTypeToString(
135 shortcut_info.orientation)); 133 shortcut_info.orientation));
136 web_app_manifest->set_display_mode( 134 web_app_manifest->set_display_mode(
137 content::WebDisplayModeToString(shortcut_info.display)); 135 content::WebDisplayModeToString(shortcut_info.display));
138 web_app_manifest->set_background_color( 136 web_app_manifest->set_background_color(
139 ColorToString(shortcut_info.background_color)); 137 ColorToString(shortcut_info.background_color));
140 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); 138 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color));
141 139
142 std::string* scope = web_app_manifest->add_scopes(); 140 std::string* scope = web_app_manifest->add_scopes();
143 scope->assign(GetScope(shortcut_info).spec()); 141 scope->assign(GetScope(shortcut_info).spec());
144 142
145 webapk::Image* best_image = web_app_manifest->add_icons(); 143 webapk::Image* best_image = web_app_manifest->add_icons();
146 best_image->set_src(shortcut_info.best_icon_url.spec()); 144 best_image->set_src(shortcut_info.best_icon_url.spec());
147 best_image->set_hash(shortcut_icon_murmur2_hash); 145 best_image->set_hash(shortcut_icon_murmur2_hash);
148 std::vector<unsigned char> png_bytes; 146 std::vector<unsigned char> png_bytes;
149 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes); 147 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes);
150 best_image->set_image_data(&png_bytes.front(), png_bytes.size()); 148 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
151 149
152 for (const std::string& icon_url : shortcut_info.icon_urls) { 150 bool add_icon_hash = stale_manifest && !icon_hashs.empty();
153 if (icon_url == shortcut_info.best_icon_url.spec()) 151 for (size_t i = 0; i < shortcut_info.icon_urls.size(); ++i) {
152 if (shortcut_info.icon_urls[i] == shortcut_info.best_icon_url.spec())
154 continue; 153 continue;
155 webapk::Image* image = web_app_manifest->add_icons(); 154 webapk::Image* image = web_app_manifest->add_icons();
156 image->set_src(icon_url); 155 image->set_src(shortcut_info.icon_urls[i]);
156 // crbug.com/669060. Sends all the icon hashs when the Web Manifest has been
157 // removed and can't be fetched by the WebAPK server. The WebAPK server will
158 // be able to create the same AndroidManifest.xml as before, therefore
159 // prevents unnecessary request for update if the Web Manifest becomes
160 // available again.
161 if (add_icon_hash)
162 image->set_hash(icon_hashs[i]);
157 } 163 }
158 164
159 return webapk; 165 return webapk;
160 } 166 }
161 167
162 // Returns task runner for running background tasks. 168 // Returns task runner for running background tasks.
163 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { 169 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() {
164 return content::BrowserThread::GetBlockingPool() 170 return content::BrowserThread::GetBlockingPool()
165 ->GetTaskRunnerWithShutdownBehavior( 171 ->GetTaskRunnerWithShutdownBehavior(
166 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 172 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // 252 //
247 // We redownload the icon in order to take the Murmur2 hash. The redownload 253 // We redownload the icon in order to take the Murmur2 hash. The redownload
248 // should be fast because the icon should be in the HTTP cache. 254 // should be fast because the icon should be in the HTTP cache.
249 DownloadAppIconAndComputeMurmur2Hash(); 255 DownloadAppIconAndComputeMurmur2Hash();
250 } 256 }
251 257
252 void WebApkInstaller::UpdateAsync(content::BrowserContext* browser_context, 258 void WebApkInstaller::UpdateAsync(content::BrowserContext* browser_context,
253 const FinishCallback& finish_callback, 259 const FinishCallback& finish_callback,
254 const std::string& icon_murmur2_hash, 260 const std::string& icon_murmur2_hash,
255 const std::string& webapk_package, 261 const std::string& webapk_package,
256 int webapk_version) { 262 int webapk_version,
263 bool stale_manifest,
264 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.
257 UpdateAsyncWithURLRequestContextGetter( 265 UpdateAsyncWithURLRequestContextGetter(
258 Profile::FromBrowserContext(browser_context)->GetRequestContext(), 266 Profile::FromBrowserContext(browser_context)->GetRequestContext(),
259 finish_callback, icon_murmur2_hash, webapk_package, webapk_version); 267 finish_callback, icon_murmur2_hash, webapk_package, webapk_version,
268 stale_manifest, icon_hashs);
260 } 269 }
261 270
262 void WebApkInstaller::UpdateAsyncWithURLRequestContextGetter( 271 void WebApkInstaller::UpdateAsyncWithURLRequestContextGetter(
263 net::URLRequestContextGetter* request_context_getter, 272 net::URLRequestContextGetter* request_context_getter,
264 const FinishCallback& finish_callback, 273 const FinishCallback& finish_callback,
265 const std::string& icon_murmur2_hash, 274 const std::string& icon_murmur2_hash,
266 const std::string& webapk_package, 275 const std::string& webapk_package,
267 int webapk_version) { 276 int webapk_version,
277 bool stale_manifest,
278 const std::vector<std::string>& icon_hashs) {
268 request_context_getter_ = request_context_getter; 279 request_context_getter_ = request_context_getter;
269 finish_callback_ = finish_callback; 280 finish_callback_ = finish_callback;
270 shortcut_icon_murmur2_hash_ = icon_murmur2_hash; 281 shortcut_icon_murmur2_hash_ = icon_murmur2_hash;
271 webapk_package_ = webapk_package; 282 webapk_package_ = webapk_package;
272 webapk_version_ = webapk_version; 283 webapk_version_ = webapk_version;
273 task_type_ = UPDATE; 284 task_type_ = UPDATE;
274 285
275 base::PostTaskAndReplyWithResult( 286 base::PostTaskAndReplyWithResult(
276 GetBackgroundTaskRunner().get(), FROM_HERE, 287 GetBackgroundTaskRunner().get(), FROM_HERE,
277 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, 288 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_,
278 shortcut_icon_, shortcut_icon_murmur2_hash_), 289 shortcut_icon_murmur2_hash_, stale_manifest, icon_hashs),
279 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, 290 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest,
280 weak_ptr_factory_.GetWeakPtr())); 291 weak_ptr_factory_.GetWeakPtr()));
281 } 292 }
282 293
283 void WebApkInstaller::SetTimeoutMs(int timeout_ms) { 294 void WebApkInstaller::SetTimeoutMs(int timeout_ms) {
284 webapk_download_url_timeout_ms_ = timeout_ms; 295 webapk_download_url_timeout_ms_ = timeout_ms;
285 download_timeout_ms_ = timeout_ms; 296 download_timeout_ms_ = timeout_ms;
286 } 297 }
287 298
288 void WebApkInstaller::OnInstallFinished( 299 void WebApkInstaller::OnInstallFinished(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 shortcut_icon_murmur2_hash_ = icon_murmur2_hash; 379 shortcut_icon_murmur2_hash_ = icon_murmur2_hash;
369 380
370 // An empty hash indicates that |icon_hasher_| encountered an error. 381 // An empty hash indicates that |icon_hasher_| encountered an error.
371 if (icon_murmur2_hash.empty()) { 382 if (icon_murmur2_hash.empty()) {
372 OnFailure(); 383 OnFailure();
373 return; 384 return;
374 } 385 }
375 386
376 base::PostTaskAndReplyWithResult( 387 base::PostTaskAndReplyWithResult(
377 GetBackgroundTaskRunner().get(), FROM_HERE, 388 GetBackgroundTaskRunner().get(), FROM_HERE,
378 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, 389 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_,
379 shortcut_icon_, shortcut_icon_murmur2_hash_), 390 shortcut_icon_murmur2_hash_, false,
391 std::vector<std::string>()),
380 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, 392 base::Bind(&WebApkInstaller::SendCreateWebApkRequest,
381 weak_ptr_factory_.GetWeakPtr())); 393 weak_ptr_factory_.GetWeakPtr()));
382 } 394 }
383 395
384 void WebApkInstaller::SendCreateWebApkRequest( 396 void WebApkInstaller::SendCreateWebApkRequest(
385 std::unique_ptr<webapk::WebApk> webapk) { 397 std::unique_ptr<webapk::WebApk> webapk) {
386 SendRequest(std::move(webapk), server_url_); 398 SendRequest(std::move(webapk), server_url_);
387 } 399 }
388 400
389 void WebApkInstaller::SendUpdateWebApkRequest( 401 void WebApkInstaller::SendUpdateWebApkRequest(
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 527
516 void WebApkInstaller::OnSuccess() { 528 void WebApkInstaller::OnSuccess() {
517 finish_callback_.Run(true, webapk_package_); 529 finish_callback_.Run(true, webapk_package_);
518 delete this; 530 delete this;
519 } 531 }
520 532
521 void WebApkInstaller::OnFailure() { 533 void WebApkInstaller::OnFailure() {
522 finish_callback_.Run(false, webapk_package_); 534 finish_callback_.Run(false, webapk_package_);
523 delete this; 535 delete this;
524 } 536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698