15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/media_galleries/fileapi/media_path_filter.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_WIN)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <windows.h>
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm>
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/mime_util.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::FilePath::CharType* const kExtraSupportedImageExtensions[] = {
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // RAW picture file types.
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Some of which are just image/tiff.
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("3fr"),  // (Hasselblad)
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("arw"),  // (Sony)
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("dcr"),  // (Kodak)
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("dng"),  // (Adobe, Leica, Ricoh, Samsung)
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("erf"),  // (Epson)
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("k25"),  // (Kodak)
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("kdc"),  // (Kodak)
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("mef"),  // (Mamiya)
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("mos"),  // (Leaf)
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("nef"),  // (Nikon)
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("pef"),  // (Pentax)
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("sr2"),  // (Sony)
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("srf"),  // (Sony)
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // More RAW picture file types.
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("cr2"),  // (Canon - image/x-canon-cr2)
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Note, some .crw files are just TIFFs.
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("crw"),  // (Canon - image/x-canon-crw)
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("mrw"),  // (Minolta - image/x-minolta-mrw)
4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("orf"),  // (Olympus - image/x-olympus-orf)
4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("raf"),  // (Fuji)
4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("rw2"),  // (Panasonic - image/x-panasonic-raw)
4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("x3f"),  // (Sigma - image/x-x3f)
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // There exists many file formats all with the .raw extension. For now, only
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // the following types are supported:
4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // - TIFF files with .raw extension - image/tiff
4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // - Leica / Panasonic RAW files - image/x-panasonic-raw
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // - Phase One RAW files - image/x-phaseone-raw
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FILE_PATH_LITERAL("raw"),
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::FilePath::CharType* const kExtraSupportedVideoExtensions[] = {
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("3gp"),
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("3gpp"),
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("avi"),
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("flv"),
598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  FILE_PATH_LITERAL("mkv"),
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("mov"),
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("mpeg"),
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("mpeg4"),
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("mpegps"),
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("mpg"),
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FILE_PATH_LITERAL("wmv"),
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::FilePath::CharType* const kExtraSupportedAudioExtensions[] = {
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Many of these file types are audio files in the same containers that the
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // MIME sniffer already detects as video/subtype.
717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  FILE_PATH_LITERAL("aac"),   // audio/mpeg
727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  FILE_PATH_LITERAL("alac"),  // video/mp4
737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  FILE_PATH_LITERAL("flac"),  // audio/x-flac
747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  FILE_PATH_LITERAL("m4b"),   // video/mp4
757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  FILE_PATH_LITERAL("m4p"),   // video/mp4
767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  FILE_PATH_LITERAL("wma"),   // video/x-ms-asf
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool IsUnsupportedExtension(const base::FilePath::StringType& extension) {
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string mime_type;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return !net::GetMimeTypeFromExtension(extension, &mime_type) ||
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      !net::IsSupportedMimeType(mime_type);
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)std::vector<base::FilePath::StringType> GetMediaExtensionList(
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& mime_type) {
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<base::FilePath::StringType> extensions;
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  net::GetExtensionsForMimeType(mime_type, &extensions);
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<base::FilePath::StringType>::iterator new_end =
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::remove_if(extensions.begin(),
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     extensions.end(),
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     &IsUnsupportedExtension);
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  extensions.erase(new_end, extensions.end());
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return extensions;
955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// static
1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool MediaPathFilter::ShouldSkip(const base::FilePath& path) {
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::FilePath::StringType base_name = path.BaseName().value();
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (base_name.empty())
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Dot files (aka hidden files)
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (base_name[0] == '.')
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Mac OS X file.
1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (base_name == FILE_PATH_LITERAL("__MACOSX"))
1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_WIN)
1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DWORD file_attributes = ::GetFileAttributes(path.value().c_str());
1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if ((file_attributes != INVALID_FILE_ATTRIBUTES) &&
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ((file_attributes & FILE_ATTRIBUTE_HIDDEN) != 0))
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#else
1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Windows always creates a recycle bin folder in the attached device to store
1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // all the deleted contents. On non-windows operating systems, there is no way
1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to get the hidden attribute of windows recycle bin folders that are present
1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // on the attached device. Therefore, compare the file path name to the
1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // recycle bin name and exclude those folders. For more details, please refer
1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to http://support.microsoft.com/kb/171694.
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const char win_98_recycle_bin_name[] = "RECYCLED";
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const char win_xp_recycle_bin_name[] = "RECYCLER";
1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const char win_vista_recycle_bin_name[] = "$Recycle.bin";
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if ((base::strncasecmp(base_name.c_str(),
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         win_98_recycle_bin_name,
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         strlen(win_98_recycle_bin_name)) == 0) ||
1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      (base::strncasecmp(base_name.c_str(),
1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         win_xp_recycle_bin_name,
1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         strlen(win_xp_recycle_bin_name)) == 0) ||
1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      (base::strncasecmp(base_name.c_str(),
1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         win_vista_recycle_bin_name,
1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         strlen(win_vista_recycle_bin_name)) == 0))
1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // defined(OS_WIN)
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return false;
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MediaPathFilter::MediaPathFilter()
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : initialized_(false) {
1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  sequence_checker_.DetachFromSequence();
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MediaPathFilter::~MediaPathFilter() {
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool MediaPathFilter::Match(const base::FilePath& path) {
1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return GetType(path) != MEDIA_GALLERY_SCAN_FILE_TYPE_UNKNOWN;
1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)MediaGalleryScanFileType MediaPathFilter::GetType(const base::FilePath& path) {
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EnsureInitialized();
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  MediaFileExtensionMap::const_iterator it =
1576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      media_file_extensions_map_.find(
1586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          base::StringToLowerASCII(path.Extension()));
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (it == media_file_extensions_map_.end())
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return MEDIA_GALLERY_SCAN_FILE_TYPE_UNKNOWN;
1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return static_cast<MediaGalleryScanFileType>(it->second);
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void MediaPathFilter::EnsureInitialized() {
1654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DCHECK(sequence_checker_.CalledOnValidSequencedThread());
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (initialized_)
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This may require I/O when it calls net::GetExtensionsForMimeType(), so
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // doing this in the ctor and removing |initialized_| would result in a
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // ThreadRestrictions failure.
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AddExtensionsToMediaFileExtensionMap(GetMediaExtensionList("image/*"),
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                       MEDIA_GALLERY_SCAN_FILE_TYPE_IMAGE);
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AddExtensionsToMediaFileExtensionMap(GetMediaExtensionList("audio/*"),
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                       MEDIA_GALLERY_SCAN_FILE_TYPE_AUDIO);
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AddExtensionsToMediaFileExtensionMap(GetMediaExtensionList("video/*"),
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                       MEDIA_GALLERY_SCAN_FILE_TYPE_VIDEO);
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AddAdditionalExtensionsToMediaFileExtensionMap(
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      kExtraSupportedImageExtensions,
1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      arraysize(kExtraSupportedImageExtensions),
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      MEDIA_GALLERY_SCAN_FILE_TYPE_IMAGE);
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AddAdditionalExtensionsToMediaFileExtensionMap(
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      kExtraSupportedAudioExtensions,
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      arraysize(kExtraSupportedAudioExtensions),
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      MEDIA_GALLERY_SCAN_FILE_TYPE_AUDIO);
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AddAdditionalExtensionsToMediaFileExtensionMap(
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      kExtraSupportedVideoExtensions,
1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      arraysize(kExtraSupportedVideoExtensions),
1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      MEDIA_GALLERY_SCAN_FILE_TYPE_VIDEO);
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  initialized_ = true;
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MediaPathFilter::AddExtensionsToMediaFileExtensionMap(
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const MediaFileExtensionList& extensions_list,
1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    MediaGalleryScanFileType type) {
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0; i < extensions_list.size(); ++i)
1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AddExtensionToMediaFileExtensionMap(extensions_list[i].c_str(), type);
1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MediaPathFilter::AddAdditionalExtensionsToMediaFileExtensionMap(
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::FilePath::CharType* const* extensions_list,
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    size_t extensions_list_size,
2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    MediaGalleryScanFileType type) {
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0; i < extensions_list_size; ++i)
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AddExtensionToMediaFileExtensionMap(extensions_list[i], type);
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MediaPathFilter::AddExtensionToMediaFileExtensionMap(
2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::FilePath::CharType* extension,
2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    MediaGalleryScanFileType type) {
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::FilePath::StringType extension_with_sep =
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::FilePath::kExtensionSeparator +
2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::FilePath::StringType(extension);
2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  media_file_extensions_map_[extension_with_sep] |= type;
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
217