summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-23 23:54:18 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-23 23:54:18 +0000
commitb47da7280c58ec3467a5f48c409db08072be8989 (patch)
tree29547400046f2027abe2c24732ad279280167be0 /chrome
parente134a72dd5bc286a4ce3007817f53ff62d785055 (diff)
downloadchromium_src-b47da7280c58ec3467a5f48c409db08072be8989.zip
chromium_src-b47da7280c58ec3467a5f48c409db08072be8989.tar.gz
chromium_src-b47da7280c58ec3467a5f48c409db08072be8989.tar.bz2
Refactor BaseDownloadItemModel and its inheritors.
* Move BaseDownloadItemModel to download_item_model.h. Previously it was in a windows-specific file in chrome/browser/views/. * Move SavePageModel to download_item_model.{cc,h}. Review URL: http://codereview.chromium.org/28033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10226 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser.scons4
-rw-r--r--chrome/browser/browser.vcproj8
-rw-r--r--chrome/browser/download/download_file.cc3
-rw-r--r--chrome/browser/download/download_file.h1
-rw-r--r--chrome/browser/download/download_item_model.cc42
-rw-r--r--chrome/browser/download/download_item_model.h50
-rw-r--r--chrome/browser/download/download_util.cc5
-rw-r--r--chrome/browser/download/download_util.h23
-rw-r--r--chrome/browser/download/save_package.cc3
-rw-r--r--chrome/browser/download/save_page_model.cc47
-rw-r--r--chrome/browser/download/save_page_model.h38
-rw-r--r--chrome/browser/views/download_item_view.cc3
-rw-r--r--chrome/browser/views/download_item_view.h14
-rw-r--r--chrome/chrome.xcodeproj/project.pbxproj2
14 files changed, 112 insertions, 131 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons
index f701eaa..9af4565 100644
--- a/chrome/browser/browser.scons
+++ b/chrome/browser/browser.scons
@@ -486,8 +486,6 @@ input_files = ChromeFileList([
'download/save_item.h',
'download/save_package.cc',
'download/save_package.h',
- 'download/save_page_model.cc',
- 'download/save_page_model.h',
'download/save_types.h',
]),
MSVSFilter('Autofill', [
@@ -682,10 +680,8 @@ if not env.Bit('windows'):
'dom_ui/html_dialog_contents.cc',
'dom_ui/new_tab_ui.cc',
'download/download_exe.cc',
- 'download/download_item_model.cc',
'download/download_util.cc',
'download/download_request_manager.cc',
- 'download/save_page_model.cc',
'drag_utils.cc',
'encoding_menu_controller_delegate.cc',
'external_protocol_handler.cc',
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index bd61f95..1636017 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -1850,14 +1850,6 @@
>
</File>
<File
- RelativePath=".\download\save_page_model.cc"
- >
- </File>
- <File
- RelativePath=".\download\save_page_model.h"
- >
- </File>
- <File
RelativePath=".\download\save_types.h"
>
</File>
diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc
index 257a8ae..79a22fa 100644
--- a/chrome/browser/download/download_file.cc
+++ b/chrome/browser/download/download_file.cc
@@ -11,6 +11,7 @@
#include "base/task.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/tab_contents/tab_util.h"
@@ -28,7 +29,7 @@
#endif
// Throttle updates to the UI thread so that a fast moving download doesn't
-// cause it to become unresponsive (ins milliseconds).
+// cause it to become unresponsive (in milliseconds).
static const int kUpdatePeriodMs = 500;
// Timer task for posting UI updates. This task is created and maintained by
diff --git a/chrome/browser/download/download_file.h b/chrome/browser/download/download_file.h
index 402be7c..5e897eae 100644
--- a/chrome/browser/download/download_file.h
+++ b/chrome/browser/download/download_file.h
@@ -51,7 +51,6 @@
#include "base/ref_counted.h"
#include "base/thread.h"
#include "base/timer.h"
-#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/history/download_types.h"
namespace net {
diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc
index cf2cc30..f90ec6b 100644
--- a/chrome/browser/download/download_item_model.cc
+++ b/chrome/browser/download/download_item_model.cc
@@ -6,12 +6,16 @@
#include "base/string_util.h"
#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/download/save_package.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/time_format.h"
#include "grit/generated_resources.h"
using base::TimeDelta;
+// -----------------------------------------------------------------------------
+// DownloadItemModel
+
DownloadItemModel::DownloadItemModel(DownloadItem* download)
: download_(download) {
}
@@ -88,3 +92,41 @@ std::wstring DownloadItemModel::GetStatusText() {
return status_text;
}
+// -----------------------------------------------------------------------------
+// SavePageModel
+
+SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download)
+ : save_(save),
+ download_(download) {
+}
+
+void SavePageModel::CancelTask() {
+ save_->Cancel(true);
+}
+
+std::wstring SavePageModel::GetStatusText() {
+ int64 size = download_->received_bytes();
+ int64 total_size = download_->total_bytes();
+
+ std::wstring status_text;
+ switch (download_->state()) {
+ case DownloadItem::IN_PROGRESS:
+ status_text = l10n_util::GetStringF(IDS_SAVE_PAGE_PROGRESS,
+ FormatNumber(size),
+ FormatNumber(total_size));
+ break;
+ case DownloadItem::COMPLETE:
+ status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_COMPLETED);
+ break;
+ case DownloadItem::CANCELLED:
+ status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_CANCELLED);
+ break;
+ case DownloadItem::REMOVING:
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ return status_text;
+}
+
diff --git a/chrome/browser/download/download_item_model.h b/chrome/browser/download/download_item_model.h
index edeac1c..8c7fe83 100644
--- a/chrome/browser/download/download_item_model.h
+++ b/chrome/browser/download/download_item_model.h
@@ -2,17 +2,31 @@
// 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_ITEM_MODEL_H__
-#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H__
+#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_
+#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_
-#include "chrome/browser/views/download_item_view.h"
+#include <string>
+
+#include "base/basictypes.h"
class DownloadItem;
+class SavePackage;
+
+// This class provides an interface for functions which have different behaviors
+// depending on the type of download.
+class BaseDownloadItemModel {
+ public:
+ // Cancel the task corresponding to the item.
+ virtual void CancelTask() = 0;
+
+ // Get the status text to display.
+ virtual std::wstring GetStatusText() = 0;
+};
// This class is a model class for DownloadItemView. It provides functionality
// for canceling the downloading, and also the text for displaying downloading
// status.
-class DownloadItemModel : public DownloadItemView::BaseDownloadItemModel {
+class DownloadItemModel : public BaseDownloadItemModel {
public:
DownloadItemModel(DownloadItem* download);
virtual ~DownloadItemModel() { }
@@ -27,8 +41,32 @@ class DownloadItemModel : public DownloadItemView::BaseDownloadItemModel {
// We query this item for status information.
DownloadItem* download_;
- DISALLOW_EVIL_CONSTRUCTORS(DownloadItemModel);
+ DISALLOW_COPY_AND_ASSIGN(DownloadItemModel);
+};
+
+// This class is a model class for DownloadItemView. It provides cancel
+// functionality for saving page, and also the text for displaying saving
+// status.
+class SavePageModel : public BaseDownloadItemModel {
+ public:
+ SavePageModel(SavePackage* save, DownloadItem* download);
+ virtual ~SavePageModel() { }
+
+ // Cancel the page saving.
+ virtual void CancelTask();
+
+ // Get page saving status text.
+ virtual std::wstring GetStatusText();
+
+ private:
+ // Saving page management.
+ SavePackage* save_;
+
+ // A fake download item for saving page use.
+ DownloadItem* download_;
+
+ DISALLOW_COPY_AND_ASSIGN(SavePageModel);
};
-#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H__
+#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 83d798f..fd80886 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -13,9 +13,10 @@
#include "base/scoped_clipboard_writer.h"
#include "base/string_util.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_manager.h"
-#include "chrome/common/clipboard_service.h"
#include "chrome/browser/drag_utils.h"
+#include "chrome/common/clipboard_service.h"
#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/os_exchange_data.h"
@@ -147,7 +148,7 @@ void BaseContextMenu::ExecuteCommand(int id) {
DownloadShelfContextMenu::DownloadShelfContextMenu(
DownloadItem* download,
HWND window,
- DownloadItemView::BaseDownloadItemModel* model,
+ BaseDownloadItemModel* model,
const CPoint& point)
: BaseContextMenu(download),
model_(model) {
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index 08ba93a..0d7d7477 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -4,18 +4,21 @@
//
// Download utilities.
-#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H__
-#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H__
+#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_
+#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_
#include <objidl.h>
+#include <set>
+#include <string>
+
#include "base/basictypes.h"
#include "base/task.h"
-#include "chrome/browser/views/download_item_view.h"
#include "chrome/views/event.h"
#include "chrome/views/menu.h"
#include "chrome/views/view.h"
+class BaseDownloadItemModel;
class DownloadItem;
class SkBitmap;
@@ -55,7 +58,7 @@ class BaseContextMenu : public Menu::Delegate {
DownloadItem* download_;
private:
- DISALLOW_EVIL_CONSTRUCTORS(BaseContextMenu);
+ DISALLOW_COPY_AND_ASSIGN(BaseContextMenu);
};
// Menu for the download shelf.
@@ -63,7 +66,7 @@ class DownloadShelfContextMenu : public BaseContextMenu {
public:
DownloadShelfContextMenu(DownloadItem* download,
HWND window,
- DownloadItemView::BaseDownloadItemModel* model,
+ BaseDownloadItemModel* model,
const CPoint& point);
virtual ~DownloadShelfContextMenu();
@@ -72,9 +75,9 @@ class DownloadShelfContextMenu : public BaseContextMenu {
private:
// A model to control the cancel behavior.
- DownloadItemView::BaseDownloadItemModel* model_;
+ BaseDownloadItemModel* model_;
- DISALLOW_EVIL_CONSTRUCTORS(DownloadShelfContextMenu);
+ DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu);
};
// Menu for the download destination view.
@@ -86,7 +89,7 @@ class DownloadDestinationContextMenu : public BaseContextMenu {
virtual ~DownloadDestinationContextMenu();
private:
- DISALLOW_EVIL_CONSTRUCTORS(DownloadDestinationContextMenu);
+ DISALLOW_COPY_AND_ASSIGN(DownloadDestinationContextMenu);
};
// DownloadProgressTask --------------------------------------------------------
@@ -103,7 +106,7 @@ class DownloadProgressTask : public Task {
}
private:
DownloadView* view_;
- DISALLOW_EVIL_CONSTRUCTORS(DownloadProgressTask);
+ DISALLOW_COPY_AND_ASSIGN(DownloadProgressTask);
};
// Download opening ------------------------------------------------------------
@@ -191,5 +194,5 @@ void InitializeExeTypes(std::set<std::wstring>* exe_extensions);
} // namespace download_util
-#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H__
+#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index c744cd5..2e206ff 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -12,6 +12,7 @@
#include "base/task.h"
#include "base/thread.h"
#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/save_file.h"
#include "chrome/browser/download/save_file_manager.h"
@@ -41,7 +42,7 @@
#if defined(OS_WIN)
// TODO(port): port these headers.
-#include "chrome/browser/download/save_page_model.h"
+#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"
diff --git a/chrome/browser/download/save_page_model.cc b/chrome/browser/download/save_page_model.cc
deleted file mode 100644
index 379f2b2..0000000
--- a/chrome/browser/download/save_page_model.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2006-2008 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/save_page_model.h"
-
-#include "base/string_util.h"
-#include "chrome/browser/download/download_manager.h"
-#include "chrome/browser/download/save_package.h"
-#include "chrome/common/l10n_util.h"
-#include "grit/generated_resources.h"
-
-SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download)
- : save_(save),
- download_(download) {
-}
-
-void SavePageModel::CancelTask() {
- save_->Cancel(true);
-}
-
-std::wstring SavePageModel::GetStatusText() {
- int64 size = download_->received_bytes();
- int64 total_size = download_->total_bytes();
-
- std::wstring status_text;
- switch (download_->state()) {
- case DownloadItem::IN_PROGRESS:
- status_text = l10n_util::GetStringF(IDS_SAVE_PAGE_PROGRESS,
- FormatNumber(size),
- FormatNumber(total_size));
- break;
- case DownloadItem::COMPLETE:
- status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_COMPLETED);
- break;
- case DownloadItem::CANCELLED:
- status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_CANCELLED);
- break;
- case DownloadItem::REMOVING:
- break;
- default:
- NOTREACHED();
- }
-
- return status_text;
-}
-
diff --git a/chrome/browser/download/save_page_model.h b/chrome/browser/download/save_page_model.h
deleted file mode 100644
index 75a4497..0000000
--- a/chrome/browser/download/save_page_model.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2006-2008 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_SAVE_PAGE_MODEL_H__
-#define CHROME_BROWSER_DOWNLOAD_SAVE_PAGE_MODEL_H__
-
-#include "chrome/browser/views/download_item_view.h"
-
-class DownloadItem;
-class SavePackage;
-
-// This class is a model class for DownloadItemView. It provides cancel
-// functionality for saving page, and also the text for displaying saving
-// status.
-class SavePageModel : public DownloadItemView::BaseDownloadItemModel {
- public:
- SavePageModel(SavePackage* save, DownloadItem* download);
- virtual ~SavePageModel() { }
-
- // Cancel the page saving.
- virtual void CancelTask();
-
- // Get page saving status text.
- virtual std::wstring GetStatusText();
-
- private:
- // Saving page management.
- SavePackage* save_;
-
- // A fake download item for saving page use.
- DownloadItem* download_;
-
- DISALLOW_EVIL_CONSTRUCTORS(SavePageModel);
-};
-
-#endif // CHROME_BROWSER_DOWNLOAD_SAVE_PAGE_MODEL_H__
-
diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc
index c7835eb..350e5f6 100644
--- a/chrome/browser/views/download_item_view.cc
+++ b/chrome/browser/views/download_item_view.cc
@@ -9,6 +9,7 @@
#include "base/file_util.h"
#include "base/string_util.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/views/download_shelf_view.h"
#include "chrome/common/gfx/chrome_canvas.h"
@@ -59,7 +60,7 @@ static const int kCompleteAnimationDurationMs = 2500;
DownloadItemView::DownloadItemView(DownloadItem* download,
DownloadShelfView* parent,
- DownloadItemView::BaseDownloadItemModel* model)
+ BaseDownloadItemModel* model)
: download_(download),
parent_(parent),
model_(model),
diff --git a/chrome/browser/views/download_item_view.h b/chrome/browser/views/download_item_view.h
index a785705..1c8aaac 100644
--- a/chrome/browser/views/download_item_view.h
+++ b/chrome/browser/views/download_item_view.h
@@ -32,6 +32,7 @@
namespace views {
class Label;
}
+class BaseDownloadItemModel;
class DownloadShelfView;
class SkBitmap;
@@ -40,17 +41,6 @@ class DownloadItemView : public views::NativeButton::Listener,
public DownloadItem::Observer,
public AnimationDelegate {
public:
- // This class provides functions which have different behaviors between
- // download and saving page.
- class BaseDownloadItemModel {
- public:
- // Cancel the task corresponding to the item.
- virtual void CancelTask() = 0;
-
- // Get the status text to display.
- virtual std::wstring GetStatusText() = 0;
- };
-
DownloadItemView(DownloadItem* download,
DownloadShelfView* parent,
BaseDownloadItemModel* model);
@@ -228,7 +218,7 @@ class DownloadItemView : public views::NativeButton::Listener,
// The size of the buttons. Cached so animation works when hidden.
gfx::Size cached_button_size_;
- DISALLOW_EVIL_CONSTRUCTORS(DownloadItemView);
+ DISALLOW_COPY_AND_ASSIGN(DownloadItemView);
};
#endif // CHROME_BROWSER_VIEWS_DOWNLOAD_ITEM_VIEW_H__
diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj
index e52ae08b..e6a3b70 100644
--- a/chrome/chrome.xcodeproj/project.pbxproj
+++ b/chrome/chrome.xcodeproj/project.pbxproj
@@ -380,6 +380,7 @@
BAC2B7A80F43595A0063A33E /* resource_dispatcher_host_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = BAC2B7A70F43594A0063A33E /* resource_dispatcher_host_unittest.cc */; };
BAC2B8AD0F436C7F0063A33E /* cross_site_resource_handler.cc in Sources */ = {isa = PBXBuildFile; fileRef = A7C613DC0F30D886008CEE5D /* cross_site_resource_handler.cc */; };
BADB8B710F3A35AC00989B26 /* resource_dispatcher_host.cc in Sources */ = {isa = PBXBuildFile; fileRef = BADB8B6D0F3A356000989B26 /* resource_dispatcher_host.cc */; };
+ BDBF78593E5B3E355CCF3FF8 /* download_item_model.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF9CC0E9D48CE009A6919 /* download_item_model.cc */; };
C53EBF7E1E204C3780FD4A7D /* ssl_policy.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5D16ED10F21451600861FAC /* ssl_policy.cc */; };
C6C256C56BA114D53849523F /* greasemonkey_api_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1F43A7C85092C58AAF011F78 /* greasemonkey_api_unittest.cc */; };
C8F5EB819EA38CE9D50AF5B5 /* history.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF9EC0E9D48F7009A6919 /* history.cc */; };
@@ -5463,6 +5464,7 @@
28283DBE4B6DB2B0F9893676 /* dns_master.cc in Sources */,
E4F324550EE5CFB1002533CE /* download_database.cc in Sources */,
970EF19CD8A79CF3D0DF4B61 /* download_file.cc in Sources */,
+ BDBF78593E5B3E355CCF3FF8 /* download_item_model.cc in Sources */,
928300674E414B42615BA4F0 /* download_manager.cc in Sources */,
E43A77170F16616E00ABD5D1 /* download_resource_handler.cc in Sources */,
E45075E30F150A6F003BE099 /* download_throttling_resource_handler.cc in Sources */,