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