Home | History | Annotate | Download | only in fileapi
      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 
      5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_PATH_FILTER_H_
      6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_PATH_FILTER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/containers/hash_tables.h"
     12 #include "base/files/file_path.h"
     13 #include "base/sequence_checker.h"
     14 #include "chrome/browser/media_galleries/media_scan_types.h"
     15 
     16 // This class holds the list of file path extensions that we should expose on
     17 // media filesystem.
     18 class MediaPathFilter {
     19  public:
     20   // Used to skip hidden folders and files. Returns true if the file specified
     21   // by |path| should be skipped.
     22   static bool ShouldSkip(const base::FilePath& path);
     23 
     24   MediaPathFilter();
     25   ~MediaPathFilter();
     26 
     27   // Returns true if |path| is a media file.
     28   bool Match(const base::FilePath& path);
     29 
     30   // Returns the type of |path| or MEDIA_GALLERY_SCAN_FILE_TYPE_UNKNOWN if it
     31   // is not a media file.
     32   MediaGalleryScanFileType GetType(const base::FilePath& path);
     33 
     34  private:
     35   typedef std::vector<base::FilePath::StringType> MediaFileExtensionList;
     36 
     37   // Key: .extension
     38   // Value: MediaGalleryScanFileType, but stored as an int to allow "|="
     39   typedef base::hash_map<base::FilePath::StringType, int> MediaFileExtensionMap;
     40 
     41   void EnsureInitialized();
     42 
     43   void AddExtensionsToMediaFileExtensionMap(
     44       const MediaFileExtensionList& extensions_list,
     45       MediaGalleryScanFileType type);
     46   void AddAdditionalExtensionsToMediaFileExtensionMap(
     47       const base::FilePath::CharType* const* extensions_list,
     48       size_t extensions_list_size,
     49       MediaGalleryScanFileType type);
     50   void AddExtensionToMediaFileExtensionMap(
     51       const base::FilePath::CharType* extension,
     52       MediaGalleryScanFileType type);
     53 
     54   // Checks |initialized_| is only accessed on one sequence.
     55   base::SequenceChecker sequence_checker_;
     56   bool initialized_;
     57   MediaFileExtensionMap media_file_extensions_map_;
     58 
     59   DISALLOW_COPY_AND_ASSIGN(MediaPathFilter);
     60 };
     61 
     62 #endif  // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_PATH_FILTER_H_
     63