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

Side by Side Diff: chrome/browser/android/webapk/webapk_installer.cc

Issue 2453423002: Send all of the icon URLs listed in Web Manifest to WebAPK Server. (Closed)
Patch Set: Created 4 years, 1 month 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 content::WebScreenOrientationLockTypeToString( 109 content::WebScreenOrientationLockTypeToString(
110 shortcut_info.orientation)); 110 shortcut_info.orientation));
111 web_app_manifest->set_display_mode( 111 web_app_manifest->set_display_mode(
112 content::WebDisplayModeToString(shortcut_info.display)); 112 content::WebDisplayModeToString(shortcut_info.display));
113 web_app_manifest->set_background_color( 113 web_app_manifest->set_background_color(
114 ColorToString(shortcut_info.background_color)); 114 ColorToString(shortcut_info.background_color));
115 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); 115 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color));
116 116
117 std::string* scope = web_app_manifest->add_scopes(); 117 std::string* scope = web_app_manifest->add_scopes();
118 scope->assign(GetScope(shortcut_info).spec()); 118 scope->assign(GetScope(shortcut_info).spec());
119 webapk::Image* image = web_app_manifest->add_icons(); 119 webapk::Image* image = web_app_manifest->add_icons();
pkotwicz 2016/11/01 00:29:50 Nit: Rename |image| -> |best_image|
Xi Han 2016/11/07 16:51:43 Done.
120 image->set_src(shortcut_info.icon_url.spec()); 120 image->set_src(shortcut_info.best_icon_url.spec());
121 image->set_hash(shortcut_icon_murmur2_hash); 121 image->set_hash(shortcut_icon_murmur2_hash);
122 std::vector<unsigned char> png_bytes; 122 std::vector<unsigned char> png_bytes;
123 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes); 123 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes);
124 image->set_image_data(&png_bytes.front(), png_bytes.size()); 124 image->set_image_data(&png_bytes.front(), png_bytes.size());
125 125
126 for (const auto& icon_url : shortcut_info.icon_urls) {
pkotwicz 2016/11/01 00:29:50 Nit: "const auto& icon_url" -> "const GURL& icon_u
Xi Han 2016/11/07 16:51:43 Done.
127 if (icon_url == shortcut_info.best_icon_url)
128 continue;
129 webapk::Image* image = web_app_manifest->add_icons();
130 image->set_src(icon_url.spec());
131 }
pkotwicz 2016/11/01 00:29:49 Can you check with Glenn whether reordering is ok?
Xi Han 2016/11/07 16:51:43 I talked to Glenn and he prefers to have the best
132
126 return webapk; 133 return webapk;
127 } 134 }
128 135
129 // Returns task runner for running background tasks. 136 // Returns task runner for running background tasks.
130 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { 137 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() {
131 return content::BrowserThread::GetBlockingPool() 138 return content::BrowserThread::GetBlockingPool()
132 ->GetTaskRunnerWithShutdownBehavior( 139 ->GetTaskRunnerWithShutdownBehavior(
133 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 140 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
134 } 141 }
135 142
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 GURL signed_download_url(response->signed_download_url()); 311 GURL signed_download_url(response->signed_download_url());
305 if (!signed_download_url.is_valid() || response->package_name().empty()) { 312 if (!signed_download_url.is_valid() || response->package_name().empty()) {
306 OnFailure(); 313 OnFailure();
307 return; 314 return;
308 } 315 }
309 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); 316 OnGotWebApkDownloadUrl(signed_download_url, response->package_name());
310 } 317 }
311 318
312 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { 319 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() {
313 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. 320 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL.
314 if (!shortcut_info_.icon_url.is_valid()) { 321 if (!shortcut_info_.best_icon_url.is_valid()) {
315 OnFailure(); 322 OnFailure();
316 return; 323 return;
317 } 324 }
318 325
319 timer_.Start( 326 timer_.Start(
320 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), 327 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_),
321 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); 328 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr()));
322 329
323 icon_hasher_.reset(new WebApkIconHasher()); 330 icon_hasher_.reset(new WebApkIconHasher());
324 icon_hasher_->DownloadAndComputeMurmur2Hash( 331 icon_hasher_->DownloadAndComputeMurmur2Hash(
325 request_context_getter_, shortcut_info_.icon_url, 332 request_context_getter_, shortcut_info_.best_icon_url,
326 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, 333 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash,
327 weak_ptr_factory_.GetWeakPtr())); 334 weak_ptr_factory_.GetWeakPtr()));
328 } 335 }
329 336
330 void WebApkInstaller::OnGotIconMurmur2Hash( 337 void WebApkInstaller::OnGotIconMurmur2Hash(
331 const std::string& icon_murmur2_hash) { 338 const std::string& icon_murmur2_hash) {
332 timer_.Stop(); 339 timer_.Stop();
333 icon_hasher_.reset(); 340 icon_hasher_.reset();
334 341
335 shortcut_icon_murmur2_hash_ = icon_murmur2_hash; 342 shortcut_icon_murmur2_hash_ = icon_murmur2_hash;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 488
482 void WebApkInstaller::OnSuccess() { 489 void WebApkInstaller::OnSuccess() {
483 finish_callback_.Run(true, webapk_package_); 490 finish_callback_.Run(true, webapk_package_);
484 delete this; 491 delete this;
485 } 492 }
486 493
487 void WebApkInstaller::OnFailure() { 494 void WebApkInstaller::OnFailure() {
488 finish_callback_.Run(false, webapk_package_); 495 finish_callback_.Run(false, webapk_package_);
489 delete this; 496 delete this;
490 } 497 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698