filename_generation.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_FILENAME_GENERATION_FILENAME_GENERATION_H_
  5. #define COMPONENTS_FILENAME_GENERATION_FILENAME_GENERATION_H_
  6. #include <string>
  7. #include "base/files/file_path.h"
  8. class GURL;
  9. namespace filename_generation {
  10. // Returns extension for supported MIME types (for example, for "text/plain"
  11. // it returns "txt").
  12. const base::FilePath::CharType* ExtensionForMimeType(
  13. const std::string& contents_mime_type);
  14. // Ensures that the file name has a proper extension for HTML by adding ".htm"
  15. // if necessary.
  16. base::FilePath EnsureHtmlExtension(const base::FilePath& name);
  17. // Ensures that the file name has a proper extension for supported formats
  18. // if necessary.
  19. base::FilePath EnsureMimeExtension(const base::FilePath& name,
  20. const std::string& contents_mime_type);
  21. // Function for generating a filename based on |title|, if it is empty, |url|
  22. // will be used as a fallback.
  23. base::FilePath GenerateFilename(const std::u16string& title,
  24. const GURL& url,
  25. bool can_save_as_complete,
  26. std::string contents_mime_type);
  27. // Truncates path->BaseName() to make path->BaseName().value().size() <= limit.
  28. // - It keeps the extension as is. Only truncates the body part.
  29. // - Only truncates if the base filename can maintain a minimum length
  30. // (currently a hardcoded internval constant kTruncatedNameLengthLowerbound,
  31. // but could be parameterized if ever required).
  32. // If it was unable to shorten the name, returns false.
  33. bool TruncateFilename(base::FilePath* path, size_t limit);
  34. } // namespace filename_generation
  35. #endif // COMPONENTS_FILENAME_GENERATION_FILENAME_GENERATION_H_