Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <stdlib.h> | |
| 8 | |
| 7 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
| 8 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 10 #include "base/android/path_utils.h" | 12 #include "base/android/path_utils.h" |
| 11 #include "base/bind.h" | 13 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 15 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/task_runner_util.h" | 20 #include "base/task_runner_util.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "chrome/browser/android/chrome_feature_list.h" | 22 #include "chrome/browser/android/chrome_feature_list.h" |
| 21 #include "chrome/browser/android/shortcut_helper.h" | 23 #include "chrome/browser/android/shortcut_helper.h" |
| 22 #include "chrome/browser/android/webapk/webapk.pb.h" | 24 #include "chrome/browser/android/webapk/webapk.pb.h" |
| 23 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" | 25 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/common/chrome_switches.h" | |
| 25 #include "components/variations/variations_associated_data.h" | 28 #include "components/variations/variations_associated_data.h" |
| 26 #include "components/version_info/version_info.h" | 29 #include "components/version_info/version_info.h" |
| 27 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/common/manifest_util.h" | 31 #include "content/public/common/manifest_util.h" |
| 29 #include "jni/WebApkInstaller_jni.h" | 32 #include "jni/WebApkInstaller_jni.h" |
| 30 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
| 31 #include "net/url_request/url_fetcher.h" | 34 #include "net/url_request/url_fetcher.h" |
| 32 #include "ui/gfx/codec/png_codec.h" | 35 #include "ui/gfx/codec/png_codec.h" |
| 33 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 34 | 37 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 if (!response->ParseFromString(response_string)) { | 324 if (!response->ParseFromString(response_string)) { |
| 322 OnFailure(); | 325 OnFailure(); |
| 323 return; | 326 return; |
| 324 } | 327 } |
| 325 | 328 |
| 326 GURL signed_download_url(response->signed_download_url()); | 329 GURL signed_download_url(response->signed_download_url()); |
| 327 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 330 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
| 328 OnFailure(); | 331 OnFailure(); |
| 329 return; | 332 return; |
| 330 } | 333 } |
| 334 | |
| 335 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 336 switches::kEnablePlayInstallWebApk)) { | |
| 337 InstallWebApkFromPlayStore(response->package_name(), | |
| 338 std::atoi(response->version().c_str()), | |
|
pkotwicz
2016/11/23 03:11:28
Random thought: Why isn't the version part of the
Xi Han
2016/11/23 15:43:46
Scott confirmed that the token is just a random nu
pkotwicz
2016/11/23 15:56:38
I dislike that the token is a random number. If it
Xi Han
2016/11/23 16:44:42
As discussed offline, the version is required by P
| |
| 339 response->token()); | |
| 340 return; | |
| 341 } | |
| 342 | |
| 331 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); | 343 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); |
| 332 } | 344 } |
| 333 | 345 |
| 334 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { | 346 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { |
| 335 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. | 347 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. |
| 336 if (!shortcut_info_.icon_url.is_valid()) { | 348 if (!shortcut_info_.icon_url.is_valid()) { |
| 337 OnFailure(); | 349 OnFailure(); |
| 338 return; | 350 return; |
| 339 } | 351 } |
| 340 | 352 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 404 |
| 393 url_fetcher_ = | 405 url_fetcher_ = |
| 394 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); | 406 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); |
| 395 url_fetcher_->SetRequestContext(request_context_getter_); | 407 url_fetcher_->SetRequestContext(request_context_getter_); |
| 396 std::string serialized_request; | 408 std::string serialized_request; |
| 397 request_proto->SerializeToString(&serialized_request); | 409 request_proto->SerializeToString(&serialized_request); |
| 398 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); | 410 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); |
| 399 url_fetcher_->Start(); | 411 url_fetcher_->Start(); |
| 400 } | 412 } |
| 401 | 413 |
| 414 void WebApkInstaller::InstallWebApkFromPlayStore( | |
| 415 const std::string& package_name, int version, const std::string& token) { | |
| 416 webapk_package_ = package_name; | |
| 417 | |
| 418 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 419 base::android::ScopedJavaLocalRef<jstring> java_webapk_package = | |
| 420 base::android::ConvertUTF8ToJavaString(env, webapk_package_); | |
| 421 base::android::ScopedJavaLocalRef<jstring> java_title = | |
| 422 base::android::ConvertUTF16ToJavaString(env, shortcut_info_.user_title); | |
| 423 base::android::ScopedJavaLocalRef<jstring> java_token = | |
| 424 base::android::ConvertUTF8ToJavaString(env, token); | |
| 425 | |
| 426 Java_WebApkInstaller_installWebApkFromPlayStoreAsyncAndMonitorInstallation( | |
| 427 env, java_ref_, java_webapk_package, version, java_title, java_token); | |
| 428 } | |
| 429 | |
| 402 void WebApkInstaller::OnGotWebApkDownloadUrl(const GURL& download_url, | 430 void WebApkInstaller::OnGotWebApkDownloadUrl(const GURL& download_url, |
| 403 const std::string& package_name) { | 431 const std::string& package_name) { |
| 404 webapk_package_ = package_name; | 432 webapk_package_ = package_name; |
| 405 | 433 |
| 406 base::PostTaskAndReplyWithResult( | 434 base::PostTaskAndReplyWithResult( |
| 407 GetBackgroundTaskRunner().get(), FROM_HERE, | 435 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 408 base::Bind(&CreateSubDirAndSetPermissionsInBackground, | 436 base::Bind(&CreateSubDirAndSetPermissionsInBackground, |
| 409 task_type_ == WebApkInstaller::INSTALL ? "install" : "update", | 437 task_type_ == WebApkInstaller::INSTALL ? "install" : "update", |
| 410 package_name), | 438 package_name), |
| 411 base::Bind(&WebApkInstaller::OnCreatedSubDirAndSetPermissions, | 439 base::Bind(&WebApkInstaller::OnCreatedSubDirAndSetPermissions, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 | 532 |
| 505 void WebApkInstaller::OnSuccess() { | 533 void WebApkInstaller::OnSuccess() { |
| 506 finish_callback_.Run(true, webapk_package_); | 534 finish_callback_.Run(true, webapk_package_); |
| 507 delete this; | 535 delete this; |
| 508 } | 536 } |
| 509 | 537 |
| 510 void WebApkInstaller::OnFailure() { | 538 void WebApkInstaller::OnFailure() { |
| 511 finish_callback_.Run(false, webapk_package_); | 539 finish_callback_.Run(false, webapk_package_); |
| 512 delete this; | 540 delete this; |
| 513 } | 541 } |
| OLD | NEW |