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 5acb396200b16497b01c67f7013a7d2722cc105c..47638d0717795a4275534a99889ad13c3aa18f4e 100644 |
--- a/chrome/browser/android/webapk/webapk_installer.cc |
+++ b/chrome/browser/android/webapk/webapk_installer.cc |
@@ -25,6 +25,7 @@ |
#include "jni/WebApkInstallerBridge_jni.h" |
#include "net/http/http_status_code.h" |
#include "net/url_request/url_fetcher.h" |
+#include "third_party/protobuf/src/google/protobuf/message_lite.h" |
#include "ui/gfx/codec/png_codec.h" |
#include "url/gurl.h" |
@@ -102,10 +103,30 @@ void WebApkInstaller::InstallAsync(const FinishCallback& finish_callback) { |
// base::Unretained() is safe because WebApkInstaller owns itself and does not |
// start the timeout timer till after |
// InitializeRequestContextGetterOnUIThread() is called. |
- content::BrowserThread::PostTask( |
+ content::BrowserThread::PostTaskAndReply( |
content::BrowserThread::UI, FROM_HERE, |
base::Bind(&WebApkInstaller::InitializeRequestContextGetterOnUIThread, |
- base::Unretained(this))); |
+ base::Unretained(this)), |
+ base::Bind(&WebApkInstaller::SendCreateWebApkRequest, |
+ io_weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
+void WebApkInstaller::UpdateAsync(const FinishCallback& finish_callback, |
+ const std::string& webapk_package, |
+ int version) { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
+ finish_callback_ = finish_callback; |
+ webapk_package_ = webapk_package; |
+ version_ = version; |
+ // base::Unretained() is safe because WebApkInstaller owns itself and does not |
+ // start the timeout timer till after |
+ // InitializeRequestContextGetterOnUIThread() is called. |
+ content::BrowserThread::PostTaskAndReply( |
+ content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&WebApkInstaller::InitializeRequestContextGetterOnUIThread, |
+ base::Unretained(this)), |
+ base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, |
+ io_weak_ptr_factory_.GetWeakPtr())); |
} |
void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { |
@@ -121,8 +142,8 @@ 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; |
@@ -142,18 +163,35 @@ void WebApkInstaller::InitializeRequestContextGetterOnUIThread() { |
// Must be called on UI thread. |
request_context_getter_ = |
Profile::FromBrowserContext(browser_context_)->GetRequestContext(); |
- |
- content::BrowserThread::PostTask( |
- content::BrowserThread::IO, FROM_HERE, |
- base::Bind(&WebApkInstaller::SendCreateWebApkRequest, |
- io_weak_ptr_factory_.GetWeakPtr())); |
} |
void WebApkInstaller::SendCreateWebApkRequest() { |
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
- std::unique_ptr<webapk::CreateWebApkRequest> request = |
- BuildCreateWebApkRequest(); |
+ std::unique_ptr<webapk::CreateWebApkRequest> request |
+ = std::unique_ptr<webapk::CreateWebApkRequest>( |
+ new webapk::CreateWebApkRequest); |
+ |
+ PopulateWebApkProto(request->mutable_webapk()); |
+ SendRequest(std::move(request)); |
+} |
+ |
+void WebApkInstaller::SendUpdateWebApkRequest() { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
+ |
+ std::unique_ptr<webapk::UpdateWebApkRequest> request |
+ = std::unique_ptr<webapk::UpdateWebApkRequest>( |
+ new webapk::UpdateWebApkRequest); |
+ |
+ webapk::WebApk* webapk = request->mutable_webapk(); |
+ PopulateWebApkProto(webapk); |
+ webapk->set_package_name(webapk_package_); |
+ webapk->set_version(std::to_string(version_)); |
+ SendRequest(std::move(request)); |
+} |
+ |
+void WebApkInstaller::SendRequest( |
+ std::unique_ptr<::google::protobuf::MessageLite> request_proto) { |
timer_.Start(FROM_HERE, |
base::TimeDelta::FromMilliseconds(kWebApkDownloadUrlTimeoutMs), |
base::Bind(&WebApkInstaller::OnTimeout, |
@@ -163,13 +201,13 @@ 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); |
+ request_proto->SerializeToString(&serialized_request); |
url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); |
url_fetcher_->Start(); |
} |
void WebApkInstaller::OnGotWebApkDownloadUrl(const std::string& download_url, |
- const std::string& package_name) { |
+ const std::string& package_name) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
base::FilePath output_dir; |
@@ -191,8 +229,8 @@ void WebApkInstaller::OnGotWebApkDownloadUrl(const std::string& download_url, |
} |
void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, |
- const std::string& package_name, |
- FileDownloader::Result result) { |
+ const std::string& package_name, |
+ FileDownloader::Result result) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
timer_.Stop(); |
@@ -215,12 +253,7 @@ 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(); |
+void WebApkInstaller::PopulateWebApkProto(webapk::WebApk* webapk) { |
webapk->set_manifest_url(shortcut_info_.manifest_url.spec()); |
webapk->set_requester_application_package( |
base::android::BuildInfo::GetInstance()->package_name()); |
@@ -250,8 +283,6 @@ WebApkInstaller::BuildCreateWebApkRequest() { |
std::vector<unsigned char> png_bytes; |
gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon_, false, &png_bytes); |
image->set_image_data(&png_bytes.front(), png_bytes.size()); |
- |
- return request; |
} |
void WebApkInstaller::OnTimeout() { |