summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/save_package.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 16:12:37 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 16:12:37 +0000
commitda74e5ae26f295b4db6565ef6b9a4c4b1f61d510 (patch)
tree3528b88054cb8b297b17d7698c1e506d3f0ce84c /chrome/browser/download/save_package.cc
parent5db3b7e4a904820eb5e8bea6aa001421c8098505 (diff)
downloadchromium_src-da74e5ae26f295b4db6565ef6b9a4c4b1f61d510.zip
chromium_src-da74e5ae26f295b4db6565ef6b9a4c4b1f61d510.tar.gz
chromium_src-da74e5ae26f295b4db6565ef6b9a4c4b1f61d510.tar.bz2
Download code cleanup:
- convert some private static members to anonymous functions - move some methods from public to private This should make the interface of some download classes smaller, and hopefully easier to understand. BUG=48913 TEST=unit_tests, browser_tests, ui_tests Review URL: http://codereview.chromium.org/2974007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52327 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/save_package.cc')
-rw-r--r--chrome/browser/download/save_package.cc86
1 files changed, 52 insertions, 34 deletions
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index f95ba7c..a9a8a6f 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -126,6 +126,58 @@ FilePath::StringType StripOrdinalNumber(
return pure_file_name.substr(0, l_paren_index);
}
+// Check whether we can save page as complete-HTML for the contents which
+// have specified a MIME type. Now only contents which have the MIME type
+// "text/html" can be saved as complete-HTML.
+bool CanSaveAsComplete(const std::string& contents_mime_type) {
+ return contents_mime_type == "text/html" ||
+ contents_mime_type == "application/xhtml+xml";
+}
+
+// File name is considered being consist of pure file name, dot and file
+// extension name. File name might has no dot and file extension, or has
+// multiple dot inside file name. The dot, which separates the pure file
+// name and file extension name, is last dot in the whole file name.
+// This function is for making sure the length of specified file path is not
+// great than the specified maximum length of file path and getting safe pure
+// file name part if the input pure file name is too long.
+// The parameter |dir_path| specifies directory part of the specified
+// file path. The parameter |file_name_ext| specifies file extension
+// name part of the specified file path (including start dot). The parameter
+// |max_file_path_len| specifies maximum length of the specified file path.
+// The parameter |pure_file_name| input pure file name part of the specified
+// file path. If the length of specified file path is great than
+// |max_file_path_len|, the |pure_file_name| will output new pure file name
+// 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 GetSafePureFileName(const FilePath& dir_path,
+ const FilePath::StringType& file_name_ext,
+ uint32 max_file_path_len,
+ FilePath::StringType* pure_file_name) {
+ DCHECK(!pure_file_name->empty());
+ int available_length = static_cast<int>(
+ max_file_path_len - dir_path.value().length() - file_name_ext.length());
+ // Need an extra space for the separator.
+ if (!file_util::EndsWithSeparator(dir_path))
+ --available_length;
+
+ // Plenty of room.
+ if (static_cast<int>(pure_file_name->length()) <= available_length)
+ return true;
+
+ // Limited room. Truncate |pure_file_name| to fit.
+ if (available_length > 0) {
+ *pure_file_name =
+ pure_file_name->substr(0, available_length);
+ return true;
+ }
+
+ // Not enough room to even use a shortened |pure_file_name|.
+ pure_file_name->clear();
+ return false;
+}
+
// This task creates a directory and then posts a task on the given thread.
class CreateDownloadDirectoryTask : public Task {
public:
@@ -1319,40 +1371,6 @@ bool SavePackage::IsSavableContents(const std::string& contents_mime_type) {
net::IsSupportedJavascriptMimeType(contents_mime_type.c_str());
}
-// Static
-bool SavePackage::CanSaveAsComplete(const std::string& contents_mime_type) {
- return contents_mime_type == "text/html" ||
- contents_mime_type == "application/xhtml+xml";
-}
-
-// Static
-bool SavePackage::GetSafePureFileName(const FilePath& dir_path,
- const FilePath::StringType& file_name_ext,
- uint32 max_file_path_len,
- FilePath::StringType* pure_file_name) {
- DCHECK(!pure_file_name->empty());
- int available_length = static_cast<int>(
- max_file_path_len - dir_path.value().length() - file_name_ext.length());
- // Need an extra space for the separator.
- if (!file_util::EndsWithSeparator(dir_path))
- --available_length;
-
- // Plenty of room.
- if (static_cast<int>(pure_file_name->length()) <= available_length)
- return true;
-
- // Limited room. Truncate |pure_file_name| to fit.
- if (available_length > 0) {
- *pure_file_name =
- pure_file_name->substr(0, available_length);
- return true;
- }
-
- // Not enough room to even use a shortened |pure_file_name|.
- pure_file_name->clear();
- return false;
-}
-
// SelectFileDialog::Listener interface.
void SavePackage::FileSelected(const FilePath& path,
int index, void* params) {