| 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 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 namespace net { | 29 namespace net { |
| 30 class URLFetcher; | 30 class URLFetcher; |
| 31 class URLRequestContextGetter; | 31 class URLRequestContextGetter; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace webapk { | 34 namespace webapk { |
| 35 class WebApk; | 35 class WebApk; |
| 36 } | 36 } |
| 37 | 37 |
| 38 class WebApkIconHasher; |
| 39 |
| 38 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the | 40 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the |
| 39 // server, download it, and install it. | 41 // server, download it, and install it. |
| 40 class WebApkInstaller : public net::URLFetcherDelegate { | 42 class WebApkInstaller : public net::URLFetcherDelegate { |
| 41 public: | 43 public: |
| 42 using FinishCallback = base::Callback<void(bool)>; | 44 using FinishCallback = base::Callback<void(bool)>; |
| 43 | 45 |
| 44 WebApkInstaller(const ShortcutInfo& shortcut_info, | 46 WebApkInstaller(const ShortcutInfo& shortcut_info, |
| 45 const SkBitmap& shorcut_icon); | 47 const SkBitmap& shorcut_icon); |
| 46 ~WebApkInstaller() override; | 48 ~WebApkInstaller() override; |
| 47 | 49 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 66 // |package_name| is the package name that the WebAPK should be installed at. | 68 // |package_name| is the package name that the WebAPK should be installed at. |
| 67 virtual bool StartDownloadedWebApkInstall( | 69 virtual bool StartDownloadedWebApkInstall( |
| 68 JNIEnv* env, | 70 JNIEnv* env, |
| 69 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, | 71 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
| 70 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); | 72 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); |
| 71 | 73 |
| 72 private: | 74 private: |
| 73 // net::URLFetcherDelegate: | 75 // net::URLFetcherDelegate: |
| 74 void OnURLFetchComplete(const net::URLFetcher* source) override; | 76 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 75 | 77 |
| 78 // Downloads app icon in order to compute Murmur2 hash. |
| 79 void DownloadAppIconAndComputeMurmur2Hash(); |
| 80 |
| 81 // Called with the computed Murmur2 hash for the app icon. |
| 82 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); |
| 83 |
| 76 // Sends request to WebAPK server to create WebAPK. During a successful | 84 // Sends request to WebAPK server to create WebAPK. During a successful |
| 77 // request the WebAPK server responds with the URL of the generated WebAPK. | 85 // request the WebAPK server responds with the URL of the generated WebAPK. |
| 78 // |webapk| is the proto to send to the WebAPK server. | 86 // |webapk| is the proto to send to the WebAPK server. |
| 79 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); | 87 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); |
| 80 | 88 |
| 81 // Called with the URL of generated WebAPK and the package name that the | 89 // Called with the URL of generated WebAPK and the package name that the |
| 82 // WebAPK should be installed at. | 90 // WebAPK should be installed at. |
| 83 void OnGotWebApkDownloadUrl(const GURL& download_url, | 91 void OnGotWebApkDownloadUrl(const GURL& download_url, |
| 84 const std::string& package_name); | 92 const std::string& package_name); |
| 85 | 93 |
| 86 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK | 94 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK |
| 87 // world readable and installs the WebAPK if the download was successful. | 95 // world readable and installs the WebAPK if the download was successful. |
| 88 // |file_path| is the file path that the WebAPK was downloaded to. | 96 // |file_path| is the file path that the WebAPK was downloaded to. |
| 89 // |package_name| is the package name that the WebAPK should be installed at. | 97 // |package_name| is the package name that the WebAPK should be installed at. |
| 90 void OnWebApkDownloaded(const base::FilePath& file_path, | 98 void OnWebApkDownloaded(const base::FilePath& file_path, |
| 91 const std::string& package_name, | 99 const std::string& package_name, |
| 92 FileDownloader::Result result); | 100 FileDownloader::Result result); |
| 93 | 101 |
| 94 // Called once the downloaded WebAPK has been made world readable. Installs | 102 // Called once the downloaded WebAPK has been made world readable. Installs |
| 95 // the WebAPK. | 103 // the WebAPK. |
| 96 // |file_path| is the file path that the WebAPK was downloaded to. | 104 // |file_path| is the file path that the WebAPK was downloaded to. |
| 97 // |package_name| is the package name that the WebAPK should be installed at. | 105 // |package_name| is the package name that the WebAPK should be installed at. |
| 98 // |change_permission_success| is whether the WebAPK could be made world | 106 // |change_permission_success| is whether the WebAPK could be made world |
| 99 // readable. | 107 // readable. |
| 100 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, | 108 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, |
| 101 const std::string& package_name, | 109 const std::string& package_name, |
| 102 bool change_permission_success); | 110 bool change_permission_success); |
| 103 | 111 |
| 104 // Populates webapk::WebApk and returns it. | |
| 105 // Must be called on a worker thread because it encodes an SkBitmap. | |
| 106 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground(); | |
| 107 | |
| 108 // Called when the request to the WebAPK server times out or when the WebAPK | 112 // Called when the request to the WebAPK server times out or when the WebAPK |
| 109 // download times out. | 113 // download times out. |
| 110 void OnTimeout(); | 114 void OnTimeout(); |
| 111 | 115 |
| 112 // Called when the request to install the WebAPK is sent to Google Play. | 116 // Called when the request to install the WebAPK is sent to Google Play. |
| 113 void OnSuccess(); | 117 void OnSuccess(); |
| 114 | 118 |
| 115 // Called if a WebAPK could not be created. WebApkInstaller only tracks the | 119 // Called if a WebAPK could not be created. WebApkInstaller only tracks the |
| 116 // WebAPK creation and the WebAPK download. It does not track the | 120 // WebAPK creation and the WebAPK download. It does not track the |
| 117 // WebAPK installation. OnFailure() is not called if the WebAPK could not be | 121 // WebAPK installation. OnFailure() is not called if the WebAPK could not be |
| 118 // installed. | 122 // installed. |
| 119 void OnFailure(); | 123 void OnFailure(); |
| 120 | 124 |
| 121 net::URLRequestContextGetter* request_context_getter_; | 125 net::URLRequestContextGetter* request_context_getter_; |
| 122 | 126 |
| 123 // Sends HTTP request to WebAPK server. | 127 // Sends HTTP request to WebAPK server. |
| 124 std::unique_ptr<net::URLFetcher> url_fetcher_; | 128 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| 125 | 129 |
| 130 // Downloads app icon and computes Murmur2 hash. |
| 131 std::unique_ptr<WebApkIconHasher> icon_hasher_; |
| 132 |
| 126 // Downloads WebAPK. | 133 // Downloads WebAPK. |
| 127 std::unique_ptr<FileDownloader> downloader_; | 134 std::unique_ptr<FileDownloader> downloader_; |
| 128 | 135 |
| 129 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the | 136 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the |
| 130 // download takes too long. | 137 // download takes too long. |
| 131 base::OneShotTimer timer_; | 138 base::OneShotTimer timer_; |
| 132 | 139 |
| 133 // Callback to call once WebApkInstaller succeeds or fails. | 140 // Callback to call once WebApkInstaller succeeds or fails. |
| 134 FinishCallback finish_callback_; | 141 FinishCallback finish_callback_; |
| 135 | 142 |
| 136 // Web Manifest info. | 143 // Web Manifest info. |
| 137 const ShortcutInfo shortcut_info_; | 144 const ShortcutInfo shortcut_info_; |
| 138 | 145 |
| 139 // WebAPK app icon. | 146 // WebAPK app icon. |
| 140 const SkBitmap shortcut_icon_; | 147 const SkBitmap shortcut_icon_; |
| 141 | 148 |
| 149 // Murmur2 hash of the bitmap at the app icon URL prior to any transformations |
| 150 // being applied to the bitmap (such as encoding/decoding the icon bitmap). |
| 151 std::string shortcut_icon_murmur2_hash_; |
| 152 |
| 142 // WebAPK server URL. | 153 // WebAPK server URL. |
| 143 GURL server_url_; | 154 GURL server_url_; |
| 144 | 155 |
| 145 // The number of milliseconds to wait for the WebAPK download URL from the | 156 // The number of milliseconds to wait for the WebAPK download URL from the |
| 146 // WebAPK server. | 157 // WebAPK server. |
| 147 int webapk_download_url_timeout_ms_; | 158 int webapk_download_url_timeout_ms_; |
| 148 | 159 |
| 149 // The number of milliseconds to wait for the WebAPK download to complete. | 160 // The number of milliseconds to wait for the WebAPK download to complete. |
| 150 int download_timeout_ms_; | 161 int download_timeout_ms_; |
| 151 | 162 |
| 152 // Used to get |weak_ptr_|. | 163 // Used to get |weak_ptr_|. |
| 153 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 164 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
| 154 | 165 |
| 155 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 166 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
| 156 }; | 167 }; |
| 157 | 168 |
| 158 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 169 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| OLD | NEW |