| 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 19 matching lines...) Expand all Loading... |
| 30 namespace webapk { | 30 namespace webapk { |
| 31 class WebApk; | 31 class WebApk; |
| 32 } | 32 } |
| 33 | 33 |
| 34 class WebApkIconHasher; | 34 class WebApkIconHasher; |
| 35 | 35 |
| 36 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the | 36 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the |
| 37 // server, download it, and install it. | 37 // server, download it, and install it. |
| 38 class WebApkInstaller : public net::URLFetcherDelegate { | 38 class WebApkInstaller : public net::URLFetcherDelegate { |
| 39 public: | 39 public: |
| 40 // Called when either a request for creating/updating a WebAPK has been sent | 40 // Called when the creation/updating of a WebAPK is finished or failed. |
| 41 // to Google Play or the create/update process fails. | |
| 42 // Parameters: | 41 // Parameters: |
| 43 // - whether the request succeeds. | 42 // - whether the process succeeds. |
| 44 using FinishCallback = base::Callback<void(bool)>; | 43 // - the package name of the WebAPK. |
| 44 using FinishCallback = base::Callback<void(bool, const std::string&)>; |
| 45 | 45 |
| 46 WebApkInstaller(const ShortcutInfo& shortcut_info, | 46 WebApkInstaller(const ShortcutInfo& shortcut_info, |
| 47 const SkBitmap& shorcut_icon); | 47 const SkBitmap& shorcut_icon); |
| 48 | 48 |
| 49 ~WebApkInstaller() override; | 49 ~WebApkInstaller() override; |
| 50 | 50 |
| 51 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to | 51 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to |
| 52 // Google Play to install the downloaded WebAPK. Calls |callback| after the | 52 // Google Play to install the downloaded WebAPK. Calls |callback| after the |
| 53 // request to install the WebAPK is sent to Google Play. | 53 // request to install the WebAPK is sent to Google Play. |
| 54 void InstallAsync(content::BrowserContext* browser_context, | 54 void InstallAsync(content::BrowserContext* browser_context, |
| 55 const FinishCallback& callback); | 55 const FinishCallback& finish_callback); |
| 56 | 56 |
| 57 // Same as InstallAsync() but uses the passed in |request_context_getter|. | 57 // Same as InstallAsync() but uses the passed in |request_context_getter|. |
| 58 void InstallAsyncWithURLRequestContextGetter( | 58 void InstallAsyncWithURLRequestContextGetter( |
| 59 net::URLRequestContextGetter* request_context_getter, | 59 net::URLRequestContextGetter* request_context_getter, |
| 60 const FinishCallback& callback); | 60 const FinishCallback& finish_callback); |
| 61 | 61 |
| 62 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to | 62 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to |
| 63 // the Google Play server to install the downloaded WebAPK. Calls |callback| | 63 // the Google Play server to install the downloaded WebAPK. Calls |callback| |
| 64 // after the request to install the WebAPK is sent to the Google Play server. | 64 // after the request to install the WebAPK is sent to the Google Play server. |
| 65 void UpdateAsync(content::BrowserContext* browser_context, | 65 void UpdateAsync(content::BrowserContext* browser_context, |
| 66 const FinishCallback& callback, | 66 const FinishCallback& callback, |
| 67 const std::string& icon_murmur2_hash, | 67 const std::string& icon_murmur2_hash, |
| 68 const std::string& webapk_package, | 68 const std::string& webapk_package, |
| 69 int webapk_version); | 69 int webapk_version); |
| 70 | 70 |
| 71 // Same as UpdateAsync() but uses the passed in |request_context_getter|. | 71 // Same as UpdateAsync() but uses the passed in |request_context_getter|. |
| 72 void UpdateAsyncWithURLRequestContextGetter( | 72 void UpdateAsyncWithURLRequestContextGetter( |
| 73 net::URLRequestContextGetter* request_context_getter, | 73 net::URLRequestContextGetter* request_context_getter, |
| 74 const FinishCallback& callback, | 74 const FinishCallback& callback, |
| 75 const std::string& icon_murmur2_hash, | 75 const std::string& icon_murmur2_hash, |
| 76 const std::string& webapk_package, | 76 const std::string& webapk_package, |
| 77 int webapk_version); | 77 int webapk_version); |
| 78 | 78 |
| 79 // Sets the timeout for the server requests. | 79 // Sets the timeout for the server requests. |
| 80 void SetTimeoutMs(int timeout_ms); | 80 void SetTimeoutMs(int timeout_ms); |
| 81 | 81 |
| 82 // Registers JNI hooks. |
| 83 static bool Register(JNIEnv* env); |
| 84 |
| 85 // Called once the installation is complete or failed. |
| 86 void OnInstallFinished(JNIEnv* env, |
| 87 const base::android::JavaParamRef<jobject>& obj, |
| 88 jboolean success); |
| 89 |
| 82 protected: | 90 protected: |
| 83 // Starts installation of the downloaded WebAPK. Returns whether the install | 91 // Starts installation of the downloaded WebAPK. Returns whether the install |
| 84 // could be started. The installation may still fail if true is returned. | 92 // could be started. The installation may still fail if true is returned. |
| 85 // |file_path| is the file path that the WebAPK was downloaded to. | 93 // |file_path| is the file path that the WebAPK was downloaded to. |
| 86 // |package_name| is the package name that the WebAPK should be installed at. | 94 // |package_name| is the package name that the WebAPK should be installed at. |
| 87 virtual bool StartInstallingDownloadedWebApk( | 95 virtual bool StartInstallingDownloadedWebApk( |
| 88 JNIEnv* env, | 96 JNIEnv* env, |
| 89 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, | 97 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
| 90 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); | 98 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); |
| 91 | 99 |
| 92 // Starts update using the downloaded WebAPK. Returns whether the updating | 100 // Starts update using the downloaded WebAPK. Returns whether the updating |
| 93 // could be started. The updating may still fail if true is returned. | 101 // could be started. The updating may still fail if true is returned. |
| 94 // |file_path| is the file path that the WebAPK was downloaded to. | 102 // |file_path| is the file path that the WebAPK was downloaded to. |
| 95 // |package_name| is the package name of the WebAPK. | 103 // |package_name| is the package name of the WebAPK. |
| 96 virtual bool StartUpdateUsingDownloadedWebApk( | 104 virtual bool StartUpdateUsingDownloadedWebApk( |
| 97 JNIEnv* env, | 105 JNIEnv* env, |
| 98 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, | 106 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
| 99 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); | 107 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); |
| 100 | 108 |
| 101 private: | 109 private: |
| 102 enum TaskType { | 110 enum TaskType { |
| 103 UNDEFINED, | 111 UNDEFINED, |
| 104 INSTALL, | 112 INSTALL, |
| 105 UPDATE, | 113 UPDATE, |
| 106 }; | 114 }; |
| 107 | 115 |
| 116 // Create the Java object. |
| 117 void CreateJavaRef(); |
| 118 |
| 108 // net::URLFetcherDelegate: | 119 // net::URLFetcherDelegate: |
| 109 void OnURLFetchComplete(const net::URLFetcher* source) override; | 120 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 110 | 121 |
| 111 // Downloads app icon in order to compute Murmur2 hash. | 122 // Downloads app icon in order to compute Murmur2 hash. |
| 112 void DownloadAppIconAndComputeMurmur2Hash(); | 123 void DownloadAppIconAndComputeMurmur2Hash(); |
| 113 | 124 |
| 114 // Called with the computed Murmur2 hash for the app icon. | 125 // Called with the computed Murmur2 hash for the app icon. |
| 115 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); | 126 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); |
| 116 | 127 |
| 117 // Sends request to WebAPK server to create WebAPK. During a successful | 128 // Sends request to WebAPK server to create WebAPK. During a successful |
| (...skipping 29 matching lines...) Expand all Loading... |
| 147 // Called once the downloaded WebAPK has been made world readable. Installs | 158 // Called once the downloaded WebAPK has been made world readable. Installs |
| 148 // the WebAPK. | 159 // the WebAPK. |
| 149 // |file_path| is the file path that the WebAPK was downloaded to. | 160 // |file_path| is the file path that the WebAPK was downloaded to. |
| 150 // |package_name| is the package name that the WebAPK should be installed at. | 161 // |package_name| is the package name that the WebAPK should be installed at. |
| 151 // |change_permission_success| is whether the WebAPK could be made world | 162 // |change_permission_success| is whether the WebAPK could be made world |
| 152 // readable. | 163 // readable. |
| 153 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, | 164 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, |
| 154 const std::string& package_name, | 165 const std::string& package_name, |
| 155 bool change_permission_success); | 166 bool change_permission_success); |
| 156 | 167 |
| 168 // A helper function called once the installation is compelete or failed. |
| 169 void OnInstallFinished(bool success); |
| 170 |
| 157 // Called when the request to the WebAPK server times out or when the WebAPK | 171 // Called when the request to the WebAPK server times out or when the WebAPK |
| 158 // download times out. | 172 // download times out. |
| 159 void OnTimeout(); | 173 void OnTimeout(); |
| 160 | 174 |
| 161 // Called when the request to install the WebAPK is sent to Google Play. | 175 // Called when the request to install the WebAPK is sent to Google Play. |
| 162 void OnSuccess(); | 176 void OnSuccess(); |
| 163 | 177 |
| 164 // Called if a WebAPK could not be created. WebApkInstaller only tracks the | 178 // Called if a WebAPK could not be created. WebApkInstaller only tracks the |
| 165 // WebAPK creation and the WebAPK download. It does not track the | 179 // WebAPK creation and the WebAPK download. It does not track the |
| 166 // WebAPK installation. OnFailure() is not called if the WebAPK could not be | 180 // WebAPK installation. OnFailure() is not called if the WebAPK could not be |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 221 |
| 208 // WebAPK package name. | 222 // WebAPK package name. |
| 209 std::string webapk_package_; | 223 std::string webapk_package_; |
| 210 | 224 |
| 211 // WebAPK version code. | 225 // WebAPK version code. |
| 212 int webapk_version_; | 226 int webapk_version_; |
| 213 | 227 |
| 214 // Indicates whether the installer is for installing or updating a WebAPK. | 228 // Indicates whether the installer is for installing or updating a WebAPK. |
| 215 TaskType task_type_; | 229 TaskType task_type_; |
| 216 | 230 |
| 231 // Points to the Java Object. |
| 232 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 233 |
| 217 // Used to get |weak_ptr_|. | 234 // Used to get |weak_ptr_|. |
| 218 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 235 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
| 219 | 236 |
| 220 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 237 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
| 221 }; | 238 }; |
| 222 | 239 |
| 223 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 240 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| OLD | NEW |