Skip to content

Commit

Permalink
update_client: make CrxDataCallback asynchronous.
Browse files Browse the repository at this point in the history
No change in behavior is intended with this CL.

Bug: 1491226
Change-Id: I768e3f0323793b2c025c482e393f37bd3fd9ad5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4929157
Reviewed-by: Sorin Jianu <sorin@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Richard (Torne) Coles <torne@chromium.org>
Commit-Queue: Joshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210418}
  • Loading branch information
Joshua Pawlicki authored and Chromium LUCI CQ committed Oct 16, 2023
1 parent 779ff58 commit 9e8c06a
Show file tree
Hide file tree
Showing 14 changed files with 382 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "android_webview/nonembedded/component_updater/aw_component_update_service.h"

#include <memory>
#include <string>
#include <vector>

#include "android_webview/common/aw_paths.h"
#include "android_webview/nonembedded/component_updater/aw_component_updater_configurator.h"
Expand Down Expand Up @@ -195,9 +197,11 @@ AwComponentUpdateService::GetComponent(const std::string& id) const {
return component_updater::GetComponent(components_, id);
}

std::vector<absl::optional<update_client::CrxComponent>>
AwComponentUpdateService::GetCrxComponents(
const std::vector<std::string>& ids) {
void AwComponentUpdateService::GetCrxComponents(
const std::vector<std::string>& ids,
base::OnceCallback<
void(const std::vector<absl::optional<update_client::CrxComponent>>&)>
callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::vector<absl::optional<update_client::CrxComponent>> crxs;
for (absl::optional<component_updater::ComponentRegistration> item :
Expand All @@ -207,7 +211,7 @@ AwComponentUpdateService::GetCrxComponents(
? absl::optional<update_client::CrxComponent>{ToCrxComponent(*item)}
: absl::nullopt);
}
return crxs;
std::move(callback).Run(crxs);
}

void AwComponentUpdateService::ScheduleUpdatesOfRegisteredComponents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ class AwComponentUpdateService {
const component_updater::ComponentRegistration& component) const;
absl::optional<component_updater::ComponentRegistration> GetComponent(
const std::string& id) const;
std::vector<absl::optional<update_client::CrxComponent>> GetCrxComponents(
const std::vector<std::string>& ids);
void GetCrxComponents(
const std::vector<std::string>& ids,
base::OnceCallback<
void(const std::vector<absl::optional<update_client::CrxComponent>>&)>
callback);
void ScheduleUpdatesOfRegisteredComponents(UpdateCallback on_finished_updates,
bool on_demand_update);

Expand Down
9 changes: 6 additions & 3 deletions chrome/updater/update_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,18 @@ MakeUpdateClientCrxStateChangeCallback(
config, persisted_data, new_install, callback);
}

std::vector<absl::optional<update_client::CrxComponent>> GetComponents(
void GetComponents(
scoped_refptr<Configurator> config,
scoped_refptr<PersistedData> persisted_data,
const AppClientInstallData& app_client_install_data,
const AppInstallDataIndex& app_install_data_index,
UpdateService::Priority priority,
bool update_blocked,
UpdateService::PolicySameVersionUpdate policy_same_version_update,
const std::vector<std::string>& ids) {
const std::vector<std::string>& ids,
base::OnceCallback<
void(const std::vector<absl::optional<update_client::CrxComponent>>&)>
callback) {
VLOG(1) << __func__
<< ". Same version update: " << policy_same_version_update;
const bool is_foreground = priority == UpdateService::Priority::kForeground;
Expand Down Expand Up @@ -273,7 +276,7 @@ std::vector<absl::optional<update_client::CrxComponent>> GetComponents(
config->GetCrxVerifierFormat())
->MakeCrxComponent());
}
return components;
std::move(callback).Run(components);
}

} // namespace
Expand Down
8 changes: 5 additions & 3 deletions components/component_updater/component_updater_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,18 @@ bool CrxUpdateService::GetComponentDetails(const std::string& id,
return false;
}

std::vector<absl::optional<CrxComponent>> CrxUpdateService::GetCrxComponents(
const std::vector<std::string>& ids) {
void CrxUpdateService::GetCrxComponents(
const std::vector<std::string>& ids,
base::OnceCallback<void(const std::vector<absl::optional<CrxComponent>>&)>
callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::vector<absl::optional<CrxComponent>> crxs;
for (absl::optional<ComponentRegistration> item :
component_updater::GetCrxComponents(components_, ids)) {
crxs.push_back(item ? absl::optional<CrxComponent>{ToCrxComponent(*item)}
: absl::nullopt);
}
return crxs;
std::move(callback).Run(crxs);
}

void CrxUpdateService::OnUpdateComplete(Callback callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ class CrxUpdateService : public ComponentUpdateService,

const CrxUpdateItem* GetComponentState(const std::string& id) const;

std::vector<absl::optional<CrxComponent>> GetCrxComponents(
const std::vector<std::string>& ids);
void GetCrxComponents(
const std::vector<std::string>& ids,
base::OnceCallback<void(const std::vector<absl::optional<CrxComponent>>&)>
callback);
void OnUpdateComplete(Callback callback,
const base::TimeTicks& start_time,
update_client::Error error);
Expand Down
19 changes: 10 additions & 9 deletions components/update_client/update_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,16 @@ using Callback = base::OnceCallback<void(Error error)>;
// the browser process has gone single-threaded.
class UpdateClient : public base::RefCountedThreadSafe<UpdateClient> {
public:
// Returns `CrxComponent` instances corresponding to the component ids
// passed as an argument to the callback. The order of components in the input
// and output vectors must match. If the instance of the `CrxComponent` is not
// available for some reason, implementors of the callback must not skip
// skip the component, and instead, they must insert a `nullopt` value in
// the output vector.
using CrxDataCallback =
base::OnceCallback<std::vector<absl::optional<CrxComponent>>(
const std::vector<std::string>& ids)>;
// Calls `callback` with `CrxComponent` instances corresponding to the
// component ids passed as an argument. The order of components in the input
// and output vectors must match. If the instance of the `CrxComponent` is
// not available for some reason, implementors of the callback must not skip
// the component, and instead, they must insert a `nullopt` value in the
// output vector.
using CrxDataCallback = base::OnceCallback<void(
const std::vector<std::string>& ids,
base::OnceCallback<void(const std::vector<absl::optional<CrxComponent>>&)>
callback)>;

// Called when state changes occur during an Install or Update call.
using CrxStateChangeCallback =
Expand Down

0 comments on commit 9e8c06a

Please sign in to comment.