1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_BASE_PLATFORM_MIME_UTIL_H_ 6 #define NET_BASE_PLATFORM_MIME_UTIL_H_ 7 8 #include <string> 9 #include <string_view> 10 #include <unordered_set> 11 12 #include "base/files/file_path.h" 13 14 namespace net { 15 16 // Encapsulates the platform-specific functionality in mime_util. 17 class PlatformMimeUtil { 18 public: 19 // Adds all the extensions that the platform associates with the type 20 // |mime_type| to the set |extensions|. Returns at least the value returned 21 // by GetPreferredExtensionForMimeType. 22 void GetPlatformExtensionsForMimeType( 23 std::string_view mime_type, 24 std::unordered_set<base::FilePath::StringType>* extensions) const; 25 26 protected: 27 // Gets the preferred filename extension associated with the given 28 // mime type. Returns true if the file type is registered in the system. The 29 // extension is returned without a prefixed dot, ex "html". 30 bool GetPlatformPreferredExtensionForMimeType( 31 std::string_view mime_type, 32 base::FilePath::StringType* extension) const; 33 34 // Gets the mime type (if any) that is associated with the file extension. 35 // Returns true if a corresponding mime type exists. 36 bool GetPlatformMimeTypeFromExtension(const base::FilePath::StringType& ext, 37 std::string* mime_type) const; 38 }; 39 40 } // namespace net 41 42 #endif // NET_BASE_PLATFORM_MIME_UTIL_H_ 43