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_ |