File: app_install_win.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (1107 lines) | stat: -rw-r--r-- 42,987 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/updater/app/app_install.h"

#include <ocidl.h>
#include <windows.h>

#include <olectl.h>
#include <shldisp.h>
#include <shlobj.h>
#include <winhttp.h>
#include <wrl/client.h>

#include <algorithm>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "base/sequence_checker.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "base/version.h"
#include "base/win/elevation_util.h"
#include "base/win/registry.h"
#include "base/win/scoped_com_initializer.h"
#include "chrome/updater/app/app_install_progress.h"
#include "chrome/updater/app/app_install_util_win.h"
#include "chrome/updater/app/app_install_win_internal.h"
#include "chrome/updater/branded_constants.h"
#include "chrome/updater/constants.h"
#include "chrome/updater/external_constants.h"
#include "chrome/updater/registration_data.h"
#include "chrome/updater/service_proxy_factory.h"
#include "chrome/updater/update_service.h"
#include "chrome/updater/update_service_internal.h"
#include "chrome/updater/updater_branding.h"
#include "chrome/updater/updater_scope.h"
#include "chrome/updater/util/progress_sampler.h"
#include "chrome/updater/util/util.h"
#include "chrome/updater/util/win_util.h"
#include "chrome/updater/win/installer/exit_code.h"
#include "chrome/updater/win/installer_api.h"
#include "chrome/updater/win/manifest_util.h"
#include "chrome/updater/win/protocol_parser_xml.h"
#include "chrome/updater/win/ui/l10n_util.h"
#include "chrome/updater/win/ui/progress_wnd.h"
#include "chrome/updater/win/ui/resources/resources.grh"
#include "chrome/updater/win/ui/resources/updater_installer_strings.h"
#include "chrome/updater/win/win_constants.h"
#include "components/update_client/update_client_errors.h"
#include "url/gurl.h"

namespace updater {
namespace {

class InstallProgressSilentObserver : public AppInstallProgress {
 public:
  explicit InstallProgressSilentObserver(ui::OmahaWndEvents* events_sink);

  // Overrides for AppInstallProgress.
  void OnCheckingForUpdate() override;
  void OnUpdateAvailable(const std::string& app_id,
                         const std::u16string& app_name,
                         const base::Version& version) override;
  void OnWaitingToDownload(const std::string& app_id,
                           const std::u16string& app_name) override;
  void OnDownloading(const std::string& app_id,
                     const std::u16string& app_name,
                     std::optional<base::TimeDelta> time_remaining,
                     int pos) override;
  void OnWaitingRetryDownload(const std::string& app_id,
                              const std::u16string& app_name,
                              base::Time next_retry_time) override;
  void OnWaitingToInstall(const std::string& app_id,
                          const std::u16string& app_name) override;
  void OnInstalling(const std::string& app_id,
                    const std::u16string& app_name,
                    std::optional<base::TimeDelta> time_remaining,
                    int pos) override;
  void OnPause() override;
  void OnComplete(const ObserverCompletionInfo& observer_info) override;

 private:
  SEQUENCE_CHECKER(sequence_checker_);

  // Event sink must out-live this observer.
  raw_ptr<ui::OmahaWndEvents> events_sink_ = nullptr;
};

InstallProgressSilentObserver::InstallProgressSilentObserver(
    ui::OmahaWndEvents* events_sink)
    : events_sink_(events_sink) {
  CHECK(events_sink_);
}

void InstallProgressSilentObserver::OnCheckingForUpdate() {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

void InstallProgressSilentObserver::OnUpdateAvailable(
    const std::string& app_id,
    const std::u16string& app_name,
    const base::Version& version) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

void InstallProgressSilentObserver::OnWaitingToDownload(
    const std::string& app_id,
    const std::u16string& app_name) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

void InstallProgressSilentObserver::OnDownloading(
    const std::string& app_id,
    const std::u16string& app_name,
    std::optional<base::TimeDelta> time_remaining,
    int pos) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

void InstallProgressSilentObserver::OnWaitingRetryDownload(
    const std::string& app_id,
    const std::u16string& app_name,
    base::Time next_retry_time) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

void InstallProgressSilentObserver::OnWaitingToInstall(
    const std::string& app_id,
    const std::u16string& app_name) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

void InstallProgressSilentObserver::OnInstalling(
    const std::string& app_id,
    const std::u16string& app_name,
    std::optional<base::TimeDelta> time_remaining,
    int pos) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

void InstallProgressSilentObserver::OnPause() {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

void InstallProgressSilentObserver::OnComplete(
    const ObserverCompletionInfo& observer_info) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  CHECK(events_sink_);
  VLOG(1) << __func__;

  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          kAlwaysLaunchCmdSwitch)) {
    auto scoped_com_initializer =
        std::make_unique<base::win::ScopedCOMInitializer>(
            base::win::ScopedCOMInitializer::kMTA);
    LaunchCmdLines(observer_info);
  }

  events_sink_->DoExit();
}

// Implements a simple inter-thread communication protocol based on Windows
// messages exchanged between the application installer and its UI.
//
// Since the installer code and the UI code execute on different sequences, the
// installer can't invoke directly functions exposed by the UI.
class AppInstallProgressIPC : public AppInstallProgress {
 public:
  // Used as an inter-thread communication mechanism between the installer and
  // UI threads.
  static constexpr unsigned int WM_PROGRESS_WINDOW_IPC = WM_APP + 1;

  AppInstallProgressIPC(AppInstallProgress* observer, DWORD observer_thread_id)
      : observer_(observer), observer_thread_id_(observer_thread_id) {
    CHECK(observer);
  }

  AppInstallProgressIPC(const AppInstallProgressIPC&) = delete;
  AppInstallProgressIPC& operator=(const AppInstallProgressIPC&) = delete;

  // Called by the window proc when a specific application message is processed
  // by the progress window. This call always occurs in the context of the
  // thread which owns the window.
  void Invoke(WPARAM wparam, LPARAM lparam) {
    CHECK_EQ(observer_thread_id_, ::GetCurrentThreadId());
    CHECK_NE(lparam, 0);
    CHECK_EQ(wparam, WPARAM{0});
    std::unique_ptr<base::OnceClosure> callback_wrapper(
        reinterpret_cast<base::OnceClosure*>(lparam));
    std::move(*callback_wrapper).Run();
  }

  // Overrides for AppInstallProgress.
  void OnCheckingForUpdate() override {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    CHECK(observer_);
    PostClosure(base::BindOnce(&AppInstallProgress::OnCheckingForUpdate,
                               base::Unretained(observer_)));
  }

  void OnUpdateAvailable(const std::string& app_id,
                         const std::u16string& app_name,
                         const base::Version& version) override {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    CHECK(observer_);
    PostClosure(base::BindOnce(&AppInstallProgress::OnUpdateAvailable,
                               base::Unretained(observer_), app_id, app_name,
                               version));
  }

  void OnWaitingToDownload(const std::string& app_id,
                           const std::u16string& app_name) override {
  }

  void OnDownloading(const std::string& app_id,
                     const std::u16string& app_name,
                     std::optional<base::TimeDelta> time_remaining,
                     int pos) override {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    CHECK(observer_);
    PostClosure(base::BindOnce(&AppInstallProgress::OnDownloading,
                               base::Unretained(observer_), app_id, app_name,
                               time_remaining, pos));
  }

  void OnWaitingRetryDownload(const std::string& app_id,
                              const std::u16string& app_name,
                              base::Time next_retry_time) override {
  }

  void OnWaitingToInstall(const std::string& app_id,
                          const std::u16string& app_name) override {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    CHECK(observer_);
    PostClosure(base::BindOnce(&AppInstallProgress::OnWaitingToInstall,
                               base::Unretained(observer_), app_id, app_name));
  }

  void OnInstalling(const std::string& app_id,
                    const std::u16string& app_name,
                    std::optional<base::TimeDelta> time_remaining,
                    int pos) override {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    CHECK(observer_);
    PostClosure(base::BindOnce(&AppInstallProgress::OnInstalling,
                               base::Unretained(observer_), app_id, app_name,
                               time_remaining, pos));
  }

  void OnPause() override {}

  void OnComplete(const ObserverCompletionInfo& observer_info) override {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    CHECK(observer_);
    PostClosure(base::BindOnce(&AppInstallProgress::OnComplete,
                               base::Unretained(observer_), observer_info));
  }

 private:
  void PostClosure(base::OnceClosure closure) {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    std::unique_ptr<base::OnceClosure> closure_wrapper =
        std::make_unique<base::OnceClosure>(std::move(closure));
    ::PostThreadMessage(observer_thread_id_, WM_PROGRESS_WINDOW_IPC, 0,
                        reinterpret_cast<LPARAM>(closure_wrapper.release()));
  }

  SEQUENCE_CHECKER(sequence_checker_);

  // This member is not owned by this class.
  raw_ptr<AppInstallProgress> observer_ = nullptr;

  // The thread id of the thread which creates the `observer_`. The thread
  // must have a message queue to enable this IPC class to post messages to it.
  DWORD observer_thread_id_ = 0;
};

void SetUsageStats(UpdaterScope scope,
                   const std::string& app_id,
                   std::optional<bool> usage_stats) {
  if (!usage_stats) {
    return;
  }

  const LONG result =
      base::win::RegKey(
          UpdaterScopeToHKeyRoot(scope),
          base::StrCat({CLIENT_STATE_KEY, base::UTF8ToWide(app_id)}).c_str(),
          Wow6432(KEY_WRITE))
          .WriteValue(L"usagestats", usage_stats.value() ? 1 : 0);
  if (result != ERROR_SUCCESS) {
    VLOG(1) << "Error writing usage stats for " << app_id << ":" << result;
    return;
  }

  if (IsSystemInstall(scope)) {
    base::win::RegKey(
        UpdaterScopeToHKeyRoot(scope),
        base::StrCat({CLIENT_STATE_MEDIUM_KEY, base::UTF8ToWide(app_id)})
            .c_str(),
        Wow6432(KEY_WRITE))
        .DeleteValue(L"usagestats");
  }
}

// Implements installing a single application by invoking the code in
// |UpdateService|, listening to |UpdateService| and UI events, and
// driving the UI code by calling the functions exposed by
// |AppInstallProgress|. This class receives state changes for an install
// and it notifies the UI, which is an observer of this class.
//
// The UI code can't run in a thread where the message loop is an instance of
// |base::MessageLoop|. |base::MessageLoop| does not handle all the messages
// needed by the UI, since the UI is written in terms of WTL, and it requires
// a |WTL::MessageLoop| to work, for example, accelerators, dialog messages,
// TAB key, etc are all handled by WTL. Therefore, the UI code runs on its own
// thread. This thread owns all the UI objects, which must be created and
// destroyed on this thread. The rest of the code in this class runs on
// the updater main thread.
//
// This class controls the lifetime of the UI thread. Once the UI thread is
// created, it is going to run a message loop until the main thread initiates
// its teardown by posting a WM_QUIT message to it. This makes the UI message
// loop exit, and after that, the execution flow returns to the scheduler task,
// which has been running the UI message loop. Upon its completion, the task
// posts a reply to the main thread, which makes the main thread exit its run
// loop, and then the main thread returns to the destructor of this class,
// and destructs its class members.
class AppInstallControllerImpl : public AppInstallController,
                                 public ui::ProgressWndEvents,
                                 public WTL::CMessageFilter {
 public:
  explicit AppInstallControllerImpl(bool is_silent_install);
  AppInstallControllerImpl();

  AppInstallControllerImpl(const AppInstallControllerImpl&) = delete;
  AppInstallControllerImpl& operator=(const AppInstallControllerImpl&) = delete;

  // Override for AppInstallController.
  void Initialize() override;

  void InstallApp(const std::string& app_id,
                  const std::string& app_name,
                  base::OnceCallback<void(int)> callback) override;

  void InstallAppOffline(const std::string& app_id,
                         const std::string& app_name,
                         base::OnceCallback<void(int)> callback) override;
  void Exit(int exit_code) override;

  void set_update_service(
      scoped_refptr<UpdateService> update_service) override {
    update_service_ = update_service;
  }

 private:
  friend class base::RefCountedThreadSafe<AppInstallControllerImpl>;

  ~AppInstallControllerImpl() override;

  // Overrides for OmahaWndEvents. These functions are called on the UI thread.
  void DoClose() override {}
  void DoExit() override;

  // Overrides for CompleteWndEvents. This function is called on the UI thread.
  bool DoLaunchBrowser(const std::string& url) override;

  // Overrides for ProgressWndEvents. These functions are called on the UI
  // thread.
  bool DoRestartBrowser(bool restart_all_browsers,
                        const std::vector<GURL>& urls) override;
  bool DoReboot() override;
  void DoCancel() override;

  // Overrides for WTL::CMessageFilter.
  BOOL PreTranslateMessage(MSG* msg) override;

  // This function is called on a dedicated COM STA thread.
  void LoadLogo(const std::string& app_id, HWND progress_hwnd);

  // These functions are called on the UI thread.
  void InitializeUI();
  void RunUI();

  // These functions are called on the main updater sequence.
  void PreInstallApp(const std::string& app_id,
                     const std::string& app_name,
                     base::OnceCallback<void(int)> callback);
  void DoInstallAppOffline(
      const OfflineManifestSystemRequirements& requirements,
      const std::string& installer_version,
      const base::FilePath& installer_path,
      const std::string& install_args,
      const std::string& install_data);
  void HandleOsNotSupported();
  void InstallComplete(UpdateService::Result result);

  // Returns the thread id of the thread which owns the progress window.
  DWORD GetUIThreadID() const;

  // Receives the state changes during handling of the Install function call.
  void StateChange(const UpdateService::UpdateState& update_state);

  SEQUENCE_CHECKER(sequence_checker_);

  // Provides an execution environment for the updater main sequence.
  scoped_refptr<base::SequencedTaskRunner> main_task_runner_;

  // Provides an execution environment for the UI code. Typically, it runs
  // a single task which is the UI run loop.
  scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;

  // The application ID and the associated application name. The application
  // name is displayed by the UI and it must be localized.
  std::string app_id_;
  std::u16string app_name_;

  // The out-of-process service used for making RPC calls to install the app.
  scoped_refptr<UpdateService> update_service_;

  // The message loop associated with the UI.
  std::unique_ptr<WTL::CMessageLoop> ui_message_loop_;

  std::unique_ptr<AppInstallProgress> observer_;
  HWND observer_hwnd_ = nullptr;
  DWORD ui_thread_id_ = 0u;

  // The adapter for the inter-thread calls between the updater main thread
  // and the UI thread.
  std::unique_ptr<AppInstallProgressIPC> install_progress_observer_ipc_;

  // Contains the result of installing the application. This is populated by the
  // state change callback or the completion callback, if the former callback
  // was not posted.
  std::optional<ObserverCompletionInfo> observer_completion_info_;

  // Called when InstallApp is done.
  base::OnceCallback<void(int)> callback_;

  const bool is_silent_install_ = false;

  ProgressSampler download_progress_sampler_;
  ProgressSampler install_progress_sampler_;
};

AppInstallControllerImpl::AppInstallControllerImpl(bool is_silent_install)
    : main_task_runner_(base::SequencedTaskRunner::GetCurrentDefault()),
      ui_task_runner_(base::ThreadPool::CreateSingleThreadTaskRunner(
          {base::TaskPriority::USER_BLOCKING,
           base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
          base::SingleThreadTaskRunnerThreadMode::DEDICATED)),
      is_silent_install_(is_silent_install),
      download_progress_sampler_(base::Seconds(5), base::Seconds(1)),
      install_progress_sampler_(base::Seconds(5), base::Seconds(1)) {}
AppInstallControllerImpl::~AppInstallControllerImpl() = default;

void AppInstallControllerImpl::Initialize() {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  base::WaitableEvent ui_initialized_event;
  ui_task_runner_->PostTask(
      FROM_HERE,
      base::BindOnce(
          [](scoped_refptr<AppInstallControllerImpl> self,
             base::WaitableEvent& event) {
            self->InitializeUI();
            event.Signal();
          },
          base::WrapRefCounted(this), std::ref(ui_initialized_event)));

  ui_initialized_event.Wait();

  // The UI thread runs the observer.
  install_progress_observer_ipc_ =
      std::make_unique<AppInstallProgressIPC>(observer_.get(), ui_thread_id_);

  // At this point, the UI has been initialized, which means the UI
  // can be used from now on as an observer of the application
  // install. The task below runs the UI message loop for the UI until
  // it exits when a WM_QUIT message has been posted to it.
  ui_task_runner_->PostTask(
      FROM_HERE, base::BindOnce(&AppInstallControllerImpl::RunUI, this));
}

void AppInstallControllerImpl::InstallApp(
    const std::string& app_id,
    const std::string& app_name,
    base::OnceCallback<void(int)> callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  PreInstallApp(app_id, app_name, std::move(callback));

  RegistrationRequest request;
  request.app_id = app_id_;
  request.version = base::Version(kNullVersion);
  std::optional<tagging::AppArgs> app_args = GetAppArgs(app_id_);
  std::optional<tagging::TagArgs> tag_args = GetTagArgs().tag_args;
  if (app_args) {
    request.ap = app_args->ap;
  }
  if (tag_args) {
    request.brand_code = tag_args->brand_code;
    request.install_id = tag_args->installation_id;

    if (!tag_args->referral_id.empty()) {
      // For backwards compatibility, record the referral id in ClientState,
      // since some applications read it from there.
      SetRegistryKey(UpdaterScopeToHKeyRoot(GetUpdaterScope()),
                     GetAppClientStateKey(base::UTF8ToWide(app_id_)),
                     kRegValueReferralId,
                     base::UTF8ToWide(tag_args->referral_id));
    }
  }

  base::ThreadPool::PostTaskAndReply(
      FROM_HERE,
      base::BindOnce(&SetUsageStats, GetUpdaterScope(), app_id_,
                     tag_args ? tag_args->usage_stats_enable : std::nullopt),
      base::BindOnce(
          &UpdateService::Install, update_service_, request,
          GetDecodedInstallDataFromAppArgs(app_id_),
          GetInstallDataIndexFromAppArgs(app_id_),
          UpdateService::Priority::kForeground, GetTagLanguage(),
          base::BindRepeating(&AppInstallControllerImpl::StateChange, this),
          base::BindOnce(&AppInstallControllerImpl::InstallComplete, this)));
}

void AppInstallControllerImpl::PreInstallApp(
    const std::string& app_id,
    const std::string& app_name,
    base::OnceCallback<void(int)> callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  app_id_ = app_id;
  app_name_ = base::UTF8ToUTF16(app_name);
  callback_ = std::move(callback);

  // The app logo is expected to be hosted at `{AppLogoURL}{url escaped
  // app_id_}.bmp`. If `{url escaped app_id_}.bmp` exists, a logo is shown in
  // the updater UI for that app install.
  //
  // For example, if `app_id_` is `{8A69D345-D564-463C-AFF1-A69D9E530F96}`,
  // the `{url escaped app_id_}.bmp` is
  // `%7b8A69D345-D564-463C-AFF1-A69D9E530F96%7d.bmp`.
  //
  // `AppLogoURL` is specified in external constants.
  base::ThreadPool::CreateCOMSTATaskRunner({base::MayBlock()})
      ->PostTask(FROM_HERE, base::BindOnce(&AppInstallControllerImpl::LoadLogo,
                                           this, app_id_, observer_hwnd_));
}

void AppInstallControllerImpl::InstallAppOffline(
    const std::string& app_id,
    const std::string& app_name,
    base::OnceCallback<void(int)> callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  PreInstallApp(app_id, app_name, std::move(callback));

  base::ThreadPool::PostTaskAndReplyWithResult(
      FROM_HERE, {base::MayBlock()},
      base::BindOnce(
          [](const std::string& app_id) {
            // Parse the offline manifest to get the install
            // command and install data.
            OfflineManifestSystemRequirements requirements;
            std::string installer_version;
            base::FilePath installer_path;
            std::string install_args;
            std::string install_data;
            ReadInstallCommandFromManifest(
                base::CommandLine::ForCurrentProcess()->GetSwitchValueNative(
                    kOfflineDirSwitch),
                app_id, GetInstallDataIndexFromAppArgs(app_id), requirements,
                installer_version, installer_path, install_args, install_data);

            const std::string client_install_data =
                GetDecodedInstallDataFromAppArgs(app_id);
            return std::make_tuple(
                requirements, installer_version, installer_path, install_args,
                client_install_data.empty() ? install_data
                                            : client_install_data);
          },
          app_id_),
      base::BindOnce(
          [](scoped_refptr<AppInstallControllerImpl> self,
             const std::tuple<
                 OfflineManifestSystemRequirements /*requirements*/,
                 std::string /*installer_version*/,
                 base::FilePath /*installer_path*/, std::string /*arguments*/,
                 std::string /*install_data*/>& result) {
            self->DoInstallAppOffline(std::get<0>(result), std::get<1>(result),
                                      std::get<2>(result), std::get<3>(result),
                                      std::get<4>(result));
          },
          base::WrapRefCounted(this)));
}

void AppInstallControllerImpl::DoInstallAppOffline(
    const OfflineManifestSystemRequirements& requirements,
    const std::string& installer_version,
    const base::FilePath& installer_path,
    const std::string& install_args,
    const std::string& install_data) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  if (!IsOsSupported(requirements)) {
    HandleOsNotSupported();
    return;
  }

  base::Value::Dict install_settings_dict;
  install_settings_dict.Set(kInstallerVersion, installer_version);

  const base::CommandLine cmd_line(*base::CommandLine::ForCurrentProcess());
  install_settings_dict.Set(kEnterpriseSwitch,
                            cmd_line.HasSwitch(kEnterpriseSwitch));
  install_settings_dict.Set(kSessionIdSwitch,
                            cmd_line.GetSwitchValueUTF8(kSessionIdSwitch));

  std::string install_settings;
  if (!JSONStringValueSerializer(&install_settings)
           .Serialize(install_settings_dict)) {
    VLOG(1) << "Failed to serialize install settings.";
  }

  RegistrationRequest request;
  request.app_id = app_id_;
  const base::Version installed_version =
      LookupVersion(GetUpdaterScope(), app_id_, {}, {}, {});
  request.version = installed_version.IsValid() ? installed_version
                                                : base::Version(kNullVersion);

  std::optional<tagging::AppArgs> app_args = GetAppArgs(app_id_);
  if (app_args) {
    request.ap = app_args->ap;
  }
  std::optional<tagging::TagArgs> tag_args = GetTagArgs().tag_args;
  if (tag_args) {
    request.brand_code = tag_args->brand_code;
    request.install_id = tag_args->installation_id;

    if (!tag_args->referral_id.empty()) {
      // For backwards compatibility, record the referral id in ClientState,
      // since some applications read it from there.
      SetRegistryKey(UpdaterScopeToHKeyRoot(GetUpdaterScope()),
                     GetAppClientStateKey(base::UTF8ToWide(app_id_)),
                     kRegValueReferralId,
                     base::UTF8ToWide(tag_args->referral_id));
    }
  }

  VLOG(1) << __func__ << ": " << installer_path << ": " << install_args << ": "
          << install_data;

  base::ThreadPool::PostTaskAndReply(
      FROM_HERE,
      base::BindOnce(&SetUsageStats, GetUpdaterScope(), app_id_,
                     tag_args ? tag_args->usage_stats_enable : std::nullopt),
      base::BindOnce(
          &UpdateService::RegisterApp, update_service_, request,
          base::BindOnce(
              [](scoped_refptr<AppInstallControllerImpl> self,
                 const base::FilePath& installer_path,
                 const std::string& install_args,
                 const std::string& install_data,
                 const std::string& install_settings,
                 const std::string& language, int result) {
                if (result != kRegistrationSuccess) {
                  VLOG(1) << "Registration failed: " << result;
                  self->InstallComplete(UpdateService::Result::kServiceFailed);
                  return;
                }
                self->update_service_->RunInstaller(
                    self->app_id_, installer_path, install_args, install_data,
                    install_settings, language,
                    base::BindRepeating(&AppInstallControllerImpl::StateChange,
                                        self),
                    base::BindOnce(&AppInstallControllerImpl::InstallComplete,
                                   self));
              },
              base::WrapRefCounted(this), installer_path, install_args,
              install_data, install_settings, GetTagLanguage())));
}

void AppInstallControllerImpl::HandleOsNotSupported() {
  const std::wstring lang = base::UTF8ToWide(GetTagLanguage());
  UpdateService::UpdateState update_state;
  update_state.app_id = app_id_;
  update_state.state = UpdateService::UpdateState::State::kUpdateError;
  update_state.error_category = UpdateService::ErrorCategory::kInstall;
  observer_completion_info_ = HandleInstallResult(update_state, lang);
  observer_completion_info_->completion_text = base::WideToUTF16(
      GetLocalizedString(IDS_UPDATER_OS_NOT_SUPPORTED_BASE, lang));
  InstallComplete(UpdateService::Result::kInstallFailed);
}

void AppInstallControllerImpl::InstallComplete(UpdateService::Result result) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  VLOG(1) << __func__;

  // Create a best-effort `UpdateState` instance if one is not available because
  // state change callbacks were never posted for this install. This happens if
  // the execution path returns early, before it has reached the state machine
  // of the component in the `update_client`.
  if (!observer_completion_info_.has_value()) {
    UpdateService::UpdateState update_state;
    update_state.app_id = app_id_;
    update_state.state = UpdateService::UpdateState::State::kUpdateError;
    update_state.error_code = static_cast<int>(result);
    update_state.error_category = [result] {
      switch (result) {
        case UpdateService::Result::kUpdateCheckFailed:
          return UpdateService::ErrorCategory::kUpdateCheck;
        case UpdateService::Result::kInstallFailed:
          return UpdateService::ErrorCategory::kInstall;
        default:
          return UpdateService::ErrorCategory::kService;
      }
    }();
    observer_completion_info_ =
        HandleInstallResult(update_state, base::UTF8ToWide(GetTagLanguage()));
  }
  update_service_ = nullptr;
  CHECK(observer_completion_info_.has_value());
  install_progress_observer_ipc_->OnComplete(observer_completion_info_.value());
}

void AppInstallControllerImpl::Exit(int exit_code) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  VLOG(1) << __func__;

  update_service_ = nullptr;

  if (exit_code == kErrorOk) {
    install_progress_observer_ipc_->OnComplete({});
  }

  UpdateService::UpdateState update_state;
  update_state.state = UpdateService::UpdateState::State::kNotStarted;
  update_state.error_code = exit_code;
  install_progress_observer_ipc_->OnComplete(
      HandleInstallResult(update_state, base::UTF8ToWide(GetTagLanguage())));
}
void AppInstallControllerImpl::StateChange(
    const UpdateService::UpdateState& update_state) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  CHECK_EQ(app_id_, update_state.app_id);

  switch (update_state.state) {
    case UpdateService::UpdateState::State::kCheckingForUpdates:
      install_progress_observer_ipc_->OnCheckingForUpdate();
      break;

    case UpdateService::UpdateState::State::kUpdateAvailable:
      install_progress_observer_ipc_->OnUpdateAvailable(
          app_id_, app_name_, update_state.next_version);
      break;

    case UpdateService::UpdateState::State::kDownloading: {
      const auto pos = GetDownloadProgress(update_state.downloaded_bytes,
                                           update_state.total_bytes);
      if (pos >= 0) {
        download_progress_sampler_.AddSample(update_state.downloaded_bytes);
      }
      install_progress_observer_ipc_->OnDownloading(
          app_id_, app_name_,
          download_progress_sampler_.GetRemainingTime(update_state.total_bytes),
          pos >= 0 ? pos : 0);
      break;
    }

    case UpdateService::UpdateState::State::kInstalling: {
      install_progress_observer_ipc_->OnWaitingToInstall(app_id_, app_name_);
      const int pos = update_state.install_progress;  // [0..100]
      if (pos >= 0) {
        install_progress_sampler_.AddSample(pos);
      }
      install_progress_observer_ipc_->OnInstalling(
          app_id_, app_name_, install_progress_sampler_.GetRemainingTime(100),
          pos >= 0 ? pos : 0);
      break;
    }

    case UpdateService::UpdateState::State::kUpdated:
    case UpdateService::UpdateState::State::kNoUpdate:
    case UpdateService::UpdateState::State::kUpdateError:
      observer_completion_info_ =
          HandleInstallResult(update_state, base::UTF8ToWide(GetTagLanguage()));
      break;

    case UpdateService::UpdateState::State::kUnknown:
    case UpdateService::UpdateState::State::kNotStarted:
      break;
  }
}

// Loads the logo in BMP format if it exists for the provided `app_id`, and sets
// the resultant image onto the app bitmap for the progress window.
void AppInstallControllerImpl::LoadLogo(const std::string& app_id,
                                        HWND progress_hwnd) {
  std::wstring url = base::UTF8ToWide(base::StringPrintf(
      "%s%s.bmp?lang=%s",
      CreateExternalConstants()->AppLogoURL().possibly_invalid_spec().c_str(),
      base::EscapeUrlEncodedData(app_id, false).c_str(),
      base::WideToUTF8(GetPreferredLanguage()).c_str()));
  if (url.empty()) {
    VLOG(1) << __func__ << "No url specified";
    return;
  }

  Microsoft::WRL::ComPtr<IPicture> picture;
  HRESULT hr =
      ::OleLoadPicturePath(&url[0], nullptr, 0, 0, IID_PPV_ARGS(&picture));
  if (FAILED(hr)) {
    VLOG(1) << __func__ << "::OleLoadPicturePath failed: " << url << ": "
            << std::hex << hr << ": " << logging::SystemErrorCodeToString(hr);
    return;
  }

  HBITMAP bitmap = nullptr;
  hr = picture->get_Handle(reinterpret_cast<UINT*>(&bitmap));
  if (FAILED(hr)) {
    VLOG(1) << __func__ << "picture->get_Handle failed: " << std::hex << hr
            << ": " << logging::SystemErrorCodeToString(hr);
    return;
  }

  if (!::IsWindow(progress_hwnd)) {
    VLOG(1) << __func__ << "progress_hwnd not valid anymore";
    return;
  }

  ::SendDlgItemMessage(progress_hwnd, IDC_APP_BITMAP, STM_SETIMAGE,
                       IMAGE_BITMAP,
                       reinterpret_cast<LPARAM>(::CopyImage(
                           bitmap, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)));
}

// Creates the install progress observer. The observer has thread affinity. It
// must be created, process its messages, and be destroyed on the same thread.
void AppInstallControllerImpl::InitializeUI() {
  CHECK(ui_task_runner_->RunsTasksInCurrentSequence());

  base::ScopedDisallowBlocking no_blocking_allowed_on_ui_thread;

  ui_message_loop_ = std::make_unique<WTL::CMessageLoop>();
  ui_message_loop_->AddMessageFilter(this);
  ui_thread_id_ = ::GetCurrentThreadId();

  if (is_silent_install_) {
    observer_ = std::make_unique<InstallProgressSilentObserver>(this);
  } else {
    auto progress_wnd =
        std::make_unique<ui::ProgressWnd>(ui_message_loop_.get(), nullptr);

    std::optional<tagging::TagArgs> tag_args = GetTagArgs().tag_args;
    if (tag_args) {
      progress_wnd->set_bundle_name(base::UTF8ToUTF16(tag_args->bundle_name));
    }
    progress_wnd->SetEventSink(this);
    progress_wnd->Initialize();
    progress_wnd->Show();

    observer_hwnd_ = progress_wnd->m_hWnd;
    observer_.reset(progress_wnd.release());
  }
}

void AppInstallControllerImpl::RunUI() {
  CHECK(ui_task_runner_->RunsTasksInCurrentSequence());
  CHECK_EQ(GetUIThreadID(), GetCurrentThreadId());

  ui_message_loop_->Run();
  ui_message_loop_->RemoveMessageFilter(this);

  // This object is owned by the UI thread must be destroyed on this thread.
  observer_ = nullptr;

  if (!callback_) {
    return;
  }

  main_task_runner_->PostTask(
      FROM_HERE, base::BindOnce(std::move(callback_), [&]() {
        if (!observer_completion_info_) {
          return kErrorNoObserverCompletionInfo;
        }

        if (observer_completion_info_->completion_code !=
            CompletionCodes::COMPLETION_CODE_ERROR) {
          return kErrorOk;
        }

        if (observer_completion_info_->apps_info.empty()) {
          return kErrorNoApps;
        }

        return std::ranges::max_element(
                   observer_completion_info_->apps_info,
                   [](const auto& app_info1, const auto& app_info2) {
                     return GetPriority(app_info1.completion_code) <
                            GetPriority(app_info2.completion_code);
                   })
            ->error_code;
      }()));
}

void AppInstallControllerImpl::DoExit() {
  CHECK_EQ(GetUIThreadID(), GetCurrentThreadId());
  PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0, 0);
}

BOOL AppInstallControllerImpl::PreTranslateMessage(MSG* msg) {
  if (const auto ui_thread_id = GetUIThreadID(); ui_thread_id != 0) {
    CHECK_EQ(ui_thread_id, GetCurrentThreadId());
  } else {
    VLOG(1) << "Can't find a thread id for the message: " << msg->message;
  }
  if (msg->message == AppInstallProgressIPC::WM_PROGRESS_WINDOW_IPC) {
    install_progress_observer_ipc_->Invoke(msg->wParam, msg->lParam);
    return true;
  }
  return false;
}

DWORD AppInstallControllerImpl::GetUIThreadID() const {
  CHECK_NE(ui_thread_id_, 0u);
  return ui_thread_id_;
}

bool AppInstallControllerImpl::DoLaunchBrowser(const std::string& url) {
  CHECK_EQ(GetUIThreadID(), GetCurrentThreadId());

  return SUCCEEDED(base::win::RunDeElevatedNoWait(
      base::UTF8ToWide(url), {}, base::FilePath::kCurrentDirectory));
}

bool AppInstallControllerImpl::DoRestartBrowser(bool restart_all_browsers,
                                                const std::vector<GURL>& urls) {
  CHECK_EQ(GetUIThreadID(), GetCurrentThreadId());
  return false;
}

bool AppInstallControllerImpl::DoReboot() {
  CHECK_EQ(GetUIThreadID(), GetCurrentThreadId());
  return false;
}

void AppInstallControllerImpl::DoCancel() {
  CHECK_EQ(GetUIThreadID(), GetCurrentThreadId());
  if (!update_service_) {
    return;
  }
  main_task_runner_->PostTask(
      FROM_HERE,
      base::BindOnce(&UpdateService::CancelInstalls, update_service_, app_id_));
}

std::wstring GetTextForStartupError(int error_code, const std::wstring& lang) {
  switch (error_code) {
    case kErrorWrongUser:
      return GetLocalizedString(
          ::IsUserAnAdmin() ? IDS_WRONG_USER_DEELEVATION_REQUIRED_ERROR_BASE
                            : IDS_WRONG_USER_ELEVATION_REQUIRED_ERROR_BASE,
          lang);
    case kErrorFailedToLockSetupMutex:
      return GetLocalizedString(IDS_UNABLE_TO_GET_SETUP_LOCK_BASE, lang);
    default:
      return GetLocalizedStringF(IDS_GENERIC_STARTUP_ERROR_BASE,
                                 GetTextForSystemError(error_code), lang);
  }
}

}  // namespace

[[nodiscard]] ObserverCompletionInfo HandleInstallResult(
    const UpdateService::UpdateState& update_state,
    const std::wstring& lang) {
  CompletionCodes completion_code = CompletionCodes::COMPLETION_CODE_ERROR;
  std::wstring completion_text;
  switch (update_state.state) {
    case UpdateService::UpdateState::State::kUpdated:
      VLOG(1) << "Update success.";
      completion_code = CompletionCodes::COMPLETION_CODE_SUCCESS;
      completion_text =
          GetLocalizedString(IDS_BUNDLE_INSTALLED_SUCCESSFULLY_BASE, lang);
      break;
    case UpdateService::UpdateState::State::kNoUpdate:
      VLOG(1) << "No updates.";
      completion_code = CompletionCodes::COMPLETION_CODE_ERROR;
      completion_text = GetLocalizedString(IDS_NO_UPDATE_RESPONSE_BASE, lang);
      break;
    case UpdateService::UpdateState::State::kUpdateError:
      VLOG(1) << "Updater error: " << update_state.error_code << ".";
      completion_code = CompletionCodes::COMPLETION_CODE_ERROR;
      completion_text =
          GetLocalizedString(IDS_INSTALL_UPDATER_FAILED_BASE, lang);
      break;
    case UpdateService::UpdateState::State::kNotStarted:
      VLOG(1) << "Updater error: " << update_state.error_code << ".";
      completion_code = CompletionCodes::COMPLETION_CODE_ERROR;
      completion_text = GetTextForStartupError(update_state.error_code, lang);
      break;
    default:
      NOTREACHED();
  }

  ObserverCompletionInfo observer_info;
  observer_info.completion_code = completion_code;
  observer_info.completion_text = base::WideToUTF16(completion_text);
  observer_info.help_url = GURL(base::StringPrintf(
      "%s?product=%s&error=%d", HELP_CENTER_URL,
      base::EscapeUrlEncodedData(update_state.app_id, false).c_str(),
      update_state.error_code));

  AppCompletionInfo app_info;
  if (update_state.state == UpdateService::UpdateState::State::kNotStarted) {
    app_info.app_id = kUpdaterAppId;
  } else if (update_state.state !=
             UpdateService::UpdateState::State::kNoUpdate) {
    app_info.app_id = update_state.app_id;
    app_info.error_code = update_state.error_code;
    app_info.completion_message =
        base::UTF8ToUTF16(update_state.installer_text);
    app_info.extra_code1 = update_state.extra_code1;
    app_info.post_install_launch_command_line = update_state.installer_cmd_line;
    VLOG(1) << app_info.app_id << " installation completed: error category["
            << update_state.error_category << "], error_code["
            << app_info.error_code << "], extra_code1[" << app_info.extra_code1
            << "], completion_message[" << app_info.completion_message
            << "], post_install_launch_command_line["
            << app_info.post_install_launch_command_line << "]";

    // If the installer provides a launch command,
    // `COMPLETION_CODE_EXIT_SILENTLY_ON_LAUNCH_COMMAND` will cause the UI
    // client to run the launch command and exit in the interactive install
    // case.
    if (app_info.error_code == 0) {
      app_info.completion_code =
          app_info.post_install_launch_command_line.empty()
              ? CompletionCodes::COMPLETION_CODE_SUCCESS
              : CompletionCodes::
                    COMPLETION_CODE_EXIT_SILENTLY_ON_LAUNCH_COMMAND;
    } else if (app_info.error_code == ERROR_SUCCESS_REBOOT_INITIATED ||
               app_info.error_code == ERROR_SUCCESS_REBOOT_REQUIRED ||
               app_info.error_code == ERROR_SUCCESS_RESTART_REQUIRED) {
      app_info.completion_code =
          CompletionCodes::COMPLETION_CODE_REBOOT_NOTICE_ONLY;
    } else {
      app_info.completion_code = CompletionCodes::COMPLETION_CODE_ERROR;
    }
  }
  observer_info.apps_info.push_back(app_info);

  return observer_info;
}

scoped_refptr<App> MakeAppInstall(bool is_silent_install) {
  if (IsSystemInstall()) {
    if (base::CommandLine::ForCurrentProcess()->HasSwitch(kOemSwitch)) {
      const bool success = SetOemInstallState();
      LOG_IF(ERROR, !success) << "SetOemInstallState failed";
    }

    std::optional<tagging::TagArgs> tag_args = GetTagArgs().tag_args;
    if (tag_args && !tag_args->enrollment_token.empty()) {
      const bool success =
          StoreRunTimeEnrollmentToken(tag_args->enrollment_token);
      LOG_IF(ERROR, !success) << "StoreRunTimeEnrollmentToken failed";
    }
  }
  return base::MakeRefCounted<AppInstall>(base::BindRepeating(
      [](bool is_silent_install) -> scoped_refptr<AppInstallController> {
        return base::MakeRefCounted<AppInstallControllerImpl>(
            is_silent_install);
      },
      is_silent_install));
}

}  // namespace updater