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

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

Issue 2733543002: [Android:WebAPK] Don't add webapp to homescreen if WebAPK install times out part 1/3 (Closed)
Patch Set: Merge branch 'start' into refactor_shortcut_helper3 Created 3 years, 9 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 <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "chrome/browser/android/shortcut_info.h" 17 #include "chrome/browser/android/shortcut_info.h"
18 #include "chrome/browser/android/webapk/webapk_install_service.h"
18 #include "chrome/browser/net/file_downloader.h" 19 #include "chrome/browser/net/file_downloader.h"
19 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
20 #include "net/url_request/url_fetcher_delegate.h" 21 #include "net/url_request/url_fetcher_delegate.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
22 23
23 namespace base { 24 namespace base {
24 class FilePath; 25 class FilePath;
25 } 26 }
26 27
27 namespace content { 28 namespace content {
28 class BrowserContext; 29 class BrowserContext;
29 } 30 }
30 31
31 namespace webapk { 32 namespace webapk {
32 class WebApk; 33 class WebApk;
33 } 34 }
34 35
35 class WebApkIconHasher; 36 class WebApkIconHasher;
36 37
37 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the 38 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the
38 // server, download it, and install it. The native WebApkInstaller owns the 39 // server, download it, and install it. The native WebApkInstaller owns the
39 // Java WebApkInstaller counterpart. 40 // Java WebApkInstaller counterpart.
40 class WebApkInstaller : public net::URLFetcherDelegate { 41 class WebApkInstaller : public net::URLFetcherDelegate {
41 public: 42 public:
42 // Called when the creation/updating of a WebAPK is finished or failed. 43 using FinishCallback = WebApkInstallService::FinishCallback;
43 // Parameters:
44 // - whether the process succeeds.
45 // - the package name of the WebAPK.
46 // - true if Chrome received a "request updates less frequently" directive
47 // from the WebAPK server.
48 using FinishCallback = base::Callback<void(bool, bool, const std::string&)>;
49 44
50 ~WebApkInstaller() override; 45 ~WebApkInstaller() override;
51 46
52 // Creates a self-owned WebApkInstaller instance and talks to the Chrome 47 // Creates a self-owned WebApkInstaller instance and talks to the Chrome
53 // WebAPK server to generate a WebAPK on the server and to Google Play to 48 // WebAPK server to generate a WebAPK on the server and to Google Play to
54 // install the downloaded WebAPK. Calls |callback| once the install completed 49 // install the downloaded WebAPK. Calls |callback| once the install completed
55 // or failed. 50 // or failed.
56 static void InstallAsync(content::BrowserContext* context, 51 static void InstallAsync(content::BrowserContext* context,
57 const ShortcutInfo& shortcut_info, 52 const ShortcutInfo& shortcut_info,
58 const SkBitmap& shortcut_icon, 53 const SkBitmap& shortcut_icon,
(...skipping 27 matching lines...) Expand all
86 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, 81 const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
87 bool is_manifest_stale, 82 bool is_manifest_stale,
88 const FinishCallback& callback); 83 const FinishCallback& callback);
89 84
90 // Sets the timeout for the server requests. 85 // Sets the timeout for the server requests.
91 void SetTimeoutMs(int timeout_ms); 86 void SetTimeoutMs(int timeout_ms);
92 87
93 // Called once the installation is complete or failed. 88 // Called once the installation is complete or failed.
94 void OnInstallFinished(JNIEnv* env, 89 void OnInstallFinished(JNIEnv* env,
95 const base::android::JavaParamRef<jobject>& obj, 90 const base::android::JavaParamRef<jobject>& obj,
96 jboolean success); 91 jint result);
97 92
98 // Creates a WebApk install or update request. 93 // Creates a WebApk install or update request.
99 // Should be used only for testing. 94 // Should be used only for testing.
100 void BuildWebApkProtoInBackgroundForTesting( 95 void BuildWebApkProtoInBackgroundForTesting(
101 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, 96 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback,
102 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, 97 const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
103 bool is_manifest_stale); 98 bool is_manifest_stale);
104 99
105 // Registers JNI hooks. 100 // Registers JNI hooks.
106 static bool Register(JNIEnv* env); 101 static bool Register(JNIEnv* env);
(...skipping 20 matching lines...) Expand all
127 // Returns whether Google Play supports installing WebAPKs. 122 // Returns whether Google Play supports installing WebAPKs.
128 virtual bool CanUseGooglePlayInstallService(); 123 virtual bool CanUseGooglePlayInstallService();
129 124
130 // Called when the package name of the WebAPK is available and the install 125 // Called when the package name of the WebAPK is available and the install
131 // or update request is handled by Google Play. 126 // or update request is handled by Google Play.
132 virtual void InstallOrUpdateWebApkFromGooglePlay( 127 virtual void InstallOrUpdateWebApkFromGooglePlay(
133 const std::string& package_name, 128 const std::string& package_name,
134 int version, 129 int version,
135 const std::string& token); 130 const std::string& token);
136 131
137 // Called when the request to install the WebAPK is sent to Google Play. 132 // Called when the install or update process has completed or failed.
138 void OnSuccess(); 133 void OnResult(WebApkInstallResult result);
139 134
140 private: 135 private:
141 enum TaskType { 136 enum TaskType {
142 UNDEFINED, 137 UNDEFINED,
143 INSTALL, 138 INSTALL,
144 UPDATE, 139 UPDATE,
145 }; 140 };
146 141
147 // Create the Java object. 142 // Create the Java object.
148 void CreateJavaRef(); 143 void CreateJavaRef();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 FileDownloader::Result result); 208 FileDownloader::Result result);
214 209
215 // Called once the downloaded WebAPK has been made world readable. Installs 210 // Called once the downloaded WebAPK has been made world readable. Installs
216 // the WebAPK. 211 // the WebAPK.
217 // |file_path| is the file path that the WebAPK was downloaded to. 212 // |file_path| is the file path that the WebAPK was downloaded to.
218 // |change_permission_success| is whether the WebAPK could be made world 213 // |change_permission_success| is whether the WebAPK could be made world
219 // readable. 214 // readable.
220 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, 215 void OnWebApkMadeWorldReadable(const base::FilePath& file_path,
221 bool change_permission_success); 216 bool change_permission_success);
222 217
223 // Called when the request to the WebAPK server times out or when the WebAPK
224 // download times out.
225 void OnTimeout();
226
227 // Called if a WebAPK could not be created. WebApkInstaller only tracks the
228 // WebAPK creation and the WebAPK download. It does not track the
229 // WebAPK installation. OnFailure() is not called if the WebAPK could not be
230 // installed.
231 void OnFailure();
232
233 net::URLRequestContextGetter* request_context_getter_; 218 net::URLRequestContextGetter* request_context_getter_;
234 219
235 // Sends HTTP request to WebAPK server. 220 // Sends HTTP request to WebAPK server.
236 std::unique_ptr<net::URLFetcher> url_fetcher_; 221 std::unique_ptr<net::URLFetcher> url_fetcher_;
237 222
238 // Downloads app icon and computes Murmur2 hash. 223 // Downloads app icon and computes Murmur2 hash.
239 std::unique_ptr<WebApkIconHasher> icon_hasher_; 224 std::unique_ptr<WebApkIconHasher> icon_hasher_;
240 225
241 // Downloads WebAPK. 226 // Downloads WebAPK.
242 std::unique_ptr<FileDownloader> downloader_; 227 std::unique_ptr<FileDownloader> downloader_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // Points to the Java Object. 264 // Points to the Java Object.
280 base::android::ScopedJavaGlobalRef<jobject> java_ref_; 265 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
281 266
282 // Used to get |weak_ptr_|. 267 // Used to get |weak_ptr_|.
283 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; 268 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_;
284 269
285 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); 270 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller);
286 }; 271 };
287 272
288 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ 273 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/webapk/webapk_install_service.cc ('k') | chrome/browser/android/webapk/webapk_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698