3
3
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
4
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5
5
6
+ #include " components/update_client/update_checker.h"
7
+
6
8
#include < optional>
7
9
10
+ #include " base/ranges/algorithm.h"
11
+ #include " components/update_client/update_client.h"
12
+
8
13
#include " src/components/update_client/update_checker.cc"
9
14
10
15
#if BUILDFLAG(WIDEVINE_ARM64_DLL_FIX)
14
19
15
20
namespace update_client {
16
21
22
+ namespace {
23
+
24
+ bool IsBraveComponent (const Component* component) {
25
+ CHECK (component);
26
+ const auto & crx_component = component->crx_component ();
27
+ if (!crx_component || !crx_component->installer ) {
28
+ return false ;
29
+ }
30
+ return crx_component->installer ->IsBraveComponent ();
31
+ }
32
+
33
+ } // namespace
34
+
17
35
SequentialUpdateChecker::SequentialUpdateChecker (
18
36
scoped_refptr<Configurator> config,
19
37
PersistedData* metadata)
@@ -39,6 +57,16 @@ void SequentialUpdateChecker::CheckForUpdates(
39
57
additional_attributes_ = additional_attributes;
40
58
update_check_callback_ = std::move (update_check_callback);
41
59
60
+ // Partition IDs for batch update checks. The order of
61
+ // `components_to_check_for_updates` doesn't matter to the caller, as
62
+ // post-update mapping is done via an Id->Component map, making this
63
+ // rearrangement safe.
64
+ base::ranges::stable_partition (
65
+ update_context_->components_to_check_for_updates ,
66
+ [&](const std::string& id) {
67
+ return IsBraveComponent (update_context_->components [id].get ());
68
+ });
69
+
42
70
for (const auto & id : update_context_->components_to_check_for_updates ) {
43
71
remaining_ids_.push_back (id);
44
72
}
@@ -56,25 +84,36 @@ void SequentialUpdateChecker::CheckNext(
56
84
DCHECK (!remaining_ids_.empty ());
57
85
DCHECK (update_context_);
58
86
59
- const auto id = remaining_ids_.front ();
60
- remaining_ids_.pop_front ();
87
+ // Support multiple checks in a single call, but only if they are all Brave.
88
+ std::vector<std::string> ids;
89
+ for (auto id_it = remaining_ids_.begin (); id_it != remaining_ids_.end ();) {
90
+ const auto & component = update_context_->components [*id_it];
91
+ if (!ids.empty () && !IsBraveComponent (component.get ())) {
92
+ break ;
93
+ }
94
+ ids.push_back (*id_it);
95
+ id_it = remaining_ids_.erase (id_it);
96
+ }
61
97
62
98
scoped_refptr<UpdateContext> context = new UpdateContext (
63
99
update_context_->config , update_context_->crx_cache_ ,
64
- update_context_->is_foreground , update_context_->is_install , {id} ,
100
+ update_context_->is_foreground , update_context_->is_install , ids ,
65
101
update_context_->crx_state_change_callback ,
66
102
update_context_->notify_observers_callback ,
67
103
// We don't pass a context callback here because UpdateChecker doesn't use
68
104
// it. This is instead done by UpdateEngine, which calls us.
69
105
base::DoNothing (), update_context_->persisted_data ,
70
106
/* is_update_check_only=*/ false );
71
107
72
- auto & component = context->components [id];
73
- auto & crx_component = update_context_->components [id]->crx_component ();
74
- component->set_crx_component (*crx_component);
75
- component->set_previous_version (crx_component->version );
76
- component->set_previous_fp (crx_component->fingerprint );
77
- context->components_to_check_for_updates .push_back (id);
108
+ DCHECK (!ids.empty ());
109
+ for (const auto & id : ids) {
110
+ auto & component = context->components [id];
111
+ auto & crx_component = update_context_->components [id]->crx_component ();
112
+ component->set_crx_component (*crx_component);
113
+ component->set_previous_version (crx_component->version );
114
+ component->set_previous_fp (crx_component->fingerprint );
115
+ context->components_to_check_for_updates .push_back (id);
116
+ }
78
117
79
118
update_checker_ = UpdateChecker::Create (config_, metadata_);
80
119
0 commit comments