// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_MULTI_PROFILE_DOWNLOAD_NOTIFIER_H_ #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_MULTI_PROFILE_DOWNLOAD_NOTIFIER_H_ #include <memory> #include <set> #include <string> #include "base/containers/unique_ptr_adapters.h" #include "base/memory/raw_ptr.h" #include "base/scoped_multi_source_observation.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_observer.h" #include "components/download/content/public/all_download_item_notifier.h" // `MultiProfileDownloadNotifier` observes the `DownloadItem`s created on an // arbitrary number of `Profile`s. No `Profile`s are observed by default; a // client must specify `Profile`s to be observed using `AddProfile()`. Once a // `Profile` is being observed, any off-the-record profile it has spawned or // spawns later will also be observed unless it is filtered out by // `ShouldObserveProfile()`. // Example Usage: // class DownloadsDelegate : public MultiProfileDownloadNotifier::Client { // public: // DownloadsDelegate(Profile* profile) { // downloads_notifier_.AddProfile(profile); // } // // void OnManagerInitialized(content::DownloadManager* manager) override { ... } // void OnManagerGoingDown(content::DownloadManager* manager) override { ... } // void OnDownloadCreated(content::DownloadManager* manager, // download::DownloadItem* item) override { ... } // void OnDownloadUpdated(content::DownloadManager* manager, // download::DownloadItem* item) override { ... } // void OnDownloadDestroyed(content::DownloadManager* manager, // download::DownloadItem* item) override { ... } // bool ShouldObserveProfile(Profile* profile) override { ... } // // private: // MultiProfileDownloadNotifier downloads_notifier_{this}; // }; namespace content { class DownloadManager; } // namespace content namespace download { class DownloadItem; } // namespace download class MultiProfileDownloadNotifier : public ProfileObserver, public download::AllDownloadItemNotifier::Observer { … }; #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_MULTI_PROFILE_DOWNLOAD_NOTIFIER_H_