Commit 3df6ea8d authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Store the browser/profile on DownloadShelf.

This eliminates the need for implementations to override the getters.

Bug: none
Change-Id: I3df33cd593c3c600739b5b0546270d89342394aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2250822
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779679}
parent 7b5f9f1a
......@@ -107,8 +107,11 @@ void GetDownload(Profile* profile,
} // namespace
DownloadShelf::DownloadShelf()
: should_show_on_unhide_(false), is_hidden_(false) {}
DownloadShelf::DownloadShelf(Browser* browser, Profile* profile)
: browser_(browser),
profile_(profile),
should_show_on_unhide_(false),
is_hidden_(false) {}
DownloadShelf::~DownloadShelf() {}
......@@ -234,10 +237,6 @@ base::TimeDelta DownloadShelf::GetTransientDownloadShowDelay() {
return base::TimeDelta::FromSeconds(kDownloadShowDelayInSeconds);
}
Profile* DownloadShelf::profile() const {
return browser() ? browser()->profile() : nullptr;
}
void DownloadShelf::ShowDownload(DownloadUIModelPtr download) {
if (download->GetState() == DownloadItem::COMPLETE &&
download->ShouldRemoveFromShelfWhenComplete())
......@@ -255,8 +254,8 @@ void DownloadShelf::ShowDownload(DownloadUIModelPtr download) {
Open();
DoAddDownload(std::move(download));
// browser() can be NULL for tests.
if (!browser())
// browser_ can be null for tests.
if (!browser_)
return;
// Show the download started animation if:
......@@ -266,7 +265,7 @@ void DownloadShelf::ShowDownload(DownloadUIModelPtr download) {
// or running under a test etc.)
// - Rich animations are enabled.
content::WebContents* shelf_tab =
browser()->tab_strip_model()->GetActiveWebContents();
browser_->tab_strip_model()->GetActiveWebContents();
if (should_show_download_started_animation && shelf_tab &&
platform_util::IsVisible(shelf_tab->GetNativeView()) &&
gfx::Animation::ShouldRenderRichAnimation()) {
......@@ -275,7 +274,7 @@ void DownloadShelf::ShowDownload(DownloadUIModelPtr download) {
}
void DownloadShelf::ShowDownloadById(ContentId id) {
GetDownload(profile(), id,
GetDownload(profile_, id,
base::BindOnce(&DownloadShelf::ShowDownload,
weak_ptr_factory_.GetWeakPtr()));
}
......@@ -33,7 +33,7 @@ class DownloadShelf {
// Size of the space used for the progress indicator.
static constexpr int kProgressIndicatorSize = 25;
DownloadShelf();
DownloadShelf(Browser* browser, Profile* profile);
virtual ~DownloadShelf();
// Paint the common download animation progress foreground and background,
......@@ -84,7 +84,7 @@ class DownloadShelf {
// when it was hidden, or was shown while it was hidden.
void Unhide();
virtual Browser* browser() const = 0;
Browser* browser() { return browser_; }
// Returns whether the download shelf is hidden.
bool is_hidden() { return is_hidden_; }
......@@ -100,8 +100,7 @@ class DownloadShelf {
// Protected virtual for testing.
virtual base::TimeDelta GetTransientDownloadShowDelay();
// Virtual for testing.
virtual Profile* profile() const;
Profile* profile() { return profile_; }
private:
// Show the download on the shelf immediately. Also displayes the download
......@@ -111,6 +110,8 @@ class DownloadShelf {
// Similar to ShowDownload() but refers to the download using an ID.
void ShowDownloadById(ContentId id);
Browser* const browser_;
Profile* const profile_;
bool should_show_on_unhide_;
bool is_hidden_;
base::WeakPtrFactory<DownloadShelf> weak_ptr_factory_{this};
......
......@@ -7,7 +7,9 @@
#include "content/public/browser/download_manager.h"
TestDownloadShelf::TestDownloadShelf(Profile* profile)
: is_showing_(false), did_add_download_(false), profile_(profile) {}
: DownloadShelf(nullptr, profile),
is_showing_(false),
did_add_download_(false) {}
TestDownloadShelf::~TestDownloadShelf() = default;
......@@ -19,10 +21,6 @@ bool TestDownloadShelf::IsClosing() const {
return false;
}
Browser* TestDownloadShelf::browser() const {
return NULL;
}
void TestDownloadShelf::DoAddDownload(DownloadUIModelPtr download) {
did_add_download_ = true;
}
......@@ -46,7 +44,3 @@ void TestDownloadShelf::DoUnhide() {
base::TimeDelta TestDownloadShelf::GetTransientDownloadShowDelay() {
return base::TimeDelta();
}
Profile* TestDownloadShelf::profile() const {
return profile_;
}
......@@ -22,14 +22,10 @@ class TestDownloadShelf : public DownloadShelf {
// DownloadShelf:
bool IsShowing() const override;
bool IsClosing() const override;
Browser* browser() const override;
// Return |true| if a download was added to this shelf.
bool did_add_download() const { return did_add_download_; }
// Set a profile.
void set_profile(Profile* profile) { profile_ = profile; }
protected:
void DoAddDownload(DownloadUIModelPtr download) override;
void DoOpen() override;
......@@ -37,12 +33,10 @@ class TestDownloadShelf : public DownloadShelf {
void DoHide() override;
void DoUnhide() override;
base::TimeDelta GetTransientDownloadShowDelay() override;
Profile* profile() const override;
private:
bool is_showing_;
bool did_add_download_;
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(TestDownloadShelf);
};
......
......@@ -24,7 +24,6 @@
#include "components/strings/grit/components_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/page_navigator.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/theme_provider.h"
......@@ -63,7 +62,7 @@ int CenterPosition(int size, int target_size) {
DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent)
: AnimationDelegateViews(this),
browser_(browser),
DownloadShelf(browser, browser->profile()),
new_item_animation_(this),
shelf_animation_(this),
parent_(parent),
......@@ -163,8 +162,7 @@ void DownloadShelfView::ConfigureButtonForTheme(views::MdTextButton* button) {
GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT));
// For the normal theme, just use the default button bg color.
base::Optional<SkColor> bg_color;
if (!ThemeServiceFactory::GetForProfile(browser_->profile())
->UsingDefaultTheme()) {
if (!ThemeServiceFactory::GetForProfile(profile())->UsingDefaultTheme()) {
// For custom themes, we have to make up a background color for the
// button. Use a slight tint of the shelf background.
bg_color = color_utils::BlendTowardMaxContrast(
......@@ -192,10 +190,6 @@ void DownloadShelfView::OpenedDownload() {
mouse_watcher_.Start(GetWidget()->GetNativeWindow());
}
content::PageNavigator* DownloadShelfView::GetNavigator() {
return browser_;
}
gfx::Size DownloadShelfView::CalculatePreferredSize() const {
gfx::Size prefsize(kEndPadding + kStartPadding + kCloseAndLinkPadding, 0);
AdjustSize(close_button_, &prefsize);
......@@ -339,7 +333,7 @@ void DownloadShelfView::ButtonPressed(
if (button == close_button_)
Close();
else if (button == show_all_view_)
chrome::ShowDownloads(browser_);
chrome::ShowDownloads(browser());
else
NOTREACHED();
}
......@@ -374,10 +368,6 @@ void DownloadShelfView::DoUnhide() {
parent_->SetDownloadShelfVisible(true);
}
Browser* DownloadShelfView::browser() const {
return browser_;
}
void DownloadShelfView::Closed() {
// Don't remove completed downloads if the shelf is just being auto-hidden
// rather than explicitly closed by the user.
......
......@@ -22,10 +22,6 @@ class Browser;
class BrowserView;
class DownloadItemView;
namespace content {
class PageNavigator;
}
namespace views {
class ImageButton;
class MdTextButton;
......@@ -47,10 +43,6 @@ class DownloadShelfView : public views::AccessiblePaneView,
// Sent from the DownloadItemView when the user opens an item.
void OpenedDownload();
// Returns the relevant containing object that can load pages.
// i.e. the |browser_|.
content::PageNavigator* GetNavigator();
// Returns the parent_.
BrowserView* get_parent() { return parent_; }
......@@ -70,7 +62,6 @@ class DownloadShelfView : public views::AccessiblePaneView,
// DownloadShelf:
bool IsShowing() const override;
bool IsClosing() const override;
Browser* browser() const override;
// views::MouseWatcherListener:
void MouseMovedOutOfHost() override;
......@@ -135,9 +126,6 @@ class DownloadShelfView : public views::AccessiblePaneView,
// Returns the color of text for the shelf (used for deriving icon color).
SkColor GetTextColorForIconMd();
// The browser for this shelf.
Browser* const browser_;
// The animation for adding new items to the shelf.
gfx::SlideAnimation new_item_animation_;
......
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