Commit 90ca68a8 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

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 <shaktisahu@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563066}
parent 14eeb1d5
......@@ -15,12 +15,14 @@
#include "base/time/time.h"
#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/android/download/download_controller.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/download/public/common/download_item.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/notification_service.h"
#include "jni/DownloadInfo_jni.h"
#include "jni/DownloadItem_jni.h"
#include "jni/DownloadManagerService_jni.h"
......@@ -137,6 +139,8 @@ static jlong JNI_DownloadManagerService_Init(
DownloadManagerService::DownloadManagerService()
: is_history_query_complete_(false),
pending_get_downloads_actions_(NONE) {
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
}
DownloadManagerService::~DownloadManagerService() {}
......@@ -147,6 +151,32 @@ void DownloadManagerService::Init(
java_ref_.Reset(env, obj);
}
void DownloadManagerService::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_PROFILE_CREATED: {
Profile* profile = content::Source<Profile>(source).ptr();
content::DownloadManager* manager =
content::BrowserContext::GetDownloadManager(profile);
if (!manager)
break;
auto& notifier = profile->IsOffTheRecord() ? off_the_record_notifier_
: original_notifier_;
// Update notifiers to monitor any newly created DownloadManagers.
if (!notifier || notifier->GetManager() != manager) {
notifier =
std::make_unique<download::AllDownloadItemNotifier>(manager, this);
}
} break;
default:
NOTREACHED();
}
}
void DownloadManagerService::OpenDownload(
JNIEnv* env,
jobject obj,
......
......@@ -17,6 +17,8 @@
#include "chrome/browser/download/download_history.h"
#include "components/download/content/public/all_download_item_notifier.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
using base::android::JavaParamRef;
......@@ -28,7 +30,8 @@ class DownloadItem;
// Java object.
class DownloadManagerService
: public download::AllDownloadItemNotifier::Observer,
public DownloadHistory::Observer {
public DownloadHistory::Observer,
public content::NotificationObserver {
public:
static void OnDownloadCanceled(
download::DownloadItem* download,
......@@ -115,6 +118,11 @@ class DownloadManagerService
void OnDownloadRemoved(content::DownloadManager* manager,
download::DownloadItem* item) override;
// content::NotificationObserver methods.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
protected:
// Called to get the content::DownloadManager instance.
virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record);
......@@ -180,6 +188,9 @@ class DownloadManagerService
ResumeCallback resume_callback_for_testing_;
// The Registrar used to register for notifications.
content::NotificationRegistrar registrar_;
std::unique_ptr<download::AllDownloadItemNotifier> original_notifier_;
std::unique_ptr<download::AllDownloadItemNotifier> off_the_record_notifier_;
......
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