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

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

Issue 2184913005: Add calls to the server to request WebAPK updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 4 years, 4 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
11 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 #include "chrome/browser/android/shortcut_info.h" 16 #include "chrome/browser/android/shortcut_info.h"
17 #include "chrome/browser/net/file_downloader.h" 17 #include "chrome/browser/net/file_downloader.h"
18 #include "net/url_request/url_fetcher.h"
18 #include "net/url_request/url_fetcher_delegate.h" 19 #include "net/url_request/url_fetcher_delegate.h"
19 #include "third_party/skia/include/core/SkBitmap.h" 20 #include "third_party/skia/include/core/SkBitmap.h"
20 21
21 namespace base { 22 namespace base {
22 class FilePath; 23 class FilePath;
23 } 24 }
24 25
25 namespace content { 26 namespace content {
26 class BrowserContext; 27 class BrowserContext;
27 } 28 }
28 29
29 namespace net {
30 class URLFetcher;
31 class URLRequestContextGetter;
32 }
33
34 namespace webapk { 30 namespace webapk {
35 class WebApk; 31 class WebApk;
36 } 32 }
37 33
38 class WebApkIconHasher; 34 class WebApkIconHasher;
39 35
40 // 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
41 // server, download it, and install it. 37 // server, download it, and install it.
42 class WebApkInstaller : public net::URLFetcherDelegate { 38 class WebApkInstaller : public net::URLFetcherDelegate {
43 public: 39 public:
40 // Called when either a request for creating/updating a WebAPK has been sent
41 // to Google Play or the create/update process fails.
42 // Parameters:
43 // - whether the request succeeds.
44 using FinishCallback = base::Callback<void(bool)>; 44 using FinishCallback = base::Callback<void(bool)>;
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 ~WebApkInstaller() override; 49 ~WebApkInstaller() override;
49 50
50 // 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
51 // Google Play to install the generated WebAPK. Calls |callback| after the 52 // Google Play to install the downloaded WebAPK. Calls |callback| after the
52 // request to install the WebAPK is sent to Google Play. 53 // request to install the WebAPK is sent to Google Play.
53 void InstallAsync(content::BrowserContext* browser_context, 54 void InstallAsync(content::BrowserContext* browser_context,
54 const FinishCallback& callback); 55 const FinishCallback& callback);
55 56
56 // Same as InstallAsync() but uses the passed in |request_context_getter|. 57 // Same as InstallAsync() but uses the passed in |request_context_getter|.
57 void InstallAsyncWithURLRequestContextGetter( 58 void InstallAsyncWithURLRequestContextGetter(
58 net::URLRequestContextGetter* request_context_getter, 59 net::URLRequestContextGetter* request_context_getter,
59 const FinishCallback& callback); 60 const FinishCallback& callback);
60 61
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|
64 // after the request to install the WebAPK is sent to the Google Play server.
65 void UpdateAsync(content::BrowserContext* browser_context,
66 const FinishCallback& callback,
67 const std::string& webapk_package,
68 int webapk_version);
69
70 // Same as UpdateAsync() but uses the passed in |request_context_getter|.
71 void UpdateAsyncWithURLRequestContextGetter(
72 net::URLRequestContextGetter* request_context_getter,
73 const FinishCallback& callback,
74 const std::string& webapk_package,
75 int webapk_version);
76
61 // Sets the timeout for the server requests. 77 // Sets the timeout for the server requests.
62 void SetTimeoutMs(int timeout_ms); 78 void SetTimeoutMs(int timeout_ms);
63 79
64 protected: 80 protected:
65 // Starts installation of the downloaded WebAPK. Returns whether the install 81 // Starts installation of the downloaded WebAPK. Returns whether the install
66 // could be started. The installation may still fail if true is returned. 82 // could be started. The installation may still fail if true is returned.
67 // |file_path| is the file path that the WebAPK was downloaded to. 83 // |file_path| is the file path that the WebAPK was downloaded to.
68 // |package_name| is the package name that the WebAPK should be installed at. 84 // |package_name| is the package name that the WebAPK should be installed at.
69 virtual bool StartDownloadedWebApkInstall( 85 virtual bool StartInstallingDownloadedWebApk(
86 JNIEnv* env,
87 const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
88 const base::android::ScopedJavaLocalRef<jstring>& java_package_name);
89
90 // Starts update using the downloaded WebAPK. Returns whether the updating
91 // could be started. The updating may still fail if true is returned.
92 // |file_path| is the file path that the WebAPK was downloaded to.
93 // |package_name| is the package name of the WebAPK.
94 virtual bool StartUpdateUsingDownloadedWebApk(
70 JNIEnv* env, 95 JNIEnv* env,
71 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, 96 const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
72 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); 97 const base::android::ScopedJavaLocalRef<jstring>& java_package_name);
73 98
74 private: 99 private:
100 enum TaskType {
101 UNDEFINED,
102 INSTALL,
103 UPDATE,
104 };
105
75 // net::URLFetcherDelegate: 106 // net::URLFetcherDelegate:
76 void OnURLFetchComplete(const net::URLFetcher* source) override; 107 void OnURLFetchComplete(const net::URLFetcher* source) override;
77 108
78 // Downloads app icon in order to compute Murmur2 hash. 109 // Downloads app icon in order to compute Murmur2 hash.
79 void DownloadAppIconAndComputeMurmur2Hash(); 110 void DownloadAppIconAndComputeMurmur2Hash();
80 111
81 // Called with the computed Murmur2 hash for the app icon. 112 // Called with the computed Murmur2 hash for the app icon.
82 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); 113 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash);
83 114
84 // Sends request to WebAPK server to create WebAPK. During a successful 115 // Sends request to WebAPK server to create WebAPK. During a successful
85 // request the WebAPK server responds with the URL of the generated WebAPK. 116 // request the WebAPK server responds with the URL of the generated WebAPK.
86 // |webapk| is the proto to send to the WebAPK server. 117 // |webapk| is the proto to send to the WebAPK server.
87 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); 118 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto);
88 119
120 // Sends request to WebAPK server to update a WebAPK. During a successful
121 // request the WebAPK server responds with the URL of the generated WebAPK.
122 // |webapk| is the proto to send to the WebAPK server.
123 void SendUpdateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto);
124
125 // Sends a request to WebAPK server to create/update WebAPK. During a
126 // successful request the WebAPK server responds with the URL of the generated
127 // WebAPK.
128 void SendRequest(std::unique_ptr<webapk::WebApk> request_proto,
129 net::URLFetcher::RequestType request_type,
130 const GURL& server_url);
131
89 // Called with the URL of generated WebAPK and the package name that the 132 // Called with the URL of generated WebAPK and the package name that the
90 // WebAPK should be installed at. 133 // WebAPK should be installed at.
91 void OnGotWebApkDownloadUrl(const GURL& download_url, 134 void OnGotWebApkDownloadUrl(const GURL& download_url,
92 const std::string& package_name); 135 const std::string& package_name);
93 136
94 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK 137 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK
95 // world readable and installs the WebAPK if the download was successful. 138 // world readable and installs the WebAPK if the download was successful.
96 // |file_path| is the file path that the WebAPK was downloaded to. 139 // |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. 140 // |package_name| is the package name that the WebAPK should be installed at.
98 void OnWebApkDownloaded(const base::FilePath& file_path, 141 void OnWebApkDownloaded(const base::FilePath& file_path,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // WebAPK server URL. 196 // WebAPK server URL.
154 GURL server_url_; 197 GURL server_url_;
155 198
156 // The number of milliseconds to wait for the WebAPK download URL from the 199 // The number of milliseconds to wait for the WebAPK download URL from the
157 // WebAPK server. 200 // WebAPK server.
158 int webapk_download_url_timeout_ms_; 201 int webapk_download_url_timeout_ms_;
159 202
160 // The number of milliseconds to wait for the WebAPK download to complete. 203 // The number of milliseconds to wait for the WebAPK download to complete.
161 int download_timeout_ms_; 204 int download_timeout_ms_;
162 205
206 // WebAPK package name.
207 std::string webapk_package_;
208
209 // WebAPK version code.
210 int webapk_version_;
211
212 // Indicates whether the installer is for installing or updating a WebAPK.
213 TaskType task_type_;
214
163 // Used to get |weak_ptr_|. 215 // Used to get |weak_ptr_|.
164 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; 216 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_;
165 217
166 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); 218 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller);
167 }; 219 };
168 220
169 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ 221 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/webapk/webapk.proto ('k') | chrome/browser/android/webapk/webapk_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698