Skip to content

Commit

Permalink
Download Infobar : Fixed bugs in incognito
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
Shakti Sahu committed Jun 1, 2018
1 parent a479208 commit 23e43f9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
30 changes: 30 additions & 0 deletions chrome/browser/android/download/download_manager_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {}
Expand All @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion chrome/browser/android/download/download_manager_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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_;

Expand Down

0 comments on commit 23e43f9

Please sign in to comment.