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

Side by Side Diff: chrome/browser/android/webapk/webapk_installer.h

Issue 2184913005: Add calls to the server to request WebAPK updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add Jni call for updateAsync. Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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 namespace google {
30 class URLFetcher; 31 namespace protobuf {
31 class URLRequestContextGetter; 32 class MessageLite;
33 }
32 } 34 }
33 35
34 namespace webapk { 36 namespace webapk {
35 class CreateWebApkRequest; 37 class WebApk;
36 } 38 }
37 39
38 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the 40 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the
39 // server, download it, and install it. 41 // server, download it, and install it.
40 class WebApkInstaller : public net::URLFetcherDelegate { 42 class WebApkInstaller : public net::URLFetcherDelegate {
41 public: 43 public:
44 // Called when either a request of creating or updating WebAPK has been sent
45 // or the creation process of the WebAPK on the server side fails.
46 // Parameters:
47 // - whether the request succeeds.
42 using FinishCallback = base::Callback<void(bool)>; 48 using FinishCallback = base::Callback<void(bool)>;
43 49
44 WebApkInstaller(const ShortcutInfo& shortcut_info, 50 WebApkInstaller(const ShortcutInfo& shortcut_info,
45 const SkBitmap& shorcut_icon); 51 const SkBitmap& shorcut_icon);
52
46 ~WebApkInstaller() override; 53 ~WebApkInstaller() override;
47 54
48 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to 55 // 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 56 // Google Play to install the generated WebAPK. Calls |callback| after the
50 // request to install the WebAPK is sent to Google Play. 57 // request to install the WebAPK is sent to Google Play.
51 void InstallAsync(content::BrowserContext* browser_context, 58 void InstallAsync(content::BrowserContext* browser_context,
52 const FinishCallback& callback); 59 const FinishCallback& callback);
53 60
54 // Same as InstallAsync() but uses the passed in |request_context_getter|. 61 // Same as InstallAsync() but uses the passed in |request_context_getter|.
55 void InstallAsyncWithURLRequestContextGetter( 62 void InstallAsyncWithURLRequestContextGetter(
56 net::URLRequestContextGetter* request_context_getter, 63 net::URLRequestContextGetter* request_context_getter,
57 const FinishCallback& callback); 64 const FinishCallback& callback);
58 65
66 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to
67 // the Google Play server to download and install the generated WebAPK. Calls
68 // |callback| after the request to download and install the WebAPK is sent to
69 // the Google Play server.
70 void UpdateAsync(content::BrowserContext* browser_context,
71 const FinishCallback& callback,
72 const std::string& webapk_package,
73 int version);
74
59 protected: 75 protected:
60 // Starts installation of the downloaded WebAPK. Returns whether the install 76 // Starts installation of the downloaded WebAPK. Returns whether the install
61 // could be started. The installation may still fail if true is returned. 77 // could be started. The installation may still fail if true is returned.
62 // |file_path| is the file path that the WebAPK was downloaded to. 78 // |file_path| is the file path that the WebAPK was downloaded to.
63 // |package_name| is the package name that the WebAPK should be installed at. 79 // |package_name| is the package name that the WebAPK should be installed at.
64 // The Method is virtual for the sake of testing. 80 // The Method is virtual for the sake of testing.
65 virtual bool StartDownloadedWebApkInstall( 81 virtual bool StartDownloadedWebApkInstall(
66 JNIEnv* env, 82 JNIEnv* env,
67 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, 83 const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
68 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); 84 const base::android::ScopedJavaLocalRef<jstring>& java_package_name);
69 85
70 private: 86 private:
87 enum TaskType {
88 UNDEFINED,
89 INSTALL,
90 UPDATE,
91 };
92
71 // net::URLFetcherDelegate: 93 // net::URLFetcherDelegate:
72 void OnURLFetchComplete(const net::URLFetcher* source) override; 94 void OnURLFetchComplete(const net::URLFetcher* source) override;
73 95
74 // Initializes |request_context_getter_| on UI thread. 96 // Initializes |request_context_getter_| on UI thread.
75 void InitializeRequestContextGetterOnUIThread( 97 void InitializeRequestContextGetterOnUIThread(
76 content::BrowserContext* browser_context); 98 content::BrowserContext* browser_context);
77 99
78 // Sends request to WebAPK server to create WebAPK. During a successful 100 // Sends request to WebAPK server to create WebAPK.
79 // request the WebAPK server responds with the URL of the generated WebAPK.
80 void SendCreateWebApkRequest(); 101 void SendCreateWebApkRequest();
81 102
103 // Sends request to WebAPK server to update a WebAPK.
104 void SendUpdateWebApkRequest();
105
106 // Sends a request to WebAPK server. During a successful request the
107 // WebAPK server responds with a URL to send to Google Play to
108 // download and install the generated WebAPK.
109 void SendRequest(
110 std::unique_ptr<::google::protobuf::MessageLite> request_proto,
111 net::URLFetcher::RequestType request_type,
112 const GURL& server_url);
113
82 // Called with the URL of generated WebAPK and the package name that the 114 // Called with the URL of generated WebAPK and the package name that the
83 // WebAPK should be installed at. 115 // WebAPK should be installed at.
84 void OnGotWebApkDownloadUrl(const std::string& download_url, 116 void OnGotWebApkDownloadUrl(const std::string& download_url,
85 const std::string& package_name); 117 const std::string& package_name);
86 118
87 // Called once the WebAPK has been downloaded. Installs the WebAPK if the 119 // Called once the WebAPK has been downloaded. Installs the WebAPK if the
88 // download was successful. 120 // download was successful.
89 // |file_path| is the file path that the WebAPK was downloaded to. 121 // |file_path| is the file path that the WebAPK was downloaded to.
90 // |package_name| is the package name that the WebAPK should be installed at. 122 // |package_name| is the package name that the WebAPK should be installed at.
91 void OnWebApkDownloaded(const base::FilePath& file_path, 123 void OnWebApkDownloaded(const base::FilePath& file_path,
92 const std::string& package_name, 124 const std::string& package_name,
93 FileDownloader::Result result); 125 FileDownloader::Result result);
94 126
95 // Populates webapk::CreateWebApkRequest and returns it. 127 // Populate the |webapk| field of a request.
96 std::unique_ptr<webapk::CreateWebApkRequest> BuildCreateWebApkRequest(); 128 void PopulateWebApkProto(webapk::WebApk* webapk);
97 129
98 // Called when the request to the WebAPK server times out or when the WebAPK 130 // Called when the request to the WebAPK server times out or when the WebAPK
99 // download times out. 131 // download times out.
100 void OnTimeout(); 132 void OnTimeout();
101 133
102 // Called when the request to install the WebAPK is sent to Google Play. 134 // Called when the request to install the WebAPK is sent to Google Play.
103 void OnSuccess(); 135 void OnSuccess();
104 136
105 // Called if a WebAPK could not be created. WebApkInstaller only tracks the 137 // Called if a WebAPK could not be created. WebApkInstaller only tracks the
106 // WebAPK creation and the WebAPK download. It does not track the 138 // WebAPK creation and the WebAPK download. It does not track the
(...skipping 18 matching lines...) Expand all
125 157
126 // Web Manifest info. 158 // Web Manifest info.
127 const ShortcutInfo shortcut_info_; 159 const ShortcutInfo shortcut_info_;
128 160
129 // WebAPK app icon. 161 // WebAPK app icon.
130 const SkBitmap shortcut_icon_; 162 const SkBitmap shortcut_icon_;
131 163
132 // WebAPK server URL. 164 // WebAPK server URL.
133 GURL server_url_; 165 GURL server_url_;
134 166
167 // WebAPK package name.
168 std::string webapk_package_;
169
170 // WebAPK version code.
171 int version_;
pkotwicz 2016/08/08 18:59:16 Nit: Rename to |webapk_version_| for the sake of c
Xi Han 2016/08/08 21:25:05 Done.
172
173 // A flag to indicate whether the installer is for installing or updating a
174 // WebAPK.
175 TaskType taskType_;
176
135 // Used to get |weak_ptr_| on the IO thread. 177 // Used to get |weak_ptr_| on the IO thread.
136 base::WeakPtrFactory<WebApkInstaller> io_weak_ptr_factory_; 178 base::WeakPtrFactory<WebApkInstaller> io_weak_ptr_factory_;
137 179
138 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); 180 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller);
139 }; 181 };
140 182
141 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ 183 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698