Commit c0e91a03 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NotificationService usage from DownloadReporter.

Bug: 268984
Change-Id: I20f24122630f106c66cf8af40cb373124678f1b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1955811Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723398}
parent 47c3c4ed
......@@ -5,20 +5,18 @@
#include "chrome/browser/safe_browsing/download_protection/download_reporter.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/simple_download_manager_coordinator_factory.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "components/download/public/common/download_danger_type.h"
#include "components/download/public/common/download_item.h"
#include "components/download/public/common/simple_download_manager_coordinator.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_service.h"
namespace safe_browsing {
......@@ -89,21 +87,28 @@ void ReportDangerousDownloadWarningBypassed(
} // namespace
DownloadReporter::DownloadReporter() {
profiles_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
// Profile manager can be null in unit tests.
if (g_browser_process->profile_manager())
g_browser_process->profile_manager()->AddObserver(this);
}
DownloadReporter::~DownloadReporter() = default;
void DownloadReporter::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_CREATED);
Profile* profile = content::Source<Profile>(source).ptr();
download::SimpleDownloadManagerCoordinator* coordinator =
SimpleDownloadManagerCoordinatorFactory::GetForKey(
profile->GetProfileKey());
observed_coordinators_.Add(coordinator);
DownloadReporter::~DownloadReporter() {
if (g_browser_process->profile_manager())
g_browser_process->profile_manager()->RemoveObserver(this);
}
void DownloadReporter::OnProfileAdded(Profile* profile) {
observed_profiles_.Add(profile);
observed_coordinators_.Add(SimpleDownloadManagerCoordinatorFactory::GetForKey(
profile->GetProfileKey()));
}
void DownloadReporter::OnOffTheRecordProfileCreated(Profile* off_the_record) {
OnProfileAdded(off_the_record);
}
void DownloadReporter::OnProfileWillBeDestroyed(Profile* profile) {
observed_profiles_.Remove(profile);
}
void DownloadReporter::OnManagerGoingDown(
......
......@@ -7,10 +7,11 @@
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "components/download/public/common/download_item.h"
#include "components/download/public/common/simple_download_manager_coordinator.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
namespace safe_browsing {
......@@ -19,29 +20,32 @@ namespace safe_browsing {
class DownloadReporter
: public download::DownloadItem::Observer,
public download::SimpleDownloadManagerCoordinator::Observer,
public content::NotificationObserver {
public ProfileManagerObserver,
public ProfileObserver {
public:
DownloadReporter();
~DownloadReporter() override;
// NotificationObserver implementation:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ProfileManagerObserver:
void OnProfileAdded(Profile* profile) override;
// SimpleDownloadManagerCoordinator::Observer implementation:
// ProfileObserver:
void OnOffTheRecordProfileCreated(Profile* off_the_record) override;
void OnProfileWillBeDestroyed(Profile* profile) override;
// SimpleDownloadManagerCoordinator::Observer:
void OnManagerGoingDown(
download::SimpleDownloadManagerCoordinator* coordinator) override;
void OnDownloadCreated(download::DownloadItem* download) override;
// DownloadItem::Observer implementation:
// DownloadItem::Observer:
void OnDownloadDestroyed(download::DownloadItem* download) override;
void OnDownloadUpdated(download::DownloadItem* download) override;
private:
content::NotificationRegistrar profiles_registrar_;
base::flat_map<download::DownloadItem*, download::DownloadDangerType>
danger_types_;
ScopedObserver<Profile, ProfileObserver> observed_profiles_{this};
ScopedObserver<download::SimpleDownloadManagerCoordinator,
download::SimpleDownloadManagerCoordinator::Observer>
observed_coordinators_{this};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment