Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_ | |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/timer/timer.h" | |
| 15 #include "chrome/browser/android/shortcut_info.h" | |
| 16 #include "chrome/browser/net/file_downloader.h" | |
| 17 #include "net/url_request/url_fetcher_delegate.h" | |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class FilePath; | |
| 22 } | |
| 23 | |
| 24 namespace content { | |
| 25 class BrowserContext; | |
| 26 } | |
| 27 | |
| 28 namespace net { | |
| 29 class URLFetcher; | |
| 30 class URLRequestContextGetter; | |
| 31 } | |
| 32 | |
| 33 namespace webapk { | |
| 34 class CreateWebApkRequest; | |
| 35 } | |
| 36 | |
| 37 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the | |
| 38 // server, download it, and install it. | |
| 39 class WebApkBuilder : public net::URLFetcherDelegate { | |
|
Robert Sesek
2016/07/25 23:01:33
Why is this not WebApkInstaller if it also install
pkotwicz
2016/07/26 17:54:46
Done.
| |
| 40 public: | |
| 41 typedef base::Callback<void(bool)> FinishCallback; | |
|
Robert Sesek
2016/07/25 23:01:33
using FinishCallback = base::Callback<void(bool);
pkotwicz
2016/07/26 17:54:46
Done.
| |
| 42 | |
| 43 WebApkBuilder(content::BrowserContext* browser_context, | |
| 44 const ShortcutInfo& shortcut_info, | |
| 45 const SkBitmap& shorcut_icon); | |
| 46 ~WebApkBuilder() override; | |
| 47 | |
| 48 // Register JNI methods. | |
| 49 static bool Register(JNIEnv* env); | |
| 50 | |
| 51 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to | |
|
Robert Sesek
2016/07/25 23:01:33
Can this be called more than once per object?
pkotwicz
2016/07/26 17:54:46
No it cannot
| |
| 52 // Google Play to install the generated WebAPK. Calls |callback| after the | |
| 53 // request to install the WebAPK is sent to Google Play. | |
| 54 void BuildAsync(const FinishCallback& callback); | |
|
Robert Sesek
2016/07/25 23:01:33
Similarly, shouldn't this be "Install" ?
pkotwicz
2016/07/26 17:54:46
Done.
| |
| 55 | |
| 56 private: | |
| 57 // net::URLFetcherDelegate: | |
| 58 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 59 | |
| 60 // Initializes |request_context_getter_| on UI thread. | |
| 61 void InitializeRequestContextGetterOnUIThread(); | |
| 62 | |
| 63 // Sends request to WebAPK server to create WebAPK. During a successful | |
| 64 // request the WebAPK server responds with the URL of the generated WebAPK. | |
| 65 void SendCreateWebApkRequest(); | |
| 66 | |
| 67 // Called with the URL of generated WebAPK and the package name that the | |
| 68 // WebAPK should be installed at. | |
| 69 void OnGotWebApkDownloadUrl(const std::string& download_url, | |
| 70 const std::string& package_name); | |
| 71 | |
| 72 // Called once the WebAPK has been downloaded. | |
|
Robert Sesek
2016/07/25 23:01:34
Mention that this installs the APK.
pkotwicz
2016/07/26 17:54:46
Done.
| |
| 73 // |file_path| is the file path that the WebAPK was downloaded to. | |
| 74 // |package_name| is the package name that the WebAPK should be installed at. | |
| 75 void OnWebApkDownloaded(const base::FilePath& file_path, | |
| 76 const std::string& package_name, | |
| 77 FileDownloader::Result result); | |
| 78 | |
| 79 // Populates webapk::CreateWebApkRequest and returns it. | |
| 80 std::unique_ptr<webapk::CreateWebApkRequest> BuildCreateWebApkRequest(); | |
| 81 | |
| 82 // Called when the request to the WebAPK server times out or when the WebAPK | |
| 83 // download times out. | |
| 84 void OnTimeout(); | |
| 85 | |
| 86 // Called when the request to install the WebAPK is sent to Google Play. | |
| 87 void OnSuccess(); | |
| 88 | |
| 89 // Called if a WebAPK could not be created. WebApkBuilder only tracks the | |
| 90 // WebAPK creation and the WebAPK download. It does not track the | |
| 91 // WebAPK installation. OnFailure() is not called if the WebAPK could not be | |
| 92 // installed. | |
| 93 void OnFailure(); | |
| 94 | |
| 95 content::BrowserContext* browser_context_; | |
| 96 net::URLRequestContextGetter* request_context_getter_; | |
| 97 | |
| 98 // Sends HTTP request to WebAPK server. | |
| 99 std::unique_ptr<net::URLFetcher> url_fetcher_; | |
| 100 | |
| 101 // Downloads WebAPK. | |
| 102 std::unique_ptr<FileDownloader> downloader_; | |
| 103 | |
| 104 // Fails WebApkBuilder if WebAPK server takes too long to respond or if the | |
| 105 // download takes too long. | |
| 106 base::OneShotTimer timer_; | |
| 107 | |
| 108 // Callback to call once WebApkBuilder succeeds or fails. | |
| 109 FinishCallback finish_callback_; | |
| 110 | |
| 111 // Web Manifest info. | |
| 112 const ShortcutInfo shortcut_info_; | |
| 113 | |
| 114 // WebAPK app icon. | |
| 115 const SkBitmap shortcut_icon_; | |
| 116 | |
| 117 // WebAPK server URL. | |
| 118 GURL server_url_; | |
| 119 | |
| 120 // Used to get |weak_ptr_| on the IO thread. | |
| 121 base::WeakPtrFactory<WebApkBuilder> io_weak_ptr_factory_; | |
| 122 | |
| 123 DISALLOW_COPY_AND_ASSIGN(WebApkBuilder); | |
| 124 }; | |
| 125 | |
| 126 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_ | |
| OLD | NEW |