Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 15 #include "chrome/browser/android/shortcut_info.h" | 15 #include "chrome/browser/android/shortcut_info.h" |
| 16 #include "chrome/browser/net/file_downloader.h" | 16 #include "chrome/browser/net/file_downloader.h" |
| 17 #include "net/url_request/url_fetcher_delegate.h" | 17 #include "net/url_request/url_fetcher_delegate.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class FilePath; | 21 class FilePath; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 class BrowserContext; | 25 class BrowserContext; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace google { | |
| 29 namespace protobuf { | |
| 30 class MessageLite; | |
| 31 } | |
| 32 } | |
| 33 | |
| 28 namespace net { | 34 namespace net { |
| 29 class URLFetcher; | 35 class URLFetcher; |
| 30 class URLRequestContextGetter; | 36 class URLRequestContextGetter; |
| 31 } | 37 } |
| 32 | 38 |
| 33 namespace webapk { | 39 namespace webapk { |
| 34 class CreateWebApkRequest; | 40 class CreateWebApkRequest; |
| 41 class UpdateWebApkRequest; | |
| 42 class WebApk; | |
| 43 class WebApkResponse; | |
|
pkotwicz
2016/08/03 19:09:34
This forward declaration does not seem necessary a
Xi Han
2016/08/03 20:22:46
Except WebApk, other classes are removed.
| |
| 35 } | 44 } |
| 36 | 45 |
| 37 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the | 46 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the |
| 38 // server, download it, and install it. | 47 // server, download it, and install it. |
| 39 class WebApkInstaller : public net::URLFetcherDelegate { | 48 class WebApkInstaller : public net::URLFetcherDelegate { |
| 40 public: | 49 public: |
| 50 // Called when either a request of creating or updating WebAPK has been sent | |
| 51 // or the creation process of the WebAPK on the server side fails. | |
| 52 // Parameters: | |
| 53 // - whether the request succeeds. | |
| 41 using FinishCallback = base::Callback<void(bool)>; | 54 using FinishCallback = base::Callback<void(bool)>; |
| 42 | 55 |
| 43 WebApkInstaller(content::BrowserContext* browser_context, | 56 WebApkInstaller(content::BrowserContext* browser_context, |
| 44 const ShortcutInfo& shortcut_info, | 57 const ShortcutInfo& shortcut_info, |
| 45 const SkBitmap& shorcut_icon); | 58 const SkBitmap& shorcut_icon); |
| 59 | |
| 46 ~WebApkInstaller() override; | 60 ~WebApkInstaller() override; |
| 47 | 61 |
| 48 // Register JNI methods. | 62 // Register JNI methods. |
| 49 static bool Register(JNIEnv* env); | 63 static bool Register(JNIEnv* env); |
| 50 | 64 |
| 51 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to | 65 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to |
| 52 // Google Play to install the generated WebAPK. Calls |callback| after the | 66 // Google Play to install the generated WebAPK. Calls |callback| after the |
| 53 // request to install the WebAPK is sent to Google Play. | 67 // request to install the WebAPK is sent to Google Play. |
| 54 void InstallAsync(const FinishCallback& callback); | 68 void InstallAsync(const FinishCallback& callback); |
| 55 | 69 |
| 70 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to | |
| 71 // the Google Play server to download and install the generated WebAPK. Calls | |
| 72 // |callback| after the request to download and install the WebAPK is sent to | |
| 73 // the Google Play server. | |
| 74 void UpdateAsync(const FinishCallback& callback, | |
| 75 const std::string& webapk_package, | |
| 76 int version); | |
| 77 | |
| 56 private: | 78 private: |
| 57 // net::URLFetcherDelegate: | 79 // net::URLFetcherDelegate: |
| 58 void OnURLFetchComplete(const net::URLFetcher* source) override; | 80 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 59 | 81 |
| 60 // Initializes |request_context_getter_| on UI thread. | 82 // Initializes |request_context_getter_| on UI thread. |
| 61 void InitializeRequestContextGetterOnUIThread(); | 83 void InitializeRequestContextGetterOnUIThread(); |
| 62 | 84 |
| 63 // Sends request to WebAPK server to create WebAPK. During a successful | 85 // Sends request to WebAPK server to create WebAPK. |
| 64 // request the WebAPK server responds with the URL of the generated WebAPK. | |
| 65 void SendCreateWebApkRequest(); | 86 void SendCreateWebApkRequest(); |
| 66 | 87 |
| 88 // Sends request to WebAPK server to update a WebAPK. | |
| 89 void SendUpdateWebApkRequest(); | |
| 90 | |
| 91 // Sends a request to WebAPK server. During a successful request the | |
| 92 // WebAPK server responds with a URL to send to Google Play to | |
| 93 // download and install the generated WebAPK. | |
| 94 void SendRequest( | |
| 95 std::unique_ptr<::google::protobuf::MessageLite> request_proto); | |
| 96 | |
| 67 // Called with the URL of generated WebAPK and the package name that the | 97 // Called with the URL of generated WebAPK and the package name that the |
| 68 // WebAPK should be installed at. | 98 // WebAPK should be installed at. |
| 69 void OnGotWebApkDownloadUrl(const std::string& download_url, | 99 void OnGotWebApkDownloadUrl(const std::string& download_url, |
| 70 const std::string& package_name); | 100 const std::string& package_name); |
| 71 | 101 |
| 72 // Called once the WebAPK has been downloaded. Installs the WebAPK if the | 102 // Called once the WebAPK has been downloaded. Installs the WebAPK if the |
| 73 // download was successful. | 103 // download was successful. |
| 74 // |file_path| is the file path that the WebAPK was downloaded to. | 104 // |file_path| is the file path that the WebAPK was downloaded to. |
| 75 // |package_name| is the package name that the WebAPK should be installed at. | 105 // |package_name| is the package name that the WebAPK should be installed at. |
| 76 void OnWebApkDownloaded(const base::FilePath& file_path, | 106 void OnWebApkDownloaded(const base::FilePath& file_path, |
| 77 const std::string& package_name, | 107 const std::string& package_name, |
| 78 FileDownloader::Result result); | 108 FileDownloader::Result result); |
| 79 | 109 |
| 80 // Populates webapk::CreateWebApkRequest and returns it. | 110 // Populate the |webapk| field of a request. |
| 81 std::unique_ptr<webapk::CreateWebApkRequest> BuildCreateWebApkRequest(); | 111 void PopulateWebApkProto(webapk::WebApk* webapk); |
| 82 | 112 |
| 83 // Called when the request to the WebAPK server times out or when the WebAPK | 113 // Called when the request to the WebAPK server times out or when the WebAPK |
| 84 // download times out. | 114 // download times out. |
| 85 void OnTimeout(); | 115 void OnTimeout(); |
| 86 | 116 |
| 87 // Called when the request to install the WebAPK is sent to Google Play. | 117 // Called when the request to install the WebAPK is sent to Google Play. |
| 88 void OnSuccess(); | 118 void OnSuccess(); |
| 89 | 119 |
| 90 // Called if a WebAPK could not be created. WebApkInstaller only tracks the | 120 // Called if a WebAPK could not be created. WebApkInstaller only tracks the |
| 91 // WebAPK creation and the WebAPK download. It does not track the | 121 // WebAPK creation and the WebAPK download. It does not track the |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 111 | 141 |
| 112 // Web Manifest info. | 142 // Web Manifest info. |
| 113 const ShortcutInfo shortcut_info_; | 143 const ShortcutInfo shortcut_info_; |
| 114 | 144 |
| 115 // WebAPK app icon. | 145 // WebAPK app icon. |
| 116 const SkBitmap shortcut_icon_; | 146 const SkBitmap shortcut_icon_; |
| 117 | 147 |
| 118 // WebAPK server URL. | 148 // WebAPK server URL. |
| 119 GURL server_url_; | 149 GURL server_url_; |
| 120 | 150 |
| 151 // WebAPK package name. | |
| 152 std::string webapk_package_; | |
| 153 | |
| 154 // WebAPK version code. | |
| 155 int version_; | |
| 156 | |
| 121 // Used to get |weak_ptr_| on the IO thread. | 157 // Used to get |weak_ptr_| on the IO thread. |
| 122 base::WeakPtrFactory<WebApkInstaller> io_weak_ptr_factory_; | 158 base::WeakPtrFactory<WebApkInstaller> io_weak_ptr_factory_; |
| 123 | 159 |
| 124 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 160 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
| 125 }; | 161 }; |
| 126 | 162 |
| 127 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_BUILDER_H_ | 163 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| OLD | NEW |