From bcef0dc01dad3fff84f0c64389a0ead525181e55 Mon Sep 17 00:00:00 2001 From: "estade@chromium.org" Date: Sat, 28 Feb 2009 00:35:02 +0000 Subject: Refactor download shelf and prepare for porting. Side effect of removing some views dependencies from places they don't belong. Review URL: http://codereview.chromium.org/28252 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10657 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/download/download_item_model.cc | 6 +-- chrome/browser/download/download_item_model.h | 14 ++++--- chrome/browser/download/download_shelf.cc | 29 +++++++++++++++ chrome/browser/download/download_shelf.h | 51 ++++++++++++++++++++++++++ chrome/browser/download/save_package.cc | 17 ++------- 5 files changed, 95 insertions(+), 22 deletions(-) create mode 100644 chrome/browser/download/download_shelf.cc create mode 100644 chrome/browser/download/download_shelf.h (limited to 'chrome/browser/download') diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc index f90ec6b..9b7f764 100644 --- a/chrome/browser/download/download_item_model.cc +++ b/chrome/browser/download/download_item_model.cc @@ -17,7 +17,7 @@ using base::TimeDelta; // DownloadItemModel DownloadItemModel::DownloadItemModel(DownloadItem* download) - : download_(download) { + : BaseDownloadItemModel(download) { } void DownloadItemModel::CancelTask() { @@ -96,8 +96,8 @@ std::wstring DownloadItemModel::GetStatusText() { // SavePageModel SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download) - : save_(save), - download_(download) { + : BaseDownloadItemModel(download), + save_(save) { } void SavePageModel::CancelTask() { diff --git a/chrome/browser/download/download_item_model.h b/chrome/browser/download/download_item_model.h index 8c7fe83..2638ccd 100644 --- a/chrome/browser/download/download_item_model.h +++ b/chrome/browser/download/download_item_model.h @@ -16,11 +16,19 @@ class SavePackage; // depending on the type of download. class BaseDownloadItemModel { public: + BaseDownloadItemModel(DownloadItem* download) : download_(download) { } + virtual ~BaseDownloadItemModel() { } + // Cancel the task corresponding to the item. virtual void CancelTask() = 0; // Get the status text to display. virtual std::wstring GetStatusText() = 0; + + DownloadItem* download() { return download_; } + + protected: + DownloadItem* download_; }; // This class is a model class for DownloadItemView. It provides functionality @@ -38,9 +46,6 @@ class DownloadItemModel : public BaseDownloadItemModel { virtual std::wstring GetStatusText(); private: - // We query this item for status information. - DownloadItem* download_; - DISALLOW_COPY_AND_ASSIGN(DownloadItemModel); }; @@ -62,9 +67,6 @@ class SavePageModel : public BaseDownloadItemModel { // Saving page management. SavePackage* save_; - // A fake download item for saving page use. - DownloadItem* download_; - DISALLOW_COPY_AND_ASSIGN(SavePageModel); }; diff --git a/chrome/browser/download/download_shelf.cc b/chrome/browser/download/download_shelf.cc new file mode 100644 index 0000000..7cce198 --- /dev/null +++ b/chrome/browser/download/download_shelf.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/download/download_shelf.h" + +#include "chrome/browser/dom_ui/downloads_ui.h" +#include "chrome/browser/metrics/user_metrics.h" + +#if defined(OS_WIN) +#include "chrome/browser/tab_contents/tab_contents.h" +#elif defined(OS_POSIX) +#include "chrome/common/temp_scaffolding_stubs.h" +#endif + +void DownloadShelf::ShowAllDownloads() { + Profile* profile = tab_contents_->profile(); + if (profile) + UserMetrics::RecordAction(L"ShowDownloads", profile); + GURL url = DownloadsUI::GetBaseURL(); + tab_contents_->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, + PageTransition::AUTO_BOOKMARK); +} + +void DownloadShelf::ChangeTabContents(TabContents* old_contents, + TabContents* new_contents) { + DCHECK(old_contents == tab_contents_); + tab_contents_ = new_contents; +} diff --git a/chrome/browser/download/download_shelf.h b/chrome/browser/download/download_shelf.h new file mode 100644 index 0000000..d3b83a1 --- /dev/null +++ b/chrome/browser/download/download_shelf.h @@ -0,0 +1,51 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_ +#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_ + +#include "base/basictypes.h" + +class BaseDownloadItemModel; +class TabContents; + +// DownloadShelf is an interface for platform-specific download shelves to +// implement. It also contains some shared logic. This class should not be +// instantiated directly, but rather created via a call to Create(). +class DownloadShelf { + public: + explicit DownloadShelf(TabContents* tab_contents) + : tab_contents_(tab_contents) { } + + virtual ~DownloadShelf() { } + + // Creates a platform-specific DownloadShelf, passing ownership to the caller. + static DownloadShelf* Create(TabContents* tab_contents); + + // A new download has started, so add it to our shelf. This object will + // take ownership of |download_model|. + virtual void AddDownload(BaseDownloadItemModel* download_model) = 0; + + // Invoked when the user clicks the 'show all downloads' link button. + void ShowAllDownloads(); + + // Invoked when the download shelf is migrated from one tab contents to a new + // one. + void ChangeTabContents(TabContents* old_contents, TabContents* new_contents); + + // The browser view needs to know when we are going away to properly return + // the resize corner size to WebKit so that we don't draw on top of it. + // This returns the showing state of our animation which is set to false at + // the beginning Show and true at the beginning of a Hide. + virtual bool IsShowing() const = 0; + + protected: + TabContents* tab_contents_; + + private: + DISALLOW_COPY_AND_ASSIGN(DownloadShelf); +}; + +#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_ + diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 1bccaa9..6af6c05 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -14,6 +14,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/download/download_shelf.h" #include "chrome/browser/download/save_file.h" #include "chrome/browser/download/save_file_manager.h" #include "chrome/browser/profile.h" @@ -41,14 +42,6 @@ #include "chrome/common/win_util.h" #endif -#if defined(OS_WIN) -// TODO(port): port these headers. -#include "chrome/browser/views/download_item_view.h" -#include "chrome/browser/views/download_shelf_view.h" -#elif defined(OS_POSIX) -#include "chrome/common/temp_scaffolding_stubs.h" -#endif - using base::Time; namespace { @@ -272,13 +265,11 @@ bool SavePackage::Init() { FilePath(), Time::Now(), 0, -1, -1, false); download_->set_manager(web_contents_->profile()->GetDownloadManager()); #if defined(OS_WIN) - // TODO(port): We need to do something like this on posix, but avoid - // using DownloadShelfView, which probably should not be ported directly. - DownloadShelfView* shelf = web_contents_->GetDownloadShelfView(); - shelf->AddDownloadView(new DownloadItemView( - download_, shelf, new SavePageModel(this, download_))); + DownloadShelf* shelf = web_contents_->GetDownloadShelf(); + shelf->AddDownload(new SavePageModel(this, download_)); web_contents_->SetDownloadShelfVisible(true); #elif defined(OS_POSIX) + // TODO(port): Create a download shelf for linux and mac. NOTIMPLEMENTED(); #endif -- cgit v1.1