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 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(); |
| 427 downloader_.reset(); | |
|
pkotwicz
2016/10/03 21:30:56
I removed this from the diff.
It looks like base:
| |
| 419 | 428 |
| 420 if (result != FileDownloader::DOWNLOADED) { | 429 if (result != FileDownloader::DOWNLOADED) { |
| 421 OnFailure(); | 430 if (!retry_if_fails) { |
| 431 OnFailure(); | |
| 432 return; | |
| 433 } | |
| 434 | |
| 435 content::BrowserThread::PostDelayedTask( | |
| 436 content::BrowserThread::UI, FROM_HERE, | |
| 437 base::Bind(&WebApkInstaller::DownloadWebApk, | |
| 438 weak_ptr_factory_.GetWeakPtr(), | |
| 439 file_path, download_url, false), | |
| 440 base::TimeDelta::FromSeconds(2)); | |
| 422 return; | 441 return; |
| 423 } | 442 } |
| 424 | 443 |
| 425 int posix_permissions = kWorldReadableFilePermission | | 444 int posix_permissions = kWorldReadableFilePermission | |
| 426 base::FILE_PERMISSION_WRITE_BY_USER | | 445 base::FILE_PERMISSION_WRITE_BY_USER | |
| 427 base::FILE_PERMISSION_EXECUTE_BY_USER; | 446 base::FILE_PERMISSION_EXECUTE_BY_USER; |
| 428 base::PostTaskAndReplyWithResult( | 447 base::PostTaskAndReplyWithResult( |
| 429 GetBackgroundTaskRunner().get(), FROM_HERE, | 448 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 430 base::Bind(&base::SetPosixFilePermissions, file_path, posix_permissions), | 449 base::Bind(&base::SetPosixFilePermissions, file_path, posix_permissions), |
| 431 base::Bind(&WebApkInstaller::OnWebApkMadeWorldReadable, | 450 base::Bind(&WebApkInstaller::OnWebApkMadeWorldReadable, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 std::string webapk_package = webapk_package_; | 490 std::string webapk_package = webapk_package_; |
| 472 delete this; | 491 delete this; |
| 473 callback.Run(true, webapk_package); | 492 callback.Run(true, webapk_package); |
| 474 } | 493 } |
| 475 | 494 |
| 476 void WebApkInstaller::OnFailure() { | 495 void WebApkInstaller::OnFailure() { |
| 477 FinishCallback callback = finish_callback_; | 496 FinishCallback callback = finish_callback_; |
| 478 delete this; | 497 delete this; |
| 479 callback.Run(false, ""); | 498 callback.Run(false, ""); |
| 480 } | 499 } |
| OLD | NEW |