| 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 #include "chrome/browser/android/webapk/webapk_installer.h" | 5 #include "chrome/browser/android/webapk/webapk_installer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
| 10 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 11 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 12 #include "base/android/path_utils.h" | 13 #include "base/android/path_utils.h" |
| 13 #include "base/bind.h" | 14 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/files/file_path.h" |
| 17 #include "base/files/file_util.h" |
| 15 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/pickle.h" |
| 17 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/task_runner_util.h" | 25 #include "base/task_runner_util.h" |
| 22 #include "base/task_scheduler/post_task.h" | 26 #include "base/task_scheduler/post_task.h" |
| 23 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
| 24 #include "base/timer/elapsed_timer.h" | 28 #include "base/timer/elapsed_timer.h" |
| 25 #include "chrome/browser/android/shortcut_helper.h" | 29 #include "chrome/browser/android/shortcut_helper.h" |
| 26 #include "chrome/browser/android/webapk/chrome_webapk_host.h" | 30 #include "chrome/browser/android/webapk/chrome_webapk_host.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 42 #include "ui/gfx/color_utils.h" | 46 #include "ui/gfx/color_utils.h" |
| 43 #include "url/gurl.h" | 47 #include "url/gurl.h" |
| 44 | 48 |
| 45 namespace { | 49 namespace { |
| 46 | 50 |
| 47 // The default WebAPK server URL. | 51 // The default WebAPK server URL. |
| 48 const char kDefaultServerUrl[] = | 52 const char kDefaultServerUrl[] = |
| 49 "https://webapk.googleapis.com/v1/webApks/" | 53 "https://webapk.googleapis.com/v1/webApks/" |
| 50 "?alt=proto&key=AIzaSyAoI6v-F31-3t9NunLYEiKcPIqgTJIUZBw"; | 54 "?alt=proto&key=AIzaSyAoI6v-F31-3t9NunLYEiKcPIqgTJIUZBw"; |
| 51 | 55 |
| 56 // The current file format version of the file for storing update requests. |
| 57 const int kCurrentUpdateFileFormatVersion = 1; |
| 58 |
| 52 // The MIME type of the POST data sent to the server. | 59 // The MIME type of the POST data sent to the server. |
| 53 const char kProtoMimeType[] = "application/x-protobuf"; | 60 const char kProtoMimeType[] = "application/x-protobuf"; |
| 54 | 61 |
| 55 // The default number of milliseconds to wait for the WebAPK download URL from | 62 // The default number of milliseconds to wait for the WebAPK download URL from |
| 56 // the WebAPK server. | 63 // the WebAPK server. |
| 57 const int kWebApkDownloadUrlTimeoutMs = 60000; | 64 const int kWebApkDownloadUrlTimeoutMs = 60000; |
| 58 | 65 |
| 59 // Returns the WebAPK server URL based on the command line. | 66 // Returns the WebAPK server URL based on the command line. |
| 60 GURL GetServerUrl() { | 67 GURL GetServerUrl() { |
| 61 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 68 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 111 |
| 105 // Populates the webapk::Image::image_data field of |image| with |icon|. | 112 // Populates the webapk::Image::image_data field of |image| with |icon|. |
| 106 void SetImageData(webapk::Image* image, const SkBitmap& icon) { | 113 void SetImageData(webapk::Image* image, const SkBitmap& icon) { |
| 107 std::vector<unsigned char> png_bytes; | 114 std::vector<unsigned char> png_bytes; |
| 108 gfx::PNGCodec::EncodeBGRASkBitmap(icon, false, &png_bytes); | 115 gfx::PNGCodec::EncodeBGRASkBitmap(icon, false, &png_bytes); |
| 109 image->set_image_data(&png_bytes.front(), png_bytes.size()); | 116 image->set_image_data(&png_bytes.front(), png_bytes.size()); |
| 110 } | 117 } |
| 111 | 118 |
| 112 // Populates webapk::WebApk and returns it. | 119 // Populates webapk::WebApk and returns it. |
| 113 // Must be called on a worker thread because it encodes an SkBitmap. | 120 // Must be called on a worker thread because it encodes an SkBitmap. |
| 114 std::unique_ptr<std::vector<uint8_t>> BuildProtoInBackground( | 121 std::unique_ptr<std::string> BuildProtoInBackground( |
| 115 const ShortcutInfo& shortcut_info, | 122 const ShortcutInfo& shortcut_info, |
| 116 const SkBitmap& primary_icon, | 123 const SkBitmap& primary_icon, |
| 117 const SkBitmap& badge_icon, | 124 const SkBitmap& badge_icon, |
| 118 const std::string& package_name, | 125 const std::string& package_name, |
| 119 const std::string& version, | 126 const std::string& version, |
| 120 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 127 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 121 bool is_manifest_stale) { | 128 bool is_manifest_stale) { |
| 122 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); | 129 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); |
| 123 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); | 130 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); |
| 124 webapk->set_requester_application_package( | 131 webapk->set_requester_application_package( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 shortcut_info.best_primary_icon_url) { | 175 shortcut_info.best_primary_icon_url) { |
| 169 SetImageData(image, badge_icon); | 176 SetImageData(image, badge_icon); |
| 170 } | 177 } |
| 171 image->add_usages(webapk::Image::BADGE_ICON); | 178 image->add_usages(webapk::Image::BADGE_ICON); |
| 172 } | 179 } |
| 173 image->set_src(entry.first); | 180 image->set_src(entry.first); |
| 174 image->set_hash(entry.second); | 181 image->set_hash(entry.second); |
| 175 } | 182 } |
| 176 | 183 |
| 177 size_t serialized_size = webapk->ByteSize(); | 184 size_t serialized_size = webapk->ByteSize(); |
| 178 std::unique_ptr<std::vector<uint8_t>> serialized_proto = | 185 std::unique_ptr<std::string> serialized_proto = |
| 179 base::MakeUnique<std::vector<uint8_t>>(); | 186 base::MakeUnique<std::string>(); |
| 180 serialized_proto->resize(serialized_size); | 187 serialized_proto->resize(serialized_size); |
| 181 webapk->SerializeToArray(serialized_proto->data(), serialized_size); | 188 webapk->SerializeToString(serialized_proto.get()); |
| 182 return serialized_proto; | 189 return serialized_proto; |
| 183 } | 190 } |
| 184 | 191 |
| 192 // Builds the WebAPK proto for an update or an install request and stores it |
| 193 // to |file|. Returns whether the proto was successfully written to disk. |
| 194 bool StoreUpdateRequestToDiskInBackground( |
| 195 const base::FilePath& file, |
| 196 const ShortcutInfo& shortcut_info, |
| 197 const SkBitmap& primary_icon, |
| 198 const SkBitmap& badge_icon, |
| 199 const std::string& package_name, |
| 200 const std::string& version, |
| 201 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 202 bool is_manifest_stale) { |
| 203 base::ThreadRestrictions::AssertIOAllowed(); |
| 204 |
| 205 std::unique_ptr<std::string> proto = BuildProtoInBackground( |
| 206 shortcut_info, primary_icon, badge_icon, package_name, version, |
| 207 icon_url_to_murmur2_hash, is_manifest_stale); |
| 208 |
| 209 base::Pickle to_store; |
| 210 to_store.WriteInt(kCurrentUpdateFileFormatVersion); |
| 211 to_store.WriteString(package_name); |
| 212 to_store.WriteString(shortcut_info.url.spec()); |
| 213 to_store.WriteString16(shortcut_info.short_name); |
| 214 to_store.WriteString(*proto); |
| 215 |
| 216 // Create directory if it does not exist. |
| 217 base::CreateDirectory(file.DirName()); |
| 218 |
| 219 int bytes_written = base::WriteFile( |
| 220 file, static_cast<const char*>(to_store.data()), to_store.size()); |
| 221 return (bytes_written != -1); |
| 222 } |
| 223 |
| 224 // Reads |file| and returns contents. Must be called on a background thread. |
| 225 std::unique_ptr<std::string> ReadFileFromDiskInBackground( |
| 226 const base::FilePath& file) { |
| 227 base::ThreadRestrictions::AssertIOAllowed(); |
| 228 std::unique_ptr<std::string> update_request = base::MakeUnique<std::string>(); |
| 229 base::ReadFileToString(file, update_request.get()); |
| 230 return update_request; |
| 231 } |
| 232 |
| 185 // Returns task runner for running background tasks. | 233 // Returns task runner for running background tasks. |
| 186 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { | 234 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { |
| 187 return base::CreateTaskRunnerWithTraits( | 235 return base::CreateTaskRunnerWithTraits( |
| 188 {base::MayBlock(), base::TaskPriority::BACKGROUND, | 236 {base::MayBlock(), base::TaskPriority::BACKGROUND, |
| 189 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}); | 237 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}); |
| 190 } | 238 } |
| 191 | 239 |
| 192 } // anonymous namespace | 240 } // anonymous namespace |
| 193 | 241 |
| 194 WebApkInstaller::~WebApkInstaller() { | 242 WebApkInstaller::~WebApkInstaller() { |
| 195 JNIEnv* env = base::android::AttachCurrentThread(); | 243 JNIEnv* env = base::android::AttachCurrentThread(); |
| 196 Java_WebApkInstaller_destroy(env, java_ref_); | 244 Java_WebApkInstaller_destroy(env, java_ref_); |
| 197 java_ref_.Reset(); | 245 java_ref_.Reset(); |
| 198 } | 246 } |
| 199 | 247 |
| 200 // static | 248 // static |
| 201 void WebApkInstaller::InstallAsync(content::BrowserContext* context, | 249 void WebApkInstaller::InstallAsync(content::BrowserContext* context, |
| 202 const ShortcutInfo& shortcut_info, | 250 const ShortcutInfo& shortcut_info, |
| 203 const SkBitmap& primary_icon, | 251 const SkBitmap& primary_icon, |
| 204 const SkBitmap& badge_icon, | 252 const SkBitmap& badge_icon, |
| 205 const FinishCallback& finish_callback) { | 253 const FinishCallback& finish_callback) { |
| 206 // The installer will delete itself when it is done. | 254 // The installer will delete itself when it is done. |
| 207 WebApkInstaller* installer = new WebApkInstaller(context); | 255 WebApkInstaller* installer = new WebApkInstaller(context); |
| 208 installer->InstallAsync(shortcut_info, primary_icon, badge_icon, | 256 installer->InstallAsync(shortcut_info, primary_icon, badge_icon, |
| 209 finish_callback); | 257 finish_callback); |
| 210 } | 258 } |
| 211 | 259 |
| 212 // static | 260 // static |
| 213 void WebApkInstaller::UpdateAsync( | 261 void WebApkInstaller::UpdateAsync(content::BrowserContext* context, |
| 214 content::BrowserContext* context, | 262 const base::FilePath& update_request_file, |
| 215 const std::string& webapk_package, | 263 const FinishCallback& finish_callback) { |
| 216 const GURL& start_url, | |
| 217 const base::string16& short_name, | |
| 218 std::unique_ptr<std::vector<uint8_t>> serialized_proto, | |
| 219 const FinishCallback& finish_callback) { | |
| 220 // The installer will delete itself when it is done. | 264 // The installer will delete itself when it is done. |
| 221 WebApkInstaller* installer = new WebApkInstaller(context); | 265 WebApkInstaller* installer = new WebApkInstaller(context); |
| 222 installer->UpdateAsync(webapk_package, start_url, short_name, | 266 installer->UpdateAsync(update_request_file, finish_callback); |
| 223 std::move(serialized_proto), finish_callback); | |
| 224 } | 267 } |
| 225 | 268 |
| 226 // static | 269 // static |
| 227 void WebApkInstaller::InstallAsyncForTesting(WebApkInstaller* installer, | 270 void WebApkInstaller::InstallAsyncForTesting(WebApkInstaller* installer, |
| 228 const ShortcutInfo& shortcut_info, | 271 const ShortcutInfo& shortcut_info, |
| 229 const SkBitmap& primary_icon, | 272 const SkBitmap& primary_icon, |
| 230 const SkBitmap& badge_icon, | 273 const SkBitmap& badge_icon, |
| 231 const FinishCallback& callback) { | 274 const FinishCallback& callback) { |
| 232 installer->InstallAsync(shortcut_info, primary_icon, badge_icon, callback); | 275 installer->InstallAsync(shortcut_info, primary_icon, badge_icon, callback); |
| 233 } | 276 } |
| 234 | 277 |
| 235 // static | 278 // static |
| 236 void WebApkInstaller::UpdateAsyncForTesting( | 279 void WebApkInstaller::UpdateAsyncForTesting( |
| 237 WebApkInstaller* installer, | 280 WebApkInstaller* installer, |
| 238 const std::string& webapk_package, | 281 const base::FilePath& update_request_file, |
| 239 const GURL& start_url, | |
| 240 const base::string16& short_name, | |
| 241 std::unique_ptr<std::vector<uint8_t>> serialized_proto, | |
| 242 const FinishCallback& finish_callback) { | 282 const FinishCallback& finish_callback) { |
| 243 installer->UpdateAsync(webapk_package, start_url, short_name, | 283 installer->UpdateAsync(update_request_file, finish_callback); |
| 244 std::move(serialized_proto), finish_callback); | |
| 245 } | 284 } |
| 246 | 285 |
| 247 void WebApkInstaller::SetTimeoutMs(int timeout_ms) { | 286 void WebApkInstaller::SetTimeoutMs(int timeout_ms) { |
| 248 webapk_server_timeout_ms_ = timeout_ms; | 287 webapk_server_timeout_ms_ = timeout_ms; |
| 249 } | 288 } |
| 250 | 289 |
| 251 void WebApkInstaller::OnInstallFinished( | 290 void WebApkInstaller::OnInstallFinished( |
| 252 JNIEnv* env, | 291 JNIEnv* env, |
| 253 const base::android::JavaParamRef<jobject>& obj, | 292 const base::android::JavaParamRef<jobject>& obj, |
| 254 jint result) { | 293 jint result) { |
| 255 OnResult(static_cast<WebApkInstallResult>(result)); | 294 OnResult(static_cast<WebApkInstallResult>(result)); |
| 256 } | 295 } |
| 257 | 296 |
| 258 // static | 297 // static |
| 259 void WebApkInstaller::BuildProto( | 298 void WebApkInstaller::BuildProto( |
| 260 const ShortcutInfo& shortcut_info, | 299 const ShortcutInfo& shortcut_info, |
| 261 const SkBitmap& primary_icon, | 300 const SkBitmap& primary_icon, |
| 262 const SkBitmap& badge_icon, | 301 const SkBitmap& badge_icon, |
| 263 const std::string& package_name, | 302 const std::string& package_name, |
| 264 const std::string& version, | 303 const std::string& version, |
| 265 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 304 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 266 bool is_manifest_stale, | 305 bool is_manifest_stale, |
| 267 const base::Callback<void(std::unique_ptr<std::vector<uint8_t>>)>& | 306 const base::Callback<void(std::unique_ptr<std::string>)>& callback) { |
| 268 callback) { | |
| 269 base::PostTaskAndReplyWithResult( | 307 base::PostTaskAndReplyWithResult( |
| 270 GetBackgroundTaskRunner().get(), FROM_HERE, | 308 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 271 base::Bind(&BuildProtoInBackground, shortcut_info, primary_icon, | 309 base::Bind(&BuildProtoInBackground, shortcut_info, primary_icon, |
| 272 badge_icon, package_name, version, icon_url_to_murmur2_hash, | 310 badge_icon, package_name, version, icon_url_to_murmur2_hash, |
| 273 is_manifest_stale), | 311 is_manifest_stale), |
| 274 callback); | 312 callback); |
| 275 } | 313 } |
| 276 | 314 |
| 315 // static |
| 316 void WebApkInstaller::StoreUpdateRequestToDisk( |
| 317 const base::FilePath& file, |
| 318 const ShortcutInfo& shortcut_info, |
| 319 const SkBitmap& primary_icon, |
| 320 const SkBitmap& badge_icon, |
| 321 const std::string& package_name, |
| 322 const std::string& version, |
| 323 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 324 bool is_manifest_stale, |
| 325 const base::Callback<void(bool)> callback) { |
| 326 base::PostTaskAndReplyWithResult( |
| 327 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 328 base::Bind(&StoreUpdateRequestToDiskInBackground, file, shortcut_info, |
| 329 primary_icon, badge_icon, package_name, version, |
| 330 icon_url_to_murmur2_hash, is_manifest_stale), |
| 331 callback); |
| 332 } |
| 333 |
| 277 void WebApkInstaller::InstallOrUpdateWebApk(const std::string& package_name, | 334 void WebApkInstaller::InstallOrUpdateWebApk(const std::string& package_name, |
| 278 int version, | 335 int version, |
| 279 const std::string& token) { | 336 const std::string& token) { |
| 280 webapk_package_ = package_name; | 337 webapk_package_ = package_name; |
| 281 | 338 |
| 282 JNIEnv* env = base::android::AttachCurrentThread(); | 339 JNIEnv* env = base::android::AttachCurrentThread(); |
| 283 base::android::ScopedJavaLocalRef<jstring> java_webapk_package = | 340 base::android::ScopedJavaLocalRef<jstring> java_webapk_package = |
| 284 base::android::ConvertUTF8ToJavaString(env, webapk_package_); | 341 base::android::ConvertUTF8ToJavaString(env, webapk_package_); |
| 285 base::android::ScopedJavaLocalRef<jstring> java_title = | 342 base::android::ScopedJavaLocalRef<jstring> java_title = |
| 286 base::android::ConvertUTF16ToJavaString(env, short_name_); | 343 base::android::ConvertUTF16ToJavaString(env, short_name_); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // generated for another user. (The icon can be dynamically generated.) | 412 // generated for another user. (The icon can be dynamically generated.) |
| 356 // | 413 // |
| 357 // We redownload the icon in order to take the Murmur2 hash. The redownload | 414 // We redownload the icon in order to take the Murmur2 hash. The redownload |
| 358 // should be fast because the icon should be in the HTTP cache. | 415 // should be fast because the icon should be in the HTTP cache. |
| 359 WebApkIconHasher::DownloadAndComputeMurmur2Hash( | 416 WebApkIconHasher::DownloadAndComputeMurmur2Hash( |
| 360 request_context_getter_, install_shortcut_info_->best_primary_icon_url, | 417 request_context_getter_, install_shortcut_info_->best_primary_icon_url, |
| 361 base::Bind(&WebApkInstaller::OnGotPrimaryIconMurmur2Hash, | 418 base::Bind(&WebApkInstaller::OnGotPrimaryIconMurmur2Hash, |
| 362 weak_ptr_factory_.GetWeakPtr())); | 419 weak_ptr_factory_.GetWeakPtr())); |
| 363 } | 420 } |
| 364 | 421 |
| 365 void WebApkInstaller::UpdateAsync( | 422 void WebApkInstaller::UpdateAsync(const base::FilePath& update_request_file, |
| 366 const std::string& webapk_package, | 423 const FinishCallback& finish_callback) { |
| 367 const GURL& start_url, | |
| 368 const base::string16& short_name, | |
| 369 std::unique_ptr<std::vector<uint8_t>> serialized_proto, | |
| 370 const FinishCallback& finish_callback) { | |
| 371 webapk_package_ = webapk_package; | |
| 372 start_url_ = start_url; | |
| 373 short_name_ = short_name; | |
| 374 finish_callback_ = finish_callback; | 424 finish_callback_ = finish_callback; |
| 375 task_type_ = UPDATE; | 425 task_type_ = UPDATE; |
| 376 | 426 |
| 377 if (!serialized_proto || serialized_proto->empty()) { | 427 base::PostTaskAndReplyWithResult( |
| 428 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 429 base::Bind(&ReadFileFromDiskInBackground, update_request_file), |
| 430 base::Bind(&WebApkInstaller::OnReadUpdateRequest, |
| 431 weak_ptr_factory_.GetWeakPtr())); |
| 432 } |
| 433 |
| 434 void WebApkInstaller::OnReadUpdateRequest( |
| 435 std::unique_ptr<std::string> update_request) { |
| 436 base::Pickle pickle(update_request->data(), update_request->size()); |
| 437 base::PickleIterator pickle_iterator(pickle); |
| 438 int version = 0; |
| 439 std::string webapk_package; |
| 440 std::string start_url; |
| 441 base::string16 short_name; |
| 442 std::unique_ptr<std::string> serialized_proto = |
| 443 base::MakeUnique<std::string>(); |
| 444 if (!pickle_iterator.ReadInt(&version) || |
| 445 !pickle_iterator.ReadString(&webapk_package) || |
| 446 !pickle_iterator.ReadString(&start_url) || |
| 447 !pickle_iterator.ReadString16(&short_name) || |
| 448 !pickle_iterator.ReadString(serialized_proto.get())) { |
| 449 OnResult(WebApkInstallResult::FAILURE); |
| 450 return; |
| 451 } |
| 452 if (version != kCurrentUpdateFileFormatVersion || serialized_proto->empty()) { |
| 378 OnResult(WebApkInstallResult::FAILURE); | 453 OnResult(WebApkInstallResult::FAILURE); |
| 379 return; | 454 return; |
| 380 } | 455 } |
| 381 | 456 |
| 457 webapk_package_ = webapk_package; |
| 458 start_url_ = GURL(start_url); |
| 459 short_name_ = short_name; |
| 382 SendRequest(std::move(serialized_proto)); | 460 SendRequest(std::move(serialized_proto)); |
| 383 } | 461 } |
| 384 | 462 |
| 385 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { | 463 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { |
| 386 timer_.Stop(); | 464 timer_.Stop(); |
| 387 | 465 |
| 388 if (!source->GetStatus().is_success() || | 466 if (!source->GetStatus().is_success() || |
| 389 source->GetResponseCode() != net::HTTP_OK) { | 467 source->GetResponseCode() != net::HTTP_OK) { |
| 390 LOG(WARNING) << base::StringPrintf( | 468 LOG(WARNING) << base::StringPrintf( |
| 391 "WebAPK server returned response code %d.", source->GetResponseCode()); | 469 "WebAPK server returned response code %d.", source->GetResponseCode()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 } | 543 } |
| 466 | 544 |
| 467 BuildProto(*install_shortcut_info_, install_primary_icon_, | 545 BuildProto(*install_shortcut_info_, install_primary_icon_, |
| 468 install_badge_icon_, "" /* package_name */, "" /* version */, | 546 install_badge_icon_, "" /* package_name */, "" /* version */, |
| 469 icon_url_to_murmur2_hash, false /* is_manifest_stale */, | 547 icon_url_to_murmur2_hash, false /* is_manifest_stale */, |
| 470 base::Bind(&WebApkInstaller::SendRequest, | 548 base::Bind(&WebApkInstaller::SendRequest, |
| 471 weak_ptr_factory_.GetWeakPtr())); | 549 weak_ptr_factory_.GetWeakPtr())); |
| 472 } | 550 } |
| 473 | 551 |
| 474 void WebApkInstaller::SendRequest( | 552 void WebApkInstaller::SendRequest( |
| 475 std::unique_ptr<std::vector<uint8_t>> serialized_proto) { | 553 std::unique_ptr<std::string> serialized_proto) { |
| 476 timer_.Start( | 554 timer_.Start( |
| 477 FROM_HERE, base::TimeDelta::FromMilliseconds(webapk_server_timeout_ms_), | 555 FROM_HERE, base::TimeDelta::FromMilliseconds(webapk_server_timeout_ms_), |
| 478 base::Bind(&WebApkInstaller::OnResult, weak_ptr_factory_.GetWeakPtr(), | 556 base::Bind(&WebApkInstaller::OnResult, weak_ptr_factory_.GetWeakPtr(), |
| 479 WebApkInstallResult::FAILURE)); | 557 WebApkInstallResult::FAILURE)); |
| 480 | 558 |
| 481 std::string serialized_proto_string(serialized_proto->begin(), | |
| 482 serialized_proto->end()); | |
| 483 | |
| 484 url_fetcher_ = | 559 url_fetcher_ = |
| 485 net::URLFetcher::Create(server_url_, net::URLFetcher::POST, this); | 560 net::URLFetcher::Create(server_url_, net::URLFetcher::POST, this); |
| 486 url_fetcher_->SetRequestContext(request_context_getter_); | 561 url_fetcher_->SetRequestContext(request_context_getter_); |
| 487 url_fetcher_->SetUploadData(kProtoMimeType, serialized_proto_string); | 562 url_fetcher_->SetUploadData(kProtoMimeType, *serialized_proto); |
| 488 url_fetcher_->SetLoadFlags( | 563 url_fetcher_->SetLoadFlags( |
| 489 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES | | 564 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES | |
| 490 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); | 565 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| 491 url_fetcher_->Start(); | 566 url_fetcher_->Start(); |
| 492 } | 567 } |
| OLD | NEW |