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

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

Issue 2515293004: Chrome talks to Play to install WebAPKs. (Closed)
Patch Set: Make GooglePlayWebApkInstallDelegate as a singleton. 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 base::android::ScopedJavaLocalRef<jstring> java_url =
339 base::android::ConvertUTF8ToJavaString(env, shortcut_info_.url.spec());
340
341 if (task_type_ == WebApkInstaller::INSTALL) {
342 return Java_WebApkInstaller_installWebApkFromGooglePlayAsync(
343 env, java_ref_, java_webapk_package, version, java_title, java_token,
344 java_url);
345 } else {
346 return Java_WebApkInstaller_updateAsyncFromGooglePlay(
347 env, java_ref_, java_webapk_package, version, java_title, java_token,
348 java_url);
349 }
350 }
351
318 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { 352 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) {
319 timer_.Stop(); 353 timer_.Stop();
320 354
321 if (!source->GetStatus().is_success() || 355 if (!source->GetStatus().is_success() ||
322 source->GetResponseCode() != net::HTTP_OK) { 356 source->GetResponseCode() != net::HTTP_OK) {
323 OnFailure(); 357 OnFailure();
324 return; 358 return;
325 } 359 }
326 360
327 std::string response_string; 361 std::string response_string;
328 source->GetResponseAsString(&response_string); 362 source->GetResponseAsString(&response_string);
329 363
330 std::unique_ptr<webapk::WebApkResponse> response( 364 std::unique_ptr<webapk::WebApkResponse> response(
331 new webapk::WebApkResponse); 365 new webapk::WebApkResponse);
332 if (!response->ParseFromString(response_string)) { 366 if (!response->ParseFromString(response_string)) {
333 OnFailure(); 367 OnFailure();
334 return; 368 return;
335 } 369 }
336 370
337 GURL signed_download_url(response->signed_download_url()); 371 GURL signed_download_url(response->signed_download_url());
338 if (!signed_download_url.is_valid() || response->package_name().empty()) { 372 if (!signed_download_url.is_valid() || response->package_name().empty()) {
339 OnFailure(); 373 OnFailure();
340 return; 374 return;
341 } 375 }
376
377 if (HasGooglePlayWebApkInstallDelegate()) {
378 int version = 1;
379 base::StringToInt(response->version(), &version);
380 if (!InstallOrUpdateWebApkFromGooglePlay(
381 response->package_name(), version, response->token())) {
382 OnFailure();
383 }
384 return;
385 }
386
342 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); 387 OnGotWebApkDownloadUrl(signed_download_url, response->package_name());
343 } 388 }
344 389
345 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { 390 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() {
346 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. 391 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL.
347 if (!shortcut_info_.best_icon_url.is_valid()) { 392 if (!shortcut_info_.best_icon_url.is_valid()) {
348 OnFailure(); 393 OnFailure();
349 return; 394 return;
350 } 395 }
351 396
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 560
516 void WebApkInstaller::OnSuccess() { 561 void WebApkInstaller::OnSuccess() {
517 finish_callback_.Run(true, webapk_package_); 562 finish_callback_.Run(true, webapk_package_);
518 delete this; 563 delete this;
519 } 564 }
520 565
521 void WebApkInstaller::OnFailure() { 566 void WebApkInstaller::OnFailure() {
522 finish_callback_.Run(false, webapk_package_); 567 finish_callback_.Run(false, webapk_package_);
523 delete this; 568 delete this;
524 } 569 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.h ('k') | chrome/browser/android/webapk/webapk_installer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698