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