media_file_system_registry.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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// MediaFileSystemRegistry registers pictures directories and media devices as 6// File API filesystems and keeps track of the path to filesystem ID mappings. 7 8#ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_ 9#define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_ 10 11#include <map> 12#include <string> 13#include <utility> 14#include <vector> 15 16#include "base/basictypes.h" 17#include "base/files/file_path.h" 18#include "base/memory/ref_counted.h" 19#include "base/memory/scoped_ptr.h" 20#include "chrome/browser/media_galleries/media_galleries_preferences.h" 21#include "components/storage_monitor/removable_storage_observer.h" 22 23class ExtensionGalleriesHost; 24class MediaFileSystemContext; 25class MediaGalleriesPreferences; 26class MediaScanManager; 27class Profile; 28 29namespace content { 30class RenderViewHost; 31} 32 33namespace extensions { 34class Extension; 35} 36 37namespace fileapi { 38class IsolatedContext; 39} 40 41// Contains information about a particular filesystem being provided to a 42// client, including metadata like the name and ID, and API handles like the 43// fsid (filesystem ID) used to hook up the API objects. 44struct MediaFileSystemInfo { 45 MediaFileSystemInfo(const base::string16& fs_name, 46 const base::FilePath& fs_path, 47 const std::string& filesystem_id, 48 MediaGalleryPrefId pref_id, 49 const std::string& transient_device_id, 50 bool removable, 51 bool media_device); 52 MediaFileSystemInfo(); 53 ~MediaFileSystemInfo(); 54 55 base::string16 name; 56 base::FilePath path; 57 std::string fsid; 58 MediaGalleryPrefId pref_id; 59 std::string transient_device_id; 60 bool removable; 61 bool media_device; 62}; 63 64typedef base::Callback<void(const std::vector<MediaFileSystemInfo>&)> 65 MediaFileSystemsCallback; 66 67// Tracks usage of filesystems by extensions. 68// This object lives on the UI thread. 69class MediaFileSystemRegistry 70 : public storage_monitor::RemovableStorageObserver, 71 public MediaGalleriesPreferences::GalleryChangeObserver { 72 public: 73 MediaFileSystemRegistry(); 74 virtual ~MediaFileSystemRegistry(); 75 76 // Passes to |callback| the list of media filesystem IDs and paths for a 77 // given RVH. 78 void GetMediaFileSystemsForExtension( 79 const content::RenderViewHost* rvh, 80 const extensions::Extension* extension, 81 const MediaFileSystemsCallback& callback); 82 83 // Returns the media galleries preferences for the specified |profile|. 84 // Caller is responsible for ensuring that the preferences are initialized 85 // before use. 86 MediaGalleriesPreferences* GetPreferences(Profile* profile); 87 88 MediaScanManager* media_scan_manager(); 89 90 // RemovableStorageObserver implementation. 91 virtual void OnRemovableStorageDetached( 92 const storage_monitor::StorageInfo& info) OVERRIDE; 93 94 private: 95 class MediaFileSystemContextImpl; 96 97 friend class MediaFileSystemContextImpl; 98 friend class MediaFileSystemRegistryTest; 99 friend class TestMediaFileSystemContext; 100 101 // Map an extension to the ExtensionGalleriesHost. 102 typedef std::map<std::string /*extension_id*/, 103 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap; 104 // Map a profile and extension to the ExtensionGalleriesHost. 105 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap; 106 107 virtual void OnPermissionRemoved(MediaGalleriesPreferences* pref, 108 const std::string& extension_id, 109 MediaGalleryPrefId pref_id) OVERRIDE; 110 virtual void OnGalleryRemoved(MediaGalleriesPreferences* pref, 111 MediaGalleryPrefId pref_id) OVERRIDE; 112 113 void OnExtensionGalleriesHostEmpty(Profile* profile, 114 const std::string& extension_id); 115 116 // This map owns all the ExtensionGalleriesHost objects created. 117 ExtensionGalleriesHostMap extension_hosts_map_; 118 119 scoped_ptr<MediaFileSystemContext> file_system_context_; 120 121 scoped_ptr<MediaScanManager> media_scan_manager_; 122 123 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry); 124}; 125 126#endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_ 127