Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3330)

Unified Diff: chrome/browser/download/download_ui_controller.cc

Issue 966983002: downloads: clicking "remove" on chrome://downloads should also hide shelf item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: probably more like this Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_ui_controller.cc
diff --git a/chrome/browser/download/download_ui_controller.cc b/chrome/browser/download/download_ui_controller.cc
index 5c249cd3f5f9ef2858758f9265bac233a59e8ed7..74e0ac5e7e26995a06f137c25dd1970a4a36e4e8 100644
--- a/chrome/browser/download/download_ui_controller.cc
+++ b/chrome/browser/download/download_ui_controller.cc
@@ -7,7 +7,6 @@
#include "base/callback.h"
#include "base/stl_util.h"
#include "chrome/browser/download/download_item_model.h"
-#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/web_contents.h"
@@ -16,95 +15,12 @@
#if defined(OS_ANDROID)
#include "content/public/browser/android/download_controller_android.h"
#else
+#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/profiles/profile.h"
#endif
-namespace {
-
-// DefaultUIControllerDelegate{Android,} is used when a DownloadUIController is
-// constructed without specifying an explicit Delegate.
-#if defined(OS_ANDROID)
-
-class DefaultUIControllerDelegateAndroid
- : public DownloadUIController::Delegate {
- public:
- DefaultUIControllerDelegateAndroid() {}
- ~DefaultUIControllerDelegateAndroid() override {}
-
- private:
- // DownloadUIController::Delegate
- void OnNewDownloadReady(content::DownloadItem* item) override;
-};
-
-void DefaultUIControllerDelegateAndroid::OnNewDownloadReady(
- content::DownloadItem* item) {
- // The Android DownloadController is only interested in IN_PROGRESS downloads.
- // Ones which are INTERRUPTED etc. can't be handed over to the Android
- // DownloadManager.
- if (item->GetState() != content::DownloadItem::IN_PROGRESS)
- return;
-
- // GET downloads without authentication are delegated to the Android
- // DownloadManager. Chrome is responsible for the rest. See
- // InterceptDownloadResourceThrottle::ProcessDownloadRequest().
- content::DownloadControllerAndroid::Get()->OnDownloadStarted(item);
-}
-
-#else // OS_ANDROID
-
-class DefaultUIControllerDelegate : public DownloadUIController::Delegate {
- public:
- // |profile| is required to outlive DefaultUIControllerDelegate.
- explicit DefaultUIControllerDelegate(Profile* profile)
- : profile_(profile) {}
- ~DefaultUIControllerDelegate() override {}
-
- private:
- // DownloadUIController::Delegate
- void OnNewDownloadReady(content::DownloadItem* item) override;
-
- Profile* profile_;
-};
-
-void DefaultUIControllerDelegate::OnNewDownloadReady(
- content::DownloadItem* item) {
- content::WebContents* web_contents = item->GetWebContents();
- Browser* browser =
- web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL;
-
- // As a last resort, use the last active browser for this profile. Not ideal,
- // but better than not showing the download at all.
- if (browser == NULL) {
- browser = chrome::FindLastActiveWithProfile(profile_,
- chrome::GetActiveDesktop());
- }
-
- if (browser)
- browser->ShowDownload(item);
-}
-
-#endif // !OS_ANDROID
-
-} // namespace
-
-DownloadUIController::Delegate::~Delegate() {
-}
-
-DownloadUIController::DownloadUIController(content::DownloadManager* manager,
- scoped_ptr<Delegate> delegate)
- : download_notifier_(manager, this),
- delegate_(delegate.Pass()) {
- if (!delegate_) {
-#if defined(OS_ANDROID)
- delegate_.reset(new DefaultUIControllerDelegateAndroid());
-#else
- // The delegate should not be invoked after the profile has gone away. This
- // should be the case since DownloadUIController is owned by
- // DownloadService, which in turn is a profile keyed service.
- delegate_.reset(new DefaultUIControllerDelegate(
- Profile::FromBrowserContext(manager->GetBrowserContext())));
-#endif
- }
+DownloadUIController::DownloadUIController(content::DownloadManager* manager)
+ : download_notifier_(manager, this) {
}
DownloadUIController::~DownloadUIController() {
@@ -130,6 +46,34 @@ void DownloadUIController::OnDownloadUpdated(content::DownloadManager* manager,
if (item->GetTargetFilePath().empty())
return;
- DownloadItemModel(item).SetWasUINotified(true);
- delegate_->OnNewDownloadReady(item);
+ item_model.SetWasUINotified(true);
+
+#if defined(OS_ANDROID)
+ // The Android DownloadController is only interested in IN_PROGRESS
+ // downloads. Ones which are INTERRUPTED etc. can't be handed over to the
+ // Android DownloadManager.
+ if (item->GetState() != content::DownloadItem::IN_PROGRESS)
+ return;
+
+ // GET downloads without authentication are delegated to the Android
+ // DownloadManager. Chrome is responsible for the rest. See
+ // InterceptDownloadResourceThrottle::ProcessDownloadRequest().
+ content::DownloadControllerAndroid::Get()->OnDownloadStarted(item);
+#else
+ content::WebContents* web_contents = item->GetWebContents();
+ Browser* browser =
+ web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL;
+
+ // As a last resort, use the last active browser for this profile. Not
+ // ideal, but better than not showing the download at all.
+ if (!browser) {
+ Profile* profile = Profile::FromBrowserContext(
+ download_notifier_.GetManager()->GetBrowserContext());
+ browser = chrome::FindLastActiveWithProfile(profile,
+ chrome::GetActiveDesktop());
+ }
+
+ if (browser)
+ browser->ShowDownload(item);
+#endif
}

Powered by Google App Engine
This is Rietveld 408576698