Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: chrome/browser/media_gallery/media_file_system_registry.cc

Issue 10780023: Change base::SystemMonitor's media device functions to take a type and string16 instead of a FilePa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/path_service.h" 11 #include "base/path_service.h"
12 #include "base/utf_string_conversions.h"
12 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
15 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
16 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
17 #include "webkit/fileapi/isolated_context.h" 18 #include "webkit/fileapi/isolated_context.h"
18 19
19 namespace chrome { 20 namespace chrome {
20 21
21 static base::LazyInstance<MediaFileSystemRegistry>::Leaky 22 static base::LazyInstance<MediaFileSystemRegistry>::Leaky
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 std::string fsid = RegisterPathAsFileSystem(pictures_path); 54 std::string fsid = RegisterPathAsFileSystem(pictures_path);
54 child_it->second.insert(std::make_pair(pictures_path, fsid)); 55 child_it->second.insert(std::make_pair(pictures_path, fsid));
55 } 56 }
56 } 57 }
57 58
58 // TODO(thestig) Handle overlap between devices and media directories. 59 // TODO(thestig) Handle overlap between devices and media directories.
59 SystemMonitor* monitor = SystemMonitor::Get(); 60 SystemMonitor* monitor = SystemMonitor::Get();
60 const std::vector<SystemMonitor::MediaDeviceInfo> media_devices = 61 const std::vector<SystemMonitor::MediaDeviceInfo> media_devices =
61 monitor->GetAttachedMediaDevices(); 62 monitor->GetAttachedMediaDevices();
62 for (size_t i = 0; i < media_devices.size(); ++i) { 63 for (size_t i = 0; i < media_devices.size(); ++i) {
63 const SystemMonitor::DeviceIdType& id = media_devices[i].a; 64 if (media_devices[i].type == SystemMonitor::TYPE_PATH) {
64 const FilePath& path = media_devices[i].c; 65 FilePath path(media_devices[i].location);
65 device_id_map_.insert(std::make_pair(id, path)); 66 device_id_map_.insert(std::make_pair(media_devices[i].unique_id, path));
66 std::string fsid = RegisterPathAsFileSystem(path); 67 const std::string fsid = RegisterPathAsFileSystem(path);
67 child_it->second.insert(std::make_pair(path, fsid)); 68 child_it->second.insert(std::make_pair(path, fsid));
69 }
68 } 70 }
69 71
70 MediaPathToFSIDMap& child_map = child_it->second; 72 MediaPathToFSIDMap& child_map = child_it->second;
71 for (MediaPathToFSIDMap::const_iterator it = child_map.begin(); 73 for (MediaPathToFSIDMap::const_iterator it = child_map.begin();
72 it != child_map.end(); 74 it != child_map.end();
73 ++it) { 75 ++it) {
74 const FilePath path = it->first; 76 const FilePath path = it->first;
75 const std::string fsid = it->second; 77 const std::string fsid = it->second;
76 results.push_back(std::make_pair(fsid, path)); 78 results.push_back(std::make_pair(fsid, path));
77 } 79 }
78 return results; 80 return results;
79 } 81 }
80 82
81 void MediaFileSystemRegistry::OnMediaDeviceDetached( 83 void MediaFileSystemRegistry::OnMediaDeviceDetached(const std::string& id) {
82 const base::SystemMonitor::DeviceIdType& id) {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
84 85
85 DeviceIdToMediaPathMap::iterator it = device_id_map_.find(id); 86 DeviceIdToMediaPathMap::iterator it = device_id_map_.find(id);
86 if (it == device_id_map_.end()) 87 if (it == device_id_map_.end())
87 return; 88 return;
88 RevokeMediaFileSystem(it->second); 89 RevokeMediaFileSystem(it->second);
89 device_id_map_.erase(it); 90 device_id_map_.erase(it);
90 } 91 }
91 92
92 void MediaFileSystemRegistry::Observe( 93 void MediaFileSystemRegistry::Observe(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 MediaPathToFSIDMap& child_map = child_it->second; 162 MediaPathToFSIDMap& child_map = child_it->second;
162 MediaPathToFSIDMap::iterator media_path_it = child_map.find(path); 163 MediaPathToFSIDMap::iterator media_path_it = child_map.find(path);
163 if (media_path_it == child_map.end()) 164 if (media_path_it == child_map.end())
164 continue; 165 continue;
165 isolated_context->RevokeFileSystem(media_path_it->second); 166 isolated_context->RevokeFileSystem(media_path_it->second);
166 child_map.erase(media_path_it); 167 child_map.erase(media_path_it);
167 } 168 }
168 } 169 }
169 170
170 } // namespace chrome 171 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698