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 "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/path_utils.h" | 10 #include "base/android/path_utils.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // the WebAPK server. | 50 // the WebAPK server. |
51 const int kWebApkDownloadUrlTimeoutMs = 60000; | 51 const int kWebApkDownloadUrlTimeoutMs = 60000; |
52 | 52 |
53 // The default number of milliseconds to wait for the WebAPK download to | 53 // The default number of milliseconds to wait for the WebAPK download to |
54 // complete. | 54 // complete. |
55 const int kDownloadTimeoutMs = 60000; | 55 const int kDownloadTimeoutMs = 60000; |
56 | 56 |
57 const int kWorldReadableFilePermission = base::FILE_PERMISSION_READ_BY_USER | | 57 const int kWorldReadableFilePermission = base::FILE_PERMISSION_READ_BY_USER | |
58 base::FILE_PERMISSION_READ_BY_GROUP | | 58 base::FILE_PERMISSION_READ_BY_GROUP | |
59 base::FILE_PERMISSION_READ_BY_OTHERS; | 59 base::FILE_PERMISSION_READ_BY_OTHERS; |
| 60 const int kDefaultWebApkVersion = 1; |
60 | 61 |
61 // Returns the WebAPK server URL based on the command line. | 62 // Returns the WebAPK server URL based on the command line. |
62 GURL GetServerUrl() { | 63 GURL GetServerUrl() { |
63 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 64 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
64 GURL command_line_url( | 65 GURL command_line_url( |
65 command_line->GetSwitchValueASCII(switches::kWebApkServerUrl)); | 66 command_line->GetSwitchValueASCII(switches::kWebApkServerUrl)); |
66 return command_line_url.is_valid() ? command_line_url | 67 return command_line_url.is_valid() ? command_line_url |
67 : GURL(kDefaultServerUrl); | 68 : GURL(kDefaultServerUrl); |
68 } | 69 } |
69 | 70 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, | 343 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, |
343 const ShortcutInfo& shortcut_info, | 344 const ShortcutInfo& shortcut_info, |
344 const SkBitmap& shortcut_icon) | 345 const SkBitmap& shortcut_icon) |
345 : request_context_getter_( | 346 : request_context_getter_( |
346 Profile::FromBrowserContext(browser_context)->GetRequestContext()), | 347 Profile::FromBrowserContext(browser_context)->GetRequestContext()), |
347 shortcut_info_(shortcut_info), | 348 shortcut_info_(shortcut_info), |
348 shortcut_icon_(shortcut_icon), | 349 shortcut_icon_(shortcut_icon), |
349 server_url_(GetServerUrl()), | 350 server_url_(GetServerUrl()), |
350 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), | 351 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), |
351 download_timeout_ms_(kDownloadTimeoutMs), | 352 download_timeout_ms_(kDownloadTimeoutMs), |
| 353 relax_updates_(false), |
| 354 webapk_version_(kDefaultWebApkVersion), |
352 task_type_(UNDEFINED), | 355 task_type_(UNDEFINED), |
353 weak_ptr_factory_(this) { | 356 weak_ptr_factory_(this) { |
354 CreateJavaRef(); | 357 CreateJavaRef(); |
355 } | 358 } |
356 | 359 |
357 void WebApkInstaller::CreateJavaRef() { | 360 void WebApkInstaller::CreateJavaRef() { |
358 JNIEnv* env = base::android::AttachCurrentThread(); | 361 JNIEnv* env = base::android::AttachCurrentThread(); |
359 java_ref_.Reset( | 362 java_ref_.Reset( |
360 Java_WebApkInstaller_create(env, reinterpret_cast<intptr_t>(this))); | 363 Java_WebApkInstaller_create(env, reinterpret_cast<intptr_t>(this))); |
361 } | 364 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 source->GetResponseAsString(&response_string); | 412 source->GetResponseAsString(&response_string); |
410 | 413 |
411 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); | 414 std::unique_ptr<webapk::WebApkResponse> response(new webapk::WebApkResponse); |
412 if (!response->ParseFromString(response_string)) { | 415 if (!response->ParseFromString(response_string)) { |
413 LOG(WARNING) << "WebAPK server did not return proto."; | 416 LOG(WARNING) << "WebAPK server did not return proto."; |
414 OnFailure(); | 417 OnFailure(); |
415 return; | 418 return; |
416 } | 419 } |
417 | 420 |
418 GURL signed_download_url(response->signed_download_url()); | 421 GURL signed_download_url(response->signed_download_url()); |
419 // https://crbug.com/680131. The server sends an empty URL if the server does | |
420 // not have a newer WebAPK to update to. | |
421 if (task_type_ == UPDATE && signed_download_url.is_empty()) { | 422 if (task_type_ == UPDATE && signed_download_url.is_empty()) { |
| 423 // https://crbug.com/680131. The server sends an empty URL if the server |
| 424 // does not have a newer WebAPK to update to. |
| 425 relax_updates_ = response->relax_updates(); |
422 OnSuccess(); | 426 OnSuccess(); |
423 return; | 427 return; |
424 } | 428 } |
425 | 429 |
426 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 430 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
427 LOG(WARNING) << "WebAPK server returned incomplete proto."; | 431 LOG(WARNING) << "WebAPK server returned incomplete proto."; |
428 OnFailure(); | 432 OnFailure(); |
429 return; | 433 return; |
430 } | 434 } |
431 | 435 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 } | 620 } |
617 if (!success) | 621 if (!success) |
618 OnFailure(); | 622 OnFailure(); |
619 } | 623 } |
620 | 624 |
621 void WebApkInstaller::OnTimeout() { | 625 void WebApkInstaller::OnTimeout() { |
622 OnFailure(); | 626 OnFailure(); |
623 } | 627 } |
624 | 628 |
625 void WebApkInstaller::OnSuccess() { | 629 void WebApkInstaller::OnSuccess() { |
626 finish_callback_.Run(true, webapk_package_); | 630 finish_callback_.Run(true, relax_updates_, webapk_package_); |
627 delete this; | 631 delete this; |
628 } | 632 } |
629 | 633 |
630 void WebApkInstaller::OnFailure() { | 634 void WebApkInstaller::OnFailure() { |
631 finish_callback_.Run(false, webapk_package_); | 635 finish_callback_.Run(false, relax_updates_, webapk_package_); |
632 delete this; | 636 delete this; |
633 } | 637 } |
OLD | NEW |