Chromium Code Reviews| 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, | 345 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, |
| 346 const ShortcutInfo& shortcut_info, | 346 const ShortcutInfo& shortcut_info, |
| 347 const SkBitmap& shortcut_icon) | 347 const SkBitmap& shortcut_icon) |
| 348 : request_context_getter_( | 348 : request_context_getter_( |
| 349 Profile::FromBrowserContext(browser_context)->GetRequestContext()), | 349 Profile::FromBrowserContext(browser_context)->GetRequestContext()), |
| 350 shortcut_info_(shortcut_info), | 350 shortcut_info_(shortcut_info), |
| 351 shortcut_icon_(shortcut_icon), | 351 shortcut_icon_(shortcut_icon), |
| 352 server_url_(GetServerUrl()), | 352 server_url_(GetServerUrl()), |
| 353 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), | 353 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), |
| 354 download_timeout_ms_(kDownloadTimeoutMs), | 354 download_timeout_ms_(kDownloadTimeoutMs), |
| 355 less_updates_(false), | |
| 355 task_type_(UNDEFINED), | 356 task_type_(UNDEFINED), |
| 356 weak_ptr_factory_(this) { | 357 weak_ptr_factory_(this) { |
| 357 CreateJavaRef(); | 358 CreateJavaRef(); |
| 358 } | 359 } |
| 359 | 360 |
| 360 void WebApkInstaller::CreateJavaRef() { | 361 void WebApkInstaller::CreateJavaRef() { |
| 361 JNIEnv* env = base::android::AttachCurrentThread(); | 362 JNIEnv* env = base::android::AttachCurrentThread(); |
| 362 java_ref_.Reset( | 363 java_ref_.Reset( |
| 363 Java_WebApkInstaller_create(env, reinterpret_cast<intptr_t>(this))); | 364 Java_WebApkInstaller_create(env, reinterpret_cast<intptr_t>(this))); |
| 364 } | 365 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 std::string response_string; | 410 std::string response_string; |
| 410 source->GetResponseAsString(&response_string); | 411 source->GetResponseAsString(&response_string); |
| 411 | 412 |
| 412 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); | 413 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); |
| 413 if (!response->ParseFromString(response_string)) { | 414 if (!response->ParseFromString(response_string)) { |
| 414 OnFailure(); | 415 OnFailure(); |
| 415 return; | 416 return; |
| 416 } | 417 } |
| 417 | 418 |
| 418 GURL signed_download_url(response->signed_download_url()); | 419 GURL signed_download_url(response->signed_download_url()); |
| 419 // https://crbug.com/680131. The server sends an empty URL if the server does | |
| 420 // not have a newer WebAPK to update to. | |
| 421 if (task_type_ == UPDATE && signed_download_url.is_empty()) { | 420 if (task_type_ == UPDATE && signed_download_url.is_empty()) { |
| 421 less_updates_ = response->infrequent_updates(); | |
|
pkotwicz
2017/02/14 00:15:13
Nit: Rename the field in the proto to |less_update
dominickn
2017/02/14 04:13:34
I'd call it relax_updates
Xi Han
2017/02/14 22:25:47
Done.
| |
| 422 // https://crbug.com/680131. The server sends an empty URL if the server | |
| 423 // does not have a newer WebAPK to update to. | |
| 422 OnSuccess(); | 424 OnSuccess(); |
| 423 return; | 425 return; |
| 424 } | 426 } |
| 425 | 427 |
| 426 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 428 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
| 427 OnFailure(); | 429 OnFailure(); |
| 428 return; | 430 return; |
| 429 } | 431 } |
| 430 | 432 |
| 431 if (CanUseGooglePlayInstallService()) { | 433 if (CanUseGooglePlayInstallService()) { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 } | 620 } |
| 619 if (!success) | 621 if (!success) |
| 620 OnFailure(); | 622 OnFailure(); |
| 621 } | 623 } |
| 622 | 624 |
| 623 void WebApkInstaller::OnTimeout() { | 625 void WebApkInstaller::OnTimeout() { |
| 624 OnFailure(); | 626 OnFailure(); |
| 625 } | 627 } |
| 626 | 628 |
| 627 void WebApkInstaller::OnSuccess() { | 629 void WebApkInstaller::OnSuccess() { |
| 628 finish_callback_.Run(true, webapk_package_); | 630 finish_callback_.Run(true, webapk_package_, less_updates_); |
| 629 delete this; | 631 delete this; |
| 630 } | 632 } |
| 631 | 633 |
| 632 void WebApkInstaller::OnFailure() { | 634 void WebApkInstaller::OnFailure() { |
| 633 finish_callback_.Run(false, webapk_package_); | 635 finish_callback_.Run(false, webapk_package_, less_updates_); |
| 634 delete this; | 636 delete this; |
| 635 } | 637 } |
| OLD | NEW |