Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5736)

Unified Diff: chrome/browser/android/webapk/webapk_installer.cc

Issue 2223443002: Fix WebApkInstaller so that it can talk to the server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_builder_impl3 Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/webapk/webapk_installer.cc
diff --git a/chrome/browser/android/webapk/webapk_installer.cc b/chrome/browser/android/webapk/webapk_installer.cc
index 645f84220524ed80767ec2c07154aee816358739..2322d478e9c00d9b13fb17c5aa65fc9935a45eba 100644
--- a/chrome/browser/android/webapk/webapk_installer.cc
+++ b/chrome/browser/android/webapk/webapk_installer.cc
@@ -12,6 +12,7 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -40,12 +41,13 @@ const char kProtoMimeType[] = "application/x-protobuf";
// The seed to use the murmur2 hash of the app icon.
const uint32_t kMurmur2HashSeed = 0;
-// The number of milliseconds to wait for the WebAPK download URL from the
-// WebAPK server.
-const int kWebApkDownloadUrlTimeoutMs = 4000;
+// The default number of milliseconds to wait for the WebAPK download URL from
+// the WebAPK server.
gone 2016/08/07 15:47:43 60 seconds is really long for just getting a downl
pkotwicz 2016/08/07 21:00:40 In practice the server takes 10 - 20 seconds. It f
+const int kWebApkDownloadUrlTimeoutMs = 60000;
-// The number of milliseconds to wait for the WebAPK download to complete.
-const int kDownloadTimeoutMs = 20000;
+// The default number of milliseconds to wait for the WebAPK download to
+// complete.
+const int kDownloadTimeoutMs = 60000;
// Returns the scope from |info| if it is specified. Otherwise, returns the
// default scope.
@@ -54,10 +56,12 @@ GURL GetScope(const ShortcutInfo& info) {
}
// Computes a murmur2 hash of |bitmap|'s PNG encoded bytes.
-uint64_t ComputeBitmapHash(const SkBitmap& bitmap) {
+std::string ComputeBitmapHash(const SkBitmap& bitmap) {
std::vector<unsigned char> png_bytes;
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_bytes);
- return MurmurHash64B(&png_bytes.front(), png_bytes.size(), kMurmur2HashSeed);
+ uint64_t hash =
+ MurmurHash64B(&png_bytes.front(), png_bytes.size(), kMurmur2HashSeed);
+ return base::Uint64ToString(hash);
}
// Converts a color from the format specified in content::Manifest to a CSS
@@ -80,6 +84,8 @@ WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info,
const SkBitmap& shortcut_icon)
: shortcut_info_(shortcut_info),
shortcut_icon_(shortcut_icon),
+ webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs),
+ download_timeout_ms_(kDownloadTimeoutMs),
io_weak_ptr_factory_(this) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
server_url_ =
@@ -113,6 +119,11 @@ void WebApkInstaller::InstallAsyncWithURLRequestContextGetter(
SendCreateWebApkRequest();
}
+void WebApkInstaller::SetTimeoutMs(int timeout_ms) {
+ webapk_download_url_timeout_ms_ = timeout_ms;
+ download_timeout_ms_ = timeout_ms;
+}
+
bool WebApkInstaller::StartDownloadedWebApkInstall(
JNIEnv* env,
const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
@@ -134,20 +145,19 @@ void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) {
std::string response_string;
source->GetResponseAsString(&response_string);
- std::unique_ptr<webapk::CreateWebApkResponse> response(
- new webapk::CreateWebApkResponse);
+ std::unique_ptr<webapk::WebApkResponse> response(
+ new webapk::WebApkResponse);
if (!response->ParseFromString(response_string)) {
OnFailure();
return;
}
- if (response->signed_download_url().empty() ||
- response->webapk_package_name().empty()) {
+ GURL signed_download_url(response->signed_download_url());
+ if (!signed_download_url.is_valid() || response->package_name().empty()) {
OnFailure();
return;
}
- OnGotWebApkDownloadUrl(response->signed_download_url(),
- response->webapk_package_name());
+ OnGotWebApkDownloadUrl(signed_download_url, response->package_name());
}
void WebApkInstaller::InitializeRequestContextGetterOnUIThread(
@@ -165,11 +175,10 @@ void WebApkInstaller::InitializeRequestContextGetterOnUIThread(
void WebApkInstaller::SendCreateWebApkRequest() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- std::unique_ptr<webapk::CreateWebApkRequest> request =
- BuildCreateWebApkRequest();
+ std::unique_ptr<webapk::WebApk> webapk_proto = BuildWebApkProto();
- timer_.Start(FROM_HERE,
- base::TimeDelta::FromMilliseconds(kWebApkDownloadUrlTimeoutMs),
+ timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(
+ webapk_download_url_timeout_ms_),
base::Bind(&WebApkInstaller::OnTimeout,
io_weak_ptr_factory_.GetWeakPtr()));
@@ -177,12 +186,12 @@ void WebApkInstaller::SendCreateWebApkRequest() {
net::URLFetcher::Create(server_url_, net::URLFetcher::POST, this);
url_fetcher_->SetRequestContext(request_context_getter_);
std::string serialized_request;
- request->SerializeToString(&serialized_request);
+ webapk_proto->SerializeToString(&serialized_request);
url_fetcher_->SetUploadData(kProtoMimeType, serialized_request);
url_fetcher_->Start();
}
-void WebApkInstaller::OnGotWebApkDownloadUrl(const std::string& download_url,
+void WebApkInstaller::OnGotWebApkDownloadUrl(const GURL& download_url,
const std::string& package_name) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
@@ -192,13 +201,14 @@ void WebApkInstaller::OnGotWebApkDownloadUrl(const std::string& download_url,
// directory.
// TODO(pkotwicz): Figure out when downloaded WebAPK should be deleted.
- timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kDownloadTimeoutMs),
+ timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(download_timeout_ms_),
base::Bind(&WebApkInstaller::OnTimeout,
io_weak_ptr_factory_.GetWeakPtr()));
base::FilePath output_path = output_dir.AppendASCII(package_name);
downloader_.reset(new FileDownloader(
- GURL(download_url), output_path, true, request_context_getter_,
+ download_url, output_path, true, request_context_getter_,
base::Bind(&WebApkInstaller::OnWebApkDownloaded,
io_weak_ptr_factory_.GetWeakPtr(), output_path,
package_name)));
@@ -229,12 +239,8 @@ void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path,
OnFailure();
}
-std::unique_ptr<webapk::CreateWebApkRequest>
-WebApkInstaller::BuildCreateWebApkRequest() {
- std::unique_ptr<webapk::CreateWebApkRequest> request(
- new webapk::CreateWebApkRequest);
-
- webapk::WebApk* webapk = request->mutable_webapk();
+std::unique_ptr<webapk::WebApk> WebApkInstaller::BuildWebApkProto() {
+ std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk);
webapk->set_manifest_url(shortcut_info_.manifest_url.spec());
webapk->set_requester_application_package(
base::android::BuildInfo::GetInstance()->package_name());
@@ -261,7 +267,7 @@ WebApkInstaller::BuildCreateWebApkRequest() {
gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon_, false, &png_bytes);
image->set_image_data(&png_bytes.front(), png_bytes.size());
- return request;
+ return webapk;
}
void WebApkInstaller::OnTimeout() {
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.h ('k') | chrome/browser/android/webapk/webapk_installer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698