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 @@ ...@@ -15,12 +15,14 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/android/chrome_feature_list.h" #include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/android/download/download_controller.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.h"
#include "chrome/browser/download/download_core_service_factory.h" #include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "components/download/public/common/download_item.h" #include "components/download/public/common/download_item.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/download_item_utils.h" #include "content/public/browser/download_item_utils.h"
#include "content/public/browser/notification_service.h"
#include "jni/DownloadInfo_jni.h" #include "jni/DownloadInfo_jni.h"
#include "jni/DownloadItem_jni.h" #include "jni/DownloadItem_jni.h"
#include "jni/DownloadManagerService_jni.h" #include "jni/DownloadManagerService_jni.h"
...@@ -137,6 +139,8 @@ static jlong JNI_DownloadManagerService_Init( ...@@ -137,6 +139,8 @@ static jlong JNI_DownloadManagerService_Init(
DownloadManagerService::DownloadManagerService() DownloadManagerService::DownloadManagerService()
: is_history_query_complete_(false), : is_history_query_complete_(false),
pending_get_downloads_actions_(NONE) { pending_get_downloads_actions_(NONE) {
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
} }
DownloadManagerService::~DownloadManagerService() {} DownloadManagerService::~DownloadManagerService() {}
...@@ -147,6 +151,32 @@ void DownloadManagerService::Init( ...@@ -147,6 +151,32 @@ void DownloadManagerService::Init(
java_ref_.Reset(env, obj); 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( void DownloadManagerService::OpenDownload(
JNIEnv* env, JNIEnv* env,
jobject obj, jobject obj,
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "chrome/browser/download/download_history.h" #include "chrome/browser/download/download_history.h"
#include "components/download/content/public/all_download_item_notifier.h" #include "components/download/content/public/all_download_item_notifier.h"
#include "content/public/browser/download_manager.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; using base::android::JavaParamRef;
...@@ -28,7 +30,8 @@ class DownloadItem; ...@@ -28,7 +30,8 @@ class DownloadItem;
// Java object. // Java object.
class DownloadManagerService class DownloadManagerService
: public download::AllDownloadItemNotifier::Observer, : public download::AllDownloadItemNotifier::Observer,
public DownloadHistory::Observer { public DownloadHistory::Observer,
public content::NotificationObserver {
public: public:
static void OnDownloadCanceled( static void OnDownloadCanceled(
download::DownloadItem* download, download::DownloadItem* download,
...@@ -115,6 +118,11 @@ class DownloadManagerService ...@@ -115,6 +118,11 @@ class DownloadManagerService
void OnDownloadRemoved(content::DownloadManager* manager, void OnDownloadRemoved(content::DownloadManager* manager,
download::DownloadItem* item) override; download::DownloadItem* item) override;
// content::NotificationObserver methods.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
protected: protected:
// Called to get the content::DownloadManager instance. // Called to get the content::DownloadManager instance.
virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record); virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record);
...@@ -180,6 +188,9 @@ class DownloadManagerService ...@@ -180,6 +188,9 @@ class DownloadManagerService
ResumeCallback resume_callback_for_testing_; 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> original_notifier_;
std::unique_ptr<download::AllDownloadItemNotifier> off_the_record_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