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 "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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
| 20 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| 21 #include "chrome/browser/android/shortcut_helper.h" | 21 #include "chrome/browser/android/shortcut_helper.h" |
| 22 #include "chrome/browser/android/webapk/webapk.pb.h" | 22 #include "chrome/browser/android/webapk/webapk.pb.h" |
| 23 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" | 23 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/common/chrome_features.h" | |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "components/variations/variations_associated_data.h" | |
| 26 #include "components/version_info/version_info.h" | 28 #include "components/version_info/version_info.h" |
| 27 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/common/manifest_util.h" | 30 #include "content/public/common/manifest_util.h" |
| 29 #include "jni/WebApkInstaller_jni.h" | 31 #include "jni/WebApkInstaller_jni.h" |
| 30 #include "net/http/http_status_code.h" | 32 #include "net/http/http_status_code.h" |
| 31 #include "net/url_request/url_fetcher.h" | 33 #include "net/url_request/url_fetcher.h" |
| 32 #include "ui/gfx/codec/png_codec.h" | 34 #include "ui/gfx/codec/png_codec.h" |
| 33 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 // The default WebAPK server URL. | 39 // The default WebAPK server URL. |
| 38 const char kDefaultWebApkServerUrl[] = | 40 const char kDefaultServerUrl[] = |
| 39 "https://webapk.googleapis.com/v1alpha/webApks/?alt=proto"; | 41 "https://webapk.googleapis.com/v1alpha/webApks/?alt=proto"; |
| 40 | 42 |
| 43 // Flag for setting the WebAPK server URL. | |
| 44 const char kServerUrlVariationsParamKey[] = "ServerUrl"; | |
| 45 | |
| 41 // The MIME type of the POST data sent to the server. | 46 // The MIME type of the POST data sent to the server. |
| 42 const char kProtoMimeType[] = "application/x-protobuf"; | 47 const char kProtoMimeType[] = "application/x-protobuf"; |
| 43 | 48 |
| 44 // The default number of milliseconds to wait for the WebAPK download URL from | 49 // The default number of milliseconds to wait for the WebAPK download URL from |
| 45 // the WebAPK server. | 50 // the WebAPK server. |
| 46 const int kWebApkDownloadUrlTimeoutMs = 60000; | 51 const int kWebApkDownloadUrlTimeoutMs = 60000; |
| 47 | 52 |
| 48 // The default number of milliseconds to wait for the WebAPK download to | 53 // The default number of milliseconds to wait for the WebAPK download to |
| 49 // complete. | 54 // complete. |
| 50 const int kDownloadTimeoutMs = 60000; | 55 const int kDownloadTimeoutMs = 60000; |
| 51 | 56 |
| 52 const int kWorldReadableFilePermission = base::FILE_PERMISSION_READ_BY_USER | | 57 const int kWorldReadableFilePermission = base::FILE_PERMISSION_READ_BY_USER | |
| 53 base::FILE_PERMISSION_READ_BY_GROUP | | 58 base::FILE_PERMISSION_READ_BY_GROUP | |
| 54 base::FILE_PERMISSION_READ_BY_OTHERS; | 59 base::FILE_PERMISSION_READ_BY_OTHERS; |
| 55 | 60 |
| 61 // Returns the WebAPK server URL based on the command line flags and the | |
| 62 // currently active field trials. | |
| 63 GURL GetServerUrl() { | |
| 64 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 65 if (command_line->HasSwitch(switches::kWebApkServerUrl)) | |
| 66 return GURL(command_line->GetSwitchValueASCII(switches::kWebApkServerUrl)); | |
|
dominickn
2016/10/24 00:32:37
For safety, should you test whether this GURL is_v
pkotwicz
2016/10/24 04:33:42
Good point.
UrlFetcher crashes if given an invali
| |
| 67 std::string server_url = variations::GetVariationParamValueByFeature( | |
| 68 features::kWebApk, kServerUrlVariationsParamKey); | |
| 69 return GURL(!server_url.empty() ? server_url : kDefaultServerUrl); | |
| 70 } | |
| 71 | |
| 56 // Returns the scope from |info| if it is specified. Otherwise, returns the | 72 // Returns the scope from |info| if it is specified. Otherwise, returns the |
| 57 // default scope. | 73 // default scope. |
| 58 GURL GetScope(const ShortcutInfo& info) { | 74 GURL GetScope(const ShortcutInfo& info) { |
| 59 return (info.scope.is_valid()) | 75 return (info.scope.is_valid()) |
| 60 ? info.scope | 76 ? info.scope |
| 61 : ShortcutHelper::GetScopeFromURL(info.url); | 77 : ShortcutHelper::GetScopeFromURL(info.url); |
| 62 } | 78 } |
| 63 | 79 |
| 64 // Converts a color from the format specified in content::Manifest to a CSS | 80 // Converts a color from the format specified in content::Manifest to a CSS |
| 65 // string. | 81 // string. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 | 169 |
| 154 return output_dir; | 170 return output_dir; |
| 155 } | 171 } |
| 156 | 172 |
| 157 } // anonymous namespace | 173 } // anonymous namespace |
| 158 | 174 |
| 159 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info, | 175 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info, |
| 160 const SkBitmap& shortcut_icon) | 176 const SkBitmap& shortcut_icon) |
| 161 : shortcut_info_(shortcut_info), | 177 : shortcut_info_(shortcut_info), |
| 162 shortcut_icon_(shortcut_icon), | 178 shortcut_icon_(shortcut_icon), |
| 179 server_url_(GetServerUrl()), | |
| 163 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), | 180 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), |
| 164 download_timeout_ms_(kDownloadTimeoutMs), | 181 download_timeout_ms_(kDownloadTimeoutMs), |
| 165 task_type_(UNDEFINED), | 182 task_type_(UNDEFINED), |
| 166 weak_ptr_factory_(this) { | 183 weak_ptr_factory_(this) { |
| 167 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 168 server_url_ = | |
| 169 GURL(command_line->HasSwitch(switches::kWebApkServerUrl) | |
| 170 ? command_line->GetSwitchValueASCII(switches::kWebApkServerUrl) | |
| 171 : kDefaultWebApkServerUrl); | |
| 172 CreateJavaRef(); | 184 CreateJavaRef(); |
| 173 } | 185 } |
| 174 | 186 |
| 175 void WebApkInstaller::CreateJavaRef() { | 187 void WebApkInstaller::CreateJavaRef() { |
| 176 JNIEnv* env = base::android::AttachCurrentThread(); | 188 JNIEnv* env = base::android::AttachCurrentThread(); |
| 177 java_ref_.Reset(Java_WebApkInstaller_create( | 189 java_ref_.Reset(Java_WebApkInstaller_create( |
| 178 env, reinterpret_cast<intptr_t>(this))); | 190 env, reinterpret_cast<intptr_t>(this))); |
| 179 } | 191 } |
| 180 | 192 |
| 181 WebApkInstaller::~WebApkInstaller() { | 193 WebApkInstaller::~WebApkInstaller() { |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 | 486 |
| 475 void WebApkInstaller::OnSuccess() { | 487 void WebApkInstaller::OnSuccess() { |
| 476 finish_callback_.Run(true, webapk_package_); | 488 finish_callback_.Run(true, webapk_package_); |
| 477 delete this; | 489 delete this; |
| 478 } | 490 } |
| 479 | 491 |
| 480 void WebApkInstaller::OnFailure() { | 492 void WebApkInstaller::OnFailure() { |
| 481 finish_callback_.Run(false, webapk_package_); | 493 finish_callback_.Run(false, webapk_package_); |
| 482 delete this; | 494 delete this; |
| 483 } | 495 } |
| OLD | NEW |