| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return ""; | 77 return ""; |
| 78 | 78 |
| 79 SkColor sk_color = reinterpret_cast<uint32_t&>(color); | 79 SkColor sk_color = reinterpret_cast<uint32_t&>(color); |
| 80 int r = SkColorGetR(sk_color); | 80 int r = SkColorGetR(sk_color); |
| 81 int g = SkColorGetG(sk_color); | 81 int g = SkColorGetG(sk_color); |
| 82 int b = SkColorGetB(sk_color); | 82 int b = SkColorGetB(sk_color); |
| 83 double a = SkColorGetA(sk_color) / 255.0; | 83 double a = SkColorGetA(sk_color) / 255.0; |
| 84 return base::StringPrintf("rgba(%d,%d,%d,%.2f)", r, g, b, a); | 84 return base::StringPrintf("rgba(%d,%d,%d,%.2f)", r, g, b, a); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Returns task runner for running background tasks. |
| 88 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { |
| 89 return content::BrowserThread::GetBlockingPool() |
| 90 ->GetTaskRunnerWithShutdownBehavior( |
| 91 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 92 } |
| 93 |
| 87 } // anonymous namespace | 94 } // anonymous namespace |
| 88 | 95 |
| 89 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info, | 96 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info, |
| 90 const SkBitmap& shortcut_icon) | 97 const SkBitmap& shortcut_icon) |
| 91 : shortcut_info_(shortcut_info), | 98 : shortcut_info_(shortcut_info), |
| 92 shortcut_icon_(shortcut_icon), | 99 shortcut_icon_(shortcut_icon), |
| 93 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), | 100 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), |
| 94 download_timeout_ms_(kDownloadTimeoutMs), | 101 download_timeout_ms_(kDownloadTimeoutMs), |
| 95 weak_ptr_factory_(this) { | 102 weak_ptr_factory_(this) { |
| 96 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 103 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 110 } | 117 } |
| 111 | 118 |
| 112 void WebApkInstaller::InstallAsyncWithURLRequestContextGetter( | 119 void WebApkInstaller::InstallAsyncWithURLRequestContextGetter( |
| 113 net::URLRequestContextGetter* request_context_getter, | 120 net::URLRequestContextGetter* request_context_getter, |
| 114 const FinishCallback& finish_callback) { | 121 const FinishCallback& finish_callback) { |
| 115 request_context_getter_ = request_context_getter; | 122 request_context_getter_ = request_context_getter; |
| 116 finish_callback_ = finish_callback; | 123 finish_callback_ = finish_callback; |
| 117 | 124 |
| 118 // base::Unretained() is safe because WebApkInstaller owns itself and does not | 125 // base::Unretained() is safe because WebApkInstaller owns itself and does not |
| 119 // start the timeout timer till after SendCreateWebApkRequest() is called. | 126 // start the timeout timer till after SendCreateWebApkRequest() is called. |
| 120 scoped_refptr<base::TaskRunner> background_task_runner = | |
| 121 content::BrowserThread::GetBlockingPool() | |
| 122 ->GetTaskRunnerWithShutdownBehavior( | |
| 123 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | |
| 124 base::PostTaskAndReplyWithResult( | 127 base::PostTaskAndReplyWithResult( |
| 125 background_task_runner.get(), FROM_HERE, | 128 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 126 base::Bind(&WebApkInstaller::BuildWebApkProtoInBackground, | 129 base::Bind(&WebApkInstaller::BuildWebApkProtoInBackground, |
| 127 base::Unretained(this)), | 130 base::Unretained(this)), |
| 128 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, | 131 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, |
| 129 base::Unretained(this))); | 132 base::Unretained(this))); |
| 130 } | 133 } |
| 131 | 134 |
| 132 void WebApkInstaller::SetTimeoutMs(int timeout_ms) { | 135 void WebApkInstaller::SetTimeoutMs(int timeout_ms) { |
| 133 webapk_download_url_timeout_ms_ = timeout_ms; | 136 webapk_download_url_timeout_ms_ = timeout_ms; |
| 134 download_timeout_ms_ = timeout_ms; | 137 download_timeout_ms_ = timeout_ms; |
| 135 } | 138 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, | 210 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, |
| 208 const std::string& package_name, | 211 const std::string& package_name, |
| 209 FileDownloader::Result result) { | 212 FileDownloader::Result result) { |
| 210 timer_.Stop(); | 213 timer_.Stop(); |
| 211 | 214 |
| 212 if (result != FileDownloader::DOWNLOADED) { | 215 if (result != FileDownloader::DOWNLOADED) { |
| 213 OnFailure(); | 216 OnFailure(); |
| 214 return; | 217 return; |
| 215 } | 218 } |
| 216 | 219 |
| 220 int posix_permissions = base::FILE_PERMISSION_READ_BY_USER | |
| 221 base::FILE_PERMISSION_WRITE_BY_USER | |
| 222 base::FILE_PERMISSION_READ_BY_GROUP | |
| 223 base::FILE_PERMISSION_READ_BY_OTHERS; |
| 224 base::PostTaskAndReplyWithResult( |
| 225 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 226 base::Bind(&base::SetPosixFilePermissions, file_path, posix_permissions), |
| 227 base::Bind(&WebApkInstaller::OnWebApkMadeWorldReadable, |
| 228 weak_ptr_factory_.GetWeakPtr(), file_path, package_name)); |
| 229 } |
| 230 |
| 231 void WebApkInstaller::OnWebApkMadeWorldReadable( |
| 232 const base::FilePath& file_path, |
| 233 const std::string& package_name, |
| 234 bool change_permission_success) { |
| 235 if (!change_permission_success) { |
| 236 OnFailure(); |
| 237 return; |
| 238 } |
| 239 |
| 217 JNIEnv* env = base::android::AttachCurrentThread(); | 240 JNIEnv* env = base::android::AttachCurrentThread(); |
| 218 base::android::ScopedJavaLocalRef<jstring> java_file_path = | 241 base::android::ScopedJavaLocalRef<jstring> java_file_path = |
| 219 base::android::ConvertUTF8ToJavaString(env, file_path.value()); | 242 base::android::ConvertUTF8ToJavaString(env, file_path.value()); |
| 220 base::android::ScopedJavaLocalRef<jstring> java_package_name = | 243 base::android::ScopedJavaLocalRef<jstring> java_package_name = |
| 221 base::android::ConvertUTF8ToJavaString(env, package_name); | 244 base::android::ConvertUTF8ToJavaString(env, package_name); |
| 222 bool success = | 245 bool success = |
| 223 StartDownloadedWebApkInstall(env, java_file_path, java_package_name); | 246 StartDownloadedWebApkInstall(env, java_file_path, java_package_name); |
| 224 if (success) | 247 if (success) |
| 225 OnSuccess(); | 248 OnSuccess(); |
| 226 else | 249 else |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 294 |
| 272 void WebApkInstaller::OnSuccess() { | 295 void WebApkInstaller::OnSuccess() { |
| 273 finish_callback_.Run(true); | 296 finish_callback_.Run(true); |
| 274 delete this; | 297 delete this; |
| 275 } | 298 } |
| 276 | 299 |
| 277 void WebApkInstaller::OnFailure() { | 300 void WebApkInstaller::OnFailure() { |
| 278 finish_callback_.Run(false); | 301 finish_callback_.Run(false); |
| 279 delete this; | 302 delete this; |
| 280 } | 303 } |
| OLD | NEW |