blob: f8295401523cbf9200307405c708151ecd844146 [file] [log] [blame]
Foromo Daniel Soromou67860ff2025-05-05 15:38:331// Copyright 2025 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_WIN_INSTALLER_DOWNLOADER_INSTALLER_DOWNLOADER_CONTROLLER_H_
6#define CHROME_BROWSER_WIN_INSTALLER_DOWNLOADER_INSTALLER_DOWNLOADER_CONTROLLER_H_
7
Foromo Daniel Soromou9c116012025-05-23 16:02:098#include <map>
Foromo Daniel Soromou67860ff2025-05-05 15:38:339#include <memory>
10#include <optional>
11
Foromo Daniel Soromou9c116012025-05-23 16:02:0912#include "base/callback_list.h"
Foromo Daniel Soromou615461c2025-05-16 14:05:3113#include "base/functional/callback.h"
Foromo Daniel Soromou9c116012025-05-23 16:02:0914#include "base/scoped_multi_source_observation.h"
15#include "chrome/browser/win/installer_downloader/installer_downloader_active_browser_window_tracker.h"
16#include "components/infobars/core/infobar_manager.h"
Foromo Daniel Soromou615461c2025-05-16 14:05:3117
Foromo Daniel Soromoued9d5882025-05-22 14:23:5218class ScopedProfileKeepAlive;
Foromo Daniel Soromou9c116012025-05-23 16:02:0919class BrowserWindowInterface;
Foromo Daniel Soromoued9d5882025-05-22 14:23:5220
Foromo Daniel Soromou67860ff2025-05-05 15:38:3321namespace base {
22class FilePath;
23}
24
25namespace content {
26class WebContents;
27}
28
Foromo Daniel Soromou9c116012025-05-23 16:02:0929namespace infobars {
30class InfoBar;
31class ContentInfoBarManager;
32} // namespace infobars
33
Foromo Daniel Soromou67860ff2025-05-05 15:38:3334namespace installer_downloader {
35
36class InstallerDownloaderModel;
Foromo Daniel Soromou9c116012025-05-23 16:02:0937class InstallerDownloaderActiveBrowserWindowTracker;
38class InstallerDownloaderInfobarWindowActiveTabTracker;
Foromo Daniel Soromou67860ff2025-05-05 15:38:3339
40// UI-thread coordinator for the Installer Downloader.
41// The controller owns a single InstallerDownloaderModel instance and:
42// • Kicks off eligibility checks at browser startup (via Initialize).
43// • Creates / updates the InstallerDownloaderInfoBar when the model reports
44// that the user is eligible.
45// • Relays user actions (Accept / Dismiss) back to the model.
46// • Forwards download progress callbacks to the InfoBar (If needed).
47//
48// Only lightweight UI work happens here; blocking I/O and network transfers
49// live in the model running on the ThreadPool. The browser local state is used
50// tod keep track the infobar show count.
51//
52// The controller is instantiated a GlobalFeature.
Foromo Daniel Soromou9c116012025-05-23 16:02:0953class InstallerDownloaderController final
54 : public infobars::InfoBarManager::Observer {
Foromo Daniel Soromou67860ff2025-05-05 15:38:3355 public:
Foromo Daniel Soromou615461c2025-05-16 14:05:3156 // A callback that will be run to show the installer download infobar in
57 // `web_contents`. `on_accept` will be run if the user accepts the prompt.
58 // This will show the infobar on the actual tab.
59 //
60 // TODO(https://crbug.com/417709084): Make the infobar global to the browser.
Foromo Daniel Soromou9c116012025-05-23 16:02:0961 using ShowInfobarCallback = base::RepeatingCallback<infobars::InfoBar*(
62 infobars::ContentInfoBarManager*,
63 base::OnceClosure on_accept,
64 base::OnceClosure on_dismiss)>;
Foromo Daniel Soromou615461c2025-05-16 14:05:3165
66 using GetActiveWebContentsCallback =
67 base::RepeatingCallback<content::WebContents*()>;
68
Foromo Daniel Soromou615461c2025-05-16 14:05:3169 InstallerDownloaderController(
70 ShowInfobarCallback show_infobar_callback,
Foromo Daniel Soromouce65be02025-05-22 14:14:0671 base::RepeatingCallback<bool()> is_metrics_enabled_callback);
72 InstallerDownloaderController(
73 ShowInfobarCallback show_infobar_callback,
74 base::RepeatingCallback<bool()> is_metrics_enabled_callback,
Foromo Daniel Soromou615461c2025-05-16 14:05:3175 std::unique_ptr<InstallerDownloaderModel> model);
76
Foromo Daniel Soromou67860ff2025-05-05 15:38:3377 InstallerDownloaderController(const InstallerDownloaderController&) = delete;
78 InstallerDownloaderController& operator=(
79 const InstallerDownloaderController&) = delete;
80
Foromo Daniel Soromou9c116012025-05-23 16:02:0981 ~InstallerDownloaderController() override;
Foromo Daniel Soromou67860ff2025-05-05 15:38:3382
83 // Called early during the browser startup and will show the installer
84 // downloader infobar if a set of conditions are met.
85 void MaybeShowInfoBar();
86
87 // Trigger when user give an explicit consent through installer download
88 // infobar.
Foromo Daniel Soromouce65be02025-05-22 14:14:0689 void OnDownloadRequestAccepted(const base::FilePath& destination);
Foromo Daniel Soromou615461c2025-05-16 14:05:3190
Muhammad Salmaandadc22982025-05-20 20:31:2691 // Called when the user dismisses the installer download infobar.
92 void OnInfoBarDismissed();
93
Foromo Daniel Soromou615461c2025-05-16 14:05:3194 void SetActiveWebContentsCallbackForTesting(
95 GetActiveWebContentsCallback callback);
Foromo Daniel Soromou67860ff2025-05-05 15:38:3396
97 private:
Foromo Daniel Soromou9c116012025-05-23 16:02:0998 using BrowserAndActiveTabTrackerMap = std::map<
99 BrowserWindowInterface*,
100 std::unique_ptr<InstallerDownloaderInfobarWindowActiveTabTracker>>;
101
Foromo Daniel Soromou3646aa82025-05-22 17:07:27102 void OnEligibilityReady(std::optional<base::FilePath> destination);
Foromo Daniel Soromoued9d5882025-05-22 14:23:52103 void OnDownloadCompleted(std::unique_ptr<ScopedProfileKeepAlive> keep_alive,
104 bool success);
Foromo Daniel Soromouce65be02025-05-22 14:14:06105
Foromo Daniel Soromou9c116012025-05-23 16:02:09106 void RegisterBrowserWindowEvents();
107
108 void OnActiveBrowserWindowChanged(BrowserWindowInterface* bwi);
109 void OnRemovedBrowserWindow(BrowserWindowInterface* bwi);
110
111 // infobars::InfoBarManager::Observer:
112 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override;
113
Foromo Daniel Soromouce65be02025-05-22 14:14:06114 base::RepeatingCallback<bool()> is_metrics_enabled_callback_;
Foromo Daniel Soromou67860ff2025-05-05 15:38:33115
Foromo Daniel Soromou615461c2025-05-16 14:05:31116 ShowInfobarCallback show_infobar_callback_;
Foromo Daniel Soromou67860ff2025-05-05 15:38:33