diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-22 01:21:56 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-22 01:21:56 +0000 |
commit | b7f0588eacdc379330d315c68b749130d1f2ed2f (patch) | |
tree | 1d087bb1dc96d8d5262e3dee94861c0f7be7a89e /chrome/browser/download | |
parent | 4c603f01f34867e3b908a1834e5a60b6f8a21924 (diff) | |
download | chromium_src-b7f0588eacdc379330d315c68b749130d1f2ed2f.zip chromium_src-b7f0588eacdc379330d315c68b749130d1f2ed2f.tar.gz chromium_src-b7f0588eacdc379330d315c68b749130d1f2ed2f.tar.bz2 |
Bring download_file, download_manager into POSIX build.
Also shuffle a bunch of headers.
Review URL: http://codereview.chromium.org/27024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10155 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_file.cc | 7 | ||||
-rw-r--r-- | chrome/browser/download/download_file.h | 3 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 74 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 10 | ||||
-rw-r--r-- | chrome/browser/download/save_package.cc | 2 |
5 files changed, 72 insertions, 24 deletions
diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc index 7d03acb..dbd632c 100644 --- a/chrome/browser/download/download_file.cc +++ b/chrome/browser/download/download_file.cc @@ -11,7 +11,6 @@ #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" @@ -90,6 +89,7 @@ void DownloadFile::Cancel() { // The UI has provided us with our finalized name. bool DownloadFile::Rename(const FilePath& new_path) { +#if defined(OS_WIN) Close(); // We cannot rename because rename will keep the same security descriptor @@ -111,6 +111,11 @@ bool DownloadFile::Rename(const FilePath& new_path) { if (!Open("a+b")) return false; return true; +#elif defined(OS_POSIX) + // TODO(port): Port this function to posix (we need file_util::Rename()). + NOTIMPLEMENTED(); + return false; +#endif } void DownloadFile::Close() { diff --git a/chrome/browser/download/download_file.h b/chrome/browser/download/download_file.h index 9991c03..402be7c 100644 --- a/chrome/browser/download/download_file.h +++ b/chrome/browser/download/download_file.h @@ -51,6 +51,7 @@ #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 { @@ -263,7 +264,7 @@ class DownloadFileManager // RequestMap maps a DownloadManager to all in-progress download IDs. // Called only on the UI thread. typedef base::hash_set<int> DownloadRequests; - typedef base::hash_map<DownloadManager*, DownloadRequests> RequestMap; + typedef std::map<DownloadManager*, DownloadRequests> RequestMap; RequestMap requests_; // Used for progress updates on the UI thread, mapping download->id() to bytes diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index 965f2ed..86c61152 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -8,17 +8,14 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/string_util.h" #include "base/task.h" #include "base/thread.h" #include "base/timer.h" #include "base/rand_util.h" -#include "base/win_util.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_file.h" -#include "chrome/browser/download/download_util.h" #include "chrome/browser/extensions/extension.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_process_host.h" @@ -33,12 +30,19 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/stl_util-inl.h" -#include "chrome/common/win_util.h" #include "googleurl/src/gurl.h" #include "net/base/mime_util.h" #include "net/base/net_util.h" #include "net/url_request/url_request_context.h" +#if defined(OS_WIN) +// TODO(port): some of these need porting. +#include "base/registry.h" +#include "base/win_util.h" +#include "chrome/browser/download/download_util.h" +#include "chrome/common/win_util.h" +#endif + #include "generated_resources.h" // Periodically update our observers. @@ -88,6 +92,7 @@ static int GetUniquePathNumber(const FilePath& path) { return -1; } +#if defined(OS_WIN) static bool DownloadPathIsDangerous(const FilePath& download_path) { FilePath desktop_dir; if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) { @@ -96,6 +101,7 @@ static bool DownloadPathIsDangerous(const FilePath& download_path) { } return (download_path == desktop_dir); } +#endif // DownloadItem implementation ------------------------------------------------- @@ -103,18 +109,18 @@ static bool DownloadPathIsDangerous(const FilePath& download_path) { DownloadItem::DownloadItem(const DownloadCreateInfo& info) : id_(-1), full_path_(info.path), - original_name_(info.original_name), url_(info.url), total_bytes_(info.total_bytes), received_bytes_(info.received_bytes), - start_tick_(0), + start_tick_(base::TimeTicks()), state_(static_cast<DownloadState>(info.state)), start_time_(info.start_time), db_handle_(info.db_handle), manager_(NULL), - safety_state_(SAFE), is_paused_(false), open_when_complete_(false), + safety_state_(SAFE), + original_name_(info.original_name), render_process_id_(-1), request_id_(-1) { if (state_ == IN_PROGRESS) @@ -137,17 +143,17 @@ DownloadItem::DownloadItem(int32 download_id, full_path_(path), path_uniquifier_(path_uniquifier), url_(url), - original_name_(original_name), total_bytes_(download_size), received_bytes_(0), - start_tick_(GetTickCount()), + start_tick_(base::TimeTicks::Now()), state_(IN_PROGRESS), start_time_(start_time), db_handle_(kUninitializedHandle), manager_(NULL), - safety_state_(is_dangerous ? DANGEROUS : SAFE), is_paused_(false), open_when_complete_(false), + safety_state_(is_dangerous ? DANGEROUS : SAFE), + original_name_(original_name), render_process_id_(render_process_id), request_id_(request_id) { Init(true /* start progress timer */); @@ -248,8 +254,9 @@ bool DownloadItem::TimeRemaining(base::TimeDelta* remaining) const { } int64 DownloadItem::CurrentSpeed() const { - uintptr_t diff = GetTickCount() - start_tick_; - return diff == 0 ? 0 : received_bytes_ * 1000 / diff; + base::TimeDelta diff = base::TimeTicks::Now() - start_tick_; + int64 diff_ms = diff.InMilliseconds(); + return diff_ms == 0 ? 0 : received_bytes_ * 1000 / diff_ms; } int DownloadItem::PercentComplete() const { @@ -291,6 +298,8 @@ void DownloadManager::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen, L""); prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded, false); +// TODO(port): port the necessary bits of chrome_paths. +#if defined(OS_WIN) // The default download path is userprofile\download. FilePath default_download_path; if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, @@ -313,6 +322,7 @@ void DownloadManager::RegisterUserPrefs(PrefService* prefs) { } prefs->SetBoolean(prefs::kDownloadDirUpgraded, true); } +#endif } DownloadManager::DownloadManager() @@ -475,6 +485,8 @@ bool DownloadManager::Init(Profile* profile) { DCHECK(prefs); prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); +// TODO(port): enable this after implementing chrome_paths for posix. +#if defined(OS_WIN) download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); // This variable is needed to resolve which CreateDirectory we want to point @@ -489,14 +501,18 @@ bool DownloadManager::Init(Profile* profile) { // We store any file extension that should be opened automatically at // download completion in this pref. download_util::InitializeExeTypes(&exe_types_); +#elif defined(OS_POSIX) + NOTIMPLEMENTED(); +#endif std::wstring extensions_to_open = prefs->GetString(prefs::kDownloadExtensionsToOpen); std::vector<std::wstring> extensions; SplitString(extensions_to_open, L':', &extensions); for (size_t i = 0; i < extensions.size(); ++i) { - if (!extensions[i].empty() && !IsExecutable(extensions[i])) - auto_open_.insert(extensions[i]); + if (!extensions[i].empty() && !IsExecutable( + FilePath::FromWStringHack(extensions[i]).value())) + auto_open_.insert(FilePath::FromWStringHack(extensions[i]).value()); } return true; @@ -609,6 +625,7 @@ void DownloadManager::CheckIfSuggestedPathExists(DownloadCreateInfo* info) { } void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { +#if defined(OS_WIN) DCHECK(MessageLoop::current() == ui_loop_); DCHECK(info); @@ -632,6 +649,10 @@ void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { // No prompting for download, just continue with the suggested name. ContinueStartDownload(info, info->suggested_path); } +#elif defined(OS_POSIX) + // TODO(port): port this file -- need dialogs. + NOTIMPLEMENTED(); +#endif } void DownloadManager::ContinueStartDownload(DownloadCreateInfo* info, @@ -802,8 +823,7 @@ void DownloadManager::ContinueDownloadFinished(DownloadItem* download) { download->UpdateObservers(); // Open the download if the user or user prefs indicate it should be. - const std::wstring extension = - file_util::GetFileExtensionFromPath(download->full_path()); + const FilePath::StringType extension = download->full_path().Extension(); if (download->open_when_complete() || ShouldOpenFileExtension(extension)) OpenDownloadInShell(download, NULL); } @@ -940,7 +960,7 @@ void DownloadManager::OnPauseDownloadRequest(ResourceDispatcherHost* rdh, bool DownloadManager::IsDangerous(const FilePath& file_name) { // TODO(jcampan): Improve me. - return IsExecutable(file_util::GetFileExtensionFromPath(file_name)); + return IsExecutable(file_name.Extension()); } void DownloadManager::RenameDownload(DownloadItem* download, @@ -994,7 +1014,7 @@ int DownloadManager::RemoveDownloadsBetween(const base::Time remove_begin, (state == DownloadItem::COMPLETE || state == DownloadItem::CANCELLED)) { // Remove from the map and move to the next in the list. - it = downloads_.erase(it); + downloads_.erase(it++); // Also remove it from any completed dangerous downloads. DownloadMap::iterator dit = dangerous_finished_.find(download->id()); @@ -1075,9 +1095,11 @@ void DownloadManager::GenerateExtension( FilePath::StringType extension( file_util::GetFileExtensionFromPath(file_name)); +#if defined(OS_WIN) // Rename shell-integrated extensions. if (win_util::IsShellIntegratedExtension(extension)) extension.assign(default_extension); +#endif std::string mime_type_from_extension; net::GetMimeTypeFromFile(file_name, @@ -1233,7 +1255,17 @@ void DownloadManager::SaveAutoOpens() { } if (!extensions.empty()) extensions.erase(extensions.size() - 1); - prefs->SetString(prefs::kDownloadExtensionsToOpen, extensions); + + std::wstring extensions_w; +#if defined(OS_WIN) + extensions_w = extensions; +#elif defined(OS_POSIX) + // TODO(port): this is not correct since FilePath::StringType is not + // necessarily UTF8. + extensions_w = UTF8ToWide(extensions); +#endif + + prefs->SetString(prefs::kDownloadExtensionsToOpen, extensions_w); } } @@ -1288,6 +1320,7 @@ void DownloadManager::GenerateSafeFilename(const std::string& mime_type, // Prepend "_" to the file name if it's a reserved name FilePath::StringType leaf_name = file_name->BaseName().value(); DCHECK(!leaf_name.empty()); +#if defined(OS_WIN) if (win_util::IsReservedName(leaf_name)) { leaf_name = FilePath::StringType(FILE_PATH_LITERAL("_")) + leaf_name; *file_name = file_name->DirName(); @@ -1297,6 +1330,9 @@ void DownloadManager::GenerateSafeFilename(const std::string& mime_type, *file_name = file_name->Append(leaf_name); } } +#elif defined(OS_POSIX) + NOTIMPLEMENTED(); +#endif } // Operations posted to us from the history service ---------------------------- diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 942361b..75ab75b 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -51,9 +51,15 @@ #include "chrome/browser/cancelable_request.h" #include "chrome/browser/history/download_types.h" #include "chrome/browser/history/history.h" -#include "chrome/browser/shell_dialogs.h" #include "chrome/common/pref_member.h" +#if defined(OS_WIN) +// TODO(port): port this header. +#include "chrome/browser/shell_dialogs.h" +#elif defined(OS_POSIX) +#include "chrome/common/temp_scaffolding_stubs.h" +#endif + class DownloadFileManager; class DownloadItemView; class DownloadManager; @@ -231,7 +237,7 @@ class DownloadItem { int64 received_bytes_; // Start time for calculating remaining time - uintptr_t start_tick_; + base::TimeTicks start_tick_; // The current state of this download DownloadState state_; diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 6f1fcf8..c40788c 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_manager.h" #include "chrome/browser/download/save_file.h" #include "chrome/browser/download/save_file_manager.h" #include "chrome/browser/profile.h" @@ -39,7 +40,6 @@ #if defined(OS_WIN) // TODO(port): port these headers. -#include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/save_page_model.h" #include "chrome/browser/views/download_shelf_view.h" #elif defined(OS_POSIX) |