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 weak_ptr_factory_.GetWeakPtr(), download_url)); | 395 weak_ptr_factory_.GetWeakPtr(), download_url)); |
396 } | 396 } |
397 | 397 |
398 void WebApkInstaller::OnCreatedSubDirAndSetPermissions( | 398 void WebApkInstaller::OnCreatedSubDirAndSetPermissions( |
399 const GURL& download_url, const base::FilePath& output_dir) { | 399 const GURL& download_url, const base::FilePath& output_dir) { |
400 if (output_dir.empty()) { | 400 if (output_dir.empty()) { |
401 OnFailure(); | 401 OnFailure(); |
402 return; | 402 return; |
403 } | 403 } |
404 | 404 |
| 405 DownloadWebApk(output_dir.AppendASCII(webapk_package_), download_url, true); |
| 406 } |
| 407 |
| 408 void WebApkInstaller::DownloadWebApk(const base::FilePath& output_path, |
| 409 const GURL& download_url, |
| 410 bool retry_if_fails) { |
405 timer_.Start( | 411 timer_.Start( |
406 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), | 412 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), |
407 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); | 413 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); |
408 | 414 |
409 base::FilePath output_path = output_dir.AppendASCII(webapk_package_); | |
410 downloader_.reset(new FileDownloader( | 415 downloader_.reset(new FileDownloader( |
411 download_url, output_path, true, request_context_getter_, | 416 download_url, output_path, true, request_context_getter_, |
412 base::Bind(&WebApkInstaller::OnWebApkDownloaded, | 417 base::Bind(&WebApkInstaller::OnWebApkDownloaded, |
413 weak_ptr_factory_.GetWeakPtr(), output_path))); | 418 weak_ptr_factory_.GetWeakPtr(), |
| 419 output_path, download_url, retry_if_fails))); |
414 } | 420 } |
415 | 421 |
416 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, | 422 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, |
| 423 const GURL& download_url, |
| 424 bool retry_if_fails, |
417 FileDownloader::Result result) { | 425 FileDownloader::Result result) { |
418 timer_.Stop(); | 426 timer_.Stop(); |
419 | 427 |
420 if (result != FileDownloader::DOWNLOADED) { | 428 if (result != FileDownloader::DOWNLOADED) { |
421 OnFailure(); | 429 if (!retry_if_fails) { |
| 430 OnFailure(); |
| 431 return; |
| 432 } |
| 433 |
| 434 content::BrowserThread::PostDelayedTask( |
| 435 content::BrowserThread::UI, FROM_HERE, |
| 436 base::Bind(&WebApkInstaller::DownloadWebApk, |
| 437 weak_ptr_factory_.GetWeakPtr(), |
| 438 file_path, download_url, false), |
| 439 base::TimeDelta::FromSeconds(2)); |
422 return; | 440 return; |
423 } | 441 } |
424 | 442 |
425 int posix_permissions = kWorldReadableFilePermission | | 443 int posix_permissions = kWorldReadableFilePermission | |
426 base::FILE_PERMISSION_WRITE_BY_USER | | 444 base::FILE_PERMISSION_WRITE_BY_USER | |
427 base::FILE_PERMISSION_EXECUTE_BY_USER; | 445 base::FILE_PERMISSION_EXECUTE_BY_USER; |
428 base::PostTaskAndReplyWithResult( | 446 base::PostTaskAndReplyWithResult( |
429 GetBackgroundTaskRunner().get(), FROM_HERE, | 447 GetBackgroundTaskRunner().get(), FROM_HERE, |
430 base::Bind(&base::SetPosixFilePermissions, file_path, posix_permissions), | 448 base::Bind(&base::SetPosixFilePermissions, file_path, posix_permissions), |
431 base::Bind(&WebApkInstaller::OnWebApkMadeWorldReadable, | 449 base::Bind(&WebApkInstaller::OnWebApkMadeWorldReadable, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 std::string webapk_package = webapk_package_; | 489 std::string webapk_package = webapk_package_; |
472 delete this; | 490 delete this; |
473 callback.Run(true, webapk_package); | 491 callback.Run(true, webapk_package); |
474 } | 492 } |
475 | 493 |
476 void WebApkInstaller::OnFailure() { | 494 void WebApkInstaller::OnFailure() { |
477 FinishCallback callback = finish_callback_; | 495 FinishCallback callback = finish_callback_; |
478 delete this; | 496 delete this; |
479 callback.Run(false, ""); | 497 callback.Run(false, ""); |
480 } | 498 } |
OLD | NEW |