diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-18 22:39:31 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-18 22:39:31 +0000 |
commit | fde6714d19b512b6190f08082c2ea05a21050253 (patch) | |
tree | 652fb54b3891708438648dd8d6cc6e0ebda700eb /chrome/browser | |
parent | f90efcffb6df294c6e0269aac4a4a4442b9505f3 (diff) | |
download | chromium_src-fde6714d19b512b6190f08082c2ea05a21050253.zip chromium_src-fde6714d19b512b6190f08082c2ea05a21050253.tar.gz chromium_src-fde6714d19b512b6190f08082c2ea05a21050253.tar.bz2 |
Prepare some files for porting:
- Trade in some old wstrings for FilePaths.
- Remove some unnecessary headers.
Review URL: http://codereview.chromium.org/21466
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9986 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/download/save_file.cc | 4 | ||||
-rw-r--r-- | chrome/browser/download/save_file.h | 9 | ||||
-rw-r--r-- | chrome/browser/download/save_file_manager.cc | 31 | ||||
-rw-r--r-- | chrome/browser/download/save_file_manager.h | 11 | ||||
-rw-r--r-- | chrome/browser/download/save_item.cc | 4 | ||||
-rw-r--r-- | chrome/browser/download/save_item.h | 11 | ||||
-rw-r--r-- | chrome/browser/download/save_package.cc | 15 | ||||
-rw-r--r-- | chrome/browser/download/save_types.h | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 4 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 4 |
10 files changed, 52 insertions, 48 deletions
diff --git a/chrome/browser/download/save_file.cc b/chrome/browser/download/save_file.cc index b889bd2..a060172 100644 --- a/chrome/browser/download/save_file.cc +++ b/chrome/browser/download/save_file.cc @@ -58,7 +58,7 @@ void SaveFile::Cancel() { } // Rename the file when we have final name. -bool SaveFile::Rename(const std::wstring& new_path) { +bool SaveFile::Rename(const FilePath& new_path) { Close(); DCHECK(!path_renamed()); @@ -101,7 +101,7 @@ bool SaveFile::Open(const char* open_mode) { // Sets the zone to tell Windows that this file comes from the Internet. // We ignore the return value because a failure is not fatal. // TODO(port): Similarly mark on Mac. - win_util::SetInternetZoneIdentifier(FilePath::FromWStringHack(full_path_)); + win_util::SetInternetZoneIdentifier(full_path_); #endif return true; } diff --git a/chrome/browser/download/save_file.h b/chrome/browser/download/save_file.h index 361e20c..33ec7be 100644 --- a/chrome/browser/download/save_file.h +++ b/chrome/browser/download/save_file.h @@ -5,9 +5,8 @@ #ifndef CHROME_BROWSER_DOWNLOAD_SAVE_FILE_H__ #define CHROME_BROWSER_DOWNLOAD_SAVE_FILE_H__ -#include <string> - #include "base/basictypes.h" +#include "base/file_path.h" #include "base/scoped_ptr.h" #include "chrome/browser/download/save_types.h" @@ -30,7 +29,7 @@ class SaveFile { void Cancel(); // Rename the saved file. Returns 'true' if the rename was successful. - bool Rename(const std::wstring& full_path); + bool Rename(const FilePath& full_path); void Finish(); @@ -44,7 +43,7 @@ class SaveFile { } int64 bytes_so_far() const { return bytes_so_far_; } - std::wstring full_path() const { return full_path_; } + FilePath full_path() const { return full_path_; } bool path_renamed() const { return path_renamed_; } bool in_progress() const { return in_progress_; } @@ -65,7 +64,7 @@ class SaveFile { int64 bytes_so_far_; // Full path to the saved file including the file name. - std::wstring full_path_; + FilePath full_path_; // Whether the saved file is still using its initial temporary path. bool path_renamed_; diff --git a/chrome/browser/download/save_file_manager.cc b/chrome/browser/download/save_file_manager.cc index 510b94c..1ec3af5 100644 --- a/chrome/browser/download/save_file_manager.cc +++ b/chrome/browser/download/save_file_manager.cc @@ -2,8 +2,7 @@ // 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 "build/build_config.h" #include "chrome/browser/download/save_file_manager.h" @@ -21,13 +20,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/net_util.h" #include "net/base/io_buffer.h" #include "net/url_request/url_request_context.h" +#if defined(OS_WIN) +#include "chrome/common/win_util.h" +#endif + SaveFileManager::SaveFileManager(MessageLoop* ui_loop, MessageLoop* io_loop, ResourceDispatcherHost* rdh) @@ -154,7 +155,7 @@ void SaveFileManager::SaveURL(const GURL& url, int render_process_host_id, int render_view_id, SaveFileCreateInfo::SaveFileSource save_source, - const std::wstring& file_full_path, + const FilePath& file_full_path, URLRequestContext* request_context, SavePackage* save_package) { DCHECK(MessageLoop::current() == ui_loop_); @@ -224,7 +225,7 @@ SavePackage* SaveFileManager::GetSavePackageFromRenderIds( } // Utility function for deleting specified file. -void SaveFileManager::DeleteDirectoryOrFile(const std::wstring& full_path, +void SaveFileManager::DeleteDirectoryOrFile(const FilePath& full_path, bool is_dir) { DCHECK(MessageLoop::current() == ui_loop_); MessageLoop* loop = GetSaveLoop(); @@ -497,14 +498,13 @@ void SaveFileManager::SaveLocalFile(const GURL& original_file_url, // Copy the local file to the temporary file. It will be renamed to its // final name later. - bool success = file_util::CopyFile(file_path, - FilePath::FromWStringHack(save_file->full_path())); + bool success = file_util::CopyFile(file_path, save_file->full_path()); if (!success) file_util::Delete(save_file->full_path(), false); SaveFinished(save_id, original_file_url, render_process_id, success); } -void SaveFileManager::OnDeleteDirectoryOrFile(const std::wstring& full_path, +void SaveFileManager::OnDeleteDirectoryOrFile(const FilePath& full_path, bool is_dir) { DCHECK(MessageLoop::current() == GetSaveLoop()); DCHECK(!full_path.empty()); @@ -514,14 +514,19 @@ void SaveFileManager::OnDeleteDirectoryOrFile(const std::wstring& full_path, // Open a saved page package, show it in a Windows Explorer window. // We run on this thread to avoid blocking the UI with slow Shell operations. -void SaveFileManager::OnShowSavedFileInShell(const std::wstring full_path) { +void SaveFileManager::OnShowSavedFileInShell(const FilePath full_path) { DCHECK(MessageLoop::current() == GetSaveLoop()); - win_util::ShowItemInFolder(full_path); + // TODO(port): make an equivalent call on mac/linux. +#if defined(OS_WIN) + win_util::ShowItemInFolder(full_path.value()); +#elif defined(OS_POSIX) + NOTIMPLEMENTED(); +#endif } void SaveFileManager::RenameAllFiles( const FinalNameList& final_names, - const std::wstring& resource_dir, + const FilePath& resource_dir, int render_process_id, int render_view_id) { DCHECK(MessageLoop::current() == GetSaveLoop()); @@ -571,7 +576,7 @@ void SaveFileManager::RemoveSavedFileFromFileMap( if (it != save_file_map_.end()) { SaveFile* save_file = it->second; DCHECK(!save_file->in_progress()); - DeleteFile(save_file->full_path().c_str()); + file_util::Delete(save_file->full_path(), false); delete save_file; save_file_map_.erase(it); } diff --git a/chrome/browser/download/save_file_manager.h b/chrome/browser/download/save_file_manager.h index 4df5abf..89672fc 100644 --- a/chrome/browser/download/save_file_manager.h +++ b/chrome/browser/download/save_file_manager.h @@ -61,6 +61,7 @@ #include <utility> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/hash_tables.h" #include "base/ref_counted.h" #include "base/thread.h" @@ -98,7 +99,7 @@ class SaveFileManager int render_process_host_id, int render_view_id, SaveFileCreateInfo::SaveFileSource save_source, - const std::wstring& file_full_path, + const FilePath& file_full_path, URLRequestContext* request_context, SavePackage* save_package); @@ -118,10 +119,10 @@ class SaveFileManager SavePackage* package); // Handler for shell operations sent from the UI to the file thread. - void OnShowSavedFileInShell(const std::wstring full_path); + void OnShowSavedFileInShell(const FilePath full_path); // Helper function for deleting specified file. - void DeleteDirectoryOrFile(const std::wstring& full_path, bool is_dir); + void DeleteDirectoryOrFile(const FilePath& full_path, bool is_dir); // For posting notifications from the UI and IO threads. MessageLoop* GetSaveLoop() const { return file_loop_; } @@ -137,7 +138,7 @@ class SaveFileManager // final names of successfully saved files. void RenameAllFiles( const FinalNameList& final_names, - const std::wstring& resource_dir, + const FilePath& resource_dir, int render_process_id, int render_view_id); @@ -204,7 +205,7 @@ class SaveFileManager // Notifications sent from the UI thread and run on the file thread. // Deletes a specified file on the file thread. - void OnDeleteDirectoryOrFile(const std::wstring& full_path, bool is_dir); + void OnDeleteDirectoryOrFile(const FilePath& full_path, bool is_dir); // Notifications sent from the UI thread and run on the IO thread diff --git a/chrome/browser/download/save_item.cc b/chrome/browser/download/save_item.cc index bd96010..da96b88 100644 --- a/chrome/browser/download/save_item.cc +++ b/chrome/browser/download/save_item.cc @@ -113,10 +113,10 @@ int SaveItem::PercentComplete() const { } // Rename the save item with new path. -void SaveItem::Rename(const std::wstring& full_path) { +void SaveItem::Rename(const FilePath& full_path) { DCHECK(!full_path.empty() && !has_final_name()); full_path_ = full_path; - file_name_ = file_util::GetFilenameFromPath(full_path_); + file_name_ = full_path_.BaseName(); has_final_name_ = true; } diff --git a/chrome/browser/download/save_item.h b/chrome/browser/download/save_item.h index b54840a..62fe877 100644 --- a/chrome/browser/download/save_item.h +++ b/chrome/browser/download/save_item.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/file_path.h" #include "chrome/browser/download/save_types.h" #include "googleurl/src/gurl.h" @@ -47,7 +48,7 @@ class SaveItem { int PercentComplete() const; // Update path for SaveItem, the actual file is renamed on the file thread. - void Rename(const std::wstring& full_path); + void Rename(const FilePath& full_path); void SetSaveId(int32 save_id); @@ -55,8 +56,8 @@ class SaveItem { // Accessors. SaveState state() const { return state_; } - const std::wstring full_path() const { return full_path_; } - const std::wstring file_name() const { return file_name_; } + const FilePath& full_path() const { return full_path_; } + const FilePath& file_name() const { return file_name_; } const GURL& url() const { return url_; } const GURL& referrer() const { return referrer_; } int64 total_bytes() const { return total_bytes_; } @@ -77,10 +78,10 @@ class SaveItem { int32 save_id_; // Full path to the save item file. - std::wstring full_path_; + FilePath full_path_; // Short display version of the file. - std::wstring file_name_; + FilePath file_name_; // The URL for this save item. GURL url_; diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 4c6d938..91e0b41 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -380,10 +380,10 @@ void SavePackage::StartSave(const SaveFileCreateInfo* info) { // Now we get final name retrieved from GenerateFilename, we will use it // rename the SaveItem. FilePath final_name = saved_main_directory_path_.Append(generated_name); - save_item->Rename(final_name.ToWStringHack()); + save_item->Rename(final_name); } else { // It is the main HTML file, use the name chosen by the user. - save_item->Rename(saved_main_file_path_.ToWStringHack()); + save_item->Rename(saved_main_file_path_); } // If the save source is from file system, inform SaveFileManager to copy @@ -524,7 +524,7 @@ void SavePackage::CheckFinish() { NewRunnableMethod(file_manager_, &SaveFileManager::RenameAllFiles, final_names, - dir.ToWStringHack(), + dir, web_contents_->process()->host_id(), web_contents_->render_view_host()->routing_id())); } @@ -684,7 +684,7 @@ void SavePackage::ShowDownloadInShell() { file_manager_->GetSaveLoop()->PostTask(FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::OnShowSavedFileInShell, - saved_main_file_path_.ToWStringHack())); + saved_main_file_path_)); } // Calculate the percentage of whole save page job. @@ -745,7 +745,7 @@ void SavePackage::GetSerializedHtmlDataForCurrentPageWithLocalLinks() { if (wait_state_ != HTML_DATA) return; std::vector<GURL> saved_links; - std::vector<std::wstring> saved_file_paths; + std::vector<FilePath> saved_file_paths; int successful_started_items_count = 0; // Collect all saved items which have local storage. @@ -778,12 +778,9 @@ void SavePackage::GetSerializedHtmlDataForCurrentPageWithLocalLinks() { // Get the relative directory name. FilePath relative_dir_name = saved_main_directory_path_.BaseName(); - std::wstring relative_dir_name_str = std::wstring(L"./") + - relative_dir_name.ToWStringHack() + L"/"; - web_contents_->render_view_host()-> GetSerializedHtmlDataForCurrentPageWithLocalLinks( - saved_links, saved_file_paths, relative_dir_name_str); + saved_links, saved_file_paths, relative_dir_name); } // Process the serialized HTML content data of a specified web page diff --git a/chrome/browser/download/save_types.h b/chrome/browser/download/save_types.h index 7e19d18..b88361f 100644 --- a/chrome/browser/download/save_types.h +++ b/chrome/browser/download/save_types.h @@ -9,9 +9,10 @@ #include <utility> #include "base/basictypes.h" +#include "base/file_path.h" #include "googleurl/src/gurl.h" -typedef std::vector<std::pair<int, std::wstring> > FinalNameList; +typedef std::vector<std::pair<int, FilePath> > FinalNameList; typedef std::vector<int> SaveIDList; // This structure is used to handle and deliver some info @@ -29,7 +30,7 @@ struct SaveFileCreateInfo { SAVE_FILE_FROM_FILE }; - SaveFileCreateInfo(const std::wstring& path, + SaveFileCreateInfo(const FilePath& path, const GURL& url, SaveFileSource save_source, int32 save_id) @@ -47,7 +48,7 @@ struct SaveFileCreateInfo { // SaveItem fields. // The local file path of saved file. - std::wstring path; + FilePath path; // Original URL of the saved resource. GURL url; // Final URL of the saved resource since some URL might be redirected. diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 8c64d5f..ae84b8f 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -1229,8 +1229,8 @@ void RenderViewHost::OnDidGetApplicationInfo( void RenderViewHost::GetSerializedHtmlDataForCurrentPageWithLocalLinks( const std::vector<GURL>& links, - const std::vector<std::wstring>& local_paths, - const std::wstring& local_directory_name) { + const std::vector<FilePath>& local_paths, + const FilePath& local_directory_name) { Send(new ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks( routing_id(), links, local_paths, local_directory_name)); } diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 2f36219..15d0c6f 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -352,8 +352,8 @@ class RenderViewHost : public RenderWidgetHost { // contain all saved auxiliary files included all sub frames and resouces. void GetSerializedHtmlDataForCurrentPageWithLocalLinks( const std::vector<GURL>& links, - const std::vector<std::wstring>& local_paths, - const std::wstring& local_directory_name); + const std::vector<FilePath>& local_paths, + const FilePath& local_directory_name); // Notifies the RenderViewHost that a file has been chosen by the user from // an Open File dialog for the form. |