aw_component_updater_configurator.cc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "android_webview/nonembedded/component_updater/aw_component_updater_configurator.h"
  5. #include <memory>
  6. #include <string>
  7. #include <vector>
  8. #include "android_webview/nonembedded/net/network_impl.h"
  9. #include "base/bind.h"
  10. #include "base/memory/scoped_refptr.h"
  11. #include "base/version.h"
  12. #include "components/component_updater/component_updater_command_line_config_policy.h"
  13. #include "components/component_updater/configurator_impl.h"
  14. #include "components/prefs/pref_service.h"
  15. #include "components/update_client/activity_data_service.h"
  16. #include "components/update_client/crx_downloader_factory.h"
  17. #include "components/update_client/network.h"
  18. #include "components/update_client/patch/in_process_patcher.h"
  19. #include "components/update_client/patcher.h"
  20. #include "components/update_client/protocol_handler.h"
  21. #include "components/update_client/unzip/in_process_unzipper.h"
  22. #include "components/update_client/unzipper.h"
  23. #include "components/update_client/update_query_params.h"
  24. #include "components/version_info/android/channel_getter.h"
  25. #include "components/version_info/version_info.h"
  26. #include "components/version_info/version_info_values.h"
  27. #include "third_party/abseil-cpp/absl/types/optional.h"
  28. namespace android_webview {
  29. AwComponentUpdaterConfigurator::AwComponentUpdaterConfigurator(
  30. const base::CommandLine* cmdline,
  31. PrefService* pref_service)
  32. : configurator_impl_(
  33. component_updater::ComponentUpdaterCommandLineConfigPolicy(cmdline),
  34. false),
  35. pref_service_(pref_service) {}
  36. AwComponentUpdaterConfigurator::~AwComponentUpdaterConfigurator() = default;
  37. double AwComponentUpdaterConfigurator::InitialDelay() const {
  38. // Initial delay acts as a "registration window" for components, so we should
  39. // have a reasonable window to allow for all components to complete
  40. // registration. We are choosing a small window of 10 seconds here because
  41. // WebView has a short list of components and components registration happens
  42. // in an android background service so we want to start the update as soon as
  43. // possible.
  44. // TODO(crbug.com/1181094): git rid of dependency in initial delay for
  45. // WebView.
  46. return 10;
  47. }
  48. int AwComponentUpdaterConfigurator::NextCheckDelay() const {
  49. return configurator_impl_.NextCheckDelay();
  50. }
  51. int AwComponentUpdaterConfigurator::OnDemandDelay() const {
  52. return configurator_impl_.OnDemandDelay();
  53. }
  54. int AwComponentUpdaterConfigurator::UpdateDelay() const {
  55. // No need to have any delays between components updates. In WebView this
  56. // doesn't run in a browser and shouldn't affect user's experience.
  57. // Furthermore, this will be a background service that is scheduled by
  58. // JobScheduler, so we want to do as much work in as little time as possible.
  59. // However, if we ever invoked installation on-demand, we should be less
  60. // aggressive here.
  61. return 0;
  62. }
  63. std::vector<GURL> AwComponentUpdaterConfigurator::UpdateUrl() const {
  64. return configurator_impl_.UpdateUrl();
  65. }
  66. std::vector<GURL> AwComponentUpdaterConfigurator::PingUrl() const {
  67. return configurator_impl_.PingUrl();
  68. }
  69. std::string AwComponentUpdaterConfigurator::GetProdId() const {
  70. return update_client::UpdateQueryParams::GetProdIdString(
  71. update_client::UpdateQueryParams::ProdId::WEBVIEW);
  72. }
  73. base::Version AwComponentUpdaterConfigurator::GetBrowserVersion() const {
  74. return configurator_impl_.GetBrowserVersion();
  75. }
  76. std::string AwComponentUpdaterConfigurator::GetChannel() const {
  77. return version_info::GetChannelString(version_info::android::GetChannel());
  78. }
  79. std::string AwComponentUpdaterConfigurator::GetLang() const {
  80. // WebView uses the locale of the embedding app. Components are shared with
  81. // WebView instances across apps so we don't set a locale.
  82. return std::string();
  83. }
  84. std::string AwComponentUpdaterConfigurator::GetOSLongName() const {
  85. return configurator_impl_.GetOSLongName();
  86. }
  87. base::flat_map<std::string, std::string>
  88. AwComponentUpdaterConfigurator::ExtraRequestParams() const {
  89. return configurator_impl_.ExtraRequestParams();
  90. }
  91. std::string AwComponentUpdaterConfigurator::GetDownloadPreference() const {
  92. // Hints for the server about caching URLs, "" means let the server decide the
  93. // best URLs to return according to its policies.
  94. return configurator_impl_.GetDownloadPreference();
  95. }
  96. scoped_refptr<update_client::NetworkFetcherFactory>
  97. AwComponentUpdaterConfigurator::GetNetworkFetcherFactory() {
  98. if (!network_fetcher_factory_) {
  99. network_fetcher_factory_ =
  100. base::MakeRefCounted<NetworkFetcherFactoryImpl>();
  101. }
  102. return network_fetcher_factory_;
  103. }
  104. scoped_refptr<update_client::CrxDownloaderFactory>
  105. AwComponentUpdaterConfigurator::GetCrxDownloaderFactory() {
  106. if (!crx_downloader_factory_) {
  107. crx_downloader_factory_ =
  108. update_client::MakeCrxDownloaderFactory(GetNetworkFetcherFactory());
  109. }
  110. return crx_downloader_factory_;
  111. }
  112. scoped_refptr<update_client::UnzipperFactory>
  113. AwComponentUpdaterConfigurator::GetUnzipperFactory() {
  114. if (!unzip_factory_) {
  115. unzip_factory_ =
  116. base::MakeRefCounted<update_client::InProcessUnzipperFactory>();
  117. }
  118. return unzip_factory_;
  119. }
  120. scoped_refptr<update_client::PatcherFactory>
  121. AwComponentUpdaterConfigurator::GetPatcherFactory() {
  122. if (!patch_factory_) {
  123. patch_factory_ =
  124. base::MakeRefCounted<update_client::InProcessPatcherFactory>();
  125. }
  126. return patch_factory_;
  127. }
  128. bool AwComponentUpdaterConfigurator::EnabledDeltas() const {
  129. return configurator_impl_.EnabledDeltas();
  130. }
  131. bool AwComponentUpdaterConfigurator::EnabledBackgroundDownloader() const {
  132. return configurator_impl_.EnabledBackgroundDownloader();
  133. }
  134. bool AwComponentUpdaterConfigurator::EnabledCupSigning() const {
  135. return configurator_impl_.EnabledCupSigning();
  136. }
  137. PrefService* AwComponentUpdaterConfigurator::GetPrefService() const {
  138. return pref_service_;
  139. }
  140. update_client::ActivityDataService*
  141. AwComponentUpdaterConfigurator::GetActivityDataService() const {
  142. // This tracks user's activity using the component, doesn't apply to
  143. // components and safe to be null.
  144. return nullptr;
  145. }
  146. bool AwComponentUpdaterConfigurator::IsPerUserInstall() const {
  147. return true;
  148. }
  149. std::unique_ptr<update_client::ProtocolHandlerFactory>
  150. AwComponentUpdaterConfigurator::GetProtocolHandlerFactory() const {
  151. return configurator_impl_.GetProtocolHandlerFactory();
  152. }
  153. absl::optional<bool>
  154. AwComponentUpdaterConfigurator::IsMachineExternallyManaged() const {
  155. return absl::nullopt;
  156. }
  157. update_client::UpdaterStateProvider
  158. AwComponentUpdaterConfigurator::GetUpdaterStateProvider() const {
  159. return configurator_impl_.GetUpdaterStateProvider();
  160. }
  161. scoped_refptr<update_client::Configurator> MakeAwComponentUpdaterConfigurator(
  162. const base::CommandLine* cmdline,
  163. PrefService* pref_service) {
  164. return base::MakeRefCounted<AwComponentUpdaterConfigurator>(cmdline,
  165. pref_service);
  166. }
  167. } // namespace android_webview