| 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 icon_url_to_murmur2_hash, is_manifest_stale), | 395 icon_url_to_murmur2_hash, is_manifest_stale), |
| 396 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, | 396 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, |
| 397 weak_ptr_factory_.GetWeakPtr())); | 397 weak_ptr_factory_.GetWeakPtr())); |
| 398 } | 398 } |
| 399 | 399 |
| 400 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { | 400 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { |
| 401 timer_.Stop(); | 401 timer_.Stop(); |
| 402 | 402 |
| 403 if (!source->GetStatus().is_success() || | 403 if (!source->GetStatus().is_success() || |
| 404 source->GetResponseCode() != net::HTTP_OK) { | 404 source->GetResponseCode() != net::HTTP_OK) { |
| 405 LOG(WARNING) << base::StringPrintf( |
| 406 "WebAPK server returned response code %d.", source->GetResponseCode()); |
| 405 OnFailure(); | 407 OnFailure(); |
| 406 return; | 408 return; |
| 407 } | 409 } |
| 408 | 410 |
| 409 std::string response_string; | 411 std::string response_string; |
| 410 source->GetResponseAsString(&response_string); | 412 source->GetResponseAsString(&response_string); |
| 411 | 413 |
| 412 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); | 414 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); |
| 413 if (!response->ParseFromString(response_string)) { | 415 if (!response->ParseFromString(response_string)) { |
| 416 LOG(WARNING) << "WebAPK server did not return proto."; |
| 414 OnFailure(); | 417 OnFailure(); |
| 415 return; | 418 return; |
| 416 } | 419 } |
| 417 | 420 |
| 418 GURL signed_download_url(response->signed_download_url()); | 421 GURL signed_download_url(response->signed_download_url()); |
| 419 // https://crbug.com/680131. The server sends an empty URL if the server does | 422 // https://crbug.com/680131. The server sends an empty URL if the server does |
| 420 // not have a newer WebAPK to update to. | 423 // not have a newer WebAPK to update to. |
| 421 if (task_type_ == UPDATE && signed_download_url.is_empty()) { | 424 if (task_type_ == UPDATE && signed_download_url.is_empty()) { |
| 422 OnSuccess(); | 425 OnSuccess(); |
| 423 return; | 426 return; |
| 424 } | 427 } |
| 425 | 428 |
| 426 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 429 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
| 430 LOG(WARNING) << "WebAPK server returned incomplete proto."; |
| 427 OnFailure(); | 431 OnFailure(); |
| 428 return; | 432 return; |
| 429 } | 433 } |
| 430 | 434 |
| 431 if (CanUseGooglePlayInstallService()) { | 435 if (CanUseGooglePlayInstallService()) { |
| 432 int version = 1; | 436 int version = 1; |
| 433 base::StringToInt(response->version(), &version); | 437 base::StringToInt(response->version(), &version); |
| 434 // TODO(hanxi): crbug.com/688759. Remove the return value of | 438 // TODO(hanxi): crbug.com/688759. Remove the return value of |
| 435 // InstallOrUpdateWebApkFromGooglePlay(), since a callback will be called | 439 // InstallOrUpdateWebApkFromGooglePlay(), since a callback will be called |
| 436 // asynchronously after the install or upidate has either failed or | 440 // asynchronously after the install or upidate has either failed or |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 | 630 |
| 627 void WebApkInstaller::OnSuccess() { | 631 void WebApkInstaller::OnSuccess() { |
| 628 finish_callback_.Run(true, webapk_package_); | 632 finish_callback_.Run(true, webapk_package_); |
| 629 delete this; | 633 delete this; |
| 630 } | 634 } |
| 631 | 635 |
| 632 void WebApkInstaller::OnFailure() { | 636 void WebApkInstaller::OnFailure() { |
| 633 finish_callback_.Run(false, webapk_package_); | 637 finish_callback_.Run(false, webapk_package_); |
| 634 delete this; | 638 delete this; |
| 635 } | 639 } |
| OLD | NEW |