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 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 infrequent_updates_(false), | |
| 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(Java_WebApkInstaller_create( | 364 java_ref_.Reset(Java_WebApkInstaller_create( |
| 364 env, reinterpret_cast<intptr_t>(this))); | 365 env, reinterpret_cast<intptr_t>(this))); |
| 365 } | 366 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 | 410 |
| 410 std::string response_string; | 411 std::string response_string; |
| 411 source->GetResponseAsString(&response_string); | 412 source->GetResponseAsString(&response_string); |
| 412 | 413 |
| 413 std::unique_ptr<webapk::WebApkResponse> response( | 414 std::unique_ptr<webapk::WebApkResponse> response( |
| 414 new webapk::WebApkResponse); | 415 new webapk::WebApkResponse); |
| 415 if (!response->ParseFromString(response_string)) { | 416 if (!response->ParseFromString(response_string)) { |
| 416 OnFailure(); | 417 OnFailure(); |
| 417 return; | 418 return; |
| 418 } | 419 } |
| 419 | 420 |
|
pkotwicz
2017/02/10 02:51:22
We should set |less_updates_| from within the
if
Xi Han
2017/02/13 22:56:14
Done.
| |
| 420 GURL signed_download_url(response->signed_download_url()); | 421 GURL signed_download_url(response->signed_download_url()); |
| 422 infrequent_updates_ = response->infrequent_updates(); | |
| 421 // https://crbug.com/680131. The server sends an empty URL if the server does | 423 // https://crbug.com/680131. The server sends an empty URL if the server does |
| 422 // not have a newer WebAPK to update to. | 424 // not have a newer WebAPK to update to. |
| 423 if (task_type_ == UPDATE && signed_download_url.is_empty()) { | 425 if (task_type_ == UPDATE && signed_download_url.is_empty()) { |
| 424 OnSuccess(); | 426 OnSuccess(); |
| 425 return; | 427 return; |
| 426 } | 428 } |
| 427 | 429 |
| 428 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 430 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
| 429 OnFailure(); | 431 OnFailure(); |
| 430 return; | 432 return; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 } | 616 } |
| 615 if (!success) | 617 if (!success) |
| 616 OnFailure(); | 618 OnFailure(); |
| 617 } | 619 } |
| 618 | 620 |
| 619 void WebApkInstaller::OnTimeout() { | 621 void WebApkInstaller::OnTimeout() { |
| 620 OnFailure(); | 622 OnFailure(); |
| 621 } | 623 } |
| 622 | 624 |
| 623 void WebApkInstaller::OnSuccess() { | 625 void WebApkInstaller::OnSuccess() { |
| 624 finish_callback_.Run(true, webapk_package_); | 626 FinishCallbackData data = {webapk_package_, infrequent_updates_}; |
| 627 finish_callback_.Run(true, data); | |
| 625 delete this; | 628 delete this; |
| 626 } | 629 } |
| 627 | 630 |
| 628 void WebApkInstaller::OnFailure() { | 631 void WebApkInstaller::OnFailure() { |
| 629 finish_callback_.Run(false, webapk_package_); | 632 FinishCallbackData data = {webapk_package_, infrequent_updates_}; |
| 633 finish_callback_.Run(false, data); | |
| 630 delete this; | 634 delete this; |
| 631 } | 635 } |
| OLD | NEW |