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

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

Issue 10827057: Plumb file system name down from MediaFileSystemRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 4 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/file_path.h" 11 #include "base/file_path.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/system_monitor/system_monitor.h" 13 #include "base/system_monitor/system_monitor.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/extensions/extension_constants.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
19 #include "content/public/browser/notification_types.h" 20 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
21 #include "webkit/fileapi/file_system_types.h" 22 #include "webkit/fileapi/file_system_types.h"
22 #include "webkit/fileapi/isolated_context.h" 23 #include "webkit/fileapi/isolated_context.h"
23 24
24 namespace chrome { 25 namespace chrome {
25 26
(...skipping 23 matching lines...) Expand all
49 50
50 /****************** 51 /******************
51 * Public methods 52 * Public methods
52 ******************/ 53 ******************/
53 54
54 // static 55 // static
55 MediaFileSystemRegistry* MediaFileSystemRegistry::GetInstance() { 56 MediaFileSystemRegistry* MediaFileSystemRegistry::GetInstance() {
56 return g_media_file_system_registry.Pointer(); 57 return g_media_file_system_registry.Pointer();
57 } 58 }
58 59
59 std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> 60 std::vector<MediaFileSystemRegistry::MediaFSInfo>
60 MediaFileSystemRegistry::GetMediaFileSystems( 61 MediaFileSystemRegistry::GetMediaFileSystemsForExtension(
61 const content::RenderProcessHost* rph, 62 const content::RenderProcessHost* rph,
62 const extensions::Extension& extension) { 63 const extensions::Extension& extension) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
64 65
65 std::vector<MediaFSIDAndPath> results; 66 std::vector<MediaFSInfo> results;
66 std::pair<ChildIdToMediaFSMap::iterator, bool> ret = 67 std::pair<ChildIdToMediaFSMap::iterator, bool> ret =
67 media_fs_map_.insert(std::make_pair(rph, MediaPathToFSIDMap())); 68 media_fs_map_.insert(std::make_pair(rph, MediaPathToFSIDMap()));
68 ChildIdToMediaFSMap::iterator& child_it = ret.first; 69 ChildIdToMediaFSMap::iterator& child_it = ret.first;
69 if (ret.second) { 70 if (ret.second) {
70 // Never seen a GetMediaFileSystems call from this RPH. Initialize its 71 // Never seen a GetMediaFileSystems call from this RPH. Initialize its
71 // file system mappings. 72 // file system mappings.
72 RegisterForRPHGoneNotifications(rph); 73 RegisterForRPHGoneNotifications(rph);
73 FilePath pictures_path; 74 FilePath pictures_path;
74 // TODO(vandebo) file system galleries need a unique id as well. 75 // TODO(vandebo) file system galleries need a unique id as well.
75 if (PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path) && 76 if (PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path) &&
(...skipping 16 matching lines...) Expand all
92 device_id_map_.insert(std::make_pair(media_devices[i].unique_id, path)); 93 device_id_map_.insert(std::make_pair(media_devices[i].unique_id, path));
93 const std::string fsid = RegisterPathAsFileSystem(path); 94 const std::string fsid = RegisterPathAsFileSystem(path);
94 child_it->second.insert(std::make_pair(path, fsid)); 95 child_it->second.insert(std::make_pair(path, fsid));
95 } 96 }
96 } 97 }
97 98
98 MediaPathToFSIDMap& child_map = child_it->second; 99 MediaPathToFSIDMap& child_map = child_it->second;
99 for (MediaPathToFSIDMap::const_iterator it = child_map.begin(); 100 for (MediaPathToFSIDMap::const_iterator it = child_map.begin();
100 it != child_map.end(); 101 it != child_map.end();
101 ++it) { 102 ++it) {
102 const FilePath path = it->first; 103 MediaFSInfo entry;
103 const std::string fsid = it->second; 104 // TODO(vandebo) use a better name, fsid for now.
104 results.push_back(std::make_pair(fsid, path)); 105 entry.name = it->second;
106 entry.fsid = it->second;
107 entry.path = it->first;
108 results.push_back(entry);
105 } 109 }
106 return results; 110 return results;
107 } 111 }
108 112
109 void MediaFileSystemRegistry::OnMediaDeviceDetached(const std::string& id) { 113 void MediaFileSystemRegistry::OnMediaDeviceDetached(const std::string& id) {
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
111 115
112 DeviceIdToMediaPathMap::iterator it = device_id_map_.find(id); 116 DeviceIdToMediaPathMap::iterator it = device_id_map_.find(id);
113 if (it == device_id_map_.end()) 117 if (it == device_id_map_.end())
114 return; 118 return;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 std::string MediaFileSystemRegistry::RegisterPathAsFileSystem( 167 std::string MediaFileSystemRegistry::RegisterPathAsFileSystem(
164 const FilePath& path) { 168 const FilePath& path) {
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
166 170
167 // Sanity checks for |path|. 171 // Sanity checks for |path|.
168 CHECK(path.IsAbsolute()); 172 CHECK(path.IsAbsolute());
169 CHECK(!path.ReferencesParent()); 173 CHECK(!path.ReferencesParent());
170 174
171 // The directory name is not exposed to the js layer and we simply use 175 // The directory name is not exposed to the js layer and we simply use
172 // a fixed name (as we only register a single directory per file system). 176 // a fixed name (as we only register a single directory per file system).
173 std::string register_name("_"); 177 std::string register_name(extension_misc::kMediaFileSystemPathPart);
174 const std::string fsid = 178 const std::string fsid =
175 IsolatedContext::GetInstance()->RegisterFileSystemForPath( 179 IsolatedContext::GetInstance()->RegisterFileSystemForPath(
176 fileapi::kFileSystemTypeIsolated, path, &register_name); 180 fileapi::kFileSystemTypeIsolated, path, &register_name);
177 CHECK(!fsid.empty()); 181 CHECK(!fsid.empty());
178 return fsid; 182 return fsid;
179 } 183 }
180 184
181 void MediaFileSystemRegistry::RevokeMediaFileSystem(const FilePath& path) { 185 void MediaFileSystemRegistry::RevokeMediaFileSystem(const FilePath& path) {
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
183 187
184 IsolatedContext* isolated_context = IsolatedContext::GetInstance(); 188 IsolatedContext* isolated_context = IsolatedContext::GetInstance();
185 for (ChildIdToMediaFSMap::iterator child_it = media_fs_map_.begin(); 189 for (ChildIdToMediaFSMap::iterator child_it = media_fs_map_.begin();
186 child_it != media_fs_map_.end(); 190 child_it != media_fs_map_.end();
187 ++child_it) { 191 ++child_it) {
188 MediaPathToFSIDMap& child_map = child_it->second; 192 MediaPathToFSIDMap& child_map = child_it->second;
189 MediaPathToFSIDMap::iterator media_path_it = child_map.find(path); 193 MediaPathToFSIDMap::iterator media_path_it = child_map.find(path);
190 if (media_path_it == child_map.end()) 194 if (media_path_it == child_map.end())
191 continue; 195 continue;
192 isolated_context->RevokeFileSystem(media_path_it->second); 196 isolated_context->RevokeFileSystem(media_path_it->second);
193 child_map.erase(media_path_it); 197 child_map.erase(media_path_it);
194 } 198 }
195 } 199 }
196 200
197 } // namespace chrome 201 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/media_gallery/media_file_system_registry.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698