Home | History | Annotate | Download | only in file_manager
      1 // Copyright 2013 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 #include "chrome/browser/chromeos/file_manager/mime_util.h"
      6 
      7 #include "base/files/file_path.h"
      8 #include "net/base/mime_util.h"
      9 
     10 namespace file_manager {
     11 namespace util {
     12 
     13 std::string GetMimeTypeForPath(const base::FilePath& file_path) {
     14   const base::FilePath::StringType file_extension = file_path.Extension();
     15 
     16   // TODO(thorogood): Rearchitect this call so it can run on the File thread;
     17   // GetMimeTypeFromFile requires this on Linux. Right now, we use
     18   // Chrome-level knowledge only.
     19   std::string mime_type;
     20   if (file_extension.empty() ||
     21       !net::GetWellKnownMimeTypeFromExtension(file_extension.substr(1),
     22                                               &mime_type)) {
     23     // If the file doesn't have an extension or its mime-type cannot be
     24     // determined, then indicate that it has the empty mime-type. This will
     25     // only be matched if the Web Intents accepts "*" or "*/*".
     26     return "";
     27   } else {
     28     return mime_type;
     29   }
     30 }
     31 
     32 }  // namespace util
     33 }  // namespace file_manager
     34