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

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: 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_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_
pkotwicz 2016/08/03 01:07:06 😲 Thanks for catching this!
Xi Han 2016/08/03 17:30:05 I used a refactoring tool which is super cool to m
pkotwicz 2016/08/03 19:09:34 Awesome! 😀 I will try it out some time
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 net { 28 namespace net {
29 class URLFetcher; 29 class URLFetcher;
30 class URLRequestContextGetter; 30 class URLRequestContextGetter;
31 } 31 }
32 32
33 namespace webapk { 33 namespace webapk {
34 class CreateWebApkRequest; 34 class CreateWebApkRequest;
35 class UpdateWebApkRequest;
36 class WebApkResponse;
35 } 37 }
36 38
37 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the 39 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the
38 // server, download it, and install it. 40 // server, download it, and install it.
39 class WebApkInstaller : public net::URLFetcherDelegate { 41 class WebApkInstaller : public net::URLFetcherDelegate {
40 public: 42 public:
41 using FinishCallback = base::Callback<void(bool)>; 43 // Called when either a request of creating or updating WebAPK has been sent
44 // or the creation process of the WebAPK on the server side fails.
45 // Parameters:
46 // - whether the request succeeds.
47 // - the package name of the WebAPK, empty for a request of creating a WebAPK.
48 using FinishCallback = base::Callback<void(bool, const std::string&)>;
42 49
43 WebApkInstaller(content::BrowserContext* browser_context, 50 WebApkInstaller(content::BrowserContext* browser_context,
44 const ShortcutInfo& shortcut_info, 51 const ShortcutInfo& shortcut_info,
45 const SkBitmap& shorcut_icon); 52 const SkBitmap& shorcut_icon);
53
54 WebApkInstaller(content::BrowserContext* browser_context,
55 const ShortcutInfo& shortcut_info,
56 const SkBitmap& shortcut_icon,
57 const std::string& WebApkPackageName);
pkotwicz 2016/08/03 01:07:06 Nit: |webapk_package_name| and |webapk_version_cod
Xi Han 2016/08/03 17:30:05 Done.
58
46 ~WebApkInstaller() override; 59 ~WebApkInstaller() override;
47 60
48 // Register JNI methods. 61 // Register JNI methods.
49 static bool Register(JNIEnv* env); 62 static bool Register(JNIEnv* env);
50 63
51 // Talks to the Chrome WebAPK server to generate a WebAPK on the server and to 64 // 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 65 // Google Play to install the generated WebAPK. Calls |callback| after the
53 // request to install the WebAPK is sent to Google Play. 66 // request to install the WebAPK is sent to Google Play.
54 void InstallAsync(const FinishCallback& callback); 67 void InstallAsync(const FinishCallback& callback);
55 68
69 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to
70 // the Google Play server to download and install the generated WebAPK. Calls
71 // |callback| after the request to download and install the WebAPK is sent to
72 // the Google Play server.
73 void UpdateAsync(const FinishCallback& callback);
74
56 private: 75 private:
57 // net::URLFetcherDelegate: 76 // net::URLFetcherDelegate:
58 void OnURLFetchComplete(const net::URLFetcher* source) override; 77 void OnURLFetchComplete(const net::URLFetcher* source) override;
59 78
60 // Initializes |request_context_getter_| on UI thread. 79 // Initializes |request_context_getter_| on UI thread when requests to create
61 void InitializeRequestContextGetterOnUIThread(); 80 // a WebAPK.
81 void InitializeCreateRequestContextGetterOnUIThread();
62 82
63 // Sends request to WebAPK server to create WebAPK. During a successful 83 // Initializes |request_context_getter_| on UI thread when requests to update
64 // request the WebAPK server responds with the URL of the generated WebAPK. 84 // a WebAPK.
85 void InitializeUpdateRequestContextGetterOnUIThread();
86
87 // Sends request to WebAPK server to create WebAPK.
65 void SendCreateWebApkRequest(); 88 void SendCreateWebApkRequest();
66 89
90 // Sends request to WebAPK server to update a WebAPK.
91 void SendUpdateWebApkRequest();
92
93 // Sends a templated request to WebAPK server. During a successful
94 // request the WebAPK server responds with a URL to send to Google Play to
95 // download and install the generated WebAPK.
96 template <class RequestProto>
97 void SendRequest(std::unique_ptr<RequestProto> request_proto);
98
67 // Called with the URL of generated WebAPK and the package name that the 99 // Called with the URL of generated WebAPK and the package name that the
68 // WebAPK should be installed at. 100 // WebAPK should be installed at.
69 void OnGotWebApkDownloadUrl(const std::string& download_url, 101 void OnGotWebApkDownloadUrl(const std::string& download_url,
70 const std::string& package_name); 102 const std::string& package_name);
71 103
72 // Called once the WebAPK has been downloaded. Installs the WebAPK if the 104 // Called once the WebAPK has been downloaded. Installs the WebAPK if the
73 // download was successful. 105 // download was successful.
74 // |file_path| is the file path that the WebAPK was downloaded to. 106 // |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. 107 // |package_name| is the package name that the WebAPK should be installed at.
76 void OnWebApkDownloaded(const base::FilePath& file_path, 108 void OnWebApkDownloaded(const base::FilePath& file_path,
77 const std::string& package_name, 109 const std::string& package_name,
78 FileDownloader::Result result); 110 FileDownloader::Result result);
79 111
80 // Populates webapk::CreateWebApkRequest and returns it. 112 // Populate a templated request and returns it.
81 std::unique_ptr<webapk::CreateWebApkRequest> BuildCreateWebApkRequest(); 113 template <class RequestProto>
114 std::unique_ptr<RequestProto> BuildRequest(
115 std::unique_ptr<RequestProto> request);
82 116
83 // Called when the request to the WebAPK server times out or when the WebAPK 117 // Called when the request to the WebAPK server times out or when the WebAPK
84 // download times out. 118 // download times out.
85 void OnTimeout(); 119 void OnTimeout();
86 120
87 // Called when the request to install the WebAPK is sent to Google Play. 121 // Called when the request to install the WebAPK is sent to Google Play.
88 void OnSuccess(); 122 void OnSuccess();
89 123
90 // Called if a WebAPK could not be created. WebApkInstaller only tracks the 124 // Called if a WebAPK could not be created. WebApkInstaller only tracks the
91 // WebAPK creation and the WebAPK download. It does not track the 125 // WebAPK creation and the WebAPK download. It does not track the
(...skipping 19 matching lines...) Expand all
111 145
112 // Web Manifest info. 146 // Web Manifest info.
113 const ShortcutInfo shortcut_info_; 147 const ShortcutInfo shortcut_info_;
114 148
115 // WebAPK app icon. 149 // WebAPK app icon.
116 const SkBitmap shortcut_icon_; 150 const SkBitmap shortcut_icon_;
117 151
118 // WebAPK server URL. 152 // WebAPK server URL.
119 GURL server_url_; 153 GURL server_url_;
120 154
155 std::string webapk_package_;
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698