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 52b114e01d872686eb2a3762329e8965f3ae7a74..e2ad5ec3bbccdd804447a2056f7d68cd6cf2a61c 100644 |
--- a/chrome/browser/android/webapk/webapk_installer.cc |
+++ b/chrome/browser/android/webapk/webapk_installer.cc |
@@ -25,6 +25,7 @@ |
#include "jni/WebApkInstaller_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 "third_party/smhasher/src/MurmurHash2.h" |
#include "ui/gfx/codec/png_codec.h" |
#include "url/gurl.h" |
@@ -103,10 +104,12 @@ void WebApkInstaller::InstallAsync(content::BrowserContext* browser_context, |
// 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), browser_context)); |
+ base::Unretained(this), browser_context), |
+ base::Bind(&WebApkInstaller::SendCreateWebApkRequest, |
+ io_weak_ptr_factory_.GetWeakPtr())); |
} |
void WebApkInstaller::InstallAsyncWithURLRequestContextGetter( |
@@ -119,6 +122,25 @@ void WebApkInstaller::InstallAsyncWithURLRequestContextGetter( |
SendCreateWebApkRequest(); |
} |
+void WebApkInstaller::UpdateAsync(content::BrowserContext* browser_context, |
+ 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), browser_context), |
+ base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, |
+ io_weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
bool WebApkInstaller::StartDownloadedWebApkInstall( |
JNIEnv* env, |
const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
@@ -140,8 +162,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; |
@@ -162,18 +184,35 @@ void WebApkInstaller::InitializeRequestContextGetterOnUIThread( |
// Profile::GetRequestContext() 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, |
@@ -183,7 +222,7 @@ 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(); |
} |
@@ -211,8 +250,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(); |
@@ -235,12 +274,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()); |
@@ -270,8 +304,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() { |