Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1122)

Unified Diff: content/browser/download/save_package.cc

Issue 12286020: Replace FilePath with base::FilePath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/download/save_package.cc
diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc
index 06aab489f609c85008aa3088f462d0f54878cb6a..af3ac78594677bf698a6af9f47165d118604d5d9 100644
--- a/content/browser/download/save_package.cc
+++ b/content/browser/download/save_package.cc
@@ -385,10 +385,11 @@ uint32 SavePackage::GetMaxPathLengthForDirectory(
// part for making sure the length of specified file path is less than
// specified maximum length of file path. Return false if the function can
// not get a safe pure file name, otherwise it returns true.
-bool SavePackage::GetSafePureFileName(const FilePath& dir_path,
- const FilePath::StringType& file_name_ext,
- uint32 max_file_path_len,
- FilePath::StringType* pure_file_name) {
+bool SavePackage::GetSafePureFileName(
+ const base::FilePath& dir_path,
+ const base::FilePath::StringType& file_name_ext,
+ uint32 max_file_path_len,
+ base::FilePath::StringType* pure_file_name) {
DCHECK(!pure_file_name->empty());
int available_length = static_cast<int>(max_file_path_len -
dir_path.value().length() -
@@ -416,16 +417,16 @@ bool SavePackage::GetSafePureFileName(const FilePath& dir_path,
bool SavePackage::GenerateFileName(const std::string& disposition,
const GURL& url,
bool need_html_ext,
- FilePath::StringType* generated_name) {
+ base::FilePath::StringType* generated_name) {
// TODO(jungshik): Figure out the referrer charset when having one
// makes sense and pass it to GenerateFileName.
- FilePath file_path = net::GenerateFileName(url, disposition, "", "", "",
- kDefaultSaveName);
+ base::FilePath file_path = net::GenerateFileName(url, disposition, "", "", "",
+ kDefaultSaveName);
DCHECK(!file_path.empty());
- FilePath::StringType pure_file_name =
+ base::FilePath::StringType pure_file_name =
file_path.RemoveExtension().BaseName().value();
- FilePath::StringType file_name_ext = file_path.Extension();
+ base::FilePath::StringType file_name_ext = file_path.Extension();
// If it is HTML resource, use ".htm{l,}" as its extension.
if (need_html_ext) {
@@ -441,7 +442,7 @@ bool SavePackage::GenerateFileName(const std::string& disposition,
max_path, &pure_file_name))
return false;
- FilePath::StringType file_name = pure_file_name + file_name_ext;
+ base::FilePath::StringType file_name = pure_file_name + file_name_ext;
// Check whether we already have same name in a case insensitive manner.
FileNameSet::const_iterator iter = file_name_set_.find(file_name);
@@ -450,8 +451,9 @@ bool SavePackage::GenerateFileName(const std::string& disposition,
} else {
// Found same name, increase the ordinal number for the file name.
pure_file_name =
- FilePath(*iter).RemoveExtension().BaseName().value();
- FilePath::StringType base_file_name = StripOrdinalNumber(pure_file_name);
+ base::FilePath(*iter).RemoveExtension().BaseName().value();
+ base::FilePath::StringType base_file_name =
+ StripOrdinalNumber(pure_file_name);
// We need to make sure the length of base file name plus maximum ordinal
// number path will be less than or equal to kMaxFilePathLength.
@@ -473,17 +475,17 @@ bool SavePackage::GenerateFileName(const std::string& disposition,
if (ordinal_number > (kMaxFileOrdinalNumber - 1)) {
// Use a random file from temporary file.
- FilePath temp_file;
+ base::FilePath temp_file;
file_util::CreateTemporaryFile(&temp_file);
file_name = temp_file.RemoveExtension().BaseName().value();
// Get safe pure file name.
if (!GetSafePureFileName(saved_main_directory_path_,
- FilePath::StringType(),
+ base::FilePath::StringType(),
max_path, &file_name))
return false;
} else {
for (int i = ordinal_number; i < kMaxFileOrdinalNumber; ++i) {
- FilePath::StringType new_name = base_file_name +
+ base::FilePath::StringType new_name = base_file_name +
StringPrintf(FILE_PATH_LITERAL("(%d)"), i) + file_name_ext;
if (file_name_set_.find(new_name) == file_name_set_.end()) {
// Resolved name conflict.
@@ -525,7 +527,7 @@ void SavePackage::StartSave(const SaveFileCreateInfo* info) {
// save directory, or prompting the user.
DCHECK(!save_item->has_final_name());
if (info->url != page_url_) {
- FilePath::StringType generated_name;
+ base::FilePath::StringType generated_name;
// For HTML resource file, make sure it will have .htm as extension name,
// otherwise, when you open the saved page in Chrome again, download
// file manager will treat it as downloadable resource, and download it
@@ -556,7 +558,8 @@ 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);
+ base::FilePath final_name =
+ saved_main_directory_path_.Append(generated_name);
save_item->Rename(final_name);
} else {
// It is the main HTML file, use the name chosen by the user.
@@ -692,9 +695,9 @@ void SavePackage::CheckFinish() {
if (in_process_count() || finished_)
return;
- FilePath dir = (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML &&
- saved_success_items_.size() > 1) ?
- saved_main_directory_path_ : FilePath();
+ base::FilePath dir = (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML &&
+ saved_success_items_.size() > 1) ?
+ saved_main_directory_path_ : base::FilePath();
// This vector contains the final names of all the successfully saved files
// along with their save ids. It will be passed to SaveFileManager to do the
@@ -972,7 +975,7 @@ void SavePackage::GetSerializedHtmlDataForCurrentPageWithLocalLinks() {
if (wait_state_ != HTML_DATA)
return;
std::vector<GURL> saved_links;
- std::vector<FilePath> saved_file_paths;
+ std::vector<base::FilePath> saved_file_paths;
int successful_started_items_count = 0;
// Collect all saved items which have local storage.
@@ -1003,7 +1006,7 @@ void SavePackage::GetSerializedHtmlDataForCurrentPageWithLocalLinks() {
}
// Get the relative directory name.
- FilePath relative_dir_name = saved_main_directory_path_.BaseName();
+ base::FilePath relative_dir_name = saved_main_directory_path_.BaseName();
Send(new ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks(
routing_id(), saved_links, saved_file_paths, relative_dir_name));
@@ -1154,12 +1157,12 @@ void SavePackage::OnReceivedSavableResourceLinksForCurrentPage(
}
}
-FilePath SavePackage::GetSuggestedNameForSaveAs(
+base::FilePath SavePackage::GetSuggestedNameForSaveAs(
bool can_save_as_complete,
const std::string& contents_mime_type,
const std::string& accept_langs) {
- FilePath name_with_proper_ext =
- FilePath::FromWStringHack(UTF16ToWideHack(title_));
+ base::FilePath name_with_proper_ext =
+ base::FilePath::FromWStringHack(UTF16ToWideHack(title_));
// If the page's title matches its URL, use the URL. Try to use the last path
// component or if there is none, the domain as the file name.
@@ -1187,7 +1190,8 @@ FilePath SavePackage::GetSuggestedNameForSaveAs(
} else {
url_path = "dataurl";
}
- name_with_proper_ext = FilePath::FromWStringHack(UTF8ToWide(url_path));
+ name_with_proper_ext =
+ base::FilePath::FromWStringHack(UTF8ToWide(url_path));
}
// Ask user for getting final saving name.
@@ -1197,48 +1201,48 @@ FilePath SavePackage::GetSuggestedNameForSaveAs(
if (can_save_as_complete)
name_with_proper_ext = EnsureHtmlExtension(name_with_proper_ext);
- FilePath::StringType file_name = name_with_proper_ext.value();
+ base::FilePath::StringType file_name = name_with_proper_ext.value();
file_util::ReplaceIllegalCharactersInPath(&file_name, ' ');
- return FilePath(file_name);
+ return base::FilePath(file_name);
}
-FilePath SavePackage::EnsureHtmlExtension(const FilePath& name) {
+base::FilePath SavePackage::EnsureHtmlExtension(const base::FilePath& name) {
// If the file name doesn't have an extension suitable for HTML files,
// append one.
- FilePath::StringType ext = name.Extension();
+ base::FilePath::StringType ext = name.Extension();
if (!ext.empty())
ext.erase(ext.begin()); // Erase preceding '.'.
std::string mime_type;
if (!net::GetMimeTypeFromExtension(ext, &mime_type) ||
!CanSaveAsComplete(mime_type)) {
- return FilePath(name.value() + FILE_PATH_LITERAL(".") +
- kDefaultHtmlExtension);
+ return base::FilePath(name.value() + FILE_PATH_LITERAL(".") +
+ kDefaultHtmlExtension);
}
return name;
}
-FilePath SavePackage::EnsureMimeExtension(const FilePath& name,
+base::FilePath SavePackage::EnsureMimeExtension(const base::FilePath& name,
const std::string& contents_mime_type) {
// Start extension at 1 to skip over period if non-empty.
- FilePath::StringType ext = name.Extension().length() ?
+ base::FilePath::StringType ext = name.Extension().length() ?
name.Extension().substr(1) : name.Extension();
- FilePath::StringType suggested_extension =
+ base::FilePath::StringType suggested_extension =
ExtensionForMimeType(contents_mime_type);
std::string mime_type;
if (!suggested_extension.empty() &&
!net::GetMimeTypeFromExtension(ext, &mime_type)) {
// Extension is absent or needs to be updated.
- return FilePath(name.value() + FILE_PATH_LITERAL(".") +
+ return base::FilePath(name.value() + FILE_PATH_LITERAL(".") +
suggested_extension);
}
return name;
}
-const FilePath::CharType* SavePackage::ExtensionForMimeType(
+const base::FilePath::CharType* SavePackage::ExtensionForMimeType(
const std::string& contents_mime_type) {
static const struct {
- const FilePath::CharType *mime_type;
- const FilePath::CharType *suggested_extension;
+ const base::FilePath::CharType *mime_type;
+ const base::FilePath::CharType *suggested_extension;
} extensions[] = {
{ FILE_PATH_LITERAL("text/html"), kDefaultHtmlExtension },
{ FILE_PATH_LITERAL("text/xml"), FILE_PATH_LITERAL("xml") },
@@ -1247,9 +1251,9 @@ const FilePath::CharType* SavePackage::ExtensionForMimeType(
{ FILE_PATH_LITERAL("text/css"), FILE_PATH_LITERAL("css") },
};
#if defined(OS_POSIX)
- FilePath::StringType mime_type(contents_mime_type);
+ base::FilePath::StringType mime_type(contents_mime_type);
#elif defined(OS_WIN)
- FilePath::StringType mime_type(UTF8ToWide(contents_mime_type));
+ base::FilePath::StringType mime_type(UTF8ToWide(contents_mime_type));
#endif // OS_WIN
for (uint32 i = 0; i < ARRAYSIZE_UNSAFE(extensions); ++i) {
if (mime_type == extensions[i].mime_type)
@@ -1265,7 +1269,7 @@ WebContents* SavePackage::web_contents() const {
void SavePackage::GetSaveInfo() {
// Can't use web_contents_ in the file thread, so get the data that we need
// before calling to it.
- FilePath website_save_dir, download_save_dir;
+ base::FilePath website_save_dir, download_save_dir;
bool skip_dir_check;
DCHECK(download_manager_);
if (download_manager_->GetDelegate()) {
@@ -1286,12 +1290,12 @@ void SavePackage::GetSaveInfo() {
}
void SavePackage::CreateDirectoryOnFileThread(
- const FilePath& website_save_dir,
- const FilePath& download_save_dir,
+ const base::FilePath& website_save_dir,
+ const base::FilePath& download_save_dir,
bool skip_dir_check,
const std::string& mime_type,
const std::string& accept_langs) {
- FilePath save_dir;
+ base::FilePath save_dir;
// If the default html/websites save folder doesn't exist...
// We skip the directory check for gdata directories on ChromeOS.
if (!skip_dir_check && !file_util::DirectoryExists(website_save_dir)) {
@@ -1307,11 +1311,11 @@ void SavePackage::CreateDirectoryOnFileThread(
}
bool can_save_as_complete = CanSaveAsComplete(mime_type);
- FilePath suggested_filename = GetSuggestedNameForSaveAs(
+ base::FilePath suggested_filename = GetSuggestedNameForSaveAs(
can_save_as_complete, mime_type, accept_langs);
- FilePath::StringType pure_file_name =
+ base::FilePath::StringType pure_file_name =
suggested_filename.RemoveExtension().BaseName().value();
- FilePath::StringType file_name_ext = suggested_filename.Extension();
+ base::FilePath::StringType file_name_ext = suggested_filename.Extension();
// Need to make sure the suggested file name is not too long.
uint32 max_path = GetMaxPathLengthForDirectory(save_dir);
@@ -1332,7 +1336,7 @@ void SavePackage::CreateDirectoryOnFileThread(
can_save_as_complete));
}
-void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path,
+void SavePackage::ContinueGetSaveInfo(const base::FilePath& suggested_path,
bool can_save_as_complete) {
// The WebContents which owns this SavePackage may have disappeared during
@@ -1341,7 +1345,7 @@ void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path,
if (!web_contents() || !download_manager_->GetDelegate())
return;
- FilePath::StringType default_extension;
+ base::FilePath::StringType default_extension;
if (can_save_as_complete)
default_extension = kDefaultHtmlExtension;
@@ -1354,7 +1358,7 @@ void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path,
}
void SavePackage::OnPathPicked(
- const FilePath& final_name,
+ const base::FilePath& final_name,
SavePageType type,
const SavePackageDownloadCreatedCallback& download_created_callback) {
// Ensure the filename is safe.
« no previous file with comments | « content/browser/download/file_metadata_mac.mm ('k') | content/browser/renderer_host/pepper/pepper_flash_file_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698