File: force_installed_metrics.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (566 lines) | stat: -rw-r--r-- 23,173 bytes parent folder | download | duplicates (2)
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
// Copyright 2020 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/browser/extensions/forced_extensions/force_installed_metrics.h"

#include <set>

#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/forced_extensions/install_stage_tracker.h"
#include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_service.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registrar.h"
#include "extensions/browser/install/crx_install_error.h"
#include "extensions/browser/install/sandboxed_unpacker_failure_reason.h"
#include "extensions/browser/updater/extension_downloader.h"

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#include "chrome/browser/extensions/management/management_util.h"
#endif

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ash/profiles/profile_helper.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

namespace extensions {

using ExtensionStatus = ForceInstalledTracker::ExtensionStatus;
using FailureReason = InstallStageTracker::FailureReason;

namespace {
// Timeout to report UMA if not all force-installed extension were loaded.
constexpr base::TimeDelta kInstallationTimeout = base::Minutes(5);

#if BUILDFLAG(IS_CHROMEOS)
// Converts user_manager::UserType to InstallStageTracker::UserType for
// histogram purposes.
ForceInstalledMetrics::UserType ConvertUserType(
    InstallStageTracker::UserInfo user_info) {
  switch (user_info.user_type) {
    case user_manager::UserType::kRegular: {
      if (user_info.is_new_user) {
        return ForceInstalledMetrics::UserType::USER_TYPE_REGULAR_NEW;
      }
      return ForceInstalledMetrics::UserType::USER_TYPE_REGULAR_EXISTING;
    }
    case user_manager::UserType::kGuest:
      return ForceInstalledMetrics::UserType::USER_TYPE_GUEST;
    case user_manager::UserType::kPublicAccount:
      return ForceInstalledMetrics::UserType::USER_TYPE_PUBLIC_ACCOUNT;
    case user_manager::UserType::kKioskApp:
      return ForceInstalledMetrics::UserType::USER_TYPE_KIOSK_APP;
    case user_manager::UserType::kChild:
      return ForceInstalledMetrics::UserType::USER_TYPE_CHILD;
    case user_manager::UserType::kWebKioskApp:
      return ForceInstalledMetrics::UserType::USER_TYPE_WEB_KIOSK_APP;
    case user_manager::UserType::kKioskIWA:
      return ForceInstalledMetrics::UserType::USER_TYPE_KIOSK_IWA;
    default:
      NOTREACHED();
  }
}

// Reports type of user in case Force Installed Extensions fail to
// install only if there is a user corresponding to given profile.
void ReportUserType(Profile* profile, bool is_stuck_in_initial_creation_stage) {
  InstallStageTracker::UserInfo user_info =
      InstallStageTracker::GetUserInfo(profile);
  // There can be extensions on the login screen. There is no user on the login
  // screen and thus we would not report in that case.
  if (!user_info.is_user_present)
    return;

  ForceInstalledMetrics::UserType user_type = ConvertUserType(user_info);
  base::UmaHistogramEnumeration("Extensions.ForceInstalledFailureSessionType",
                                user_type);
  if (is_stuck_in_initial_creation_stage) {
    base::UmaHistogramEnumeration(
        "Extensions.ForceInstalledFailureSessionType."
        "ExtensionStuckInInitialCreationStage",
        user_type);
  }
}
#endif  // BUILDFLAG(IS_CHROMEOS)

// Reports time taken for force installed extension during different
// installation stages.
void ReportInstallationStageTimes(
    const ExtensionId& extension_id,
    const InstallStageTracker::InstallationData& installation) {
  if (installation.download_manifest_finish_time &&
      installation.download_manifest_started_time) {
    base::UmaHistogramLongTimes(
        "Extensions.ForceInstalledTime.DownloadingStartTo."
        "ManifestDownloadComplete",
        installation.download_manifest_finish_time.value() -
            installation.download_manifest_started_time.value());
  }
  // Report the download time for CRX only when
  // installation.download_CRX_started_time is set because in other case CRX
  // is fetched from cache and the download was not started.
  if (installation.download_CRX_finish_time &&
      installation.download_CRX_started_time) {
    base::UmaHistogramLongTimes(
        "Extensions.ForceInstalledTime.ManifestDownloadCompleteTo."
        "CRXDownloadComplete",
        installation.download_CRX_finish_time.value() -
            installation.download_CRX_started_time.value());
  }
  if (installation.copying_started_time) {
    DCHECK(installation.verification_started_time);
    base::UmaHistogramLongTimes(
        "Extensions.ForceInstalledTime.VerificationStartTo.CopyingStart",
        installation.copying_started_time.value() -
            installation.verification_started_time.value());
  }
  if (installation.unpacking_started_time &&
      installation.copying_started_time) {
    base::UmaHistogramLongTimes(
        "Extensions.ForceInstalledTime.CopyingStartTo.UnpackingStart",
        installation.unpacking_started_time.value() -
            installation.copying_started_time.value());
  }
  if (installation.checking_expectations_started_time &&
      installation.unpacking_started_time) {
    base::UmaHistogramLongTimes(
        "Extensions.ForceInstalledTime.UnpackingStartTo."
        "CheckingExpectationsStart",
        installation.checking_expectations_started_time.value() -
            installation.unpacking_started_time.value());
  }
  if (installation.finalizing_started_time &&
      installation.checking_expectations_started_time) {
    base::UmaHistogramLongTimes(
        "Extensions.ForceInstalledTime.CheckingExpectationsStartTo."
        "FinalizingStart",
        installation.finalizing_started_time.value() -
            installation.checking_expectations_started_time.value());
  }
  if (installation.installation_complete_time &&
      installation.finalizing_started_time) {
    base::UmaHistogramLongTimes(
        "Extensions.ForceInstalledTime.FinalizingStartTo."
        "CRXInstallComplete",
        installation.installation_complete_time.value() -
            installation.finalizing_started_time.value());
  }
}

// Reports the network error code, HTTP error code and number of fetch tries
// made when extension fails to install with MANIFEST_FETCH_FAILED.
void ReportManifestFetchFailedErrorCodes(
    const InstallStageTracker::InstallationData& installation,
    bool is_from_store) {
  base::UmaHistogramSparse(
      "Extensions.ForceInstalledManifestFetchFailedNetworkErrorCode",
      installation.network_error_code.value());

  if (installation.response_code) {
    if (is_from_store) {
      base::UmaHistogramSparse(
          "Extensions.WebStore_ForceInstalledManifestFetchFailedHttpErrorCode2",
          installation.response_code.value());
    } else {
      base::UmaHistogramSparse(
          "Extensions.OffStore_ForceInstalledManifestFetchFailedHttpErrorCode2",
          installation.response_code.value());
    }
    base::UmaHistogramSparse(
        "Extensions.ForceInstalledManifestFetchFailedHttpErrorCode2",
        installation.response_code.value());
  }
  base::UmaHistogramExactLinear(
      "Extensions.ForceInstalledManifestFetchFailedFetchTries",
      installation.fetch_tries.value(), ExtensionDownloader::kMaxRetries);
}

// Reports the network error code, HTTP error code and number of fetch tries
// made when extension fails to install with CRX_FETCH_FAILED.
void ReportCrxFetchFailedErrorCodes(
    const InstallStageTracker::InstallationData& installation,
    bool is_from_store) {
  base::UmaHistogramSparse("Extensions.ForceInstalledNetworkErrorCode",
                           installation.network_error_code.value());

  if (installation.response_code) {
    if (is_from_store) {
      base::UmaHistogramSparse(
          "Extensions.WebStore_ForceInstalledHttpErrorCode2",
          installation.response_code.value());
    } else {
      base::UmaHistogramSparse(
          "Extensions.OffStore_ForceInstalledHttpErrorCode2",
          installation.response_code.value());
    }
    base::UmaHistogramSparse("Extensions.ForceInstalledHttpErrorCode2",
                             installation.response_code.value());
  }
  base::UmaHistogramExactLinear("Extensions.ForceInstalledFetchTries",
                                installation.fetch_tries.value(),
                                ExtensionDownloader::kMaxRetries);
}

// Reports the network error code, HTTP error code and number of fetch tries
// made when extension is stuck in DOWNLOAD_MANIFEST_RETRY downloading stage.
void ReportManifestFetchRetryErrorCodes(
    const InstallStageTracker::InstallationData& installation,
    bool is_from_store) {
  base::UmaHistogramSparse(
      "Extensions.ForceInstalledManifestFetchRetryNetworkErrorCode",
      installation.network_error_code.value());

  if (installation.response_code) {
    if (is_from_store) {
      base::UmaHistogramSparse(
          "Extensions.WebStore_ForceInstalledManifestFetchRetryHttpErrorCode2",
          installation.response_code.value());
    } else {
      base::UmaHistogramSparse(
          "Extensions.OffStore_ForceInstalledManifestFetchRetryHttpErrorCode2",
          installation.response_code.value());
    }
  }
  base::UmaHistogramExactLinear(
      "Extensions.ForceInstalledManifestFetchRetryFetchTries",
      installation.fetch_tries.value(), ExtensionDownloader::kMaxRetries);
}

// Reports the network error code, HTTP error code and number of fetch tries
// made when extension is stuck in DOWNLOAD_CRX_RETRY downloading stage.
void ReportCrxFetchRetryErrorCodes(
    const InstallStageTracker::InstallationData& installation,
    bool is_from_store) {
  base::UmaHistogramSparse(
      "Extensions.ForceInstalledCrxFetchRetryNetworkErrorCode",
      installation.network_error_code.value());

  if (installation.response_code) {
    if (is_from_store) {
      base::UmaHistogramSparse(
          "Extensions.WebStore_ForceInstalledCrxFetchRetryHttpErrorCode2",
          installation.response_code.value());
    } else {
      base::UmaHistogramSparse(
          "Extensions.OffStore_ForceInstalledCrxFetchRetryHttpErrorCode2",
          installation.response_code.value());
    }
  }
  base::UmaHistogramExactLinear(
      "Extensions.ForceInstalledCrxFetchRetryFetchTries",
      installation.fetch_tries.value(), ExtensionDownloader::kMaxRetries);
}

// Reports installation stage and downloading stage for extensions which are
// currently in progress of the installation.
void ReportCurrentStage(
    const InstallStageTracker::InstallationData& installation) {
  InstallStageTracker::Stage install_stage = installation.install_stage.value();
  base::UmaHistogramEnumeration("Extensions.ForceInstalledStage2",
                                install_stage);
  if (install_stage == InstallStageTracker::Stage::CREATED) {
    DCHECK(installation.install_creation_stage);
    InstallStageTracker::InstallCreationStage install_creation_stage =
        installation.install_creation_stage.value();
    base::UmaHistogramEnumeration("Extensions.ForceInstalledCreationStage",
                                  install_creation_stage);
  }
  if (install_stage == InstallStageTracker::Stage::DOWNLOADING) {
    DCHECK(installation.downloading_stage);
    ExtensionDownloaderDelegate::Stage downloading_stage =
        installation.downloading_stage.value();
    base::UmaHistogramEnumeration("Extensions.ForceInstalledDownloadingStage",
                                  downloading_stage);
  }
}

// Reports detailed failure reason for the extensions which failed to install
// after 5 minutes.
void ReportDetailedFailureReasons(
    Profile* profile,
    const InstallStageTracker::InstallationData& installation,
    const bool is_from_store) {
  FailureReason failure_reason =
      installation.failure_reason.value_or(FailureReason::UNKNOWN);

  // In case of CRX_FETCH_FAILURE, report the network error code, HTTP
  // error code and number of fetch tries made.
  if (failure_reason == FailureReason::CRX_FETCH_FAILED)
    ReportCrxFetchFailedErrorCodes(installation, is_from_store);

  // In case of MANIFEST_FETCH_FAILURE, report the network error code,
  // HTTP error code and number of fetch tries made.
  if (failure_reason == FailureReason::MANIFEST_FETCH_FAILED)
    ReportManifestFetchFailedErrorCodes(installation, is_from_store);

  if (failure_reason == FailureReason::IN_PROGRESS) {
    if (installation.downloading_stage ==
        ExtensionDownloaderDelegate::Stage::DOWNLOADING_MANIFEST_RETRY) {
      ReportManifestFetchRetryErrorCodes(installation, is_from_store);
    }

    if (failure_reason == FailureReason::IN_PROGRESS &&
        installation.downloading_stage ==
            ExtensionDownloaderDelegate::Stage::DOWNLOADING_CRX_RETRY) {
      ReportCrxFetchRetryErrorCodes(installation, is_from_store);
    }
  }

  if (installation.install_error_detail) {
    CrxInstallErrorDetail detail = installation.install_error_detail.value();
    base::UmaHistogramEnumeration(
        "Extensions.ForceInstalledFailureCrxInstallError", detail);
  }
  if (failure_reason ==
      FailureReason::CRX_INSTALL_ERROR_SANDBOXED_UNPACKER_FAILURE) {
    DCHECK(installation.unpacker_failure_reason);
    base::UmaHistogramEnumeration(
        "Extensions.ForceInstalledFailureSandboxUnpackFailureReason2",
        installation.unpacker_failure_reason.value(),
        SandboxedUnpackerFailureReason::NUM_FAILURE_REASONS);
  }
  if (failure_reason == FailureReason::CRX_FETCH_URL_EMPTY) {
    DCHECK(installation.no_updates_info);
    base::UmaHistogramEnumeration(
        "Extensions."
        "ForceInstalledFailureNoUpdatesInfo",
        installation.no_updates_info.value());
  }
  if (installation.manifest_invalid_error) {
    DCHECK_EQ(failure_reason, FailureReason::MANIFEST_INVALID);
    if (is_from_store) {
      base::UmaHistogramEnumeration(
          "Extensions.WebStore_"
          "ForceInstalledFailureManifestInvalidErrorDetail2",
          installation.manifest_invalid_error.value());
    } else {
      base::UmaHistogramEnumeration(
          "Extensions.OffStore_"
          "ForceInstalledFailureManifestInvalidErrorDetail2",
          installation.manifest_invalid_error.value());
    }
    if (installation.app_status_error) {
      base::UmaHistogramEnumeration(
          "Extensions.ForceInstalledFailureManifestInvalidAppStatusError",
          installation.app_status_error.value());
    }
  }
  if (installation.unpacker_failure_reason &&
      installation.unpacker_failure_reason.value() ==
          SandboxedUnpackerFailureReason::CRX_HEADER_INVALID) {
    base::UmaHistogramBoolean(
        "Extensions.ForceInstalledFailureWithCrxHeaderInvalidIsCWS",
        is_from_store);
    base::UmaHistogramBoolean(
        "Extensions.ForceInstalledFailureWithCrxHeaderInvalidIsFromCache",
        ForceInstalledTracker::IsExtensionFetchedFromCache(
            installation.downloading_cache_status));
  }

  if (installation.failure_reason == FailureReason::IN_PROGRESS &&
      installation.install_creation_stage ==
          InstallStageTracker::InstallCreationStage::
              NOTIFIED_FROM_MANAGEMENT_INITIAL_CREATION_FORCED) {
    base::UmaHistogramBoolean(
        "Extensions."
        "ForceInstalledFailureStuckInInitialCreationStageAreExtensionsEnabled",
        ExtensionRegistrar::Get(profile)->extensions_enabled());
  }
}

// Returns false if the extension status corresponds to a missing extension
// which is not yet installed or loaded.
bool IsStatusGood(ExtensionStatus status) {
  switch (status) {
    case ExtensionStatus::kPending:
      return false;
    case ExtensionStatus::kLoaded:
      return true;
    case ExtensionStatus::kReady:
      return true;
    case ExtensionStatus::kFailed:
      return false;
  }
  NOTREACHED();
}

}  // namespace

ForceInstalledMetrics::ForceInstalledMetrics(
    ExtensionRegistry* registry,
    Profile* profile,
    ForceInstalledTracker* tracker,
    std::unique_ptr<base::OneShotTimer> timer)
    : registry_(registry),
      profile_(profile),
      tracker_(tracker),
      start_time_(base::Time::Now()),
      timer_(std::move(timer)) {
  timer_->Start(
      FROM_HERE, kInstallationTimeout,
      base::BindOnce(&ForceInstalledMetrics::OnForceInstalledExtensionsLoaded,
                     base::Unretained(this)));
  if (tracker_->IsDoneLoading())
    OnForceInstalledExtensionsLoaded();
  else
    tracker_observation_.Observe(tracker_.get());
}

ForceInstalledMetrics::~ForceInstalledMetrics() = default;

void ForceInstalledMetrics::ReportDisableReason(
    const ExtensionId& extension_id) {
  DisableReasonSet all_disable_reasons =
      ExtensionPrefs::Get(profile_)->GetDisableReasons(extension_id);
  // Choose the disable reason with the lowest value.
  int smallest_disable_reason =
      all_disable_reasons.empty()
          ? 0
          : *std::ranges::min_element(all_disable_reasons);
  base::UmaHistogramSparse("Extensions.ForceInstalledNotLoadedDisableReason",
                           smallest_disable_reason);
}

void ForceInstalledMetrics::ReportMetricsOnExtensionsReady() {
  for (const auto& extension : tracker_->extensions()) {
    if (extension.second.status != ExtensionStatus::kReady)
      return;
  }
  base::UmaHistogramLongTimes("Extensions.ForceInstalledReadyTime",
                              base::Time::Now() - start_time_);

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
  base::UmaHistogramEnumeration(
      "Extensions.ForceInstalledManagementAuthorityTrustworthiness",
      GetHigherManagementAuthorityTrustworthiness(profile_));
#endif
}

void ForceInstalledMetrics::ReportMetrics() {
  base::UmaHistogramCounts100("Extensions.ForceInstalledTotalCandidateCount",
                              tracker_->extensions().size());
  std::set<ExtensionId> missing_forced_extensions;
  InstallStageTracker* install_stage_tracker =
      InstallStageTracker::Get(profile_);
  for (const auto& extension : tracker_->extensions()) {
    if (!IsStatusGood(extension.second.status)) {
      missing_forced_extensions.insert(extension.first);
    } else {
      InstallStageTracker::InstallationData installation =
          install_stage_tracker->Get(extension.first);
      ReportInstallationStageTimes(extension.first, installation);
    }
  }
  if (missing_forced_extensions.empty()) {
    base::UmaHistogramLongTimes("Extensions.ForceInstalledLoadTime",
                                base::Time::Now() - start_time_);
    LOG(WARNING) << "All forced extensions seem to be installed";
    return;
  }
  size_t enabled_missing_count = missing_forced_extensions.size();
  size_t blocklisted_count = 0;
  auto installed_extensions = registry_->GenerateInstalledExtensionsSet();
  const ExtensionSet& blocklisted_extensions =
      registry_->blocklisted_extensions();
  for (const auto& entry : installed_extensions) {
    if (missing_forced_extensions.count(entry->id())) {
      missing_forced_extensions.erase(entry->id());
      ReportDisableReason(entry->id());
      if (blocklisted_extensions.Contains(entry->id())) {
        blocklisted_count++;
      }
    }
  }
  size_t misconfigured_extensions = 0;
  size_t installed_missing_count = missing_forced_extensions.size();

  base::UmaHistogramCounts100("Extensions.ForceInstalledTimedOutCount",
                              enabled_missing_count);
  base::UmaHistogramCounts100(
      "Extensions.ForceInstalledTimedOutAndNotInstalledCount",
      installed_missing_count);
  base::UmaHistogramCounts100("Extensions.ForceInstalledAndBlockListed",
                              blocklisted_count);
  LOG(WARNING) << "Failed to install " << installed_missing_count
               << " forced extensions.";
  for (const auto& extension_id : missing_forced_extensions) {
    InstallStageTracker::InstallationData installation =
        install_stage_tracker->Get(extension_id);
    base::UmaHistogramEnumeration(
        "Extensions.ForceInstalledFailureCacheStatus",
        installation.downloading_cache_status.value_or(
            ExtensionDownloaderDelegate::CacheStatus::CACHE_UNKNOWN));
    if (!installation.failure_reason && installation.install_stage) {
      installation.failure_reason = FailureReason::IN_PROGRESS;
      ReportCurrentStage(installation);
    }
    if (tracker_->IsMisconfiguration(installation, extension_id))
      misconfigured_extensions++;
    FailureReason failure_reason =
        installation.failure_reason.value_or(FailureReason::UNKNOWN);
    base::UmaHistogramEnumeration("Extensions.ForceInstalledFailureReason3",
                                  failure_reason);
    bool is_from_store = tracker_->extensions().at(extension_id).is_from_store;
    if (is_from_store) {
      base::UmaHistogramEnumeration(
          "Extensions.WebStore_ForceInstalledFailureReason3", failure_reason);
    } else {
      base::UmaHistogramEnumeration(
          "Extensions.OffStore_ForceInstalledFailureReason3", failure_reason);
    }

#if BUILDFLAG(IS_CHROMEOS)
    bool is_stuck_in_initial_creation_stage =
        failure_reason == FailureReason::IN_PROGRESS &&
        installation.install_stage == InstallStageTracker::Stage::CREATED &&
        installation.install_creation_stage ==
            InstallStageTracker::InstallCreationStage::
                NOTIFIED_FROM_MANAGEMENT_INITIAL_CREATION_FORCED;
    ReportUserType(profile_, is_stuck_in_initial_creation_stage);
#endif  // BUILDFLAG(IS_CHROMEOS)
    LOG(WARNING) << "Forced extension " << extension_id
                 << " failed to install with data="
                 << InstallStageTracker::GetFormattedInstallationData(
                        installation);
    ReportDetailedFailureReasons(profile_, installation, is_from_store);
  }
  bool non_misconfigured_failure_occurred =
      misconfigured_extensions != missing_forced_extensions.size();
  base::UmaHistogramBoolean(
      "Extensions."
      "ForceInstalledSessionsWithNonMisconfigurationFailureOccured",
      non_misconfigured_failure_occurred);
}

void ForceInstalledMetrics::OnForceInstalledExtensionsLoaded() {
  if (load_reported_)
    return;
  // Report only if there was non-empty list of force-installed extensions.
  if (!tracker_->extensions().empty())
    ReportMetrics();
  load_reported_ = true;
  timer_->Stop();
}

void ForceInstalledMetrics::OnForceInstalledExtensionsReady() {
  if (ready_reported_)
    return;
  // Report only if there was non-empty list of force-installed extensions.
  if (!tracker_->extensions().empty())
    ReportMetricsOnExtensionsReady();
  ready_reported_ = true;
}

void ForceInstalledMetrics::OnExtensionDownloadCacheStatusRetrieved(
    const ExtensionId& id,
    ExtensionDownloaderDelegate::CacheStatus cache_status) {
  UMA_HISTOGRAM_ENUMERATION("Extensions.ForceInstalledCacheStatus",
                            cache_status);
}

}  //  namespace extensions