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

Side by Side Diff: webkit/fileapi/external_mount_points.cc

Issue 12258021: Fix filesystem API file_handlers to work for drive on ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
« no previous file with comments | « webkit/fileapi/external_mount_points.h ('k') | webkit/fileapi/file_system_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "webkit/fileapi/external_mount_points.h" 5 #include "webkit/fileapi/external_mount_points.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return false; 122 return false;
123 123
124 instance_map_[mount_name] = new Instance(type, path, remote_proxy); 124 instance_map_[mount_name] = new Instance(type, path, remote_proxy);
125 if (!path.empty()) 125 if (!path.empty())
126 path_to_name_map_.insert(std::make_pair(path, mount_name)); 126 path_to_name_map_.insert(std::make_pair(path, mount_name));
127 return true; 127 return true;
128 } 128 }
129 129
130 bool ExternalMountPoints::HandlesFileSystemMountType( 130 bool ExternalMountPoints::HandlesFileSystemMountType(
131 FileSystemType type) const { 131 FileSystemType type) const {
132 return type == kFileSystemTypeExternal; 132 return type == kFileSystemTypeExternal ||
133 type == kFileSystemTypeExternalFullPath;
133 } 134 }
134 135
135 bool ExternalMountPoints::RevokeFileSystem(const std::string& mount_name) { 136 bool ExternalMountPoints::RevokeFileSystem(const std::string& mount_name) {
136 base::AutoLock locker(lock_); 137 base::AutoLock locker(lock_);
137 NameToInstance::iterator found = instance_map_.find(mount_name); 138 NameToInstance::iterator found = instance_map_.find(mount_name);
138 if (found == instance_map_.end()) 139 if (found == instance_map_.end())
139 return false; 140 return false;
140 Instance* instance = found->second; 141 Instance* instance = found->second;
141 path_to_name_map_.erase(NormalizeFilePath(instance->path())); 142 path_to_name_map_.erase(NormalizeFilePath(instance->path()));
142 delete found->second; 143 delete found->second;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 for (; component_iter != components.end(); ++component_iter) 197 for (; component_iter != components.end(); ++component_iter)
197 cracked_path = cracked_path.Append(*component_iter); 198 cracked_path = cracked_path.Append(*component_iter);
198 *path = cracked_path; 199 *path = cracked_path;
199 return true; 200 return true;
200 } 201 }
201 202
202 FileSystemURL ExternalMountPoints::CrackURL(const GURL& url) const { 203 FileSystemURL ExternalMountPoints::CrackURL(const GURL& url) const {
203 FileSystemURL filesystem_url = FileSystemURL(url); 204 FileSystemURL filesystem_url = FileSystemURL(url);
204 if (!filesystem_url.is_valid()) 205 if (!filesystem_url.is_valid())
205 return FileSystemURL(); 206 return FileSystemURL();
206 return CreateCrackedFileSystemURL(filesystem_url.origin(), 207 return CrackFileSystemURL(filesystem_url);
207 filesystem_url.mount_type(), 208 }
208 filesystem_url.path()); 209
210 FileSystemURL ExternalMountPoints::CrackFileSystemURL(
211 const FileSystemURL& url) const {
212 if (!HandlesFileSystemMountType(url.type()))
213 return FileSystemURL();
214
215 base::FilePath virtual_path = url.path();
216 if (url.type() == kFileSystemTypeExternalFullPath) {
217 if (!GetVirtualPath(url.path(), &virtual_path))
218 return FileSystemURL();
219 }
220
221 std::string mount_name;
222 FileSystemType cracked_type;
223 base::FilePath cracked_path;
224
225 if (!CrackVirtualPath(virtual_path, &mount_name, &cracked_type,
226 &cracked_path)) {
227 return FileSystemURL();
228 }
229
230 return FileSystemURL(
231 url.origin(), url.mount_type(), url.virtual_path(),
232 !url.filesystem_id().empty() ? url.filesystem_id() : mount_name,
233 cracked_type, cracked_path, mount_name);
209 } 234 }
210 235
211 FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL( 236 FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL(
212 const GURL& origin, 237 const GURL& origin,
213 FileSystemType type, 238 FileSystemType type,
214 const base::FilePath& path) const { 239 const base::FilePath& path) const {
215 if (!HandlesFileSystemMountType(type)) 240 return CrackFileSystemURL(FileSystemURL(origin, type, path));
216 return FileSystemURL();
217
218 std::string mount_name;
219 FileSystemType cracked_type;
220 base::FilePath cracked_path;
221 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path))
222 return FileSystemURL();
223
224 return FileSystemURL(origin, type, path,
225 mount_name, cracked_type, cracked_path);
226 } 241 }
227 242
228 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy( 243 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy(
229 const std::string& mount_name) const { 244 const std::string& mount_name) const {
230 base::AutoLock locker(lock_); 245 base::AutoLock locker(lock_);
231 NameToInstance::const_iterator found = instance_map_.find(mount_name); 246 NameToInstance::const_iterator found = instance_map_.find(mount_name);
232 if (found == instance_map_.end()) 247 if (found == instance_map_.end())
233 return NULL; 248 return NULL;
234 return found->second->remote_proxy(); 249 return found->second->remote_proxy();
235 } 250 }
236 251
237 void ExternalMountPoints::AddMountPointInfosTo( 252 void ExternalMountPoints::AddMountPointInfosTo(
238 std::vector<MountPointInfo>* mount_points) const { 253 std::vector<MountPointInfo>* mount_points) const {
239 base::AutoLock locker(lock_); 254 base::AutoLock locker(lock_);
240 DCHECK(mount_points); 255 DCHECK(mount_points);
241 for (NameToInstance::const_iterator iter = instance_map_.begin(); 256 for (NameToInstance::const_iterator iter = instance_map_.begin();
242 iter != instance_map_.end(); ++iter) { 257 iter != instance_map_.end(); ++iter) {
243 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); 258 mount_points->push_back(MountPointInfo(iter->first, iter->second->path()));
244 } 259 }
245 } 260 }
246 261
247 bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path_in, 262 bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path_in,
248 base::FilePath* virtual_path) { 263 base::FilePath* virtual_path) const {
249 DCHECK(virtual_path); 264 DCHECK(virtual_path);
250 265
251 base::AutoLock locker(lock_); 266 base::AutoLock locker(lock_);
252 267
253 base::FilePath path = NormalizeFilePath(path_in); 268 base::FilePath path = NormalizeFilePath(path_in);
254 std::map<base::FilePath, std::string>::reverse_iterator iter( 269 std::map<base::FilePath, std::string>::const_reverse_iterator iter(
255 path_to_name_map_.upper_bound(path)); 270 path_to_name_map_.upper_bound(path));
256 if (iter == path_to_name_map_.rend()) 271 if (iter == path_to_name_map_.rend())
257 return false; 272 return false;
258 273
259 *virtual_path = CreateVirtualRootPath(iter->second); 274 *virtual_path = CreateVirtualRootPath(iter->second);
260 if (iter->first == path) 275 if (iter->first == path)
261 return true; 276 return true;
262 return iter->first.AppendRelativePath(path, virtual_path); 277 return iter->first.AppendRelativePath(path, virtual_path);
263 } 278 }
264 279
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 base::FilePath ScopedExternalFileSystem::GetVirtualRootPath() const { 340 base::FilePath ScopedExternalFileSystem::GetVirtualRootPath() const {
326 return ExternalMountPoints::GetSystemInstance()-> 341 return ExternalMountPoints::GetSystemInstance()->
327 CreateVirtualRootPath(mount_name_); 342 CreateVirtualRootPath(mount_name_);
328 } 343 }
329 344
330 ScopedExternalFileSystem::~ScopedExternalFileSystem() { 345 ScopedExternalFileSystem::~ScopedExternalFileSystem() {
331 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); 346 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_);
332 } 347 }
333 348
334 } // namespace fileapi 349 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/external_mount_points.h ('k') | webkit/fileapi/file_system_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698