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

Unified Diff: chrome/browser/android/webapk/webapk_builder.h

Issue 2138973002: Initial CL for talking to the WebAPK server to generate WebAPK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'webapk_builder_impl0' into webapk_builder_impl2 Created 4 years, 5 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_builder.h
diff --git a/chrome/browser/android/webapk/webapk_builder.h b/chrome/browser/android/webapk/webapk_builder.h
new file mode 100644
index 0000000000000000000000000000000000000000..ac22dedb6b7b49eee356e3f6f488ca094bdd13e1
--- /dev/null
+++ b/chrome/browser/android/webapk/webapk_builder.h
@@ -0,0 +1,119 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_
+#define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_
+
+#include <jni.h>
+#include <memory>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/timer/timer.h"
+#include "chrome/browser/android/shortcut_info.h"
+#include "net/url_request/url_fetcher_delegate.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+namespace content {
+class BrowserContext;
+}
+
+namespace net {
+class URLFetcher;
+class URLRequestContextGetter;
+}
+
+namespace webapk {
+class CreateWebApkRequest;
+}
+
+// Talks to Chrome WebAPK server and Google Play servers to generate a WebAPK on
+// the server, download it, and install it.
+class WebApkBuilder : public net::URLFetcherDelegate {
+ public:
+ typedef base::Callback<void(bool)> FinishCallback;
+
+ WebApkBuilder(content::BrowserContext* browser_context,
+ const ShortcutInfo& shortcut_info,
+ const SkBitmap& shorcut_icon);
+ ~WebApkBuilder() override;
+
+ // Register JNI methods.
+ static bool Register(JNIEnv* env);
+
+ // Converts a blink::WebDisplayMode to a string. Returns one of
+ // https://www.w3.org/TR/appmanifest/#dfn-fallback-display-mode
+ static std::string DisplayToString(blink::WebDisplayMode display);
+
+ // Converts a blink::WebScreenOrientationLockType to a string. Returns one of
+ // https://www.w3.org/TR/screen-orientation/#orientationlocktype-enum
+ static std::string OrientationToString(
+ blink::WebScreenOrientationLockType orientation);
+
+ // Converts a color from the format specified in content::Manifest to a CSS
+ // string.
+ static std::string ColorToString(int64_t color);
+
+ // Talks to Chrome WebAPK server and Google Play servers to generate a WebAPK
+ // on the server, download it, and install it. Calls |callback| after the
+ // request to download the WebAPK is sent tot he Google Play server.
Xi Han 2016/07/14 14:53:16 "sent tot he" -> "send to the". The description is
pkotwicz 2016/07/20 05:13:41 You are right that the comment was a little confus
+ void BuildAsync(const FinishCallback& callback);
+
+ private:
+ // net::URLFetcherDelegate:
+ void OnURLFetchComplete(const net::URLFetcher* source) override;
+
+ // Initializes |request_context_getter_| on UI thread.
+ void InitializeRequestContextGetterOnUIThread();
+
+ // Sends request to WebAPK server to create WebAPK. During a successful
+ // request the WebAPK server responds with a URL to send to Google Play to
+ // download the generated WebAPK.
Xi Han 2016/07/14 14:53:16 to download and install the generated WebAPK.
pkotwicz 2016/07/20 05:13:41 I changed "to download" to "to download and instal
+ void SendCreateWebApkRequest();
+
+ // Called with the URL to send to the Google Play server to download the
Xi Han 2016/07/14 14:53:16 "to download" -> "to install".
+ // WebAPK.
+ void OnGotMarketUrl(const std::string& signed_market_url);
+
+ // Populates webapk::CreateWebApkRequest and returns it.
+ std::unique_ptr<webapk::CreateWebApkRequest> BuildCreateWebApkRequest();
+
+ // Called when the request to the server times out.
+ void OnTimeout();
+
+ // Called when the request to download the WebAPK is sent to the Google Play
Xi Han 2016/07/14 14:53:16 Maybe "download and install"?
+ // server.
+ void OnSuccess();
+
+ // Called if a WebAPK could not be created. WebApkBuilder only tracks the
+ // generation of the WebAPK on the WebAPK server. It does not track the WebAPK
+ // download and installation. OnFailure() is not called if the WebAPK could
+ // not be downloaded or installed.
+ void OnFailure();
+
+ content::BrowserContext* browser_context_;
+ net::URLRequestContextGetter* request_context_getter_;
+
+ // Sends HTTP request to WebAPK server.
+ std::unique_ptr<net::URLFetcher> url_fetcher_;
+
+ // Fails WebApkBuilder if WebAPK server takes too long to respond.
+ base::OneShotTimer timer_;
+
+ // Callback to call once WebApkBuilder succeeds or fails.
+ FinishCallback finish_callback_;
+
+ // Web Manifest info.
+ const ShortcutInfo shortcut_info_;
+
+ // WebAPK app icon.
+ const SkBitmap shortcut_icon_;
+
+ // WebAPK server URL.
+ GURL server_url_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebApkBuilder);
+};
+
+#endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_

Powered by Google App Engine
This is Rietveld 408576698