Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1180)

Side by Side Diff: chrome/browser/android/webapk/webapk_installer.h

Issue 2259553002: Make AppBannerInfoBar install WebAPK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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. The native WebApkInstaller owns the
38 // Java WebApkInstaller counterpart.
38 class WebApkInstaller : public net::URLFetcherDelegate { 39 class WebApkInstaller : public net::URLFetcherDelegate {
39 public: 40 public:
40 // Called when either a request for creating/updating a WebAPK has been sent 41 // Called when the creation/updating of a WebAPK is finished or failed.
41 // to Google Play or the create/update process fails.
42 // Parameters: 42 // Parameters:
43 // - whether the request succeeds. 43 // - whether the process succeeds.
44 using FinishCallback = base::Callback<void(bool)>; 44 // - the package name of the WebAPK.
45 using FinishCallback = base::Callback<void(bool, const std::string&)>;
45 46
46 WebApkInstaller(const ShortcutInfo& shortcut_info, 47 WebApkInstaller(const ShortcutInfo& shortcut_info,
47 const SkBitmap& shorcut_icon); 48 const SkBitmap& shorcut_icon);
48 49
49 ~WebApkInstaller() override; 50 ~WebApkInstaller() override;
50 51
51 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to 52 // 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 53 // Google Play to install the downloaded WebAPK. Calls |callback| after the
53 // request to install the WebAPK is sent to Google Play. 54 // request to install the WebAPK is sent to Google Play.
54 void InstallAsync(content::BrowserContext* browser_context, 55 void InstallAsync(content::BrowserContext* browser_context,
55 const FinishCallback& callback); 56 const FinishCallback& finish_callback);
56 57
57 // Same as InstallAsync() but uses the passed in |request_context_getter|. 58 // Same as InstallAsync() but uses the passed in |request_context_getter|.
58 void InstallAsyncWithURLRequestContextGetter( 59 void InstallAsyncWithURLRequestContextGetter(
59 net::URLRequestContextGetter* request_context_getter, 60 net::URLRequestContextGetter* request_context_getter,
60 const FinishCallback& callback); 61 const FinishCallback& finish_callback);
61 62
62 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to 63 // 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| 64 // 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. 65 // after the request to install the WebAPK is sent to the Google Play server.
65 void UpdateAsync(content::BrowserContext* browser_context, 66 void UpdateAsync(content::BrowserContext* browser_context,
66 const FinishCallback& callback, 67 const FinishCallback& callback,
67 const std::string& icon_murmur2_hash, 68 const std::string& icon_murmur2_hash,
68 const std::string& webapk_package, 69 const std::string& webapk_package,
69 int webapk_version); 70 int webapk_version);
70 71
71 // Same as UpdateAsync() but uses the passed in |request_context_getter|. 72 // Same as UpdateAsync() but uses the passed in |request_context_getter|.
72 void UpdateAsyncWithURLRequestContextGetter( 73 void UpdateAsyncWithURLRequestContextGetter(
73 net::URLRequestContextGetter* request_context_getter, 74 net::URLRequestContextGetter* request_context_getter,
74 const FinishCallback& callback, 75 const FinishCallback& callback,
75 const std::string& icon_murmur2_hash, 76 const std::string& icon_murmur2_hash,
76 const std::string& webapk_package, 77 const std::string& webapk_package,
77 int webapk_version); 78 int webapk_version);
78 79
79 // Sets the timeout for the server requests. 80 // Sets the timeout for the server requests.
80 void SetTimeoutMs(int timeout_ms); 81 void SetTimeoutMs(int timeout_ms);
81 82
83 // Called once the installation is complete or failed.
84 void OnInstallFinished(JNIEnv* env,
85 const base::android::JavaParamRef<jobject>& obj,
86 jboolean success);
87
88 // Registers JNI hooks.
89 static bool Register(JNIEnv* env);
90
82 protected: 91 protected:
83 // Starts installation of the downloaded WebAPK. Returns whether the install 92 // Starts installation of the downloaded WebAPK. Returns whether the install
84 // could be started. The installation may still fail if true is returned. 93 // 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. 94 // |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. 95 // |package_name| is the package name that the WebAPK should be installed at.
87 virtual bool StartInstallingDownloadedWebApk( 96 virtual bool StartInstallingDownloadedWebApk(
88 JNIEnv* env, 97 JNIEnv* env,
89 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, 98 const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
90 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); 99 const base::android::ScopedJavaLocalRef<jstring>& java_package_name);
91 100
92 // Starts update using the downloaded WebAPK. Returns whether the updating 101 // Starts update using the downloaded WebAPK. Returns whether the updating
93 // could be started. The updating may still fail if true is returned. 102 // 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. 103 // |file_path| is the file path that the WebAPK was downloaded to.
95 // |package_name| is the package name of the WebAPK. 104 // |package_name| is the package name of the WebAPK.
96 virtual bool StartUpdateUsingDownloadedWebApk( 105 virtual bool StartUpdateUsingDownloadedWebApk(
97 JNIEnv* env, 106 JNIEnv* env,
98 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, 107 const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
99 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); 108 const base::android::ScopedJavaLocalRef<jstring>& java_package_name);
100 109
110 // Called when the request to install the WebAPK is sent to Google Play.
111 void OnSuccess();
112
101 private: 113 private:
102 enum TaskType { 114 enum TaskType {
103 UNDEFINED, 115 UNDEFINED,
104 INSTALL, 116 INSTALL,
105 UPDATE, 117 UPDATE,
106 }; 118 };
107 119
120 // Create the Java object.
121 void CreateJavaRef();
122
108 // net::URLFetcherDelegate: 123 // net::URLFetcherDelegate:
109 void OnURLFetchComplete(const net::URLFetcher* source) override; 124 void OnURLFetchComplete(const net::URLFetcher* source) override;
110 125
111 // Downloads app icon in order to compute Murmur2 hash. 126 // Downloads app icon in order to compute Murmur2 hash.
112 void DownloadAppIconAndComputeMurmur2Hash(); 127 void DownloadAppIconAndComputeMurmur2Hash();
113 128
114 // Called with the computed Murmur2 hash for the app icon. 129 // Called with the computed Murmur2 hash for the app icon.
115 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); 130 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash);
116 131
117 // Sends request to WebAPK server to create WebAPK. During a successful 132 // Sends request to WebAPK server to create WebAPK. During a successful
(...skipping 14 matching lines...) Expand all
132 const GURL& server_url); 147 const GURL& server_url);
133 148
134 // Called with the URL of generated WebAPK and the package name that the 149 // Called with the URL of generated WebAPK and the package name that the
135 // WebAPK should be installed at. 150 // WebAPK should be installed at.
136 void OnGotWebApkDownloadUrl(const GURL& download_url, 151 void OnGotWebApkDownloadUrl(const GURL& download_url,
137 const std::string& package_name); 152 const std::string& package_name);
138 153
139 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK 154 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK
140 // world readable and installs the WebAPK if the download was successful. 155 // world readable and installs the WebAPK if the download was successful.
141 // |file_path| is the file path that the WebAPK was downloaded to. 156 // |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, 157 void OnWebApkDownloaded(const base::FilePath& file_path,
144 const std::string& package_name,
145 FileDownloader::Result result); 158 FileDownloader::Result result);
146 159
147 // Called once the downloaded WebAPK has been made world readable. Installs 160 // Called once the downloaded WebAPK has been made world readable. Installs
148 // the WebAPK. 161 // the WebAPK.
149 // |file_path| is the file path that the WebAPK was downloaded to. 162 // |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 163 // |change_permission_success| is whether the WebAPK could be made world
152 // readable. 164 // readable.
153 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, 165 void OnWebApkMadeWorldReadable(const base::FilePath& file_path,
154 const std::string& package_name,
155 bool change_permission_success); 166 bool change_permission_success);
156 167
157 // Called when the request to the WebAPK server times out or when the WebAPK 168 // Called when the request to the WebAPK server times out or when the WebAPK
158 // download times out. 169 // download times out.
159 void OnTimeout(); 170 void OnTimeout();
160 171
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 172 // Called if a WebAPK could not be created. WebApkInstaller only tracks the
165 // WebAPK creation and the WebAPK download. It does not track the 173 // WebAPK creation and the WebAPK download. It does not track the
166 // WebAPK installation. OnFailure() is not called if the WebAPK could not be 174 // WebAPK installation. OnFailure() is not called if the WebAPK could not be
167 // installed. 175 // installed.
168 void OnFailure(); 176 void OnFailure();
169 177
170 net::URLRequestContextGetter* request_context_getter_; 178 net::URLRequestContextGetter* request_context_getter_;
171 179
172 // Sends HTTP request to WebAPK server. 180 // Sends HTTP request to WebAPK server.
173 std::unique_ptr<net::URLFetcher> url_fetcher_; 181 std::unique_ptr<net::URLFetcher> url_fetcher_;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 215
208 // WebAPK package name. 216 // WebAPK package name.
209 std::string webapk_package_; 217 std::string webapk_package_;
210 218
211 // WebAPK version code. 219 // WebAPK version code.
212 int webapk_version_; 220 int webapk_version_;
213 221
214 // Indicates whether the installer is for installing or updating a WebAPK. 222 // Indicates whether the installer is for installing or updating a WebAPK.
215 TaskType task_type_; 223 TaskType task_type_;
216 224
225 // Points to the Java Object.
226 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
227
217 // Used to get |weak_ptr_|. 228 // Used to get |weak_ptr_|.
218 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; 229 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_;
219 230
220 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); 231 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller);
221 }; 232 };
222 233
223 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ 234 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698