Index: chrome/browser/android/webapk/webapk_installer.h |
diff --git a/chrome/browser/android/webapk/webapk_installer.h b/chrome/browser/android/webapk/webapk_installer.h |
index 3c18002005e730d6976687d6a06bab77892cafdf..81b0741135f800907a4153c8575f6faf04955622 100644 |
--- a/chrome/browser/android/webapk/webapk_installer.h |
+++ b/chrome/browser/android/webapk/webapk_installer.h |
@@ -15,6 +15,7 @@ |
#include "base/timer/timer.h" |
#include "chrome/browser/android/shortcut_info.h" |
#include "chrome/browser/net/file_downloader.h" |
+#include "net/url_request/url_fetcher.h" |
#include "net/url_request/url_fetcher_delegate.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
@@ -26,11 +27,6 @@ namespace content { |
class BrowserContext; |
} |
-namespace net { |
-class URLFetcher; |
-class URLRequestContextGetter; |
-} |
- |
namespace webapk { |
class WebApk; |
} |
@@ -39,14 +35,19 @@ class WebApk; |
// server, download it, and install it. |
class WebApkInstaller : public net::URLFetcherDelegate { |
public: |
+ // Called when either a request for creating/updating a WebAPK has been sent |
+ // to Google Play or the create/update process fails. |
+ // Parameters: |
+ // - whether the request succeeds. |
using FinishCallback = base::Callback<void(bool)>; |
WebApkInstaller(const ShortcutInfo& shortcut_info, |
const SkBitmap& shorcut_icon); |
+ |
~WebApkInstaller() override; |
// Talks to the Chrome WebAPK server to generate a WebAPK on the server and to |
- // Google Play to install the generated WebAPK. Calls |callback| after the |
+ // Google Play to install the downloaded WebAPK. Calls |callback| after the |
// request to install the WebAPK is sent to Google Play. |
void InstallAsync(content::BrowserContext* browser_context, |
const FinishCallback& callback); |
@@ -56,6 +57,22 @@ class WebApkInstaller : public net::URLFetcherDelegate { |
net::URLRequestContextGetter* request_context_getter, |
const FinishCallback& callback); |
+ // Talks to the Chrome WebAPK server to update a WebAPK on the server and to |
+ // the Google Play server to install the downloaded WebAPK. Calls |callback| |
+ // after the request to download and install the WebAPK is sent to |
pkotwicz
2016/08/11 22:02:44
Nit: "request to download and install" -> "request
Xi Han
2016/08/15 21:38:45
Done.
|
+ // the Google Play server. |
+ void UpdateAsync(content::BrowserContext* browser_context, |
+ const FinishCallback& callback, |
+ const std::string& webapk_package, |
+ int webapk_version); |
+ |
+ // Same as UpdateAsync() but uses the passed in |request_context_getter|. |
+ void UpdateAsyncWithURLRequestContextGetter( |
+ net::URLRequestContextGetter* request_context_getter, |
+ const FinishCallback& callback, |
+ const std::string& webapk_package, |
+ int webapk_version); |
+ |
// Sets the timeout for the server requests. |
void SetTimeoutMs(int timeout_ms); |
@@ -64,20 +81,43 @@ class WebApkInstaller : public net::URLFetcherDelegate { |
// could be started. The installation may still fail if true is returned. |
// |file_path| is the file path that the WebAPK was downloaded to. |
// |package_name| is the package name that the WebAPK should be installed at. |
- virtual bool StartDownloadedWebApkInstall( |
+ virtual bool StartInstallingDownloadedWebApk( |
+ JNIEnv* env, |
+ const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
+ const base::android::ScopedJavaLocalRef<jstring>& java_package_name); |
+ |
+ // Starts updating of the downloaded WebAPK. Returns whether the updating |
pkotwicz
2016/08/11 22:02:44
Nit: "updating of the downloaded WebAPK" -> "updat
Xi Han
2016/08/15 21:38:45
Done.
|
+ // could be started. The updating may still fail if true is returned. |
+ // |file_path| is the file path that the WebAPK was downloaded to. |
+ // |package_name| is the package name of the WebAPK. |
+ virtual bool StartUpdateUsingDownloadedWebApk( |
JNIEnv* env, |
const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
const base::android::ScopedJavaLocalRef<jstring>& java_package_name); |
private: |
+ enum TaskType { |
+ UNDEFINED, |
+ INSTALL, |
+ UPDATE, |
+ }; |
+ |
// net::URLFetcherDelegate: |
void OnURLFetchComplete(const net::URLFetcher* source) override; |
- // Sends request to WebAPK server to create WebAPK. During a successful |
- // request the WebAPK server responds with the URL of the generated WebAPK. |
- // |webapk| is the proto to send to the WebAPK server. |
+ // Sends request to WebAPK server to create WebAPK. |
void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); |
+ // Sends request to WebAPK server to update a WebAPK. |
+ void SendUpdateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); |
+ |
+ // Sends a request to WebAPK server to create/update WebAPK. During a |
+ // successful request the WebAPK server responds with the URL of the generated |
+ // WebAPK. |
+ void SendRequest(std::unique_ptr<webapk::WebApk> request_proto, |
+ net::URLFetcher::RequestType request_type, |
+ const GURL& server_url); |
+ |
// Called with the URL of generated WebAPK and the package name that the |
// WebAPK should be installed at. |
void OnGotWebApkDownloadUrl(const GURL& download_url, |
@@ -139,6 +179,15 @@ class WebApkInstaller : public net::URLFetcherDelegate { |
// The number of milliseconds to wait for the WebAPK download to complete. |
int download_timeout_ms_; |
+ // WebAPK package name. |
+ std::string webapk_package_; |
+ |
+ // WebAPK version code. |
+ int webapk_version_; |
+ |
+ // Indicates whether the installer is for installing or updating a WebAPK. |
+ TaskType task_type_; |
+ |
// Used to get |weak_ptr_|. |
base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |