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 @@ ...@@ -5,20 +5,18 @@
#include "chrome/browser/safe_browsing/download_protection/download_reporter.h" #include "chrome/browser/safe_browsing/download_protection/download_reporter.h"
#include "base/strings/string_number_conversions.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/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.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router_factory.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_key.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.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_danger_type.h"
#include "components/download/public/common/download_item.h" #include "components/download/public/common/download_item.h"
#include "components/download/public/common/simple_download_manager_coordinator.h" #include "components/download/public/common/simple_download_manager_coordinator.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_item_utils.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 { namespace safe_browsing {
...@@ -89,21 +87,28 @@ void ReportDangerousDownloadWarningBypassed( ...@@ -89,21 +87,28 @@ void ReportDangerousDownloadWarningBypassed(
} // namespace } // namespace
DownloadReporter::DownloadReporter() { DownloadReporter::DownloadReporter() {
profiles_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, // Profile manager can be null in unit tests.
content::NotificationService::AllSources()); if (g_browser_process->profile_manager())
g_browser_process->profile_manager()->AddObserver(this);
} }
DownloadReporter::~DownloadReporter() = default; DownloadReporter::~DownloadReporter() {
if (g_browser_process->profile_manager())
void DownloadReporter::Observe(int type, g_browser_process->profile_manager()->RemoveObserver(this);
const content::NotificationSource& source, }
const content::NotificationDetails& details) {
DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_CREATED); void DownloadReporter::OnProfileAdded(Profile* profile) {
Profile* profile = content::Source<Profile>(source).ptr(); observed_profiles_.Add(profile);
download::SimpleDownloadManagerCoordinator* coordinator = observed_coordinators_.Add(SimpleDownloadManagerCoordinatorFactory::GetForKey(
SimpleDownloadManagerCoordinatorFactory::GetForKey( profile->GetProfileKey()));
profile->GetProfileKey()); }
observed_coordinators_.Add(coordinator);
void DownloadReporter::OnOffTheRecordProfileCreated(Profile* off_the_record) {
OnProfileAdded(off_the_record);
}
void DownloadReporter::OnProfileWillBeDestroyed(Profile* profile) {
observed_profiles_.Remove(profile);
} }
void DownloadReporter::OnManagerGoingDown( void DownloadReporter::OnManagerGoingDown(
......
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/scoped_observer.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/download_item.h"
#include "components/download/public/common/simple_download_manager_coordinator.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 { namespace safe_browsing {
...@@ -19,29 +20,32 @@ namespace safe_browsing { ...@@ -19,29 +20,32 @@ namespace safe_browsing {
class DownloadReporter class DownloadReporter
: public download::DownloadItem::Observer, : public download::DownloadItem::Observer,
public download::SimpleDownloadManagerCoordinator::Observer, public download::SimpleDownloadManagerCoordinator::Observer,
public content::NotificationObserver { public ProfileManagerObserver,
public ProfileObserver {
public: public:
DownloadReporter(); DownloadReporter();
~DownloadReporter() override; ~DownloadReporter() override;
// NotificationObserver implementation: // ProfileManagerObserver:
void Observe(int type, void OnProfileAdded(Profile* profile) override;
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// SimpleDownloadManagerCoordinator::Observer implementation: // ProfileObserver:
void OnOffTheRecordProfileCreated(Profile* off_the_record) override;
void OnProfileWillBeDestroyed(Profile* profile) override;
// SimpleDownloadManagerCoordinator::Observer:
void OnManagerGoingDown( void OnManagerGoingDown(
download::SimpleDownloadManagerCoordinator* coordinator) override; download::SimpleDownloadManagerCoordinator* coordinator) override;
void OnDownloadCreated(download::DownloadItem* download) override; void OnDownloadCreated(download::DownloadItem* download) override;
// DownloadItem::Observer implementation: // DownloadItem::Observer:
void OnDownloadDestroyed(download::DownloadItem* download) override; void OnDownloadDestroyed(download::DownloadItem* download) override;
void OnDownloadUpdated(download::DownloadItem* download) override; void OnDownloadUpdated(download::DownloadItem* download) override;
private: private:
content::NotificationRegistrar profiles_registrar_;
base::flat_map<download::DownloadItem*, download::DownloadDangerType> base::flat_map<download::DownloadItem*, download::DownloadDangerType>
danger_types_; danger_types_;
ScopedObserver<Profile, ProfileObserver> observed_profiles_{this};
ScopedObserver<download::SimpleDownloadManagerCoordinator, ScopedObserver<download::SimpleDownloadManagerCoordinator,
download::SimpleDownloadManagerCoordinator::Observer> download::SimpleDownloadManagerCoordinator::Observer>
observed_coordinators_{this}; 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