Skip to content

Commit 23e43f9

Browse files
author
Shakti Sahu
committed
Download Infobar : Fixed bugs in incognito
For incognito profiles, the infobar is not being shown since the DownloadManagerService only starts observing the download item updates after we open download home in incognito. Fixed this bug in this CL. Bug: 846139 Change-Id: I507c285901474ce47f09a1610639805afe3c904f Reviewed-on: https://chromium-review.googlesource.com/1073078 Commit-Queue: Shakti Sahu <[email protected]> Reviewed-by: Min Qin <[email protected]> Reviewed-by: David Trainor <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#563066}(cherry picked from commit 90ca68a) Reviewed-on: https://chromium-review.googlesource.com/1080973 Reviewed-by: Shakti Sahu <[email protected]> Cr-Commit-Position: refs/branch-heads/3440@{#74} Cr-Branched-From: 010ddcf-refs/heads/master@{#561733}
1 parent a479208 commit 23e43f9

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

chrome/browser/android/download/download_manager_service.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
#include "base/time/time.h"
1616
#include "chrome/browser/android/chrome_feature_list.h"
1717
#include "chrome/browser/android/download/download_controller.h"
18+
#include "chrome/browser/chrome_notification_types.h"
1819
#include "chrome/browser/download/download_core_service.h"
1920
#include "chrome/browser/download/download_core_service_factory.h"
2021
#include "chrome/browser/profiles/profile_manager.h"
2122
#include "components/download/public/common/download_item.h"
2223
#include "content/public/browser/browser_context.h"
2324
#include "content/public/browser/download_item_utils.h"
25+
#include "content/public/browser/notification_service.h"
2426
#include "jni/DownloadInfo_jni.h"
2527
#include "jni/DownloadItem_jni.h"
2628
#include "jni/DownloadManagerService_jni.h"
@@ -137,6 +139,8 @@ static jlong JNI_DownloadManagerService_Init(
137139
DownloadManagerService::DownloadManagerService()
138140
: is_history_query_complete_(false),
139141
pending_get_downloads_actions_(NONE) {
142+
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
143+
content::NotificationService::AllSources());
140144
}
141145

142146
DownloadManagerService::~DownloadManagerService() {}
@@ -147,6 +151,32 @@ void DownloadManagerService::Init(
147151
java_ref_.Reset(env, obj);
148152
}
149153

154+
void DownloadManagerService::Observe(
155+
int type,
156+
const content::NotificationSource& source,
157+
const content::NotificationDetails& details) {
158+
switch (type) {
159+
case chrome::NOTIFICATION_PROFILE_CREATED: {
160+
Profile* profile = content::Source<Profile>(source).ptr();
161+
content::DownloadManager* manager =
162+
content::BrowserContext::GetDownloadManager(profile);
163+
if (!manager)
164+
break;
165+
166+
auto& notifier = profile->IsOffTheRecord() ? off_the_record_notifier_
167+
: original_notifier_;
168+
169+
// Update notifiers to monitor any newly created DownloadManagers.
170+
if (!notifier || notifier->GetManager() != manager) {
171+
notifier =
172+
std::make_unique<download::AllDownloadItemNotifier>(manager, this);
173+
}
174+
} break;
175+
default:
176+
NOTREACHED();
177+
}
178+
}
179+
150180
void DownloadManagerService::OpenDownload(
151181
JNIEnv* env,
152182
jobject obj,

chrome/browser/android/download/download_manager_service.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "chrome/browser/download/download_history.h"
1818
#include "components/download/content/public/all_download_item_notifier.h"
1919
#include "content/public/browser/download_manager.h"
20+
#include "content/public/browser/notification_observer.h"
21+
#include "content/public/browser/notification_registrar.h"
2022

2123
using base::android::JavaParamRef;
2224

@@ -28,7 +30,8 @@ class DownloadItem;
2830
// Java object.
2931
class DownloadManagerService
3032
: public download::AllDownloadItemNotifier::Observer,
31-
public DownloadHistory::Observer {
33+
public DownloadHistory::Observer,
34+
public content::NotificationObserver {
3235
public:
3336
static void OnDownloadCanceled(
3437
download::DownloadItem* download,
@@ -115,6 +118,11 @@ class DownloadManagerService
115118
void OnDownloadRemoved(content::DownloadManager* manager,
116119
download::DownloadItem* item) override;
117120

121+
// content::NotificationObserver methods.
122+
void Observe(int type,
123+
const content::NotificationSource& source,
124+
const content::NotificationDetails& details) override;
125+
118126
protected:
119127
// Called to get the content::DownloadManager instance.
120128
virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record);
@@ -180,6 +188,9 @@ class DownloadManagerService
180188

181189
ResumeCallback resume_callback_for_testing_;
182190

191+
// The Registrar used to register for notifications.
192+
content::NotificationRegistrar registrar_;
193+
183194
std::unique_ptr<download::AllDownloadItemNotifier> original_notifier_;
184195
std::unique_ptr<download::AllDownloadItemNotifier> off_the_record_notifier_;
185196

0 commit comments

Comments
 (0)