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" |
| 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 webApkInstallResult) { |
| 275 if (success) | 276 OnResult(static_cast<WebApkInstallResult>(webApkInstallResult)); |
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 base::android::ScopedJavaLocalRef<jstring> java_token = | 319 base::android::ScopedJavaLocalRef<jstring> java_token = |
| 322 base::android::ConvertUTF8ToJavaString(env, token); | 320 base::android::ConvertUTF8ToJavaString(env, token); |
| 323 base::android::ScopedJavaLocalRef<jstring> java_url = | 321 base::android::ScopedJavaLocalRef<jstring> java_url = |
| 324 base::android::ConvertUTF8ToJavaString(env, shortcut_info_.url.spec()); | 322 base::android::ConvertUTF8ToJavaString(env, shortcut_info_.url.spec()); |
| 325 | 323 |
| 326 Java_WebApkInstaller_installOrUpdateWebApkFromGooglePlayAsync( | 324 Java_WebApkInstaller_installOrUpdateWebApkFromGooglePlayAsync( |
| 327 env, java_ref_, task_type_ == UPDATE, java_webapk_package, version, | 325 env, java_ref_, task_type_ == UPDATE, java_webapk_package, version, |
| 328 java_title, java_token, java_url); | 326 java_title, java_token, java_url); |
| 329 } | 327 } |
| 330 | 328 |
| 329 void WebApkInstaller::OnResult(WebApkInstallResult result) { | |
| 330 finish_callback_.Run(result, relax_updates_, webapk_package_); | |
|
dominickn
2017/03/13 03:22:24
Nit: this should call weak_ptr_factory_.Invalidate
pkotwicz
2017/03/14 22:38:57
Doesn't the destructor call WeakPtrFactory::Invali
dominickn
2017/03/14 23:25:19
Yes, but finish_callback_ could potentially be bou
pkotwicz
2017/03/14 23:43:29
Fair enough
| |
| 331 delete this; | |
| 332 } | |
| 333 | |
| 331 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, | 334 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, |
| 332 const ShortcutInfo& shortcut_info, | 335 const ShortcutInfo& shortcut_info, |
| 333 const SkBitmap& shortcut_icon) | 336 const SkBitmap& shortcut_icon) |
| 334 : request_context_getter_( | 337 : request_context_getter_( |
| 335 Profile::FromBrowserContext(browser_context)->GetRequestContext()), | 338 Profile::FromBrowserContext(browser_context)->GetRequestContext()), |
| 336 shortcut_info_(shortcut_info), | 339 shortcut_info_(shortcut_info), |
| 337 shortcut_icon_(shortcut_icon), | 340 shortcut_icon_(shortcut_icon), |
| 338 server_url_(GetServerUrl()), | 341 server_url_(GetServerUrl()), |
| 339 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), | 342 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), |
| 340 download_timeout_ms_(kDownloadTimeoutMs), | 343 download_timeout_ms_(kDownloadTimeoutMs), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 weak_ptr_factory_.GetWeakPtr())); | 388 weak_ptr_factory_.GetWeakPtr())); |
| 386 } | 389 } |
| 387 | 390 |
| 388 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { | 391 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { |
| 389 timer_.Stop(); | 392 timer_.Stop(); |
| 390 | 393 |
| 391 if (!source->GetStatus().is_success() || | 394 if (!source->GetStatus().is_success() || |
| 392 source->GetResponseCode() != net::HTTP_OK) { | 395 source->GetResponseCode() != net::HTTP_OK) { |
| 393 LOG(WARNING) << base::StringPrintf( | 396 LOG(WARNING) << base::StringPrintf( |
| 394 "WebAPK server returned response code %d.", source->GetResponseCode()); | 397 "WebAPK server returned response code %d.", source->GetResponseCode()); |
| 395 OnFailure(); | 398 OnResult(WebApkInstallResult::FAILURE); |
| 396 return; | 399 return; |
| 397 } | 400 } |
| 398 | 401 |
| 399 std::string response_string; | 402 std::string response_string; |
| 400 source->GetResponseAsString(&response_string); | 403 source->GetResponseAsString(&response_string); |
| 401 | 404 |
| 402 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); | 405 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); |
| 403 if (!response->ParseFromString(response_string)) { | 406 if (!response->ParseFromString(response_string)) { |
| 404 LOG(WARNING) << "WebAPK server did not return proto."; | 407 LOG(WARNING) << "WebAPK server did not return proto."; |
| 405 OnFailure(); | 408 OnResult(WebApkInstallResult::FAILURE); |
| 406 return; | 409 return; |
| 407 } | 410 } |
| 408 | 411 |
| 409 GURL signed_download_url(response->signed_download_url()); | 412 GURL signed_download_url(response->signed_download_url()); |
| 410 if (task_type_ == UPDATE && signed_download_url.is_empty()) { | 413 if (task_type_ == UPDATE && signed_download_url.is_empty()) { |
| 411 // https://crbug.com/680131. The server sends an empty URL if the server | 414 // https://crbug.com/680131. The server sends an empty URL if the server |
| 412 // does not have a newer WebAPK to update to. | 415 // does not have a newer WebAPK to update to. |
| 413 relax_updates_ = response->relax_updates(); | 416 relax_updates_ = response->relax_updates(); |
| 414 OnSuccess(); | 417 OnResult(WebApkInstallResult::SUCCESS); |
| 415 return; | 418 return; |
| 416 } | 419 } |
| 417 | 420 |
| 418 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 421 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
| 419 LOG(WARNING) << "WebAPK server returned incomplete proto."; | 422 LOG(WARNING) << "WebAPK server returned incomplete proto."; |
| 420 OnFailure(); | 423 OnResult(WebApkInstallResult::FAILURE); |
| 421 return; | 424 return; |
| 422 } | 425 } |
| 423 | 426 |
| 424 if (CanUseGooglePlayInstallService()) { | 427 if (CanUseGooglePlayInstallService()) { |
| 425 int version = 1; | 428 int version = 1; |
| 426 base::StringToInt(response->version(), &version); | 429 base::StringToInt(response->version(), &version); |
| 427 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, | 430 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, |
| 428 response->token()); | 431 response->token()); |
| 429 return; | 432 return; |
| 430 } | 433 } |
| 431 | 434 |
| 432 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); | 435 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); |
| 433 } | 436 } |
| 434 | 437 |
| 435 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { | 438 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { |
| 436 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. | 439 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. |
| 437 if (!shortcut_info_.best_primary_icon_url.is_valid()) { | 440 if (!shortcut_info_.best_primary_icon_url.is_valid()) { |
| 438 OnFailure(); | 441 OnResult(WebApkInstallResult::FAILURE); |
| 439 return; | 442 return; |
| 440 } | 443 } |
| 441 | 444 |
| 442 timer_.Start( | 445 timer_.Start( |
| 443 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), | 446 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), |
| 444 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); | 447 base::Bind(&WebApkInstaller::OnResult, weak_ptr_factory_.GetWeakPtr(), |
| 448 WebApkInstallResult::FAILURE)); | |
| 445 | 449 |
| 446 icon_hasher_.reset(new WebApkIconHasher()); | 450 icon_hasher_.reset(new WebApkIconHasher()); |
| 447 icon_hasher_->DownloadAndComputeMurmur2Hash( | 451 icon_hasher_->DownloadAndComputeMurmur2Hash( |
| 448 request_context_getter_, shortcut_info_.best_primary_icon_url, | 452 request_context_getter_, shortcut_info_.best_primary_icon_url, |
| 449 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, | 453 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, |
| 450 weak_ptr_factory_.GetWeakPtr())); | 454 weak_ptr_factory_.GetWeakPtr())); |
| 451 } | 455 } |
| 452 | 456 |
| 453 void WebApkInstaller::OnGotIconMurmur2Hash( | 457 void WebApkInstaller::OnGotIconMurmur2Hash( |
| 454 const std::string& icon_murmur2_hash) { | 458 const std::string& icon_murmur2_hash) { |
| 455 timer_.Stop(); | 459 timer_.Stop(); |
| 456 icon_hasher_.reset(); | 460 icon_hasher_.reset(); |
| 457 | 461 |
| 458 // An empty hash indicates that |icon_hasher_| encountered an error. | 462 // An empty hash indicates that |icon_hasher_| encountered an error. |
| 459 if (icon_murmur2_hash.empty()) { | 463 if (icon_murmur2_hash.empty()) { |
| 460 OnFailure(); | 464 OnResult(WebApkInstallResult::FAILURE); |
| 461 return; | 465 return; |
| 462 } | 466 } |
| 463 | 467 |
| 464 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 468 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
| 465 for (const std::string& icon_url : shortcut_info_.icon_urls) { | 469 for (const std::string& icon_url : shortcut_info_.icon_urls) { |
| 466 if (icon_url != shortcut_info_.best_primary_icon_url.spec()) | 470 if (icon_url != shortcut_info_.best_primary_icon_url.spec()) |
| 467 icon_url_to_murmur2_hash[icon_url] = ""; | 471 icon_url_to_murmur2_hash[icon_url] = ""; |
| 468 else | 472 else |
| 469 icon_url_to_murmur2_hash[icon_url] = icon_murmur2_hash; | 473 icon_url_to_murmur2_hash[icon_url] = icon_murmur2_hash; |
| 470 } | 474 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 488 webapk->set_version(std::to_string(webapk_version_)); | 492 webapk->set_version(std::to_string(webapk_version_)); |
| 489 | 493 |
| 490 SendRequest(std::move(webapk), server_url_); | 494 SendRequest(std::move(webapk), server_url_); |
| 491 } | 495 } |
| 492 | 496 |
| 493 void WebApkInstaller::SendRequest(std::unique_ptr<webapk::WebApk> request_proto, | 497 void WebApkInstaller::SendRequest(std::unique_ptr<webapk::WebApk> request_proto, |
| 494 const GURL& server_url) { | 498 const GURL& server_url) { |
| 495 timer_.Start( | 499 timer_.Start( |
| 496 FROM_HERE, | 500 FROM_HERE, |
| 497 base::TimeDelta::FromMilliseconds(webapk_download_url_timeout_ms_), | 501 base::TimeDelta::FromMilliseconds(webapk_download_url_timeout_ms_), |
| 498 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); | 502 base::Bind(&WebApkInstaller::OnResult, weak_ptr_factory_.GetWeakPtr(), |
| 503 WebApkInstallResult::FAILURE)); | |
| 499 | 504 |
| 500 url_fetcher_ = | 505 url_fetcher_ = |
| 501 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); | 506 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); |
| 502 url_fetcher_->SetRequestContext(request_context_getter_); | 507 url_fetcher_->SetRequestContext(request_context_getter_); |
| 503 std::string serialized_request; | 508 std::string serialized_request; |
| 504 request_proto->SerializeToString(&serialized_request); | 509 request_proto->SerializeToString(&serialized_request); |
| 505 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); | 510 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); |
| 506 url_fetcher_->SetLoadFlags( | 511 url_fetcher_->SetLoadFlags( |
| 507 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES | | 512 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES | |
| 508 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); | 513 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 519 task_type_ == WebApkInstaller::INSTALL ? "install" : "update", | 524 task_type_ == WebApkInstaller::INSTALL ? "install" : "update", |
| 520 package_name), | 525 package_name), |
| 521 base::Bind(&WebApkInstaller::OnCreatedSubDirAndSetPermissions, | 526 base::Bind(&WebApkInstaller::OnCreatedSubDirAndSetPermissions, |
| 522 weak_ptr_factory_.GetWeakPtr(), download_url)); | 527 weak_ptr_factory_.GetWeakPtr(), download_url)); |
| 523 } | 528 } |
| 524 | 529 |
| 525 void WebApkInstaller::OnCreatedSubDirAndSetPermissions( | 530 void WebApkInstaller::OnCreatedSubDirAndSetPermissions( |
| 526 const GURL& download_url, | 531 const GURL& download_url, |
| 527 const base::FilePath& output_dir) { | 532 const base::FilePath& output_dir) { |
| 528 if (output_dir.empty()) { | 533 if (output_dir.empty()) { |
| 529 OnFailure(); | 534 OnResult(WebApkInstallResult::FAILURE); |
| 530 return; | 535 return; |
| 531 } | 536 } |
| 532 | 537 |
| 533 DownloadWebApk(output_dir.AppendASCII(webapk_package_ + ".apk"), download_url, | 538 DownloadWebApk(output_dir.AppendASCII(webapk_package_ + ".apk"), download_url, |
| 534 true); | 539 true); |
| 535 } | 540 } |
| 536 | 541 |
| 537 void WebApkInstaller::DownloadWebApk(const base::FilePath& output_path, | 542 void WebApkInstaller::DownloadWebApk(const base::FilePath& output_path, |
| 538 const GURL& download_url, | 543 const GURL& download_url, |
| 539 bool retry_if_fails) { | 544 bool retry_if_fails) { |
| 540 timer_.Start( | 545 timer_.Start( |
| 541 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), | 546 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), |
| 542 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); | 547 base::Bind(&WebApkInstaller::OnResult, weak_ptr_factory_.GetWeakPtr(), |
| 548 WebApkInstallResult::FAILURE)); | |
| 543 | 549 |
| 544 downloader_.reset(new FileDownloader( | 550 downloader_.reset(new FileDownloader( |
| 545 download_url, output_path, true, request_context_getter_, | 551 download_url, output_path, true, request_context_getter_, |
| 546 base::Bind(&WebApkInstaller::OnWebApkDownloaded, | 552 base::Bind(&WebApkInstaller::OnWebApkDownloaded, |
| 547 weak_ptr_factory_.GetWeakPtr(), output_path, download_url, | 553 weak_ptr_factory_.GetWeakPtr(), output_path, download_url, |
| 548 retry_if_fails), | 554 retry_if_fails), |
| 549 NO_TRAFFIC_ANNOTATION_YET)); | 555 NO_TRAFFIC_ANNOTATION_YET)); |
| 550 } | 556 } |
| 551 | 557 |
| 552 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, | 558 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, |
| 553 const GURL& download_url, | 559 const GURL& download_url, |
| 554 bool retry_if_fails, | 560 bool retry_if_fails, |
| 555 FileDownloader::Result result) { | 561 FileDownloader::Result result) { |
| 556 timer_.Stop(); | 562 timer_.Stop(); |
| 557 | 563 |
| 558 if (result != FileDownloader::DOWNLOADED) { | 564 if (result != FileDownloader::DOWNLOADED) { |
| 559 if (!retry_if_fails) { | 565 if (!retry_if_fails) { |
| 560 OnFailure(); | 566 OnResult(WebApkInstallResult::FAILURE); |
| 561 return; | 567 return; |
| 562 } | 568 } |
| 563 | 569 |
| 564 content::BrowserThread::PostDelayedTask( | 570 content::BrowserThread::PostDelayedTask( |
| 565 content::BrowserThread::UI, FROM_HERE, | 571 content::BrowserThread::UI, FROM_HERE, |
| 566 base::Bind(&WebApkInstaller::DownloadWebApk, | 572 base::Bind(&WebApkInstaller::DownloadWebApk, |
| 567 weak_ptr_factory_.GetWeakPtr(), file_path, download_url, | 573 weak_ptr_factory_.GetWeakPtr(), file_path, download_url, |
| 568 false), | 574 false), |
| 569 base::TimeDelta::FromSeconds(2)); | 575 base::TimeDelta::FromSeconds(2)); |
| 570 return; | 576 return; |
| 571 } | 577 } |
| 572 | 578 |
| 573 int posix_permissions = kWorldReadableFilePermission | | 579 int posix_permissions = kWorldReadableFilePermission | |
| 574 base::FILE_PERMISSION_WRITE_BY_USER | | 580 base::FILE_PERMISSION_WRITE_BY_USER | |
| 575 base::FILE_PERMISSION_EXECUTE_BY_USER; | 581 base::FILE_PERMISSION_EXECUTE_BY_USER; |
| 576 base::PostTaskAndReplyWithResult( | 582 base::PostTaskAndReplyWithResult( |
| 577 GetBackgroundTaskRunner().get(), FROM_HERE, | 583 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 578 base::Bind(&base::SetPosixFilePermissions, file_path, posix_permissions), | 584 base::Bind(&base::SetPosixFilePermissions, file_path, posix_permissions), |
| 579 base::Bind(&WebApkInstaller::OnWebApkMadeWorldReadable, | 585 base::Bind(&WebApkInstaller::OnWebApkMadeWorldReadable, |
| 580 weak_ptr_factory_.GetWeakPtr(), file_path)); | 586 weak_ptr_factory_.GetWeakPtr(), file_path)); |
| 581 } | 587 } |
| 582 | 588 |
| 583 void WebApkInstaller::OnWebApkMadeWorldReadable( | 589 void WebApkInstaller::OnWebApkMadeWorldReadable( |
| 584 const base::FilePath& file_path, | 590 const base::FilePath& file_path, |
| 585 bool change_permission_success) { | 591 bool change_permission_success) { |
| 586 if (!change_permission_success) { | 592 if (!change_permission_success) { |
| 587 OnFailure(); | 593 OnResult(WebApkInstallResult::FAILURE); |
| 588 return; | 594 return; |
| 589 } | 595 } |
| 590 | 596 |
| 591 JNIEnv* env = base::android::AttachCurrentThread(); | 597 JNIEnv* env = base::android::AttachCurrentThread(); |
| 592 base::android::ScopedJavaLocalRef<jstring> java_file_path = | 598 base::android::ScopedJavaLocalRef<jstring> java_file_path = |
| 593 base::android::ConvertUTF8ToJavaString(env, file_path.value()); | 599 base::android::ConvertUTF8ToJavaString(env, file_path.value()); |
| 594 base::android::ScopedJavaLocalRef<jstring> java_package_name = | 600 base::android::ScopedJavaLocalRef<jstring> java_package_name = |
| 595 base::android::ConvertUTF8ToJavaString(env, webapk_package_); | 601 base::android::ConvertUTF8ToJavaString(env, webapk_package_); |
| 596 InstallOrUpdateDownloadedWebApk(env, java_file_path, java_package_name); | 602 InstallOrUpdateDownloadedWebApk(env, java_file_path, java_package_name); |
| 597 } | 603 } |
| 598 | |
| 599 void WebApkInstaller::OnTimeout() { | |
| 600 OnFailure(); | |
| 601 } | |
| 602 | |
| 603 void WebApkInstaller::OnSuccess() { | |
| 604 finish_callback_.Run(true, relax_updates_, webapk_package_); | |
| 605 delete this; | |
| 606 } | |
| 607 | |
| 608 void WebApkInstaller::OnFailure() { | |
| 609 finish_callback_.Run(false, relax_updates_, webapk_package_); | |
| 610 delete this; | |
| 611 } | |
| OLD | NEW |