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 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
130 const RenderProcessHost* rph = | 130 const RenderProcessHost* rph = |
131 content::Source<content::RenderProcessHost>(source).ptr(); | 131 content::Source<content::RenderProcessHost>(source).ptr(); |
132 ChildIdToMediaFSMap::iterator child_it = media_fs_map_.find(rph); | 132 ChildIdToMediaFSMap::iterator child_it = media_fs_map_.find(rph); |
133 CHECK(child_it != media_fs_map_.end()); | 133 CHECK(child_it != media_fs_map_.end()); |
134 // No need to revoke the isolated file systems. The RPH will do that. | 134 // No need to revoke the isolated file systems. The RPH will do that. |
135 media_fs_map_.erase(child_it); | 135 media_fs_map_.erase(child_it); |
136 UnregisterForRPHGoneNotifications(rph); | 136 UnregisterForRPHGoneNotifications(rph); |
137 } | 137 } |
138 | 138 |
| 139 std::string MediaFileSystemRegistry::GetDeviceIdFromPath(const FilePath& path) { |
| 140 // TODO(vandebo) Do something better here, at least iterate system monitor |
| 141 // attached media devices looking for a match. If not, return the path. |
| 142 return path.value(); |
| 143 } |
| 144 |
139 /****************** | 145 /****************** |
140 * Private methods | 146 * Private methods |
141 ******************/ | 147 ******************/ |
142 | 148 |
143 MediaFileSystemRegistry::MediaFileSystemRegistry() { | 149 MediaFileSystemRegistry::MediaFileSystemRegistry() { |
144 SystemMonitor::Get()->AddDevicesChangedObserver(this); | 150 // SystemMonitor may be NULL in unit tests. |
| 151 SystemMonitor* system_monitor = SystemMonitor::Get(); |
| 152 if (system_monitor) |
| 153 system_monitor->AddDevicesChangedObserver(this); |
145 } | 154 } |
146 | 155 |
147 MediaFileSystemRegistry::~MediaFileSystemRegistry() { | 156 MediaFileSystemRegistry::~MediaFileSystemRegistry() { |
148 SystemMonitor::Get()->RemoveDevicesChangedObserver(this); | 157 // SystemMonitor may be NULL in unit tests. |
| 158 SystemMonitor* system_monitor = SystemMonitor::Get(); |
| 159 if (system_monitor) |
| 160 system_monitor->RemoveDevicesChangedObserver(this); |
149 } | 161 } |
150 | 162 |
151 void MediaFileSystemRegistry::RegisterForRPHGoneNotifications( | 163 void MediaFileSystemRegistry::RegisterForRPHGoneNotifications( |
152 const content::RenderProcessHost* rph) { | 164 const content::RenderProcessHost* rph) { |
153 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 165 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
154 content::Source<RenderProcessHost>(rph)); | 166 content::Source<RenderProcessHost>(rph)); |
155 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 167 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
156 content::Source<RenderProcessHost>(rph)); | 168 content::Source<RenderProcessHost>(rph)); |
157 } | 169 } |
158 | 170 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 MediaPathToFSIDMap& child_map = child_it->second; | 204 MediaPathToFSIDMap& child_map = child_it->second; |
193 MediaPathToFSIDMap::iterator media_path_it = child_map.find(path); | 205 MediaPathToFSIDMap::iterator media_path_it = child_map.find(path); |
194 if (media_path_it == child_map.end()) | 206 if (media_path_it == child_map.end()) |
195 continue; | 207 continue; |
196 isolated_context->RevokeFileSystem(media_path_it->second); | 208 isolated_context->RevokeFileSystem(media_path_it->second); |
197 child_map.erase(media_path_it); | 209 child_map.erase(media_path_it); |
198 } | 210 } |
199 } | 211 } |
200 | 212 |
201 } // namespace chrome | 213 } // namespace chrome |
OLD | NEW |