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

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

Issue 2231843003: Take Murmur2 hash of untransformed icon when creating WebAPK part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'webapk_builder_impl2_directory' into webapk_builder_impl2_hash 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
(...skipping 17 matching lines...) Expand all
28 28
29 namespace net { 29 namespace net {
30 class URLFetcher; 30 class URLFetcher;
31 class URLRequestContextGetter; 31 class URLRequestContextGetter;
32 } 32 }
33 33
34 namespace webapk { 34 namespace webapk {
35 class WebApk; 35 class WebApk;
36 } 36 }
37 37
38 class WebApkIconHasher;
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:
42 using FinishCallback = base::Callback<void(bool)>; 44 using FinishCallback = base::Callback<void(bool)>;
43 45
44 WebApkInstaller(const ShortcutInfo& shortcut_info, 46 WebApkInstaller(const ShortcutInfo& shortcut_info,
45 const SkBitmap& shorcut_icon); 47 const SkBitmap& shorcut_icon);
46 ~WebApkInstaller() override; 48 ~WebApkInstaller() override;
47 49
(...skipping 18 matching lines...) Expand all
66 // |package_name| is the package name that the WebAPK should be installed at. 68 // |package_name| is the package name that the WebAPK should be installed at.
67 virtual bool StartDownloadedWebApkInstall( 69 virtual bool StartDownloadedWebApkInstall(
68 JNIEnv* env, 70 JNIEnv* env,
69 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, 71 const base::android::ScopedJavaLocalRef<jstring>& java_file_path,
70 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); 72 const base::android::ScopedJavaLocalRef<jstring>& java_package_name);
71 73
72 private: 74 private:
73 // net::URLFetcherDelegate: 75 // net::URLFetcherDelegate:
74 void OnURLFetchComplete(const net::URLFetcher* source) override; 76 void OnURLFetchComplete(const net::URLFetcher* source) override;
75 77
78 // Downloads app icon in order to compute Murmur2 hash.
79 void DownloadAppIconAndComputeMurmur2Hash();
80
81 // Called with the computed Murmur2 hash for the app icon.
82 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash);
83
76 // Sends request to WebAPK server to create WebAPK. During a successful 84 // Sends request to WebAPK server to create WebAPK. During a successful
77 // request the WebAPK server responds with the URL of the generated WebAPK. 85 // request the WebAPK server responds with the URL of the generated WebAPK.
78 // |webapk| is the proto to send to the WebAPK server. 86 void SendCreateWebApkRequest();
79 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); 87
88 void SendCreateWebApkRequestWithProto(
89 std::unique_ptr<webapk::WebApk> webapk_proto);
80 90
81 // Called with the URL of generated WebAPK and the package name that the 91 // Called with the URL of generated WebAPK and the package name that the
82 // WebAPK should be installed at. 92 // WebAPK should be installed at.
83 void OnGotWebApkDownloadUrl(const GURL& download_url, 93 void OnGotWebApkDownloadUrl(const GURL& download_url,
84 const std::string& package_name); 94 const std::string& package_name);
85 95
86 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK 96 // Called once the WebAPK has been downloaded. Makes the downloaded WebAPK
87 // world readable and installs the WebAPK if the download was successful. 97 // world readable and installs the WebAPK if the download was successful.
88 // |file_path| is the file path that the WebAPK was downloaded to. 98 // |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. 99 // |package_name| is the package name that the WebAPK should be installed at.
90 void OnWebApkDownloaded(const base::FilePath& file_path, 100 void OnWebApkDownloaded(const base::FilePath& file_path,
91 const std::string& package_name, 101 const std::string& package_name,
92 FileDownloader::Result result); 102 FileDownloader::Result result);
93 103
94 // Called once the downloaded WebAPK has been made world readable. Installs 104 // Called once the downloaded WebAPK has been made world readable. Installs
95 // the WebAPK. 105 // the WebAPK.
96 // |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.
97 // |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.
98 // |change_permission_success| is whether the WebAPK could be made world 108 // |change_permission_success| is whether the WebAPK could be made world
99 // readable. 109 // readable.
100 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, 110 void OnWebApkMadeWorldReadable(const base::FilePath& file_path,
101 const std::string& package_name, 111 const std::string& package_name,
102 bool change_permission_success); 112 bool change_permission_success);
103 113
104 // Populates webapk::WebApk and returns it.
105 // Must be called on a worker thread because it encodes an SkBitmap.
106 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground();
107
108 // Called when the request to the WebAPK server times out or when the WebAPK 114 // Called when the request to the WebAPK server times out or when the WebAPK
109 // download times out. 115 // download times out.
110 void OnTimeout(); 116 void OnTimeout();
111 117
112 // Called when the request to install the WebAPK is sent to Google Play. 118 // Called when the request to install the WebAPK is sent to Google Play.
113 void OnSuccess(); 119 void OnSuccess();
114 120
115 // Called if a WebAPK could not be created. WebApkInstaller only tracks the 121 // Called if a WebAPK could not be created. WebApkInstaller only tracks the
116 // WebAPK creation and the WebAPK download. It does not track the 122 // WebAPK creation and the WebAPK download. It does not track the
117 // WebAPK installation. OnFailure() is not called if the WebAPK could not be 123 // WebAPK installation. OnFailure() is not called if the WebAPK could not be
118 // installed. 124 // installed.
119 void OnFailure(); 125 void OnFailure();
120 126
121 net::URLRequestContextGetter* request_context_getter_; 127 net::URLRequestContextGetter* request_context_getter_;
122 128
123 // Sends HTTP request to WebAPK server. 129 // Sends HTTP request to WebAPK server.
124 std::unique_ptr<net::URLFetcher> url_fetcher_; 130 std::unique_ptr<net::URLFetcher> url_fetcher_;
125 131
132 // Downloads app icon and computes Murmur2 hash.
133 std::unique_ptr<WebApkIconHasher> icon_hasher_;
134
126 // Downloads WebAPK. 135 // Downloads WebAPK.
127 std::unique_ptr<FileDownloader> downloader_; 136 std::unique_ptr<FileDownloader> downloader_;
128 137
129 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the 138 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the
130 // download takes too long. 139 // download takes too long.
131 base::OneShotTimer timer_; 140 base::OneShotTimer timer_;
132 141
133 // Callback to call once WebApkInstaller succeeds or fails. 142 // Callback to call once WebApkInstaller succeeds or fails.
134 FinishCallback finish_callback_; 143 FinishCallback finish_callback_;
135 144
136 // Web Manifest info. 145 // Web Manifest info.
137 const ShortcutInfo shortcut_info_; 146 const ShortcutInfo shortcut_info_;
138 147
139 // WebAPK app icon. 148 // WebAPK app icon.
140 const SkBitmap shortcut_icon_; 149 const SkBitmap shortcut_icon_;
141 150
151 // Murmur2 hash of the bitmap at the app icon URL prior to any transformations
152 // being applied to the bitmap (such as encoding/decoding the icon bitmap).
153 std::string shortcut_icon_murmur2_hash_;
154
142 // WebAPK server URL. 155 // WebAPK server URL.
143 GURL server_url_; 156 GURL server_url_;
144 157
145 // The number of milliseconds to wait for the WebAPK download URL from the 158 // The number of milliseconds to wait for the WebAPK download URL from the
146 // WebAPK server. 159 // WebAPK server.
147 int webapk_download_url_timeout_ms_; 160 int webapk_download_url_timeout_ms_;
148 161
149 // The number of milliseconds to wait for the WebAPK download to complete. 162 // The number of milliseconds to wait for the WebAPK download to complete.
150 int download_timeout_ms_; 163 int download_timeout_ms_;
151 164
152 // Used to get |weak_ptr_|. 165 // Used to get |weak_ptr_|.
153 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; 166 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_;
154 167
155 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); 168 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller);
156 }; 169 };
157 170
158 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ 171 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698