OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // MediaFileSystemRegistry implementation. | 5 // MediaFileSystemRegistry implementation. |
6 | 6 |
7 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 7 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
| 11 #include "base/file_path.h" |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/system_monitor/system_monitor.h" |
12 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/extensions/extension.h" |
14 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
18 #include "webkit/fileapi/isolated_context.h" | 21 #include "webkit/fileapi/isolated_context.h" |
19 | 22 |
20 namespace chrome { | 23 namespace chrome { |
21 | 24 |
22 static base::LazyInstance<MediaFileSystemRegistry>::Leaky | 25 static base::LazyInstance<MediaFileSystemRegistry>::Leaky |
23 g_media_file_system_registry = LAZY_INSTANCE_INITIALIZER; | 26 g_media_file_system_registry = LAZY_INSTANCE_INITIALIZER; |
24 | 27 |
25 using base::SystemMonitor; | 28 using base::SystemMonitor; |
26 using content::BrowserThread; | 29 using content::BrowserThread; |
27 using content::RenderProcessHost; | 30 using content::RenderProcessHost; |
28 using fileapi::IsolatedContext; | 31 using fileapi::IsolatedContext; |
29 | 32 |
| 33 namespace { |
| 34 |
| 35 bool IsGalleryPermittedForExtension(const extensions::Extension& extension, |
| 36 SystemMonitor::MediaDeviceType type, |
| 37 const FilePath::StringType& location) { |
| 38 if (extension.HasAPIPermission( |
| 39 extensions::APIPermission::kMediaGalleriesAllGalleries)) { |
| 40 return true; |
| 41 } |
| 42 // TODO(vandebo) Check with prefs for permission to this gallery. |
| 43 return false; |
| 44 } |
| 45 |
| 46 } // namespace |
| 47 |
| 48 |
30 /****************** | 49 /****************** |
31 * Public methods | 50 * Public methods |
32 ******************/ | 51 ******************/ |
33 | 52 |
34 // static | 53 // static |
35 MediaFileSystemRegistry* MediaFileSystemRegistry::GetInstance() { | 54 MediaFileSystemRegistry* MediaFileSystemRegistry::GetInstance() { |
36 return g_media_file_system_registry.Pointer(); | 55 return g_media_file_system_registry.Pointer(); |
37 } | 56 } |
38 | 57 |
39 std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> | 58 std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> |
40 MediaFileSystemRegistry::GetMediaFileSystems( | 59 MediaFileSystemRegistry::GetMediaFileSystems( |
41 const content::RenderProcessHost* rph) { | 60 const content::RenderProcessHost* rph, |
| 61 const extensions::Extension& extension) { |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
43 | 63 |
44 std::vector<MediaFSIDAndPath> results; | 64 std::vector<MediaFSIDAndPath> results; |
45 std::pair<ChildIdToMediaFSMap::iterator, bool> ret = | 65 std::pair<ChildIdToMediaFSMap::iterator, bool> ret = |
46 media_fs_map_.insert(std::make_pair(rph, MediaPathToFSIDMap())); | 66 media_fs_map_.insert(std::make_pair(rph, MediaPathToFSIDMap())); |
47 ChildIdToMediaFSMap::iterator& child_it = ret.first; | 67 ChildIdToMediaFSMap::iterator& child_it = ret.first; |
48 if (ret.second) { | 68 if (ret.second) { |
49 // Never seen a GetMediaFileSystems call from this RPH. Initialize its | 69 // Never seen a GetMediaFileSystems call from this RPH. Initialize its |
50 // file system mappings. | 70 // file system mappings. |
51 RegisterForRPHGoneNotifications(rph); | 71 RegisterForRPHGoneNotifications(rph); |
52 FilePath pictures_path; | 72 FilePath pictures_path; |
53 if (PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path)) { | 73 // TODO(vandebo) file system galleries need a unique id as well. |
| 74 if (PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path) && |
| 75 IsGalleryPermittedForExtension(extension, SystemMonitor::TYPE_PATH, |
| 76 pictures_path.value())) { |
54 std::string fsid = RegisterPathAsFileSystem(pictures_path); | 77 std::string fsid = RegisterPathAsFileSystem(pictures_path); |
55 child_it->second.insert(std::make_pair(pictures_path, fsid)); | 78 child_it->second.insert(std::make_pair(pictures_path, fsid)); |
56 } | 79 } |
57 } | 80 } |
58 | 81 |
59 // TODO(thestig) Handle overlap between devices and media directories. | 82 // TODO(thestig) Handle overlap between devices and media directories. |
60 SystemMonitor* monitor = SystemMonitor::Get(); | 83 SystemMonitor* monitor = SystemMonitor::Get(); |
61 const std::vector<SystemMonitor::MediaDeviceInfo> media_devices = | 84 const std::vector<SystemMonitor::MediaDeviceInfo> media_devices = |
62 monitor->GetAttachedMediaDevices(); | 85 monitor->GetAttachedMediaDevices(); |
63 for (size_t i = 0; i < media_devices.size(); ++i) { | 86 for (size_t i = 0; i < media_devices.size(); ++i) { |
64 if (media_devices[i].type == SystemMonitor::TYPE_PATH) { | 87 if (media_devices[i].type == SystemMonitor::TYPE_PATH && |
| 88 IsGalleryPermittedForExtension(extension, media_devices[i].type, |
| 89 media_devices[i].location)) { |
65 FilePath path(media_devices[i].location); | 90 FilePath path(media_devices[i].location); |
66 device_id_map_.insert(std::make_pair(media_devices[i].unique_id, path)); | 91 device_id_map_.insert(std::make_pair(media_devices[i].unique_id, path)); |
67 const std::string fsid = RegisterPathAsFileSystem(path); | 92 const std::string fsid = RegisterPathAsFileSystem(path); |
68 child_it->second.insert(std::make_pair(path, fsid)); | 93 child_it->second.insert(std::make_pair(path, fsid)); |
69 } | 94 } |
70 } | 95 } |
71 | 96 |
72 MediaPathToFSIDMap& child_map = child_it->second; | 97 MediaPathToFSIDMap& child_map = child_it->second; |
73 for (MediaPathToFSIDMap::const_iterator it = child_map.begin(); | 98 for (MediaPathToFSIDMap::const_iterator it = child_map.begin(); |
74 it != child_map.end(); | 99 it != child_map.end(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 MediaPathToFSIDMap& child_map = child_it->second; | 187 MediaPathToFSIDMap& child_map = child_it->second; |
163 MediaPathToFSIDMap::iterator media_path_it = child_map.find(path); | 188 MediaPathToFSIDMap::iterator media_path_it = child_map.find(path); |
164 if (media_path_it == child_map.end()) | 189 if (media_path_it == child_map.end()) |
165 continue; | 190 continue; |
166 isolated_context->RevokeFileSystem(media_path_it->second); | 191 isolated_context->RevokeFileSystem(media_path_it->second); |
167 child_map.erase(media_path_it); | 192 child_map.erase(media_path_it); |
168 } | 193 } |
169 } | 194 } |
170 | 195 |
171 } // namespace chrome | 196 } // namespace chrome |
OLD | NEW |