platform_mime_util.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2012 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 NET_BASE_PLATFORM_MIME_UTIL_H_
  5. #define NET_BASE_PLATFORM_MIME_UTIL_H_
  6. #include <string>
  7. #include <unordered_set>
  8. #include "base/files/file_path.h"
  9. namespace net {
  10. // Encapsulates the platform-specific functionality in mime_util.
  11. class PlatformMimeUtil {
  12. public:
  13. // Adds all the extensions that the platform associates with the type
  14. // |mime_type| to the set |extensions|. Returns at least the value returned
  15. // by GetPreferredExtensionForMimeType.
  16. void GetPlatformExtensionsForMimeType(
  17. const std::string& mime_type,
  18. std::unordered_set<base::FilePath::StringType>* extensions) const;
  19. protected:
  20. // Gets the preferred filename extension associated with the given
  21. // mime type. Returns true if the file type is registered in the system. The
  22. // extension is returned without a prefixed dot, ex "html".
  23. bool GetPlatformPreferredExtensionForMimeType(
  24. const std::string& mime_type,
  25. base::FilePath::StringType* extension) const;
  26. // Gets the mime type (if any) that is associated with the file extension.
  27. // Returns true if a corresponding mime type exists.
  28. bool GetPlatformMimeTypeFromExtension(const base::FilePath::StringType& ext,
  29. std::string* mime_type) const;
  30. };
  31. } // namespace net
  32. #endif // NET_BASE_PLATFORM_MIME_UTIL_H_