| 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" |
| 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/chrome_webapk_host.h" | 23 #include "chrome/browser/android/webapk/chrome_webapk_host.h" |
| 24 #include "chrome/browser/android/webapk/webapk.pb.h" | 24 #include "chrome/browser/android/webapk/webapk.pb.h" |
| 25 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" | 25 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" |
| 26 #include "chrome/browser/android/webapk/webapk_install_service.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 28 #include "components/version_info/version_info.h" | 29 #include "components/version_info/version_info.h" |
| 29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/common/manifest_util.h" | 31 #include "content/public/common/manifest_util.h" |
| 31 #include "jni/WebApkInstaller_jni.h" | 32 #include "jni/WebApkInstaller_jni.h" |
| 32 #include "net/base/load_flags.h" | 33 #include "net/base/load_flags.h" |
| 33 #include "net/http/http_status_code.h" | 34 #include "net/http/http_status_code.h" |
| 34 #include "net/traffic_annotation/network_traffic_annotation.h" | 35 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 35 #include "net/url_request/url_fetcher.h" | 36 #include "net/url_request/url_fetcher.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 265 } |
| 265 | 266 |
| 266 void WebApkInstaller::SetTimeoutMs(int timeout_ms) { | 267 void WebApkInstaller::SetTimeoutMs(int timeout_ms) { |
| 267 webapk_download_url_timeout_ms_ = timeout_ms; | 268 webapk_download_url_timeout_ms_ = timeout_ms; |
| 268 download_timeout_ms_ = timeout_ms; | 269 download_timeout_ms_ = timeout_ms; |
| 269 } | 270 } |
| 270 | 271 |
| 271 void WebApkInstaller::OnInstallFinished( | 272 void WebApkInstaller::OnInstallFinished( |
| 272 JNIEnv* env, | 273 JNIEnv* env, |
| 273 const base::android::JavaParamRef<jobject>& obj, | 274 const base::android::JavaParamRef<jobject>& obj, |
| 274 jboolean success) { | 275 jint result) { |
| 275 if (success) | 276 OnResult(static_cast<WebApkInstallResult>(result)); |
| 276 OnSuccess(); | |
| 277 else | |
| 278 OnFailure(); | |
| 279 } | 277 } |
| 280 | 278 |
| 281 void WebApkInstaller::BuildWebApkProtoInBackgroundForTesting( | 279 void WebApkInstaller::BuildWebApkProtoInBackgroundForTesting( |
| 282 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 280 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
| 283 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 281 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 284 bool is_manifest_stale) { | 282 bool is_manifest_stale) { |
| 285 base::PostTaskAndReplyWithResult( | 283 base::PostTaskAndReplyWithResult( |
| 286 GetBackgroundTaskRunner().get(), FROM_HERE, | 284 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 287 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, | 285 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, |
| 288 icon_url_to_murmur2_hash, is_manifest_stale), | 286 icon_url_to_murmur2_hash, is_manifest_stale), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 Java_WebApkInstaller_installWebApkFromGooglePlayAsync( | 332 Java_WebApkInstaller_installWebApkFromGooglePlayAsync( |
| 335 env, java_ref_, java_webapk_package, version, java_title, java_token, | 333 env, java_ref_, java_webapk_package, version, java_title, java_token, |
| 336 java_url); | 334 java_url); |
| 337 } else { | 335 } else { |
| 338 Java_WebApkInstaller_updateAsyncFromGooglePlay( | 336 Java_WebApkInstaller_updateAsyncFromGooglePlay( |
| 339 env, java_ref_, java_webapk_package, version, java_title, java_token, | 337 env, java_ref_, java_webapk_package, version, java_title, java_token, |
| 340 java_url); | 338 java_url); |
| 341 } | 339 } |
| 342 } | 340 } |
| 343 | 341 |
| 342 void WebApkInstaller::OnResult(WebApkInstallResult result) { |
| 343 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 344 finish_callback_.Run(result, relax_updates_, webapk_package_); |
| 345 delete this; |
| 346 } |
| 347 |
| 344 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, | 348 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, |
| 345 const ShortcutInfo& shortcut_info, | 349 const ShortcutInfo& shortcut_info, |
| 346 const SkBitmap& shortcut_icon) | 350 const SkBitmap& shortcut_icon) |
| 347 : request_context_getter_( | 351 : request_context_getter_( |
| 348 Profile::FromBrowserContext(browser_context)->GetRequestContext()), | 352 Profile::FromBrowserContext(browser_context)->GetRequestContext()), |
| 349 shortcut_info_(shortcut_info), | 353 shortcut_info_(shortcut_info), |
| 350 shortcut_icon_(shortcut_icon), | 354 shortcut_icon_(shortcut_icon), |
| 351 server_url_(GetServerUrl()), | 355 server_url_(GetServerUrl()), |
| 352 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), | 356 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), |
| 353 download_timeout_ms_(kDownloadTimeoutMs), | 357 download_timeout_ms_(kDownloadTimeoutMs), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 weak_ptr_factory_.GetWeakPtr())); | 402 weak_ptr_factory_.GetWeakPtr())); |
| 399 } | 403 } |
| 400 | 404 |
| 401 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { | 405 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { |
| 402 timer_.Stop(); | 406 timer_.Stop(); |
| 403 | 407 |
| 404 if (!source->GetStatus().is_success() || | 408 if (!source->GetStatus().is_success() || |
| 405 source->GetResponseCode() != net::HTTP_OK) { | 409 source->GetResponseCode() != net::HTTP_OK) { |
| 406 LOG(WARNING) << base::StringPrintf( | 410 LOG(WARNING) << base::StringPrintf( |
| 407 "WebAPK server returned response code %d.", source->GetResponseCode()); | 411 "WebAPK server returned response code %d.", source->GetResponseCode()); |
| 408 OnFailure(); | 412 OnResult(WebApkInstallResult::FAILURE); |
| 409 return; | 413 return; |
| 410 } | 414 } |
| 411 | 415 |
| 412 std::string response_string; | 416 std::string response_string; |
| 413 source->GetResponseAsString(&response_string); | 417 source->GetResponseAsString(&response_string); |
| 414 | 418 |
| 415 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); | 419 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); |
| 416 if (!response->ParseFromString(response_string)) { | 420 if (!response->ParseFromString(response_string)) { |
| 417 LOG(WARNING) << "WebAPK server did not return proto."; | 421 LOG(WARNING) << "WebAPK server did not return proto."; |
| 418 OnFailure(); | 422 OnResult(WebApkInstallResult::FAILURE); |
| 419 return; | 423 return; |
| 420 } | 424 } |
| 421 | 425 |
| 422 GURL signed_download_url(response->signed_download_url()); | 426 GURL signed_download_url(response->signed_download_url()); |
| 423 if (task_type_ == UPDATE && signed_download_url.is_empty()) { | 427 if (task_type_ == UPDATE && signed_download_url.is_empty()) { |
| 424 // https://crbug.com/680131. The server sends an empty URL if the server | 428 // https://crbug.com/680131. The server sends an empty URL if the server |
| 425 // does not have a newer WebAPK to update to. | 429 // does not have a newer WebAPK to update to. |
| 426 relax_updates_ = response->relax_updates(); | 430 relax_updates_ = response->relax_updates(); |
| 427 OnSuccess(); | 431 OnResult(WebApkInstallResult::SUCCESS); |
| 428 return; | 432 return; |
| 429 } | 433 } |
| 430 | 434 |
| 431 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 435 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
| 432 LOG(WARNING) << "WebAPK server returned incomplete proto."; | 436 LOG(WARNING) << "WebAPK server returned incomplete proto."; |
| 433 OnFailure(); | 437 OnResult(WebApkInstallResult::FAILURE); |
| 434 return; | 438 return; |
| 435 } | 439 } |
| 436 | 440 |
| 437 if (CanUseGooglePlayInstallService()) { | 441 if (CanUseGooglePlayInstallService()) { |
| 438 int version = 1; | 442 int version = 1; |
| 439 base::StringToInt(response->version(), &version); | 443 base::StringToInt(response->version(), &version); |
| 440 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, | 444 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, |
| 441 response->token()); | 445 response->token()); |
| 442 return; | 446 return; |
| 443 } | 447 } |
| 444 | 448 |
| 445 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); | 449 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); |
| 446 } | 450 } |
| 447 | 451 |
| 448 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { | 452 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { |
| 449 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. | 453 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. |
| 450 if (!shortcut_info_.best_primary_icon_url.is_valid()) { | 454 if (!shortcut_info_.best_primary_icon_url.is_valid()) { |
| 451 OnFailure(); | 455 OnResult(WebApkInstallResult::FAILURE); |
| 452 return; | 456 return; |
| 453 } | 457 } |
| 454 | 458 |
| 455 timer_.Start( | 459 timer_.Start( |
| 456 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), | 460 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), |
| 457 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); | 461 base::Bind(&WebApkInstaller::OnResult, weak_ptr_factory_.GetWeakPtr(), |
| 462 WebApkInstallResult::FAILURE)); |
| 458 | 463 |
| 459 icon_hasher_.reset(new WebApkIconHasher()); | 464 icon_hasher_.reset(new WebApkIconHasher()); |
| 460 icon_hasher_->DownloadAndComputeMurmur2Hash( | 465 icon_hasher_->DownloadAndComputeMurmur2Hash( |
| 461 request_context_getter_, shortcut_info_.best_primary_icon_url, | 466 request_context_getter_, shortcut_info_.best_primary_icon_url, |
| 462 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, | 467 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, |
| 463 weak_ptr_factory_.GetWeakPtr())); | 468 weak_ptr_factory_.GetWeakPtr())); |
| 464 } | 469 } |
| 465 | 470 |
| 466 void WebApkInstaller::OnGotIconMurmur2Hash( | 471 void WebApkInstaller::OnGotIconMurmur2Hash( |
| 467 const std::string& icon_murmur2_hash) { | 472 const std::string& icon_murmur2_hash) { |
| 468 timer_.Stop(); | 473 timer_.Stop(); |
| 469 icon_hasher_.reset(); | 474 icon_hasher_.reset(); |
| 470 | 475 |
| 471 // An empty hash indicates that |icon_hasher_| encountered an error. | 476 // An empty hash indicates that |icon_hasher_| encountered an error. |
| 472 if (icon_murmur2_hash.empty()) { | 477 if (icon_murmur2_hash.empty()) { |
| 473 OnFailure(); | 478 OnResult(WebApkInstallResult::FAILURE); |
| 474 return; | 479 return; |
| 475 } | 480 } |
| 476 | 481 |
| 477 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 482 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
| 478 for (const std::string& icon_url : shortcut_info_.icon_urls) { | 483 for (const std::string& icon_url : shortcut_info_.icon_urls) { |
| 479 if (icon_url != shortcut_info_.best_primary_icon_url.spec()) | 484 if (icon_url != shortcut_info_.best_primary_icon_url.spec()) |
| 480 icon_url_to_murmur2_hash[icon_url] = ""; | 485 icon_url_to_murmur2_hash[icon_url] = ""; |
| 481 else | 486 else |
| 482 icon_url_to_murmur2_hash[icon_url] = icon_murmur2_hash; | 487 icon_url_to_murmur2_hash[icon_url] = icon_murmur2_hash; |
| 483 } | 488 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 501 webapk->set_version(std::to_string(webapk_version_)); | 506 webapk->set_version(std::to_string(webapk_version_)); |
| 502 | 507 |
| 503 SendRequest(std::move(webapk), server_url_); | 508 SendRequest(std::move(webapk), server_url_); |
| 504 } | 509 } |
| 505 | 510 |
| 506 void WebApkInstaller::SendRequest(std::unique_ptr<webapk::WebApk> request_proto, | 511 void WebApkInstaller::SendRequest(std::unique_ptr<webapk::WebApk> request_proto, |
| 507 const GURL& server_url) { | 512 const GURL& server_url) { |
| 508 timer_.Start( | 513 timer_.Start( |
| 509 FROM_HERE, | 514 FROM_HERE, |
| 510 base::TimeDelta::FromMilliseconds(webapk_download_url_timeout_ms_), | 515 base::TimeDelta::FromMilliseconds(webapk_download_url_timeout_ms_), |
| 511 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); | 516 base::Bind(&WebApkInstaller::OnResult, weak_ptr_factory_.GetWeakPtr(), |
| 517 WebApkInstallResult::FAILURE)); |
| 512 | 518 |
| 513 url_fetcher_ = | 519 url_fetcher_ = |
| 514 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); | 520 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); |
| 515 url_fetcher_->SetRequestContext(request_context_getter_); | 521 url_fetcher_->SetRequestContext(request_context_getter_); |
| 516 std::string serialized_request; | 522 std::string serialized_request; |
| 517 request_proto->SerializeToString(&serialized_request); | 523 request_proto->SerializeToString(&serialized_request); |
| 518 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); | 524 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); |
| 519 url_fetcher_->SetLoadFlags( | 525 url_fetcher_->SetLoadFlags( |
| 520 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES | | 526 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES | |
| 521 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); | 527 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 532 task_type_ == WebApkInstaller::INSTALL ? "install" : "update", | 538 task_type_ == WebApkInstaller::INSTALL ? "install" : "update", |
| 533 package_name), | 539 package_name), |
| 534 base::Bind(&WebApkInstaller::OnCreatedSubDirAndSetPermissions, | 540 base::Bind(&WebApkInstaller::OnCreatedSubDirAndSetPermissions, |
| 535 weak_ptr_factory_.GetWeakPtr(), download_url)); | 541 weak_ptr_factory_.GetWeakPtr(), download_url)); |
| 536 } | 542 } |
| 537 | 543 |
| 538 void WebApkInstaller::OnCreatedSubDirAndSetPermissions( | 544 void WebApkInstaller::OnCreatedSubDirAndSetPermissions( |
| 539 const GURL& download_url, | 545 const GURL& download_url, |
| 540 const base::FilePath& output_dir) { | 546 const base::FilePath& output_dir) { |
| 541 if (output_dir.empty()) { | 547 if (output_dir.empty()) { |
| 542 OnFailure(); | 548 OnResult(WebApkInstallResult::FAILURE); |
| 543 return; | 549 return; |
| 544 } | 550 } |
| 545 | 551 |
| 546 DownloadWebApk(output_dir.AppendASCII(webapk_package_ + ".apk"), download_url, | 552 DownloadWebApk(output_dir.AppendASCII(webapk_package_ + ".apk"), download_url, |
| 547 true); | 553 true); |
| 548 } | 554 } |
| 549 | 555 |
| 550 void WebApkInstaller::DownloadWebApk(const base::FilePath& output_path, | 556 void WebApkInstaller::DownloadWebApk(const base::FilePath& output_path, |
| 551 const GURL& download_url, | 557 const GURL& download_url, |
| 552 bool retry_if_fails) { | 558 bool retry_if_fails) { |
| 553 timer_.Start( | 559 timer_.Start( |
| 554 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), | 560 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), |
| 555 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); | 561 base::Bind(&WebApkInstaller::OnResult, weak_ptr_factory_.GetWeakPtr(), |
| 562 WebApkInstallResult::FAILURE)); |
| 556 | 563 |
| 557 downloader_.reset(new FileDownloader( | 564 downloader_.reset(new FileDownloader( |
| 558 download_url, output_path, true, request_context_getter_, | 565 download_url, output_path, true, request_context_getter_, |
| 559 base::Bind(&WebApkInstaller::OnWebApkDownloaded, | 566 base::Bind(&WebApkInstaller::OnWebApkDownloaded, |
| 560 weak_ptr_factory_.GetWeakPtr(), output_path, download_url, | 567 weak_ptr_factory_.GetWeakPtr(), output_path, download_url, |
| 561 retry_if_fails), | 568 retry_if_fails), |
| 562 NO_TRAFFIC_ANNOTATION_YET)); | 569 NO_TRAFFIC_ANNOTATION_YET)); |
| 563 } | 570 } |
| 564 | 571 |
| 565 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, | 572 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, |
| 566 const GURL& download_url, | 573 const GURL& download_url, |
| 567 bool retry_if_fails, | 574 bool retry_if_fails, |
| 568 FileDownloader::Result result) { | 575 FileDownloader::Result result) { |
| 569 timer_.Stop(); | 576 timer_.Stop(); |
| 570 | 577 |
| 571 if (result != FileDownloader::DOWNLOADED) { | 578 if (result != FileDownloader::DOWNLOADED) { |
| 572 if (!retry_if_fails) { | 579 if (!retry_if_fails) { |
| 573 OnFailure(); | 580 OnResult(WebApkInstallResult::FAILURE); |
| 574 return; | 581 return; |
| 575 } | 582 } |
| 576 | 583 |
| 577 content::BrowserThread::PostDelayedTask( | 584 content::BrowserThread::PostDelayedTask( |
| 578 content::BrowserThread::UI, FROM_HERE, | 585 content::BrowserThread::UI, FROM_HERE, |
| 579 base::Bind(&WebApkInstaller::DownloadWebApk, | 586 base::Bind(&WebApkInstaller::DownloadWebApk, |
| 580 weak_ptr_factory_.GetWeakPtr(), file_path, download_url, | 587 weak_ptr_factory_.GetWeakPtr(), file_path, download_url, |
| 581 false), | 588 false), |
| 582 base::TimeDelta::FromSeconds(2)); | 589 base::TimeDelta::FromSeconds(2)); |
| 583 return; | 590 return; |
| 584 } | 591 } |
| 585 | 592 |
| 586 int posix_permissions = kWorldReadableFilePermission | | 593 int posix_permissions = kWorldReadableFilePermission | |
| 587 base::FILE_PERMISSION_WRITE_BY_USER | | 594 base::FILE_PERMISSION_WRITE_BY_USER | |
| 588 base::FILE_PERMISSION_EXECUTE_BY_USER; | 595 base::FILE_PERMISSION_EXECUTE_BY_USER; |
| 589 base::PostTaskAndReplyWithResult( | 596 base::PostTaskAndReplyWithResult( |
| 590 GetBackgroundTaskRunner().get(), FROM_HERE, | 597 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 591 base::Bind(&base::SetPosixFilePermissions, file_path, posix_permissions), | 598 base::Bind(&base::SetPosixFilePermissions, file_path, posix_permissions), |
| 592 base::Bind(&WebApkInstaller::OnWebApkMadeWorldReadable, | 599 base::Bind(&WebApkInstaller::OnWebApkMadeWorldReadable, |
| 593 weak_ptr_factory_.GetWeakPtr(), file_path)); | 600 weak_ptr_factory_.GetWeakPtr(), file_path)); |
| 594 } | 601 } |
| 595 | 602 |
| 596 void WebApkInstaller::OnWebApkMadeWorldReadable( | 603 void WebApkInstaller::OnWebApkMadeWorldReadable( |
| 597 const base::FilePath& file_path, | 604 const base::FilePath& file_path, |
| 598 bool change_permission_success) { | 605 bool change_permission_success) { |
| 599 if (!change_permission_success) { | 606 if (!change_permission_success) { |
| 600 OnFailure(); | 607 OnResult(WebApkInstallResult::FAILURE); |
| 601 return; | 608 return; |
| 602 } | 609 } |
| 603 | 610 |
| 604 JNIEnv* env = base::android::AttachCurrentThread(); | 611 JNIEnv* env = base::android::AttachCurrentThread(); |
| 605 base::android::ScopedJavaLocalRef<jstring> java_file_path = | 612 base::android::ScopedJavaLocalRef<jstring> java_file_path = |
| 606 base::android::ConvertUTF8ToJavaString(env, file_path.value()); | 613 base::android::ConvertUTF8ToJavaString(env, file_path.value()); |
| 607 if (task_type_ == INSTALL) { | 614 if (task_type_ == INSTALL) { |
| 608 base::android::ScopedJavaLocalRef<jstring> java_package_name = | 615 base::android::ScopedJavaLocalRef<jstring> java_package_name = |
| 609 base::android::ConvertUTF8ToJavaString(env, webapk_package_); | 616 base::android::ConvertUTF8ToJavaString(env, webapk_package_); |
| 610 InstallDownloadedWebApk(env, java_file_path, java_package_name); | 617 InstallDownloadedWebApk(env, java_file_path, java_package_name); |
| 611 } else if (task_type_ == UPDATE) { | 618 } else if (task_type_ == UPDATE) { |
| 612 UpdateUsingDownloadedWebApk(env, java_file_path); | 619 UpdateUsingDownloadedWebApk(env, java_file_path); |
| 613 } | 620 } |
| 614 } | 621 } |
| 615 | |
| 616 void WebApkInstaller::OnTimeout() { | |
| 617 OnFailure(); | |
| 618 } | |
| 619 | |
| 620 void WebApkInstaller::OnSuccess() { | |
| 621 finish_callback_.Run(true, relax_updates_, webapk_package_); | |
| 622 delete this; | |
| 623 } | |
| 624 | |
| 625 void WebApkInstaller::OnFailure() { | |
| 626 finish_callback_.Run(false, relax_updates_, webapk_package_); | |
| 627 delete this; | |
| 628 } | |
| OLD | NEW |