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 #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 16 matching lines...) Expand all Loading... | |
| 27 class BrowserContext; | 27 class BrowserContext; |
| 28 } | 28 } |
| 29 | 29 |
| 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. |
|
gone
2016/08/29 17:24:09
Indicate that the native side WebApkInstaller owns
Xi Han
2016/08/29 17:55:46
Done.
| |
| 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 // Called once the installation is complete or failed. | |
| 83 void OnInstallFinished(JNIEnv* env, | |
| 84 const base::android::JavaParamRef<jobject>& obj, | |
| 85 jboolean success); | |
| 86 | |
| 87 // Registers JNI hooks. | |
| 88 static bool Register(JNIEnv* env); | |
| 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 |
| 109 // Called when the request to install the WebAPK is sent to Google Play. | |
| 110 void OnSuccess(); | |
| 111 | |
| 101 private: | 112 private: |
| 102 enum TaskType { | 113 enum TaskType { |
| 103 UNDEFINED, | 114 UNDEFINED, |
| 104 INSTALL, | 115 INSTALL, |
| 105 UPDATE, | 116 UPDATE, |
| 106 }; | 117 }; |
| 107 | 118 |
| 119 // Create the Java object. | |
| 120 void CreateJavaRef(); | |
| 121 | |
| 108 // net::URLFetcherDelegate: | 122 // net::URLFetcherDelegate: |
| 109 void OnURLFetchComplete(const net::URLFetcher* source) override; | 123 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 110 | 124 |
| 111 // Downloads app icon in order to compute Murmur2 hash. | 125 // Downloads app icon in order to compute Murmur2 hash. |
| 112 void DownloadAppIconAndComputeMurmur2Hash(); | 126 void DownloadAppIconAndComputeMurmur2Hash(); |
| 113 | 127 |
| 114 // Called with the computed Murmur2 hash for the app icon. | 128 // Called with the computed Murmur2 hash for the app icon. |
| 115 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); | 129 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); |
| 116 | 130 |
| 117 // Sends request to WebAPK server to create WebAPK. During a successful | 131 // Sends request to WebAPK server to create WebAPK. During a successful |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 132 const GURL& server_url); | 146 const GURL& server_url); |
| 133 | 147 |
| 134 // Called with the URL of generated WebAPK and the package name that the | 148 // Called with the URL of generated WebAPK and the package name that the |
| 135 // WebAPK should be installed at. | 149 // WebAPK should be installed at. |
| 136 void OnGotWebApkDownloadUrl(const GURL& download_url, | 150 void OnGotWebApkDownloadUrl(const GURL& download_url, |
| 137 const std::string& package_name); | 151 const std::string& package_name); |
| 138 | 152 |
| 139 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK | 153 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK |
| 140 // world readable and installs the WebAPK if the download was successful. | 154 // world readable and installs the WebAPK if the download was successful. |
| 141 // |file_path| is the file path that the WebAPK was downloaded to. | 155 // |file_path| is the file path that the WebAPK was downloaded to. |
| 142 // |package_name| is the package name that the WebAPK should be installed at. | |
| 143 void OnWebApkDownloaded(const base::FilePath& file_path, | 156 void OnWebApkDownloaded(const base::FilePath& file_path, |
| 144 const std::string& package_name, | |
| 145 FileDownloader::Result result); | 157 FileDownloader::Result result); |
| 146 | 158 |
| 147 // Called once the downloaded WebAPK has been made world readable. Installs | 159 // Called once the downloaded WebAPK has been made world readable. Installs |
| 148 // the WebAPK. | 160 // the WebAPK. |
| 149 // |file_path| is the file path that the WebAPK was downloaded to. | 161 // |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. | |
| 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, | |
| 155 bool change_permission_success); | 165 bool change_permission_success); |
| 156 | 166 |
| 157 // Called when the request to the WebAPK server times out or when the WebAPK | 167 // Called when the request to the WebAPK server times out or when the WebAPK |
| 158 // download times out. | 168 // download times out. |
| 159 void OnTimeout(); | 169 void OnTimeout(); |
| 160 | 170 |
| 161 // Called when the request to install the WebAPK is sent to Google Play. | |
| 162 void OnSuccess(); | |
| 163 | |
| 164 // Called if a WebAPK could not be created. WebApkInstaller only tracks the | 171 // Called if a WebAPK could not be created. WebApkInstaller only tracks the |
| 165 // WebAPK creation and the WebAPK download. It does not track the | 172 // WebAPK creation and the WebAPK download. It does not track the |
| 166 // WebAPK installation. OnFailure() is not called if the WebAPK could not be | 173 // WebAPK installation. OnFailure() is not called if the WebAPK could not be |
| 167 // installed. | 174 // installed. |
| 168 void OnFailure(); | 175 void OnFailure(); |
| 169 | 176 |
| 170 net::URLRequestContextGetter* request_context_getter_; | 177 net::URLRequestContextGetter* request_context_getter_; |
| 171 | 178 |
| 172 // Sends HTTP request to WebAPK server. | 179 // Sends HTTP request to WebAPK server. |
| 173 std::unique_ptr<net::URLFetcher> url_fetcher_; | 180 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 | 214 |
| 208 // WebAPK package name. | 215 // WebAPK package name. |
| 209 std::string webapk_package_; | 216 std::string webapk_package_; |
| 210 | 217 |
| 211 // WebAPK version code. | 218 // WebAPK version code. |
| 212 int webapk_version_; | 219 int webapk_version_; |
| 213 | 220 |
| 214 // Indicates whether the installer is for installing or updating a WebAPK. | 221 // Indicates whether the installer is for installing or updating a WebAPK. |
| 215 TaskType task_type_; | 222 TaskType task_type_; |
| 216 | 223 |
| 224 // Points to the Java Object. | |
| 225 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | |
| 226 | |
| 217 // Used to get |weak_ptr_|. | 227 // Used to get |weak_ptr_|. |
| 218 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 228 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
| 219 | 229 |
| 220 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 230 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
| 221 }; | 231 }; |
| 222 | 232 |
| 223 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 233 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| OLD | NEW |