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