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

Unified 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: Add Jni call for updateAsync. 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 side-by-side diff with in-line comments
Download patch
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 2dd425de7932a5b2ac3b82f04a774dea95ecb4d2..9909449d2e6d4bb9b4fe9f22dcfc387911879e5d 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,23 +27,29 @@ namespace content {
class BrowserContext;
}
-namespace net {
-class URLFetcher;
-class URLRequestContextGetter;
+namespace google {
+namespace protobuf {
+class MessageLite;
+}
}
namespace webapk {
-class CreateWebApkRequest;
+class WebApk;
}
// Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the
// server, download it, and install it.
class WebApkInstaller : public net::URLFetcherDelegate {
public:
+ // Called when either a request of creating or updating WebAPK has been sent
+ // or the creation process of the WebAPK on the server side 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
@@ -56,6 +63,15 @@ 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 download and install the generated WebAPK. Calls
+ // |callback| after the request to download and install the WebAPK is sent to
+ // the Google Play server.
+ void UpdateAsync(content::BrowserContext* browser_context,
+ const FinishCallback& callback,
+ const std::string& webapk_package,
+ int version);
+
protected:
// Starts installation of the downloaded WebAPK. Returns whether the install
// could be started. The installation may still fail if true is returned.
@@ -68,6 +84,12 @@ class WebApkInstaller : public net::URLFetcherDelegate {
const base::android::ScopedJavaLocalRef<jstring>& java_package_name);
private:
+ enum TaskType {
+ UNDEFINED,
+ INSTALL,
+ UPDATE,
+ };
+
// net::URLFetcherDelegate:
void OnURLFetchComplete(const net::URLFetcher* source) override;
@@ -75,10 +97,20 @@ class WebApkInstaller : public net::URLFetcherDelegate {
void InitializeRequestContextGetterOnUIThread(
content::BrowserContext* browser_context);
- // Sends request to WebAPK server to create WebAPK. During a successful
- // request the WebAPK server responds with the URL of the generated WebAPK.
+ // Sends request to WebAPK server to create WebAPK.
void SendCreateWebApkRequest();
+ // Sends request to WebAPK server to update a WebAPK.
+ void SendUpdateWebApkRequest();
+
+ // Sends a request to WebAPK server. During a successful request the
+ // WebAPK server responds with a URL to send to Google Play to
+ // download and install the generated WebAPK.
+ void SendRequest(
+ std::unique_ptr<::google::protobuf::MessageLite> 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 std::string& download_url,
@@ -92,8 +124,8 @@ class WebApkInstaller : public net::URLFetcherDelegate {
const std::string& package_name,
FileDownloader::Result result);
- // Populates webapk::CreateWebApkRequest and returns it.
- std::unique_ptr<webapk::CreateWebApkRequest> BuildCreateWebApkRequest();
+ // Populate the |webapk| field of a request.
+ void PopulateWebApkProto(webapk::WebApk* webapk);
// Called when the request to the WebAPK server times out or when the WebAPK
// download times out.
@@ -132,6 +164,16 @@ class WebApkInstaller : public net::URLFetcherDelegate {
// WebAPK server URL.
GURL server_url_;
+ // WebAPK package name.
+ std::string webapk_package_;
+
+ // WebAPK version code.
+ int version_;
pkotwicz 2016/08/08 18:59:16 Nit: Rename to |webapk_version_| for the sake of c
Xi Han 2016/08/08 21:25:05 Done.
+
+ // A flag to indicate whether the installer is for installing or updating a
+ // WebAPK.
+ TaskType taskType_;
+
// Used to get |weak_ptr_| on the IO thread.
base::WeakPtrFactory<WebApkInstaller> io_weak_ptr_factory_;

Powered by Google App Engine
This is Rietveld 408576698