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

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

Issue 2259553002: Make AppBannerInfoBar install WebAPK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 weak_ptr_factory_(this) { 140 weak_ptr_factory_(this) {
141 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 141 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
142 server_url_ = 142 server_url_ =
143 GURL(command_line->HasSwitch(switches::kWebApkServerUrl) 143 GURL(command_line->HasSwitch(switches::kWebApkServerUrl)
144 ? command_line->GetSwitchValueASCII(switches::kWebApkServerUrl) 144 ? command_line->GetSwitchValueASCII(switches::kWebApkServerUrl)
145 : kDefaultWebApkServerUrl); 145 : kDefaultWebApkServerUrl);
146 } 146 }
147 147
148 WebApkInstaller::~WebApkInstaller() {} 148 WebApkInstaller::~WebApkInstaller() {}
149 149
150 void WebApkInstaller::InstallAsync(content::BrowserContext* browser_context, 150 void WebApkInstaller::InstallAsync(
151 const FinishCallback& finish_callback) { 151 content::BrowserContext* browser_context,
152 const ShortcutHelper::WebApkPackageNameAvailableCallback& callback,
153 const FinishCallback& finish_callback) {
152 InstallAsyncWithURLRequestContextGetter( 154 InstallAsyncWithURLRequestContextGetter(
153 Profile::FromBrowserContext(browser_context)->GetRequestContext(), 155 Profile::FromBrowserContext(browser_context)->GetRequestContext(),
156 callback,
154 finish_callback); 157 finish_callback);
155 } 158 }
156 159
157 void WebApkInstaller::InstallAsyncWithURLRequestContextGetter( 160 void WebApkInstaller::InstallAsyncWithURLRequestContextGetter(
158 net::URLRequestContextGetter* request_context_getter, 161 net::URLRequestContextGetter* request_context_getter,
162 const ShortcutHelper::WebApkPackageNameAvailableCallback& callback,
159 const FinishCallback& finish_callback) { 163 const FinishCallback& finish_callback) {
160 request_context_getter_ = request_context_getter; 164 request_context_getter_ = request_context_getter;
165 package_available_callback_ = callback;
161 finish_callback_ = finish_callback; 166 finish_callback_ = finish_callback;
162 task_type_ = INSTALL; 167 task_type_ = INSTALL;
163 168
164 if (!shortcut_info_.icon_url.is_valid()) { 169 if (!shortcut_info_.icon_url.is_valid()) {
165 OnFailure(); 170 OnFailure();
166 return; 171 return;
167 } 172 }
168 173
169 // We need to take the hash of the bitmap at the icon URL prior to any 174 // We need to take the hash of the bitmap at the icon URL prior to any
170 // transformations being applied to the bitmap (such as encoding/decoding 175 // transformations being applied to the bitmap (such as encoding/decoding
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 373
369 void WebApkInstaller::OnWebApkMadeWorldReadable( 374 void WebApkInstaller::OnWebApkMadeWorldReadable(
370 const base::FilePath& file_path, 375 const base::FilePath& file_path,
371 const std::string& package_name, 376 const std::string& package_name,
372 bool change_permission_success) { 377 bool change_permission_success) {
373 if (!change_permission_success) { 378 if (!change_permission_success) {
374 OnFailure(); 379 OnFailure();
375 return; 380 return;
376 } 381 }
377 382
383 if (package_available_callback_)
384 package_available_callback_.Run(package_name);
385
378 JNIEnv* env = base::android::AttachCurrentThread(); 386 JNIEnv* env = base::android::AttachCurrentThread();
379 base::android::ScopedJavaLocalRef<jstring> java_file_path = 387 base::android::ScopedJavaLocalRef<jstring> java_file_path =
380 base::android::ConvertUTF8ToJavaString(env, file_path.value()); 388 base::android::ConvertUTF8ToJavaString(env, file_path.value());
381 base::android::ScopedJavaLocalRef<jstring> java_package_name = 389 base::android::ScopedJavaLocalRef<jstring> java_package_name =
382 base::android::ConvertUTF8ToJavaString(env, package_name); 390 base::android::ConvertUTF8ToJavaString(env, package_name);
383 bool success = false; 391 bool success = false;
384 if (task_type_ == INSTALL) { 392 if (task_type_ == INSTALL) {
385 success = StartInstallingDownloadedWebApk(env, java_file_path, 393 success = StartInstallingDownloadedWebApk(env, java_file_path,
386 java_package_name); 394 java_package_name);
387 } else if (task_type_ == UPDATE) { 395 } else if (task_type_ == UPDATE) {
(...skipping 10 matching lines...) Expand all
398 OnFailure(); 406 OnFailure();
399 } 407 }
400 408
401 void WebApkInstaller::OnSuccess() { 409 void WebApkInstaller::OnSuccess() {
402 FinishCallback callback = finish_callback_; 410 FinishCallback callback = finish_callback_;
403 delete this; 411 delete this;
404 callback.Run(true); 412 callback.Run(true);
405 } 413 }
406 414
407 void WebApkInstaller::OnFailure() { 415 void WebApkInstaller::OnFailure() {
408 FinishCallback callback = finish_callback_; 416 ShortcutHelper::WebApkPackageNameAvailableCallback callback =
417 package_available_callback_;
418 FinishCallback finish_callback = finish_callback_;
409 delete this; 419 delete this;
410 callback.Run(false); 420 callback.Run("");
421 finish_callback.Run(false);
411 } 422 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698