diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-30 05:59:59 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-30 05:59:59 +0000 |
commit | e93d2823ba7df0b5f8d4d3869d6f0d7d94264012 (patch) | |
tree | 7e3783f67b8a68605dec8b3493252029c22aa3d5 /chrome/browser/download | |
parent | 7663e411f3f65fb232093cb3b078a5ef733562e6 (diff) | |
download | chromium_src-e93d2823ba7df0b5f8d4d3869d6f0d7d94264012.zip chromium_src-e93d2823ba7df0b5f8d4d3869d6f0d7d94264012.tar.gz chromium_src-e93d2823ba7df0b5f8d4d3869d6f0d7d94264012.tar.bz2 |
Porting in the download manager (plus tiny bits of cleanup).
Review URL: http://codereview.chromium.org/19697
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8951 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_file.cc | 35 | ||||
-rw-r--r-- | chrome/browser/download/download_file.h | 10 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 28 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 18 |
4 files changed, 51 insertions, 40 deletions
diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc index 5d7b5e5c..d3c7c63 100644 --- a/chrome/browser/download/download_file.cc +++ b/chrome/browser/download/download_file.cc @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <Windows.h> -#include <objbase.h> - #include "chrome/browser/download/download_file.h" #include "base/file_util.h" @@ -12,6 +9,7 @@ #include "base/scoped_ptr.h" #include "base/string_util.h" #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" @@ -20,14 +18,15 @@ #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/stl_util-inl.h" -#include "chrome/common/win_util.h" -#include "chrome/common/win_safe_util.h" #include "googleurl/src/gurl.h" #include "net/base/io_buffer.h" #include "net/base/net_util.h" #include "net/url_request/url_request_context.h" -using base::TimeDelta; +#if defined(OS_WIN) +#include "chrome/common/win_util.h" +#include "chrome/common/win_safe_util.h" +#endif // Throttle updates to the UI thread so that a fast moving download doesn't // cause it to become unresponsive (ins milliseconds). @@ -48,7 +47,7 @@ class DownloadFileUpdateTask : public Task { private: DownloadFileManager* manager_; - DISALLOW_EVIL_CONSTRUCTORS(DownloadFileUpdateTask); + DISALLOW_COPY_AND_ASSIGN(DownloadFileUpdateTask); }; // DownloadFile implementation ------------------------------------------------- @@ -127,9 +126,15 @@ bool DownloadFile::Open(const char* open_mode) { if (!file_) { return false; } + +#if defined(OS_WIN) // Sets the Zone to tell Windows that this file comes from the internet. // We ignore the return value because a failure is not fatal. win_util::SetInternetZoneIdentifier(full_path_); +#elif defined(OS_MAC) + // TODO(port) there should be an equivalent on Mac (there isn't on Linux). + NOTREACHED(); +#endif return true; } @@ -196,8 +201,8 @@ void DownloadFileManager::RemoveDownloadFromUIProgress(int id) { void DownloadFileManager::StartUpdateTimer() { DCHECK(MessageLoop::current() == ui_loop_); if (!update_timer_.IsRunning()) { - update_timer_.Start(TimeDelta::FromMilliseconds(kUpdatePeriodMs), this, - &DownloadFileManager::UpdateInProgressDownloads); + update_timer_.Start(base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), + this, &DownloadFileManager::UpdateInProgressDownloads); } } @@ -513,8 +518,13 @@ void DownloadFileManager::OnDownloadUrl(const GURL& url, // thread to avoid blocking the UI with (potentially) slow Shell operations. // TODO(paulg): File 'stat' operations. void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) { +#if defined(OS_WIN) DCHECK(MessageLoop::current() == file_loop_); win_util::ShowItemInFolder(full_path.value()); +#else + // TODO(port) implement me. + NOTREACHED(); +#endif } // Launches the selected download using ShellExecute 'open' verb. If there is @@ -522,13 +532,18 @@ void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) { // display a modal dialog asking for user consent on dangerous files. void DownloadFileManager::OnOpenDownloadInShell(const FilePath& full_path, const std::wstring& url, - HWND parent_window) { + gfx::NativeView parent_window) { +#if defined(OS_WIN) DCHECK(MessageLoop::current() == file_loop_); if (NULL != parent_window) { win_util::SaferOpenItemViaShell(parent_window, L"", full_path, url, true); } else { win_util::OpenItemViaShell(full_path, true); } +#else + // TODO(port) implement me. + NOTREACHED(); +#endif } // The DownloadManager in the UI thread has provided a final name for the diff --git a/chrome/browser/download/download_file.h b/chrome/browser/download/download_file.h index 40ba670..ebc1dde 100644 --- a/chrome/browser/download/download_file.h +++ b/chrome/browser/download/download_file.h @@ -38,8 +38,8 @@ // appropriate DownloadManager. In progress downloads are cancelled for a // DownloadManager that exits (such as when closing a profile). -#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H__ -#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H__ +#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ +#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ #include <string> #include <vector> @@ -145,7 +145,7 @@ class DownloadFile { // Whether the download is still receiving data. bool in_progress_; - DISALLOW_EVIL_CONSTRUCTORS(DownloadFile); + DISALLOW_COPY_AND_ASSIGN(DownloadFile); }; @@ -272,7 +272,7 @@ class DownloadFileManager ProgressMap ui_progress_; Lock progress_lock_; - DISALLOW_EVIL_CONSTRUCTORS(DownloadFileManager); + DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); }; -#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H__ +#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index fde5103..9ac3099 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <time.h> - #include "chrome/browser/download/download_manager.h" #include "base/file_util.h" @@ -41,9 +39,6 @@ #include "generated_resources.h" -using base::Time; -using base::TimeDelta; - // Periodically update our observers. class DownloadItemUpdateTask : public Task { public: @@ -131,7 +126,7 @@ DownloadItem::DownloadItem(int32 download_id, int path_uniquifier, const std::wstring& url, const FilePath& original_name, - const Time start_time, + const base::Time start_time, int64 download_size, int render_process_id, int request_id, @@ -229,7 +224,7 @@ void DownloadItem::Remove(bool delete_on_disk) { } void DownloadItem::StartProgressTimer() { - update_timer_.Start(TimeDelta::FromMilliseconds(kUpdateTimeMs), this, + update_timer_.Start(base::TimeDelta::FromMilliseconds(kUpdateTimeMs), this, &DownloadItem::UpdateObservers); } @@ -237,7 +232,7 @@ void DownloadItem::StopProgressTimer() { update_timer_.Stop(); } -bool DownloadItem::TimeRemaining(TimeDelta* remaining) const { +bool DownloadItem::TimeRemaining(base::TimeDelta* remaining) const { if (total_bytes_ <= 0) return false; // We never received the content_length for this download. @@ -246,7 +241,7 @@ bool DownloadItem::TimeRemaining(TimeDelta* remaining) const { return false; *remaining = - TimeDelta::FromSeconds((total_bytes_ - received_bytes_) / speed); + base::TimeDelta::FromSeconds((total_bytes_ - received_bytes_) / speed); return true; } @@ -723,8 +718,9 @@ void DownloadManager::RemoveDownloadFromHistory(DownloadItem* download) { hs->RemoveDownload(download->db_handle()); } -void DownloadManager::RemoveDownloadsFromHistoryBetween(const Time remove_begin, - const Time remove_end) { +void DownloadManager::RemoveDownloadsFromHistoryBetween( + const base::Time remove_begin, + const base::Time remove_end) { // FIXME(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); if (hs) @@ -982,8 +978,8 @@ void DownloadManager::RemoveDownload(int64 download_handle) { delete download; } -int DownloadManager::RemoveDownloadsBetween(const Time remove_begin, - const Time remove_end) { +int DownloadManager::RemoveDownloadsBetween(const base::Time remove_begin, + const base::Time remove_end) { RemoveDownloadsFromHistoryBetween(remove_begin, remove_end); int num_deleted = 0; @@ -1019,8 +1015,8 @@ int DownloadManager::RemoveDownloadsBetween(const Time remove_begin, return num_deleted; } -int DownloadManager::RemoveDownloads(const Time remove_begin) { - return RemoveDownloadsBetween(remove_begin, Time()); +int DownloadManager::RemoveDownloads(const base::Time remove_begin) { + return RemoveDownloadsBetween(remove_begin, base::Time()); } // Initiate a download of a specific URL. We send the request to the @@ -1152,7 +1148,7 @@ void DownloadManager::ShowDownloadInShell(const DownloadItem* download) { } void DownloadManager::OpenDownloadInShell(const DownloadItem* download, - HWND parent_window) { + gfx::NativeView parent_window) { DCHECK(file_manager_); file_loop_->PostTask(FROM_HERE, NewRunnableMethod(file_manager_, diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 3d7bcc2..6f05e02 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -32,8 +32,8 @@ // DownloadManager is constructed, we query the history service for the state of // all persisted downloads. -#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H__ -#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H__ +#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ +#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ #include "build/build_config.h" @@ -47,13 +47,11 @@ #include "base/hash_tables.h" #include "base/observer_list.h" #include "base/ref_counted.h" +#include "base/time.h" #include "chrome/browser/cancelable_request.h" #include "chrome/browser/history/download_types.h" #include "chrome/browser/history/history.h" -#if defined(OS_WIN) -// TODO(port): Port this header and remove #ifdef. #include "chrome/browser/shell_dialogs.h" -#endif #include "chrome/common/pref_member.h" class DownloadFileManager; @@ -365,7 +363,8 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, // Show or Open a download via the Windows shell. void ShowDownloadInShell(const DownloadItem* download); - void OpenDownloadInShell(const DownloadItem* download, HWND parent_window); + void OpenDownloadInShell(const DownloadItem* download, + gfx::NativeView parent_window); // The number of in progress (including paused) downloads. int in_progress_count() const { @@ -535,7 +534,8 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, scoped_refptr<URLRequestContext> request_context_; // Used for history service request management. - CancelableRequestConsumerT<Observer*, 0> cancelable_consumer_; + CancelableRequestConsumerT<Observer*, (DownloadManager::Observer*)NULL> + cancelable_consumer_; // Non-owning pointer for handling file writing on the download_thread_. DownloadFileManager* file_manager_; @@ -573,9 +573,9 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, // saved. scoped_refptr<SelectFileDialog> select_file_dialog_; - DISALLOW_EVIL_CONSTRUCTORS(DownloadManager); + DISALLOW_COPY_AND_ASSIGN(DownloadManager); }; #endif // defined(OS_WIN) -#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H__ +#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |