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

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

Issue 2882243002: Remove ChromeWebApkHost::GetGooglePlayInstallState() check from WebApkInstaller (Closed)
Patch Set: Created 3 years, 7 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, primary_icon_, 262 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, primary_icon_,
263 badge_icon_, icon_url_to_murmur2_hash, is_manifest_stale), 263 badge_icon_, icon_url_to_murmur2_hash, is_manifest_stale),
264 base::Bind(&OnWebApkProtoBuilt, callback)); 264 base::Bind(&OnWebApkProtoBuilt, callback));
265 } 265 }
266 266
267 // static 267 // static
268 bool WebApkInstaller::Register(JNIEnv* env) { 268 bool WebApkInstaller::Register(JNIEnv* env) {
269 return RegisterNativesImpl(env); 269 return RegisterNativesImpl(env);
270 } 270 }
271 271
272 bool WebApkInstaller::CanInstallWebApks() {
273 return ChromeWebApkHost::GetGooglePlayInstallState() ==
274 GooglePlayInstallState::SUPPORTED;
275 }
276
277 void WebApkInstaller::InstallOrUpdateWebApk(const std::string& package_name, 272 void WebApkInstaller::InstallOrUpdateWebApk(const std::string& package_name,
278 int version, 273 int version,
279 const std::string& token) { 274 const std::string& token) {
280 webapk_package_ = package_name; 275 webapk_package_ = package_name;
281 276
282 JNIEnv* env = base::android::AttachCurrentThread(); 277 JNIEnv* env = base::android::AttachCurrentThread();
283 base::android::ScopedJavaLocalRef<jstring> java_webapk_package = 278 base::android::ScopedJavaLocalRef<jstring> java_webapk_package =
284 base::android::ConvertUTF8ToJavaString(env, webapk_package_); 279 base::android::ConvertUTF8ToJavaString(env, webapk_package_);
285 base::android::ScopedJavaLocalRef<jstring> java_title = 280 base::android::ScopedJavaLocalRef<jstring> java_title =
286 base::android::ConvertUTF16ToJavaString(env, shortcut_info_.user_title); 281 base::android::ConvertUTF16ToJavaString(env, shortcut_info_.user_title);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 OnResult(WebApkInstallResult::SUCCESS); 402 OnResult(WebApkInstallResult::SUCCESS);
408 return; 403 return;
409 } 404 }
410 405
411 if (token.empty() || response->package_name().empty()) { 406 if (token.empty() || response->package_name().empty()) {
412 LOG(WARNING) << "WebAPK server returned incomplete proto."; 407 LOG(WARNING) << "WebAPK server returned incomplete proto.";
413 OnResult(WebApkInstallResult::FAILURE); 408 OnResult(WebApkInstallResult::FAILURE);
414 return; 409 return;
415 } 410 }
416 411
417 if (!CanInstallWebApks()) {
418 OnResult(WebApkInstallResult::FAILURE);
419 return;
420 }
421
422 int version = 1; 412 int version = 1;
423 base::StringToInt(response->version(), &version); 413 base::StringToInt(response->version(), &version);
424 InstallOrUpdateWebApk(response->package_name(), version, token); 414 InstallOrUpdateWebApk(response->package_name(), version, token);
425 } 415 }
426 416
427 void WebApkInstaller::OnGotPrimaryIconMurmur2Hash( 417 void WebApkInstaller::OnGotPrimaryIconMurmur2Hash(
428 const std::string& primary_icon_hash) { 418 const std::string& primary_icon_hash) {
429 // An empty hash indicates an error during hash calculation. 419 // An empty hash indicates an error during hash calculation.
430 if (primary_icon_hash.empty()) { 420 if (primary_icon_hash.empty()) {
431 OnResult(WebApkInstallResult::FAILURE); 421 OnResult(WebApkInstallResult::FAILURE);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); 489 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this);
500 url_fetcher_->SetRequestContext(request_context_getter_); 490 url_fetcher_->SetRequestContext(request_context_getter_);
501 std::string serialized_request; 491 std::string serialized_request;
502 request_proto->SerializeToString(&serialized_request); 492 request_proto->SerializeToString(&serialized_request);
503 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); 493 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request);
504 url_fetcher_->SetLoadFlags( 494 url_fetcher_->SetLoadFlags(
505 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES | 495 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES |
506 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); 496 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA);
507 url_fetcher_->Start(); 497 url_fetcher_->Start();
508 } 498 }
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