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 5 #ifndef CHROME_BROWSER_CHROMEOS_CROSTINI_CROSTINI_MIME_TYPES_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROSTINI_CROSTINI_MIME_TYPES_SERVICE_H_ 7 8 #include <string> 9 10 #include "base/files/file_path.h" 11 #include "base/macros.h" 12 #include "components/keyed_service/core/keyed_service.h" 13 14 class Profile; 15 class PrefService; 16 17 namespace vm_tools { 18 namespace apps { 19 class MimeTypes; 20 } // namespace apps 21 } // namespace vm_tools 22 23 namespace crostini { 24 25 // The CrostiniMimeTypesService stores information about file extension to MIME 26 // type mappings in Crostini. We store this in prefs so that it is readily 27 // available even when the VM isn't running. 28 class CrostiniMimeTypesService : public KeyedService { 29 public: 30 explicit CrostiniMimeTypesService(Profile* profile); 31 ~CrostiniMimeTypesService() override; 32 33 // Returns a MIME type that corresponds to the file extension for the passed 34 // in |file_path| for the specified |vm_name| and |container_name|. Returns 35 // the empty string if there is no mapping. 36 std::string GetMimeType(const base::FilePath& file_path, 37 const std::string& vm_name, 38 const std::string& container_name) const; 39 40 // Remove all MIME type associations for the named VM. Used in the 41 // uninstall process. 42 void ClearMimeTypes(const std::string& vm_name, 43 const std::string& container_name); 44 45 // The existing list of MIME type mappings is replaced by 46 // |mime_type_mappings|. 47 void UpdateMimeTypes(const vm_tools::apps::MimeTypes& mime_type_mappings); 48 49 private: 50 // Owned by the Profile. 51 PrefService* const prefs_; 52 53 DISALLOW_COPY_AND_ASSIGN(CrostiniMimeTypesService); 54 }; 55 56 } // namespace crostini 57 58 #endif // CHROME_BROWSER_CHROMEOS_CROSTINI_CROSTINI_MIME_TYPES_SERVICE_H_ 59