Commit ace8dc83 authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Retry WebAPK download if fails for the first time.

The WebAPK server may send us the URL of the WebAPK to download prior to the
WebAPK being available at that URL. WebApkInstaller will sleep 2 seconds and
retry the download if the download fails.

BUG=649704
TBR=dfalcantara

Review-Url: https://codereview.chromium.org/2381023003
Cr-Commit-Position: refs/heads/master@{#422583}
parent 2bf5588f
...@@ -402,23 +402,41 @@ void WebApkInstaller::OnCreatedSubDirAndSetPermissions( ...@@ -402,23 +402,41 @@ void WebApkInstaller::OnCreatedSubDirAndSetPermissions(
return; return;
} }
DownloadWebApk(output_dir.AppendASCII(webapk_package_), download_url, true);
}
void WebApkInstaller::DownloadWebApk(const base::FilePath& output_path,
const GURL& download_url,
bool retry_if_fails) {
timer_.Start( timer_.Start(
FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_),
base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr()));
base::FilePath output_path = output_dir.AppendASCII(webapk_package_);
downloader_.reset(new FileDownloader( downloader_.reset(new FileDownloader(
download_url, output_path, true, request_context_getter_, download_url, output_path, true, request_context_getter_,
base::Bind(&WebApkInstaller::OnWebApkDownloaded, base::Bind(&WebApkInstaller::OnWebApkDownloaded,
weak_ptr_factory_.GetWeakPtr(), output_path))); weak_ptr_factory_.GetWeakPtr(),
output_path, download_url, retry_if_fails)));
} }
void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path,
const GURL& download_url,
bool retry_if_fails,
FileDownloader::Result result) { FileDownloader::Result result) {
timer_.Stop(); timer_.Stop();
if (result != FileDownloader::DOWNLOADED) { if (result != FileDownloader::DOWNLOADED) {
OnFailure(); if (!retry_if_fails) {
OnFailure();
return;
}
content::BrowserThread::PostDelayedTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&WebApkInstaller::DownloadWebApk,
weak_ptr_factory_.GetWeakPtr(),
file_path, download_url, false),
base::TimeDelta::FromSeconds(2));
return; return;
} }
......
...@@ -149,6 +149,11 @@ class WebApkInstaller : public net::URLFetcherDelegate { ...@@ -149,6 +149,11 @@ class WebApkInstaller : public net::URLFetcherDelegate {
void OnGotWebApkDownloadUrl(const GURL& download_url, void OnGotWebApkDownloadUrl(const GURL& download_url,
const std::string& package_name); const std::string& package_name);
// Downloads the WebAPK from the given |download_url|.
void DownloadWebApk(const base::FilePath& output_path,
const GURL& download_url,
bool retry_if_fails);
// Called once the sub directory to store the downloaded WebAPK was // Called once the sub directory to store the downloaded WebAPK was
// created with permissions set properly or if creation failed. // created with permissions set properly or if creation failed.
void OnCreatedSubDirAndSetPermissions(const GURL& download_url, void OnCreatedSubDirAndSetPermissions(const GURL& download_url,
...@@ -157,7 +162,11 @@ class WebApkInstaller : public net::URLFetcherDelegate { ...@@ -157,7 +162,11 @@ class WebApkInstaller : public net::URLFetcherDelegate {
// Called once the WebAPK has been downloaded. Makes the downloaded WebAPK // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK
// world readable and installs the WebAPK if the download was successful. // world readable and installs the WebAPK if the download was successful.
// |file_path| is the file path that the WebAPK was downloaded to. // |file_path| is the file path that the WebAPK was downloaded to.
// If |retry_if_fails| is true, will post a delayed task and retry the
// download after 2 seconds.
void OnWebApkDownloaded(const base::FilePath& file_path, void OnWebApkDownloaded(const base::FilePath& file_path,
const GURL& download_url,
bool retry_if_fails,
FileDownloader::Result result); FileDownloader::Result result);
// Called once the downloaded WebAPK has been made world readable. Installs // Called once the downloaded WebAPK has been made world readable. Installs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment