| 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 "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 Loading... |
| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 if (!response->ParseFromString(response_string)) { | 248 if (!response->ParseFromString(response_string)) { |
| 244 OnFailure(); | 249 OnFailure(); |
| 245 return; | 250 return; |
| 246 } | 251 } |
| 247 | 252 |
| 248 GURL signed_download_url(response->signed_download_url()); | 253 GURL signed_download_url(response->signed_download_url()); |
| 249 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 254 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
| 250 OnFailure(); | 255 OnFailure(); |
| 251 return; | 256 return; |
| 252 } | 257 } |
| 258 |
| 253 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); | 259 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); |
| 254 } | 260 } |
| 255 | 261 |
| 256 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { | 262 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { |
| 257 timer_.Start( | 263 timer_.Start( |
| 258 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), | 264 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), |
| 259 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); | 265 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); |
| 260 | 266 |
| 261 icon_hasher_.reset(new WebApkIconHasher()); | 267 icon_hasher_.reset(new WebApkIconHasher()); |
| 262 icon_hasher_->DownloadAndComputeMurmur2Hash( | 268 icon_hasher_->DownloadAndComputeMurmur2Hash( |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 374 |
| 369 void WebApkInstaller::OnWebApkMadeWorldReadable( | 375 void WebApkInstaller::OnWebApkMadeWorldReadable( |
| 370 const base::FilePath& file_path, | 376 const base::FilePath& file_path, |
| 371 const std::string& package_name, | 377 const std::string& package_name, |
| 372 bool change_permission_success) { | 378 bool change_permission_success) { |
| 373 if (!change_permission_success) { | 379 if (!change_permission_success) { |
| 374 OnFailure(); | 380 OnFailure(); |
| 375 return; | 381 return; |
| 376 } | 382 } |
| 377 | 383 |
| 384 if (package_available_callback_) |
| 385 package_available_callback_.Run(package_name); |
| 386 |
| 378 JNIEnv* env = base::android::AttachCurrentThread(); | 387 JNIEnv* env = base::android::AttachCurrentThread(); |
| 379 base::android::ScopedJavaLocalRef<jstring> java_file_path = | 388 base::android::ScopedJavaLocalRef<jstring> java_file_path = |
| 380 base::android::ConvertUTF8ToJavaString(env, file_path.value()); | 389 base::android::ConvertUTF8ToJavaString(env, file_path.value()); |
| 381 base::android::ScopedJavaLocalRef<jstring> java_package_name = | 390 base::android::ScopedJavaLocalRef<jstring> java_package_name = |
| 382 base::android::ConvertUTF8ToJavaString(env, package_name); | 391 base::android::ConvertUTF8ToJavaString(env, package_name); |
| 383 bool success = false; | 392 bool success = false; |
| 384 if (task_type_ == INSTALL) { | 393 if (task_type_ == INSTALL) { |
| 385 success = StartInstallingDownloadedWebApk(env, java_file_path, | 394 success = StartInstallingDownloadedWebApk(env, java_file_path, |
| 386 java_package_name); | 395 java_package_name); |
| 387 } else if (task_type_ == UPDATE) { | 396 } else if (task_type_ == UPDATE) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 398 OnFailure(); | 407 OnFailure(); |
| 399 } | 408 } |
| 400 | 409 |
| 401 void WebApkInstaller::OnSuccess() { | 410 void WebApkInstaller::OnSuccess() { |
| 402 FinishCallback callback = finish_callback_; | 411 FinishCallback callback = finish_callback_; |
| 403 delete this; | 412 delete this; |
| 404 callback.Run(true); | 413 callback.Run(true); |
| 405 } | 414 } |
| 406 | 415 |
| 407 void WebApkInstaller::OnFailure() { | 416 void WebApkInstaller::OnFailure() { |
| 408 FinishCallback callback = finish_callback_; | 417 ShortcutHelper::WebApkPackageNameAvailableCallback callback = |
| 418 package_available_callback_; |
| 419 FinishCallback finish_callback = finish_callback_; |
| 409 delete this; | 420 delete this; |
| 410 callback.Run(false); | 421 callback.Run(""); |
| 422 finish_callback.Run(false); |
| 411 } | 423 } |
| OLD | NEW |