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

Side by Side Diff: chrome/browser/android/webapk/webapk_installer.cc

Issue 2263673003: Pass icon and icon murmur2 hash to WebApkInstaller when updating WebAPKs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/webapk/webapk_installer.h" 5 #include "chrome/browser/android/webapk/webapk_installer.h"
6 6
7 #include "base/android/build_info.h" 7 #include "base/android/build_info.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/path_utils.h" 10 #include "base/android/path_utils.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 DownloadAppIconAndComputeMurmur2Hash(); 177 DownloadAppIconAndComputeMurmur2Hash();
178 } 178 }
179 179
180 void WebApkInstaller::SetTimeoutMs(int timeout_ms) { 180 void WebApkInstaller::SetTimeoutMs(int timeout_ms) {
181 webapk_download_url_timeout_ms_ = timeout_ms; 181 webapk_download_url_timeout_ms_ = timeout_ms;
182 download_timeout_ms_ = timeout_ms; 182 download_timeout_ms_ = timeout_ms;
183 } 183 }
184 184
185 void WebApkInstaller::UpdateAsync(content::BrowserContext* browser_context, 185 void WebApkInstaller::UpdateAsync(content::BrowserContext* browser_context,
186 const FinishCallback& finish_callback, 186 const FinishCallback& finish_callback,
187 const std::string& icon_murmur2_hash,
187 const std::string& webapk_package, 188 const std::string& webapk_package,
188 int webapk_version) { 189 int webapk_version) {
189 UpdateAsyncWithURLRequestContextGetter( 190 UpdateAsyncWithURLRequestContextGetter(
190 Profile::FromBrowserContext(browser_context)->GetRequestContext(), 191 Profile::FromBrowserContext(browser_context)->GetRequestContext(),
191 finish_callback, webapk_package, webapk_version); 192 finish_callback, icon_murmur2_hash, webapk_package, webapk_version);
192 } 193 }
193 194
194 void WebApkInstaller::UpdateAsyncWithURLRequestContextGetter( 195 void WebApkInstaller::UpdateAsyncWithURLRequestContextGetter(
195 net::URLRequestContextGetter* request_context_getter, 196 net::URLRequestContextGetter* request_context_getter,
196 const FinishCallback& finish_callback, 197 const FinishCallback& finish_callback,
198 const std::string& icon_murmur2_hash,
197 const std::string& webapk_package, 199 const std::string& webapk_package,
198 int webapk_version) { 200 int webapk_version) {
199 request_context_getter_ = request_context_getter; 201 request_context_getter_ = request_context_getter;
200 finish_callback_ = finish_callback; 202 finish_callback_ = finish_callback;
203 shortcut_icon_murmur2_hash_ = icon_murmur2_hash;
201 webapk_package_ = webapk_package; 204 webapk_package_ = webapk_package;
202 webapk_version_ = webapk_version; 205 webapk_version_ = webapk_version;
203 task_type_ = UPDATE; 206 task_type_ = UPDATE;
204 207
pkotwicz 2016/08/19 23:38:17 The purpose of the check is to ensure that we do n
Xi Han 2016/08/26 17:54:08 Done.
205 if (!shortcut_info_.icon_url.is_valid()) { 208 if (!shortcut_info_.icon_url.is_valid()) {
206 OnFailure(); 209 OnFailure();
207 return; 210 return;
208 } 211 }
209 212
210 DownloadAppIconAndComputeMurmur2Hash(); 213 base::PostTaskAndReplyWithResult(
214 GetBackgroundTaskRunner().get(), FROM_HERE,
215 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_,
216 shortcut_icon_, shortcut_icon_murmur2_hash_),
217 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest,
218 weak_ptr_factory_.GetWeakPtr()));
211 } 219 }
212 220
213 bool WebApkInstaller::StartInstallingDownloadedWebApk( 221 bool WebApkInstaller::StartInstallingDownloadedWebApk(
214 JNIEnv* env, 222 JNIEnv* env,
215 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, 223 const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
216 const base::android::ScopedJavaLocalRef<jstring>& java_package_name) { 224 const base::android::ScopedJavaLocalRef<jstring>& java_package_name) {
217 return Java_WebApkInstaller_installAsyncFromNative(env, java_file_path, 225 return Java_WebApkInstaller_installAsyncFromNative(env, java_file_path,
218 java_package_name); 226 java_package_name);
219 } 227 }
220 228
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 icon_hasher_.reset(); 279 icon_hasher_.reset();
272 280
273 shortcut_icon_murmur2_hash_ = icon_murmur2_hash; 281 shortcut_icon_murmur2_hash_ = icon_murmur2_hash;
274 282
275 // An empty hash indicates that |icon_hasher_| encountered an error. 283 // An empty hash indicates that |icon_hasher_| encountered an error.
276 if (icon_murmur2_hash.empty()) { 284 if (icon_murmur2_hash.empty()) {
277 OnFailure(); 285 OnFailure();
278 return; 286 return;
279 } 287 }
280 288
281 if (task_type_ == INSTALL) { 289 base::PostTaskAndReplyWithResult(
282 base::PostTaskAndReplyWithResult( 290 GetBackgroundTaskRunner().get(), FROM_HERE,
283 GetBackgroundTaskRunner().get(), FROM_HERE, 291 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_,
284 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, 292 shortcut_icon_, shortcut_icon_murmur2_hash_),
285 shortcut_icon_, shortcut_icon_murmur2_hash_), 293 base::Bind(&WebApkInstaller::SendCreateWebApkRequest,
286 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, 294 weak_ptr_factory_.GetWeakPtr()));
287 weak_ptr_factory_.GetWeakPtr()));
288 } else if (task_type_ == UPDATE) {
289 base::PostTaskAndReplyWithResult(
290 GetBackgroundTaskRunner().get(), FROM_HERE,
291 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_,
292 shortcut_icon_, shortcut_icon_murmur2_hash_),
293 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest,
294 weak_ptr_factory_.GetWeakPtr()));
295 }
296 } 295 }
297 296
298 void WebApkInstaller::SendCreateWebApkRequest( 297 void WebApkInstaller::SendCreateWebApkRequest(
299 std::unique_ptr<webapk::WebApk> webapk) { 298 std::unique_ptr<webapk::WebApk> webapk) {
300 GURL server_url(server_url_.spec() + kDefaultWebApkServerUrlResponseType); 299 GURL server_url(server_url_.spec() + kDefaultWebApkServerUrlResponseType);
301 SendRequest(std::move(webapk), net::URLFetcher::POST, server_url); 300 SendRequest(std::move(webapk), net::URLFetcher::POST, server_url);
302 } 301 }
303 302
304 void WebApkInstaller::SendUpdateWebApkRequest( 303 void WebApkInstaller::SendUpdateWebApkRequest(
305 std::unique_ptr<webapk::WebApk> webapk) { 304 std::unique_ptr<webapk::WebApk> webapk) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 FinishCallback callback = finish_callback_; 401 FinishCallback callback = finish_callback_;
403 delete this; 402 delete this;
404 callback.Run(true); 403 callback.Run(true);
405 } 404 }
406 405
407 void WebApkInstaller::OnFailure() { 406 void WebApkInstaller::OnFailure() {
408 FinishCallback callback = finish_callback_; 407 FinishCallback callback = finish_callback_;
409 delete this; 408 delete this;
410 callback.Run(false); 409 callback.Run(false);
411 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698