OLD | NEW |
---|---|
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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, | 346 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, |
347 const ShortcutInfo& shortcut_info, | 347 const ShortcutInfo& shortcut_info, |
348 const SkBitmap& shortcut_icon) | 348 const SkBitmap& shortcut_icon) |
349 : request_context_getter_( | 349 : request_context_getter_( |
350 Profile::FromBrowserContext(browser_context)->GetRequestContext()), | 350 Profile::FromBrowserContext(browser_context)->GetRequestContext()), |
351 shortcut_info_(shortcut_info), | 351 shortcut_info_(shortcut_info), |
352 shortcut_icon_(shortcut_icon), | 352 shortcut_icon_(shortcut_icon), |
353 server_url_(GetServerUrl()), | 353 server_url_(GetServerUrl()), |
354 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), | 354 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), |
355 download_timeout_ms_(kDownloadTimeoutMs), | 355 download_timeout_ms_(kDownloadTimeoutMs), |
356 relax_updates_(false), | |
pkotwicz
2017/03/04 00:20:47
Nit: Can you initialize |webapk_version_| ?
Xi Han
2017/03/06 22:14:21
Done.
| |
356 task_type_(UNDEFINED), | 357 task_type_(UNDEFINED), |
357 weak_ptr_factory_(this) { | 358 weak_ptr_factory_(this) { |
358 CreateJavaRef(); | 359 CreateJavaRef(); |
359 } | 360 } |
360 | 361 |
361 void WebApkInstaller::CreateJavaRef() { | 362 void WebApkInstaller::CreateJavaRef() { |
362 JNIEnv* env = base::android::AttachCurrentThread(); | 363 JNIEnv* env = base::android::AttachCurrentThread(); |
363 java_ref_.Reset( | 364 java_ref_.Reset( |
364 Java_WebApkInstaller_create(env, reinterpret_cast<intptr_t>(this))); | 365 Java_WebApkInstaller_create(env, reinterpret_cast<intptr_t>(this))); |
365 } | 366 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 source->GetResponseAsString(&response_string); | 414 source->GetResponseAsString(&response_string); |
414 | 415 |
415 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); | 416 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); |
416 if (!response->ParseFromString(response_string)) { | 417 if (!response->ParseFromString(response_string)) { |
417 LOG(WARNING) << "WebAPK server did not return proto."; | 418 LOG(WARNING) << "WebAPK server did not return proto."; |
418 OnFailure(); | 419 OnFailure(); |
419 return; | 420 return; |
420 } | 421 } |
421 | 422 |
422 GURL signed_download_url(response->signed_download_url()); | 423 GURL signed_download_url(response->signed_download_url()); |
423 // https://crbug.com/680131. The server sends an empty URL if the server does | |
424 // not have a newer WebAPK to update to. | |
425 if (task_type_ == UPDATE && signed_download_url.is_empty()) { | 424 if (task_type_ == UPDATE && signed_download_url.is_empty()) { |
425 relax_updates_ = response->relax_updates(); | |
pkotwicz
2017/03/04 00:20:47
Nit: Move the setting of |relax_updates_| after th
Xi Han
2017/03/06 22:14:21
Done.
| |
426 // https://crbug.com/680131. The server sends an empty URL if the server | |
427 // does not have a newer WebAPK to update to. | |
426 OnSuccess(); | 428 OnSuccess(); |
427 return; | 429 return; |
428 } | 430 } |
429 | 431 |
430 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 432 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
431 LOG(WARNING) << "WebAPK server returned incomplete proto."; | 433 LOG(WARNING) << "WebAPK server returned incomplete proto."; |
432 OnFailure(); | 434 OnFailure(); |
433 return; | 435 return; |
434 } | 436 } |
435 | 437 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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::OnSuccess() { |
630 finish_callback_.Run(true, webapk_package_); | 632 finish_callback_.Run(true, relax_updates_, webapk_package_); |
631 delete this; | 633 delete this; |
632 } | 634 } |
633 | 635 |
634 void WebApkInstaller::OnFailure() { | 636 void WebApkInstaller::OnFailure() { |
635 finish_callback_.Run(false, webapk_package_); | 637 finish_callback_.Run(false, relax_updates_, webapk_package_); |
636 delete this; | 638 delete this; |
637 } | 639 } |
OLD | NEW |