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

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

Issue 2733543002: [Android:WebAPK] Don't add webapp to homescreen if WebAPK install times out part 1/3 (Closed)
Patch Set: Merge branch 'refactor_shortcut_helper29' into refactor_shortcut_helper3 Created 3 years, 9 months 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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
21 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
22 #include "chrome/browser/android/shortcut_helper.h" 22 #include "chrome/browser/android/shortcut_helper.h"
23 #include "chrome/browser/android/webapk/webapk.pb.h" 23 #include "chrome/browser/android/webapk/webapk.pb.h"
24 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" 24 #include "chrome/browser/android/webapk/webapk_icon_hasher.h"
25 #include "chrome/browser/android/webapk/webapk_install_service.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "components/version_info/version_info.h" 28 #include "components/version_info/version_info.h"
28 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
29 #include "content/public/common/manifest_util.h" 30 #include "content/public/common/manifest_util.h"
30 #include "jni/WebApkInstaller_jni.h" 31 #include "jni/WebApkInstaller_jni.h"
31 #include "net/base/load_flags.h" 32 #include "net/base/load_flags.h"
32 #include "net/http/http_status_code.h" 33 #include "net/http/http_status_code.h"
33 #include "net/traffic_annotation/network_traffic_annotation.h" 34 #include "net/traffic_annotation/network_traffic_annotation.h"
34 #include "net/url_request/url_fetcher.h" 35 #include "net/url_request/url_fetcher.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 267 }
267 268
268 void WebApkInstaller::SetTimeoutMs(int timeout_ms) { 269 void WebApkInstaller::SetTimeoutMs(int timeout_ms) {
269 webapk_download_url_timeout_ms_ = timeout_ms; 270 webapk_download_url_timeout_ms_ = timeout_ms;
270 download_timeout_ms_ = timeout_ms; 271 download_timeout_ms_ = timeout_ms;
271 } 272 }
272 273
273 void WebApkInstaller::OnInstallFinished( 274 void WebApkInstaller::OnInstallFinished(
274 JNIEnv* env, 275 JNIEnv* env,
275 const base::android::JavaParamRef<jobject>& obj, 276 const base::android::JavaParamRef<jobject>& obj,
276 jboolean success) { 277 jint result) {
277 if (success) 278 OnResult(static_cast<WebApkInstallResult>(result));
278 OnSuccess();
279 else
280 OnFailure();
281 } 279 }
282 280
283 void WebApkInstaller::BuildWebApkProtoInBackgroundForTesting( 281 void WebApkInstaller::BuildWebApkProtoInBackgroundForTesting(
284 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, 282 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback,
285 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, 283 const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
286 bool is_manifest_stale) { 284 bool is_manifest_stale) {
287 base::PostTaskAndReplyWithResult( 285 base::PostTaskAndReplyWithResult(
288 GetBackgroundTaskRunner().get(), FROM_HERE, 286 GetBackgroundTaskRunner().get(), FROM_HERE,
289 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, 287 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_,
290 icon_url_to_murmur2_hash, is_manifest_stale), 288 icon_url_to_murmur2_hash, is_manifest_stale),
291 base::Bind(&OnWebApkProtoBuilt, callback)); 289 base::Bind(&OnWebApkProtoBuilt, callback));
292 } 290 }
293 291
294 // static 292 // static
295 bool WebApkInstaller::Register(JNIEnv* env) { 293 bool WebApkInstaller::Register(JNIEnv* env) {
296 return RegisterNativesImpl(env); 294 return RegisterNativesImpl(env);
297 } 295 }
298 296
299 bool WebApkInstaller::StartInstallingDownloadedWebApk( 297 bool WebApkInstaller::StartInstallingDownloadedWebApk(
300 JNIEnv* env, 298 JNIEnv* env,
301 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, 299 const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
302 const base::android::ScopedJavaLocalRef<jstring>& java_package_name) { 300 const base::android::ScopedJavaLocalRef<jstring>& java_package_name) {
303 return Java_WebApkInstaller_installAsyncAndMonitorInstallationFromNative( 301 return Java_WebApkInstaller_installAsyncAndMonitorInstallationFromNative(
304 env, java_ref_, java_file_path, java_package_name); 302 env, java_ref_, java_file_path, java_package_name);
305 } 303 }
306 304
307 bool WebApkInstaller::StartUpdateUsingDownloadedWebApk( 305 bool WebApkInstaller::StartUpdateUsingDownloadedWebApk(
308 JNIEnv* env, 306 JNIEnv* env,
309 const base::android::ScopedJavaLocalRef<jstring>& java_file_path) { 307 const base::android::ScopedJavaLocalRef<jstring>& java_file_path) {
310 return Java_WebApkInstaller_updateAsyncFromNative(env, java_ref_, 308 return Java_WebApkInstaller_updateAsyncFromNative(env, java_ref_,
dominickn 2017/03/05 23:52:40 Can updates also use WebApkInstallResult instead o
pkotwicz 2017/03/12 21:11:48 I have addressed this concern in https://coderevie
311 java_file_path); 309 java_file_path);
312 } 310 }
313 311
314 bool WebApkInstaller::CanUseGooglePlayInstallService() { 312 bool WebApkInstaller::CanUseGooglePlayInstallService() {
315 JNIEnv* env = base::android::AttachCurrentThread(); 313 JNIEnv* env = base::android::AttachCurrentThread();
316 return Java_WebApkInstaller_canUseGooglePlayInstallService(env, java_ref_); 314 return Java_WebApkInstaller_canUseGooglePlayInstallService(env, java_ref_);
317 } 315 }
318 316
319 void WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay( 317 void WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay(
320 const std::string& package_name, 318 const std::string& package_name,
(...skipping 15 matching lines...) Expand all
336 Java_WebApkInstaller_installWebApkFromGooglePlayAsync( 334 Java_WebApkInstaller_installWebApkFromGooglePlayAsync(
337 env, java_ref_, java_webapk_package, version, java_title, java_token, 335 env, java_ref_, java_webapk_package, version, java_title, java_token,
338 java_url); 336 java_url);
339 } else { 337 } else {
340 Java_WebApkInstaller_updateAsyncFromGooglePlay( 338 Java_WebApkInstaller_updateAsyncFromGooglePlay(
341 env, java_ref_, java_webapk_package, version, java_title, java_token, 339 env, java_ref_, java_webapk_package, version, java_title, java_token,
342 java_url); 340 java_url);
343 } 341 }
344 } 342 }
345 343
344 void WebApkInstaller::OnSuccess() {
dominickn 2017/03/05 23:52:40 Can you remove this method and just call OnResult
345 OnResult(WebApkInstallResult::INSTALLED);
346 }
347
346 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, 348 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context,
347 const ShortcutInfo& shortcut_info, 349 const ShortcutInfo& shortcut_info,
348 const SkBitmap& shortcut_icon) 350 const SkBitmap& shortcut_icon)
349 : request_context_getter_( 351 : request_context_getter_(
350 Profile::FromBrowserContext(browser_context)->GetRequestContext()), 352 Profile::FromBrowserContext(browser_context)->GetRequestContext()),
351 shortcut_info_(shortcut_info), 353 shortcut_info_(shortcut_info),
352 shortcut_icon_(shortcut_icon), 354 shortcut_icon_(shortcut_icon),
353 server_url_(GetServerUrl()), 355 server_url_(GetServerUrl()),
354 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), 356 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs),
355 download_timeout_ms_(kDownloadTimeoutMs), 357 download_timeout_ms_(kDownloadTimeoutMs),
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 621 }
620 } 622 }
621 if (!success) 623 if (!success)
622 OnFailure(); 624 OnFailure();
623 } 625 }
624 626
625 void WebApkInstaller::OnTimeout() { 627 void WebApkInstaller::OnTimeout() {
626 OnFailure(); 628 OnFailure();
627 } 629 }
628 630
629 void WebApkInstaller::OnSuccess() { 631 void WebApkInstaller::OnFailure() {
dominickn 2017/03/05 23:52:40 Can you remove this method and call OnResult direc
630 finish_callback_.Run(true, webapk_package_); 632 OnResult(WebApkInstallResult::INSTALL_FAILED);
633 }
634
635 void WebApkInstaller::OnResult(WebApkInstallResult result) {
636 finish_callback_.Run(result, webapk_package_);
631 delete this; 637 delete this;
632 } 638 }
633
634 void WebApkInstaller::OnFailure() {
635 finish_callback_.Run(false, webapk_package_);
636 delete this;
637 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698