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_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_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/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
16 #include "chrome/browser/android/shortcut_info.h" | 16 #include "chrome/browser/android/shortcut_info.h" |
17 #include "chrome/browser/net/file_downloader.h" | 17 #include "chrome/browser/net/file_downloader.h" |
18 #include "net/url_request/url_fetcher.h" | |
18 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
19 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 class FilePath; | 23 class FilePath; |
23 } | 24 } |
24 | 25 |
25 namespace content { | 26 namespace content { |
26 class BrowserContext; | 27 class BrowserContext; |
27 } | 28 } |
28 | 29 |
29 namespace net { | |
30 class URLFetcher; | |
31 class URLRequestContextGetter; | |
32 } | |
33 | |
34 namespace webapk { | 30 namespace webapk { |
35 class WebApk; | 31 class WebApk; |
36 } | 32 } |
37 | 33 |
38 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the | 34 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the |
39 // server, download it, and install it. | 35 // server, download it, and install it. |
40 class WebApkInstaller : public net::URLFetcherDelegate { | 36 class WebApkInstaller : public net::URLFetcherDelegate { |
41 public: | 37 public: |
38 // Called when either a request for creating/updating a WebAPK has been sent | |
39 // to Google Play or the create/update process fails. | |
40 // Parameters: | |
41 // - whether the request succeeds. | |
42 using FinishCallback = base::Callback<void(bool)>; | 42 using FinishCallback = base::Callback<void(bool)>; |
43 | 43 |
44 WebApkInstaller(const ShortcutInfo& shortcut_info, | 44 WebApkInstaller(const ShortcutInfo& shortcut_info, |
45 const SkBitmap& shorcut_icon); | 45 const SkBitmap& shorcut_icon); |
46 | |
46 ~WebApkInstaller() override; | 47 ~WebApkInstaller() override; |
47 | 48 |
48 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to | 49 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to |
49 // Google Play to install the generated WebAPK. Calls |callback| after the | 50 // Google Play to install the downloaded WebAPK. Calls |callback| after the |
50 // request to install the WebAPK is sent to Google Play. | 51 // request to install the WebAPK is sent to Google Play. |
51 void InstallAsync(content::BrowserContext* browser_context, | 52 void InstallAsync(content::BrowserContext* browser_context, |
52 const FinishCallback& callback); | 53 const FinishCallback& callback); |
53 | 54 |
54 // Same as InstallAsync() but uses the passed in |request_context_getter|. | 55 // Same as InstallAsync() but uses the passed in |request_context_getter|. |
55 void InstallAsyncWithURLRequestContextGetter( | 56 void InstallAsyncWithURLRequestContextGetter( |
56 net::URLRequestContextGetter* request_context_getter, | 57 net::URLRequestContextGetter* request_context_getter, |
57 const FinishCallback& callback); | 58 const FinishCallback& callback); |
58 | 59 |
60 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to | |
61 // the Google Play server to install the downloaded WebAPK. Calls |callback| | |
62 // after the request to download and install the WebAPK is sent to | |
pkotwicz
2016/08/11 22:02:44
Nit: "request to download and install" -> "request
Xi Han
2016/08/15 21:38:45
Done.
| |
63 // the Google Play server. | |
64 void UpdateAsync(content::BrowserContext* browser_context, | |
65 const FinishCallback& callback, | |
66 const std::string& webapk_package, | |
67 int webapk_version); | |
68 | |
69 // Same as UpdateAsync() but uses the passed in |request_context_getter|. | |
70 void UpdateAsyncWithURLRequestContextGetter( | |
71 net::URLRequestContextGetter* request_context_getter, | |
72 const FinishCallback& callback, | |
73 const std::string& webapk_package, | |
74 int webapk_version); | |
75 | |
59 // Sets the timeout for the server requests. | 76 // Sets the timeout for the server requests. |
60 void SetTimeoutMs(int timeout_ms); | 77 void SetTimeoutMs(int timeout_ms); |
61 | 78 |
62 protected: | 79 protected: |
63 // Starts installation of the downloaded WebAPK. Returns whether the install | 80 // Starts installation of the downloaded WebAPK. Returns whether the install |
64 // could be started. The installation may still fail if true is returned. | 81 // could be started. The installation may still fail if true is returned. |
65 // |file_path| is the file path that the WebAPK was downloaded to. | 82 // |file_path| is the file path that the WebAPK was downloaded to. |
66 // |package_name| is the package name that the WebAPK should be installed at. | 83 // |package_name| is the package name that the WebAPK should be installed at. |
67 virtual bool StartDownloadedWebApkInstall( | 84 virtual bool StartInstallingDownloadedWebApk( |
85 JNIEnv* env, | |
86 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, | |
87 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); | |
88 | |
89 // Starts updating of the downloaded WebAPK. Returns whether the updating | |
pkotwicz
2016/08/11 22:02:44
Nit: "updating of the downloaded WebAPK" -> "updat
Xi Han
2016/08/15 21:38:45
Done.
| |
90 // could be started. The updating may still fail if true is returned. | |
91 // |file_path| is the file path that the WebAPK was downloaded to. | |
92 // |package_name| is the package name of the WebAPK. | |
93 virtual bool StartUpdateUsingDownloadedWebApk( | |
68 JNIEnv* env, | 94 JNIEnv* env, |
69 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, | 95 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
70 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); | 96 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); |
71 | 97 |
72 private: | 98 private: |
99 enum TaskType { | |
100 UNDEFINED, | |
101 INSTALL, | |
102 UPDATE, | |
103 }; | |
104 | |
73 // net::URLFetcherDelegate: | 105 // net::URLFetcherDelegate: |
74 void OnURLFetchComplete(const net::URLFetcher* source) override; | 106 void OnURLFetchComplete(const net::URLFetcher* source) override; |
75 | 107 |
76 // Sends request to WebAPK server to create WebAPK. During a successful | 108 // Sends request to WebAPK server to create WebAPK. |
77 // request the WebAPK server responds with the URL of the generated WebAPK. | |
78 // |webapk| is the proto to send to the WebAPK server. | |
79 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); | 109 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); |
80 | 110 |
111 // Sends request to WebAPK server to update a WebAPK. | |
112 void SendUpdateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); | |
113 | |
114 // Sends a request to WebAPK server to create/update WebAPK. During a | |
115 // successful request the WebAPK server responds with the URL of the generated | |
116 // WebAPK. | |
117 void SendRequest(std::unique_ptr<webapk::WebApk> request_proto, | |
118 net::URLFetcher::RequestType request_type, | |
119 const GURL& server_url); | |
120 | |
81 // Called with the URL of generated WebAPK and the package name that the | 121 // Called with the URL of generated WebAPK and the package name that the |
82 // WebAPK should be installed at. | 122 // WebAPK should be installed at. |
83 void OnGotWebApkDownloadUrl(const GURL& download_url, | 123 void OnGotWebApkDownloadUrl(const GURL& download_url, |
84 const std::string& package_name); | 124 const std::string& package_name); |
85 | 125 |
86 // Called once the WebAPK has been downloaded. Installs the WebAPK if the | 126 // Called once the WebAPK has been downloaded. Installs the WebAPK if the |
87 // download was successful. | 127 // download was successful. |
88 // |file_path| is the file path that the WebAPK was downloaded to. | 128 // |file_path| is the file path that the WebAPK was downloaded to. |
89 // |package_name| is the package name that the WebAPK should be installed at. | 129 // |package_name| is the package name that the WebAPK should be installed at. |
90 void OnWebApkDownloaded(const base::FilePath& file_path, | 130 void OnWebApkDownloaded(const base::FilePath& file_path, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 // WebAPK server URL. | 172 // WebAPK server URL. |
133 GURL server_url_; | 173 GURL server_url_; |
134 | 174 |
135 // The number of milliseconds to wait for the WebAPK download URL from the | 175 // The number of milliseconds to wait for the WebAPK download URL from the |
136 // WebAPK server. | 176 // WebAPK server. |
137 int webapk_download_url_timeout_ms_; | 177 int webapk_download_url_timeout_ms_; |
138 | 178 |
139 // The number of milliseconds to wait for the WebAPK download to complete. | 179 // The number of milliseconds to wait for the WebAPK download to complete. |
140 int download_timeout_ms_; | 180 int download_timeout_ms_; |
141 | 181 |
182 // WebAPK package name. | |
183 std::string webapk_package_; | |
184 | |
185 // WebAPK version code. | |
186 int webapk_version_; | |
187 | |
188 // Indicates whether the installer is for installing or updating a WebAPK. | |
189 TaskType task_type_; | |
190 | |
142 // Used to get |weak_ptr_|. | 191 // Used to get |weak_ptr_|. |
143 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 192 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
144 | 193 |
145 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 194 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
146 }; | 195 }; |
147 | 196 |
148 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 197 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
OLD | NEW |