Skip to content

Instantly share code, notes, and snippets.

@t4kemyh4nd
Created October 15, 2023 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t4kemyh4nd/3d73e706c0f86938721b2b5cab53d668 to your computer and use it in GitHub Desktop.
Save t4kemyh4nd/3d73e706c0f86938721b2b5cab53d668 to your computer and use it in GitHub Desktop.
void WebApkInstaller::OnURLLoaderComplete(
std::unique_ptr<std::string> response_body) {
timer_.Stop();
int response_code = -1;
if (loader_->ResponseInfo() && loader_->ResponseInfo()->headers)
response_code = loader_->ResponseInfo()->headers->response_code();
if (!response_body || response_code != net::HTTP_OK) {
LOG(WARNING) << base::StringPrintf(
"WebAPK server returned response code %d.", response_code);
OnResult(webapps::WebApkInstallResult::SERVER_ERROR);
return;
}
std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse);
if (!response_body || !response->ParseFromString(*response_body)) {
LOG(WARNING) << "WebAPK server did not return proto.";
OnResult(webapps::WebApkInstallResult::SERVER_ERROR);
return;
}
base::StringToInt(response->version(), &webapk_version_);
const std::string& token = response->token();
if (task_type_ == UPDATE && token.empty()) {
// https://crbug.com/680131. The server sends an empty URL if the server
// does not have a newer WebAPK to update to.
relax_updates_ = response->relax_updates();
OnResult(webapps::WebApkInstallResult::SUCCESS);
return;
}
if (token.empty() || response->package_name().empty()) {
LOG(WARNING) << "WebAPK server returned incomplete proto.";
OnResult(webapps::WebApkInstallResult::SERVER_ERROR);
return;
}
InstallOrUpdateWebApk(response->package_name(), token);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment