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

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

Issue 2515293004: Chrome talks to Play to install WebAPKs. (Closed)
Patch Set: Upload the missing GooglePlayWebApkInstallDelegate. Created 4 years 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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
20 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
21 #include "chrome/browser/android/shortcut_helper.h" 22 #include "chrome/browser/android/shortcut_helper.h"
22 #include "chrome/browser/android/webapk/webapk.pb.h" 23 #include "chrome/browser/android/webapk/webapk.pb.h"
23 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" 24 #include "chrome/browser/android/webapk/webapk_icon_hasher.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 env, java_ref_, java_file_path, java_package_name); 309 env, java_ref_, java_file_path, java_package_name);
309 } 310 }
310 311
311 bool WebApkInstaller::StartUpdateUsingDownloadedWebApk( 312 bool WebApkInstaller::StartUpdateUsingDownloadedWebApk(
312 JNIEnv* env, 313 JNIEnv* env,
313 const base::android::ScopedJavaLocalRef<jstring>& java_file_path) { 314 const base::android::ScopedJavaLocalRef<jstring>& java_file_path) {
314 return Java_WebApkInstaller_updateAsyncFromNative( 315 return Java_WebApkInstaller_updateAsyncFromNative(
315 env, java_ref_, java_file_path); 316 env, java_ref_, java_file_path);
316 } 317 }
317 318
319 bool WebApkInstaller::HasGooglePlayWebApkInstallDelegate() {
320 JNIEnv* env = base::android::AttachCurrentThread();
321 return Java_WebApkInstaller_hasGooglePlayWebApkInstallDelegate(
322 env, java_ref_);
323 }
324
325 bool WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay(
326 const std::string& package_name,
327 int version,
328 const std::string& token) {
329 webapk_package_ = package_name;
330
331 JNIEnv* env = base::android::AttachCurrentThread();
332 base::android::ScopedJavaLocalRef<jstring> java_webapk_package =
333 base::android::ConvertUTF8ToJavaString(env, webapk_package_);
334 base::android::ScopedJavaLocalRef<jstring> java_title =
335 base::android::ConvertUTF16ToJavaString(env, shortcut_info_.user_title);
336 base::android::ScopedJavaLocalRef<jstring> java_token =
337 base::android::ConvertUTF8ToJavaString(env, token);
338
339 if (task_type_ == WebApkInstaller::INSTALL) {
340 return Java_WebApkInstaller_installWebApkFromGooglePlayAsync(
341 env, java_ref_, java_webapk_package, version, java_title, java_token);
342 } else {
343 return Java_WebApkInstaller_updateAsyncFromGooglePlay(
344 env, java_ref_, java_webapk_package, version, java_title, java_token);
345 }
346 }
347
318 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { 348 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) {
319 timer_.Stop(); 349 timer_.Stop();
320 350
321 if (!source->GetStatus().is_success() || 351 if (!source->GetStatus().is_success() ||
322 source->GetResponseCode() != net::HTTP_OK) { 352 source->GetResponseCode() != net::HTTP_OK) {
323 OnFailure(); 353 OnFailure();
324 return; 354 return;
325 } 355 }
326 356
327 std::string response_string; 357 std::string response_string;
328 source->GetResponseAsString(&response_string); 358 source->GetResponseAsString(&response_string);
329 359
330 std::unique_ptr<webapk::WebApkResponse> response( 360 std::unique_ptr<webapk::WebApkResponse> response(
331 new webapk::WebApkResponse); 361 new webapk::WebApkResponse);
332 if (!response->ParseFromString(response_string)) { 362 if (!response->ParseFromString(response_string)) {
333 OnFailure(); 363 OnFailure();
334 return; 364 return;
335 } 365 }
336 366
337 GURL signed_download_url(response->signed_download_url()); 367 GURL signed_download_url(response->signed_download_url());
338 if (!signed_download_url.is_valid() || response->package_name().empty()) { 368 if (!signed_download_url.is_valid() || response->package_name().empty()) {
339 OnFailure(); 369 OnFailure();
340 return; 370 return;
341 } 371 }
372
373 if (HasGooglePlayWebApkInstallDelegate()) {
374 int version = 1;
dominickn 2016/12/08 03:31:26 Set this to 0 by default, and check the return val
Xi Han 2016/12/08 18:03:07 Good catch, but maybe we still want to continue th
375 base::StringToInt(response->version(), &version);
376 if (!InstallOrUpdateWebApkFromGooglePlay(
377 response->package_name(), version, response->token())) {
378 OnFailure();
379 }
380 return;
381 }
382
342 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); 383 OnGotWebApkDownloadUrl(signed_download_url, response->package_name());
343 } 384 }
344 385
345 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { 386 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() {
346 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. 387 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL.
347 if (!shortcut_info_.best_icon_url.is_valid()) { 388 if (!shortcut_info_.best_icon_url.is_valid()) {
348 OnFailure(); 389 OnFailure();
349 return; 390 return;
350 } 391 }
351 392
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 556
516 void WebApkInstaller::OnSuccess() { 557 void WebApkInstaller::OnSuccess() {
517 finish_callback_.Run(true, webapk_package_); 558 finish_callback_.Run(true, webapk_package_);
518 delete this; 559 delete this;
519 } 560 }
520 561
521 void WebApkInstaller::OnFailure() { 562 void WebApkInstaller::OnFailure() {
522 finish_callback_.Run(false, webapk_package_); 563 finish_callback_.Run(false, webapk_package_);
523 delete this; 564 delete this;
524 } 565 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698